[Pkg-privacy-commits] [pyptlib] 14/136: Use string substitution for building output lines

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:00 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 3b0b709a26516b707cde342d06747b8261ca72ca
Author: Brandon Wiley <brandon at blanu.net>
Date:   Wed Jun 6 15:03:58 2012 -0500

    Use string substitution for building output lines
---
 src/pyptlib/config/client.py | 24 ++++++++++++------------
 src/pyptlib/config/config.py | 13 +++++++------
 src/pyptlib/config/server.py | 18 ++++++++++--------
 3 files changed, 29 insertions(+), 26 deletions(-)

diff --git a/src/pyptlib/config/client.py b/src/pyptlib/config/client.py
index 1fc130c..59898dc 100644
--- a/src/pyptlib/config/client.py
+++ b/src/pyptlib/config/client.py
@@ -8,35 +8,35 @@ Configuration for a Pluggable Transport client.
 
 __docformat__ = 'restructuredtext'
 
-
-class ClientConfig(Config):
-  clientTransports=[] # TOR_PT_CLIENT_TRANSPORTS
-  
+class ClientConfig(Config):  
   #Public methods
   
   def __init__(self): # throws EnvError
     Config.__init__(self)
     
-    clientTransports=self.get('TOR_PT_CLIENT_TRANSPORTS').split(',')
-    
+    transports=self.get('TOR_PT_CLIENT_TRANSPORTS').split(',')
+    if '*' in transports:
+      allTransportsEnabled=True
+      transports.remove('*')      
+
   # Returns a list of strings representing the client transports reported by Tor. If present, '*' is stripped from this list and used to set allTransportsEnabled to True.
   def getClientTransports(self):
-    return clientTransports
+    return transports
 
   # Write a message to stdout specifying a supported transport
   # Takes: str, int, (str, int), [str], [str]
   def writeMethod(self, name, socksVersion, address, args, optArgs): # CMETHOD
-    s='CMETHOD '+str(name)+' socks'+str(socksVersion)+' '+str(address[0])+':'+str(address[1])
+    methodLine='CMETHOD %s socks%s %s:%s' % (name, socksVersion, address[0], address[1]))
     if args and len(args)>0:
-      s=s+' ARGS='+args.join(',')
+      methodLine=methodLine+' ARGS='+args.join(',')
     if optArgs and len(optArgs)>0:
-      s=s+' OPT-ARGS='+args.join(',')
-    print(s) 
+      methodLine=methodLine+' OPT-ARGS='+args.join(',')
+    print(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 '+str(name)+' '+str(message))
+    print('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
diff --git a/src/pyptlib/config/config.py b/src/pyptlib/config/config.py
index f75d1b7..a497d10 100644
--- a/src/pyptlib/config/config.py
+++ b/src/pyptlib/config/config.py
@@ -9,6 +9,7 @@ __docformat__ = 'restructuredtext'
 class Config:
   stateLocation=None     # TOR_PT_STATE_LOCATION
   managedTransportVer=[] # TOR_PT_MANAGED_TRANSPORT_VER
+  transports=[] # TOR_PT_SERVER_TRANSPORTS or TOR_PT_CLIENT_TRANSPORTS
   allTransportsEnabled=False
   
   #Public methods
@@ -16,9 +17,6 @@ class Config:
   def __init__(self): # throws EnvError
     stateLocation=self.get('TOR_PT_STATE_LOCATION')
     managedTransportVer=self.get('TOR_PT_MANAGED_TRANSPORT_VER').split(',')
-    if '*' in managedTransportVer:
-      allTransportsEnabled=True
-      managedTransportVer.remove('*')      
         
   # 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):
@@ -31,21 +29,24 @@ class Config:
   # Checks to see if the specified version is included in those reported by Tor
   # Returns True if the version is included and False if it is not
   def checkManagedTransportVersion(self, version):
-    return allTransportsEnabled or version in managedTransportVer
+    return version in managedTransportVer
 
   # Returns a bool, True if the transport '*' was specified by Tor, otherwise False.
   def getAllTransportsEnabled(self):
     return allTransportsEnabled
+    
+  def checkTransportEnabled(self, transport):
+    return allTransportsEnabled or transport in transports    
 
   # Write a message to stdout specifying that an error parsing the environment variables has occurred
   # Takes: str
   def writeEnvError(self, message): # ENV-ERROR
-    print('ENV-ERROR '+str(message))
+    print('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 '+str(version))
+    print('VERSION %s' % (version))
 
   # Write a message to stdout specifying that none of the specified configuration protocol versions are supported
   def writeVersionError(self): # VERSION-ERROR
diff --git a/src/pyptlib/config/server.py b/src/pyptlib/config/server.py
index 3d076d9..827c5d0 100644
--- a/src/pyptlib/config/server.py
+++ b/src/pyptlib/config/server.py
@@ -12,7 +12,6 @@ class ServerConfig(Config):
   extendedServerPort=None # TOR_PT_EXTENDED_SERVER_PORT
   ORPort=None             # TOR_PT_ORPORT
   serverBindAddr={}       # TOR_PT_SERVER_BINADDR
-  serverTransports=[]     # TOR_PT_SERVER_TRANSPORTS
   
   #Public methods
   
@@ -27,7 +26,10 @@ class ServerConfig(Config):
       key,value=bind.split(',')
       serverBindAddr[key]=value
     
-    serverTransports=self.get('TOR_PT_SERVER_TRANSPORTS').split(',')
+    transports=self.get('TOR_PT_SERVER_TRANSPORTS').split(',')
+    if '*' in transports:
+      allTransportsEnabled=True
+      transports.remove('*')      
     
   # Returns a tuple (str,int) representing the address of the Tor server port as reported by Tor
   def getExtendedServerPort(self):
@@ -43,20 +45,20 @@ class ServerConfig(Config):
     
   # Returns a list of strings representing the server transports reported by Tor. If present, '*' is stripped from this list and used to set allTransportsEnabled to True.
   def getServerTransports(self):
-    return serverTransports
-
+    return transports
+    
   # Write a message to stdout specifying a supported transport
   # Takes: str, (str, int), MethodOptions
   def writeMethod(self, name, address, options): # SMETHOD
-    s='SMETHOD '+str(name)+' '+str(address[0])+':'+str(address[1])
     if options:
-      s=s+' '+str(options)
-    print(s)
+      print('SMETHOD %s %s:%s %s' % (name, address[0], address[1], options))
+    else:
+      print('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 '+str(name)+' '+str(message))
+    print('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

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