[Pkg-privacy-commits] [pyptlib] 54/136: Add sphinx documentation.

Ximin Luo infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:07 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 a08b477846fe3818bdc85e827042723332021de1
Author: George Kadianakis <desnacked at riseup.net>
Date:   Sat Oct 6 18:42:53 2012 -0400

    Add sphinx documentation.
---
 pyptlib/client.py        |  93 ++++++++++++++++++------------
 pyptlib/client_config.py |  50 ++++++++--------
 pyptlib/config.py        | 104 +++++++++++++++++++++------------
 pyptlib/server.py        | 112 +++++++++++++++++++-----------------
 pyptlib/server_config.py | 145 +++++++++++++++++------------------------------
 pyptlib/util.py          |  12 ++--
 6 files changed, 268 insertions(+), 248 deletions(-)

diff --git a/pyptlib/client.py b/pyptlib/client.py
index a0d5b9d..b00d2b9 100644
--- a/pyptlib/client.py
+++ b/pyptlib/client.py
@@ -2,30 +2,30 @@
 # -*- coding: utf-8 -*-
 
 """
-This module provides a convenient API for writing pluggable transport clients.
+Public client-side pyptlib API.
 """
 
 from pyptlib.config import EnvError
 from pyptlib.client_config import ClientConfig
 
-
 def init(supported_transports):
     """
-    Initialize the pluggable transport by parsing the environment
-    variables and generating output to report any errors.  The given
-    transports are checked against the transports enabled by a
-    dictionary containing information for the managed proxy is
-    returned.
+    Bootstrap client-side managed-proxy mode.
+
+    *Call in the beginning of your application.*
 
-    The dictionary contains the following keys and values:
+    :param list supported_transports: Names of the transports that the application supports.
 
-    'state_loc' : Directory where the managed proxy should dump its
-    state files (if needed).
+    :returns: dictionary that contains information for the application.
 
-    'transports' : The names of the transports that must be
-    launched. The list can be empty.
+	    ==========  ========== ==========
+	    Key         Type       Value
+	    ==========  ========== ==========
+	    state_loc   string     Directory where the managed proxy should dump its state files (if needed).
+	    transports  list       Strings of the names of the transports that should be launched. The list can be empty.
+	    ==========  ========== ==========
 
-    Throws EnvError.
+    :raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
     """
 
     supportedTransportVersion = '1'
@@ -41,40 +41,35 @@ def init(supported_transports):
 
     retval = {}
     retval['state_loc'] = config.getStateLocation()
-    retval['transports'] = getTransportsList(supported_transports, config)
+    retval['transports'] = _getTransportsList(supported_transports, config)
 
     return retval
 
-def getTransportsList(supported_transports, config):
-    transports = []
-
-    if config.getAllTransportsEnabled():
-        return supported_transports
-
-    for transport in config.getClientTransports():
-        if transport in supported_transports:
-            transports.append(transport)
-        else:
-            config.writeMethodError(transport, "not supported")
+def reportSuccess(name, socksVersion, addrport, args=None, optArgs=None):
+    """
+    Report that a client transport was launched succesfully.
 
-    return transports
+    *Always call after successfully launching a transport.*
 
-def reportSuccess(name, socksVersion, address, args, optArgs):
-    """
-        This method should be called to report when a transport has been successfully launched.
-        It generates output to Tor informing that the transport launched successfully and can be used.
-        After all transports have been launched, the client should call reportEnd().
+    :param str name: Name of transport.
+    :param int socksVersion: The SOCKS protocol version.
+    :param tuple addrport: (addr,port) where this transport is listening for connections.
+    :param str args: ARGS field for this transport.
+    :param str args: OPT-ARGS field for this transport.
     """
 
     config = ClientConfig()
-    config.writeMethod(name, socksVersion, address, args, optArgs)
+    config.writeMethod(name, socksVersion, addrport, args, optArgs)
 
 
 def reportFailure(name, message):
     """
