[Pkg-privacy-commits] [pyptlib] 88/136: move getEnv away from being an unnecessary classmethod
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:13 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 60667b35a25dad6773e7c8d4599bc33430940cb0
Author: Ximin Luo <infinity0 at gmx.com>
Date: Mon Aug 19 18:29:08 2013 +0100
move getEnv away from being an unnecessary classmethod
---
pyptlib/client_config.py | 8 ++++----
pyptlib/config.py | 35 +++++++++++++++++------------------
pyptlib/server_config.py | 16 ++++++++--------
3 files changed, 29 insertions(+), 30 deletions(-)
diff --git a/pyptlib/client_config.py b/pyptlib/client_config.py
index dcc0636..003f24e 100644
--- a/pyptlib/client_config.py
+++ b/pyptlib/client_config.py
@@ -7,7 +7,7 @@ Low-level parts of pyptlib that are only useful to clients.
import sys
-from pyptlib.config import Config
+from pyptlib.config import Config, get_env
class ClientConfig(Config):
"""
@@ -22,7 +22,7 @@ class ClientConfig(Config):
:raises: :class:`pyptlib.config.EnvError` if environment was incomplete or corrupted.
"""
return cls(
- stateLocation = cls.getEnv('TOR_PT_STATE_LOCATION'),
- managedTransportVer = cls.getEnv('TOR_PT_MANAGED_TRANSPORT_VER').split(','),
- transports = cls.getEnv('TOR_PT_CLIENT_TRANSPORTS').split(','),
+ stateLocation = get_env('TOR_PT_STATE_LOCATION'),
+ managedTransportVer = get_env('TOR_PT_MANAGED_TRANSPORT_VER').split(','),
+ transports = get_env('TOR_PT_CLIENT_TRANSPORTS').split(','),
)
diff --git a/pyptlib/config.py b/pyptlib/config.py
index 65dca68..2247b57 100644
--- a/pyptlib/config.py
+++ b/pyptlib/config.py
@@ -65,27 +65,26 @@ class Config(object):
return self.allTransportsEnabled
- @classmethod
- def getEnv(cls, key, validate=env_has_k):
- """
- Get the value of an environment variable.
+def get_env(key, validate=env_has_k):
+ """
+ Get the value of an environment variable.
- :param str key: Environment variable key.
- :param f validate: Function that takes a var and a value and returns
- a transformed value if it is valid, or throws an exception.
- If the environment does not define var, value is None. By default,
- we return the value if the environment has the variable, otherwise
- we raise a ValueError.
+ :param str key: Environment variable key.
+ :param f validate: Function that takes a var and a value and returns
+ a transformed value if it is valid, or throws an exception.
+ If the environment does not define var, value is None. By default,
+ we return the value if the environment has the variable, otherwise
+ we raise a ValueError.
- :returns: str -- The value of the envrionment variable.
+ :returns: str -- The value of the envrionment variable.
- :raises: :class:`pyptlib.config.EnvError` if environment variable could not be
- found, or if it did not pass validation.
- """
- try:
- return validate(key, os.getenv(key))
- except Exception, e:
- raise EnvError(cause=e)
+ :raises: :class:`pyptlib.config.EnvError` if environment variable could not be
+ found, or if it did not pass validation.
+ """
+ try:
+ return validate(key, os.getenv(key))
+ except Exception, e:
+ raise EnvError(cause=e)
class EnvError(Exception):
"""
diff --git a/pyptlib/server_config.py b/pyptlib/server_config.py
index ecaa277..3e7fb86 100644
--- a/pyptlib/server_config.py
+++ b/pyptlib/server_config.py
@@ -9,7 +9,7 @@ import pyptlib.config as config
import pyptlib.util as util
import sys
-from pyptlib.config import env_has_k, env_id
+from pyptlib.config import env_has_k, env_id, get_env
class ServerConfig(config.Config):
"""
@@ -37,7 +37,7 @@ class ServerConfig(config.Config):
if v == '': return None
return util.parse_addr_spec(v)
- extendedORPort = cls.getEnv('TOR_PT_EXTENDED_SERVER_PORT', empty_or_valid_addr)
+ extendedORPort = get_env('TOR_PT_EXTENDED_SERVER_PORT', empty_or_valid_addr)
# Check that either both Extended ORPort and the Extended
# ORPort Authentication Cookie are present, or neither.
@@ -49,10 +49,10 @@ class ServerConfig(config.Config):
def validate_authcookie(k, v):
if v is not None: raise ValueError("Extended ORPort Authentication cookie file provided, but no Extended ORPort address.")
return v
- authCookieFile = cls.getEnv('TOR_PT_AUTH_COOKIE_FILE', validate_authcookie)
+ authCookieFile = get_env('TOR_PT_AUTH_COOKIE_FILE', validate_authcookie)
# Get ORPort.
- ORPort = cls.getEnv('TOR_PT_ORPORT', empty_or_valid_addr)
+ ORPort = get_env('TOR_PT_ORPORT', empty_or_valid_addr)
# Get bind addresses.
def validate_server_bindaddr(k, bindaddrs):
@@ -63,7 +63,7 @@ class ServerConfig(config.Config):
(addr, port) = util.parse_addr_spec(addrport)
serverBindAddr[transport_name] = (addr, port)
return serverBindAddr
- serverBindAddr = cls.getEnv('TOR_PT_SERVER_BINDADDR', validate_server_bindaddr)
+ serverBindAddr = get_env('TOR_PT_SERVER_BINDADDR', validate_server_bindaddr)
# Get transports.
def validate_transports(k, transports):
@@ -73,11 +73,11 @@ class ServerConfig(config.Config):
if t != b:
raise ValueError("Can't match transports with bind addresses (%s, %s)" % (t, b))
return transports
- transports = cls.getEnv('TOR_PT_SERVER_TRANSPORTS', validate_transports)
+ transports = get_env('TOR_PT_SERVER_TRANSPORTS', validate_transports)
return cls(
- stateLocation = cls.getEnv('TOR_PT_STATE_LOCATION'),
- managedTransportVer = cls.getEnv('TOR_PT_MANAGED_TRANSPORT_VER').split(','),
+ stateLocation = get_env('TOR_PT_STATE_LOCATION'),
+ managedTransportVer = get_env('TOR_PT_MANAGED_TRANSPORT_VER').split(','),
transports = transports,
serverBindAddr = serverBindAddr,
ORPort = ORPort,
--
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