[Pkg-privacy-commits] [pyptlib] 82/136: allow Config to direct their output elsewhere; useful for tests

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:12 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 232d4eb61c3f4bb4a3962638fc6fda8bd0336f63
Author: Ximin Luo <infinity0 at gmx.com>
Date:   Wed Aug 14 15:18:35 2013 +0100

    allow Config to direct their output elsewhere; useful for tests
---
 pyptlib/client_config.py | 5 +++--
 pyptlib/config.py        | 7 ++++---
 pyptlib/server_config.py | 4 ++--
 3 files changed, 9 insertions(+), 7 deletions(-)

diff --git a/pyptlib/client_config.py b/pyptlib/client_config.py
index 6cd6317..d5536cc 100644
--- a/pyptlib/client_config.py
+++ b/pyptlib/client_config.py
@@ -15,9 +15,10 @@ class ClientConfig(Config):
 
     :raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
     """
-    def __init__(self):
+    def __init__(self, stdout=sys.stdout):
         Config.__init__(self,
-            transports = self.getEnv('TOR_PT_CLIENT_TRANSPORTS').split(','))
+            transports = self.getEnv('TOR_PT_CLIENT_TRANSPORTS').split(','),
+            stdout = stdout)
 
     def writeMethod(self, name, socksVersion, addrport, args=None, optArgs=None):
         """
diff --git a/pyptlib/config.py b/pyptlib/config.py
index ea9600c..f62991d 100644
--- a/pyptlib/config.py
+++ b/pyptlib/config.py
@@ -36,7 +36,7 @@ class Config(object):
     :raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
     """
 
-    def __init__(self, transports):
+    def __init__(self, transports, stdout=sys.stdout):
         self.stateLocation = self.getEnv('TOR_PT_STATE_LOCATION')
         self.managedTransportVer = self.getEnv('TOR_PT_MANAGED_TRANSPORT_VER').split(',')
         self.allTransportsEnabled = False
@@ -44,6 +44,7 @@ class Config(object):
             self.allTransportsEnabled = True
             transports.remove('*')
         self.transports = transports
+        self.stdout = stdout
 
     def getStateLocation(self):
         """
@@ -137,8 +138,8 @@ class Config(object):
         :param str msg: A message.
         """
 
-        print msg
-        sys.stdout.flush()
+        print >>self.stdout, msg
+        self.stdout.flush()
 
 class EnvError(Exception):
     """
diff --git a/pyptlib/server_config.py b/pyptlib/server_config.py
index afeeaa6..d6099c0 100644
--- a/pyptlib/server_config.py
+++ b/pyptlib/server_config.py
@@ -22,7 +22,7 @@ class ServerConfig(config.Config):
 
     :raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
     """
-    def __init__(self):
+    def __init__(self, stdout=sys.stdout):
         """
         TOR_PT_EXTENDED_SERVER_PORT is optional; tor uses the empty
         string as its value if it does not support the Extended
@@ -71,7 +71,7 @@ class ServerConfig(config.Config):
             return transports
         transports = self.getEnv('TOR_PT_SERVER_TRANSPORTS', validate_transports)
 
-        config.Config.__init__(self, transports)
+        config.Config.__init__(self, transports, stdout)
 
     def getExtendedORPort(self):
         """

-- 
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