-        This method should be called to report when a transport has failed to launch.
-        It generates output to Tor informing that the transport failed to launch and cannot be used.
-        After all transports have been launched, the client should call reportEnd().
+    Report that a client transport failed to launch.
+
+    *Always call after failing to launch a transport.*
+
+    :param str name: Name of transport.
+    :param str message: Error message.
     """
 
     config = ClientConfig()
@@ -83,11 +78,35 @@ def reportFailure(name, message):
 
 def reportEnd():
     """
-        This method should be called after all transports have been launched.
-        It generates output to Tor informing that all transports have been launched.
+    Report that we are done launching transports.
+
+    *Call after you have launched all the transports you could launch.*
     """
 
     config = ClientConfig()
     config.writeMethodEnd()
 
+def _getTransportsList(supported_transports, config):
+    """
+    Figure out which transports the application should launch, based on
+    the transports it supports and on the transports that Tor wants it
+    to spawn.
+
+    :param list supported_transports: Transports that the application supports.
+    :param :class:`pyptlib.client_config.ClientConfig` config: Configuration of Tor.
+
+    :returns: A list of transports that the application should launch.
+    """
+    transports = []
+
+    if config.getAllTransportsEnabled():
+        return supported_transports
+
+    for transport in config.getClientTransports():
+        if transport in supported_transports:
+            transports.append(transport)
+        else:
+            config.writeMethodError(transport, "not supported")
+
+    return transport
 
diff --git a/pyptlib/client_config.py b/pyptlib/client_config.py
index f2a5039..33e34a6 100644
--- a/pyptlib/client_config.py
+++ b/pyptlib/client_config.py
@@ -2,27 +2,18 @@
 # -*- coding: utf-8 -*-
 
 """
-This module contains parts of the API that are only useful to clients.
+Low-level parts of pyptlib that are only useful to clients.
 """
 
 from pyptlib.config import Config
 
 class ClientConfig(Config):
     """
-    Attributes:
+    A client-side pyptlib configuration.
 
-    self.transports: List with strings of pluggable transport names
-    that Tor wants us to handle.
-
-    self.allTransportsEnabled: True if Tor wants us to spawn all the
-    transports.
+    :raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
     """
     def __init__(self):
-        """
-        Initializer.
-        Throws EnvError.
-        """
-
         Config.__init__(self)
 
         self.transports = self.get('TOR_PT_CLIENT_TRANSPORTS').split(',')
@@ -32,39 +23,48 @@ class ClientConfig(Config):
 
     def getClientTransports(self): # XXX why is this client-specific ???
         """
-        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.
+        Return a list of strings representing the client transports reported by Tor.
+
+        If present, the wildcard transport, '*', is stripped from this list and used to set allTransportsEnabled to True.
+
+        :returns: list of transports
         """
 
         return self.transports
 
-    def writeMethod(self, name, socksVersion, address, args, optArgs):
+    def writeMethod(self, name, socksVersion, addrport, args=None, optArgs=None):
         """
-        Write a message to stdout specifying a supported transport
-        Takes: str, int, (str, int), [str], [str]
+        Write a message to stdout announcing that a transport was
+        successfully launched.
+
+        :param str name: Name of transport.
+        :param int socksVersion: The SOCKS protocol version.
+        :param tuple addrport: (addr,port) where this transport is listening for connections.
+        :param str args: ARGS field for this transport.
+        :param str optArgs: OPT-ARGS field for this transport.
         """
 
         methodLine = 'CMETHOD %s socks%s %s:%s' % (name, socksVersion,
-                address[0], address[1])
+                addrport[0], addrport[1])
         if args and len(args) > 0:
             methodLine = methodLine + ' ARGS=' + args.join(',')
         if optArgs and len(optArgs) > 0:
             methodLine = methodLine + ' OPT-ARGS=' + args.join(',')
         self.emit(methodLine)
 
-    def writeMethodError(self, name, message):  # CMETHOD-ERROR
+    def writeMethodError(self, name, message):
         """
