[Pkg-privacy-commits] [obfsproxy] 60/353: Tidy up the code. Beautify and document.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:01:39 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository obfsproxy.
commit 17d6d09a1fd900e210f7695f28dcc2c178b86b75
Author: George Kadianakis <desnacked at riseup.net>
Date: Wed Sep 5 03:49:09 2012 +0300
Tidy up the code. Beautify and document.
---
src/cli.py | 23 +++++++++++++++++------
src/obfsproxy/common/log.py | 13 +++++++++++++
src/obfsproxy/framework/managed/client.py | 1 -
src/obfsproxy/framework/managed/server.py | 1 -
4 files changed, 30 insertions(+), 8 deletions(-)
diff --git a/src/cli.py b/src/cli.py
index f754b49..4f9ef3a 100644
--- a/src/cli.py
+++ b/src/cli.py
@@ -39,7 +39,7 @@ def set_up_cli_parsing():
subparsers = parser.add_subparsers(title='supported transports', dest='name')
parser.add_argument('--log-file', help='set logfile')
- parser.add_argument('--log-min-severity', default='warning',
+ parser.add_argument('--log-min-severity',
choices=['error', 'warning', 'info', 'debug'],
help='set minimum logging severity (default: %(default)s)')
parser.add_argument('--no-log', action='store_true', default=False,
@@ -94,10 +94,8 @@ def do_external_mode(args):
add_service(Service(handler.handle, bindaddr=args.listen_addr[0], port=int(args.listen_addr[1])))
eventloop.run()
-def main(argv):
- parser = set_up_cli_parsing()
-
- args = parser.parse_args()
+def consider_cli_args(args):
+ """Check out parsed CLI arguments and take the appropriate actions."""
if args.log_file:
log.set_log_file(args.log_file)
@@ -108,7 +106,20 @@ def main(argv):
if args.no_safe_logging:
pass # XXX
- # XXX do sanity checks. like in case managed is set along with external options etc.
+ # validate:
+ if (args.name == 'managed') and (not args.log_file) and (args.log_min_severity):
+ log.error("obfsproxy in managed-proxy mode can only log to a file!")
+ sys.exit(1)
+ elif (args.name == 'managed') and (not args.log_file):
+ # managed proxies without a logfile must not log at all.
+ log.disable_logs()
+
+def main(argv):
+ parser = set_up_cli_parsing()
+
+ args = parser.parse_args()
+
+ consider_cli_args(args)
log.error('py-obfsproxy CLI loaded')
log.warning('argv: ' + str(sys.argv))
diff --git a/src/obfsproxy/common/log.py b/src/obfsproxy/common/log.py
index 103a1bb..5b594a6 100644
--- a/src/obfsproxy/common/log.py
+++ b/src/obfsproxy/common/log.py
@@ -1,21 +1,34 @@
# obfsproxy logging code
import logging
+import sys
# XXX Add Formatter!!!
our_logger = logging.getLogger('our_logger')
+default_handler = logging.StreamHandler(sys.stdout)
+our_logger.addHandler(default_handler)
our_logger.propagate = False
def set_log_file(filename):
+ """Set up our logger so that it starts logging to file in 'filename' instead."""
+
+ # remove the default handler, and add the FileHandler:
+ our_logger.removeHandler(default_handler)
+
log_handler = logging.FileHandler(filename)
our_logger.addHandler(log_handler)
def set_log_severity(sev_string):
+ """Update our minimum logging severity to 'sev_string'."""
+
+ # Turn it into a numeric level that logging understands first.
numeric_level = getattr(logging, sev_string.upper(), None)
our_logger.setLevel(numeric_level)
def disable_logs():
+ """Disable all logging."""
+
logging.disable(logging.CRITICAL)
# Redirect logging functions to our custom logger.
diff --git a/src/obfsproxy/framework/managed/client.py b/src/obfsproxy/framework/managed/client.py
index 9b7c526..c870a54 100755
--- a/src/obfsproxy/framework/managed/client.py
+++ b/src/obfsproxy/framework/managed/client.py
@@ -39,7 +39,6 @@ class ManagedClient:
managed_info = init(self.supportedTransports.keys())
if managed_info is None: # XXX what should we return?
- print "failz" # XXX make sure that pyptlib has whined to Tor.
return
for transport in managed_info['transports']:
diff --git a/src/obfsproxy/framework/managed/server.py b/src/obfsproxy/framework/managed/server.py
index 3fcb62a..d5a069e 100755
--- a/src/obfsproxy/framework/managed/server.py
+++ b/src/obfsproxy/framework/managed/server.py
@@ -36,7 +36,6 @@ class ManagedServer:
managed_info = init(self.supportedTransports)
if managed_info is None: # XXX what is this function supposed to return?!
- print "failz" # XXX make sure that pyptlib has whined to Tor.
return
self.orport_handler = ProxyHandler(*managed_info['orport'])
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/obfsproxy.git
More information about the Pkg-privacy-commits
mailing list