[Pkg-privacy-commits] [pyptlib] 104/136: Rename environment parsing functions to get_* instead of validate_*.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 13:25:16 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 d5d2fd3e9d4ddcaf480e6db4b7705a63342860c0
Author: George Kadianakis <desnacked at riseup.net>
Date: Sun Sep 8 18:11:04 2013 +0300
Rename environment parsing functions to get_* instead of validate_*.
They actually parse and return values; they don't just validate.
---
pyptlib/server_config.py | 22 +++++++++++-----------
pyptlib/test/test_server.py | 12 ++++++------
2 files changed, 17 insertions(+), 17 deletions(-)
diff --git a/pyptlib/server_config.py b/pyptlib/server_config.py
index 5f66f4a..4b017a2 100644
--- a/pyptlib/server_config.py
+++ b/pyptlib/server_config.py
@@ -10,7 +10,7 @@ import pyptlib.util as util
from pyptlib.config import env_has_k, get_env, SUPPORTED_TRANSPORT_VERSIONS
-def validate_transport_options(string):
+def get_transport_options_impl(string):
"""
Parse transport options.
:param str optstring: Example input: 'scramblesuit:k=v;scramblesuit:k2=v2;obs3fs:k=v'
@@ -69,20 +69,20 @@ class ServerConfig(config.Config):
# Check that either both Extended ORPort and the Extended
# ORPort Authentication Cookie are present, or neither.
if extendedORPort:
- def validate_authcookie(_, v):
+ def get_authcookie(_, v):
if v is None: raise ValueError("Extended ORPort address provided, but no cookie file.")
return v
else:
- def validate_authcookie(_, v):
+ def get_authcookie(_, v):
if v is not None: raise ValueError("Extended ORPort Authentication cookie file provided, but no Extended ORPort address.")
return v
- authCookieFile = get_env('TOR_PT_AUTH_COOKIE_FILE', validate_authcookie)
+ authCookieFile = get_env('TOR_PT_AUTH_COOKIE_FILE', get_authcookie)
# Get ORPort.
ORPort = get_env('TOR_PT_ORPORT', empty_or_valid_addr)
# Get bind addresses.
- def validate_server_bindaddr(k, bindaddrs):
+ def get_server_bindaddr(k, bindaddrs):
serverBindAddr = {}
bindaddrs = env_has_k(k, bindaddrs).split(',')
for bindaddr in bindaddrs:
@@ -90,24 +90,24 @@ class ServerConfig(config.Config):
(addr, port) = util.parse_addr_spec(addrport)
serverBindAddr[transport_name] = (addr, port)
return serverBindAddr
- serverBindAddr = get_env('TOR_PT_SERVER_BINDADDR', validate_server_bindaddr)
+ serverBindAddr = get_env('TOR_PT_SERVER_BINDADDR', get_server_bindaddr)
# Get transports.
- def validate_transports(k, transports):
+ def get_transports(k, transports):
transports = env_has_k(k, transports).split(',')
t = sorted(transports)
b = sorted(serverBindAddr.keys())
if t != b:
raise ValueError("Can't match transports with bind addresses (%s, %s)" % (t, b))
return transports
- transports = get_env('TOR_PT_SERVER_TRANSPORTS', validate_transports)
+ transports = get_env('TOR_PT_SERVER_TRANSPORTS', get_transports)
- def validate_transport_options(k, v):
+ def get_transport_options(k, v):
if v is None:
return None
serverTransportOptions = env_has_k(k, v)
- return validate_transport_options(serverTransportOptions)
- transport_options = get_env('TOR_PT_SERVER_TRANSPORT_OPTIONS', validate_transport_options)
+ return get_transport_options_impl(serverTransportOptions)
+ transport_options = get_env('TOR_PT_SERVER_TRANSPORT_OPTIONS', get_transport_options)
return cls(
stateLocation = get_env('TOR_PT_STATE_LOCATION'),
diff --git a/pyptlib/test/test_server.py b/pyptlib/test/test_server.py
index 3e9b217..fbb15cd 100644
--- a/pyptlib/test/test_server.py
+++ b/pyptlib/test/test_server.py
@@ -144,21 +144,21 @@ class testServer(PluginCoreTestMixin, unittest.TestCase):
self.assertOutputLinesStartWith("VERSION ")
class testUtils(unittest.TestCase):
- def test_validate_transport_options_wrong(self):
+ def test_get_transport_options_wrong(self):
"""Invalid options string"""
to_parse = "trebuchet_secret=nou"
- self.assertRaises(ValueError, validate_transport_options, to_parse)
+ self.assertRaises(ValueError, get_transport_options_impl, to_parse)
- def test_validate_transport_options_wrong_2(self):
+ def test_get_transport_options_wrong_2(self):
"""No k=v value"""
to_parse = "trebuchet:secret~nou"
- self.assertRaises(ValueError, validate_transport_options, to_parse)
+ self.assertRaises(ValueError, get_transport_options_impl, to_parse)
- def test_validate_transport_options_correct(self):
+ def test_get_transport_options_correct(self):
to_parse = "trebuchet:secret=nou;trebuchet:cache=/tmp/cache;ballista:secret=yes;ballista:fun=no;archer:bow=yes"
expected = {"trebuchet" : {"secret" : "nou", "cache" : "/tmp/cache"} , "ballista" : {"secret" : "yes", "fun" : "no"}, "archer" : {"bow" : "yes" } }
- result = validate_transport_options(to_parse)
+ result = get_transport_options_impl(to_parse)
self.assertEquals(result, expected) # XXX does this check iteratables?
if __name__ == '__main__':
--
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