-        Write a message to stdout specifying that an error occurred setting up the specified method
-        Takes: str, str
+        Write a message to stdout announcing that we failed to launch a transport.
+
+        :param str name: Name of transport.
+        :param str message: Error message.
         """
 
         self.emit('CMETHOD-ERROR %s %s' % (name, message))
 
-    def writeMethodEnd(self):  # CMETHODS DONE
+    def writeMethodEnd(self):
         """
-        Write a message to stdout specifying that the list of
-        supported transports has ended.
+        Write a message to stdout announcing that we finished launching transports..
         """
 
         self.emit('CMETHODS DONE')
diff --git a/pyptlib/config.py b/pyptlib/config.py
index aa859dd..ebaa8f2 100644
--- a/pyptlib/config.py
+++ b/pyptlib/config.py
@@ -2,19 +2,21 @@
 # -*- coding: utf-8 -*-
 
 """
-This module contains parts of the managed proxy specification which
-are shared by both client and server implementations of the protocol.
+Parts of pyptlib that are useful both to clients and servers.
 """
 
 import os, sys
 
-__docformat__ = 'restructuredtext'
+class Config(object):
+    """
+    pyptlib's configuration.
 
-class Config:
+    :var string stateLocation: Location where application should store state.
+    :var list managedTransportVer: List of managed-proxy protocol versions that Tor supports.
+    :var list transports: Strings of pluggable transport names that Tor wants us to handle.
+    :var bool allTransportsEnabled: True if Tor wants us to spawn all the transports.
 
-    """
-    The Config module class a low-level API which closely follows the Tor Proposal 180: Pluggable transports for circumvention.
-    This class contains the parts of the API which are shared by both client and server implementations of the protocol.
+    :raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
     """
 
     stateLocation = None  # TOR_PT_STATE_LOCATION
@@ -22,87 +24,111 @@ class Config:
     transports = []  # TOR_PT_SERVER_TRANSPORTS or TOR_PT_CLIENT_TRANSPORTS
     allTransportsEnabled = False
 
-  # Public methods
-
     def __init__(self):
-        """
-        Initialize the Config object. this causes the state location
-        and managed transport version to be set.
-
-        Throws EnvError.
-        """
-
         self.stateLocation = self.get('TOR_PT_STATE_LOCATION')
         self.managedTransportVer = self.get('TOR_PT_MANAGED_TRANSPORT_VER').split(',')
 
     def checkClientMode(self):
-        """ Check to see if the daemon is being run as a client or a server. This is determined by looking for the presence of the TOR_PT_CLIENT_TRANSPORTS environment variable. """
+        """
+        Check whether Tor wants us to run as a client or as a server.
+
+        :returns: bool -- True if Tor wants us to run as a client.
+        """
 
         return self.check('TOR_PT_CLIENT_TRANSPORTS')
 
     def getStateLocation(self):
-        """ Return the state location, a string representing the path to the state storage directory (which may not exist, but should be creatable) reported by Tor. """
+        """
+        :returns: string -- The state location.
+        """
 
         return self.stateLocation
 
     def getManagedTransportVersions(self):
-        """ Return the managed transport versions, a list of strings representing supported versions as reported by Tor. """
+        """
+        :returns: list -- The managed-proxy protocol versions that Tor supports.
+        """
 
         return self.managedTransportVer
 
     def checkManagedTransportVersion(self, version):
         """
-            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
+        Check if Tor supports a specific managed-proxy protocol version.
+
+        :param string version: A managed-proxy protocol version.
+
+        :returns: bool -- True if version is supported.
         """
 
         return version in self.managedTransportVer
 
     def getAllTransportsEnabled(self):
-        """ Returns a bool, True if the transport '*' was specified by Tor, otherwise False. """
+        """
+        Check if Tor wants the application to spawn all its transpotrs.
+
+        :returns: bool -- True if Tor wants the application to spawn all its transports.
+        """
 
         return self.allTransportsEnabled
 
     def checkTransportEnabled(self, transport):
