[Pkg-privacy-commits] [pyptlib] 37/136: Fixes to get pyptlib working with Tor
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:04 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository pyptlib.
commit 7e45afc10434df389e27ebcc392d9e140ff36538
Author: Brandon Wiley <brandon at blanu.net>
Date: Wed Jul 18 12:29:32 2012 -0500
Fixes to get pyptlib working with Tor
---
src/pyptlib/client.py | 6 +++---
src/pyptlib/config.py | 16 +++++++++++++---
src/pyptlib/easy/util.py | 10 +++-------
src/pyptlib/server.py | 10 +++++-----
4 files changed, 24 insertions(+), 18 deletions(-)
diff --git a/src/pyptlib/client.py b/src/pyptlib/client.py
index 11e51e2..0186aac 100644
--- a/src/pyptlib/client.py
+++ b/src/pyptlib/client.py
@@ -44,17 +44,17 @@ class ClientConfig(Config):
methodLine = methodLine + ' ARGS=' + args.join(',')
if optArgs and len(optArgs) > 0:
methodLine = methodLine + ' OPT-ARGS=' + args.join(',')
- print methodLine
+ self.emit(methodLine)
# Write a message to stdout specifying that an error occurred setting up the specified method
# Takes: str, str
def writeMethodError(self, name, message): # CMETHOD-ERROR
- print 'CMETHOD-ERROR %s %s' % (name, message)
+ self.emit('CMETHOD-ERROR %s %s' % (name, message))
# Write a message to stdout specifying that the list of supported transports has ended
def writeMethodEnd(self): # CMETHODS DONE
- print 'CMETHODS DONE'
+ self.emit('CMETHODS DONE')
diff --git a/src/pyptlib/config.py b/src/pyptlib/config.py
index 71d63c8..f3e71b1 100644
--- a/src/pyptlib/config.py
+++ b/src/pyptlib/config.py
@@ -2,6 +2,7 @@
# -*- coding: utf-8 -*-
import os
+import logging
__docformat__ = 'restructuredtext'
@@ -20,6 +21,9 @@ class Config:
self.managedTransportVer = \
self.get('TOR_PT_MANAGED_TRANSPORT_VER').split(',')
+ def checkClientMode(self):
+ return self.check('TOR_PT_CLIENT_TRANSPORTS')
+
# Returns a string representing the path to the state storage directory (which may not exist, but should be creatable) reported by Tor
def getStateLocation(self):
@@ -48,21 +52,24 @@ class Config:
# Takes: str
def writeEnvError(self, message): # ENV-ERROR
- print 'ENV-ERROR %s' % message
+ self.emit('ENV-ERROR %s' % message)
# Write a message to stdout specifying that the specified configuration protocol version is supported
# Takes: str
def writeVersion(self, version): # VERSION
- print 'VERSION %s' % version
+ self.emit('VERSION %s' % version)
# Write a message to stdout specifying that none of the specified configuration protocol versions are supported
def writeVersionError(self): # VERSION-ERROR
- print 'VERSION-ERROR no-version'
+ self.emit('VERSION-ERROR no-version')
# Private methods
+ def check(self, key):
+ return key in os.environ
+
def get(self, key):
if key in os.environ:
return os.environ[key]
@@ -71,6 +78,9 @@ class Config:
self.writeEnvError(message)
raise EnvException(message)
+ def emit(self, msg):
+ print(msg)
+ logging.error(msg)
# Exception thrown when there is an error parsing the configuration parameters provided by Tor in environment variables
diff --git a/src/pyptlib/easy/util.py b/src/pyptlib/easy/util.py
index 75498fc..04eccde 100644
--- a/src/pyptlib/easy/util.py
+++ b/src/pyptlib/easy/util.py
@@ -1,15 +1,11 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
-from pyptlib.config import EnvException
-from pyptlib.client import ClientConfig
-
+from pyptlib.config import Config, EnvException
def checkClientMode():
try:
- client = ClientConfig()
- return True
+ c = Config()
+ return c.checkClientMode()
except EnvException:
return False
-
-
diff --git a/src/pyptlib/server.py b/src/pyptlib/server.py
index 7383660..1aee58e 100644
--- a/src/pyptlib/server.py
+++ b/src/pyptlib/server.py
@@ -65,21 +65,21 @@ class ServerConfig(Config):
):
if options:
- print 'SMETHOD %s %s:%s %s' % (name, address[0],
- address[1], options)
+ self.emit('SMETHOD %s %s:%s %s' % (name, address[0],
+ address[1], options))
else:
- print 'SMETHOD %s %s:%s' % (name, address[0], address[1])
+ self.emit('SMETHOD %s %s:%s' % (name, address[0], address[1]))
# Write a message to stdout specifying that an error occurred setting up the specified method
# Takes: str, str
def writeMethodError(self, name, message): # SMETHOD-ERROR
- print 'SMETHOD-ERROR %s %s' % (name, message)
+ self.emit('SMETHOD-ERROR %s %s' % (name, message))
# Write a message to stdout specifying that the list of supported transports has ended
def writeMethodEnd(self): # SMETHODS DONE
- print 'SMETHODS DONE'
+ self.emit('SMETHODS DONE')
class MethodOptions:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/pyptlib.git
More information about the Pkg-privacy-commits
mailing list