-        """ Returns a bool, True if either the given transport or the transport '*' was specified by Tor, otherwise False. """
+        """
+        Check if Tor wants the application to spawn a specific transport.
+
+        :param string transport: The name of a pluggable transport.
+
+        :returns: bool -- True if Tor wants the application to spawn that transport.
+        """
 
         return self.allTransportsEnabled or transport in self.transports
 
     def writeEnvError(self, message):  # ENV-ERROR
         """
-            Write a message to stdout specifying that an error parsing the environment variables has occurred
-            Takes: str
+        Announce that an error occured while parsing the environment.
+
+        :param str message: Error message.
         """
 
         self.emit('ENV-ERROR %s' % message)
 
     def writeVersion(self, version):  # VERSION
         """
-            Write a message to stdout specifying that the specified configuration protocol version is supported
-            Takes: str
+        Announce that a specific managed-proxy protocol version is supported.
+
+        :param str version: A managed-proxy protocol version.
         """
 
         self.emit('VERSION %s' % version)
 
     def writeVersionError(self):  # VERSION-ERROR
         """
-            Write a message to stdout specifying that none of the specified configuration protocol versions are supported
+        Announce that we could not find a supported managed-proxy
+        protocol version.
         """
 
         self.emit('VERSION-ERROR no-version')
 
- # Private methods
-
     def check(self, key):
-        """ Returns True if the specified environment variable is set, otherwise returns False. """
+        """
+        Check the environment for a specific environment variable.
+
+        :param str key: Environment variable key.
+
+        :returns: bool -- True if the environment variable is set.
+        """
 
         return key in os.environ
 
     def get(self, key):
         """
-        Attempts to fetch the given key from the environment
-        variables. If it is present, it is returned, otherwise an
-        EnvError is thrown.
+        Get the value of an environment variable.
+
+        :param str key: Environment variable key.
+
+        :returns: str -- The value of the envrionment variable.
+
+        :raises: :class:`pyptlib.config.EnvError` if environment
+        variable could not be found.
         """
 
         if key in os.environ:
@@ -113,12 +139,16 @@ class Config:
             raise EnvError(message)
 
     def emit(self, msg):
+        """
+        Announce a message.
+
+        :param str msg: A message.
+        """
+
         print msg
         sys.stdout.flush()
 
-
 """
-Exception thrown when there is an error parsing managed proxy
-environment variables. Also sends an ENV-ERROR to Tor.
+Exception thrown when the environment is incomplete or corrupted.
 """
 class EnvError(Exception): pass
diff --git a/pyptlib/server.py b/pyptlib/server.py
index 900667e..3ccfb6f 100644
--- a/pyptlib/server.py
+++ b/pyptlib/server.py
@@ -1,7 +1,9 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-""" The pyptlib.easy.server module includes a convenient API for writing pluggable transport servers. """
+"""
+Public server-side pyptlib API.
+"""
 
 from pyptlib.config import EnvError
 from pyptlib.server_config import ServerConfig
@@ -9,30 +11,24 @@ from pyptlib.server_config import ServerConfig
 
 def init(supported_transports):
     """
-    Initialize the pluggable transport by parsing the environment
-    variables and generating output to report any errors.  The
-    given transports are checked against the transports enabled by
-    Tor and a dictionary containing information for the managed
-    proxy is returned.
+    Bootstrap server-side managed-proxy mode.
 
-    The dictionary contains the following keys and values:
+    *Call in the beginning of your application.*
 
-    'state_loc' : Directory where the managed proxy should dump its
-    state files (if needed).
+    :param list supported_transports: Names of the transports that the application supports.
 
-    'orport' : [<addr>, <port>] tuple containing the address and port
-    of Tor's ORPort.
+    :returns: dictionary that contains information for the application:
 
-    'ext_orport' : [<addr>, <port>] tuple containing the address and
-    port of Tor's Extended ORPort, or None if the Extended ORPort it's
-    not supported.
+	    ==========  ========== ==========
+	    Key         Type       Value
+	    ==========  ========== ==========
+	    state_loc   string     Directory where the managed proxy should dump its state files (if needed).
+	    orport      tuple      (ip,port) tuple pointing to Tor's ORPort.
+	    ext_orport  tuple      (ip,port) tuple pointing to Tor's Extended ORPort. None if Extended ORPort is not supported.
+	    transports  dict       A dictionary 'transport => (ip,port)' where 'transport' is the name of the transport that should be spawned, and '(ip,port)' is the location where the transport should bind. The dictionary can be empty.
+	    ==========  ========== ==========
 
-    'transports' : A dictionary {<transport> : [<addr>, <port>]},
-    where <transport> is the name of the transport that must be
-    spawned, and [<addr>, <port>] is a list containing the location
-    where that transport should bind. The dictionary can be empty.
-
-    Throws EnvError.
+    :raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
     """
 
     supportedTransportVersion = '1'
@@ -50,49 +46,33 @@ def init(supported_transports):
     retval['state_loc'] = config.getStateLocation()
     retval['orport'] = config.getORPort()
     retval['ext_orport'] = config.getExtendedORPort()
-    retval['transports'] = getTransportsDict(supported_transports, config)
+    retval['transports'] = _getTransportsDict(supported_transports, config)
 
     return retval
 
-def getTransportsDict(supported_transports, config):
-    """
-    Given the transport names that the managed proxy support in
-    'transports', and Tor's configuration in 'config', figure out
-    which transports Tor wants us to spawn and create the appropriate
-    dictionary.
+def reportSuccess(name, addrport, options):
     """
-    transports = {}
-
-    if config.getAllTransportsEnabled():
-        return config.getServerBindAddresses()
-
-    for transport in config.getServerTransports():
-        if transport in supported_transports:
-            assert(transport in config.getServerBindAddresses())
-            transports[transport] = config.getServerBindAddresses()[transport]
-        else:
-            # Issue SMETHOD-ERROR when Tor asks us to spawn a
-            # transport that we do not support.
-            config.writeMethodError(transport, "not supported")
+    Report that a server transport was launched succesfully.
 
-    return transports
+    *Always call after successfully launching a transport.*
 
-def reportSuccess(name, address, options):
-    """
-        This method should be called to report when a transport has been successfully launched.
-        It generates output to Tor informing that the transport launched successfully and can be used.
-        After all transports have been launched, the server should call reportEnd().
+    :param str name: Name of transport.
+    :param tuple addrport: (addr,port) where this transport is listening for connections.
+    :param str options: Transport options.
     """
 
     config = ServerConfig()
-    config.writeMethod(name, address, options)
+    config.writeMethod(name, addrport, options)
 
 
 def reportFailure(name, message):
     """
-        This method should be called to report when a transport has failed to launch.
-        It generates output to Tor informing that the transport failed to launch and cannot be used.
-        After all transports have been launched, the server should call reportEnd().
+    Report that a server transport failed to launch.
+
+    *Always call after failing to launch a transport.*
+
+    :param str name: Name of transport.
+    :param str message: Error message.
     """
 
     config = ServerConfig()
@@ -101,9 +81,37 @@ def reportFailure(name, message):
 
 def reportEnd():
     """
-        This method should be called after all transports have been launched.
-        It generates output to Tor informing that all transports have been launched.
+    Report that we are done launching transports.
+
+    *Call after you have launched all the transports you could launch.*
     """
 
     config = ServerConfig()
     config.writeMethodEnd()
+
+def _getTransportsDict(supported_transports, config):
+    """
+    Figure out which transports the application should launch, based on
+    the transports it supports and on the transports that Tor wants it
+    to spawn.
+
+    :param list supported_transports: Transports that the application supports.
+    :param :class:`pyptlib.client_config.ClientConfig` config: Configuration of Tor.
+
+    :returns: A dictionary of 'transport => bind address' of transports that the application should launch.
+    """
+    transports = {}
+
+    if config.getAllTransportsEnabled():
+        return config.getServerBindAddresses()
+
+    for transport in config.getServerTransports():
+        if transport in supported_transports:
+            assert(transport in config.getServerBindAddresses())
+            transports[transport] = config.getServerBindAddresses()[transport]
+        else:
+            # Issue SMETHOD-ERROR when Tor asks us to spawn a
+            # transport that we do not support.
+            config.writeMethodError(transport, "not supported")
+
+    return transports
diff --git a/pyptlib/server_config.py b/pyptlib/server_config.py
index c56e127..233f987 100644
--- a/pyptlib/server_config.py
+++ b/pyptlib/server_config.py
@@ -2,35 +2,22 @@
 # -*- coding: utf-8 -*-
 
 """
-This module contains parts of the API that are only useful to servers.
+Low-level parts of pyptlib that are only useful to servers.
 """
 
 import pyptlib.config as config
 
 class ServerConfig(config.Config):
     """
-    Attributes:
+    A client-side pyptlib configuration.
 
-    self.transports: List with strings of pluggable transport names
-    that Tor wants us to handle.
+    :var tuple ORPort: (ip,port) pointing to Tor's ORPort.
+    :var tuple extendedORPort: (ip,port) pointing to Tor's Extended ORPort. None if Extended ORPort is not supported.
+    :var dict serverBindAddr: A dictionary {<transport> : [<addr>, <port>]}, where <transport> is the name of the transport that must be spawned, and [<addr>, <port>] is a list containing the location where that transport should bind. The dictionary can be empty.
 
-    self.allTransportsEnabled: True if Tor wants us to spawn all the
-    transports.
-
-    self.extendedORPort: '(<ip>,<port>)' tuple pointing to Tor's
-    Extended ORPort. 'None' if Extended ORPort is not supported.
-
-    self.serverBindAddr: A dictionary {<transport> : [<addr>, <port>]},
-    where <transport> is the name of the transport that must be
-    spawned, and [<addr>, <port>] is a list containing the location
-    where that transport should bind. The dictionary can be empty.
+    :raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
     """
     def __init__(self):
-        """
-        Initializer.
-        Throws EnvError.
-        """
-
         config.Config.__init__(self)
 
         """
@@ -65,59 +52,88 @@ class ServerConfig(config.Config):
             raise config.EnvError("Can't match transports with bind addresses (%s, %s)" % (self.transports, self.serverBindAddr.keys()))
 
     def getExtendedORPort(self):
+        """
+        :returns: :attr:`pyptlib.server_config.ServerConfig.extendedORPort`
+        """
         return self.extendedORPort
 
     def getORPort(self):
+        """
+        :returns: :attr:`pyptlib.server_config.ServerConfig.ORPort`
+        """
         return self.ORPort
 
     def getServerBindAddresses(self):
+        """
+        :returns: :attr:`pyptlib.server_config.ServerConfig.serverBindAddr`
+        """
         return self.serverBindAddr
 
     def getServerTransports(self):
+        """
+        :returns: :attr:`pyptlib.config.Config.transports`
+        """
         return self.transports
 
-    def writeMethod(self, name, address, options):
+    def writeMethod(self, name, addrport, options):
         """
-        Write a message to stdout specifying a supported transport
-        Takes: str, (str, int), MethodOptions
+        Write a message to stdout announcing that a server transport was
+        successfully launched.
+
+        :param str name: Name of transport.
+        :param tuple addrport: (addr,port) where this transport is listening for connections.
+        :param str options: Transport options.
         """
 
         if options:
-            self.emit('SMETHOD %s %s:%s %s' % (name, address[0],
-                      address[1], options))
+            self.emit('SMETHOD %s %s:%s %s' % (name, addrport[0],
+                      addrport[1], options))
         else:
-            self.emit('SMETHOD %s %s:%s' % (name, address[0],
-                      address[1]))
+            self.emit('SMETHOD %s %s:%s' % (name, addrport[0],
+                      addrport[1]))
 
     def writeMethodError(self, name, message):  # SMETHOD-ERROR
         """
-            Write a message to stdout specifying that an error occurred setting up the specified method
-            Takes: str, str
+        Write a message to stdout announcing that we failed to launch
+        a transport.
+
+        :param str name: Name of transport.
+        :param str message: Error message.
         """
 
         self.emit('SMETHOD-ERROR %s %s' % (name, message))
 
     def writeMethodEnd(self):  # SMETHODS DONE
-        """ Write a message to stdout specifying that the list of supported transports has ended """
+        """
+        Write a message to stdout announcing that we finished
+        launching transports..
+        """
 
         self.emit('SMETHODS DONE')
 
     def get_addrport(self, key):
         """
-        Given an environment variable name in 'key' with an
-        '<addr>:<port>' value, return [<addr>,<port>].
+        Parse an environment variable holding an address:port value.
+
+        :param str key: Environment variable key.
 
-        Throws EnvError.
+        :returns: tuple -- (address,port)
+
+        :raises: :class:`pyptlib.config.EnvError` if string was not in address:port format.
         """
+
         string = self.get(key)
         return self.get_addrport_from_string(string)
 
     def get_addrport_from_string(self, string):
         """
-        Given a string in 'string' with an '<addr>:<port>' value,
-        return [<addr>,<port>].
+        Parse a string holding an address:port value.
 
-        Throws EnvError.
+        :param str string: A string.
+
+        :returns: tuple -- (address,port)
+
+        :raises: :class:`pyptlib.config.EnvError` if string was not in address:port format.
         """
 
         addrport = string.split(':')
@@ -125,7 +141,7 @@ class ServerConfig(config.Config):
         if (len(addrport) != 2) or (not addrport[1].isdigit()):
             message = 'Parsing error (%s).' % (string)
             self.writeEnvError(message)
-            raise config.EnvError(message)
+            raise config.EnvError(message) # XXX maybe return ValueError
 
         if (not 0 <= int(addrport[1]) < 65536):
             message = 'Port out of range (%s).' % (string)
@@ -134,60 +150,3 @@ class ServerConfig(config.Config):
 
         return addrport
 
-class MethodOptions:
-
-    """ The MethodOptions class represents the method options: FORWARD, ARGS, DECLARE, and USE-EXTENDED-PORT. """
-
-    forward = False  # FORWARD
-    args = {}  # ARGS
-    declare = {}  # DECLARE
-    useExtendedPort = False  # USE-EXTENDED-PORT
-
-  # Public methods
-
-    def setForward(self):
-        """ Sets forward to True """
-
-        self.forward = True
-
-    def addArg(self, key, value):
-        """ Adds a key-value pair to args """
-
-        self.args[key] = value
-
-    def addDeclare(self, key, value):
-        """ Adds a key-value pair to declare """
-
-        self.declare[key] = value
-
-    def setUserExtendedPort(self):
-        """ Sets useExtendedPort to True """
-
-        self.useExtendedPort = True
-
-    def __str__(self):
-        """ Returns a string representation of the method options. """
-
-        options = []
-        if self.forward:
-            options.append('FORWARD:1')
-        if len(self.args) > 0:
-            argstr = 'ARGS:'
-            for key in self.args:
-                value = self.args[key]
-                argstr = argstr + key + '=' + value + ','
-            argstr = argstr[:-1]  # Remove trailing comma
-            options.append(argstr)
-        if len(self.declare) > 0:
-            decs = 'DECLARE:'
-            for key in self.declare:
-                value = self.declare[key]
-                decs = decs + key + '=' + value + ','
-            decs = decs[:-1]  # Remove trailing comma
-            options.append(decs)
-        if self.useExtendedPort:
-            options.append('USE-EXTENDED-PORT:1')
-
-        return ' '.join(options)
-
-
diff --git a/pyptlib/util.py b/pyptlib/util.py
index 2d4c064..9b75786 100644
--- a/pyptlib/util.py
+++ b/pyptlib/util.py
@@ -1,14 +1,18 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
-""" The pyptlib.util module contains useful functions that don't fit in anywhere else. """
+"""
+Utility functions.
+"""
 
 from pyptlib.config import Config, EnvError
 
+def checkClientMode(): # XXX WTF!???! This also exists in config.py.
+    """
+    Check whether Tor wants us to run as a client or as a server.
 
-def checkClientMode():
-    """ Checks to see if the daemon has been launched in client mode or server mode. Returns True if it is in client mode, otherwise False. """
-
+    :returns: bool -- True if Tor wants us to run as a client.
+    """
     try:
         c = Config()
         return c.checkClientMode()

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