tor-commits
Threads by month
- ----- 2025 -----
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
January 2013
- 19 participants
- 1125 discussions

07 Jan '13
commit 1af5594eda89aa0008f20d3c63f6447b0a4e44bf
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sun Jan 6 21:50:32 2013 -0800
Conforming to E241 (multiple spaces after ':')
---
stem/response/__init__.py | 4 ++--
stem/util/log.py | 10 +++++-----
test/check_whitespace.py | 2 +-
test/integ/descriptor/networkstatus.py | 15 ++++++++++++---
4 files changed, 20 insertions(+), 11 deletions(-)
diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index 968fa8d..b838bd7 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -50,8 +50,8 @@ KEY_ARG = re.compile("^(\S+)=")
# - logged messages about bugs
# - the 'getinfo_helper_listeners' function of control.c
-CONTROL_ESCAPES = {r"\\": "\\", r"\"": "\"", r"\'": "'",
- r"\r": "\r", r"\n": "\n", r"\t": "\t"}
+CONTROL_ESCAPES = {r"\\": "\\", r"\"": "\"", r"\'": "'",
+ r"\r": "\r", r"\n": "\n", r"\t": "\t"}
def convert(response_type, message, **kwargs):
"""
diff --git a/stem/util/log.py b/stem/util/log.py
index 0def83b..88b4bd6 100644
--- a/stem/util/log.py
+++ b/stem/util/log.py
@@ -146,12 +146,12 @@ def log_once(message_id, runlevel, message):
log(runlevel, message)
# shorter aliases for logging at a runlevel
-def trace(message): log(Runlevel.TRACE, message)
-def debug(message): log(Runlevel.DEBUG, message)
-def info(message): log(Runlevel.INFO, message)
+def trace(message): log(Runlevel.TRACE, message)
+def debug(message): log(Runlevel.DEBUG, message)
+def info(message): log(Runlevel.INFO, message)
def notice(message): log(Runlevel.NOTICE, message)
-def warn(message): log(Runlevel.WARN, message)
-def error(message): log(Runlevel.ERROR, message)
+def warn(message): log(Runlevel.WARN, message)
+def error(message): log(Runlevel.ERROR, message)
class LogBuffer(logging.Handler):
"""
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index 8419762..a91cf13 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -47,7 +47,7 @@ def pep8_issues(base_path = DEFAULT_TARGET):
# We're gonna trim these down by cateogry but include the pep8 checks to
# prevent regression.
- ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E261,W391,E127,E241"
+ ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E261,W391,E127"
issues = {}
pep8_output = system.call("pep8 --ignore %s %s" % (ignored_issues, base_path))
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py
index 2e179ec..e9bfd69 100644
--- a/test/integ/descriptor/networkstatus.py
+++ b/test/integ/descriptor/networkstatus.py
@@ -126,9 +126,18 @@ class TestNetworkStatus(unittest.TestCase):
# the document's expected client and server versions are the same
expected_versions = [stem.version.Version(v) for v in (
- "0.2.2.35", "0.2.2.36", "0.2.2.37", "0.2.3.10-alpha",
- "0.2.3.11-alpha", "0.2.3.12-alpha", "0.2.3.13-alpha", "0.2.3.14-alpha",
- "0.2.3.15-alpha", "0.2.3.16-alpha", "0.2.3.17-beta", "0.2.3.18-rc",
+ "0.2.2.35",
+ "0.2.2.36",
+ "0.2.2.37",
+ "0.2.3.10-alpha",
+ "0.2.3.11-alpha",
+ "0.2.3.12-alpha",
+ "0.2.3.13-alpha",
+ "0.2.3.14-alpha",
+ "0.2.3.15-alpha",
+ "0.2.3.16-alpha",
+ "0.2.3.17-beta",
+ "0.2.3.18-rc",
"0.2.3.19-rc",
)]
1
0

[stem/master] Conforming to E128 (continuation line under-indented for visual indent)
by atagar@torproject.org 07 Jan '13
by atagar@torproject.org 07 Jan '13
07 Jan '13
commit 9e45887a491b6b1938303bc3077d00673fca119a
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sun Jan 6 20:40:51 2013 -0800
Conforming to E128 (continuation line under-indented for visual indent)
Meh.
---
stem/connection.py | 10 +++--
stem/util/connection.py | 5 +-
stem/util/proc.py | 6 ++-
test/check_whitespace.py | 2 +-
test/integ/descriptor/networkstatus.py | 10 +++--
test/unit/connection/authentication.py | 10 +++--
test/unit/control/controller.py | 27 +++++++++----
test/unit/descriptor/networkstatus/document_v3.py | 6 ++-
test/unit/util/conf.py | 42 +++++++++++++-------
9 files changed, 76 insertions(+), 42 deletions(-)
diff --git a/stem/connection.py b/stem/connection.py
index e4760ef..ee8f852 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -678,15 +678,17 @@ def authenticate_safecookie(controller, cookie_path, suppress_ctl_errors = True)
if not suppress_ctl_errors: raise exc
else: raise AuthChallengeFailed("Unable to parse AUTHCHALLENGE response: %s" % exc, cookie_path)
- expected_server_hash = stem.util.connection.hmac_sha256(SERVER_HASH_CONSTANT,
- cookie_data + client_nonce + authchallenge_response.server_nonce)
+ expected_server_hash = stem.util.connection.hmac_sha256(
+ SERVER_HASH_CONSTANT,
+ cookie_data + client_nonce + authchallenge_response.server_nonce)
if not stem.util.connection.cryptovariables_equal(authchallenge_response.server_hash, expected_server_hash):
raise AuthSecurityFailure("Tor provided the wrong server nonce", cookie_path)
try:
- client_hash = stem.util.connection.hmac_sha256(CLIENT_HASH_CONSTANT,
- cookie_data + client_nonce + authchallenge_response.server_nonce)
+ client_hash = stem.util.connection.hmac_sha256(
+ CLIENT_HASH_CONSTANT,
+ cookie_data + client_nonce + authchallenge_response.server_nonce)
auth_response = _msg(controller, "AUTHENTICATE %s" % (binascii.b2a_hex(client_hash)))
except stem.ControllerError, exc:
try: controller.connect()
diff --git a/stem/util/connection.py b/stem/util/connection.py
index c325bd9..91614b7 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -278,6 +278,7 @@ def cryptovariables_equal(x, y):
:returns: **True** if both strings are equal, **False** otherwise.
"""
- return (hmac_sha256(CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE, x) ==
- hmac_sha256(CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE, y))
+ return (
+ hmac_sha256(CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE, x) ==
+ hmac_sha256(CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE, y))
diff --git a/stem/util/proc.py b/stem/util/proc.py
index fd019cb..56b2928 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -55,8 +55,10 @@ CLOCK_TICKS = None
try: CLOCK_TICKS = os.sysconf(os.sysconf_names["SC_CLK_TCK"])
except AttributeError: pass
-Stat = stem.util.enum.Enum(("COMMAND", "command"), ("CPU_UTIME", "utime"),
- ("CPU_STIME", "stime"), ("START_TIME", "start time"))
+Stat = stem.util.enum.Enum(
+ ("COMMAND", "command"), ("CPU_UTIME", "utime"),
+ ("CPU_STIME", "stime"), ("START_TIME", "start time")
+)
def is_available():
"""
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index 0671d65..8419762 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -47,7 +47,7 @@ def pep8_issues(base_path = DEFAULT_TARGET):
# We're gonna trim these down by cateogry but include the pep8 checks to
# prevent regression.
- ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E261,W391,E127,E241,E128"
+ ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E261,W391,E127,E241"
issues = {}
pep8_output = system.call("pep8 --ignore %s %s" % (ignored_issues, base_path))
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py
index aa20169..2e179ec 100644
--- a/test/integ/descriptor/networkstatus.py
+++ b/test/integ/descriptor/networkstatus.py
@@ -132,8 +132,9 @@ class TestNetworkStatus(unittest.TestCase):
"0.2.3.19-rc",
)]
- expected_flags = set(["Authority", "BadExit", "Exit", "Fast", "Guard", "HSDir",
- "Named", "Running", "Stable", "Unnamed", "V2Dir", "Valid"])
+ expected_flags = set(
+ ["Authority", "BadExit", "Exit", "Fast", "Guard", "HSDir",
+ "Named", "Running", "Stable", "Unnamed", "V2Dir", "Valid"])
expected_bandwidth_weights = {
"Wbd": 3335, "Wbe": 0, "Wbg": 3536, "Wbm": 10000, "Wdb": 10000,
@@ -305,8 +306,9 @@ TpQQk3nNQF8z6UIvdlvP+DnJV4izWVkQEZgUZgIVM0E=
Checks that vote documents are properly parsed.
"""
- expected_flags = set(["Authority", "BadExit", "Exit", "Fast", "Guard", "HSDir",
- "Running", "Stable", "V2Dir", "Valid"])
+ expected_flags = set(
+ ["Authority", "BadExit", "Exit", "Fast", "Guard", "HSDir",
+ "Running", "Stable", "V2Dir", "Valid"])
expected_identity_key = """-----BEGIN RSA PUBLIC KEY-----
MIIBigKCAYEA6uSmsoxj2MiJ3qyZq0qYXlRoG8o82SNqg+22m+t1c7MlQOZWPJYn
diff --git a/test/unit/connection/authentication.py b/test/unit/connection/authentication.py
index fa4aba4..abc4af8 100644
--- a/test/unit/connection/authentication.py
+++ b/test/unit/connection/authentication.py
@@ -62,14 +62,16 @@ class TestAuthenticate(unittest.TestCase):
stem_logger.setLevel(log.logging_level(None))
# exceptions that the authentication functions are documented to raise
- all_auth_none_exc = (None,
- stem.connection.OpenAuthRejected(None))
- all_auth_password_exc = (None,
+ all_auth_none_exc = (None, stem.connection.OpenAuthRejected(None))
+
+ all_auth_password_exc = (
+ None,
stem.connection.PasswordAuthRejected(None),
stem.connection.IncorrectPassword(None))
- all_auth_cookie_exc = (None,
+ all_auth_cookie_exc = (
+ None,
stem.connection.IncorrectCookieSize(None, False, None),
stem.connection.UnreadableCookieFile(None, False, None),
stem.connection.CookieAuthRejected(None, False, None),
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index 624de39..c669870 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -53,8 +53,10 @@ class TestControl(unittest.TestCase):
mocking.mock_method(Controller, "get_info", mocking.raise_exception(InvalidArguments))
# Get a default value when the call fails.
- self.assertEqual("default returned",
- self.controller.get_version(default = "default returned"))
+ self.assertEqual(
+ "default returned",
+ self.controller.get_version(default = "default returned")
+ )
# No default value, accept the error.
self.assertRaises(InvalidArguments, self.controller.get_version)
@@ -138,8 +140,11 @@ class TestControl(unittest.TestCase):
mocking.mock_method(Controller, "get_info", mocking.return_value(
'"127.0.0.1:1112" "127.0.0.1:1114"'
))
- self.assertEqual([('127.0.0.1', 1112), ('127.0.0.1', 1114)],
- self.controller.get_socks_listeners())
+
+ self.assertEqual(
+ [('127.0.0.1', 1112), ('127.0.0.1', 1114)],
+ self.controller.get_socks_listeners()
+ )
# no SOCKS listeners
mocking.mock_method(Controller, "get_info", mocking.return_value(""))
@@ -175,8 +180,11 @@ class TestControl(unittest.TestCase):
mocking.mock(stem.connection.get_protocolinfo, mocking.raise_exception(ProtocolError))
# Get a default value when the call fails.
- self.assertEqual("default returned",
- self.controller.get_protocolinfo(default = "default returned"))
+
+ self.assertEqual(
+ "default returned",
+ self.controller.get_protocolinfo(default = "default returned")
+ )
# No default value, accept the error.
self.assertRaises(ProtocolError, self.controller.get_protocolinfo)
@@ -210,8 +218,11 @@ class TestControl(unittest.TestCase):
mocking.mock_method(Controller, "get_info", mocking.raise_exception(InvalidArguments))
# Get a default value when the call fails.
- self.assertEqual("default returned",
- self.controller.get_network_status(nickname, default = "default returned"))
+
+ self.assertEqual(
+ "default returned",
+ self.controller.get_network_status(nickname, default = "default returned")
+ )
# No default value, accept the error.
self.assertRaises(InvalidArguments, self.controller.get_network_status, nickname)
diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py
index 009d365..6a825ea 100644
--- a/test/unit/descriptor/networkstatus/document_v3.py
+++ b/test/unit/descriptor/networkstatus/document_v3.py
@@ -41,7 +41,8 @@ class TestNetworkStatusDocument(unittest.TestCase):
document = get_network_status_document_v3()
- expected_known_flags = [Flag.AUTHORITY, Flag.BADEXIT, Flag.EXIT,
+ expected_known_flags = [
+ Flag.AUTHORITY, Flag.BADEXIT, Flag.EXIT,
Flag.FAST, Flag.GUARD, Flag.HSDIR, Flag.NAMED, Flag.RUNNING,
Flag.STABLE, Flag.UNNAMED, Flag.V2DIR, Flag.VALID]
@@ -75,7 +76,8 @@ class TestNetworkStatusDocument(unittest.TestCase):
document = get_network_status_document_v3({"vote-status": "vote"})
- expected_known_flags = [Flag.AUTHORITY, Flag.BADEXIT, Flag.EXIT,
+ expected_known_flags = [
+ Flag.AUTHORITY, Flag.BADEXIT, Flag.EXIT,
Flag.FAST, Flag.GUARD, Flag.HSDIR, Flag.NAMED, Flag.RUNNING,
Flag.STABLE, Flag.UNNAMED, Flag.V2DIR, Flag.VALID]
diff --git a/test/unit/util/conf.py b/test/unit/util/conf.py
index 8b85216..9006b54 100644
--- a/test/unit/util/conf.py
+++ b/test/unit/util/conf.py
@@ -82,25 +82,37 @@ class TestConf(unittest.TestCase):
self.assertEqual([], parse_enum_csv("my_option", "", Insects))
self.assertEqual([Insects.LADYBUG], parse_enum_csv("my_option", "ladybug", Insects))
- self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY],
- parse_enum_csv("my_option", "ladybug, butterfly", Insects))
+ self.assertEqual(
+ [Insects.LADYBUG, Insects.BUTTERFLY],
+ parse_enum_csv("my_option", "ladybug, butterfly", Insects)
+ )
- self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY, Insects.CRICKET],
- parse_enum_csv("my_option", "ladybug, butterfly, cricket", Insects))
+ self.assertEqual(
+ [Insects.LADYBUG, Insects.BUTTERFLY, Insects.CRICKET],
+ parse_enum_csv("my_option", "ladybug, butterfly, cricket", Insects)
+ )
# edge cases for count argument where things are ok
- self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY],
- parse_enum_csv("my_option", "ladybug, butterfly", Insects, 2))
-
- self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY],
- parse_enum_csv("my_option", "ladybug, butterfly", Insects, (1, 2)))
-
- self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY],
- parse_enum_csv("my_option", "ladybug, butterfly", Insects, (2, 3)))
-
- self.assertEqual([Insects.LADYBUG, Insects.BUTTERFLY],
- parse_enum_csv("my_option", "ladybug, butterfly", Insects, (2, 2)))
+ self.assertEqual(
+ [Insects.LADYBUG, Insects.BUTTERFLY],
+ parse_enum_csv("my_option", "ladybug, butterfly", Insects, 2)
+ )
+
+ self.assertEqual(
+ [Insects.LADYBUG, Insects.BUTTERFLY],
+ parse_enum_csv("my_option", "ladybug, butterfly", Insects, (1, 2))
+ )
+
+ self.assertEqual(
+ [Insects.LADYBUG, Insects.BUTTERFLY],
+ parse_enum_csv("my_option", "ladybug, butterfly", Insects, (2, 3))
+ )
+
+ self.assertEqual(
+ [Insects.LADYBUG, Insects.BUTTERFLY],
+ parse_enum_csv("my_option", "ladybug, butterfly", Insects, (2, 2))
+ )
# failure cases
1
0

[stem/master] Conforming to E226 (missing optional whitespace around operator)
by atagar@torproject.org 07 Jan '13
by atagar@torproject.org 07 Jan '13
07 Jan '13
commit b8b32e0aa751d8f2c2fbe43502b1f400871f0919
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sun Jan 6 20:29:16 2013 -0800
Conforming to E226 (missing optional whitespace around operator)
Another nice one.
---
stem/descriptor/server_descriptor.py | 4 ++--
test/check_whitespace.py | 2 +-
test/mocking.py | 6 +++---
test/unit/util/proc.py | 4 ++--
4 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index e51de8b..a1b486d 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -488,7 +488,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
else: raise ValueError("or-address line missing a colon: %s" % line)
div = entry.rfind(":")
- address, ports = entry[:div], entry[div+1:]
+ address, ports = entry[:div], entry[div + 1:]
is_ipv6 = address.startswith("[") and address.endswith("]")
if is_ipv6: address = address[1:-1] # remove brackets
@@ -715,7 +715,7 @@ class RelayDescriptor(ServerDescriptor):
except ValueError:
raise ValueError("Verification failed, seperator not found")
- digest = decrypted_bytes[seperator_index+1:]
+ digest = decrypted_bytes[seperator_index + 1:]
# The local digest is stored in uppercase hex;
# - so decode it from hex
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index b566106..0671d65 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -47,7 +47,7 @@ def pep8_issues(base_path = DEFAULT_TARGET):
# We're gonna trim these down by cateogry but include the pep8 checks to
# prevent regression.
- ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E261,W391,E127,E241,E128,E226"
+ ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E261,W391,E127,E241,E128"
issues = {}
pep8_output = system.call("pep8 --ignore %s %s" % (ignored_issues, base_path))
diff --git a/test/mocking.py b/test/mocking.py
index ef4a209..99f18b2 100644
--- a/test/mocking.py
+++ b/test/mocking.py
@@ -880,7 +880,7 @@ def sign_descriptor_content(desc_content):
grouped_fingerprint = ""
for x in range(0, len(key_hash), 4):
- grouped_fingerprint += " " + key_hash[x:x+4]
+ grouped_fingerprint += " " + key_hash[x:x + 4]
fingerprint_token = "\nfingerprint"
new_fp = fingerprint_token + grouped_fingerprint
@@ -894,8 +894,8 @@ def sign_descriptor_content(desc_content):
# if the descriptor does not already contain a fingerprint do not add one
if ft_start >= 0:
- ft_end = desc_content.find("\n", ft_start+1)
- desc_content = desc_content[:ft_start]+new_fp+desc_content[ft_end:]
+ ft_end = desc_content.find("\n", ft_start + 1)
+ desc_content = desc_content[:ft_start] + new_fp + desc_content[ft_end:]
# create a temporary object to use to calculate the digest
diff --git a/test/unit/util/proc.py b/test/unit/util/proc.py
index 3cad349..13942b4 100644
--- a/test/unit/util/proc.py
+++ b/test/unit/util/proc.py
@@ -33,7 +33,7 @@ class TestProc(unittest.TestCase):
('/proc/meminfo', 'MemTotal:', 'system physical memory'): 'MemTotal: 12345 kB',
}))
- self.assertEquals((12345*1024), proc.get_physical_memory())
+ self.assertEquals((12345 * 1024), proc.get_physical_memory())
def test_get_cwd(self):
"""
@@ -70,7 +70,7 @@ class TestProc(unittest.TestCase):
}))
self.assertEqual((0, 0), proc.get_memory_usage(0))
- self.assertEqual((100*1024, 1800*1024), proc.get_memory_usage(1111))
+ self.assertEqual((100 * 1024, 1800 * 1024), proc.get_memory_usage(1111))
def test_get_stats(self):
"""
1
0

[stem/master] Skipping E251 (no spaces around keyword / parameter equals)
by atagar@torproject.org 07 Jan '13
by atagar@torproject.org 07 Jan '13
07 Jan '13
commit ed070ee78b2a3d0baed01158b669611646957d97
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sun Jan 6 22:48:59 2013 -0800
Skipping E251 (no spaces around keyword / parameter equals)
I got a little ways through switching us over to this one then stopped. It
looks aweful and makes the code less readable. If Sean and Ravi both decide
that they want this then fine - one of them can be the person to swap it over.
---
test/check_whitespace.py | 8 ++++++++
1 files changed, 8 insertions(+), 0 deletions(-)
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index ba41190..d65c5b5 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -53,6 +53,14 @@ def pep8_issues(base_path = DEFAULT_TARGET):
#
# Pep8 only works with this one if we have four space indents (its
# detection is based on multiples of four).
+ #
+ # * E251 no spaces around keyword / parameter equals
+ #
+ # This one I dislike a great deal. It makes keyword arguments different
+ # from assignments which looks... aweful. I'm not sure what PEP8's author
+ # was on when he wrote this one but it's stupid.
+ #
+ # Someone else can change this if they really care.
ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E127"
1
0

[stem/master] Skipping E127 (continuation line over-indented for visual indent)
by atagar@torproject.org 07 Jan '13
by atagar@torproject.org 07 Jan '13
07 Jan '13
commit ff92770fba42f0daa40204795b9568fb6389d7cc
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sun Jan 6 21:57:07 2013 -0800
Skipping E127 (continuation line over-indented for visual indent)
Bug with pep8 where detection only works for this if we have four space indents
(which we aren't swapping to at present).
---
test/check_whitespace.py | 7 +++++++
1 files changed, 7 insertions(+), 0 deletions(-)
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index a91cf13..61ad69c 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -47,6 +47,13 @@ def pep8_issues(base_path = DEFAULT_TARGET):
# We're gonna trim these down by cateogry but include the pep8 checks to
# prevent regression.
+ # Ignoring the following compliance issues.
+ #
+ # * E127 continuation line over-indented for visual indent
+ #
+ # Pep8 only works with this one if we have four space indents (its
+ # detection is based on multiples of four).
+
ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E261,W391,E127"
issues = {}
1
0

[stem/master] Conforming to E261 (at least two spaces before inline comment)
by atagar@torproject.org 07 Jan '13
by atagar@torproject.org 07 Jan '13
07 Jan '13
commit 23b06d380c4e2b3e0bfb0348ff03c5685e59754b
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sun Jan 6 22:37:33 2013 -0800
Conforming to E261 (at least two spaces before inline comment)
---
stem/connection.py | 2 +-
stem/control.py | 12 +++++-----
stem/descriptor/__init__.py | 6 ++--
stem/descriptor/extrainfo_descriptor.py | 14 +++++-----
stem/descriptor/networkstatus.py | 6 ++--
stem/descriptor/reader.py | 2 +-
stem/descriptor/server_descriptor.py | 12 +++++-----
stem/exit_policy.py | 4 +-
stem/process.py | 4 +-
stem/response/__init__.py | 6 ++--
stem/response/getconf.py | 2 +-
stem/socket.py | 8 +++---
stem/util/conf.py | 12 +++++-----
stem/util/connection.py | 10 ++++----
stem/util/proc.py | 4 +-
stem/util/system.py | 8 +++---
stem/version.py | 2 +-
test/check_whitespace.py | 2 +-
test/integ/control/base_controller.py | 2 +-
test/integ/control/controller.py | 2 +-
test/integ/descriptor/extrainfo_descriptor.py | 4 +-
test/integ/descriptor/networkstatus.py | 2 +-
test/integ/descriptor/reader.py | 26 ++++++++++----------
test/integ/descriptor/server_descriptor.py | 12 +++++-----
test/integ/process.py | 6 ++--
test/mocking.py | 6 ++--
test/runner.py | 2 +-
test/unit/control/controller.py | 20 ++++++++--------
test/unit/descriptor/networkstatus/document_v3.py | 10 ++++----
test/unit/descriptor/router_status_entry.py | 6 ++--
test/unit/response/control_message.py | 2 +-
test/unit/response/events.py | 2 +-
test/unit/tutorial.py | 2 +-
test/unit/util/conf.py | 2 +-
test/unit/util/str_tools.py | 4 +-
35 files changed, 113 insertions(+), 113 deletions(-)
diff --git a/stem/connection.py b/stem/connection.py
index ee8f852..737776f 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -370,7 +370,7 @@ def authenticate(controller, password = None, chroot_path = None, protocolinfo_r
else:
authenticate_cookie(controller, cookie_path, False)
- return # success!
+ return # success!
except OpenAuthRejected, exc:
auth_exceptions.append(exc)
except IncorrectPassword, exc:
diff --git a/stem/control.py b/stem/control.py
index c1f1114..fc4af05 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -226,7 +226,7 @@ class BaseController(object):
self._socket = control_socket
self._msg_lock = threading.RLock()
- self._status_listeners = [] # tuples of the form (callback, spawn_thread)
+ self._status_listeners = [] # tuples of the form (callback, spawn_thread)
self._status_listeners_lock = threading.RLock()
# queues where incoming messages are directed
@@ -249,7 +249,7 @@ class BaseController(object):
self._socket._connect = self._connect
self._socket._close = self._close
- self._last_heartbeat = 0.0 # timestamp for when we last heard from tor
+ self._last_heartbeat = 0.0 # timestamp for when we last heard from tor
if self._socket.is_alive():
self._launch_threads()
@@ -293,7 +293,7 @@ class BaseController(object):
response = self._reply_queue.get_nowait()
if isinstance(response, stem.SocketClosed):
- pass # this is fine
+ pass # this is fine
elif isinstance(response, stem.ProtocolError):
log.info("Tor provided a malformed message (%s)" % response)
elif isinstance(response, stem.ControllerError):
@@ -735,7 +735,7 @@ class Controller(BaseController):
if self.is_caching_enabled():
for key, value in response.entries.items():
- key = key.lower() # make case insensitive
+ key = key.lower() # make case insensitive
if key in CACHEABLE_GETINFO_PARAMS:
self._request_cache["getinfo.%s" % key] = value
@@ -821,7 +821,7 @@ class Controller(BaseController):
elif not ':' in listener:
raise stem.ProtocolError("'GETINFO net/listeners/socks' had a listener without a colon: %s" % listener)
- listener = listener[1:-1] # strip quotes
+ listener = listener[1:-1] # strip quotes
addr, port = listener.split(':')
proxy_addrs.append((addr, port))
except stem.InvalidArguments:
@@ -1945,7 +1945,7 @@ def _parse_circ_entry(entry):
if not stem.util.tor_tools.is_valid_fingerprint(fingerprint, True):
raise stem.ProtocolError("Fingerprint in the circuit path is malformed (%s)" % fingerprint)
- fingerprint = fingerprint[1:] # strip off the leading '$'
+ fingerprint = fingerprint[1:] # strip off the leading '$'
if nickname is not None and not stem.util.tor_tools.is_valid_nickname(nickname):
raise stem.ProtocolError("Nickname in the circuit path is malformed (%s)" % nickname)
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index ed74b1f..ed52b42 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -211,7 +211,7 @@ def _read_until_keywords(keywords, descriptor_file, inclusive = False, ignore_fi
break
line = descriptor_file.readline()
- if not line: break # EOF
+ if not line: break # EOF
line_match = KEYWORD_LINE.match(line)
@@ -252,7 +252,7 @@ def _get_pseudo_pgp_block(remaining_contents):
"""
if not remaining_contents:
- return None # nothing left
+ return None # nothing left
block_match = PGP_BLOCK_START.match(remaining_contents[0])
@@ -300,7 +300,7 @@ def _get_descriptor_components(raw_contents, validate, extra_keywords = ()):
"""
entries = OrderedDict()
- extra_entries = [] # entries with a keyword in extra_keywords
+ extra_entries = [] # entries with a keyword in extra_keywords
remaining_lines = raw_contents.split("\n")
while remaining_lines:
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 0976943..7ea457c 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -158,7 +158,7 @@ def parse_file(descriptor_file, validate = True):
if extrainfo_content:
yield RelayExtraInfoDescriptor("".join(extrainfo_content), validate)
- else: break # done parsing file
+ else: break # done parsing file
def _parse_timestamp_and_interval(keyword, content):
"""
@@ -180,7 +180,7 @@ def _parse_timestamp_and_interval(keyword, content):
raise ValueError("Malformed %s line: %s" % (keyword, line))
timestamp_str, interval, remainder = content_match.groups()
- if remainder: remainder = remainder[1:] # remove leading space
+ if remainder: remainder = remainder[1:] # remove leading space
if not interval.isdigit():
raise ValueError("%s line's interval wasn't a number: %s" % (keyword, line))
@@ -423,7 +423,7 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
for keyword, values in entries.items():
# most just work with the first (and only) value
value, _ = values[0]
- line = "%s %s" % (keyword, value) # original line
+ line = "%s %s" % (keyword, value) # original line
if keyword == "extra-info":
# "extra-info" Nickname Fingerprint
@@ -800,13 +800,13 @@ class RelayExtraInfoDescriptor(ExtraInfoDescriptor):
return self._digest
def _parse(self, entries, validate):
- entries = dict(entries) # shallow copy since we're destructive
+ entries = dict(entries) # shallow copy since we're destructive
# handles fields only in server descriptors
for keyword, values in entries.items():
value, block_contents = values[0]
- line = "%s %s" % (keyword, value) # original line
+ line = "%s %s" % (keyword, value) # original line
if block_contents: line += "\n%s" % block_contents
if keyword == "router-signature":
@@ -836,12 +836,12 @@ class BridgeExtraInfoDescriptor(ExtraInfoDescriptor):
return self._digest
def _parse(self, entries, validate):
- entries = dict(entries) # shallow copy since we're destructive
+ entries = dict(entries) # shallow copy since we're destructive
# handles fields only in server descriptors
for keyword, values in entries.items():
value, _ = values[0]
- line = "%s %s" % (keyword, value) # original line
+ line = "%s %s" % (keyword, value) # original line
if keyword == "router-digest":
if validate and not stem.util.tor_tools.is_hex_digits(value, 40):
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index 40b3257..2bdfbc4 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -310,7 +310,7 @@ class NetworkStatusDocumentV2(NetworkStatusDocument):
for keyword, values in entries.items():
value, block_contents = values[0]
- line = "%s %s" % (keyword, value) # original line
+ line = "%s %s" % (keyword, value) # original line
if block_contents: line += "\n%s" % block_contents
if keyword == "network-status-version":
@@ -729,7 +729,7 @@ class _DocumentFooter(object):
if validate and content and not header.meets_consensus_method(9):
raise ValueError("Network status document's footer should only appear in consensus-method 9 or later")
elif not content and not header.meets_consensus_method(9):
- return # footer is optional and there's nothing to parse
+ return # footer is optional and there's nothing to parse
entries = stem.descriptor._get_descriptor_components(content, validate)
self._parse(entries, validate, header)
@@ -773,7 +773,7 @@ class _DocumentFooter(object):
raise ValueError("Authority signatures in a network status document are expected to be of the form 'directory-signature [METHOD] FINGERPRINT KEY_DIGEST\\nSIGNATURE', got:\n%s\n%s" % (sig_value, block_contents))
if sig_value.count(" ") == 1:
- method = 'sha1' # default if none was provided
+ method = 'sha1' # default if none was provided
fingerprint, key_digest = sig_value.split(" ", 1)
else:
method, fingerprint, key_digest = sig_value.split(" ", 2)
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 6069bfa..d47a5ed 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -173,7 +173,7 @@ def load_processed_files(path):
for line in input_file.readlines():
line = line.strip()
- if not line: continue # skip blank lines
+ if not line: continue # skip blank lines
if not " " in line:
raise TypeError("Malformed line: %s" % line)
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index da9715d..1ea13a2 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -126,7 +126,7 @@ def parse_file(descriptor_file, validate = True):
descriptor_text = "".join(descriptor_content)
yield RelayDescriptor(descriptor_text, validate, annotations)
- else: break # done parsing descriptors
+ else: break # done parsing descriptors
class ServerDescriptor(stem.descriptor.Descriptor):
"""
@@ -242,7 +242,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
self._unrecognized_lines = []
self._annotation_lines = annotations if annotations else []
- self._annotation_dict = None # cached breakdown of key/value mappings
+ self._annotation_dict = None # cached breakdown of key/value mappings
# A descriptor contains a series of 'keyword lines' which are simply a
# keyword followed by an optional value. Lines can also be followed by a
@@ -325,7 +325,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
# most just work with the first (and only) value
value, block_contents = values[0]
- line = "%s %s" % (keyword, value) # original line
+ line = "%s %s" % (keyword, value) # original line
if block_contents: line += "\n%s" % block_contents
if keyword == "router":
@@ -490,7 +490,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
div = entry.rfind(":")
address, ports = entry[:div], entry[div + 1:]
is_ipv6 = address.startswith("[") and address.endswith("]")
- if is_ipv6: address = address[1:-1] # remove brackets
+ if is_ipv6: address = address[1:-1] # remove brackets
if not ((not is_ipv6 and stem.util.connection.is_valid_ip_address(address)) or
(is_ipv6 and stem.util.connection.is_valid_ipv6_address(address))):
@@ -669,7 +669,7 @@ class RelayDescriptor(ServerDescriptor):
seq = asn1.DerSequence()
seq.decode(key_as_der)
modulus = seq[0]
- public_exponent = seq[1] # should always be 65537
+ public_exponent = seq[1] # should always be 65537
sig_as_bytes = RelayDescriptor._get_key_bytes(self.signature)
@@ -727,7 +727,7 @@ class RelayDescriptor(ServerDescriptor):
raise ValueError("Decrypted digest does not match local digest")
def _parse(self, entries, validate):
- entries = dict(entries) # shallow copy since we're destructive
+ entries = dict(entries) # shallow copy since we're destructive
# handles fields only in server descriptors
diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index eb34e97..9b0a111 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -188,7 +188,7 @@ class ExitPolicy(object):
if display_ports:
display_ranges, temp_range = [], []
display_ports.sort()
- display_ports.append(None) # ending item to include last range in loop
+ display_ports.append(None) # ending item to include last range in loop
for port in display_ports:
if not temp_range or temp_range[-1] + 1 == port:
@@ -702,7 +702,7 @@ class MicroExitPolicyRule(ExitPolicyRule):
def __init__(self, is_accept, min_port, max_port):
self.is_accept = is_accept
- self.address = None # wildcard address
+ self.address = None # wildcard address
self.min_port = min_port
self.max_port = max_port
self._str_representation = None
diff --git a/stem/process.py b/stem/process.py
index 6698c99..4db51d3 100644
--- a/stem/process.py
+++ b/stem/process.py
@@ -126,7 +126,7 @@ def launch_tor(tor_cmd = "tor", args = None, torrc_path = None, completion_perce
# this will provide empty results if the process is terminated
if not init_line:
- if timeout: signal.alarm(0) # stop alarm
+ if timeout: signal.alarm(0) # stop alarm
# ... but best make sure
if stem.prereq.is_python_26():
@@ -144,7 +144,7 @@ def launch_tor(tor_cmd = "tor", args = None, torrc_path = None, completion_perce
problem_match = problem_line.search(init_line)
if bootstrap_match and int(bootstrap_match.groups()[0]) >= completion_percent:
- if timeout: signal.alarm(0) # stop alarm
+ if timeout: signal.alarm(0) # stop alarm
if temp_file:
try: os.remove(temp_file)
diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index 1b7387b..388d755 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -285,7 +285,7 @@ class ControlLine(str):
**False** otherwise
"""
- remainder = self._remainder # temp copy to avoid locking
+ remainder = self._remainder # temp copy to avoid locking
key_match = KEY_ARG.match(remainder)
if key_match:
@@ -297,9 +297,9 @@ class ControlLine(str):
start_quote, end_quote = _get_quote_indices(remainder, escaped)
return start_quote == key_match.end() and end_quote != -1
else:
- return True # we just needed to check for the key
+ return True # we just needed to check for the key
else:
- return False # doesn't start with a key
+ return False # doesn't start with a key
def peek_key(self):
"""
diff --git a/stem/response/getconf.py b/stem/response/getconf.py
index 6e96c83..bf16ec1 100644
--- a/stem/response/getconf.py
+++ b/stem/response/getconf.py
@@ -39,7 +39,7 @@ class GetConfResponse(stem.response.ControlMessage):
line = remaining_lines.pop(0)
if line.is_next_mapping(quoted = False):
- key, value = line.split("=", 1) # TODO: make this part of the ControlLine?
+ key, value = line.split("=", 1) # TODO: make this part of the ControlLine?
elif line.is_next_mapping(quoted = True):
# TODO: doesn't seem to occur yet in practice...
# https://trac.torproject.org/6172
diff --git a/stem/socket.py b/stem/socket.py
index 2055991..4dca361 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -183,7 +183,7 @@ class ControlSocket(object):
try:
self._connect()
except stem.SocketError:
- self._connect() # single retry
+ self._connect() # single retry
def close(self):
"""
@@ -482,7 +482,7 @@ def recv_message(control_file):
log.info(prefix + "no CRLF linebreak, \"%s\"" % log.escape(line))
raise stem.ProtocolError("All lines should end with CRLF")
- line = line[:-2] # strips off the CRLF
+ line = line[:-2] # strips off the CRLF
status_code, divider, content = line[:3], line[3], line[4:]
if divider == "-":
@@ -514,9 +514,9 @@ def recv_message(control_file):
log.info(prefix + "CRLF linebreaks missing from a data reply, \"%s\"" % log.escape(raw_content))
raise stem.ProtocolError("All lines should end with CRLF")
elif line == ".\r\n":
- break # data block termination
+ break # data block termination
- line = line[:-2] # strips off the CRLF
+ line = line[:-2] # strips off the CRLF
# lines starting with a period are escaped by a second period (as per
# section 2.4 of the control-spec)
diff --git a/stem/util/conf.py b/stem/util/conf.py
index 05d3796..0166ad9 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -169,7 +169,7 @@ class _SyncListener(object):
def update(self, config, key):
if key in self.config_dict:
new_value = config.get(key, self.config_dict[key])
- if new_value == self.config_dict[key]: return # no change
+ if new_value == self.config_dict[key]: return # no change
if self.interceptor:
interceptor_value = self.interceptor(key, new_value)
@@ -268,7 +268,7 @@ def parse_enum_csv(key, value, enumeration, count = None):
if values == ['']: return []
if count is None:
- pass # no count validateion checks to do
+ pass # no count validateion checks to do
elif isinstance(count, int):
if len(values) != count:
raise ValueError("Config entry '%s' is expected to be %i comma separated values, got '%s'" % (key, count, value))
@@ -432,8 +432,8 @@ class Config(object):
multiline_buffer = []
while remainder and remainder[0].lstrip().startswith("|"):
- content = remainder.pop(0).lstrip()[1:] # removes '\s+|' prefix
- content = content.rstrip("\n") # trailing newline
+ content = remainder.pop(0).lstrip()[1:] # removes '\s+|' prefix
+ content = content.rstrip("\n") # trailing newline
multiline_buffer.append(content)
if multiline_buffer:
@@ -588,7 +588,7 @@ class Config(object):
is_multivalue = isinstance(default, (list, tuple, dict))
val = self.get_value(key, default, is_multivalue)
- if val == default: return val # don't try to infer undefined values
+ if val == default: return val # don't try to infer undefined values
if isinstance(default, bool):
if val.lower() == "true": val = True
@@ -607,7 +607,7 @@ class Config(object):
log.debug("Config entry '%s' is expected to be a float, defaulting to '%f'" % (key, default))
val = default
elif isinstance(default, list):
- pass # nothing special to do (already a list)
+ pass # nothing special to do (already a list)
elif isinstance(default, tuple):
val = tuple(val)
elif isinstance(default, dict):
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 8eefea2..3b16c1f 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -49,7 +49,7 @@ def is_valid_ip_address(address):
if not entry.isdigit() or int(entry) < 0 or int(entry) > 255:
return False
elif entry[0] == "0" and len(entry) > 1:
- return False # leading zeros, for instance in "1.2.3.001"
+ return False # leading zeros, for instance in "1.2.3.001"
return True
@@ -74,11 +74,11 @@ def is_valid_ipv6_address(address, allow_brackets = False):
colon_count = address.count(":")
if colon_count > 7:
- return False # too many groups
+ return False # too many groups
elif colon_count != 7 and not "::" in address:
- return False # not enough groups and none are collapsed
+ return False # not enough groups and none are collapsed
elif address.count("::") > 1 or ":::" in address:
- return False # multiple groupings of zeros can't be collapsed
+ return False # multiple groupings of zeros can't be collapsed
for entry in address.split(":"):
if not re.match("^[0-9a-fA-f]{0,4}$", entry):
@@ -106,7 +106,7 @@ def is_valid_port(entry, allow_zero = False):
if not entry.isdigit():
return False
elif entry[0] == "0" and len(entry) > 1:
- return False # leading zeros, ex "001"
+ return False # leading zeros, ex "001"
entry = int(entry)
diff --git a/stem/util/proc.py b/stem/util/proc.py
index bfb771e..05a7ff0 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -317,7 +317,7 @@ def get_connections(pid):
for proc_file_path in ("/proc/net/tcp", "/proc/net/udp"):
try:
proc_file = open(proc_file_path)
- proc_file.readline() # skip the first line
+ proc_file.readline() # skip the first line
for line in proc_file:
_, l_addr, f_addr, status, _, _, _, _, _, inode = line.split()[:10]
@@ -411,7 +411,7 @@ def _get_lines(file_path, line_prefixes, parameter):
proc_file, results = open(file_path), {}
for line in proc_file:
- if not remaining_prefixes: break # found everything we're looking for
+ if not remaining_prefixes: break # found everything we're looking for
for prefix in remaining_prefixes:
if line.startswith(prefix):
diff --git a/stem/util/system.py b/stem/util/system.py
index 9e7aaa2..a3a4c5f 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -322,7 +322,7 @@ def get_pid_by_port(port):
results = [r for r in results if "127.0.0.1:%s" % port in r]
if len(results) == 1 and len(results[0].split()) == 7:
- results = results[0].split()[6] # process field (ex. "7184/tor")
+ results = results[0].split()[6] # process field (ex. "7184/tor")
pid = results[:results.find("/")]
if pid.isdigit(): return int(pid)
@@ -390,7 +390,7 @@ def get_pid_by_port(port):
pid = results[0].split()[1]
if pid.isdigit(): return int(pid)
- return None # all queries failed
+ return None # all queries failed
def get_pid_by_open_file(path):
"""
@@ -425,7 +425,7 @@ def get_pid_by_open_file(path):
pid = results[0].strip()
if pid.isdigit(): return int(pid)
- return None # all queries failed
+ return None # all queries failed
def get_cwd(pid):
"""
@@ -489,7 +489,7 @@ def get_cwd(pid):
else:
log.debug("%s we got unexpected output from lsof: %s" % (logging_prefix, results))
- return None # all queries failed
+ return None # all queries failed
def get_bsd_jail_id(pid):
"""
diff --git a/stem/version.py b/stem/version.py
index 43c96ba..bf8c32c 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -172,7 +172,7 @@ class Version(object):
"""
if not isinstance(other, Version):
- return 1 # this is also used for equality checks
+ return 1 # this is also used for equality checks
for attr in ("major", "minor", "micro", "patch"):
my_version = max(0, self.__dict__[attr])
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index bda512e..ba41190 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -54,7 +54,7 @@ def pep8_issues(base_path = DEFAULT_TARGET):
# Pep8 only works with this one if we have four space indents (its
# detection is based on multiples of four).
- ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E261,E127"
+ ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E127"
issues = {}
pep8_output = system.call("pep8 --ignore %s %s" % (ignored_issues, base_path))
diff --git a/test/integ/control/base_controller.py b/test/integ/control/base_controller.py
index a2814ce..d43b009 100644
--- a/test/integ/control/base_controller.py
+++ b/test/integ/control/base_controller.py
@@ -246,7 +246,7 @@ class TestBaseController(unittest.TestCase):
controller.add_status_listener(state_observer.listener, True)
controller.close()
- time.sleep(0.1) # not much work going on so this doesn't need to be much
+ time.sleep(0.1) # not much work going on so this doesn't need to be much
self.assertEquals(controller, state_observer.controller)
self.assertEquals(stem.control.State.CLOSED, state_observer.state)
self.assertTrue(state_observer.timestamp < time.time())
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 901a0e1..b769fbc 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -658,7 +658,7 @@ class TestController(unittest.TestCase):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect(('127.0.0.1', int(controller.get_conf('SocksListenAddress').rsplit(':', 1)[1])))
test.util.negotiate_socks(s, '1.2.1.2', 80)
- s.sendall(test.util.ip_request) # make the http request for the ip address
+ s.sendall(test.util.ip_request) # make the http request for the ip address
response = s.recv(1000)
# everything after the blank line is the 'data' in a HTTP response.
diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py
index 06b1a3c..a2bf144 100644
--- a/test/integ/descriptor/extrainfo_descriptor.py
+++ b/test/integ/descriptor/extrainfo_descriptor.py
@@ -23,7 +23,7 @@ class TestExtraInfoDescriptor(unittest.TestCase):
descriptor_path = test.integ.descriptor.get_resource("extrainfo_relay_descriptor")
descriptor_file = open(descriptor_path)
- descriptor_file.readline() # strip header
+ descriptor_file.readline() # strip header
descriptor_contents = descriptor_file.read()
descriptor_file.close()
@@ -74,7 +74,7 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
descriptor_path = test.integ.descriptor.get_resource("extrainfo_bridge_descriptor")
descriptor_file = open(descriptor_path)
- descriptor_file.readline() # strip header
+ descriptor_file.readline() # strip header
descriptor_contents = descriptor_file.read()
descriptor_file.close()
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py
index d6ef4fc..ad2933e 100644
--- a/test/integ/descriptor/networkstatus.py
+++ b/test/integ/descriptor/networkstatus.py
@@ -234,7 +234,7 @@ TpQQk3nNQF8z6UIvdlvP+DnJV4izWVkQEZgUZgIVM0E=
consensus_path = test.integ.descriptor.get_resource("cached-consensus-v2")
with open(consensus_path) as descriptor_file:
- descriptor_file.readline() # strip header
+ descriptor_file.readline() # strip header
document = stem.descriptor.networkstatus.NetworkStatusDocumentV2(descriptor_file.read())
self.assertEquals(2, document.version)
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index a285952..637583e 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -60,7 +60,7 @@ def _get_raw_tar_descriptors():
for tar_entry in tar_file:
if tar_entry.isfile():
entry = tar_file.extractfile(tar_entry)
- entry.readline() # strip header
+ entry.readline() # strip header
raw_descriptors.append(entry.read())
entry.close()
finally:
@@ -72,7 +72,7 @@ def _get_raw_tar_descriptors():
class SkipListener:
def __init__(self):
- self.results = [] # (path, exception) tuples that we've received
+ self.results = [] # (path, exception) tuples that we've received
def listener(self, path, exception):
self.results.append((path, exception))
@@ -122,7 +122,7 @@ class TestDescriptorReader(unittest.TestCase):
test.runner.skip(self, "(chmod not functional)")
test_listing_path = _make_processed_files_listing(BASIC_LISTING)
- os.chmod(test_listing_path, 0077) # remove read permissions
+ os.chmod(test_listing_path, 0077) # remove read permissions
self.assertRaises(IOError, stem.descriptor.reader.load_processed_files, test_listing_path)
def test_save_processed_files(self):
@@ -168,7 +168,7 @@ class TestDescriptorReader(unittest.TestCase):
descriptor_path = os.path.join(DESCRIPTOR_TEST_DATA, "example_descriptor")
with open(descriptor_path) as descriptor_file:
- descriptor_file.readline() # strip header
+ descriptor_file.readline() # strip header
descriptor_entries.append(descriptor_file.read())
# running this test multiple times to flush out concurrency issues
@@ -335,7 +335,7 @@ class TestDescriptorReader(unittest.TestCase):
expected_results[path] = last_modified
reader = stem.descriptor.reader.DescriptorReader(DESCRIPTOR_TEST_DATA)
- with reader: list(reader) # iterates over all of the descriptors
+ with reader: list(reader) # iterates over all of the descriptors
self.assertEquals(expected_results, reader.get_processed_files())
@@ -349,12 +349,12 @@ class TestDescriptorReader(unittest.TestCase):
reader = stem.descriptor.reader.DescriptorReader(DESCRIPTOR_TEST_DATA)
reader.register_skip_listener(skip_listener.listener)
- with reader: list(reader) # iterates over all of the descriptors
+ with reader: list(reader) # iterates over all of the descriptors
self.assertEqual(4, len(skip_listener.results))
for skip_path, skip_exception in skip_listener.results:
- if skip_path.endswith(".swp"): continue # skip vim temp files
+ if skip_path.endswith(".swp"): continue # skip vim temp files
if not os.path.basename(skip_path) in ("riddle", "tiny.png", "vote", "new_metrics_type"):
self.fail("Unexpected non-descriptor content: %s" % skip_path)
@@ -378,7 +378,7 @@ class TestDescriptorReader(unittest.TestCase):
reader.set_processed_files(initial_processed_files)
self.assertEquals(initial_processed_files, reader.get_processed_files())
- with reader: list(reader) # iterates over all of the descriptors
+ with reader: list(reader) # iterates over all of the descriptors
self.assertEquals(1, len(skip_listener.results))
@@ -405,7 +405,7 @@ class TestDescriptorReader(unittest.TestCase):
skip_listener = SkipListener()
reader = stem.descriptor.reader.DescriptorReader(test_path)
reader.register_skip_listener(skip_listener.listener)
- with reader: list(reader) # iterates over all of the descriptors
+ with reader: list(reader) # iterates over all of the descriptors
self.assertEqual(1, len(skip_listener.results))
@@ -432,12 +432,12 @@ class TestDescriptorReader(unittest.TestCase):
test_file.write("test data for test_skip_listener_unrecognized_type()")
test_file.close()
- os.chmod(test_path, 0077) # remove read permissions
+ os.chmod(test_path, 0077) # remove read permissions
skip_listener = SkipListener()
reader = stem.descriptor.reader.DescriptorReader(test_path)
reader.register_skip_listener(skip_listener.listener)
- with reader: list(reader) # iterates over all of the descriptors
+ with reader: list(reader) # iterates over all of the descriptors
self.assertEqual(1, len(skip_listener.results))
@@ -459,7 +459,7 @@ class TestDescriptorReader(unittest.TestCase):
skip_listener = SkipListener()
reader = stem.descriptor.reader.DescriptorReader(test_path)
reader.register_skip_listener(skip_listener.listener)
- with reader: list(reader) # iterates over all of the descriptors
+ with reader: list(reader) # iterates over all of the descriptors
self.assertEqual(1, len(skip_listener.results))
@@ -477,7 +477,7 @@ class TestDescriptorReader(unittest.TestCase):
skip_listener = SkipListener()
reader = stem.descriptor.reader.DescriptorReader(test_path)
reader.register_skip_listener(skip_listener.listener)
- with reader: list(reader) # iterates over all of the descriptors
+ with reader: list(reader) # iterates over all of the descriptors
self.assertEqual(1, len(skip_listener.results))
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py
index ae30209..a2ee34a 100644
--- a/test/integ/descriptor/server_descriptor.py
+++ b/test/integ/descriptor/server_descriptor.py
@@ -24,7 +24,7 @@ class TestServerDescriptor(unittest.TestCase):
descriptor_path = test.integ.descriptor.get_resource("example_descriptor")
descriptor_file = open(descriptor_path)
- descriptor_file.readline() # strip header
+ descriptor_file.readline() # strip header
descriptor_contents = descriptor_file.read()
descriptor_file.close()
@@ -96,7 +96,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
descriptor_path = test.integ.descriptor.get_resource("old_descriptor")
descriptor_file = open(descriptor_path)
- descriptor_file.readline() # strip header
+ descriptor_file.readline() # strip header
descriptor_contents = descriptor_file.read()
descriptor_file.close()
@@ -182,7 +182,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
descriptor_path = test.integ.descriptor.get_resource("non-ascii_descriptor")
descriptor_file = open(descriptor_path)
- descriptor_file.readline() # strip header
+ descriptor_file.readline() # strip header
descriptor_contents = descriptor_file.read()
descriptor_file.close()
@@ -224,7 +224,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
descriptor_path = test.integ.descriptor.get_resource("cr_in_contact_line")
descriptor_file = open(descriptor_path)
- descriptor_file.readline() # strip header
+ descriptor_file.readline() # strip header
descriptor_contents = descriptor_file.read()
descriptor_file.close()
@@ -252,7 +252,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
descriptor_path = test.integ.descriptor.get_resource("negative_uptime")
descriptor_file = open(descriptor_path)
- descriptor_file.readline() # strip header
+ descriptor_file.readline() # strip header
descriptor_contents = descriptor_file.read()
descriptor_file.close()
@@ -276,7 +276,7 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
descriptor_path = test.integ.descriptor.get_resource("bridge_descriptor")
descriptor_file = open(descriptor_path)
- descriptor_file.readline() # strip header
+ descriptor_file.readline() # strip header
descriptor_contents = descriptor_file.read()
descriptor_file.close()
diff --git a/test/integ/process.py b/test/integ/process.py
index 7aa3382..ea8909a 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -26,7 +26,7 @@ def _kill_process(process):
elif not stem.util.system.is_windows():
os.kill(process.pid, signal.SIGTERM)
- process.communicate() # block until its definitely gone
+ process.communicate() # block until its definitely gone
class TestProcess(unittest.TestCase):
def setUp(self):
@@ -136,7 +136,7 @@ class TestProcess(unittest.TestCase):
for seconds_waited in xrange(30):
if tor_process.poll() == 0:
- return # tor exited
+ return # tor exited
time.sleep(1)
@@ -171,7 +171,7 @@ class TestProcess(unittest.TestCase):
# give tor a few seconds to quit
for seconds_waited in xrange(5):
if tor_process.poll() == 0:
- return # tor exited
+ return # tor exited
time.sleep(1)
diff --git a/test/mocking.py b/test/mocking.py
index 12c6bef..ff314ee 100644
--- a/test/mocking.py
+++ b/test/mocking.py
@@ -459,7 +459,7 @@ def get_object(object_class, methods = None):
if method_name in methods:
mock_methods[method_name] = methods[method_name]
elif method_name.startswith('__') and method_name.endswith('__'):
- pass # messing with most private methods makes for a broken mock object
+ pass # messing with most private methods makes for a broken mock object
else:
mock_methods[method_name] = raise_exception(ValueError("Unexpected call of '%s' on a mock object" % method_name))
@@ -548,7 +548,7 @@ def _get_descriptor_content(attr = None, exclude = (), header_template = (), foo
header_content, footer_content = [], []
if attr is None: attr = {}
- attr = dict(attr) # shallow copy since we're destructive
+ attr = dict(attr) # shallow copy since we're destructive
for content, template in ((header_content, header_template),
(footer_content, footer_template)):
@@ -863,7 +863,7 @@ def sign_descriptor_content(desc_content):
# generate the new signing key string
- signing_key_token = "\nsigning-key\n" # note the trailing '\n' is important here so as not to match the string elsewhere
+ signing_key_token = "\nsigning-key\n" # note the trailing '\n' is important here so as not to match the string elsewhere
signing_key_token_start = "-----BEGIN RSA PUBLIC KEY-----\n"
signing_key_token_end = "\n-----END RSA PUBLIC KEY-----\n"
new_sk = signing_key_token + signing_key_token_start + public_key_string + signing_key_token_end
diff --git a/test/runner.py b/test/runner.py
index 17abefb..af5ed73 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -332,7 +332,7 @@ class Runner(object):
test.output.print_line("failed (unable to call kill() in python 2.5)", *ERROR_ATTR)
except OSError: pass
- self._tor_process.communicate() # blocks until the process is done
+ self._tor_process.communicate() # blocks until the process is done
# if we've made a temporary data directory then clean it up
if self._test_dir and CONFIG["integ.test_directory"] == "":
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index aa2c7ae..34b98a5 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -153,10 +153,10 @@ class TestControl(unittest.TestCase):
# check where GETINFO provides malformed content
invalid_responses = (
- '"127.0.0.1"', # address only
- '"1112"', # port only
- '"5127.0.0.1:1112"', # invlaid address
- '"127.0.0.1:991112"', # invalid port
+ '"127.0.0.1"', # address only
+ '"1112"', # port only
+ '"5127.0.0.1:1112"', # invlaid address
+ '"127.0.0.1:991112"', # invalid port
)
for response in invalid_responses:
@@ -301,12 +301,12 @@ class TestControl(unittest.TestCase):
# exercise with some invalid inputs
malformed_inputs = [
- '=piyaz', # no fingerprint
- '999A226EBED397F331B612FE1E4CFAE5C1F201BA=piyaz', # fingerprint missing prefix
- '$999A226EBED397F331B612FE1E4CFAE5C1F201BAA=piyaz', # fingerprint too long
- '$999A226EBED397F331B612FE1E4CFAE5C1F201B=piyaz', # fingerprint too short
- '$999A226EBED397F331B612FE1E4CFAE5C1F201Bz=piyaz', # invalid character in fingerprint
- '$999A226EBED397F331B612FE1E4CFAE5C1F201BA=', # no nickname
+ '=piyaz', # no fingerprint
+ '999A226EBED397F331B612FE1E4CFAE5C1F201BA=piyaz', # fingerprint missing prefix
+ '$999A226EBED397F331B612FE1E4CFAE5C1F201BAA=piyaz', # fingerprint too long
+ '$999A226EBED397F331B612FE1E4CFAE5C1F201B=piyaz', # fingerprint too short
+ '$999A226EBED397F331B612FE1E4CFAE5C1F201Bz=piyaz', # invalid character in fingerprint
+ '$999A226EBED397F331B612FE1E4CFAE5C1F201BA=', # no nickname
]
for test_input in malformed_inputs:
diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py
index f422f5b..0ab5694 100644
--- a/test/unit/descriptor/networkstatus/document_v3.py
+++ b/test/unit/descriptor/networkstatus/document_v3.py
@@ -163,7 +163,7 @@ class TestNetworkStatusDocument(unittest.TestCase):
if is_mandatory and ((is_consensus and in_consensus) or (is_vote and in_votes)):
content = get_network_status_document_v3(attr, exclude = (field,), content = True)
self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
- NetworkStatusDocumentV3(content, False) # constructs without validation
+ NetworkStatusDocumentV3(content, False) # constructs without validation
def test_unrecognized_line(self):
"""
@@ -193,7 +193,7 @@ class TestNetworkStatusDocument(unittest.TestCase):
content = "\n".join(test_lines)
self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
- NetworkStatusDocumentV3(content, False) # constructs without validation
+ NetworkStatusDocumentV3(content, False) # constructs without validation
def test_duplicate_fields(self):
"""
@@ -220,7 +220,7 @@ class TestNetworkStatusDocument(unittest.TestCase):
content = "\n".join(test_lines)
self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
- NetworkStatusDocumentV3(content, False) # constructs without validation
+ NetworkStatusDocumentV3(content, False) # constructs without validation
def test_version(self):
"""
@@ -293,7 +293,7 @@ class TestNetworkStatusDocument(unittest.TestCase):
(" ", []),
("1 2 3 a 5", [1, 2, 3, 5]),
("1 2 3 4.0 5", [1, 2, 3, 5]),
- ("2 3 4", [2, 3, 4]), # spec says version one must be included
+ ("2 3 4", [2, 3, 4]), # spec says version one must be included
)
for test_value, expected_consensus_methods in test_values:
@@ -693,7 +693,7 @@ class TestNetworkStatusDocument(unittest.TestCase):
content = get_network_status_document_v3({"directory-signature": "%s %s\n%s" % tuple(attrs)}, content = True)
self.assertRaises(ValueError, NetworkStatusDocumentV3, content)
- NetworkStatusDocumentV3(content, False) # checks that it's still parsable without validation
+ NetworkStatusDocumentV3(content, False) # checks that it's still parsable without validation
def test_with_router_status_entries(self):
"""
diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py
index a0ff74d..5d74678 100644
--- a/test/unit/descriptor/router_status_entry.py
+++ b/test/unit/descriptor/router_status_entry.py
@@ -190,8 +190,8 @@ class TestRouterStatusEntry(unittest.TestCase):
test_values = (
"",
- "saberrider2008ReallyLongNickname", # too long
- "$aberrider2008", # invalid characters
+ "saberrider2008ReallyLongNickname", # too long
+ "$aberrider2008", # invalid characters
)
for value in test_values:
@@ -474,7 +474,7 @@ class TestRouterStatusEntry(unittest.TestCase):
}
# we need a document that's a vote
- mock_document = lambda x: x # just need anything with a __dict__
+ mock_document = lambda x: x # just need anything with a __dict__
mock_document.__dict__["is_vote"] = True
mock_document.__dict__["is_consensus"] = False
diff --git a/test/unit/response/control_message.py b/test/unit/response/control_message.py
index 091aff9..4a55c98 100644
--- a/test/unit/response/control_message.py
+++ b/test/unit/response/control_message.py
@@ -170,7 +170,7 @@ class TestControlMessage(unittest.TestCase):
# checks that the contents match the input
message_lines = str(message).splitlines()
controller_lines = controller_reply.split("\r\n")
- controller_lines.pop() # the ControlMessage won't have a trailing newline
+ controller_lines.pop() # the ControlMessage won't have a trailing newline
while controller_lines:
line = controller_lines.pop(0)
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index 885be6b..adc055c 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -10,7 +10,7 @@ import stem.response
import stem.response.events
import stem.util.log
-from stem import * # enums and exceptions
+from stem import * # enums and exceptions
from test import mocking
# ADDRMAP event
diff --git a/test/unit/tutorial.py b/test/unit/tutorial.py
index 6358344..47e8107 100644
--- a/test/unit/tutorial.py
+++ b/test/unit/tutorial.py
@@ -51,7 +51,7 @@ class TestTutorial(unittest.TestCase):
'__exit__': mocking.no_op(),
'__iter__': mocking.return_value(iter((
exit_descriptor,
- mocking.get_relay_server_descriptor(), # non-exit
+ mocking.get_relay_server_descriptor(), # non-exit
exit_descriptor,
exit_descriptor,
)))
diff --git a/test/unit/util/conf.py b/test/unit/util/conf.py
index abb645a..4e70c1d 100644
--- a/test/unit/util/conf.py
+++ b/test/unit/util/conf.py
@@ -118,7 +118,7 @@ class TestConf(unittest.TestCase):
self.assertRaises(ValueError, parse_enum_csv, "my_option", "ugabuga", Insects)
self.assertRaises(ValueError, parse_enum_csv, "my_option", "ladybug, ugabuga", Insects)
- self.assertRaises(ValueError, parse_enum_csv, "my_option", "ladybug butterfly", Insects) # no comma
+ self.assertRaises(ValueError, parse_enum_csv, "my_option", "ladybug butterfly", Insects) # no comma
self.assertRaises(ValueError, parse_enum_csv, "my_option", "ladybug", Insects, 2)
self.assertRaises(ValueError, parse_enum_csv, "my_option", "ladybug", Insects, (2, 3))
diff --git a/test/unit/util/str_tools.py b/test/unit/util/str_tools.py
index ed31c43..c1c5ee8 100644
--- a/test/unit/util/str_tools.py
+++ b/test/unit/util/str_tools.py
@@ -143,8 +143,8 @@ class TestStrTools(unittest.TestCase):
None,
32,
'hello world',
- '2012-11-08T16:48:41.42025', # too few microsecond digits
- '2012-11-08T16:48:41.4202511', # too many microsecond digits
+ '2012-11-08T16:48:41.42025', # too few microsecond digits
+ '2012-11-08T16:48:41.4202511', # too many microsecond digits
'2012-11-08T16:48',
]
1
0

[stem/master] Conforming to E302 (two blank lines above methods and functions)
by atagar@torproject.org 07 Jan '13
by atagar@torproject.org 07 Jan '13
07 Jan '13
commit 26b27b6eff21214b17b4018a16ac97f3bd674734
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Jan 7 00:31:22 2013 -0800
Conforming to E302 (two blank lines above methods and functions)
Another long one. I hope this is almost done...
---
run_tests.py | 2 +
stem/__init__.py | 9 +++++
stem/connection.py | 34 ++++++++++++++++++++
stem/control.py | 5 +++
stem/descriptor/__init__.py | 6 +++
stem/descriptor/export.py | 3 ++
stem/descriptor/extrainfo_descriptor.py | 5 +++
stem/descriptor/networkstatus.py | 12 +++++++
stem/descriptor/reader.py | 9 +++++
stem/descriptor/router_status_entry.py | 13 +++++++
stem/descriptor/server_descriptor.py | 4 ++
stem/exit_policy.py | 6 +++
stem/prereq.py | 5 +++
stem/process.py | 3 ++
stem/response/__init__.py | 6 +++
stem/response/authchallenge.py | 1 +
stem/response/events.py | 20 +++++++++++
stem/response/getconf.py | 1 +
stem/response/getinfo.py | 1 +
stem/response/mapaddress.py | 1 +
stem/response/protocolinfo.py | 1 +
stem/socket.py | 6 +++
stem/util/conf.py | 6 +++
stem/util/connection.py | 11 ++++++
stem/util/enum.py | 2 +
stem/util/log.py | 15 +++++++++
stem/util/ordereddict.py | 1 +
stem/util/proc.py | 14 ++++++++
stem/util/str_tools.py | 8 +++++
stem/util/system.py | 12 +++++++
stem/util/term.py | 1 +
stem/util/tor_tools.py | 5 +++
stem/version.py | 3 ++
test/check_whitespace.py | 5 ++-
test/integ/connection/authentication.py | 3 ++
test/integ/connection/connect.py | 1 +
test/integ/control/base_controller.py | 2 +
test/integ/control/controller.py | 1 +
test/integ/descriptor/__init__.py | 1 +
test/integ/descriptor/extrainfo_descriptor.py | 1 +
test/integ/descriptor/networkstatus.py | 1 +
test/integ/descriptor/reader.py | 5 +++
test/integ/descriptor/server_descriptor.py | 1 +
test/integ/process.py | 2 +
test/integ/response/protocolinfo.py | 1 +
test/integ/socket/control_message.py | 1 +
test/integ/socket/control_socket.py | 1 +
test/integ/util/conf.py | 3 ++
test/integ/util/proc.py | 1 +
test/integ/util/system.py | 3 ++
test/integ/version.py | 1 +
test/mocking.py | 29 +++++++++++++++++
test/network.py | 4 ++
test/output.py | 10 ++++++
test/prompt.py | 5 +++
test/runner.py | 11 ++++++
test/unit/connection/authentication.py | 1 +
test/unit/control/controller.py | 1 +
test/unit/descriptor/export.py | 1 +
test/unit/descriptor/extrainfo_descriptor.py | 1 +
.../networkstatus/directory_authority.py | 1 +
test/unit/descriptor/networkstatus/document_v2.py | 1 +
test/unit/descriptor/networkstatus/document_v3.py | 1 +
.../descriptor/networkstatus/key_certificate.py | 1 +
test/unit/descriptor/reader.py | 1 +
test/unit/descriptor/router_status_entry.py | 1 +
test/unit/descriptor/server_descriptor.py | 1 +
test/unit/exit_policy/policy.py | 1 +
test/unit/exit_policy/rule.py | 1 +
test/unit/response/authchallenge.py | 1 +
test/unit/response/control_line.py | 1 +
test/unit/response/control_message.py | 1 +
test/unit/response/events.py | 1 +
test/unit/response/getconf.py | 1 +
test/unit/response/getinfo.py | 1 +
test/unit/response/mapaddress.py | 1 +
test/unit/response/protocolinfo.py | 1 +
test/unit/response/singleline.py | 1 +
test/unit/tutorial.py | 1 +
test/unit/util/conf.py | 1 +
test/unit/util/connection.py | 1 +
test/unit/util/enum.py | 1 +
test/unit/util/proc.py | 1 +
test/unit/util/str_tools.py | 1 +
test/unit/util/system.py | 2 +
test/unit/util/tor_tools.py | 1 +
test/unit/version.py | 1 +
test/util.py | 2 +
88 files changed, 357 insertions(+), 1 deletions(-)
diff --git a/run_tests.py b/run_tests.py
index f9b18fc..9774c55 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -165,6 +165,7 @@ INTEG_TESTS = (
test.integ.control.controller.TestController,
)
+
def load_user_configuration(test_config):
"""
Parses our commandline arguments, loading our custom test configuration if
@@ -254,6 +255,7 @@ def load_user_configuration(test_config):
print " TRACE, DEBUG, INFO, NOTICE, WARN, ERROR"
sys.exit(1)
+
def _clean_orphaned_pyc():
test.output.print_noline(" checking for orphaned .pyc files... ", *test.runner.STATUS_ATTR)
diff --git a/stem/__init__.py b/stem/__init__.py
index f02897c..45bf14d 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -403,12 +403,15 @@ import stem.util.enum
UNDEFINED = "<Undefined_ >"
+
class ControllerError(Exception):
"Base error for controller communication issues."
+
class ProtocolError(ControllerError):
"Malformed content from the control socket."
+
class OperationFailed(ControllerError):
"""
Base exception class for failed operations that return an error code
@@ -423,11 +426,13 @@ class OperationFailed(ControllerError):
self.code = code
self.message = message
+
class UnsatisfiableRequest(OperationFailed):
"""
Exception raised if Tor was unable to process our request.
"""
+
class CircuitExtensionFailed(UnsatisfiableRequest):
"""
An attempt to create or extend a circuit failed.
@@ -439,11 +444,13 @@ class CircuitExtensionFailed(UnsatisfiableRequest):
super(CircuitExtensionFailed, self).__init__(message = message)
self.circ = circ
+
class InvalidRequest(OperationFailed):
"""
Exception raised when the request was invalid or malformed.
"""
+
class InvalidArguments(InvalidRequest):
"""
Exception class for requests which had invalid arguments.
@@ -458,9 +465,11 @@ class InvalidArguments(InvalidRequest):
super(InvalidArguments, self).__init__(code, message)
self.arguments = arguments
+
class SocketError(ControllerError):
"Error arose while communicating with the control socket."
+
class SocketClosed(SocketError):
"Control socket was closed before completing the message."
diff --git a/stem/connection.py b/stem/connection.py
index 0291a82..ef7ba04 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -120,6 +120,7 @@ AuthMethod = stem.util.enum.Enum("NONE", "PASSWORD", "COOKIE", "SAFECOOKIE", "UN
CLIENT_HASH_CONSTANT = "Tor safe cookie authentication controller-to-server hash"
SERVER_HASH_CONSTANT = "Tor safe cookie authentication server-to-controller hash"
+
def connect_port(control_addr = "127.0.0.1", control_port = 9051, password = None, chroot_path = None, controller = stem.control.Controller):
"""
Convenience function for quickly getting a control connection. This is very
@@ -145,6 +146,7 @@ def connect_port(control_addr = "127.0.0.1", control_port = 9051, password = Non
return _connect(control_port, password, chroot_path, controller)
+
def connect_socket_file(socket_path = "/var/run/tor/control", password = None, chroot_path = None, controller = stem.control.Controller):
"""
Convenience function for quickly getting a control connection. For more
@@ -167,6 +169,7 @@ def connect_socket_file(socket_path = "/var/run/tor/control", password = None, c
return _connect(control_socket, password, chroot_path, controller)
+
def _connect(control_socket, password, chroot_path, controller):
"""
Common implementation for the connect_* functions.
@@ -202,6 +205,7 @@ def _connect(control_socket, password, chroot_path, controller):
print "Unable to authenticate: %s" % exc
return None
+
def authenticate(controller, password = None, chroot_path = None, protocolinfo_response = None):
"""
Authenticates to a control socket using the information provided by a
@@ -412,6 +416,7 @@ def authenticate(controller, password = None, chroot_path = None, protocolinfo_r
raise AssertionError("BUG: Authentication failed without providing a recognized exception: %s" % str(auth_exceptions))
+
def authenticate_none(controller, suppress_ctl_errors = True):
"""
Authenticates to an open control socket. All control connections need to
@@ -458,6 +463,7 @@ def authenticate_none(controller, suppress_ctl_errors = True):
else:
raise OpenAuthRejected("Socket failed (%s)" % exc)
+
def authenticate_password(controller, password, suppress_ctl_errors = True):
"""
Authenticates to a control socket that uses a password (via the
@@ -527,6 +533,7 @@ def authenticate_password(controller, password, suppress_ctl_errors = True):
else:
raise PasswordAuthRejected("Socket failed (%s)" % exc)
+
def authenticate_cookie(controller, cookie_path, suppress_ctl_errors = True):
"""
Authenticates to a control socket that uses the contents of an authentication
@@ -605,6 +612,7 @@ def authenticate_cookie(controller, cookie_path, suppress_ctl_errors = True):
else:
raise CookieAuthRejected("Socket failed (%s)" % exc, cookie_path, False)
+
def authenticate_safecookie(controller, cookie_path, suppress_ctl_errors = True):
"""
Authenticates to a control socket using the safe cookie method, which is
@@ -750,6 +758,7 @@ def authenticate_safecookie(controller, cookie_path, suppress_ctl_errors = True)
else:
raise CookieAuthRejected(str(auth_response), cookie_path, True, auth_response)
+
def get_protocolinfo(controller):
"""
Issues a PROTOCOLINFO query to a control socket, getting information about
@@ -815,6 +824,7 @@ def get_protocolinfo(controller):
return protocolinfo_response
+
def _msg(controller, message):
"""
Sends and receives a message with either a
@@ -827,6 +837,7 @@ def _msg(controller, message):
else:
return controller.msg(message)
+
def _read_cookie(cookie_path, is_safecookie):
"""
Provides the contents of a given cookie file.
@@ -868,6 +879,7 @@ def _read_cookie(cookie_path, is_safecookie):
exc_msg = "Authentication failed: unable to read '%s' (%s)" % (cookie_path, exc)
raise UnreadableCookieFile(exc_msg, cookie_path, is_safecookie)
+
def _expand_cookie_path(protocolinfo_response, pid_resolver, pid_resolution_arg):
"""
Attempts to expand a relative cookie path with the given pid resolver. This
@@ -901,6 +913,7 @@ def _expand_cookie_path(protocolinfo_response, pid_resolver, pid_resolution_arg)
protocolinfo_response.cookie_path = cookie_path
+
class AuthenticationFailure(Exception):
"""
Base error for authentication failures.
@@ -913,6 +926,7 @@ class AuthenticationFailure(Exception):
super(AuthenticationFailure, self).__init__(message)
self.auth_response = auth_response
+
class UnrecognizedAuthMethods(AuthenticationFailure):
"""
All methods for authenticating aren't recognized.
@@ -924,27 +938,35 @@ class UnrecognizedAuthMethods(AuthenticationFailure):
super(UnrecognizedAuthMethods, self).__init__(message)
self.unknown_auth_methods = unknown_auth_methods
+
class IncorrectSocketType(AuthenticationFailure):
"Socket does not speak the control protocol."
+
class OpenAuthFailed(AuthenticationFailure):
"Failure to authenticate to an open socket."
+
class OpenAuthRejected(OpenAuthFailed):
"Attempt to connect to an open control socket was rejected."
+
class PasswordAuthFailed(AuthenticationFailure):
"Failure to authenticate with a password."
+
class PasswordAuthRejected(PasswordAuthFailed):
"Socket does not support password authentication."
+
class IncorrectPassword(PasswordAuthFailed):
"Authentication password incorrect."
+
class MissingPassword(PasswordAuthFailed):
"Password authentication is supported but we weren't provided with one."
+
class CookieAuthFailed(AuthenticationFailure):
"""
Failure to authenticate with an authentication cookie.
@@ -961,18 +983,23 @@ class CookieAuthFailed(AuthenticationFailure):
self.is_safecookie = is_safecookie
self.cookie_path = cookie_path
+
class CookieAuthRejected(CookieAuthFailed):
"Socket does not support password authentication."
+
class IncorrectCookieValue(CookieAuthFailed):
"Authentication cookie value was rejected."
+
class IncorrectCookieSize(CookieAuthFailed):
"Aborted because the cookie file is the wrong size."
+
class UnreadableCookieFile(CookieAuthFailed):
"Error arose in reading the authentication cookie."
+
class AuthChallengeFailed(CookieAuthFailed):
"""
AUTHCHALLENGE command has failed.
@@ -981,11 +1008,13 @@ class AuthChallengeFailed(CookieAuthFailed):
def __init__(self, message, cookie_path):
super(AuthChallengeFailed, self).__init__(message, cookie_path, True)
+
class AuthChallengeUnsupported(AuthChallengeFailed):
"""
AUTHCHALLENGE isn't implemented.
"""
+
class UnrecognizedAuthChallengeMethod(AuthChallengeFailed):
"""
Tor couldn't recognize our AUTHCHALLENGE method.
@@ -997,21 +1026,26 @@ class UnrecognizedAuthChallengeMethod(AuthChallengeFailed):
super(UnrecognizedAuthChallengeMethod, self).__init__(message, cookie_path)
self.authchallenge_method = authchallenge_method
+
class AuthSecurityFailure(AuthChallengeFailed):
"AUTHCHALLENGE response is invalid."
+
class InvalidClientNonce(AuthChallengeFailed):
"AUTHCHALLENGE request contains an invalid client nonce."
+
class MissingAuthInfo(AuthenticationFailure):
"""
The PROTOCOLINFO response didn't have enough information to authenticate.
These are valid control responses but really shouldn't happen in practice.
"""
+
class NoAuthMethods(MissingAuthInfo):
"PROTOCOLINFO response didn't have any methods for authenticating."
+
class NoAuthCookie(MissingAuthInfo):
"""
PROTOCOLINFO response supports cookie auth but doesn't have its path.
diff --git a/stem/control.py b/stem/control.py
index feb7834..2e82a65 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -210,6 +210,7 @@ GEOIP_FAILURE_THRESHOLD = 5
# changed to the more conventional is_alive() and current_thread() in python
# 2.6 and above. We should use that when dropping python 2.5 compatibility.
+
class BaseController(object):
"""
Controller for the tor process. This is a minimal base class for other
@@ -584,6 +585,7 @@ class BaseController(object):
self._event_notice.wait()
self._event_notice.clear()
+
class Controller(BaseController):
"""
Communicates with a control socket. This is built on top of the
@@ -1920,6 +1922,7 @@ class Controller(BaseController):
if not response.is_ok():
raise stem.ProtocolError("SETEVENTS received unexpected response\n%s" % response)
+
def _parse_circ_path(path):
"""
Parses a circuit path as a list of **(fingerprint, nickname)** tuples. Tor
@@ -1962,6 +1965,7 @@ def _parse_circ_path(path):
else:
return []
+
def _parse_circ_entry(entry):
"""
Parses a single relay's 'LongName' or 'ServerID'. See the
@@ -1998,6 +2002,7 @@ def _parse_circ_entry(entry):
return (fingerprint, nickname)
+
def _case_insensitive_lookup(entries, key, default = UNDEFINED):
"""
Makes a case insensitive lookup within a list or dictionary, providing the
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 0dba96c..97dc94a 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -55,6 +55,7 @@ Flag = stem.util.enum.Enum(
("VALID", "Valid"),
)
+
def parse_file(path, descriptor_file):
"""
Provides an iterator for the descriptors within a given file.
@@ -111,6 +112,7 @@ def parse_file(path, descriptor_file):
raise TypeError("Unable to determine the descriptor's type. filename: '%s', first line: '%s'" % (filename, first_line))
+
def _parse_metrics_file(descriptor_type, major_version, minor_version, descriptor_file):
# Parses descriptor files from metrics, yielding individual descriptors. This
# throws a TypeError if the descriptor_type or version isn't recognized.
@@ -141,6 +143,7 @@ def _parse_metrics_file(descriptor_type, major_version, minor_version, descripto
else:
raise TypeError("Unrecognized metrics descriptor format. type: '%s', version: '%i.%i'" % (descriptor_type, major_version, minor_version))
+
class Descriptor(object):
"""
Common parent for all types of descriptors.
@@ -176,6 +179,7 @@ class Descriptor(object):
def __str__(self):
return self._raw_contents
+
def _read_until_keywords(keywords, descriptor_file, inclusive = False, ignore_first = False, skip = False, end_position = None, include_ending_keyword = False):
"""
Reads from the descriptor file until we get to one of the given keywords or reach the
@@ -241,6 +245,7 @@ def _read_until_keywords(keywords, descriptor_file, inclusive = False, ignore_fi
else:
return content
+
def _get_pseudo_pgp_block(remaining_contents):
"""
Checks if given contents begins with a pseudo-Open-PGP-style block and, if
@@ -276,6 +281,7 @@ def _get_pseudo_pgp_block(remaining_contents):
else:
return None
+
def _get_descriptor_components(raw_contents, validate, extra_keywords = ()):
"""
Initial breakup of the server descriptor contents to make parsing easier.
diff --git a/stem/descriptor/export.py b/stem/descriptor/export.py
index becc72f..5be7dbc 100644
--- a/stem/descriptor/export.py
+++ b/stem/descriptor/export.py
@@ -15,9 +15,11 @@ import csv
import stem.descriptor
import stem.prereq
+
class _ExportDialect(csv.excel):
lineterminator = '\n'
+
def export_csv(descriptors, included_fields = (), excluded_fields = (), header = True):
"""
Provides a newline separated CSV for one or more descriptors. If simply
@@ -40,6 +42,7 @@ def export_csv(descriptors, included_fields = (), excluded_fields = (), header =
export_csv_file(output_buffer, descriptors, included_fields, excluded_fields, header)
return output_buffer.getvalue()
+
def export_csv_file(output_file, descriptors, included_fields = (), excluded_fields = (), header = True):
"""
Similar to :func:`stem.descriptor.export.export_csv`, except that the CSV is
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 2c14c92..25ab615 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -133,6 +133,7 @@ SINGLE_FIELDS = (
"exit-streams-opened",
)
+
def parse_file(descriptor_file, validate = True):
"""
Iterates over the extra-info descriptors in a file.
@@ -161,6 +162,7 @@ def parse_file(descriptor_file, validate = True):
else:
break # done parsing file
+
def _parse_timestamp_and_interval(keyword, content):
"""
Parses a 'YYYY-MM-DD HH:MM:SS (NSEC s) *' entry.
@@ -194,6 +196,7 @@ def _parse_timestamp_and_interval(keyword, content):
except ValueError:
raise ValueError("%s line's timestamp wasn't parsable: %s" % (keyword, line))
+
class ExtraInfoDescriptor(stem.descriptor.Descriptor):
"""
Extra-info descriptor document.
@@ -791,6 +794,7 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
def _last_keyword(self):
return "router-signature"
+
class RelayExtraInfoDescriptor(ExtraInfoDescriptor):
"""
Relay extra-info descriptor, constructed from data such as that provided by
@@ -838,6 +842,7 @@ class RelayExtraInfoDescriptor(ExtraInfoDescriptor):
ExtraInfoDescriptor._parse(self, entries, validate)
+
class BridgeExtraInfoDescriptor(ExtraInfoDescriptor):
"""
Bridge extra-info descriptor (`bridge descriptor specification
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index 28537c2..e8e3ae2 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -165,6 +165,7 @@ BANDWIDTH_WEIGHT_ENTRIES = (
"Wmb", "Wmd", "Wme", "Wmg", "Wmm",
)
+
def parse_file(document_file, validate = True, is_microdescriptor = False, document_version = 3):
"""
Parses a network status and iterates over the RouterStatusEntry in it. The
@@ -223,6 +224,7 @@ def parse_file(document_file, validate = True, is_microdescriptor = False, docum
for desc in desc_iterator:
yield desc
+
class NetworkStatusDocument(stem.descriptor.Descriptor):
"""
Common parent for network status documents.
@@ -235,6 +237,7 @@ class NetworkStatusDocument(stem.descriptor.Descriptor):
def get_unrecognized_lines(self):
return list(self._unrecognized_lines)
+
class NetworkStatusDocumentV2(NetworkStatusDocument):
"""
Version 2 network status document. These have been deprecated and are no
@@ -406,6 +409,7 @@ class NetworkStatusDocumentV2(NetworkStatusDocument):
if 'network-status-version' != entries.keys()[0]:
raise ValueError("Network status document (v2) are expected to start with a 'network-status-version' line:\n%s" % str(self))
+
class NetworkStatusDocumentV3(NetworkStatusDocument):
"""
Version 3 network status document. This could be either a vote or consensus.
@@ -524,6 +528,7 @@ class NetworkStatusDocumentV3(NetworkStatusDocument):
return str(self) > str(other)
+
class _DocumentHeader(object):
def __init__(self, document_file, validate, default_params):
self.version = None
@@ -733,6 +738,7 @@ class _DocumentHeader(object):
if value < minimum or value > maximum:
raise ValueError("'%s' value on the params line must be in the range of %i - %i, was %i" % (key, minimum, maximum, value))
+
class _DocumentFooter(object):
def __init__(self, document_file, validate, header):
self.signatures = []
@@ -796,6 +802,7 @@ class _DocumentFooter(object):
self.signatures.append(DocumentSignature(method, fingerprint, key_digest, block_contents, validate))
+
def _check_for_missing_and_disallowed_fields(header, entries, fields):
"""
Checks that we have mandatory fields for our type, and that we don't have
@@ -828,6 +835,7 @@ def _check_for_missing_and_disallowed_fields(header, entries, fields):
if disallowed_fields:
raise ValueError("Network status document has fields that shouldn't appear in this document type or version: %s" % ', '.join(disallowed_fields))
+
def _check_for_misordered_fields(entries, expected):
"""
To be valid a network status document's fiends need to appear in a specific
@@ -857,6 +865,7 @@ def _check_for_misordered_fields(entries, expected):
expected_label = ', '.join(expected)
raise ValueError("The fields in a section of the document are misordered. It should be '%s' but was '%s'" % (actual_label, expected_label))
+
def _parse_int_mappings(keyword, value, validate):
# Parse a series of 'key=value' entries, checking the following:
# - values are integers
@@ -895,6 +904,7 @@ def _parse_int_mappings(keyword, value, validate):
return results
+
class DirectoryAuthority(stem.descriptor.Descriptor):
"""
Directory authority information obtained from a v3 network status document.
@@ -1085,6 +1095,7 @@ class DirectoryAuthority(stem.descriptor.Descriptor):
return str(self) > str(other)
+
class KeyCertificate(stem.descriptor.Descriptor):
"""
Directory key certificate for a v3 network status document.
@@ -1245,6 +1256,7 @@ class KeyCertificate(stem.descriptor.Descriptor):
return str(self) > str(other)
+
class DocumentSignature(object):
"""
Directory signature of a v3 network status document.
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 9f9f505..3373a1e 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -93,9 +93,11 @@ FINISHED = "DONE"
# dropping python 2.5 compatibility...
# http://docs.python.org/library/threading.html#threading.Event.is_set
+
class FileSkipped(Exception):
"Base error when we can't provide descriptor data from a file."
+
class AlreadyRead(FileSkipped):
"""
Already read a file with this 'last modified' timestamp or later.
@@ -110,6 +112,7 @@ class AlreadyRead(FileSkipped):
self.last_modified = last_modified
self.last_modified_when_read = last_modified_when_read
+
class ParsingFailure(FileSkipped):
"""
File contents could not be parsed as descriptor data.
@@ -121,6 +124,7 @@ class ParsingFailure(FileSkipped):
super(ParsingFailure, self).__init__()
self.exception = parsing_exception
+
class UnrecognizedType(FileSkipped):
"""
File doesn't contain descriptor data. This could either be due to its file
@@ -133,6 +137,7 @@ class UnrecognizedType(FileSkipped):
super(UnrecognizedType, self).__init__()
self.mime_type = mime_type
+
class ReadFailed(FileSkipped):
"""
An IOError occurred while trying to read the file.
@@ -145,12 +150,14 @@ class ReadFailed(FileSkipped):
super(ReadFailed, self).__init__()
self.exception = read_exception
+
class FileMissing(ReadFailed):
"File does not exist."
def __init__(self):
super(FileMissing, self).__init__(None)
+
def load_processed_files(path):
"""
Loads a dictionary of 'path => last modified timestamp' mappings, as
@@ -190,6 +197,7 @@ def load_processed_files(path):
return processed_files
+
def save_processed_files(path, processed_files):
"""
Persists a dictionary of 'path => last modified timestamp' mappings (as
@@ -222,6 +230,7 @@ def save_processed_files(path, processed_files):
output_file.write("%s %i\n" % (path, timestamp))
+
class DescriptorReader(object):
"""
Iterator for the descriptor data on the local file system. This can process
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 6e048dd..0479bbd 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -22,6 +22,7 @@ import datetime
import stem.descriptor
import stem.exit_policy
+
def parse_file(document_file, validate, entry_class, entry_keyword = "r", start_position = None, end_position = None, section_end_keywords = (), extra_args = ()):
"""
Reads a range of the document_file containing some number of entry_class
@@ -88,6 +89,7 @@ def parse_file(document_file, validate, entry_class, entry_keyword = "r", start_
else:
break
+
class RouterStatusEntry(stem.descriptor.Descriptor):
"""
Information about an individual router stored within a network status
@@ -226,6 +228,7 @@ class RouterStatusEntry(stem.descriptor.Descriptor):
return str(self) > str(other)
+
class RouterStatusEntryV2(RouterStatusEntry):
"""
Information about an individual router stored within a version 2 network
@@ -269,6 +272,7 @@ class RouterStatusEntryV2(RouterStatusEntry):
return str(self) > str(other)
+
class RouterStatusEntryV3(RouterStatusEntry):
"""
Information about an individual router stored within a version 3 network
@@ -350,6 +354,7 @@ class RouterStatusEntryV3(RouterStatusEntry):
return str(self) > str(other)
+
class RouterStatusEntryMicroV3(RouterStatusEntry):
"""
Information about an individual router stored within a microdescriptor
@@ -411,6 +416,7 @@ class RouterStatusEntryMicroV3(RouterStatusEntry):
return str(self) > str(other)
+
def _parse_r_line(desc, value, validate, include_digest = True):
# Parses a RouterStatusEntry's 'r' line. They're very nearly identical for
# all current entry types (v2, v3, and microdescriptor v3) with one little
@@ -466,6 +472,7 @@ def _parse_r_line(desc, value, validate, include_digest = True):
if validate:
raise ValueError("Publication time time wasn't parsable: r %s" % value)
+
def _parse_a_line(desc, value, validate):
# "a" SP address ":" portlist
# example: a [2001:888:2133:0:82:94:251:204]:9001
@@ -499,6 +506,7 @@ def _parse_a_line(desc, value, validate):
desc.addresses_v6.setdefault(address, []).append((int(min_port), int(max_port)))
+
def _parse_s_line(desc, value, validate):
# "s" Flags
# example: s Named Running Stable Valid
@@ -513,6 +521,7 @@ def _parse_s_line(desc, value, validate):
elif flag == "":
raise ValueError("%s had extra whitespace on its 's' line: s %s" % (desc._name(), value))
+
def _parse_v_line(desc, value, validate):
# "v" version
# example: v Tor 0.2.2.35
@@ -530,6 +539,7 @@ def _parse_v_line(desc, value, validate):
if validate:
raise ValueError("%s has a malformed tor version (%s): v %s" % (desc._name(), exc, value))
+
def _parse_w_line(desc, value, validate):
# "w" "Bandwidth=" INT ["Measured=" INT]
# example: w Bandwidth=7980
@@ -572,6 +582,7 @@ def _parse_w_line(desc, value, validate):
else:
desc.unrecognized_bandwidth_entries.append(w_entry)
+
def _parse_p_line(desc, value, validate):
# "p" ("accept" / "reject") PortList
# p reject 1-65535
@@ -585,6 +596,7 @@ def _parse_p_line(desc, value, validate):
raise ValueError("%s exit policy is malformed (%s): p %s" % (desc._name(), exc, value))
+
def _parse_m_line(desc, value, validate):
# "m" methods 1*(algorithm "=" digest)
# example: m 8,9,10,11,12 sha256=g1vx9si329muxV3tquWIXXySNOIwRGMeAESKs/v4DWs
@@ -625,6 +637,7 @@ def _parse_m_line(desc, value, validate):
desc.microdescriptor_hashes.append((methods, hashes))
+
def _decode_fingerprint(identity, validate):
"""
Decodes the 'identity' value found in consensuses into the more common hex
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 037a4bd..6fe0e7c 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -71,6 +71,7 @@ SINGLE_FIELDS = (
"ntor-onion-key",
)
+
def parse_file(descriptor_file, validate = True):
"""
Iterates over the server descriptors in a file.
@@ -129,6 +130,7 @@ def parse_file(descriptor_file, validate = True):
else:
break # done parsing descriptors
+
class ServerDescriptor(stem.descriptor.Descriptor):
"""
Common parent for server descriptors.
@@ -607,6 +609,7 @@ class ServerDescriptor(stem.descriptor.Descriptor):
def _last_keyword(self):
return "router-signature"
+
class RelayDescriptor(ServerDescriptor):
"""
Server descriptor (`descriptor specification
@@ -806,6 +809,7 @@ class RelayDescriptor(ServerDescriptor):
return key_bytes
+
class BridgeDescriptor(ServerDescriptor):
"""
Bridge descriptor (`bridge descriptor specification
diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index 56c68dc..d82892f 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -75,6 +75,7 @@ AddressType = stem.util.enum.Enum(("WILDCARD", "Wildcard"), ("IPv4", "IPv4"), ("
# some use cases where we might want to construct custom policies. Maybe make
# it a CustomExitPolicyRule subclass?
+
class ExitPolicy(object):
"""
Policy for the destinations that a relay allows or denies exiting to. This
@@ -259,6 +260,7 @@ class ExitPolicy(object):
else:
return False
+
class MicroExitPolicy(ExitPolicy):
"""
Exit policy provided by the microdescriptors. This is a distilled version of
@@ -338,6 +340,7 @@ class MicroExitPolicy(ExitPolicy):
else:
return False
+
class ExitPolicyRule(object):
"""
Single rule from the user's exit policy. These rules are chained together to
@@ -698,12 +701,15 @@ class ExitPolicyRule(object):
else:
return False
+
def _address_type_to_int(address_type):
return AddressType.index_of(address_type)
+
def _int_to_address_type(address_type_int):
return AddressType[AddressType.keys()[address_type_int]]
+
class MicroExitPolicyRule(ExitPolicyRule):
"""
Lighter weight ExitPolicyRule derivative for microdescriptors.
diff --git a/stem/prereq.py b/stem/prereq.py
index e3b4fdc..f9e53a7 100644
--- a/stem/prereq.py
+++ b/stem/prereq.py
@@ -26,6 +26,7 @@ from stem.util import log
IS_CRYPTO_AVAILABLE = None
+
def check_requirements():
"""
Checks that we meet the minimum requirements to run stem. If we don't then
@@ -41,6 +42,7 @@ def check_requirements():
elif major_version < 2 or minor_version < 5:
raise ImportError("stem requires python version 2.5 or greater")
+
def is_python_26():
"""
Checks if we're in the 2.6 - 2.x range.
@@ -50,6 +52,7 @@ def is_python_26():
return _check_version(6)
+
def is_python_27():
"""
Checks if we're in the 2.7 - 2.x range.
@@ -59,6 +62,7 @@ def is_python_27():
return _check_version(7)
+
def is_crypto_available():
global IS_CRYPTO_AVAILABLE
@@ -77,6 +81,7 @@ def is_crypto_available():
return IS_CRYPTO_AVAILABLE
+
def _check_version(minor_req):
major_version, minor_version = sys.version_info[0:2]
diff --git a/stem/process.py b/stem/process.py
index e654e85..64ee591 100644
--- a/stem/process.py
+++ b/stem/process.py
@@ -29,6 +29,7 @@ import stem.util.system
NO_TORRC = "<no torrc>"
DEFAULT_INIT_TIMEOUT = 90
+
def launch_tor(tor_cmd = "tor", args = None, torrc_path = None, completion_percent = 100, init_msg_handler = None, timeout = DEFAULT_INIT_TIMEOUT, take_ownership = False):
"""
Initializes a tor process. This blocks until initialization completes or we
@@ -170,6 +171,7 @@ def launch_tor(tor_cmd = "tor", args = None, torrc_path = None, completion_perce
last_problem = msg
+
def launch_tor_with_config(config, tor_cmd = "tor", completion_percent = 100, init_msg_handler = None, timeout = DEFAULT_INIT_TIMEOUT, take_ownership = False):
"""
Initializes a tor process, like :func:`~stem.process.launch_tor`, but with a
@@ -230,5 +232,6 @@ def launch_tor_with_config(config, tor_cmd = "tor", completion_percent = 100, in
except:
pass
+
def _get_pid():
return str(os.getpid())
diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index dbf50f9..9544d71 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -53,6 +53,7 @@ KEY_ARG = re.compile("^(\S+)=")
CONTROL_ESCAPES = {r"\\": "\\", r"\"": "\"", r"\'": "'",
r"\r": "\r", r"\n": "\n", r"\t": "\t"}
+
def convert(response_type, message, **kwargs):
"""
Converts a :class:`~stem.response.ControlMessage` into a particular kind of
@@ -115,6 +116,7 @@ def convert(response_type, message, **kwargs):
message.__class__ = response_class
message._parse_message(**kwargs)
+
class ControlMessage(object):
"""
Message from the control socket. This is iterable and can be stringified for
@@ -226,6 +228,7 @@ class ControlMessage(object):
return ControlLine(self._parsed_content[index][2])
+
class ControlLine(str):
"""
String subclass that represents a line of controller output. This behaves as
@@ -384,6 +387,7 @@ class ControlLine(str):
self._remainder = remainder
return (key, next_entry)
+
def _parse_entry(line, quoted, escaped):
"""
Parses the next entry from the given space separated content.
@@ -425,6 +429,7 @@ def _parse_entry(line, quoted, escaped):
return (next_entry, remainder.lstrip())
+
def _get_quote_indices(line, escaped):
"""
Provides the indices of the next two quotes in the given content.
@@ -450,6 +455,7 @@ def _get_quote_indices(line, escaped):
return tuple(indices)
+
class SingleLineResponse(ControlMessage):
"""
Reply to a request that performs an action rather than querying data. These
diff --git a/stem/response/authchallenge.py b/stem/response/authchallenge.py
index cdc0ad4..161dd84 100644
--- a/stem/response/authchallenge.py
+++ b/stem/response/authchallenge.py
@@ -4,6 +4,7 @@ import stem.response
import stem.socket
import stem.util.tor_tools
+
class AuthChallengeResponse(stem.response.ControlMessage):
"""
AUTHCHALLENGE query response.
diff --git a/stem/response/events.py b/stem/response/events.py
index 51aa3d2..e9c3fdc 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -17,6 +17,7 @@ from stem.util import connection, log, str_tools, tor_tools
KW_ARG = re.compile("^(.*) ([A-Za-z0-9_]+)=(\S*)$")
QUOTED_KW_ARG = re.compile("^(.*) ([A-Za-z0-9_]+)=\"(.*)\"$")
+
class Event(stem.response.ControlMessage):
"""
Base for events we receive asynchronously, as described in section 4.1 of the
@@ -141,6 +142,7 @@ class Event(stem.response.ControlMessage):
unrecognized_msg = "%s event had an unrecognized %s (%s). Maybe a new addition to the control protocol? Full Event: '%s'" % (self.type, attr, value, self)
log.log_once(log_id, log.INFO, unrecognized_msg)
+
class AddrMapEvent(Event):
"""
Event that indicates a new address mapping.
@@ -174,6 +176,7 @@ class AddrMapEvent(Event):
if self.utc_expiry is not None:
self.utc_expiry = datetime.datetime.strptime(self.utc_expiry, "%Y-%m-%d %H:%M:%S")
+
class AuthDirNewDescEvent(Event):
"""
Event specific to directory authorities, indicating that we just received new
@@ -202,6 +205,7 @@ class AuthDirNewDescEvent(Event):
self.message = lines[2]
self.descriptor = '\n'.join(lines[3:-1])
+
class BandwidthEvent(Event):
"""
Event emitted every second with the bytes sent and received by tor.
@@ -226,6 +230,7 @@ class BandwidthEvent(Event):
self.read = long(self.read)
self.written = long(self.written)
+
class BuildTimeoutSetEvent(Event):
"""
Event indicating that the timeout value for a circuit has changed. This was
@@ -280,6 +285,7 @@ class BuildTimeoutSetEvent(Event):
self._log_if_unrecognized('set_type', stem.TimeoutSetType)
+
class CircuitEvent(Event):
"""
Event that indicates that a circuit has changed.
@@ -338,6 +344,7 @@ class CircuitEvent(Event):
self._log_if_unrecognized('reason', stem.CircClosureReason)
self._log_if_unrecognized('remote_reason', stem.CircClosureReason)
+
class CircMinorEvent(Event):
"""
Event providing information about minor changes in our circuits. This was
@@ -393,6 +400,7 @@ class CircMinorEvent(Event):
self._log_if_unrecognized('old_purpose', stem.CircPurpose)
self._log_if_unrecognized('old_hs_state', stem.HiddenServiceState)
+
class ClientsSeenEvent(Event):
"""
Periodic event on bridge relays that provides a summary of our users.
@@ -451,6 +459,7 @@ class ClientsSeenEvent(Event):
self.ip_versions = protocol_to_count
+
class ConfChangedEvent(Event):
"""
Event that indicates that our configuration changed, either in response to a
@@ -485,6 +494,7 @@ class ConfChangedEvent(Event):
self.config[key] = value
+
class DescChangedEvent(Event):
"""
Event that indicates that our descriptor has changed.
@@ -496,6 +506,7 @@ class DescChangedEvent(Event):
pass
+
class GuardEvent(Event):
"""
Event that indicates that our guard relays have changed.
@@ -516,6 +527,7 @@ class GuardEvent(Event):
_POSITIONAL_ARGS = ("guard_type", "name", "status")
+
class LogEvent(Event):
"""
Tor logging event. These are the most visible kind of event since, by
@@ -539,6 +551,7 @@ class LogEvent(Event):
self.message = str(self)[len(self.runlevel) + 1:].rstrip("\nOK")
+
class NetworkStatusEvent(Event):
"""
Event for when our copy of the consensus has changed. This was introduced in
@@ -561,6 +574,7 @@ class NetworkStatusEvent(Event):
entry_class = stem.descriptor.router_status_entry.RouterStatusEntryV3,
))
+
class NewConsensusEvent(Event):
"""
Event for when we have a new consensus. This is similar to
@@ -585,6 +599,7 @@ class NewConsensusEvent(Event):
entry_class = stem.descriptor.router_status_entry.RouterStatusEntryV3,
))
+
class NewDescEvent(Event):
"""
Event that indicates that a new descriptor is available.
@@ -603,6 +618,7 @@ class NewDescEvent(Event):
def _parse(self):
self.relays = tuple([stem.control._parse_circ_entry(entry) for entry in str(self).split()[1:]])
+
class ORConnEvent(Event):
"""
Event that indicates a change in a relay connection. The 'endpoint' could be
@@ -664,6 +680,7 @@ class ORConnEvent(Event):
self._log_if_unrecognized('status', stem.ORStatus)
self._log_if_unrecognized('reason', stem.ORClosureReason)
+
class SignalEvent(Event):
"""
Event that indicates that tor has received and acted upon a signal being sent
@@ -696,6 +713,7 @@ class SignalEvent(Event):
self._log_if_unrecognized('signal', expected_signals)
+
class StatusEvent(Event):
"""
Notification of a change in tor's state. These are generally triggered for
@@ -726,6 +744,7 @@ class StatusEvent(Event):
self._log_if_unrecognized('runlevel', stem.Runlevel)
+
class StreamEvent(Event):
"""
Event that indicates that a stream has changed.
@@ -796,6 +815,7 @@ class StreamEvent(Event):
self._log_if_unrecognized('remote_reason', stem.StreamClosureReason)
self._log_if_unrecognized('purpose', stem.StreamPurpose)
+
class StreamBwEvent(Event):
"""
Event (emitted approximately every second) with the bytes sent and received
diff --git a/stem/response/getconf.py b/stem/response/getconf.py
index c8b7da3..fff5380 100644
--- a/stem/response/getconf.py
+++ b/stem/response/getconf.py
@@ -1,6 +1,7 @@
import stem.response
import stem.socket
+
class GetConfResponse(stem.response.ControlMessage):
"""
Reply for a GETCONF query.
diff --git a/stem/response/getinfo.py b/stem/response/getinfo.py
index 3ef418b..3fcf6c3 100644
--- a/stem/response/getinfo.py
+++ b/stem/response/getinfo.py
@@ -1,6 +1,7 @@
import stem.response
import stem.socket
+
class GetInfoResponse(stem.response.ControlMessage):
"""
Reply for a GETINFO query.
diff --git a/stem/response/mapaddress.py b/stem/response/mapaddress.py
index d30ccfa..528f3ad 100644
--- a/stem/response/mapaddress.py
+++ b/stem/response/mapaddress.py
@@ -1,6 +1,7 @@
import stem.response
import stem.socket
+
class MapAddressResponse(stem.response.ControlMessage):
"""
Reply for a MAPADDRESS query.
diff --git a/stem/response/protocolinfo.py b/stem/response/protocolinfo.py
index 65a2d02..ba841d7 100644
--- a/stem/response/protocolinfo.py
+++ b/stem/response/protocolinfo.py
@@ -5,6 +5,7 @@ import stem.version
from stem.connection import AuthMethod
from stem.util import log
+
class ProtocolInfoResponse(stem.response.ControlMessage):
"""
Version one PROTOCOLINFO query response.
diff --git a/stem/socket.py b/stem/socket.py
index b23b247..ac21429 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -39,6 +39,7 @@ import stem.response
from stem.util import log
+
class ControlSocket(object):
"""
Wrapper for a socket connection that speaks the Tor control protocol. To the
@@ -282,6 +283,7 @@ class ControlSocket(object):
raise NotImplementedError("Unsupported Operation: this should be implemented by the ControlSocket subclass")
+
class ControlPort(ControlSocket):
"""
Control connection to tor. For more information see tor's ControlPort torrc
@@ -336,6 +338,7 @@ class ControlPort(ControlSocket):
except socket.error, exc:
raise stem.SocketError(exc)
+
class ControlSocketFile(ControlSocket):
"""
Control connection to tor. For more information see tor's ControlSocket torrc
@@ -379,6 +382,7 @@ class ControlSocketFile(ControlSocket):
except socket.error, exc:
raise stem.SocketError(exc)
+
def send_message(control_file, message, raw = False):
"""
Sends a message to the control socket, adding the expected formatting for
@@ -438,6 +442,7 @@ def send_message(control_file, message, raw = False):
log.info("Failed to send message: file has been closed")
raise stem.SocketClosed("file has been closed")
+
def recv_message(control_file):
"""
Pulls from a control socket until we either have a complete message or
@@ -557,6 +562,7 @@ def recv_message(control_file):
log.warn(prefix + "\"%s\" isn't a recognized divider type" % line)
raise stem.ProtocolError("Unrecognized divider type '%s': %s" % (divider, line))
+
def send_formatting(message):
"""
Performs the formatting expected from sent control messages. For more
diff --git a/stem/util/conf.py b/stem/util/conf.py
index 57f1fda..7e4cc8d 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -161,6 +161,7 @@ from stem.util import log
CONFS = {} # mapping of identifier to singleton instances of configs
+
class _SyncListener(object):
def __init__(self, config_dict, interceptor):
self.config_dict = config_dict
@@ -181,6 +182,7 @@ class _SyncListener(object):
self.config_dict[key] = new_value
+
def config_dict(handle, conf_mappings, handler = None):
"""
Makes a dictionary that stays synchronized with a configuration.
@@ -214,6 +216,7 @@ def config_dict(handle, conf_mappings, handler = None):
selected_config.add_listener(_SyncListener(conf_mappings, handler).update)
return conf_mappings
+
def get_config(handle):
"""
Singleton constructor for configuration file instances. If a configuration
@@ -228,6 +231,7 @@ def get_config(handle):
return CONFS[handle]
+
def parse_enum(key, value, enumeration):
"""
Provides the enumeration value for a given key. This is a case insensitive
@@ -244,6 +248,7 @@ def parse_enum(key, value, enumeration):
return parse_enum_csv(key, value, enumeration, 1)[0]
+
def parse_enum_csv(key, value, enumeration, count = None):
"""
Parses a given value as being a comma separated listing of enumeration keys,
@@ -303,6 +308,7 @@ def parse_enum_csv(key, value, enumeration, count = None):
return result
+
class Config(object):
"""
Handler for easily working with custom configurations, providing persistence
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 6892bed..2a9c529 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -30,6 +30,7 @@ CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE = os.urandom(32)
FULL_IPv4_MASK = "255.255.255.255"
FULL_IPv6_MASK = "FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF:FFFF"
+
def is_valid_ip_address(address):
"""
Checks if a string is a valid IPv4 address.
@@ -56,6 +57,7 @@ def is_valid_ip_address(address):
return True
+
def is_valid_ipv6_address(address, allow_brackets = False):
"""
Checks if a string is a valid IPv6 address.
@@ -89,6 +91,7 @@ def is_valid_ipv6_address(address, allow_brackets = False):
return True
+
def is_valid_port(entry, allow_zero = False):
"""
Checks if a string or int is a valid port number.
@@ -118,6 +121,7 @@ def is_valid_port(entry, allow_zero = False):
return entry > 0 and entry < 65536
+
def expand_ipv6_address(address):
"""
Expands abbreviated IPv6 addresses to their full colon separated hex format.
@@ -156,6 +160,7 @@ def expand_ipv6_address(address):
return address
+
def get_mask(bits):
"""
Provides the IPv4 mask for a given number of bits, in the dotted-quad format.
@@ -181,6 +186,7 @@ def get_mask(bits):
# converts each octet into its integer value
return ".".join([str(int(octet, 2)) for octet in octets])
+
def get_masked_bits(mask):
"""
Provides the number of bits that an IPv4 subnet mask represents. Note that
@@ -205,6 +211,7 @@ def get_masked_bits(mask):
else:
raise ValueError("Unable to convert mask to a bit count: %s" % mask)
+
def get_mask_ipv6(bits):
"""
Provides the IPv6 mask for a given number of bits, in the hex colon-delimited
@@ -231,6 +238,7 @@ def get_mask_ipv6(bits):
# converts each group into its hex value
return ":".join(["%04x" % int(group, 2) for group in groupings]).upper()
+
def get_binary(value, bits):
"""
Provides the given value as a binary string, padded with zeros to the given
@@ -243,6 +251,7 @@ def get_binary(value, bits):
# http://www.daniweb.com/code/snippet216539.html
return "".join([str((value >> y) & 1) for y in range(bits - 1, -1, -1)])
+
def get_address_binary(address):
"""
Provides the binary value for an IPv4 or IPv6 address.
@@ -260,6 +269,7 @@ def get_address_binary(address):
else:
raise ValueError("'%s' is neither an IPv4 or IPv6 address" % address)
+
def hmac_sha256(key, msg):
"""
Generates a sha256 digest using the given key and message.
@@ -272,6 +282,7 @@ def hmac_sha256(key, msg):
return hmac.new(key, msg, hashlib.sha256).digest()
+
def cryptovariables_equal(x, y):
"""
Compares two strings for equality securely.
diff --git a/stem/util/enum.py b/stem/util/enum.py
index d22cd22..4617077 100644
--- a/stem/util/enum.py
+++ b/stem/util/enum.py
@@ -39,6 +39,7 @@ constructed as simple type listings...
import stem.util.str_tools
+
def UppercaseEnum(*args):
"""
Provides an :class:`~stem.util.enum.Enum` instance where the values are
@@ -59,6 +60,7 @@ def UppercaseEnum(*args):
return Enum(*[(v, v) for v in args])
+
class Enum(object):
"""
Basic enumeration.
diff --git a/stem/util/log.py b/stem/util/log.py
index 14b09df..04bcbaf 100644
--- a/stem/util/log.py
+++ b/stem/util/log.py
@@ -77,6 +77,7 @@ DEDUPLICATION_MESSAGE_IDS = set()
# could be found for logger "stem"' warning as per...
# http://docs.python.org/release/3.1.3/library/logging.html#configuring-loggi…
+
class _NullHandler(logging.Handler):
def emit(self, record):
pass
@@ -84,6 +85,7 @@ class _NullHandler(logging.Handler):
if not LOGGER.handlers:
LOGGER.addHandler(_NullHandler())
+
def get_logger():
"""
Provides the stem logger.
@@ -93,6 +95,7 @@ def get_logger():
return LOGGER
+
def logging_level(runlevel):
"""
Translates a runlevel into the value expected by the logging module.
@@ -105,6 +108,7 @@ def logging_level(runlevel):
else:
return logging.FATAL + 5
+
def escape(message):
"""
Escapes specific sequences for logging (newlines, tabs, carriage returns).
@@ -119,6 +123,7 @@ def escape(message):
return message
+
def log(runlevel, message):
"""
Logs a message at the given runlevel.
@@ -130,6 +135,7 @@ def log(runlevel, message):
if runlevel:
LOGGER.log(LOG_VALUES[runlevel], message)
+
def log_once(message_id, runlevel, message):
"""
Logs a message at the given runlevel. If a message with this ID has already
@@ -150,24 +156,31 @@ def log_once(message_id, runlevel, message):
# shorter aliases for logging at a runlevel
+
def trace(message):
log(Runlevel.TRACE, message)
+
def debug(message):
log(Runlevel.DEBUG, message)
+
def info(message):
log(Runlevel.INFO, message)
+
def notice(message):
log(Runlevel.NOTICE, message)
+
def warn(message):
log(Runlevel.WARN, message)
+
def error(message):
log(Runlevel.ERROR, message)
+
class LogBuffer(logging.Handler):
"""
Basic log handler that listens for stem events and stores them so they can be
@@ -198,6 +211,7 @@ class LogBuffer(logging.Handler):
def emit(self, record):
self._buffer.append(record)
+
class _StdoutLogger(logging.Handler):
def __init__(self, runlevel):
logging.Handler.__init__(self, level = logging_level(runlevel))
@@ -209,6 +223,7 @@ class _StdoutLogger(logging.Handler):
def emit(self, record):
print self.formatter.format(record)
+
def log_to_stdout(runlevel):
"""
Logs further events to stdout.
diff --git a/stem/util/ordereddict.py b/stem/util/ordereddict.py
index 778a534..b03ffb6 100644
--- a/stem/util/ordereddict.py
+++ b/stem/util/ordereddict.py
@@ -25,6 +25,7 @@
from UserDict import DictMixin
+
class OrderedDict(dict, DictMixin):
def __init__(self, *args, **kwds):
if len(args) > 1:
diff --git a/stem/util/proc.py b/stem/util/proc.py
index 436e061..e5be48d 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -62,6 +62,7 @@ Stat = stem.util.enum.Enum(
("CPU_STIME", "stime"), ("START_TIME", "start time")
)
+
def is_available():
"""
Checks if proc information is available on this platform.
@@ -88,6 +89,7 @@ def is_available():
return IS_PROC_AVAILABLE
+
def get_system_start_time():
"""
Provides the unix time (seconds since epoch) when the system started.
@@ -112,6 +114,7 @@ def get_system_start_time():
return SYS_START_TIME
+
def get_physical_memory():
"""
Provides the total physical memory on the system in bytes.
@@ -136,6 +139,7 @@ def get_physical_memory():
return SYS_PHYSICAL_MEMORY
+
def get_cwd(pid):
"""
Provides the current working directory for the given process.
@@ -163,6 +167,7 @@ def get_cwd(pid):
_log_runtime(parameter, proc_cwd_link, start_time)
return cwd
+
def get_uid(pid):
"""
Provides the user ID the given process is running under.
@@ -187,6 +192,7 @@ def get_uid(pid):
_log_failure(parameter, exc)
raise exc
+
def get_memory_usage(pid):
"""
Provides the memory usage in bytes for the given process.
@@ -219,6 +225,7 @@ def get_memory_usage(pid):
_log_failure(parameter, exc)
raise exc
+
def get_stats(pid, *stat_types):
"""
Provides process specific information. See the :data:`~stem.util.proc.Stat`
@@ -286,6 +293,7 @@ def get_stats(pid, *stat_types):
_log_runtime(parameter, stat_path, start_time)
return tuple(results)
+
def get_connections(pid):
"""
Queries connection related information from the proc contents. This provides
@@ -358,6 +366,7 @@ def get_connections(pid):
_log_runtime(parameter, "/proc/net/[tcp|udp]", start_time)
return conn
+
def _decode_proc_address_encoding(addr):
"""
Translates an address entry in the /proc/net/* contents to a human readable
@@ -396,6 +405,7 @@ def _decode_proc_address_encoding(addr):
return (ip, port)
+
def _is_float(*value):
try:
for v in value:
@@ -405,9 +415,11 @@ def _is_float(*value):
except ValueError:
return False
+
def _get_line(file_path, line_prefix, parameter):
return _get_lines(file_path, (line_prefix, ), parameter)[line_prefix]
+
def _get_lines(file_path, line_prefixes, parameter):
"""
Fetches lines with the given prefixes from a file. This only provides back
@@ -451,6 +463,7 @@ def _get_lines(file_path, line_prefixes, parameter):
_log_failure(parameter, exc)
raise exc
+
def _log_runtime(parameter, proc_location, start_time):
"""
Logs a message indicating a successful proc query.
@@ -463,6 +476,7 @@ def _log_runtime(parameter, proc_location, start_time):
runtime = time.time() - start_time
log.debug("proc call (%s): %s (runtime: %0.4f)" % (parameter, proc_location, runtime))
+
def _log_failure(parameter, exc):
"""
Logs a message indicating that the proc query failed.
diff --git a/stem/util/str_tools.py b/stem/util/str_tools.py
index 443bd4f..8527f2a 100644
--- a/stem/util/str_tools.py
+++ b/stem/util/str_tools.py
@@ -44,6 +44,7 @@ TIME_UNITS = (
(1.0, "s", " second"),
)
+
def to_camel_case(label, divider = "_", joiner = " "):
"""
Converts the given string to camel case, ie:
@@ -71,6 +72,7 @@ def to_camel_case(label, divider = "_", joiner = " "):
return joiner.join(words)
+
def get_size_label(byte_count, decimal = 0, is_long = False, is_bytes = True):
"""
Converts a number of bytes into a human readable label in its most
@@ -103,6 +105,7 @@ def get_size_label(byte_count, decimal = 0, is_long = False, is_bytes = True):
else:
return _get_label(SIZE_UNITS_BITS, byte_count, decimal, is_long)
+
def get_time_label(seconds, decimal = 0, is_long = False):
"""
Converts seconds into a time label truncated to its most significant units.
@@ -133,6 +136,7 @@ def get_time_label(seconds, decimal = 0, is_long = False):
return _get_label(TIME_UNITS, seconds, decimal, is_long)
+
def get_time_labels(seconds, is_long = False):
"""
Provides a list of label conversions for each time unit, starting with its
@@ -162,6 +166,7 @@ def get_time_labels(seconds, is_long = False):
return time_labels
+
def get_short_time_label(seconds):
"""
Provides a time in the following format:
@@ -201,6 +206,7 @@ def get_short_time_label(seconds):
return label
+
def parse_short_time_label(label):
"""
Provides the number of seconds corresponding to the formatting used for the
@@ -245,6 +251,7 @@ def parse_short_time_label(label):
except ValueError:
raise ValueError("Non-numeric value in time entry: %s" % label)
+
def parse_iso_timestamp(entry):
"""
Parses the ISO 8601 standard that provides for timestamps like...
@@ -277,6 +284,7 @@ def parse_iso_timestamp(entry):
timestamp = datetime.datetime.strptime(timestamp_str, "%Y-%m-%dT%H:%M:%S")
return timestamp + datetime.timedelta(microseconds = int(microseconds))
+
def _get_label(units, count, decimal, is_long):
"""
Provides label corresponding to units of the highest significance in the
diff --git a/stem/util/system.py b/stem/util/system.py
index acba9c1..760cc05 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -59,6 +59,7 @@ GET_CWD_PWDX = "pwdx %s"
GET_CWD_LSOF = "lsof -a -p %s -d cwd -Fn"
GET_BSD_JAIL_ID_PS = "ps -p %s -o jid"
+
def is_windows():
"""
Checks if we are running on Windows.
@@ -68,6 +69,7 @@ def is_windows():
return platform.system() == "Windows"
+
def is_mac():
"""
Checks if we are running on Mac OSX.
@@ -77,6 +79,7 @@ def is_mac():
return platform.system() == "Darwin"
+
def is_bsd():
"""
Checks if we are within the BSD family of operating systems. This presently
@@ -87,6 +90,7 @@ def is_bsd():
return platform.system() in ("Darwin", "FreeBSD", "OpenBSD")
+
def is_available(command, cached=True):
"""
Checks the current PATH to see if a command is available or not. If more
@@ -128,6 +132,7 @@ def is_available(command, cached=True):
CMD_AVAILABLE_CACHE[command] = cmd_exists
return cmd_exists
+
def is_running(command):
"""
Checks for if a process with a given name is running or not.
@@ -169,6 +174,7 @@ def is_running(command):
return None
+
def get_pid_by_name(process_name):
"""
Attempts to determine the process id for a running process, using...
@@ -288,6 +294,7 @@ def get_pid_by_name(process_name):
log.debug("failed to resolve a pid for '%s'" % process_name)
return None
+
def get_pid_by_port(port):
"""
Attempts to determine the process id for a process with the given port,
@@ -411,6 +418,7 @@ def get_pid_by_port(port):
return None # all queries failed
+
def get_pid_by_open_file(path):
"""
Attempts to determine the process id for a process with the given open file,
@@ -448,6 +456,7 @@ def get_pid_by_open_file(path):
return None # all queries failed
+
def get_cwd(pid):
"""
Provides the working directory of the given process.
@@ -515,6 +524,7 @@ def get_cwd(pid):
return None # all queries failed
+
def get_bsd_jail_id(pid):
"""
Gets the jail id for a process. These seem to only exist for FreeBSD (this
@@ -549,6 +559,7 @@ def get_bsd_jail_id(pid):
return 0
+
def expand_path(path, cwd = None):
"""
Provides an absolute path, expanding tildes with the user's home and
@@ -593,6 +604,7 @@ def expand_path(path, cwd = None):
return relative_path
+
def call(command, default = UNDEFINED):
"""
Issues a command in a subprocess, blocking until completion and returning the
diff --git a/stem/util/term.py b/stem/util/term.py
index d77fccf..dd2a8d2 100644
--- a/stem/util/term.py
+++ b/stem/util/term.py
@@ -55,6 +55,7 @@ ATTR_ENCODING = {Attr.BOLD: "1", Attr.UNDERLINE: "4", Attr.HILIGHT: "7"}
CSI = "\x1B[%sm"
RESET = CSI % "0"
+
def format(msg, *attr):
"""
Simple terminal text formatting using `ANSI escape sequences
diff --git a/stem/util/tor_tools.py b/stem/util/tor_tools.py
index 3f15eb2..59a3a59 100644
--- a/stem/util/tor_tools.py
+++ b/stem/util/tor_tools.py
@@ -32,6 +32,7 @@ FINGERPRINT_PATTERN = re.compile("^%s{40}$" % HEX_DIGIT)
NICKNAME_PATTERN = re.compile("^[a-zA-Z0-9]{1,19}$")
CIRC_ID_PATTERN = re.compile("^[a-zA-Z0-9]{1,16}$")
+
def is_valid_fingerprint(entry, check_prefix = False):
"""
Checks if a string is a properly formatted relay fingerprint. This checks for
@@ -54,6 +55,7 @@ def is_valid_fingerprint(entry, check_prefix = False):
return bool(FINGERPRINT_PATTERN.match(entry))
+
def is_valid_nickname(entry):
"""
Checks if a string is a valid format for being a nickname.
@@ -68,6 +70,7 @@ def is_valid_nickname(entry):
return bool(NICKNAME_PATTERN.match(entry))
+
def is_valid_circuit_id(entry):
"""
Checks if a string is a valid format for being a circuit identifier.
@@ -80,6 +83,7 @@ def is_valid_circuit_id(entry):
return bool(CIRC_ID_PATTERN.match(entry))
+
def is_valid_stream_id(entry):
"""
Checks if a string is a valid format for being a stream identifier.
@@ -90,6 +94,7 @@ def is_valid_stream_id(entry):
return is_valid_circuit_id(entry)
+
def is_hex_digits(entry, count):
"""
Checks if a string is the given number of hex digits. Digits represented by
diff --git a/stem/version.py b/stem/version.py
index 76b8a88..bbbd211 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -55,6 +55,7 @@ import stem.util.system
# cache for the get_system_tor_version function
VERSION_CACHE = {}
+
def get_system_tor_version(tor_cmd = "tor"):
"""
Queries tor for its version. This is os dependent, only working on linux,
@@ -94,6 +95,7 @@ def get_system_tor_version(tor_cmd = "tor"):
return VERSION_CACHE[tor_cmd]
+
class Version(object):
"""
Comparable tor version. These are constructed from strings that conform to
@@ -205,6 +207,7 @@ class Version(object):
else:
return 0
+
class VersionRequirements(object):
"""
Series of version constraints that can be compared to. For instance, this
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index 6bbbea4..63bc1c1 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -25,6 +25,7 @@ from stem.util import system
# if ran directly then run over everything one level up
DEFAULT_TARGET = os.path.sep.join(__file__.split(os.path.sep)[:-1])
+
def pep8_issues(base_path = DEFAULT_TARGET):
"""
Checks for stylistic issues that are an issue according to the parts of PEP8
@@ -62,7 +63,7 @@ def pep8_issues(base_path = DEFAULT_TARGET):
#
# Someone else can change this if they really care.
- ignored_issues = "E111,E121,W293,E501,E302,E251,E127"
+ ignored_issues = "E111,E121,W293,E501,E251,E127"
issues = {}
pep8_output = system.call("pep8 --ignore %s %s" % (ignored_issues, base_path))
@@ -76,6 +77,7 @@ def pep8_issues(base_path = DEFAULT_TARGET):
return issues
+
def get_issues(base_path = DEFAULT_TARGET):
"""
Checks python source code in the given directory for whitespace issues.
@@ -151,6 +153,7 @@ def get_issues(base_path = DEFAULT_TARGET):
return issues
+
def _get_files_with_suffix(base_path, suffix = ".py"):
"""
Iterates over files in a given directory, providing filenames with a certain
diff --git a/test/integ/connection/authentication.py b/test/integ/connection/authentication.py
index e707b49..50bc3c0 100644
--- a/test/integ/connection/authentication.py
+++ b/test/integ/connection/authentication.py
@@ -28,6 +28,7 @@ INCORRECT_COOKIE_FAIL = "Authentication failed: Authentication cookie did not ma
INCORRECT_SAFECOOKIE_FAIL = "Authentication failed: Safe cookie response did not match expected value."
INCORRECT_PASSWORD_FAIL = "Authentication failed: Password did not match HashedControlPassword value from configuration"
+
def _can_authenticate(auth_type):
"""
Checks if a given authentication method can authenticate to our control
@@ -56,6 +57,7 @@ def _can_authenticate(auth_type):
else:
return False
+
def _get_auth_failure_message(auth_type):
"""
Provides the message that tor will respond with if our current method of
@@ -96,6 +98,7 @@ def _get_auth_failure_message(auth_type):
raise ValueError("No methods of authentication. If this is an open socket then auth shouldn't fail.")
+
class TestAuthenticate(unittest.TestCase):
def setUp(self):
self.cookie_auth_methods = [stem.connection.AuthMethod.COOKIE]
diff --git a/test/integ/connection/connect.py b/test/integ/connection/connect.py
index 66b793d..e2d3d02 100644
--- a/test/integ/connection/connect.py
+++ b/test/integ/connection/connect.py
@@ -9,6 +9,7 @@ import unittest
import stem.connection
import test.runner
+
class TestConnect(unittest.TestCase):
def setUp(self):
# prevents the function from printing to the real stdout
diff --git a/test/integ/control/base_controller.py b/test/integ/control/base_controller.py
index 25af63d..2850bd9 100644
--- a/test/integ/control/base_controller.py
+++ b/test/integ/control/base_controller.py
@@ -14,6 +14,7 @@ import test.runner
import stem.socket
import stem.util.system
+
class StateObserver(object):
"""
Simple container for listening to ControlSocket state changes and
@@ -34,6 +35,7 @@ class StateObserver(object):
self.state = state
self.timestamp = timestamp
+
class TestBaseController(unittest.TestCase):
def test_connect_repeatedly(self):
"""
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 6d91f50..a237f0a 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -27,6 +27,7 @@ import test.util
from stem.control import EventType
from stem.version import Requirement
+
class TestController(unittest.TestCase):
def test_from_port(self):
"""
diff --git a/test/integ/descriptor/__init__.py b/test/integ/descriptor/__init__.py
index 6553b2d..691d2f6 100644
--- a/test/integ/descriptor/__init__.py
+++ b/test/integ/descriptor/__init__.py
@@ -8,6 +8,7 @@ import os
DESCRIPTOR_TEST_DATA = os.path.join(os.path.dirname(__file__), "data")
+
def get_resource(filename):
"""
Provides the path for a file in our descriptor data directory.
diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py
index 1293b3c..2ef5521 100644
--- a/test/integ/descriptor/extrainfo_descriptor.py
+++ b/test/integ/descriptor/extrainfo_descriptor.py
@@ -14,6 +14,7 @@ import test.runner
from stem.descriptor.extrainfo_descriptor import DirResponse
+
class TestExtraInfoDescriptor(unittest.TestCase):
def test_metrics_relay_descriptor(self):
"""
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py
index 862c166..5442d91 100644
--- a/test/integ/descriptor/networkstatus.py
+++ b/test/integ/descriptor/networkstatus.py
@@ -14,6 +14,7 @@ import stem.descriptor.networkstatus
import stem.version
import test.integ.descriptor
+
class TestNetworkStatus(unittest.TestCase):
def test_cached_consensus(self):
"""
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index ba807f0..ec0d87e 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -27,9 +27,11 @@ DESCRIPTOR_TEST_DATA = os.path.join(my_dir, "data")
TAR_DESCRIPTORS = None
+
def _get_processed_files_path():
return test.runner.get_runner().get_test_dir("descriptor_processed_files")
+
def _make_processed_files_listing(contents):
"""
Writes the given 'processed file' listing to disk, returning the path where
@@ -44,6 +46,7 @@ def _make_processed_files_listing(contents):
return test_listing_path
+
def _get_raw_tar_descriptors():
global TAR_DESCRIPTORS
@@ -71,6 +74,7 @@ def _get_raw_tar_descriptors():
return TAR_DESCRIPTORS
+
class SkipListener:
def __init__(self):
self.results = [] # (path, exception) tuples that we've received
@@ -78,6 +82,7 @@ class SkipListener:
def listener(self, path, exception):
self.results.append((path, exception))
+
class TestDescriptorReader(unittest.TestCase):
def tearDown(self):
# cleans up 'processed file' listings that we made
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py
index b6b8e62..8cf0bd1 100644
--- a/test/integ/descriptor/server_descriptor.py
+++ b/test/integ/descriptor/server_descriptor.py
@@ -15,6 +15,7 @@ import stem.version
import test.integ.descriptor
import test.runner
+
class TestServerDescriptor(unittest.TestCase):
def test_metrics_descriptor(self):
"""
diff --git a/test/integ/process.py b/test/integ/process.py
index 6629575..0612163 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -20,6 +20,7 @@ from test import mocking
DATA_DIRECTORY = '/tmp/stem_integ'
+
def _kill_process(process):
if stem.prereq.is_python_26():
process.kill()
@@ -28,6 +29,7 @@ def _kill_process(process):
process.communicate() # block until its definitely gone
+
class TestProcess(unittest.TestCase):
def setUp(self):
if not os.path.exists(DATA_DIRECTORY):
diff --git a/test/integ/response/protocolinfo.py b/test/integ/response/protocolinfo.py
index 623ce48..b309e91 100644
--- a/test/integ/response/protocolinfo.py
+++ b/test/integ/response/protocolinfo.py
@@ -16,6 +16,7 @@ import test.runner
from test import mocking
from test.integ.util.system import filter_system_call
+
class TestProtocolInfo(unittest.TestCase):
def setUp(self):
mocking.mock(stem.util.proc.is_available, mocking.return_false())
diff --git a/test/integ/socket/control_message.py b/test/integ/socket/control_message.py
index 5c78f1a..ccceb26 100644
--- a/test/integ/socket/control_message.py
+++ b/test/integ/socket/control_message.py
@@ -11,6 +11,7 @@ import stem.socket
import stem.version
import test.runner
+
class TestControlMessage(unittest.TestCase):
def test_unestablished_socket(self):
"""
diff --git a/test/integ/socket/control_socket.py b/test/integ/socket/control_socket.py
index 13daaf4..0d6dd36 100644
--- a/test/integ/socket/control_socket.py
+++ b/test/integ/socket/control_socket.py
@@ -17,6 +17,7 @@ import stem.control
import stem.socket
import test.runner
+
class TestControlSocket(unittest.TestCase):
def test_send_buffered(self):
"""
diff --git a/test/integ/util/conf.py b/test/integ/util/conf.py
index 6fedca1..6eb1cbb 100644
--- a/test/integ/util/conf.py
+++ b/test/integ/util/conf.py
@@ -45,9 +45,11 @@ what a beautiful day.
Why are those arrows",
coming my way?!?"""
+
def _get_test_config_path():
return test.runner.get_runner().get_test_dir("integ_test_cfg")
+
def _make_config(contents):
"""
Writes a test configuration to disk, returning the path where it is located.
@@ -62,6 +64,7 @@ def _make_config(contents):
return test_config_path
+
class TestConf(unittest.TestCase):
def tearDown(self):
# clears the config contents
diff --git a/test/integ/util/proc.py b/test/integ/util/proc.py
index 557c7a8..2282831 100644
--- a/test/integ/util/proc.py
+++ b/test/integ/util/proc.py
@@ -12,6 +12,7 @@ import test.runner
from stem.util import proc
+
class TestProc(unittest.TestCase):
def test_get_cwd(self):
"""
diff --git a/test/integ/util/system.py b/test/integ/util/system.py
index 0564118..f6601fc 100644
--- a/test/integ/util/system.py
+++ b/test/integ/util/system.py
@@ -13,6 +13,7 @@ import test.runner
from test import mocking
+
def filter_system_call(prefixes):
"""
Provides a functor that passes calls on to the stem.util.system.call()
@@ -27,6 +28,7 @@ def filter_system_call(prefixes):
return _filter_system_call
+
def _has_port():
"""
True if our test runner has a control port, False otherwise.
@@ -34,6 +36,7 @@ def _has_port():
return test.runner.Torrc.PORT in test.runner.get_runner().get_options()
+
class TestSystem(unittest.TestCase):
is_extra_tor_running = None
diff --git a/test/integ/version.py b/test/integ/version.py
index 9542c63..b40537c 100644
--- a/test/integ/version.py
+++ b/test/integ/version.py
@@ -9,6 +9,7 @@ import stem.prereq
import stem.version
import test.runner
+
class TestVersion(unittest.TestCase):
def test_get_system_tor_version(self):
"""
diff --git a/test/mocking.py b/test/mocking.py
index 1ebe88d..df545dc 100644
--- a/test/mocking.py
+++ b/test/mocking.py
@@ -192,27 +192,33 @@ NETWORK_STATUS_DOCUMENT_FOOTER = (
("directory-signature", "%s %s\n%s" % (DOC_SIG.identity, DOC_SIG.key_digest, DOC_SIG.signature)),
)
+
def no_op():
def _no_op(*args):
pass
return _no_op
+
def return_value(value):
def _return_value(*args):
return value
return _return_value
+
def return_true():
return return_value(True)
+
def return_false():
return return_value(False)
+
def return_none():
return return_value(None)
+
def return_for_args(args_to_return_value, default = None, is_method = False):
"""
Returns a value if the arguments to it match something in a given
@@ -274,12 +280,14 @@ def return_for_args(args_to_return_value, default = None, is_method = False):
return _return_value
+
def raise_exception(exception):
def _raise(*args):
raise exception
return _raise
+
def support_with(obj):
"""
Provides no-op support for the 'with' keyword, adding __enter__ and __exit__
@@ -295,6 +303,7 @@ def support_with(obj):
obj.__dict__["__exit__"] = no_op()
return obj
+
def mock(target, mock_call, target_module=None):
"""
Mocks the given function, saving the initial implementation so it can be
@@ -330,6 +339,7 @@ def mock(target, mock_call, target_module=None):
else:
setattr(target_module, target.__name__, mock_call)
+
def mock_method(target_class, method_name, mock_call):
"""
Mocks the given method in target_class in a similar fashion as mock()
@@ -375,6 +385,7 @@ def mock_method(target_class, method_name, mock_call):
# mocks the function with this wrapper
setattr(target_class, method_name, mock_wrapper)
+
def revert_mocking():
"""
Reverts any mocking done by this function.
@@ -399,6 +410,7 @@ def revert_mocking():
MOCK_STATE.clear()
+
def get_real_function(function):
"""
Provides the original, non-mocked implementation for a function or method.
@@ -415,6 +427,7 @@ def get_real_function(function):
else:
return function
+
def get_all_combinations(attr, include_empty = False):
"""
Provides an iterator for all combinations of a set of attributes. For
@@ -451,6 +464,7 @@ def get_all_combinations(attr, include_empty = False):
seen.add(item)
yield item
+
def get_object(object_class, methods = None):
"""
Provides a mock instance of an arbitrary class. Its methods are mocked with
@@ -482,6 +496,7 @@ def get_object(object_class, methods = None):
return mock_class()
+
def get_message(content, reformat = True):
"""
Provides a ControlMessage with content modified to be parsable. This makes
@@ -504,6 +519,7 @@ def get_message(content, reformat = True):
return stem.socket.recv_message(StringIO.StringIO(content))
+
def get_protocolinfo_response(**attributes):
"""
Provides a ProtocolInfoResponse, customized with the given attributes. The
@@ -523,6 +539,7 @@ def get_protocolinfo_response(**attributes):
return protocolinfo_response
+
def _get_descriptor_content(attr = None, exclude = (), header_template = (), footer_template = ()):
"""
Constructs a minimal descriptor with the given attributes. The content we
@@ -595,6 +612,7 @@ def _get_descriptor_content(attr = None, exclude = (), header_template = (), foo
return "\n".join(header_content + remainder + footer_content)
+
def get_relay_server_descriptor(attr = None, exclude = (), content = False):
"""
Provides the descriptor content for...
@@ -615,6 +633,7 @@ def get_relay_server_descriptor(attr = None, exclude = (), content = False):
desc_content = sign_descriptor_content(desc_content)
return stem.descriptor.server_descriptor.RelayDescriptor(desc_content, validate = True)
+
def get_bridge_server_descriptor(attr = None, exclude = (), content = False):
"""
Provides the descriptor content for...
@@ -634,6 +653,7 @@ def get_bridge_server_descriptor(attr = None, exclude = (), content = False):
else:
return stem.descriptor.server_descriptor.BridgeDescriptor(desc_content, validate = True)
+
def get_relay_extrainfo_descriptor(attr = None, exclude = (), content = False):
"""
Provides the descriptor content for...
@@ -653,6 +673,7 @@ def get_relay_extrainfo_descriptor(attr = None, exclude = (), content = False):
else:
return stem.descriptor.extrainfo_descriptor.RelayExtraInfoDescriptor(desc_content, validate = True)
+
def get_bridge_extrainfo_descriptor(attr = None, exclude = (), content = False):
"""
Provides the descriptor content for...
@@ -672,6 +693,7 @@ def get_bridge_extrainfo_descriptor(attr = None, exclude = (), content = False):
else:
return stem.descriptor.extrainfo_descriptor.BridgeExtraInfoDescriptor(desc_content, validate = True)
+
def get_router_status_entry_v2(attr = None, exclude = (), content = False):
"""
Provides the descriptor content for...
@@ -691,6 +713,7 @@ def get_router_status_entry_v2(attr = None, exclude = (), content = False):
else:
return stem.descriptor.router_status_entry.RouterStatusEntryV2(desc_content, validate = True)
+
def get_router_status_entry_v3(attr = None, exclude = (), content = False):
"""
Provides the descriptor content for...
@@ -710,6 +733,7 @@ def get_router_status_entry_v3(attr = None, exclude = (), content = False):
else:
return stem.descriptor.router_status_entry.RouterStatusEntryV3(desc_content, validate = True)
+
def get_router_status_entry_micro_v3(attr = None, exclude = (), content = False):
"""
Provides the descriptor content for...
@@ -729,6 +753,7 @@ def get_router_status_entry_micro_v3(attr = None, exclude = (), content = False)
else:
return stem.descriptor.router_status_entry.RouterStatusEntryMicroV3(desc_content, validate = True)
+
def get_directory_authority(attr = None, exclude = (), is_vote = False, content = False):
"""
Provides the descriptor content for...
@@ -760,6 +785,7 @@ def get_directory_authority(attr = None, exclude = (), is_vote = False, content
else:
return stem.descriptor.networkstatus.DirectoryAuthority(desc_content, validate = True, is_vote = is_vote)
+
def get_key_certificate(attr = None, exclude = (), content = False):
"""
Provides the descriptor content for...
@@ -779,6 +805,7 @@ def get_key_certificate(attr = None, exclude = (), content = False):
else:
return stem.descriptor.networkstatus.KeyCertificate(desc_content, validate = True)
+
def get_network_status_document_v2(attr = None, exclude = (), routers = None, content = False):
"""
Provides the descriptor content for...
@@ -799,6 +826,7 @@ def get_network_status_document_v2(attr = None, exclude = (), routers = None, co
else:
return stem.descriptor.networkstatus.NetworkStatusDocumentV2(desc_content, validate = True)
+
def get_network_status_document_v3(attr = None, exclude = (), authorities = None, routers = None, content = False):
"""
Provides the descriptor content for...
@@ -850,6 +878,7 @@ def get_network_status_document_v3(attr = None, exclude = (), authorities = None
else:
return stem.descriptor.networkstatus.NetworkStatusDocumentV3(desc_content, validate = True)
+
def sign_descriptor_content(desc_content):
"""
Add a valid signature to the supplied descriptor string.
diff --git a/test/network.py b/test/network.py
index cab998a..74b4832 100644
--- a/test/network.py
+++ b/test/network.py
@@ -27,9 +27,11 @@ SOCKS5_NOAUTH_RESPONSE = (0x05, 0x00)
SOCKS5_CONN_BY_IPV4 = (0x05, 0x01, 0x00, 0x01)
SOCKS5_CONN_BY_NAME = (0x05, 0x01, 0x00, 0x03)
+
class ProxyError(Exception):
"Base error for proxy issues."
+
class SocksError(ProxyError):
"""
Exception raised for any problems returned by the SOCKS proxy.
@@ -59,6 +61,7 @@ class SocksError(ProxyError):
code = self.code
return "[%s] %s" % (code, self._ERROR_MESSAGE[code])
+
class Socks(_socket_socket):
"""
A **socket.socket**-like interface through a SOCKS5 proxy connection.
@@ -218,6 +221,7 @@ class Socks(_socket_socket):
raise NotImplementedError
+
class SocksPatch(object):
"""
Monkey-patch **socket.socket** to use :class:`~test.network.Socks`, instead.
diff --git a/test/output.py b/test/output.py
index cadf071..0a3f9da 100644
--- a/test/output.py
+++ b/test/output.py
@@ -36,22 +36,26 @@ LINE_ATTR = {
LineType.CONTENT: (term.Color.CYAN,),
}
+
def print_line(msg, *attr):
if CONFIG["argument.no_color"]:
print msg
else:
print term.format(msg, *attr)
+
def print_noline(msg, *attr):
if CONFIG["argument.no_color"]:
sys.stdout.write(msg)
else:
sys.stdout.write(term.format(msg, *attr))
+
def print_divider(msg, is_header = False):
attr = HEADER_ATTR if is_header else CATEGORY_ATTR
print_line("%s\n%s\n%s\n" % (DIVIDER, msg.center(70), DIVIDER), *attr)
+
def print_logging(logging_buffer):
if not logging_buffer.is_empty():
for entry in logging_buffer:
@@ -59,6 +63,7 @@ def print_logging(logging_buffer):
print
+
def print_config(test_config):
print_divider("TESTING CONFIG", True)
print_line("Test configuration... ", term.Color.BLUE, term.Attr.BOLD)
@@ -74,6 +79,7 @@ def print_config(test_config):
print
+
def apply_filters(testing_output, *filters):
"""
Gets the tests results, possibly processed through a series of filters. The
@@ -111,6 +117,7 @@ def apply_filters(testing_output, *filters):
return "\n".join(results) + "\n"
+
def colorize(line_type, line_content):
"""
Applies escape sequences so each line is colored according to its type.
@@ -121,6 +128,7 @@ def colorize(line_type, line_content):
else:
return term.format(line_content, *LINE_ATTR[line_type])
+
def strip_module(line_type, line_content):
"""
Removes the module name from testing output. This information tends to be
@@ -134,6 +142,7 @@ def strip_module(line_type, line_content):
return line_content
+
def align_results(line_type, line_content):
"""
Strips the normal test results, and adds a right aligned variant instead with
@@ -168,6 +177,7 @@ def align_results(line_type, line_content):
else:
return "%-61s[%s]" % (line_content, term.format(new_ending, term.Attr.BOLD))
+
class ErrorTracker(object):
"""
Stores any failure or error results we've encountered.
diff --git a/test/prompt.py b/test/prompt.py
index afbd743..2d5219d 100644
--- a/test/prompt.py
+++ b/test/prompt.py
@@ -27,6 +27,7 @@ CONTROL_PORT = 2779
STOP_CONFIRMATION = "Would you like to stop the tor instance we made? (y/n, default: n): "
+
def print_usage():
"""
Provides a welcoming message.
@@ -36,6 +37,7 @@ def print_usage():
print "via the 'controller' variable."
print
+
def start():
"""
Starts up a tor instance that we can attach a controller to.
@@ -51,6 +53,7 @@ def start():
stem.process.launch_tor_with_config(config = tor_config, completion_percent = 5)
sys.stdout.write(" done\n\n")
+
def stop(prompt = False):
"""
Stops the tor instance spawned by this module.
@@ -69,6 +72,7 @@ def stop(prompt = False):
os.kill(tor_pid, signal.SIGTERM)
+
def is_running():
"""
Checks if we're likely running a tor instance spawned by this module. This is
@@ -80,6 +84,7 @@ def is_running():
return bool(stem.util.system.get_pid_by_port(CONTROL_PORT))
+
def controller():
"""
Provides a Controller for our tor instance. This starts tor if it isn't
diff --git a/test/runner.py b/test/runner.py
index dbfed24..bba9e78 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -100,12 +100,15 @@ Torrc = stem.util.enum.Enum(
# (test_instance, test_name) tuples that we've registered as having been ran
RAN_TESTS = []
+
class RunnerStopped(Exception):
"Raised when we try to use a Runner that doesn't have an active tor instance"
+
class TorInaccessable(Exception):
"Raised when information is needed from tor but the instance we have is inaccessible"
+
def skip(test_case, message):
"""
Skips the test if we can. The capability for skipping tests was added in
@@ -119,6 +122,7 @@ def skip(test_case, message):
if stem.prereq.is_python_27():
test_case.skipTest(message)
+
def require_control(test_case):
"""
Skips the test unless tor provides an endpoint for controllers to attach to.
@@ -132,6 +136,7 @@ def require_control(test_case):
skip(test_case, "(no connection)")
return True
+
def require_version(test_case, req_version):
"""
Skips the test unless we meet the required version.
@@ -146,6 +151,7 @@ def require_version(test_case, req_version):
skip(test_case, "(requires %s)" % req_version)
return True
+
def require_online(test_case):
"""
Skips the test if we weren't started with the ONLINE target, which indicates
@@ -160,6 +166,7 @@ def require_online(test_case):
skip(test_case, "(requires online target)")
return True
+
def only_run_once(test_case, test_name):
"""
Skips the test if it has ran before. If it hasn't then flags it as being ran.
@@ -178,6 +185,7 @@ def only_run_once(test_case, test_name):
else:
RAN_TESTS.append((test_case, test_name))
+
def exercise_controller(test_case, controller):
"""
Checks that we can now use the socket by issuing a 'GETINFO config-file'
@@ -199,6 +207,7 @@ def exercise_controller(test_case, controller):
test_case.assertEquals("config-file=%s\nOK" % torrc_path, str(config_file_response))
+
def get_runner():
"""
Singleton for the runtime context of integration tests.
@@ -213,6 +222,7 @@ def get_runner():
return INTEG_RUNNER
+
class _MockChrootFile(object):
"""
Wrapper around a file object that strips given content from readline()
@@ -227,6 +237,7 @@ class _MockChrootFile(object):
def readline(self):
return self.wrapped_file.readline().replace(self.strip_text, "")
+
class Runner(object):
def __init__(self):
self._runner_lock = threading.RLock()
diff --git a/test/unit/connection/authentication.py b/test/unit/connection/authentication.py
index 0c05f21..05818b4 100644
--- a/test/unit/connection/authentication.py
+++ b/test/unit/connection/authentication.py
@@ -16,6 +16,7 @@ import stem.connection
from stem.util import log
from test import mocking
+
class TestAuthenticate(unittest.TestCase):
def setUp(self):
mocking.mock(stem.connection.get_protocolinfo, mocking.no_op())
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index 34b98a5..7cb14b7 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -14,6 +14,7 @@ from stem.control import _parse_circ_path, Controller, EventType
from stem.response import events
from test import mocking
+
class TestControl(unittest.TestCase):
def setUp(self):
socket = stem.socket.ControlSocket()
diff --git a/test/unit/descriptor/export.py b/test/unit/descriptor/export.py
index bd25c6e..12c6e56 100644
--- a/test/unit/descriptor/export.py
+++ b/test/unit/descriptor/export.py
@@ -11,6 +11,7 @@ import test.runner
from stem.descriptor.export import export_csv, export_csv_file
from test.mocking import get_relay_server_descriptor, get_bridge_server_descriptor
+
class TestExport(unittest.TestCase):
def test_minimal_descriptor(self):
"""
diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py
index 4ef0276..382aaee 100644
--- a/test/unit/descriptor/extrainfo_descriptor.py
+++ b/test/unit/descriptor/extrainfo_descriptor.py
@@ -8,6 +8,7 @@ import unittest
from stem.descriptor.extrainfo_descriptor import RelayExtraInfoDescriptor, DirResponse, DirStat
from test.mocking import get_relay_extrainfo_descriptor, get_bridge_extrainfo_descriptor, CRYPTO_BLOB
+
class TestExtraInfoDescriptor(unittest.TestCase):
def test_minimal_extrainfo_descriptor(self):
"""
diff --git a/test/unit/descriptor/networkstatus/directory_authority.py b/test/unit/descriptor/networkstatus/directory_authority.py
index 68e4713..f3d7fe1 100644
--- a/test/unit/descriptor/networkstatus/directory_authority.py
+++ b/test/unit/descriptor/networkstatus/directory_authority.py
@@ -9,6 +9,7 @@ import test.runner
from stem.descriptor.networkstatus import DirectoryAuthority
from test.mocking import get_directory_authority, get_key_certificate, AUTHORITY_HEADER
+
class TestDirectoryAuthority(unittest.TestCase):
def test_minimal_consensus_authority(self):
"""
diff --git a/test/unit/descriptor/networkstatus/document_v2.py b/test/unit/descriptor/networkstatus/document_v2.py
index 88561e6..9412cf9 100644
--- a/test/unit/descriptor/networkstatus/document_v2.py
+++ b/test/unit/descriptor/networkstatus/document_v2.py
@@ -7,6 +7,7 @@ import unittest
from test.mocking import get_network_status_document_v2, NETWORK_STATUS_DOCUMENT_HEADER_V2, NETWORK_STATUS_DOCUMENT_FOOTER_V2
+
class TestNetworkStatusDocument(unittest.TestCase):
def test_minimal_document(self):
"""
diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py
index 0ab5694..f2d0bf1 100644
--- a/test/unit/descriptor/networkstatus/document_v3.py
+++ b/test/unit/descriptor/networkstatus/document_v3.py
@@ -33,6 +33,7 @@ from test.mocking import support_with, \
DOC_SIG, \
NETWORK_STATUS_DOCUMENT_FOOTER
+
class TestNetworkStatusDocument(unittest.TestCase):
def test_minimal_consensus(self):
"""
diff --git a/test/unit/descriptor/networkstatus/key_certificate.py b/test/unit/descriptor/networkstatus/key_certificate.py
index fdd90c5..c91c9e3 100644
--- a/test/unit/descriptor/networkstatus/key_certificate.py
+++ b/test/unit/descriptor/networkstatus/key_certificate.py
@@ -12,6 +12,7 @@ from test.mocking import get_key_certificate, \
KEY_CERTIFICATE_HEADER, \
KEY_CERTIFICATE_FOOTER
+
class TestKeyCertificate(unittest.TestCase):
def test_minimal(self):
"""
diff --git a/test/unit/descriptor/reader.py b/test/unit/descriptor/reader.py
index 4ae0aff..985c129 100644
--- a/test/unit/descriptor/reader.py
+++ b/test/unit/descriptor/reader.py
@@ -8,6 +8,7 @@ import unittest
import stem.descriptor.reader
import test.mocking as mocking
+
class TestDescriptorReader(unittest.TestCase):
def tearDown(self):
mocking.revert_mocking()
diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py
index 9565702..e35174c 100644
--- a/test/unit/descriptor/router_status_entry.py
+++ b/test/unit/descriptor/router_status_entry.py
@@ -15,6 +15,7 @@ from test.mocking import get_router_status_entry_v2, \
get_router_status_entry_micro_v3, \
ROUTER_STATUS_ENTRY_V3_HEADER
+
class TestRouterStatusEntry(unittest.TestCase):
def test_fingerprint_decoding(self):
"""
diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py
index e3f4e78..bb49c02 100644
--- a/test/unit/descriptor/server_descriptor.py
+++ b/test/unit/descriptor/server_descriptor.py
@@ -18,6 +18,7 @@ from test.mocking import get_relay_server_descriptor, \
CRYPTO_BLOB, \
sign_descriptor_content
+
class TestServerDescriptor(unittest.TestCase):
def test_minimal_relay_descriptor(self):
"""
diff --git a/test/unit/exit_policy/policy.py b/test/unit/exit_policy/policy.py
index dce4cb7..f4cc499 100644
--- a/test/unit/exit_policy/policy.py
+++ b/test/unit/exit_policy/policy.py
@@ -8,6 +8,7 @@ from stem.exit_policy import ExitPolicy, \
MicroExitPolicy, \
ExitPolicyRule
+
class TestExitPolicy(unittest.TestCase):
def test_example(self):
# tests the ExitPolicy and MicroExitPolicy pydoc examples
diff --git a/test/unit/exit_policy/rule.py b/test/unit/exit_policy/rule.py
index 538418d..176ad26 100644
--- a/test/unit/exit_policy/rule.py
+++ b/test/unit/exit_policy/rule.py
@@ -6,6 +6,7 @@ import unittest
from stem.exit_policy import AddressType, ExitPolicyRule
+
class TestExitPolicyRule(unittest.TestCase):
def test_accept_or_reject(self):
self.assertTrue(ExitPolicyRule("accept *:*").is_accept)
diff --git a/test/unit/response/authchallenge.py b/test/unit/response/authchallenge.py
index 0583d04..314b953 100644
--- a/test/unit/response/authchallenge.py
+++ b/test/unit/response/authchallenge.py
@@ -20,6 +20,7 @@ INVALID_RESPONSE = "250 AUTHCHALLENGE \
SERVERHASH=FOOBARB16F72DACD4B5ED1531F3FCC04B593D46A1E30267E636EA7C7F8DD7A2B7BAA05 \
SERVERNONCE=FOOBAR653574272ABBB49395BD1060D642D653CFB7A2FCE6A4955BCFED819703A9998C"
+
class TestAuthChallengeResponse(unittest.TestCase):
def test_valid_response(self):
"""
diff --git a/test/unit/response/control_line.py b/test/unit/response/control_line.py
index 546a410..993afcb 100644
--- a/test/unit/response/control_line.py
+++ b/test/unit/response/control_line.py
@@ -14,6 +14,7 @@ PROTOCOLINFO_RESPONSE = (
'OK',
)
+
class TestControlLine(unittest.TestCase):
def test_pop_examples(self):
"""
diff --git a/test/unit/response/control_message.py b/test/unit/response/control_message.py
index 4a55c98..8c9ece7 100644
--- a/test/unit/response/control_message.py
+++ b/test/unit/response/control_message.py
@@ -30,6 +30,7 @@ version -- The current version of Tor.
250 OK
""".replace("\n", "\r\n")
+
class TestControlMessage(unittest.TestCase):
def test_ok_response(self):
"""
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index adc055c..4473c2a 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -308,6 +308,7 @@ def _get_event(content):
stem.response.convert("EVENT", controller_event, arrived_at = 25)
return controller_event
+
class TestEvents(unittest.TestCase):
def test_example(self):
"""
diff --git a/test/unit/response/getconf.py b/test/unit/response/getconf.py
index a072738..171fc8c 100644
--- a/test/unit/response/getconf.py
+++ b/test/unit/response/getconf.py
@@ -35,6 +35,7 @@ INVALID_RESPONSE = """\
123-FOO
232 BAR"""
+
class TestGetConfResponse(unittest.TestCase):
def test_empty_response(self):
"""
diff --git a/test/unit/response/getinfo.py b/test/unit/response/getinfo.py
index 589d7b9..2fa4f6e 100644
--- a/test/unit/response/getinfo.py
+++ b/test/unit/response/getinfo.py
@@ -49,6 +49,7 @@ DataDirectory /home/atagar/.tor
.
250 OK"""
+
class TestGetInfoResponse(unittest.TestCase):
def test_empty_response(self):
"""
diff --git a/test/unit/response/mapaddress.py b/test/unit/response/mapaddress.py
index c3e0b18..23faa6b 100644
--- a/test/unit/response/mapaddress.py
+++ b/test/unit/response/mapaddress.py
@@ -29,6 +29,7 @@ UNRECOGNIZED_KEYS_RESPONSE = "512 syntax error: mapping '2389' is not of expecte
FAILED_RESPONSE = "451 Resource exhausted"
+
class TestMapAddressResponse(unittest.TestCase):
def test_single_response(self):
"""
diff --git a/test/unit/response/protocolinfo.py b/test/unit/response/protocolinfo.py
index 28cd212..0a209f9 100644
--- a/test/unit/response/protocolinfo.py
+++ b/test/unit/response/protocolinfo.py
@@ -48,6 +48,7 @@ RELATIVE_COOKIE_PATH = r"""250-PROTOCOLINFO 1
250-VERSION Tor="0.2.1.30"
250 OK"""
+
class TestProtocolInfoResponse(unittest.TestCase):
def test_convert(self):
"""
diff --git a/test/unit/response/singleline.py b/test/unit/response/singleline.py
index e3b68e5..d48dee2 100644
--- a/test/unit/response/singleline.py
+++ b/test/unit/response/singleline.py
@@ -12,6 +12,7 @@ from test import mocking
MULTILINE_RESPONSE = """250-MULTI
250 LINE"""
+
class TestSingleLineResponse(unittest.TestCase):
def test_single_line_response(self):
message = mocking.get_message("552 NOTOK")
diff --git a/test/unit/tutorial.py b/test/unit/tutorial.py
index 47e8107..b0a1588 100644
--- a/test/unit/tutorial.py
+++ b/test/unit/tutorial.py
@@ -8,6 +8,7 @@ import unittest
from test import mocking
+
class TestTutorial(unittest.TestCase):
def tearDown(self):
mocking.revert_mocking()
diff --git a/test/unit/util/conf.py b/test/unit/util/conf.py
index 4e70c1d..5c4e094 100644
--- a/test/unit/util/conf.py
+++ b/test/unit/util/conf.py
@@ -9,6 +9,7 @@ import stem.util.enum
from stem.util.conf import parse_enum, parse_enum_csv
+
class TestConf(unittest.TestCase):
def tearDown(self):
# clears the config contents
diff --git a/test/unit/util/connection.py b/test/unit/util/connection.py
index 358ab49..5f4e62d 100644
--- a/test/unit/util/connection.py
+++ b/test/unit/util/connection.py
@@ -6,6 +6,7 @@ import unittest
import stem.util.connection
+
class TestConnection(unittest.TestCase):
def test_is_valid_ip_address(self):
"""
diff --git a/test/unit/util/enum.py b/test/unit/util/enum.py
index 1b33296..2eae439 100644
--- a/test/unit/util/enum.py
+++ b/test/unit/util/enum.py
@@ -6,6 +6,7 @@ import unittest
import stem.util.enum
+
class TestEnum(unittest.TestCase):
def test_enum_examples(self):
"""
diff --git a/test/unit/util/proc.py b/test/unit/util/proc.py
index 85aff2f..ded149f 100644
--- a/test/unit/util/proc.py
+++ b/test/unit/util/proc.py
@@ -9,6 +9,7 @@ import unittest
from stem.util import proc
from test import mocking
+
class TestProc(unittest.TestCase):
def tearDown(self):
mocking.revert_mocking()
diff --git a/test/unit/util/str_tools.py b/test/unit/util/str_tools.py
index c1c5ee8..6b10ade 100644
--- a/test/unit/util/str_tools.py
+++ b/test/unit/util/str_tools.py
@@ -7,6 +7,7 @@ import unittest
from stem.util import str_tools
+
class TestStrTools(unittest.TestCase):
def test_to_camel_case(self):
"""
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index e780375..2f1f6e1 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -56,6 +56,7 @@ GET_PID_BY_PORT_LSOF_RESULTS = [
"tor 1745 atagar 6u IPv4 14229 0t0 TCP 127.0.0.1:9051 (LISTEN)",
"apache 329 atagar 6u IPv4 14229 0t0 TCP 127.0.0.1:80 (LISTEN)"]
+
def mock_call(base_cmd, responses):
"""
Provides mocking for the system module's call function. There are a couple
@@ -93,6 +94,7 @@ def mock_call(base_cmd, responses):
return functools.partial(_mock_call, base_cmd, responses)
+
class TestSystem(unittest.TestCase):
def setUp(self):
mocking.mock(stem.util.proc.is_available, mocking.return_false())
diff --git a/test/unit/util/tor_tools.py b/test/unit/util/tor_tools.py
index 59f448b..634a57b 100644
--- a/test/unit/util/tor_tools.py
+++ b/test/unit/util/tor_tools.py
@@ -6,6 +6,7 @@ import unittest
import stem.util.tor_tools
+
class TestTorTools(unittest.TestCase):
def test_is_valid_fingerprint(self):
"""
diff --git a/test/unit/version.py b/test/unit/version.py
index 78a1a49..95aa690 100644
--- a/test/unit/version.py
+++ b/test/unit/version.py
@@ -15,6 +15,7 @@ TOR_VERSION_OUTPUT = """Mar 22 23:09:37.088 [notice] Tor v0.2.2.35 \
strong anonymity. (Running on Linux i686)
Tor version 0.2.2.35 (git-73ff13ab3cc9570d)."""
+
class TestVersion(unittest.TestCase):
def tearDown(self):
mocking.revert_mocking()
diff --git a/test/util.py b/test/util.py
index db6f53c..597dca5 100644
--- a/test/util.py
+++ b/test/util.py
@@ -18,6 +18,7 @@ Accept-Encoding: identity
"""
+
def external_ip(host, port):
"""
Returns the externally visible IP address when using a SOCKS4a proxy.
@@ -51,6 +52,7 @@ def external_ip(host, port):
except Exception, exc:
return None
+
def negotiate_socks(sock, host, port):
"""
Negotiate with a socks4a server. Closes the socket and raises an exception on
1
0

07 Jan '13
commit 82a2994d21120b7505c7ebc9f78fbf6774843f35
Author: Damian Johnson <atagar(a)torproject.org>
Date: Sun Jan 6 22:15:58 2013 -0800
Conforming to W391 (blank line at end of file)
I've been including an empty line at the end of files since it makes it a bit
easier for me to work with via vim. I don't care overly much though so
appeasing pip8.
---
run_tests.py | 1 -
stem/__init__.py | 1 -
stem/control.py | 1 -
stem/descriptor/__init__.py | 1 -
stem/descriptor/export.py | 1 -
stem/descriptor/extrainfo_descriptor.py | 1 -
stem/descriptor/networkstatus.py | 1 -
stem/descriptor/reader.py | 1 -
stem/descriptor/router_status_entry.py | 1 -
stem/descriptor/server_descriptor.py | 1 -
stem/exit_policy.py | 1 -
stem/prereq.py | 1 -
stem/process.py | 1 -
stem/response/__init__.py | 1 -
stem/response/authchallenge.py | 1 -
stem/response/events.py | 1 -
stem/response/getconf.py | 1 -
stem/response/getinfo.py | 1 -
stem/response/mapaddress.py | 1 -
stem/response/protocolinfo.py | 1 -
stem/socket.py | 1 -
stem/util/__init__.py | 1 -
stem/util/conf.py | 1 -
stem/util/connection.py | 1 -
stem/util/enum.py | 1 -
stem/util/log.py | 1 -
stem/util/ordereddict.py | 1 -
stem/util/proc.py | 1 -
stem/util/str_tools.py | 1 -
stem/util/system.py | 1 -
stem/util/term.py | 1 -
stem/util/tor_tools.py | 1 -
stem/version.py | 1 -
test/__init__.py | 1 -
test/check_whitespace.py | 3 +--
test/integ/__init__.py | 1 -
test/integ/connection/__init__.py | 1 -
test/integ/connection/authentication.py | 1 -
test/integ/connection/connect.py | 1 -
test/integ/control/__init__.py | 1 -
test/integ/control/base_controller.py | 1 -
test/integ/control/controller.py | 1 -
test/integ/descriptor/__init__.py | 1 -
test/integ/descriptor/extrainfo_descriptor.py | 1 -
test/integ/descriptor/networkstatus.py | 1 -
test/integ/descriptor/reader.py | 1 -
test/integ/descriptor/server_descriptor.py | 1 -
test/integ/process.py | 1 -
test/integ/response/__init__.py | 1 -
test/integ/response/protocolinfo.py | 1 -
test/integ/socket/__init__.py | 1 -
test/integ/socket/control_message.py | 1 -
test/integ/socket/control_socket.py | 1 -
test/integ/util/__init__.py | 1 -
test/integ/util/conf.py | 1 -
test/integ/util/proc.py | 1 -
test/integ/util/system.py | 1 -
test/integ/version.py | 1 -
test/mocking.py | 1 -
test/network.py | 1 -
test/output.py | 1 -
test/prompt.py | 1 -
test/runner.py | 1 -
test/unit/__init__.py | 1 -
test/unit/connection/__init__.py | 1 -
test/unit/connection/authentication.py | 1 -
test/unit/control/__init__.py | 1 -
test/unit/control/controller.py | 1 -
test/unit/descriptor/__init__.py | 1 -
test/unit/descriptor/export.py | 1 -
test/unit/descriptor/extrainfo_descriptor.py | 1 -
test/unit/descriptor/networkstatus/__init__.py | 1 -
.../networkstatus/directory_authority.py | 1 -
test/unit/descriptor/networkstatus/document_v2.py | 1 -
test/unit/descriptor/networkstatus/document_v3.py | 1 -
.../descriptor/networkstatus/key_certificate.py | 1 -
test/unit/descriptor/reader.py | 1 -
test/unit/descriptor/router_status_entry.py | 1 -
test/unit/descriptor/server_descriptor.py | 1 -
test/unit/exit_policy/__init__.py | 1 -
test/unit/exit_policy/policy.py | 1 -
test/unit/exit_policy/rule.py | 1 -
test/unit/response/__init__.py | 1 -
test/unit/response/authchallenge.py | 1 -
test/unit/response/control_line.py | 1 -
test/unit/response/control_message.py | 1 -
test/unit/response/events.py | 1 -
test/unit/response/getconf.py | 1 -
test/unit/response/getinfo.py | 1 -
test/unit/response/mapaddress.py | 1 -
test/unit/response/protocolinfo.py | 1 -
test/unit/response/singleline.py | 1 -
test/unit/tutorial.py | 1 -
test/unit/util/__init__.py | 1 -
test/unit/util/conf.py | 1 -
test/unit/util/connection.py | 1 -
test/unit/util/enum.py | 1 -
test/unit/util/proc.py | 1 -
test/unit/util/str_tools.py | 1 -
test/unit/util/system.py | 1 -
test/unit/util/tor_tools.py | 1 -
test/unit/version.py | 1 -
test/util.py | 1 -
103 files changed, 1 insertions(+), 104 deletions(-)
diff --git a/run_tests.py b/run_tests.py
index d005817..c17898b 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -501,4 +501,3 @@ if __name__ == '__main__':
else:
test.output.print_line("TESTING PASSED %s" % runtime_label, term.Color.GREEN, term.Attr.BOLD)
print
-
diff --git a/stem/__init__.py b/stem/__init__.py
index 5fd34ab..f02897c 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -650,4 +650,3 @@ TimeoutSetType = stem.util.enum.UppercaseEnum(
"DISCARD",
"RESUME",
)
-
diff --git a/stem/control.py b/stem/control.py
index 6435c38..c1f1114 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -1978,4 +1978,3 @@ def _case_insensitive_lookup(entries, key, default = UNDEFINED):
if default != UNDEFINED: return default
else: raise ValueError("key '%s' doesn't exist in dict: %s" % (key, entries))
-
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 98388a3..ed74b1f 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -346,4 +346,3 @@ def _get_descriptor_components(raw_contents, validate, extra_keywords = ()):
return entries, extra_entries
else:
return entries
-
diff --git a/stem/descriptor/export.py b/stem/descriptor/export.py
index 2231122..becc72f 100644
--- a/stem/descriptor/export.py
+++ b/stem/descriptor/export.py
@@ -98,4 +98,3 @@ def export_csv_file(output_file, descriptors, included_fields = (), excluded_fie
raise ValueError("To export a descriptor CSV all of the descriptors must be of the same type. First descriptor was a %s but we later got a %s." % (descriptor_type_label, type(desc)))
writer.writerow(vars(desc))
-
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 25c9a82..0976943 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -880,4 +880,3 @@ class BridgeExtraInfoDescriptor(ExtraInfoDescriptor):
def _last_keyword(self):
return None
-
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index 5643fe0..40b3257 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -1259,4 +1259,3 @@ class DocumentSignature(object):
elif getattr(self, attr) < getattr(other, attr): return -1
return 0
-
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index c1c32ed..6069bfa 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -537,4 +537,3 @@ class DescriptorReader(object):
def __exit__(self, exit_type, value, traceback):
self.stop()
-
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 57b018a..bc6aa46 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -643,4 +643,3 @@ def _decode_fingerprint(identity, validate):
raise ValueError("Decoded '%s' to be '%s', which isn't a valid fingerprint" % (identity, fingerprint))
return fingerprint
-
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index a1b486d..da9715d 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -888,4 +888,3 @@ class BridgeDescriptor(ServerDescriptor):
return 1
return str(self).strip() > str(other).strip()
-
diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index f39fc75..eb34e97 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -718,4 +718,3 @@ class MicroExitPolicyRule(ExitPolicyRule):
def get_masked_bits(self):
return None
-
diff --git a/stem/prereq.py b/stem/prereq.py
index 072900a..e3b4fdc 100644
--- a/stem/prereq.py
+++ b/stem/prereq.py
@@ -86,4 +86,3 @@ def _check_version(minor_req):
return False
return True
-
diff --git a/stem/process.py b/stem/process.py
index a27c68e..6698c99 100644
--- a/stem/process.py
+++ b/stem/process.py
@@ -218,4 +218,3 @@ def launch_tor_with_config(config, tor_cmd = "tor", completion_percent = 100, in
def _get_pid():
return str(os.getpid())
-
diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index b838bd7..1b7387b 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -480,4 +480,3 @@ class SingleLineResponse(ControlMessage):
raise stem.ProtocolError("Received empty response")
else:
self.code, _, self.message = content[0]
-
diff --git a/stem/response/authchallenge.py b/stem/response/authchallenge.py
index 25573da..cdc0ad4 100644
--- a/stem/response/authchallenge.py
+++ b/stem/response/authchallenge.py
@@ -49,4 +49,3 @@ class AuthChallengeResponse(stem.response.ControlMessage):
self.server_nonce = binascii.a2b_hex(value)
else:
raise stem.ProtocolError("Missing SERVERNONCE mapping: %s" % line)
-
diff --git a/stem/response/events.py b/stem/response/events.py
index c8e10f3..7ba077f 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -852,4 +852,3 @@ EVENT_TYPE_TO_CLASS = {
# accounting for a bug in tor 0.2.0.22
"STATUS_SEVER": StatusEvent,
}
-
diff --git a/stem/response/getconf.py b/stem/response/getconf.py
index f8d55e7..6e96c83 100644
--- a/stem/response/getconf.py
+++ b/stem/response/getconf.py
@@ -53,4 +53,3 @@ class GetConfResponse(stem.response.ControlMessage):
if value is not None:
self.entries[key].append(value)
-
diff --git a/stem/response/getinfo.py b/stem/response/getinfo.py
index e68d4ae..3ef418b 100644
--- a/stem/response/getinfo.py
+++ b/stem/response/getinfo.py
@@ -69,4 +69,3 @@ class GetInfoResponse(stem.response.ControlMessage):
reply_label = ", ".join(reply_params)
raise stem.ProtocolError("GETINFO reply doesn't match the parameters that we requested. Queried '%s' but got '%s'." % (requested_label, reply_label))
-
diff --git a/stem/response/mapaddress.py b/stem/response/mapaddress.py
index a6542ff..d30ccfa 100644
--- a/stem/response/mapaddress.py
+++ b/stem/response/mapaddress.py
@@ -36,4 +36,3 @@ class MapAddressResponse(stem.response.ControlMessage):
self.entries[key] = value
except ValueError:
raise stem.ProtocolError(None, "MAPADDRESS returned '%s', which isn't a mapping" % message)
-
diff --git a/stem/response/protocolinfo.py b/stem/response/protocolinfo.py
index 0530717..65a2d02 100644
--- a/stem/response/protocolinfo.py
+++ b/stem/response/protocolinfo.py
@@ -116,4 +116,3 @@ class ProtocolInfoResponse(stem.response.ControlMessage):
self.auth_methods = tuple(auth_methods)
self.unknown_auth_methods = tuple(unknown_auth_methods)
-
diff --git a/stem/socket.py b/stem/socket.py
index adfc83e..2055991 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -563,4 +563,3 @@ def send_formatting(message):
return "+%s\r\n.\r\n" % message.replace("\n", "\r\n")
else:
return message + "\r\n"
-
diff --git a/stem/util/__init__.py b/stem/util/__init__.py
index d371629..53741ae 100644
--- a/stem/util/__init__.py
+++ b/stem/util/__init__.py
@@ -13,4 +13,3 @@ __all__ = [
"term",
"tor_tools",
]
-
diff --git a/stem/util/conf.py b/stem/util/conf.py
index 2a6623b..05d3796 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -647,4 +647,3 @@ class Config(object):
message_id = "stem.util.conf.missing_config_key_%s" % key
log.log_once(message_id, log.TRACE, "config entry '%s' not found, defaulting to '%s'" % (key, default))
return default
-
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 91614b7..8eefea2 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -281,4 +281,3 @@ def cryptovariables_equal(x, y):
return (
hmac_sha256(CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE, x) ==
hmac_sha256(CRYPTOVARIABLE_EQUALITY_COMPARISON_NONCE, y))
-
diff --git a/stem/util/enum.py b/stem/util/enum.py
index f120e5c..e07772d 100644
--- a/stem/util/enum.py
+++ b/stem/util/enum.py
@@ -166,4 +166,3 @@ class Enum(object):
for entry in self._values:
yield entry
-
diff --git a/stem/util/log.py b/stem/util/log.py
index 88b4bd6..c2f7912 100644
--- a/stem/util/log.py
+++ b/stem/util/log.py
@@ -202,4 +202,3 @@ def log_to_stdout(runlevel):
"""
get_logger().addHandler(_StdoutLogger(runlevel))
-
diff --git a/stem/util/ordereddict.py b/stem/util/ordereddict.py
index 4466097..778a534 100644
--- a/stem/util/ordereddict.py
+++ b/stem/util/ordereddict.py
@@ -127,4 +127,3 @@ class OrderedDict(dict, DictMixin):
def __ne__(self, other):
return not self == other
-
diff --git a/stem/util/proc.py b/stem/util/proc.py
index 56b2928..bfb771e 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -455,4 +455,3 @@ def _log_failure(parameter, exc):
"""
log.debug("proc call failed (%s): %s" % (parameter, exc))
-
diff --git a/stem/util/str_tools.py b/stem/util/str_tools.py
index ca4f44d..b1e854d 100644
--- a/stem/util/str_tools.py
+++ b/stem/util/str_tools.py
@@ -314,4 +314,3 @@ def _get_label(units, count, decimal, is_long):
return count_label + long_label + ("s" if is_plural else "")
else:
return count_label + short_label
-
diff --git a/stem/util/system.py b/stem/util/system.py
index bfdeb14..9e7aaa2 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -604,4 +604,3 @@ def call(command, default = UNDEFINED):
if default != UNDEFINED: return default
else: raise exc
-
diff --git a/stem/util/term.py b/stem/util/term.py
index d0bb02b..05b51e3 100644
--- a/stem/util/term.py
+++ b/stem/util/term.py
@@ -89,4 +89,3 @@ def format(msg, *attr):
if encodings:
return (CSI % ";".join(encodings)) + msg + RESET
else: return msg
-
diff --git a/stem/util/tor_tools.py b/stem/util/tor_tools.py
index c28bc64..d7a785a 100644
--- a/stem/util/tor_tools.py
+++ b/stem/util/tor_tools.py
@@ -100,4 +100,3 @@ def is_hex_digits(entry, count):
"""
return bool(re.match("^%s{%i}$" % (HEX_DIGIT, count), entry))
-
diff --git a/stem/version.py b/stem/version.py
index 7bcd289..43c96ba 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -266,4 +266,3 @@ Requirement = stem.util.enum.Enum(
("FEATURE_VERBOSE_NAMES", Version("0.2.2.1-alpha")),
("FEATURE_EXTENDED_EVENTS", Version("0.2.2.1-alpha")),
)
-
diff --git a/test/__init__.py b/test/__init__.py
index 2f35bf7..43fdd7f 100644
--- a/test/__init__.py
+++ b/test/__init__.py
@@ -12,4 +12,3 @@ __all__ = [
"tutorial",
"utils",
]
-
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index 61ad69c..bda512e 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -54,7 +54,7 @@ def pep8_issues(base_path = DEFAULT_TARGET):
# Pep8 only works with this one if we have four space indents (its
# detection is based on multiples of four).
- ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E261,W391,E127"
+ ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E261,E127"
issues = {}
pep8_output = system.call("pep8 --ignore %s %s" % (ignored_issues, base_path))
@@ -172,4 +172,3 @@ if __name__ == '__main__':
print " line %s %s" % (line_count, msg)
print
-
diff --git a/test/integ/__init__.py b/test/integ/__init__.py
index d57f031..5779e3f 100644
--- a/test/integ/__init__.py
+++ b/test/integ/__init__.py
@@ -12,4 +12,3 @@ __all__ = [
"process",
"version",
]
-
diff --git a/test/integ/connection/__init__.py b/test/integ/connection/__init__.py
index eec60e6..134dbe1 100644
--- a/test/integ/connection/__init__.py
+++ b/test/integ/connection/__init__.py
@@ -3,4 +3,3 @@ Integration tests for stem.connection.
"""
__all__ = ["authenticate", "connect"]
-
diff --git a/test/integ/connection/authentication.py b/test/integ/connection/authentication.py
index 1024906..5396d02 100644
--- a/test/integ/connection/authentication.py
+++ b/test/integ/connection/authentication.py
@@ -394,4 +394,3 @@ class TestAuthenticate(unittest.TestCase):
self.assertEqual(failure_msg, str(exc))
raise exc
-
diff --git a/test/integ/connection/connect.py b/test/integ/connection/connect.py
index acd8864..fcf55a9 100644
--- a/test/integ/connection/connect.py
+++ b/test/integ/connection/connect.py
@@ -59,4 +59,3 @@ class TestConnect(unittest.TestCase):
control_socket.close()
else:
self.assertEquals(control_socket, None)
-
diff --git a/test/integ/control/__init__.py b/test/integ/control/__init__.py
index 10c3cf5..7e71dad 100644
--- a/test/integ/control/__init__.py
+++ b/test/integ/control/__init__.py
@@ -3,4 +3,3 @@ Integration tests for stem.control.
"""
__all__ = ["base_controller", "controller"]
-
diff --git a/test/integ/control/base_controller.py b/test/integ/control/base_controller.py
index 319f7a8..a2814ce 100644
--- a/test/integ/control/base_controller.py
+++ b/test/integ/control/base_controller.py
@@ -252,4 +252,3 @@ class TestBaseController(unittest.TestCase):
self.assertTrue(state_observer.timestamp < time.time())
self.assertTrue(state_observer.timestamp > time.time() - 1.0)
state_observer.reset()
-
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index 3514c23..901a0e1 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -832,4 +832,3 @@ class TestController(unittest.TestCase):
new_circ = controller.new_circuit()
circuits = controller.get_circuits()
self.assertTrue(new_circ in [circ.id for circ in circuits])
-
diff --git a/test/integ/descriptor/__init__.py b/test/integ/descriptor/__init__.py
index eb8da22..6553b2d 100644
--- a/test/integ/descriptor/__init__.py
+++ b/test/integ/descriptor/__init__.py
@@ -14,4 +14,3 @@ def get_resource(filename):
"""
return os.path.join(DESCRIPTOR_TEST_DATA, filename)
-
diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py
index 44185c7..06b1a3c 100644
--- a/test/integ/descriptor/extrainfo_descriptor.py
+++ b/test/integ/descriptor/extrainfo_descriptor.py
@@ -169,4 +169,3 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
# failing to get our attention if it does.
self.fail("Unrecognized descriptor content: %s" % unrecognized_lines)
-
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py
index e9bfd69..d6ef4fc 100644
--- a/test/integ/descriptor/networkstatus.py
+++ b/test/integ/descriptor/networkstatus.py
@@ -425,4 +425,3 @@ DnN5aFtYKiTc19qIC7Nmo+afPdDEf0MlJvEOP5EWl3w=
self.assertEquals("27B6B5996C426270A5C95488AA5BCEB6BCC86956", signature.identity)
self.assertEquals("D5C30C15BB3F1DA27669C2D88439939E8F418FCF", signature.key_digest)
self.assertEquals(expected_signature, signature.signature)
-
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index ec957fd..a285952 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -485,4 +485,3 @@ class TestDescriptorReader(unittest.TestCase):
self.assertEqual(test_path, skipped_path)
self.assertTrue(isinstance(skip_exception, stem.descriptor.reader.UnrecognizedType))
self.assertEqual((None, None), skip_exception.mime_type)
-
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py
index 35e3d2a..ae30209 100644
--- a/test/integ/descriptor/server_descriptor.py
+++ b/test/integ/descriptor/server_descriptor.py
@@ -313,4 +313,3 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
self.assertEquals(stem.exit_policy.ExitPolicy("reject *:*"), desc.exit_policy)
self.assertEquals("006FD96BA35E7785A6A3B8B75FE2E2435A13BDB4", desc.digest())
self.assertEquals([], desc.get_unrecognized_lines())
-
diff --git a/test/integ/process.py b/test/integ/process.py
index 5811e37..7aa3382 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -176,4 +176,3 @@ class TestProcess(unittest.TestCase):
time.sleep(1)
self.fail("tor didn't quit after the controller that owned it disconnected")
-
diff --git a/test/integ/response/__init__.py b/test/integ/response/__init__.py
index 2e3a991..d44f035 100644
--- a/test/integ/response/__init__.py
+++ b/test/integ/response/__init__.py
@@ -3,4 +3,3 @@ Integration tests for stem.response.
"""
__all__ = ["protocolinfo"]
-
diff --git a/test/integ/response/protocolinfo.py b/test/integ/response/protocolinfo.py
index fb5b163..2affe17 100644
--- a/test/integ/response/protocolinfo.py
+++ b/test/integ/response/protocolinfo.py
@@ -151,4 +151,3 @@ class TestProtocolInfo(unittest.TestCase):
self.assertEqual((), protocolinfo_response.unknown_auth_methods)
self.assertEqual(tuple(auth_methods), protocolinfo_response.auth_methods)
self.assertEqual(auth_cookie_path, protocolinfo_response.cookie_path)
-
diff --git a/test/integ/socket/__init__.py b/test/integ/socket/__init__.py
index 7479a48..ec37503 100644
--- a/test/integ/socket/__init__.py
+++ b/test/integ/socket/__init__.py
@@ -3,4 +3,3 @@ Integration tests for stem.socket.
"""
__all__ = ["control_message", "control_socket"]
-
diff --git a/test/integ/socket/control_message.py b/test/integ/socket/control_message.py
index af6af16..2a358cb 100644
--- a/test/integ/socket/control_message.py
+++ b/test/integ/socket/control_message.py
@@ -169,4 +169,3 @@ class TestControlMessage(unittest.TestCase):
self.assertTrue(re.match("BW [0-9]+ [0-9]+", str(bw_event)))
self.assertTrue(re.match("650 BW [0-9]+ [0-9]+\r\n", bw_event.raw_content()))
self.assertEquals(("650", " "), bw_event.content()[0][:2])
-
diff --git a/test/integ/socket/control_socket.py b/test/integ/socket/control_socket.py
index a775b20..2f2a4e7 100644
--- a/test/integ/socket/control_socket.py
+++ b/test/integ/socket/control_socket.py
@@ -127,4 +127,3 @@ class TestControlSocket(unittest.TestCase):
control_socket.close()
self.assertRaises(stem.SocketClosed, control_socket.send, "PROTOCOLINFO 1")
control_socket.connect()
-
diff --git a/test/integ/util/__init__.py b/test/integ/util/__init__.py
index 3d275b8..eac6be5 100644
--- a/test/integ/util/__init__.py
+++ b/test/integ/util/__init__.py
@@ -3,4 +3,3 @@ Integration tests for stem.util.* contents.
"""
__all__ = ["conf", "proc", "system"]
-
diff --git a/test/integ/util/conf.py b/test/integ/util/conf.py
index c51bc0c..6fedca1 100644
--- a/test/integ/util/conf.py
+++ b/test/integ/util/conf.py
@@ -133,4 +133,3 @@ class TestConf(unittest.TestCase):
self.assertEquals("yup, I'm there", test_config.get_value("single_value"))
self.assertEquals(["a", "b", "c"], test_config.get_value("multiple_values", multiple = True))
self.assertEquals(HERALD_POEM, test_config.get_value("multiline_value"))
-
diff --git a/test/integ/util/proc.py b/test/integ/util/proc.py
index 8da3730..557c7a8 100644
--- a/test/integ/util/proc.py
+++ b/test/integ/util/proc.py
@@ -101,4 +101,3 @@ class TestProc(unittest.TestCase):
return
self.fail()
-
diff --git a/test/integ/util/system.py b/test/integ/util/system.py
index 7de90ec..0564118 100644
--- a/test/integ/util/system.py
+++ b/test/integ/util/system.py
@@ -393,4 +393,3 @@ class TestSystem(unittest.TestCase):
self.assertEquals(home_dir, stem.util.system.expand_path("~/"))
self.assertEquals(home_dir, stem.util.system.expand_path("~%s" % username))
self.assertEquals(os.path.join(home_dir, "foo"), stem.util.system.expand_path("~%s/foo" % username))
-
diff --git a/test/integ/version.py b/test/integ/version.py
index 4e9409f..9195126 100644
--- a/test/integ/version.py
+++ b/test/integ/version.py
@@ -63,4 +63,3 @@ class TestVersion(unittest.TestCase):
tor_version = list(version_response)[0]
tor_version = tor_version[8:tor_version.find(' ', 8)]
stem.version.Version(tor_version)
-
diff --git a/test/mocking.py b/test/mocking.py
index 99f18b2..12c6bef 100644
--- a/test/mocking.py
+++ b/test/mocking.py
@@ -936,4 +936,3 @@ def sign_descriptor_content(desc_content):
desc_content = desc_content[:rst_start] + router_signature_token + router_signature_start + signature_base64 + router_signature_end
return desc_content
-
diff --git a/test/network.py b/test/network.py
index a0d5ded..cab998a 100644
--- a/test/network.py
+++ b/test/network.py
@@ -245,4 +245,3 @@ class SocksPatch(object):
def __exit__(self, exit_type, value, traceback):
socket.socket = _socket_socket
-
diff --git a/test/output.py b/test/output.py
index 8295b1b..d79db70 100644
--- a/test/output.py
+++ b/test/output.py
@@ -197,4 +197,3 @@ class ErrorTracker(object):
def __iter__(self):
for error_line in self._errors:
yield error_line
-
diff --git a/test/prompt.py b/test/prompt.py
index 290d1ce..32e75ab 100644
--- a/test/prompt.py
+++ b/test/prompt.py
@@ -88,4 +88,3 @@ def controller():
controller = stem.control.Controller.from_port(control_port = CONTROL_PORT)
controller.authenticate()
return controller
-
diff --git a/test/runner.py b/test/runner.py
index f3e44f3..17abefb 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -689,4 +689,3 @@ class Runner(object):
except OSError, exc:
test.output.print_line(" failed to start tor: %s\n" % exc, *ERROR_ATTR)
raise exc
-
diff --git a/test/unit/__init__.py b/test/unit/__init__.py
index a57679c..1932601 100644
--- a/test/unit/__init__.py
+++ b/test/unit/__init__.py
@@ -11,4 +11,3 @@ __all__ = [
"util",
"version",
]
-
diff --git a/test/unit/connection/__init__.py b/test/unit/connection/__init__.py
index 7073319..103b792 100644
--- a/test/unit/connection/__init__.py
+++ b/test/unit/connection/__init__.py
@@ -3,4 +3,3 @@ Unit tests for stem.connection.
"""
__all__ = ["authentication"]
-
diff --git a/test/unit/connection/authentication.py b/test/unit/connection/authentication.py
index abc4af8..0c05f21 100644
--- a/test/unit/connection/authentication.py
+++ b/test/unit/connection/authentication.py
@@ -154,4 +154,3 @@ class TestAuthenticate(unittest.TestCase):
# revert logging back to normal
stem_logger.setLevel(log.logging_level(log.TRACE))
-
diff --git a/test/unit/control/__init__.py b/test/unit/control/__init__.py
index 448a597..6db492b 100644
--- a/test/unit/control/__init__.py
+++ b/test/unit/control/__init__.py
@@ -3,4 +3,3 @@ Unit tests for stem.control.
"""
__all__ = ["controller"]
-
diff --git a/test/unit/control/controller.py b/test/unit/control/controller.py
index c669870..aa2c7ae 100644
--- a/test/unit/control/controller.py
+++ b/test/unit/control/controller.py
@@ -311,4 +311,3 @@ class TestControl(unittest.TestCase):
for test_input in malformed_inputs:
self.assertRaises(ProtocolError, _parse_circ_path, test_input)
-
diff --git a/test/unit/descriptor/__init__.py b/test/unit/descriptor/__init__.py
index 163f33b..aceb1ea 100644
--- a/test/unit/descriptor/__init__.py
+++ b/test/unit/descriptor/__init__.py
@@ -10,4 +10,3 @@ __all__ = [
"router_status_entry",
"server_descriptor",
]
-
diff --git a/test/unit/descriptor/export.py b/test/unit/descriptor/export.py
index 5d43a8f..bd25c6e 100644
--- a/test/unit/descriptor/export.py
+++ b/test/unit/descriptor/export.py
@@ -102,4 +102,3 @@ class TestExport(unittest.TestCase):
server_desc = get_relay_server_descriptor()
bridge_desc = get_bridge_server_descriptor()
self.assertRaises(ValueError, export_csv, (server_desc, bridge_desc))
-
diff --git a/test/unit/descriptor/extrainfo_descriptor.py b/test/unit/descriptor/extrainfo_descriptor.py
index 2c33225..4ef0276 100644
--- a/test/unit/descriptor/extrainfo_descriptor.py
+++ b/test/unit/descriptor/extrainfo_descriptor.py
@@ -503,4 +503,3 @@ class TestExtraInfoDescriptor(unittest.TestCase):
self.assertEquals("ninja", desc.nickname)
return desc
-
diff --git a/test/unit/descriptor/networkstatus/__init__.py b/test/unit/descriptor/networkstatus/__init__.py
index 75c27b7..e1ffef4 100644
--- a/test/unit/descriptor/networkstatus/__init__.py
+++ b/test/unit/descriptor/networkstatus/__init__.py
@@ -3,4 +3,3 @@ Unit tests for stem.descriptor.networkstatus.
"""
__all__ = ["directory_authority", "key_certificate", "document_v3"]
-
diff --git a/test/unit/descriptor/networkstatus/directory_authority.py b/test/unit/descriptor/networkstatus/directory_authority.py
index 545d72f..68e4713 100644
--- a/test/unit/descriptor/networkstatus/directory_authority.py
+++ b/test/unit/descriptor/networkstatus/directory_authority.py
@@ -247,4 +247,3 @@ class TestDirectoryAuthority(unittest.TestCase):
authority = DirectoryAuthority(content, False, True)
self.assertEqual('turtles', authority.nickname)
-
diff --git a/test/unit/descriptor/networkstatus/document_v2.py b/test/unit/descriptor/networkstatus/document_v2.py
index 70f904e..88561e6 100644
--- a/test/unit/descriptor/networkstatus/document_v2.py
+++ b/test/unit/descriptor/networkstatus/document_v2.py
@@ -29,4 +29,3 @@ class TestNetworkStatusDocument(unittest.TestCase):
self.assertEquals([], document.options)
self.assertEquals("moria2", document.signing_authority)
self.assertEquals(NETWORK_STATUS_DOCUMENT_FOOTER_V2[0][1][7:], document.signature)
-
diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py
index 6a825ea..f422f5b 100644
--- a/test/unit/descriptor/networkstatus/document_v3.py
+++ b/test/unit/descriptor/networkstatus/document_v3.py
@@ -802,4 +802,3 @@ class TestNetworkStatusDocument(unittest.TestCase):
document = NetworkStatusDocumentV3(content, validate = False)
self.assertEquals((DirectoryAuthority(authority_content, False, True),), document.directory_authorities)
-
diff --git a/test/unit/descriptor/networkstatus/key_certificate.py b/test/unit/descriptor/networkstatus/key_certificate.py
index c3e8c9f..fdd90c5 100644
--- a/test/unit/descriptor/networkstatus/key_certificate.py
+++ b/test/unit/descriptor/networkstatus/key_certificate.py
@@ -190,4 +190,3 @@ class TestKeyCertificate(unittest.TestCase):
certificate = KeyCertificate(content, False)
self.assertEquals(None, getattr(certificate, attr))
-
diff --git a/test/unit/descriptor/reader.py b/test/unit/descriptor/reader.py
index 28b7155..4ae0aff 100644
--- a/test/unit/descriptor/reader.py
+++ b/test/unit/descriptor/reader.py
@@ -93,4 +93,3 @@ class TestDescriptorReader(unittest.TestCase):
mocking.support_with(test_content)
mocking.mock(open, mocking.return_value(test_content))
self.assertRaises(TypeError, stem.descriptor.reader.load_processed_files, "")
-
diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py
index fd668d2..a0ff74d 100644
--- a/test/unit/descriptor/router_status_entry.py
+++ b/test/unit/descriptor/router_status_entry.py
@@ -526,4 +526,3 @@ class TestRouterStatusEntry(unittest.TestCase):
self.assertEquals(expected_value, getattr(entry, attr))
else:
self.assertEquals("caerSidi", entry.nickname)
-
diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py
index 0edf429..e3f4e78 100644
--- a/test/unit/descriptor/server_descriptor.py
+++ b/test/unit/descriptor/server_descriptor.py
@@ -411,4 +411,3 @@ class TestServerDescriptor(unittest.TestCase):
else:
# check a default attribute
self.assertEquals("caerSidi", desc.nickname)
-
diff --git a/test/unit/exit_policy/__init__.py b/test/unit/exit_policy/__init__.py
index 99a4651..04ea48a 100644
--- a/test/unit/exit_policy/__init__.py
+++ b/test/unit/exit_policy/__init__.py
@@ -3,4 +3,3 @@ Unit tests for stem.exit_policy.py contents.
"""
__all__ = ["policy", "rule"]
-
diff --git a/test/unit/exit_policy/policy.py b/test/unit/exit_policy/policy.py
index c4e675e..12cc52a 100644
--- a/test/unit/exit_policy/policy.py
+++ b/test/unit/exit_policy/policy.py
@@ -188,4 +188,3 @@ class TestExitPolicy(unittest.TestCase):
self.assertFalse(policy.can_exit_to('127.0.0.1', 79))
self.assertTrue(policy.can_exit_to('127.0.0.1', 80))
-
diff --git a/test/unit/exit_policy/rule.py b/test/unit/exit_policy/rule.py
index 0341f43..538418d 100644
--- a/test/unit/exit_policy/rule.py
+++ b/test/unit/exit_policy/rule.py
@@ -322,4 +322,3 @@ class TestExitPolicyRule(unittest.TestCase):
for match_args, expected_result in matches.items():
self.assertEquals(expected_result, rule.is_match(*match_args))
-
diff --git a/test/unit/response/__init__.py b/test/unit/response/__init__.py
index 51f3cd1..3320f64 100644
--- a/test/unit/response/__init__.py
+++ b/test/unit/response/__init__.py
@@ -12,4 +12,3 @@ __all__ = [
"authchallenge",
"singleline"
]
-
diff --git a/test/unit/response/authchallenge.py b/test/unit/response/authchallenge.py
index 436bca0..0583d04 100644
--- a/test/unit/response/authchallenge.py
+++ b/test/unit/response/authchallenge.py
@@ -52,4 +52,3 @@ class TestAuthChallengeResponse(unittest.TestCase):
remaining_comp = auth_challenge_comp[:index] + auth_challenge_comp[index + 1:]
control_message = mocking.get_message(' '.join(remaining_comp))
self.assertRaises(stem.ProtocolError, stem.response.convert, "AUTHCHALLENGE", control_message)
-
diff --git a/test/unit/response/control_line.py b/test/unit/response/control_line.py
index 1d0a0dd..546a410 100644
--- a/test/unit/response/control_line.py
+++ b/test/unit/response/control_line.py
@@ -164,4 +164,3 @@ class TestControlLine(unittest.TestCase):
line = stem.response.ControlLine(cookie_file_entry)
self.assertEquals(line.pop_mapping(True, True), ('COOKIEFILE', r'/tmp/my data\"dir//control_auth_cookie'))
self.assertTrue(line.is_empty())
-
diff --git a/test/unit/response/control_message.py b/test/unit/response/control_message.py
index 51ad8f0..091aff9 100644
--- a/test/unit/response/control_message.py
+++ b/test/unit/response/control_message.py
@@ -182,4 +182,3 @@ class TestControlMessage(unittest.TestCase):
self.assertTrue(line.endswith(message_lines.pop(0)))
return message
-
diff --git a/test/unit/response/events.py b/test/unit/response/events.py
index 57dda95..885be6b 100644
--- a/test/unit/response/events.py
+++ b/test/unit/response/events.py
@@ -1118,4 +1118,3 @@ class TestEvents(unittest.TestCase):
self.assertTrue("STATUS_GENERAL event had an unrecognized runlevel" in logged_events[0])
stem_logger.removeHandler(logging_buffer)
-
diff --git a/test/unit/response/getconf.py b/test/unit/response/getconf.py
index 8a3aedb..a072738 100644
--- a/test/unit/response/getconf.py
+++ b/test/unit/response/getconf.py
@@ -113,4 +113,3 @@ class TestGetConfResponse(unittest.TestCase):
control_message = mocking.get_message(INVALID_RESPONSE)
self.assertRaises(stem.ProtocolError, stem.response.convert, "GETCONF", control_message)
-
diff --git a/test/unit/response/getinfo.py b/test/unit/response/getinfo.py
index f5481c6..589d7b9 100644
--- a/test/unit/response/getinfo.py
+++ b/test/unit/response/getinfo.py
@@ -136,4 +136,3 @@ class TestGetInfoResponse(unittest.TestCase):
control_message = mocking.get_message(MISSING_MULTILINE_NEWLINE)
self.assertRaises(stem.ProtocolError, stem.response.convert, "GETINFO", control_message)
-
diff --git a/test/unit/response/mapaddress.py b/test/unit/response/mapaddress.py
index d4884b6..c3e0b18 100644
--- a/test/unit/response/mapaddress.py
+++ b/test/unit/response/mapaddress.py
@@ -81,4 +81,3 @@ class TestMapAddressResponse(unittest.TestCase):
control_message = mocking.get_message(INVALID_RESPONSE)
self.assertRaises(stem.ProtocolError, stem.response.convert, "MAPADDRESS", control_message)
-
diff --git a/test/unit/response/protocolinfo.py b/test/unit/response/protocolinfo.py
index 23b8173..28cd212 100644
--- a/test/unit/response/protocolinfo.py
+++ b/test/unit/response/protocolinfo.py
@@ -184,4 +184,3 @@ class TestProtocolInfoResponse(unittest.TestCase):
# reset system call mocking
mocking.revert_mocking()
-
diff --git a/test/unit/response/singleline.py b/test/unit/response/singleline.py
index 30c967f..e3b68e5 100644
--- a/test/unit/response/singleline.py
+++ b/test/unit/response/singleline.py
@@ -33,4 +33,3 @@ class TestSingleLineResponse(unittest.TestCase):
def test_multi_line_response(self):
message = mocking.get_message(MULTILINE_RESPONSE)
self.assertRaises(stem.ProtocolError, stem.response.convert, "SINGLELINE", message)
-
diff --git a/test/unit/tutorial.py b/test/unit/tutorial.py
index 79baa8c..6358344 100644
--- a/test/unit/tutorial.py
+++ b/test/unit/tutorial.py
@@ -85,4 +85,3 @@ class TestTutorial(unittest.TestCase):
return
self.assertEqual(4, count)
-
diff --git a/test/unit/util/__init__.py b/test/unit/util/__init__.py
index 33b81d3..a5faacf 100644
--- a/test/unit/util/__init__.py
+++ b/test/unit/util/__init__.py
@@ -11,4 +11,3 @@ __all__ = [
"system",
"tor_tools",
]
-
diff --git a/test/unit/util/conf.py b/test/unit/util/conf.py
index 9006b54..abb645a 100644
--- a/test/unit/util/conf.py
+++ b/test/unit/util/conf.py
@@ -223,4 +223,3 @@ class TestConf(unittest.TestCase):
self.assertEquals(None, test_config.get_value("foo"))
self.assertEquals("hello", test_config.get_value("foo", "hello"))
-
diff --git a/test/unit/util/connection.py b/test/unit/util/connection.py
index 673da71..358ab49 100644
--- a/test/unit/util/connection.py
+++ b/test/unit/util/connection.py
@@ -154,4 +154,3 @@ class TestConnection(unittest.TestCase):
self.assertRaises(ValueError, stem.util.connection.get_address_binary, "")
self.assertRaises(ValueError, stem.util.connection.get_address_binary, "blarg")
-
diff --git a/test/unit/util/enum.py b/test/unit/util/enum.py
index c5b73bf..1b33296 100644
--- a/test/unit/util/enum.py
+++ b/test/unit/util/enum.py
@@ -46,4 +46,3 @@ class TestEnum(unittest.TestCase):
# keys method
self.assertEquals(("ANT", "WASP", "LADYBUG", "FIREFLY"), insects.keys())
-
diff --git a/test/unit/util/proc.py b/test/unit/util/proc.py
index 13942b4..85aff2f 100644
--- a/test/unit/util/proc.py
+++ b/test/unit/util/proc.py
@@ -168,4 +168,3 @@ class TestProc(unittest.TestCase):
]
self.assertEquals(expected_results, proc.get_connections(pid))
-
diff --git a/test/unit/util/str_tools.py b/test/unit/util/str_tools.py
index 8c161fb..ed31c43 100644
--- a/test/unit/util/str_tools.py
+++ b/test/unit/util/str_tools.py
@@ -150,4 +150,3 @@ class TestStrTools(unittest.TestCase):
for arg in invalid_input:
self.assertRaises(ValueError, str_tools.parse_iso_timestamp, arg)
-
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index b948696..a3c5e5a 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -323,4 +323,3 @@ class TestSystem(unittest.TestCase):
self.assertEquals("C:\\tmp", system.expand_path(".\\", "C:\\tmp"))
self.assertEquals("C:\\tmp\\foo", system.expand_path("foo", "C:\\tmp"))
self.assertEquals("C:\\tmp\\foo", system.expand_path(".\\foo", "C:\\tmp"))
-
diff --git a/test/unit/util/tor_tools.py b/test/unit/util/tor_tools.py
index 0c0e6e2..59f448b 100644
--- a/test/unit/util/tor_tools.py
+++ b/test/unit/util/tor_tools.py
@@ -80,4 +80,3 @@ class TestTorTools(unittest.TestCase):
for circuit_id in invalid_circuit_ids:
self.assertFalse(stem.util.tor_tools.is_valid_circuit_id(circuit_id))
-
diff --git a/test/unit/version.py b/test/unit/version.py
index 9fb72e0..78a1a49 100644
--- a/test/unit/version.py
+++ b/test/unit/version.py
@@ -257,4 +257,3 @@ class TestVersion(unittest.TestCase):
"""
self.assertEqual(version, str(Version(version)))
-
diff --git a/test/util.py b/test/util.py
index c8c40af..db6f53c 100644
--- a/test/util.py
+++ b/test/util.py
@@ -75,4 +75,3 @@ def negotiate_socks(sock, host, port):
raise ProtocolError(error_msgs.get(response[1], "SOCKS server returned unrecognized error code"))
return [socket.inet_ntoa(response[4:]), struct.unpack("!H", response[2:4])[0]]
-
1
0

[stem/master] Conforming to E701 (multiple statements on one line)
by atagar@torproject.org 07 Jan '13
by atagar@torproject.org 07 Jan '13
07 Jan '13
commit 1eed64be89d0cf0382234786c020ab4760a4e8e4
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Jan 7 00:00:20 2013 -0800
Conforming to E701 (multiple statements on one line)
Well, that took a while.
---
run_tests.py | 18 +++-
stem/connection.py | 118 ++++++++++++++-------
stem/control.py | 124 +++++++++++++++-------
stem/descriptor/__init__.py | 25 +++--
stem/descriptor/extrainfo_descriptor.py | 52 ++++++---
stem/descriptor/networkstatus.py | 52 +++++++---
stem/descriptor/reader.py | 49 ++++++---
stem/descriptor/router_status_entry.py | 68 +++++++++---
stem/descriptor/server_descriptor.py | 69 ++++++++----
stem/exit_policy.py | 23 +++--
stem/process.py | 36 +++++--
stem/response/__init__.py | 13 ++-
stem/response/events.py | 4 +-
stem/response/getconf.py | 3 +-
stem/socket.py | 53 +++++++---
stem/util/conf.py | 55 +++++++---
stem/util/connection.py | 10 ++-
stem/util/enum.py | 3 +-
stem/util/log.py | 33 ++++--
stem/util/proc.py | 47 ++++++---
stem/util/str_tools.py | 15 ++-
stem/util/system.py | 72 +++++++++----
stem/util/term.py | 7 +-
stem/util/tor_tools.py | 4 +-
stem/version.py | 32 ++++--
test/check_whitespace.py | 6 +-
test/integ/connection/authentication.py | 45 +++++---
test/integ/connection/connect.py | 6 +-
test/integ/control/base_controller.py | 24 +++--
test/integ/control/controller.py | 145 +++++++++++++++++--------
test/integ/descriptor/extrainfo_descriptor.py | 4 +-
test/integ/descriptor/networkstatus.py | 8 +-
test/integ/descriptor/reader.py | 45 ++++++--
test/integ/descriptor/server_descriptor.py | 4 +-
test/integ/process.py | 22 +++--
test/integ/response/protocolinfo.py | 12 ++-
test/integ/socket/control_message.py | 15 ++-
test/integ/socket/control_socket.py | 18 ++-
test/integ/version.py | 6 +-
test/mocking.py | 47 ++++++---
test/output.py | 30 ++++--
test/prompt.py | 8 +-
test/runner.py | 26 ++++--
test/unit/descriptor/router_status_entry.py | 3 +-
test/unit/exit_policy/policy.py | 3 +-
test/unit/util/system.py | 6 +-
46 files changed, 1029 insertions(+), 439 deletions(-)
diff --git a/run_tests.py b/run_tests.py
index c17898b..f9b18fc 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -208,7 +208,9 @@ def load_user_configuration(test_config):
sys.exit(1)
else:
target_config = test_config.get("target.config", {}).get(target)
- if target_config: arg_overrides[target_config] = "true"
+
+ if target_config:
+ arg_overrides[target_config] = "true"
elif opt in ("-l", "--test"):
arg_overrides["argument.test"] = arg
elif opt in ("-l", "--log"):
@@ -304,7 +306,8 @@ if __name__ == '__main__':
our_level = stem.util.log.logging_level(CONFIG["argument.log"])
info_level = stem.util.log.logging_level(stem.util.log.INFO)
- if our_level <= info_level: test.output.print_config(test_config)
+ if our_level <= info_level:
+ test.output.print_config(test_config)
error_tracker = test.output.ErrorTracker()
output_filters = (
@@ -388,7 +391,9 @@ if __name__ == '__main__':
skip_targets.append(target)
for target in integ_run_targets:
- if target in skip_targets: continue
+ if target in skip_targets:
+ continue
+
error_tracker.set_category(target)
try:
@@ -486,8 +491,11 @@ if __name__ == '__main__':
print
runtime = time.time() - start_time
- if runtime < 1: runtime_label = "(%0.1f seconds)" % runtime
- else: runtime_label = "(%i seconds)" % runtime
+
+ if runtime < 1:
+ runtime_label = "(%0.1f seconds)" % runtime
+ else:
+ runtime_label = "(%i seconds)" % runtime
if testing_failed or error_tracker.has_error_occured():
test.output.print_line("TESTING FAILED %s" % runtime_label, *ERROR_ATTR)
diff --git a/stem/connection.py b/stem/connection.py
index 737776f..0291a82 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -188,10 +188,13 @@ def _connect(control_socket, password, chroot_path, controller):
else:
return controller(control_socket)
except MissingPassword:
- assert password is None, "BUG: authenticate raised MissingPassword despite getting one"
+ if password is None:
+ raise ValueError("BUG: authenticate raised MissingPassword despite getting one")
- try: password = getpass.getpass("Controller password: ")
- except KeyboardInterrupt: return None
+ try:
+ password = getpass.getpass("Controller password: ")
+ except KeyboardInterrupt:
+ return None
return _connect(control_socket, password, chroot_path, controller)
except AuthenticationFailure, exc:
@@ -352,7 +355,8 @@ def authenticate(controller, password = None, chroot_path = None, protocolinfo_r
# iterating over AuthMethods so we can try them in this order
for auth_type in (AuthMethod.NONE, AuthMethod.PASSWORD, AuthMethod.SAFECOOKIE, AuthMethod.COOKIE):
- if not auth_type in auth_methods: continue
+ if not auth_type in auth_methods:
+ continue
try:
if auth_type == AuthMethod.NONE:
@@ -437,16 +441,22 @@ def authenticate_none(controller, suppress_ctl_errors = True):
# if we got anything but an OK response then error
if str(auth_response) != "OK":
- try: controller.connect()
- except: pass
+ try:
+ controller.connect()
+ except:
+ pass
raise OpenAuthRejected(str(auth_response), auth_response)
except stem.ControllerError, exc:
- try: controller.connect()
- except: pass
+ try:
+ controller.connect()
+ except:
+ pass
- if not suppress_ctl_errors: raise exc
- else: raise OpenAuthRejected("Socket failed (%s)" % exc)
+ if not suppress_ctl_errors:
+ raise exc
+ else:
+ raise OpenAuthRejected("Socket failed (%s)" % exc)
def authenticate_password(controller, password, suppress_ctl_errors = True):
"""
@@ -493,8 +503,10 @@ def authenticate_password(controller, password, suppress_ctl_errors = True):
# if we got anything but an OK response then error
if str(auth_response) != "OK":
- try: controller.connect()
- except: pass
+ try:
+ controller.connect()
+ except:
+ pass
# all we have to go on is the error message from tor...
# Password did not match HashedControlPassword value value from configuration...
@@ -505,11 +517,15 @@ def authenticate_password(controller, password, suppress_ctl_errors = True):
else:
raise PasswordAuthRejected(str(auth_response), auth_response)
except stem.ControllerError, exc:
- try: controller.connect()
- except: pass
+ try:
+ controller.connect()
+ except:
+ pass
- if not suppress_ctl_errors: raise exc
- else: raise PasswordAuthRejected("Socket failed (%s)" % exc)
+ if not suppress_ctl_errors:
+ raise exc
+ else:
+ raise PasswordAuthRejected("Socket failed (%s)" % exc)
def authenticate_cookie(controller, cookie_path, suppress_ctl_errors = True):
"""
@@ -564,8 +580,10 @@ def authenticate_cookie(controller, cookie_path, suppress_ctl_errors = True):
# if we got anything but an OK response then error
if str(auth_response) != "OK":
- try: controller.connect()
- except: pass
+ try:
+ controller.connect()
+ except:
+ pass
# all we have to go on is the error message from tor...
# ... Authentication cookie did not match expected value.
@@ -577,11 +595,15 @@ def authenticate_cookie(controller, cookie_path, suppress_ctl_errors = True):
else:
raise CookieAuthRejected(str(auth_response), cookie_path, False, auth_response)
except stem.ControllerError, exc:
- try: controller.connect()
- except: pass
+ try:
+ controller.connect()
+ except:
+ pass
- if not suppress_ctl_errors: raise exc
- else: raise CookieAuthRejected("Socket failed (%s)" % exc, cookie_path, False)
+ if not suppress_ctl_errors:
+ raise exc
+ else:
+ raise CookieAuthRejected("Socket failed (%s)" % exc, cookie_path, False)
def authenticate_safecookie(controller, cookie_path, suppress_ctl_errors = True):
"""
@@ -651,10 +673,13 @@ def authenticate_safecookie(controller, cookie_path, suppress_ctl_errors = True)
authchallenge_response = _msg(controller, "AUTHCHALLENGE SAFECOOKIE %s" % client_nonce_hex)
if not authchallenge_response.is_ok():
- try: controller.connect()
- except: pass
+ try:
+ controller.connect()
+ except:
+ pass
authchallenge_response_str = str(authchallenge_response)
+
if "Authentication required." in authchallenge_response_str:
raise AuthChallengeUnsupported("SAFECOOKIE authentication isn't supported", cookie_path)
elif "AUTHCHALLENGE only supports" in authchallenge_response_str:
@@ -666,17 +691,23 @@ def authenticate_safecookie(controller, cookie_path, suppress_ctl_errors = True)
else:
raise AuthChallengeFailed(authchallenge_response, cookie_path)
except stem.ControllerError, exc:
- try: controller.connect()
- except: pass
+ try:
+ controller.connect()
+ except:
+ pass
- if not suppress_ctl_errors: raise exc
- else: raise AuthChallengeFailed("Socket failed (%s)" % exc, cookie_path, True)
+ if not suppress_ctl_errors:
+ raise exc
+ else:
+ raise AuthChallengeFailed("Socket failed (%s)" % exc, cookie_path, True)
try:
stem.response.convert("AUTHCHALLENGE", authchallenge_response)
except stem.ProtocolError, exc:
- if not suppress_ctl_errors: raise exc
- else: raise AuthChallengeFailed("Unable to parse AUTHCHALLENGE response: %s" % exc, cookie_path)
+ if not suppress_ctl_errors:
+ raise exc
+ else:
+ raise AuthChallengeFailed("Unable to parse AUTHCHALLENGE response: %s" % exc, cookie_path)
expected_server_hash = stem.util.connection.hmac_sha256(
SERVER_HASH_CONSTANT,
@@ -689,18 +720,25 @@ def authenticate_safecookie(controller, cookie_path, suppress_ctl_errors = True)
client_hash = stem.util.connection.hmac_sha256(
CLIENT_HASH_CONSTANT,
cookie_data + client_nonce + authchallenge_response.server_nonce)
+
auth_response = _msg(controller, "AUTHENTICATE %s" % (binascii.b2a_hex(client_hash)))
except stem.ControllerError, exc:
- try: controller.connect()
- except: pass
+ try:
+ controller.connect()
+ except:
+ pass
- if not suppress_ctl_errors: raise exc
- else: raise CookieAuthRejected("Socket failed (%s)" % exc, cookie_path, True, auth_response)
+ if not suppress_ctl_errors:
+ raise exc
+ else:
+ raise CookieAuthRejected("Socket failed (%s)" % exc, cookie_path, True, auth_response)
# if we got anything but an OK response then err
if not auth_response.is_ok():
- try: controller.connect()
- except: pass
+ try:
+ controller.connect()
+ except:
+ pass
# all we have to go on is the error message from tor...
# ... Safe cookie response did not match expected value
@@ -841,10 +879,14 @@ def _expand_cookie_path(protocolinfo_response, pid_resolver, pid_resolution_arg)
if cookie_path and not os.path.isabs(cookie_path):
try:
tor_pid = pid_resolver(pid_resolution_arg)
- if not tor_pid: raise IOError("pid lookup failed")
+
+ if not tor_pid:
+ raise IOError("pid lookup failed")
tor_cwd = stem.util.system.get_cwd(tor_pid)
- if not tor_cwd: raise IOError("cwd lookup failed")
+
+ if not tor_cwd:
+ raise IOError("cwd lookup failed")
cookie_path = stem.util.system.expand_path(cookie_path, tor_cwd)
except IOError, exc:
diff --git a/stem/control.py b/stem/control.py
index fc4af05..feb7834 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -426,7 +426,8 @@ class BaseController(object):
for listener, spawn in self._status_listeners:
if listener != callback:
new_listeners.append((listener, spawn))
- else: is_changed = True
+ else:
+ is_changed = True
self._status_listeners = new_listeners
return is_changed
@@ -577,7 +578,8 @@ class BaseController(object):
event_message = self._event_queue.get_nowait()
self._handle_event(event_message)
except Queue.Empty:
- if not self.is_alive(): break
+ if not self.is_alive():
+ break
self._event_notice.wait()
self._event_notice.clear()
@@ -656,8 +658,10 @@ class Controller(BaseController):
def close(self):
# making a best-effort attempt to quit before detaching the socket
if self.is_alive():
- try: self.msg("QUIT")
- except: pass
+ try:
+ self.msg("QUIT")
+ except:
+ pass
super(Controller, self).close()
@@ -703,7 +707,9 @@ class Controller(BaseController):
is_multiple = False
params = set([params])
else:
- if not params: return {}
+ if not params:
+ return {}
+
is_multiple = True
params = set(params)
@@ -718,14 +724,17 @@ class Controller(BaseController):
# the geoip database already looks to be unavailable - abort the request
if default == UNDEFINED:
raise stem.ProtocolError("Tor geoip database is unavailable")
- else: return default
+ else:
+ return default
# if everything was cached then short circuit making the query
if not params:
log.trace("GETINFO %s (cache fetch)" % " ".join(reply.keys()))
- if is_multiple: return reply
- else: return reply.values()[0]
+ if is_multiple:
+ return reply
+ else:
+ return reply.values()[0]
try:
response = self.msg("GETINFO %s" % " ".join(params))
@@ -766,8 +775,10 @@ class Controller(BaseController):
log.debug("GETINFO %s (failed: %s)" % (" ".join(params), exc))
- if default == UNDEFINED: raise exc
- else: return default
+ if default == UNDEFINED:
+ raise exc
+ else:
+ return default
def get_version(self, default = UNDEFINED):
"""
@@ -795,8 +806,10 @@ class Controller(BaseController):
return self._request_cache["version"]
except Exception, exc:
- if default == UNDEFINED: raise exc
- else: return default
+ if default == UNDEFINED:
+ raise exc
+ else:
+ return default
def get_socks_listeners(self, default = UNDEFINED):
"""
@@ -845,8 +858,10 @@ class Controller(BaseController):
return [(addr, int(port)) for (addr, port) in proxy_addrs]
except Exception, exc:
- if default == UNDEFINED: raise exc
- else: return default
+ if default == UNDEFINED:
+ raise exc
+ else:
+ return default
def get_protocolinfo(self, default = UNDEFINED):
"""
@@ -870,8 +885,10 @@ class Controller(BaseController):
try:
return stem.connection.get_protocolinfo(self)
except Exception, exc:
- if default == UNDEFINED: raise exc
- else: return default
+ if default == UNDEFINED:
+ raise exc
+ else:
+ return default
def get_server_descriptor(self, relay, default = UNDEFINED):
"""
@@ -903,8 +920,10 @@ class Controller(BaseController):
desc_content = self.get_info(query)
return stem.descriptor.server_descriptor.RelayDescriptor(desc_content)
except Exception, exc:
- if default == UNDEFINED: raise exc
- else: return default
+ if default == UNDEFINED:
+ raise exc
+ else:
+ return default
def get_server_descriptors(self, default = UNDEFINED):
"""
@@ -930,7 +949,8 @@ class Controller(BaseController):
for desc in stem.descriptor.server_descriptor.parse_file(StringIO.StringIO(desc_content)):
yield desc
except Exception, exc:
- if default == UNDEFINED: raise exc
+ if default == UNDEFINED:
+ raise exc
else:
if entry is not None:
for entry in default:
@@ -967,8 +987,10 @@ class Controller(BaseController):
desc_content = self.get_info(query)
return stem.descriptor.router_status_entry.RouterStatusEntryV2(desc_content)
except Exception, exc:
- if default == UNDEFINED: raise exc
- else: return default
+ if default == UNDEFINED:
+ raise exc
+ else:
+ return default
def get_network_statuses(self, default = UNDEFINED):
"""
@@ -1000,7 +1022,8 @@ class Controller(BaseController):
for desc in desc_iterator:
yield desc
except Exception, exc:
- if default == UNDEFINED: raise exc
+ if default == UNDEFINED:
+ raise exc
else:
if entry is not None:
for entry in default:
@@ -1104,7 +1127,9 @@ class Controller(BaseController):
# remove strings which contain only whitespace
params = filter(lambda entry: entry.strip(), params)
- if params == []: return {}
+
+ if params == []:
+ return {}
# translate context sensitive options
lookup_params = set([MAPPED_CONFIG_KEYS.get(entry, entry) for entry in params])
@@ -1154,8 +1179,10 @@ class Controller(BaseController):
except stem.ControllerError, exc:
log.debug("GETCONF %s (failed: %s)" % (" ".join(lookup_params), exc))
- if default != UNDEFINED: return dict((param, default) for param in params)
- else: raise exc
+ if default != UNDEFINED:
+ return dict((param, default) for param in params)
+ else:
+ raise exc
def _get_conf_dict_to_response(self, config_dict, default, multiple):
"""
@@ -1467,15 +1494,19 @@ class Controller(BaseController):
* :class:`stem.InvalidArguments` if features passed were invalid
"""
- if isinstance(features, str): features = [features]
+ if isinstance(features, str):
+ features = [features]
+
response = self.msg("USEFEATURE %s" % " ".join(features))
stem.response.convert("SINGLELINE", response)
if not response.is_ok():
if response.code == "552":
invalid_feature = []
+
if response.message.startswith("Unrecognized feature \""):
invalid_feature = [response.message[22:response.message.find("\"", 22)]]
+
raise stem.InvalidArguments(response.code, response.message, invalid_feature)
raise stem.ProtocolError("USEFEATURE provided an invalid response code: %s" % response.code)
@@ -1505,8 +1536,10 @@ class Controller(BaseController):
raise ValueError("Tor presently does not have a circuit with the id of '%s'" % circuit_id)
except Exception, exc:
- if default == UNDEFINED: raise exc
- else: return default
+ if default == UNDEFINED:
+ raise exc
+ else:
+ return default
def get_circuits(self, default = UNDEFINED):
"""
@@ -1530,8 +1563,10 @@ class Controller(BaseController):
return circuits
except Exception, exc:
- if default == UNDEFINED: raise exc
- else: return default
+ if default == UNDEFINED:
+ raise exc
+ else:
+ return default
def new_circuit(self, path = None, purpose = "general", await_build = False):
"""
@@ -1609,9 +1644,15 @@ class Controller(BaseController):
raise stem.InvalidRequest(512, "EXTENDCIRCUIT requires the path prior to version %s" % path_opt_version)
args = [circuit_id]
- if isinstance(path, str): path = [path]
- if path: args.append(",".join(path))
- if purpose: args.append("purpose=%s" % purpose)
+
+ if isinstance(path, str):
+ path = [path]
+
+ if path:
+ args.append(",".join(path))
+
+ if purpose:
+ args.append("purpose=%s" % purpose)
response = self.msg("EXTENDCIRCUIT %s" % " ".join(args))
stem.response.convert("SINGLELINE", response)
@@ -1710,8 +1751,10 @@ class Controller(BaseController):
return streams
except Exception, exc:
- if default == UNDEFINED: raise exc
- else: return default
+ if default == UNDEFINED:
+ raise exc
+ else:
+ return default
def attach_stream(self, stream_id, circuit_id, exiting_hop = None):
"""
@@ -1730,7 +1773,10 @@ class Controller(BaseController):
"""
query = "ATTACHSTREAM %s %s" % (stream_id, circuit_id)
- if exiting_hop: query += " HOP=%s" % exiting_hop
+
+ if exiting_hop:
+ query += " HOP=%s" % exiting_hop
+
response = self.msg(query)
stem.response.convert("SINGLELINE", response)
@@ -1976,5 +2022,7 @@ def _case_insensitive_lookup(entries, key, default = UNDEFINED):
if entry.lower() == key.lower():
return entry
- if default != UNDEFINED: return default
- else: raise ValueError("key '%s' doesn't exist in dict: %s" % (key, entries))
+ if default != UNDEFINED:
+ return default
+ else:
+ raise ValueError("key '%s' doesn't exist in dict: %s" % (key, entries))
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index ed52b42..0dba96c 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -196,7 +196,8 @@ def _read_until_keywords(keywords, descriptor_file, inclusive = False, ignore_fi
content = None if skip else []
ending_keyword = None
- if isinstance(keywords, str): keywords = (keywords,)
+ if isinstance(keywords, str):
+ keywords = (keywords,)
if ignore_first:
first_line = descriptor_file.readline()
@@ -211,7 +212,9 @@ def _read_until_keywords(keywords, descriptor_file, inclusive = False, ignore_fi
break
line = descriptor_file.readline()
- if not line: break # EOF
+
+ if not line:
+ break # EOF
line_match = KEYWORD_LINE.match(line)
@@ -314,27 +317,35 @@ def _get_descriptor_components(raw_contents, validate, extra_keywords = ()):
# ... and server descriptors end with an extra newline. But other documents
# don't say how blank lines should be handled so globally ignoring them.
- if not line: continue
+ if not line:
+ continue
# Some lines have an 'opt ' for backward compatibility. They should be
# ignored. This prefix is being removed in...
# https://trac.torproject.org/projects/tor/ticket/5124
- if line.startswith("opt "): line = line[4:]
+ if line.startswith("opt "):
+ line = line[4:]
line_match = KEYWORD_LINE.match(line)
if not line_match:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Line contains invalid characters: %s" % line)
keyword, value = line_match.groups()
- if value is None: value = ''
+
+ if value is None:
+ value = ''
try:
block_contents = _get_pseudo_pgp_block(remaining_lines)
except ValueError, exc:
- if not validate: continue
+ if not validate:
+ continue
+
raise exc
if keyword in extra_keywords:
diff --git a/stem/descriptor/extrainfo_descriptor.py b/stem/descriptor/extrainfo_descriptor.py
index 7ea457c..2c14c92 100644
--- a/stem/descriptor/extrainfo_descriptor.py
+++ b/stem/descriptor/extrainfo_descriptor.py
@@ -158,7 +158,8 @@ def parse_file(descriptor_file, validate = True):
if extrainfo_content:
yield RelayExtraInfoDescriptor("".join(extrainfo_content), validate)
- else: break # done parsing file
+ else:
+ break # done parsing file
def _parse_timestamp_and_interval(keyword, content):
"""
@@ -180,7 +181,9 @@ def _parse_timestamp_and_interval(keyword, content):
raise ValueError("Malformed %s line: %s" % (keyword, line))
timestamp_str, interval, remainder = content_match.groups()
- if remainder: remainder = remainder[1:] # remove leading space
+
+ if remainder:
+ remainder = remainder[1:] # remove leading space
if not interval.isdigit():
raise ValueError("%s line's interval wasn't a number: %s" % (keyword, line))
@@ -430,7 +433,9 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
extra_info_comp = value.split()
if len(extra_info_comp) < 2:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Extra-info line must have two values: %s" % line)
if validate:
@@ -527,8 +532,10 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
if value:
for entry in value.split(","):
if not "=" in entry:
- if validate: raise ValueError(error_msg)
- else: continue
+ if validate:
+ raise ValueError(error_msg)
+ else:
+ continue
status, count = entry.split("=", 1)
@@ -562,7 +569,9 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
# "<keyword>" num%
try:
- if not value.endswith("%"): raise ValueError()
+ if not value.endswith("%"):
+ raise ValueError()
+
percentage = float(value[:-1]) / 100
# Bug lets these be above 100%, however they're soon going away...
@@ -593,7 +602,8 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
entries.append(float(entry))
except ValueError:
- if validate: raise ValueError("Non-numeric entry in %s listing: %s" % (keyword, line))
+ if validate:
+ raise ValueError("Non-numeric entry in %s listing: %s" % (keyword, line))
if keyword == "cell-processed-cells":
self.cell_processed_cells = entries
@@ -636,7 +646,8 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
self.dir_stats_end = timestamp
self.dir_stats_interval = interval
except ValueError, exc:
- if validate: raise exc
+ if validate:
+ raise exc
elif keyword == "conn-bi-direct":
# "conn-bi-direct" YYYY-MM-DD HH:MM:SS (NSEC s) BELOW,READ,WRITE,BOTH
@@ -655,7 +666,8 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
self.conn_bi_direct_write = int(stats[2])
self.conn_bi_direct_both = int(stats[3])
except ValueError, exc:
- if validate: raise exc
+ if validate:
+ raise exc
elif keyword in ("read-history", "write-history", "dirreq-read-history", "dirreq-write-history"):
# "<keyword>" YYYY-MM-DD HH:MM:SS (NSEC s) NUM,NUM,NUM,NUM,NUM...
try:
@@ -685,7 +697,8 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
self.dir_write_history_interval = interval
self.dir_write_history_values = history_values
except ValueError, exc:
- if validate: raise exc
+ if validate:
+ raise exc
elif keyword in ("exit-kibibytes-written", "exit-kibibytes-read", "exit-streams-opened"):
# "<keyword>" port=N,port=N,...
@@ -695,13 +708,16 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
if value:
for entry in value.split(","):
if not "=" in entry:
- if validate: raise ValueError(error_msg)
- else: continue
+ if validate:
+ raise ValueError(error_msg)
+ else:
+ continue
port, stat = entry.split("=", 1)
if (port == 'other' or stem.util.connection.is_valid_port(port)) and stat.isdigit():
- if port != 'other': port = int(port)
+ if port != 'other':
+ port = int(port)
port_mappings[port] = int(stat)
elif validate:
raise ValueError(error_msg)
@@ -727,8 +743,10 @@ class ExtraInfoDescriptor(stem.descriptor.Descriptor):
if value:
for entry in value.split(","):
if not "=" in entry:
- if validate: raise ValueError(error_msg)
- else: continue
+ if validate:
+ raise ValueError(error_msg)
+ else:
+ continue
locale, count = entry.split("=", 1)
@@ -807,7 +825,9 @@ class RelayExtraInfoDescriptor(ExtraInfoDescriptor):
value, block_contents = values[0]
line = "%s %s" % (keyword, value) # original line
- if block_contents: line += "\n%s" % block_contents
+
+ if block_contents:
+ line += "\n%s" % block_contents
if keyword == "router-signature":
if validate and not block_contents:
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index 2bdfbc4..28537c2 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -303,7 +303,10 @@ class NetworkStatusDocumentV2(NetworkStatusDocument):
document_content += "\n" + document_file.read()
entries = stem.descriptor._get_descriptor_components(document_content, validate)
- if validate: self._check_constraints(entries)
+
+ if validate:
+ self._check_constraints(entries)
+
self._parse(entries, validate)
def _parse(self, entries, validate):
@@ -311,11 +314,15 @@ class NetworkStatusDocumentV2(NetworkStatusDocument):
value, block_contents = values[0]
line = "%s %s" % (keyword, value) # original line
- if block_contents: line += "\n%s" % block_contents
+
+ if block_contents:
+ line += "\n%s" % block_contents
if keyword == "network-status-version":
if not value.isdigit():
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Network status document has a non-numeric version: %s" % line)
self.version = int(value)
@@ -326,7 +333,9 @@ class NetworkStatusDocumentV2(NetworkStatusDocument):
dir_source_comp = value.split()
if len(dir_source_comp) < 3:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("The 'dir-source' line of a v2 network status document must have three values: %s" % line)
if validate:
@@ -569,7 +578,9 @@ class _DocumentHeader(object):
version, flavor = value, None
if not version.isdigit():
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Network status document has a non-numeric version: %s" % line)
self.version = int(version)
@@ -663,11 +674,14 @@ class _DocumentHeader(object):
# Parameters ::= Parameter | Parameters SP Parameter
# should only appear in consensus-method 7 or later
+
if validate and not self.meets_consensus_method(7):
raise ValueError("A network status document's 'params' line should only appear in consensus-method 7 or later")
# skip if this is a blank line
- if value == "": continue
+
+ if value == "":
+ continue
self.params.update(_parse_int_mappings(keyword, value, validate))
@@ -769,7 +783,9 @@ class _DocumentFooter(object):
elif keyword == "directory-signature":
for sig_value, block_contents in values:
if not sig_value.count(" ") in (1, 2) or not block_contents:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Authority signatures in a network status document are expected to be of the form 'directory-signature [METHOD] FINGERPRINT KEY_DIGEST\\nSIGNATURE', got:\n%s\n%s" % (sig_value, block_contents))
if sig_value.count(" ") == 1:
@@ -872,7 +888,9 @@ def _parse_int_mappings(keyword, value, validate):
results[entry_key] = entry_value
seen_keys.append(entry_key)
except ValueError, exc:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Unable to parse network status document's '%s' line (%s): %s'" % (keyword, exc, value))
return results
@@ -999,7 +1017,9 @@ class DirectoryAuthority(stem.descriptor.Descriptor):
dir_source_comp = value.split(" ")
if len(dir_source_comp) < 6:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Authority entry's 'dir-source' line must have six values: %s" % line)
if validate:
@@ -1139,7 +1159,9 @@ class KeyCertificate(stem.descriptor.Descriptor):
# "dir-key-certificate-version" version
if not value.isdigit():
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Key certificate has a non-integer version: %s" % line)
self.version = int(value)
@@ -1150,7 +1172,9 @@ class KeyCertificate(stem.descriptor.Descriptor):
# "dir-address" IPPort
if not ':' in value:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Key certificate's 'dir-address' is expected to be of the form ADDRESS:PORT: %s" % line)
address, dirport = value.split(':', 1)
@@ -1255,7 +1279,9 @@ class DocumentSignature(object):
return 1
for attr in ("identity", "key_digest", "signature"):
- if getattr(self, attr) > getattr(other, attr): return 1
- elif getattr(self, attr) < getattr(other, attr): return -1
+ if getattr(self, attr) > getattr(other, attr):
+ return 1
+ elif getattr(self, attr) < getattr(other, attr):
+ return -1
return 0
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index d47a5ed..9f9f505 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -173,7 +173,8 @@ def load_processed_files(path):
for line in input_file.readlines():
line = line.strip()
- if not line: continue # skip blank lines
+ if not line:
+ continue # skip blank lines
if not " " in line:
raise TypeError("Malformed line: %s" % line)
@@ -208,8 +209,11 @@ def save_processed_files(path, processed_files):
# makes the parent directory if it doesn't already exist
try:
path_dir = os.path.dirname(path)
- if not os.path.exists(path_dir): os.makedirs(path_dir)
- except OSError, exc: raise IOError(exc)
+
+ if not os.path.exists(path_dir):
+ os.makedirs(path_dir)
+ except OSError, exc:
+ raise IOError(exc)
with open(path, "w") as output_file:
for path, timestamp in processed_files.items():
@@ -243,8 +247,10 @@ class DescriptorReader(object):
"""
def __init__(self, target, follow_links = False, buffer_size = 100, persistence_path = None):
- if isinstance(target, str): self._targets = [target]
- else: self._targets = target
+ if isinstance(target, str):
+ self._targets = [target]
+ else:
+ self._targets = target
self._follow_links = follow_links
self._persistence_path = persistence_path
@@ -270,7 +276,8 @@ class DescriptorReader(object):
try:
processed_files = load_processed_files(self._persistence_path)
self.set_processed_files(processed_files)
- except: pass
+ except:
+ pass
def get_processed_files(self):
"""
@@ -371,10 +378,12 @@ class DescriptorReader(object):
self._iter_notice.set()
# clears our queue to unblock enqueue calls
+
try:
while True:
self._unreturned_descriptors.get_nowait()
- except Queue.Empty: pass
+ except Queue.Empty:
+ pass
self._reader_thread.join()
self._reader_thread = None
@@ -383,7 +392,8 @@ class DescriptorReader(object):
try:
processed_files = self.get_processed_files()
save_processed_files(self._persistence_path, processed_files)
- except: pass
+ except:
+ pass
def _read_descriptor_files(self):
new_processed_files = {}
@@ -419,8 +429,10 @@ class DescriptorReader(object):
try:
descriptor = self._unreturned_descriptors.get_nowait()
- if descriptor == FINISHED: break
- else: yield descriptor
+ if descriptor == FINISHED:
+ break
+ else:
+ yield descriptor
except Queue.Empty:
self._iter_notice.wait()
self._iter_notice.clear()
@@ -431,7 +443,8 @@ class DescriptorReader(object):
self._handle_file(os.path.join(root, filename), new_processed_files)
# this can take a while if, say, we're including the root directory
- if self._is_stopped.isSet(): return
+ if self._is_stopped.isSet():
+ return
def _handle_file(self, target, new_processed_files):
# This is a file. Register its last modified timestamp and check if
@@ -452,7 +465,8 @@ class DescriptorReader(object):
# Block devices and such are never descriptors, and can cause us to block
# for quite a while so skipping anything that isn't a regular file.
- if not os.path.isfile(target): return
+ if not os.path.isfile(target):
+ return
# The mimetypes module only checks the file extension. To actually
# check the content (like the 'file' command) we'd need something like
@@ -483,7 +497,9 @@ class DescriptorReader(object):
self._notify_read_listeners(target)
with open(target) as target_file:
for desc in stem.descriptor.parse_file(target, target_file):
- if self._is_stopped.isSet(): return
+ if self._is_stopped.isSet():
+ return
+
self._unreturned_descriptors.put(desc)
self._iter_notice.set()
except TypeError, exc:
@@ -509,7 +525,9 @@ class DescriptorReader(object):
entry = tar_file.extractfile(tar_entry)
for desc in stem.descriptor.parse_file(target, entry):
- if self._is_stopped.isSet(): return
+ if self._is_stopped.isSet():
+ return
+
self._unreturned_descriptors.put(desc)
self._iter_notice.set()
@@ -521,7 +539,8 @@ class DescriptorReader(object):
except IOError, exc:
self._notify_skip_listeners(target, ReadFailed(exc))
finally:
- if tar_file: tar_file.close()
+ if tar_file:
+ tar_file.close()
def _notify_read_listeners(self, path):
for listener in self._read_listeners:
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index bc6aa46..6e048dd 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -83,7 +83,8 @@ def parse_file(document_file, validate, entry_class, entry_keyword = "r", start_
yield entry_class(desc_content, validate, *extra_args)
# check if we stopped at the end of the section
- if ending_keyword in section_end_keywords: break
+ if ending_keyword in section_end_keywords:
+ break
else:
break
@@ -139,7 +140,10 @@ class RouterStatusEntry(stem.descriptor.Descriptor):
self._unrecognized_lines = []
entries = stem.descriptor._get_descriptor_components(content, validate)
- if validate: self._check_constraints(entries)
+
+ if validate:
+ self._check_constraints(entries)
+
self._parse(entries, validate)
def _parse(self, entries, validate):
@@ -427,7 +431,8 @@ def _parse_r_line(desc, value, validate, include_digest = True):
r_comp.insert(2, None)
if len(r_comp) < 8:
- if not validate: return
+ if not validate:
+ return
expected_field_count = 'eight' if include_digest else 'seven'
raise ValueError("%s 'r' line must have %s values: r %s" % (desc._name(), expected_field_count, value))
@@ -446,7 +451,10 @@ def _parse_r_line(desc, value, validate, include_digest = True):
desc.nickname = r_comp[0]
desc.fingerprint = _decode_fingerprint(r_comp[1], validate)
- if include_digest: desc.digest = r_comp[2]
+
+ if include_digest:
+ desc.digest = r_comp[2]
+
desc.address = r_comp[5]
desc.or_port = int(r_comp[6])
desc.dir_port = None if r_comp[7] == '0' else int(r_comp[7])
@@ -463,7 +471,9 @@ def _parse_a_line(desc, value, validate):
# example: a [2001:888:2133:0:82:94:251:204]:9001
if not ':' in value:
- if not validate: return
+ if not validate:
+ return
+
raise ValueError("%s 'a' line must be of the form '[address]:[ports]': a %s" % (desc._name(), value))
address, ports = value.rsplit(':', 1)
@@ -481,7 +491,10 @@ def _parse_a_line(desc, value, validate):
if not stem.util.connection.is_valid_port(min_port) or \
not stem.util.connection.is_valid_port(max_port):
- if not validate: continue
+
+ if not validate:
+ continue
+
raise ValueError("%s 'a' line had an invalid port range (%s): a %s" % (desc._name(), port_entry, value))
desc.addresses_v6.setdefault(address, []).append((int(min_port), int(max_port)))
@@ -524,10 +537,14 @@ def _parse_w_line(desc, value, validate):
w_comp = value.split(" ")
if len(w_comp) < 1:
- if not validate: return
+ if not validate:
+ return
+
raise ValueError("%s 'w' line is blank: w %s" % (desc._name(), value))
elif not w_comp[0].startswith("Bandwidth="):
- if not validate: return
+ if not validate:
+ return
+
raise ValueError("%s 'w' line needs to start with a 'Bandwidth=' entry: w %s" % (desc._name(), value))
for w_entry in w_comp:
@@ -538,13 +555,17 @@ def _parse_w_line(desc, value, validate):
if w_key == "Bandwidth":
if not (w_value and w_value.isdigit()):
- if not validate: return
+ if not validate:
+ return
+
raise ValueError("%s 'Bandwidth=' entry needs to have a numeric value: w %s" % (desc._name(), value))
desc.bandwidth = int(w_value)
elif w_key == "Measured":
if not (w_value and w_value.isdigit()):
- if not validate: return
+ if not validate:
+ return
+
raise ValueError("%s 'Measured=' entry needs to have a numeric value: w %s" % (desc._name(), value))
desc.measured = int(w_value)
@@ -559,7 +580,9 @@ def _parse_p_line(desc, value, validate):
try:
desc.exit_policy = stem.exit_policy.MicroExitPolicy(value)
except ValueError, exc:
- if not validate: return
+ if not validate:
+ return
+
raise ValueError("%s exit policy is malformed (%s): p %s" % (desc._name(), exc, value))
def _parse_m_line(desc, value, validate):
@@ -569,25 +592,32 @@ def _parse_m_line(desc, value, validate):
m_comp = value.split(" ")
if not (desc.document and desc.document.is_vote):
- if not validate: return
+ if not validate:
+ return
vote_status = "vote" if desc.document else "<undefined document>"
raise ValueError("%s 'm' line should only appear in votes (appeared in a %s): m %s" % (desc._name(), vote_status, value))
elif len(m_comp) < 1:
- if not validate: return
+ if not validate:
+ return
+
raise ValueError("%s 'm' line needs to start with a series of methods: m %s" % (desc._name(), value))
try:
methods = [int(entry) for entry in m_comp[0].split(",")]
except ValueError:
- if not validate: return
+ if not validate:
+ return
+
raise ValueError("%s microdescriptor methods should be a series of comma separated integers: m %s" % (desc._name(), value))
hashes = {}
for entry in m_comp[1:]:
if not '=' in entry:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("%s can only have a series of 'algorithm=digest' mappings after the methods: m %s" % (desc._name(), value))
hash_name, digest = entry.split('=', 1)
@@ -622,7 +652,9 @@ def _decode_fingerprint(identity, validate):
try:
identity_decoded = base64.b64decode(identity)
except TypeError:
- if not validate: return None
+ if not validate:
+ return None
+
raise ValueError("Unable to decode identity string '%s'" % identity)
for char in identity_decoded:
@@ -639,7 +671,9 @@ def _decode_fingerprint(identity, validate):
fingerprint += hex(ord(char))[2:].zfill(2).upper()
if not stem.util.tor_tools.is_valid_fingerprint(fingerprint):
- if not validate: return None
+ if not validate:
+ return None
+
raise ValueError("Decoded '%s' to be '%s', which isn't a valid fingerprint" % (identity, fingerprint))
return fingerprint
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 1ea13a2..037a4bd 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -126,7 +126,8 @@ def parse_file(descriptor_file, validate = True):
descriptor_text = "".join(descriptor_content)
yield RelayDescriptor(descriptor_text, validate, annotations)
- else: break # done parsing descriptors
+ else:
+ break # done parsing descriptors
class ServerDescriptor(stem.descriptor.Descriptor):
"""
@@ -257,7 +258,9 @@ class ServerDescriptor(stem.descriptor.Descriptor):
self.exit_policy = stem.exit_policy.ExitPolicy(*policy)
self._parse(entries, validate)
- if validate: self._check_constraints(entries)
+
+ if validate:
+ self._check_constraints(entries)
def digest(self):
"""
@@ -292,7 +295,8 @@ class ServerDescriptor(stem.descriptor.Descriptor):
if " " in line:
key, value = line.split(" ", 1)
annotation_dict[key] = value
- else: annotation_dict[line] = None
+ else:
+ annotation_dict[line] = None
self._annotation_dict = annotation_dict
@@ -326,14 +330,18 @@ class ServerDescriptor(stem.descriptor.Descriptor):
value, block_contents = values[0]
line = "%s %s" % (keyword, value) # original line
- if block_contents: line += "\n%s" % block_contents
+
+ if block_contents:
+ line += "\n%s" % block_contents
if keyword == "router":
# "router" nickname address ORPort SocksPort DirPort
router_comp = value.split()
if len(router_comp) < 5:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Router line must have five values: %s" % line)
if validate:
@@ -360,17 +368,24 @@ class ServerDescriptor(stem.descriptor.Descriptor):
bandwidth_comp = value.split()
if len(bandwidth_comp) < 3:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Bandwidth line must have three values: %s" % line)
-
- if not bandwidth_comp[0].isdigit():
- if not validate: continue
+ elif not bandwidth_comp[0].isdigit():
+ if not validate:
+ continue
+
raise ValueError("Bandwidth line's average rate isn't numeric: %s" % bandwidth_comp[0])
elif not bandwidth_comp[1].isdigit():
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Bandwidth line's burst rate isn't numeric: %s" % bandwidth_comp[1])
elif not bandwidth_comp[2].isdigit():
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Bandwidth line's observed rate isn't numeric: %s" % bandwidth_comp[2])
self.average_bandwidth = int(bandwidth_comp[0])
@@ -395,7 +410,8 @@ class ServerDescriptor(stem.descriptor.Descriptor):
try:
self.tor_version = stem.version.Version(version_str)
- except ValueError: pass
+ except ValueError:
+ pass
elif keyword == "published":
# "published" YYYY-MM-DD HH:MM:SS
@@ -458,7 +474,9 @@ class ServerDescriptor(stem.descriptor.Descriptor):
try:
self.uptime = int(value)
except ValueError:
- if not validate: continue
+ if not validate:
+ continue
+
raise ValueError("Uptime line must have an integer value: %s" % value)
elif keyword == "contact":
self.contact = value
@@ -484,23 +502,31 @@ class ServerDescriptor(stem.descriptor.Descriptor):
line = "%s %s" % (keyword, entry)
if not ":" in entry:
- if not validate: continue
- else: raise ValueError("or-address line missing a colon: %s" % line)
+ if not validate:
+ continue
+ else:
+ raise ValueError("or-address line missing a colon: %s" % line)
div = entry.rfind(":")
address, ports = entry[:div], entry[div + 1:]
is_ipv6 = address.startswith("[") and address.endswith("]")
- if is_ipv6: address = address[1:-1] # remove brackets
+
+ if is_ipv6:
+ address = address[1:-1] # remove brackets
if not ((not is_ipv6 and stem.util.connection.is_valid_ip_address(address)) or
(is_ipv6 and stem.util.connection.is_valid_ipv6_address(address))):
- if not validate: continue
- else: raise ValueError("or-address line has a malformed address: %s" % line)
+ if not validate:
+ continue
+ else:
+ raise ValueError("or-address line has a malformed address: %s" % line)
for port in ports.split(","):
if not stem.util.connection.is_valid_port(port):
- if not validate: break
- else: raise ValueError("or-address line has malformed ports: %s" % line)
+ if not validate:
+ break
+ else:
+ raise ValueError("or-address line has malformed ports: %s" % line)
self.address_alt.append((address, int(port), is_ipv6))
elif keyword in ("read-history", "write-history"):
@@ -525,7 +551,8 @@ class ServerDescriptor(stem.descriptor.Descriptor):
self.write_history_interval = interval
self.write_history_values = history_values
except ValueError, exc:
- if validate: raise exc
+ if validate:
+ raise exc
else:
self._unrecognized_lines.append(line)
diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index 9b0a111..56c68dc 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -171,11 +171,14 @@ class ExitPolicy(object):
display_ports, skip_ports = [], set()
for rule in self._get_rules():
- if not rule.is_address_wildcard(): continue
- elif rule.is_port_wildcard(): break
+ if not rule.is_address_wildcard():
+ continue
+ elif rule.is_port_wildcard():
+ break
for port in xrange(rule.min_port, rule.max_port + 1):
- if port in skip_ports: continue
+ if port in skip_ports:
+ continue
# if accept + white-list or reject + blacklist then add
if rule.is_accept == is_whitelist:
@@ -447,9 +450,11 @@ class ExitPolicyRule(object):
address_type = self.get_address_type()
if stem.util.connection.is_valid_ip_address(address):
- if address_type == AddressType.IPv6: return False
+ if address_type == AddressType.IPv6:
+ return False
elif stem.util.connection.is_valid_ipv6_address(address, allow_brackets = True):
- if address_type == AddressType.IPv4: return False
+ if address_type == AddressType.IPv4:
+ return False
address = address.lstrip("[").rstrip("]")
else:
@@ -468,7 +473,9 @@ class ExitPolicyRule(object):
else:
comparison_addr_bin = int(stem.util.connection.get_address_binary(address), 2)
comparison_addr_bin &= self._get_mask_bin()
- if self._get_address_bin() != comparison_addr_bin: return False
+
+ if self._get_address_bin() != comparison_addr_bin:
+ return False
if not self.is_port_wildcard():
if port is None:
@@ -510,7 +517,9 @@ class ExitPolicyRule(object):
elif address_type == AddressType.IPv6:
mask = stem.util.connection.get_mask_ipv6(self._masked_bits)
- if not cache: return mask
+ if not cache:
+ return mask
+
self._mask = mask
return self._mask
diff --git a/stem/process.py b/stem/process.py
index 4db51d3..e654e85 100644
--- a/stem/process.py
+++ b/stem/process.py
@@ -82,7 +82,9 @@ def launch_tor(tor_cmd = "tor", args = None, torrc_path = None, completion_perce
# starts a tor subprocess, raising an OSError if it fails
runtime_args, temp_file = [tor_cmd], None
- if args: runtime_args += args
+
+ if args:
+ runtime_args += args
if torrc_path:
if torrc_path == NO_TORRC:
@@ -100,8 +102,10 @@ def launch_tor(tor_cmd = "tor", args = None, torrc_path = None, completion_perce
def timeout_handler(signum, frame):
# terminates the uninitialized tor process and raise on timeout
if temp_file:
- try: os.remove(temp_file)
- except: pass
+ try:
+ os.remove(temp_file)
+ except:
+ pass
# We can't kill the subprocess on python 2.5 running Windows without the
# win32process module...
@@ -126,7 +130,8 @@ def launch_tor(tor_cmd = "tor", args = None, torrc_path = None, completion_perce
# this will provide empty results if the process is terminated
if not init_line:
- if timeout: signal.alarm(0) # stop alarm
+ if timeout:
+ signal.alarm(0) # stop alarm
# ... but best make sure
if stem.prereq.is_python_26():
@@ -137,25 +142,32 @@ def launch_tor(tor_cmd = "tor", args = None, torrc_path = None, completion_perce
raise OSError("Process terminated: %s" % last_problem)
# provide the caller with the initialization message if they want it
- if init_msg_handler: init_msg_handler(init_line)
+
+ if init_msg_handler:
+ init_msg_handler(init_line)
# return the process if we're done with bootstrapping
bootstrap_match = bootstrap_line.search(init_line)
problem_match = problem_line.search(init_line)
if bootstrap_match and int(bootstrap_match.groups()[0]) >= completion_percent:
- if timeout: signal.alarm(0) # stop alarm
+ if timeout:
+ signal.alarm(0) # stop alarm
if temp_file:
- try: os.remove(temp_file)
- except: pass
+ try:
+ os.remove(temp_file)
+ except:
+ pass
return tor_process
elif problem_match:
runlevel, msg = problem_match.groups()
if not "see warnings above" in msg:
- if ": " in msg: msg = msg.split(": ")[-1].strip()
+ if ": " in msg:
+ msg = msg.split(": ")[-1].strip()
+
last_problem = msg
def launch_tor_with_config(config, tor_cmd = "tor", completion_percent = 100, init_msg_handler = None, timeout = DEFAULT_INIT_TIMEOUT, take_ownership = False):
@@ -213,8 +225,10 @@ def launch_tor_with_config(config, tor_cmd = "tor", completion_percent = 100, in
return launch_tor(tor_cmd, args, torrc_path, completion_percent, init_msg_handler, timeout, take_ownership)
finally:
- try: os.remove(torrc_path)
- except: pass
+ try:
+ os.remove(torrc_path)
+ except:
+ pass
def _get_pid():
return str(os.getpid())
diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index 388d755..dbf50f9 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -137,7 +137,8 @@ class ControlMessage(object):
"""
for code, _, _ in self._parsed_content:
- if code == "250": return True
+ if code == "250":
+ return True
return False
@@ -367,7 +368,9 @@ class ControlLine(str):
"""
with self._remainder_lock:
- if self.is_empty(): raise IndexError("no remaining content to parse")
+ if self.is_empty():
+ raise IndexError("no remaining content to parse")
+
key_match = KEY_ARG.match(self._remainder)
if not key_match:
@@ -411,8 +414,10 @@ def _parse_entry(line, quoted, escaped):
next_entry, remainder = remainder[1:end_quote], remainder[end_quote + 1:]
else:
# non-quoted value, just need to check if there's more data afterward
- if " " in remainder: next_entry, remainder = remainder.split(" ", 1)
- else: next_entry, remainder = remainder, ""
+ if " " in remainder:
+ next_entry, remainder = remainder.split(" ", 1)
+ else:
+ next_entry, remainder = remainder, ""
if escaped:
for esc_sequence, replacement in CONTROL_ESCAPES.items():
diff --git a/stem/response/events.py b/stem/response/events.py
index 7ba077f..51aa3d2 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -103,7 +103,9 @@ class Event(stem.response.ControlMessage):
raise stem.ProtocolError("The %s value should be quoted, but didn't have an ending quote: %s" % (attr_name, self))
attr_values.append(positional.pop(0))
- if attr_values[-1].endswith('"'): break
+
+ if attr_values[-1].endswith('"'):
+ break
attr_value = " ".join(attr_values)[1:-1]
else:
diff --git a/stem/response/getconf.py b/stem/response/getconf.py
index bf16ec1..c8b7da3 100644
--- a/stem/response/getconf.py
+++ b/stem/response/getconf.py
@@ -22,7 +22,8 @@ class GetConfResponse(stem.response.ControlMessage):
self.entries = {}
remaining_lines = list(self)
- if self.content() == [("250", " ", "OK")]: return
+ if self.content() == [("250", " ", "OK")]:
+ return
if not self.is_ok():
unrecognized_keywords = []
diff --git a/stem/socket.py b/stem/socket.py
index 4dca361..b23b247 100644
--- a/stem/socket.py
+++ b/stem/socket.py
@@ -75,12 +75,17 @@ class ControlSocket(object):
with self._send_lock:
try:
- if not self.is_alive(): raise stem.SocketClosed()
+ if not self.is_alive():
+ raise stem.SocketClosed()
+
send_message(self._socket_file, message, raw)
except stem.SocketClosed, exc:
# if send_message raises a SocketClosed then we should properly shut
# everything down
- if self.is_alive(): self.close()
+
+ if self.is_alive():
+ self.close()
+
raise exc
def recv(self):
@@ -102,7 +107,9 @@ class ControlSocket(object):
socket_file = self._socket_file
- if not socket_file: raise stem.SocketClosed()
+ if not socket_file:
+ raise stem.SocketClosed()
+
return recv_message(socket_file)
except stem.SocketClosed, exc:
# If recv_message raises a SocketClosed then we should properly shut
@@ -168,7 +175,8 @@ class ControlSocket(object):
# longer alive it'll be safe to acquire the recv lock because recv()
# calls no longer block (raising SocketClosed instead).
- if self.is_alive(): self.close()
+ if self.is_alive():
+ self.close()
with self._recv_lock:
self._socket = self._make_socket()
@@ -200,20 +208,26 @@ class ControlSocket(object):
# if we haven't yet established a connection then this raises an error
# socket.error: [Errno 107] Transport endpoint is not connected
- try: self._socket.shutdown(socket.SHUT_RDWR)
- except socket.error: pass
+ try:
+ self._socket.shutdown(socket.SHUT_RDWR)
+ except socket.error:
+ pass
# Suppressing unexpected exceptions from close. For instance, if the
# socket's file has already been closed then with python 2.7 that raises
# with...
# error: [Errno 32] Broken pipe
- try: self._socket.close()
- except: pass
+ try:
+ self._socket.close()
+ except:
+ pass
if self._socket_file:
- try: self._socket_file.close()
- except: pass
+ try:
+ self._socket_file.close()
+ except:
+ pass
self._socket = None
self._socket_file = None
@@ -290,7 +304,8 @@ class ControlPort(ControlSocket):
self._control_addr = control_addr
self._control_port = control_port
- if connect: self.connect()
+ if connect:
+ self.connect()
def get_address(self):
"""
@@ -341,7 +356,8 @@ class ControlSocketFile(ControlSocket):
super(ControlSocketFile, self).__init__()
self._socket_path = socket_path
- if connect: self.connect()
+ if connect:
+ self.connect()
def get_socket_path(self):
"""
@@ -395,7 +411,8 @@ def send_message(control_file, message, raw = False):
* :class:`stem.SocketClosed` if the socket is known to be shut down
"""
- if not raw: message = send_formatting(message)
+ if not raw:
+ message = send_formatting(message)
try:
control_file.write(message)
@@ -441,7 +458,8 @@ def recv_message(control_file):
logging_prefix = "Error while receiving a control message (%s): "
while True:
- try: line = control_file.readline()
+ try:
+ line = control_file.readline()
except AttributeError:
# if the control_file has been closed then we will receive:
# AttributeError: 'NoneType' object has no attribute 'recv'
@@ -501,7 +519,8 @@ def recv_message(control_file):
# get a line with just a period
while True:
- try: line = control_file.readline()
+ try:
+ line = control_file.readline()
except socket.error, exc:
prefix = logging_prefix % "SocketClosed"
log.info(prefix + "received an exception while mid-way through a data reply (exception: \"%s\", read content: \"%s\")" % (exc, log.escape(raw_content)))
@@ -520,7 +539,9 @@ def recv_message(control_file):
# lines starting with a period are escaped by a second period (as per
# section 2.4 of the control-spec)
- if line.startswith(".."): line = line[1:]
+
+ if line.startswith(".."):
+ line = line[1:]
# appends to previous content, using a newline rather than CRLF
# separator (more conventional for multi-line string content outside
diff --git a/stem/util/conf.py b/stem/util/conf.py
index 0166ad9..57f1fda 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -169,11 +169,15 @@ class _SyncListener(object):
def update(self, config, key):
if key in self.config_dict:
new_value = config.get(key, self.config_dict[key])
- if new_value == self.config_dict[key]: return # no change
+
+ if new_value == self.config_dict[key]:
+ return # no change
if self.interceptor:
interceptor_value = self.interceptor(key, new_value)
- if interceptor_value: new_value = interceptor_value
+
+ if interceptor_value:
+ new_value = interceptor_value
self.config_dict[key] = new_value
@@ -219,7 +223,9 @@ def get_config(handle):
:param str handle: unique identifier used to access this config instance
"""
- if not handle in CONFS: CONFS[handle] = Config()
+ if not handle in CONFS:
+ CONFS[handle] = Config()
+
return CONFS[handle]
def parse_enum(key, value, enumeration):
@@ -265,7 +271,9 @@ def parse_enum_csv(key, value, enumeration, count = None):
"""
values = [val.upper().strip() for val in value.split(',')]
- if values == ['']: return []
+
+ if values == ['']:
+ return []
if count is None:
pass # no count validateion checks to do
@@ -415,7 +423,10 @@ class Config(object):
# strips any commenting or excess whitespace
comment_start = line.find("#")
- if comment_start != -1: line = line[:comment_start]
+
+ if comment_start != -1:
+ line = line[:comment_start]
+
line = line.strip()
# parse the key/value pair
@@ -463,7 +474,8 @@ class Config(object):
for entry_key in sorted(self.keys()):
for entry_value in self.get_value(entry_key, multiple = True):
# check for multi line entries
- if "\n" in entry_value: entry_value = "\n|" + entry_value.replace("\n", "\n|")
+ if "\n" in entry_value:
+ entry_value = "\n|" + entry_value.replace("\n", "\n|")
output_file.write('%s %s\n' % (entry_key, entry_value))
@@ -535,16 +547,21 @@ class Config(object):
with self._contents_lock:
if isinstance(value, str):
- if not overwrite and key in self._contents: self._contents[key].append(value)
- else: self._contents[key] = [value]
+ if not overwrite and key in self._contents:
+ self._contents[key].append(value)
+ else:
+ self._contents[key] = [value]
- for listener in self._listeners: listener(self, key)
+ for listener in self._listeners:
+ listener(self, key)
elif isinstance(value, (list, tuple)):
if not overwrite and key in self._contents:
self._contents[key] += value
- else: self._contents[key] = value
+ else:
+ self._contents[key] = value
- for listener in self._listeners: listener(self, key)
+ for listener in self._listeners:
+ listener(self, key)
else:
raise ValueError("Config.set() only accepts str, list, or tuple. Provided value was a '%s'" % type(value))
@@ -588,21 +605,27 @@ class Config(object):
is_multivalue = isinstance(default, (list, tuple, dict))
val = self.get_value(key, default, is_multivalue)
- if val == default: return val # don't try to infer undefined values
+
+ if val == default:
+ return val # don't try to infer undefined values
if isinstance(default, bool):
- if val.lower() == "true": val = True
- elif val.lower() == "false": val = False
+ if val.lower() == "true":
+ val = True
+ elif val.lower() == "false":
+ val = False
else:
log.debug("Config entry '%s' is expected to be a boolean, defaulting to '%s'" % (key, str(default)))
val = default
elif isinstance(default, int):
- try: val = int(val)
+ try:
+ val = int(val)
except ValueError:
log.debug("Config entry '%s' is expected to be an integer, defaulting to '%i'" % (key, default))
val = default
elif isinstance(default, float):
- try: val = float(val)
+ try:
+ val = float(val)
except ValueError:
log.debug("Config entry '%s' is expected to be a float, defaulting to '%f'" % (key, default))
val = default
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 3b16c1f..6892bed 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -39,10 +39,13 @@ def is_valid_ip_address(address):
:returns: **True** if input is a valid IPv4 address, **False** otherwise
"""
- if not isinstance(address, str): return False
+ if not isinstance(address, str):
+ return False
# checks if theres four period separated values
- if address.count(".") != 3: return False
+
+ if address.count(".") != 3:
+ return False
# checks that each value in the octet are decimal values between 0-255
for entry in address.split("."):
@@ -110,7 +113,8 @@ def is_valid_port(entry, allow_zero = False):
entry = int(entry)
- if allow_zero and entry == 0: return True
+ if allow_zero and entry == 0:
+ return True
return entry > 0 and entry < 65536
diff --git a/stem/util/enum.py b/stem/util/enum.py
index e07772d..d22cd22 100644
--- a/stem/util/enum.py
+++ b/stem/util/enum.py
@@ -73,7 +73,8 @@ class Enum(object):
key, val = entry, stem.util.str_tools.to_camel_case(entry)
elif isinstance(entry, tuple) and len(entry) == 2:
key, val = entry
- else: raise ValueError("Unrecognized input: %s" % args)
+ else:
+ raise ValueError("Unrecognized input: %s" % args)
keys.append(key)
values.append(val)
diff --git a/stem/util/log.py b/stem/util/log.py
index c2f7912..14b09df 100644
--- a/stem/util/log.py
+++ b/stem/util/log.py
@@ -78,7 +78,8 @@ DEDUPLICATION_MESSAGE_IDS = set()
# http://docs.python.org/release/3.1.3/library/logging.html#configuring-loggi…
class _NullHandler(logging.Handler):
- def emit(self, record): pass
+ def emit(self, record):
+ pass
if not LOGGER.handlers:
LOGGER.addHandler(_NullHandler())
@@ -99,8 +100,10 @@ def logging_level(runlevel):
:param stem.util.log.Runlevel runlevel: runlevel to be returned, no logging if **None**
"""
- if runlevel: return LOG_VALUES[runlevel]
- else: return logging.FATAL + 5
+ if runlevel:
+ return LOG_VALUES[runlevel]
+ else:
+ return logging.FATAL + 5
def escape(message):
"""
@@ -146,12 +149,24 @@ def log_once(message_id, runlevel, message):
log(runlevel, message)
# shorter aliases for logging at a runlevel
-def trace(message): log(Runlevel.TRACE, message)
-def debug(message): log(Runlevel.DEBUG, message)
-def info(message): log(Runlevel.INFO, message)
-def notice(message): log(Runlevel.NOTICE, message)
-def warn(message): log(Runlevel.WARN, message)
-def error(message): log(Runlevel.ERROR, message)
+
+def trace(message):
+ log(Runlevel.TRACE, message)
+
+def debug(message):
+ log(Runlevel.DEBUG, message)
+
+def info(message):
+ log(Runlevel.INFO, message)
+
+def notice(message):
+ log(Runlevel.NOTICE, message)
+
+def warn(message):
+ log(Runlevel.WARN, message)
+
+def error(message):
+ log(Runlevel.ERROR, message)
class LogBuffer(logging.Handler):
"""
diff --git a/stem/util/proc.py b/stem/util/proc.py
index 05a7ff0..436e061 100644
--- a/stem/util/proc.py
+++ b/stem/util/proc.py
@@ -52,8 +52,10 @@ IS_PROC_AVAILABLE, SYS_START_TIME, SYS_PHYSICAL_MEMORY = None, None, None
CLOCK_TICKS = None
# os.sysconf is only defined on unix
-try: CLOCK_TICKS = os.sysconf(os.sysconf_names["SC_CLK_TCK"])
-except AttributeError: pass
+try:
+ CLOCK_TICKS = os.sysconf(os.sysconf_names["SC_CLK_TCK"])
+except AttributeError:
+ pass
Stat = stem.util.enum.Enum(
("COMMAND", "command"), ("CPU_UTIME", "utime"),
@@ -148,9 +150,11 @@ def get_cwd(pid):
start_time, parameter = time.time(), "cwd"
proc_cwd_link = "/proc/%s/cwd" % pid
- if pid == 0: cwd = ""
+ if pid == 0:
+ cwd = ""
else:
- try: cwd = os.readlink(proc_cwd_link)
+ try:
+ cwd = os.readlink(proc_cwd_link)
except OSError:
exc = IOError("unable to read %s" % proc_cwd_link)
_log_failure(parameter, exc)
@@ -196,7 +200,9 @@ def get_memory_usage(pid):
"""
# checks if this is the kernel process
- if pid == 0: return (0, 0)
+
+ if pid == 0:
+ return (0, 0)
start_time, parameter = time.time(), "memory usage"
status_path = "/proc/%s/status" % pid
@@ -253,16 +259,23 @@ def get_stats(pid, *stat_types):
results = []
for stat_type in stat_types:
if stat_type == Stat.COMMAND:
- if pid == 0: results.append("sched")
- else: results.append(stat_comp[1])
+ if pid == 0:
+ results.append("sched")
+ else:
+ results.append(stat_comp[1])
elif stat_type == Stat.CPU_UTIME:
- if pid == 0: results.append("0")
- else: results.append(str(float(stat_comp[13]) / CLOCK_TICKS))
+ if pid == 0:
+ results.append("0")
+ else:
+ results.append(str(float(stat_comp[13]) / CLOCK_TICKS))
elif stat_type == Stat.CPU_STIME:
- if pid == 0: results.append("0")
- else: results.append(str(float(stat_comp[14]) / CLOCK_TICKS))
+ if pid == 0:
+ results.append("0")
+ else:
+ results.append(str(float(stat_comp[14]) / CLOCK_TICKS))
elif stat_type == Stat.START_TIME:
- if pid == 0: return get_system_start_time()
+ if pid == 0:
+ return get_system_start_time()
else:
# According to documentation, starttime is in field 21 and the unit is
# jiffies (clock ticks). We divide it for clock ticks, then add the
@@ -288,7 +301,8 @@ def get_connections(pid):
:raises: **IOError** if it can't be determined
"""
- if pid == 0: return []
+ if pid == 0:
+ return []
# fetches the inode numbers for socket file descriptors
start_time, parameter = time.time(), "process connections"
@@ -384,7 +398,9 @@ def _decode_proc_address_encoding(addr):
def _is_float(*value):
try:
- for v in value: float(v)
+ for v in value:
+ float(v)
+
return True
except ValueError:
return False
@@ -411,7 +427,8 @@ def _get_lines(file_path, line_prefixes, parameter):
proc_file, results = open(file_path), {}
for line in proc_file:
- if not remaining_prefixes: break # found everything we're looking for
+ if not remaining_prefixes:
+ break # found everything we're looking for
for prefix in remaining_prefixes:
if line.startswith(prefix):
diff --git a/stem/util/str_tools.py b/stem/util/str_tools.py
index b1e854d..443bd4f 100644
--- a/stem/util/str_tools.py
+++ b/stem/util/str_tools.py
@@ -62,9 +62,12 @@ def to_camel_case(label, divider = "_", joiner = " "):
words = []
for entry in label.split(divider):
- if len(entry) == 0: words.append("")
- elif len(entry) == 1: words.append(entry.upper())
- else: words.append(entry[0].upper() + entry[1:].lower())
+ if len(entry) == 0:
+ words.append("")
+ elif len(entry) == 1:
+ words.append(entry.upper())
+ else:
+ words.append(entry[0].upper() + entry[1:].lower())
return joiner.join(words)
@@ -95,8 +98,10 @@ def get_size_label(byte_count, decimal = 0, is_long = False, is_bytes = True):
:returns: **str** with human readable representation of the size
"""
- if is_bytes: return _get_label(SIZE_UNITS_BYTES, byte_count, decimal, is_long)
- else: return _get_label(SIZE_UNITS_BITS, byte_count, decimal, is_long)
+ if is_bytes:
+ return _get_label(SIZE_UNITS_BYTES, byte_count, decimal, is_long)
+ else:
+ return _get_label(SIZE_UNITS_BITS, byte_count, decimal, is_long)
def get_time_label(seconds, decimal = 0, is_long = False):
"""
diff --git a/stem/util/system.py b/stem/util/system.py
index a3a4c5f..acba9c1 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -104,7 +104,8 @@ def is_available(command, cached=True):
PATH, **False** otherwise
"""
- if " " in command: command = command.split(" ")[0]
+ if " " in command:
+ command = command.split(" ")[0]
if command in SHELL_COMMANDS:
# we can't actually look it up, so hope the shell really provides it...
@@ -116,7 +117,9 @@ def is_available(command, cached=True):
cmd_exists = False
for path in os.environ["PATH"].split(os.pathsep):
cmd_path = os.path.join(path, command)
- if is_windows(): cmd_path += ".exe"
+
+ if is_windows():
+ cmd_path += ".exe"
if os.path.exists(cmd_path) and os.access(cmd_path, os.X_OK):
cmd_exists = True
@@ -198,7 +201,9 @@ def get_pid_by_name(process_name):
if results and len(results) == 1:
pid = results[0].strip()
- if pid.isdigit(): return int(pid)
+
+ if pid.isdigit():
+ return int(pid)
# attempts to resolve using pidof, failing if:
# - we're running on bsd (command unavailable)
@@ -212,7 +217,9 @@ def get_pid_by_name(process_name):
if results and len(results) == 1 and len(results[0].split()) == 1:
pid = results[0].strip()
- if pid.isdigit(): return int(pid)
+
+ if pid.isdigit():
+ return int(pid)
# attempts to resolve using ps, failing if:
# - system's ps variant doesn't handle these flags (none known at the moment)
@@ -237,7 +244,9 @@ def get_pid_by_name(process_name):
if results and len(results) == 2:
pid = results[1].strip()
- if pid.isdigit(): return int(pid)
+
+ if pid.isdigit():
+ return int(pid)
if is_bsd():
# bsd variant of ps
@@ -249,7 +258,9 @@ def get_pid_by_name(process_name):
if len(results) == 1 and len(results[0].split()) > 0:
pid = results[0].split()[0]
- if pid.isdigit(): return int(pid)
+
+ if pid.isdigit():
+ return int(pid)
# resolves using lsof which works on both Linux and BSD, only failing if:
# - lsof is unavailable (not included by default on OpenBSD)
@@ -270,7 +281,9 @@ def get_pid_by_name(process_name):
if results and len(results) == 1:
pid = results[0].strip()
- if pid.isdigit(): return int(pid)
+
+ if pid.isdigit():
+ return int(pid)
log.debug("failed to resolve a pid for '%s'" % process_name)
return None
@@ -324,7 +337,9 @@ def get_pid_by_port(port):
if len(results) == 1 and len(results[0].split()) == 7:
results = results[0].split()[6] # process field (ex. "7184/tor")
pid = results[:results.find("/")]
- if pid.isdigit(): return int(pid)
+
+ if pid.isdigit():
+ return int(pid)
# attempts to resolve using sockstat, failing if:
# - sockstat doesn't accept the -4 flag (BSD only)
@@ -358,7 +373,9 @@ def get_pid_by_port(port):
if len(results) == 1:
pid = results[0].split()[2]
- if pid.isdigit(): return int(pid)
+
+ if pid.isdigit():
+ return int(pid)
# resolves using lsof which works on both Linux and BSD, only failing if:
# - lsof is unavailable (not included by default on OpenBSD)
@@ -388,7 +405,9 @@ def get_pid_by_port(port):
if len(results) == 1:
pid = results[0].split()[1]
- if pid.isdigit(): return int(pid)
+
+ if pid.isdigit():
+ return int(pid)
return None # all queries failed
@@ -423,7 +442,9 @@ def get_pid_by_open_file(path):
if results and len(results) == 1:
pid = results[0].strip()
- if pid.isdigit(): return int(pid)
+
+ if pid.isdigit():
+ return int(pid)
return None # all queries failed
@@ -438,8 +459,10 @@ def get_cwd(pid):
# try fetching via the proc contents if it's available
if stem.util.proc.is_available():
- try: return stem.util.proc.get_cwd(pid)
- except IOError: pass
+ try:
+ return stem.util.proc.get_cwd(pid)
+ except IOError:
+ pass
# Fall back to a pwdx query. This isn't available on BSD.
logging_prefix = "get_cwd(%s):" % pid
@@ -485,7 +508,8 @@ def get_cwd(pid):
# p2683
# n/proc/2683/cwd (readlink: Permission denied)
- if not " " in lsof_result: return lsof_result
+ if not " " in lsof_result:
+ return lsof_result
else:
log.debug("%s we got unexpected output from lsof: %s" % (logging_prefix, results))
@@ -513,7 +537,9 @@ def get_bsd_jail_id(pid):
if ps_output and len(ps_output) == 2 and len(ps_output[1].split()) == 1:
jid = ps_output[1].strip()
- if jid.isdigit(): return int(jid)
+
+ if jid.isdigit():
+ return int(jid)
os_name = platform.system()
if os_name == "FreeBSD":
@@ -549,7 +575,9 @@ def expand_path(path, cwd = None):
relative_path = os.path.expanduser(relative_path)
else:
# relative path, expand with the cwd
- if not cwd: cwd = os.getcwd()
+
+ if not cwd:
+ cwd = os.getcwd()
# we'll be dealing with both "my/path/" and "./my/path" entries, so
# cropping the later
@@ -597,10 +625,14 @@ def call(command, default = UNDEFINED):
elif stderr:
log.trace(trace_prefix + ", stderr:\n%s" % stderr)
- if stdout: return stdout.splitlines()
- else: return []
+ if stdout:
+ return stdout.splitlines()
+ else:
+ return []
except OSError, exc:
log.debug("System call (failed): %s (error: %s)" % (command, exc))
- if default != UNDEFINED: return default
- else: raise exc
+ if default != UNDEFINED:
+ return default
+ else:
+ raise exc
diff --git a/stem/util/term.py b/stem/util/term.py
index 05b51e3..d77fccf 100644
--- a/stem/util/term.py
+++ b/stem/util/term.py
@@ -84,8 +84,11 @@ def format(msg, *attr):
encoding = FG_ENCODING.get(text_attr, encoding)
encoding = BG_ENCODING.get(text_attr, encoding)
encoding = ATTR_ENCODING.get(text_attr, encoding)
- if encoding: encodings.append(encoding)
+
+ if encoding:
+ encodings.append(encoding)
if encodings:
return (CSI % ";".join(encodings)) + msg + RESET
- else: return msg
+ else:
+ return msg
diff --git a/stem/util/tor_tools.py b/stem/util/tor_tools.py
index d7a785a..3f15eb2 100644
--- a/stem/util/tor_tools.py
+++ b/stem/util/tor_tools.py
@@ -47,7 +47,9 @@ def is_valid_fingerprint(entry, check_prefix = False):
if not isinstance(entry, str):
return False
elif check_prefix:
- if not entry or entry[0] != "$": return False
+ if not entry or entry[0] != "$":
+ return False
+
entry = entry[1:]
return bool(FINGERPRINT_PATTERN.match(entry))
diff --git a/stem/version.py b/stem/version.py
index bf8c32c..76b8a88 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -125,9 +125,14 @@ class Version(object):
# The patch and status matches are optional (may be None) and have an extra
# proceeding period or dash if they exist. Stripping those off.
- if patch: patch = int(patch[1:])
- if status: status = status[1:]
- if extra: extra = extra[2:-1]
+ if patch:
+ patch = int(patch[1:])
+
+ if status:
+ status = status[1:]
+
+ if extra:
+ extra = extra[2:-1]
self.major = int(major)
self.minor = int(minor)
@@ -140,7 +145,8 @@ class Version(object):
self.git_commit = extra[4:]
else:
self.git_commit = None
- else: raise ValueError("'%s' isn't a properly formatted tor version" % version_str)
+ else:
+ raise ValueError("'%s' isn't a properly formatted tor version" % version_str)
def meets_requirements(self, requirements):
"""
@@ -155,7 +161,8 @@ class Version(object):
return self >= requirements
else:
for rule in requirements.rules:
- if rule(self): return True
+ if rule(self):
+ return True
return False
@@ -178,8 +185,10 @@ class Version(object):
my_version = max(0, self.__dict__[attr])
other_version = max(0, other.__dict__[attr])
- if my_version > other_version: return 1
- elif my_version < other_version: return -1
+ if my_version > other_version:
+ return 1
+ elif my_version < other_version:
+ return -1
# According to the version spec...
#
@@ -189,9 +198,12 @@ class Version(object):
my_status = self.status if self.status else ""
other_status = other.status if other.status else ""
- if my_status > other_status: return 1
- elif my_status < other_status: return -1
- else: return 0
+ if my_status > other_status:
+ return 1
+ elif my_status < other_status:
+ return -1
+ else:
+ return 0
class VersionRequirements(object):
"""
diff --git a/test/check_whitespace.py b/test/check_whitespace.py
index d65c5b5..6bbbea4 100644
--- a/test/check_whitespace.py
+++ b/test/check_whitespace.py
@@ -62,7 +62,7 @@ def pep8_issues(base_path = DEFAULT_TARGET):
#
# Someone else can change this if they really care.
- ignored_issues = "E111,E121,W293,E501,E302,E701,E251,E127"
+ ignored_issues = "E111,E121,W293,E501,E302,E251,E127"
issues = {}
pep8_output = system.call("pep8 --ignore %s %s" % (ignored_issues, base_path))
@@ -92,7 +92,9 @@ def get_issues(base_path = DEFAULT_TARGET):
issues = {}
for file_path in _get_files_with_suffix(base_path):
- with open(file_path) as f: file_contents = f.read()
+ with open(file_path) as f:
+ file_contents = f.read()
+
lines, file_issues, prev_indent = file_contents.split("\n"), [], 0
has_with_import, given_with_warning = False, False
is_block_comment = False
diff --git a/test/integ/connection/authentication.py b/test/integ/connection/authentication.py
index 5396d02..e707b49 100644
--- a/test/integ/connection/authentication.py
+++ b/test/integ/connection/authentication.py
@@ -47,10 +47,14 @@ def _can_authenticate(auth_type):
if not password_auth and not cookie_auth:
# open socket, anything but safecookie will work
return auth_type != stem.connection.AuthMethod.SAFECOOKIE
- elif auth_type == stem.connection.AuthMethod.PASSWORD: return password_auth
- elif auth_type == stem.connection.AuthMethod.COOKIE: return cookie_auth
- elif auth_type == stem.connection.AuthMethod.SAFECOOKIE: return safecookie_auth
- else: return False
+ elif auth_type == stem.connection.AuthMethod.PASSWORD:
+ return password_auth
+ elif auth_type == stem.connection.AuthMethod.COOKIE:
+ return cookie_auth
+ elif auth_type == stem.connection.AuthMethod.SAFECOOKIE:
+ return safecookie_auth
+ else:
+ return False
def _get_auth_failure_message(auth_type):
"""
@@ -105,7 +109,8 @@ class TestAuthenticate(unittest.TestCase):
Tests that the authenticate function can authenticate to our socket.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
with runner.get_tor_socket(False) as control_socket:
@@ -117,7 +122,8 @@ class TestAuthenticate(unittest.TestCase):
Tests that the authenticate function can authenticate via a Controller.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
with runner.get_tor_controller(False) as controller:
@@ -129,7 +135,8 @@ class TestAuthenticate(unittest.TestCase):
Tests the authenticate function with something like its pydoc example.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
tor_options = runner.get_options()
@@ -166,7 +173,8 @@ class TestAuthenticate(unittest.TestCase):
Tests the authenticate function's password argument.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
# this is a much better test if we're just using password auth, since
# authenticate will work reguardless if there's something else to
@@ -204,7 +212,8 @@ class TestAuthenticate(unittest.TestCase):
individually.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
tor_options = runner.get_options()
@@ -228,7 +237,8 @@ class TestAuthenticate(unittest.TestCase):
Tests the authenticate_none function.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
auth_type = stem.connection.AuthMethod.NONE
@@ -242,7 +252,8 @@ class TestAuthenticate(unittest.TestCase):
Tests the authenticate_password function.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
auth_type = stem.connection.AuthMethod.PASSWORD
auth_value = test.runner.CONTROL_PASSWORD
@@ -271,7 +282,8 @@ class TestAuthenticate(unittest.TestCase):
Tests the authenticate_cookie function.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
auth_value = test.runner.get_runner().get_auth_cookie_path()
@@ -295,7 +307,8 @@ class TestAuthenticate(unittest.TestCase):
value.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
auth_value = test.runner.get_runner().get_test_dir("fake_cookie")
@@ -333,7 +346,8 @@ class TestAuthenticate(unittest.TestCase):
shouldn't exist.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
for auth_type in self.cookie_auth_methods:
auth_value = "/if/this/exists/then/they're/asking/for/a/failure"
@@ -346,7 +360,8 @@ class TestAuthenticate(unittest.TestCase):
socket.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
auth_value = test.runner.get_runner().get_torrc_path(True)
diff --git a/test/integ/connection/connect.py b/test/integ/connection/connect.py
index fcf55a9..66b793d 100644
--- a/test/integ/connection/connect.py
+++ b/test/integ/connection/connect.py
@@ -23,7 +23,8 @@ class TestConnect(unittest.TestCase):
Basic sanity checks for the connect_port function.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
@@ -44,7 +45,8 @@ class TestConnect(unittest.TestCase):
Basic sanity checks for the connect_socket_file function.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
diff --git a/test/integ/control/base_controller.py b/test/integ/control/base_controller.py
index d43b009..25af63d 100644
--- a/test/integ/control/base_controller.py
+++ b/test/integ/control/base_controller.py
@@ -41,7 +41,8 @@ class TestBaseController(unittest.TestCase):
trigger concurrency issues.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
elif stem.util.system.is_mac():
test.runner.skip(self, "(ticket #6235)")
return
@@ -58,7 +59,8 @@ class TestBaseController(unittest.TestCase):
Tests a basic query with the msg() method.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket() as control_socket:
controller = stem.control.BaseController(control_socket)
@@ -69,7 +71,8 @@ class TestBaseController(unittest.TestCase):
Tests the msg() method against an invalid controller command.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket() as control_socket:
controller = stem.control.BaseController(control_socket)
@@ -81,7 +84,8 @@ class TestBaseController(unittest.TestCase):
Tests the msg() method against a non-existant GETINFO option.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket() as control_socket:
controller = stem.control.BaseController(control_socket)
@@ -94,7 +98,8 @@ class TestBaseController(unittest.TestCase):
is a simple attempt to trigger concurrency issues.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
elif stem.util.system.is_mac():
test.runner.skip(self, "(ticket #6235)")
return
@@ -133,7 +138,8 @@ class TestBaseController(unittest.TestCase):
listeners will still receive all of the enqueued events.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
class ControlledListener(stem.control.BaseController):
"""
@@ -188,7 +194,8 @@ class TestBaseController(unittest.TestCase):
Basic check for get_latest_heartbeat().
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
# makes a getinfo query, then checks that the heartbeat is close to now
with test.runner.get_runner().get_tor_socket() as control_socket:
@@ -202,7 +209,8 @@ class TestBaseController(unittest.TestCase):
remove_status_listener() methods.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
state_observer = StateObserver()
diff --git a/test/integ/control/controller.py b/test/integ/control/controller.py
index b769fbc..6d91f50 100644
--- a/test/integ/control/controller.py
+++ b/test/integ/control/controller.py
@@ -33,7 +33,8 @@ class TestController(unittest.TestCase):
Basic sanity check for the from_port constructor.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
if test.runner.Torrc.PORT in test.runner.get_runner().get_options():
with stem.control.Controller.from_port(control_port = test.runner.CONTROL_PORT) as controller:
@@ -46,7 +47,8 @@ class TestController(unittest.TestCase):
Basic sanity check for the from_socket_file constructor.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
if test.runner.Torrc.SOCKET in test.runner.get_runner().get_options():
with stem.control.Controller.from_socket_file(socket_path = test.runner.CONTROL_SOCKET_PATH) as controller:
@@ -60,7 +62,8 @@ class TestController(unittest.TestCase):
them. Then remove the listeners.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
event_notice1, event_notice2 = threading.Event(), threading.Event()
event_buffer1, event_buffer2 = [], []
@@ -74,6 +77,7 @@ class TestController(unittest.TestCase):
event_notice2.set()
runner = test.runner.get_runner()
+
with runner.get_tor_controller() as controller:
controller.add_event_listener(listener1, EventType.BW)
controller.add_event_listener(listener2, EventType.BW, EventType.DEBUG)
@@ -116,7 +120,8 @@ class TestController(unittest.TestCase):
then reconnects to tor.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
event_notice = threading.Event()
event_buffer = []
@@ -126,6 +131,7 @@ class TestController(unittest.TestCase):
event_notice.set()
runner = test.runner.get_runner()
+
with runner.get_tor_controller() as controller:
controller.add_event_listener(listener, EventType.BW)
@@ -192,7 +198,8 @@ class TestController(unittest.TestCase):
Exercises GETINFO with valid and invalid queries.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
@@ -231,9 +238,11 @@ class TestController(unittest.TestCase):
Test that the convenient method get_version() works.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
+
with runner.get_tor_controller() as controller:
version = controller.get_version()
self.assertTrue(isinstance(version, stem.version.Version))
@@ -244,9 +253,11 @@ class TestController(unittest.TestCase):
Test that the convenient method authenticate() works.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
+
with runner.get_tor_controller(False) as controller:
controller.authenticate(test.runner.CONTROL_PASSWORD)
test.runner.exercise_controller(self, controller)
@@ -256,7 +267,8 @@ class TestController(unittest.TestCase):
Test that the convenient method protocolinfo() works.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
@@ -288,12 +300,14 @@ class TestController(unittest.TestCase):
Exercises GETCONF with valid and invalid queries.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
with runner.get_tor_controller() as controller:
socket = controller.get_socket()
+
if isinstance(socket, stem.socket.ControlPort):
connection_value = str(socket.get_port())
config_key = "ControlPort"
@@ -352,7 +366,8 @@ class TestController(unittest.TestCase):
and invalid requests.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
tmpdir = tempfile.mkdtemp()
@@ -425,8 +440,10 @@ class TestController(unittest.TestCase):
Exercises Controller.load_conf with valid and invalid requests.
"""
- if test.runner.require_control(self): return
- elif test.runner.require_version(self, stem.version.Requirement.LOADCONF): return
+ if test.runner.require_control(self):
+ return
+ elif test.runner.require_version(self, stem.version.Requirement.LOADCONF):
+ return
runner = test.runner.get_runner()
@@ -436,6 +453,7 @@ class TestController(unittest.TestCase):
try:
# invalid requests
self.assertRaises(stem.InvalidRequest, controller.load_conf, "ContactInfo confloaded")
+
try:
controller.load_conf("Blahblah blah")
self.fail()
@@ -443,6 +461,7 @@ class TestController(unittest.TestCase):
self.assertEqual(["Blahblah"], exc.arguments)
# valid config
+
controller.load_conf(runner.get_torrc_contents() + "\nContactInfo confloaded\n")
self.assertEqual("confloaded", controller.get_conf("ContactInfo"))
finally:
@@ -450,7 +469,8 @@ class TestController(unittest.TestCase):
controller.load_conf(oldconf)
def test_saveconf(self):
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
@@ -462,6 +482,7 @@ class TestController(unittest.TestCase):
try:
controller.set_conf("ContactInfo", "confsaved")
controller.save_conf()
+
with file(runner.get_torrc_path()) as torrcfile:
self.assertTrue("\nContactInfo confsaved\n" in torrcfile.read())
finally:
@@ -472,7 +493,9 @@ class TestController(unittest.TestCase):
"""
Test Controller.get_socks_ports against a running tor instance.
"""
- if test.runner.require_control(self): return
+
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
@@ -484,7 +507,8 @@ class TestController(unittest.TestCase):
Test Controller.enable_feature with valid and invalid inputs.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
@@ -498,22 +522,26 @@ class TestController(unittest.TestCase):
# the orconn-status results will be empty if we don't have a connection
if orconn_output == '':
- if test.runner.require_online(self): return
+ if test.runner.require_online(self):
+ return
self.assertTrue("VERBOSE_NAMES" in controller._enabled_features)
self.assertRaises(stem.InvalidArguments, controller.enable_feature, ["NOT", "A", "FEATURE"])
+
try:
controller.enable_feature(["NOT", "A", "FEATURE"])
except stem.InvalidArguments, exc:
self.assertEqual(["NOT"], exc.arguments)
- else: self.fail()
+ else:
+ self.fail()
def test_signal(self):
"""
Test controller.signal with valid and invalid signals.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_controller() as controller:
# valid signal
@@ -523,9 +551,12 @@ class TestController(unittest.TestCase):
self.assertRaises(stem.InvalidArguments, controller.signal, "FOOBAR")
def test_extendcircuit(self):
- if test.runner.require_control(self): return
- elif test.runner.require_online(self): return
- elif test.runner.require_version(self, Requirement.EXTENDCIRCUIT_PATH_OPTIONAL): return
+ if test.runner.require_control(self):
+ return
+ elif test.runner.require_online(self):
+ return
+ elif test.runner.require_version(self, Requirement.EXTENDCIRCUIT_PATH_OPTIONAL):
+ return
with test.runner.get_runner().get_tor_controller() as controller:
circuit_id = controller.extend_circuit('0')
@@ -544,9 +575,12 @@ class TestController(unittest.TestCase):
Tests Controller.repurpose_circuit with valid and invalid input.
"""
- if test.runner.require_control(self): return
- elif test.runner.require_online(self): return
- elif test.runner.require_version(self, Requirement.EXTENDCIRCUIT_PATH_OPTIONAL): return
+ if test.runner.require_control(self):
+ return
+ elif test.runner.require_online(self):
+ return
+ elif test.runner.require_version(self, Requirement.EXTENDCIRCUIT_PATH_OPTIONAL):
+ return
runner = test.runner.get_runner()
@@ -568,9 +602,12 @@ class TestController(unittest.TestCase):
Tests Controller.close_circuit with valid and invalid input.
"""
- if test.runner.require_control(self): return
- elif test.runner.require_online(self): return
- elif test.runner.require_version(self, Requirement.EXTENDCIRCUIT_PATH_OPTIONAL): return
+ if test.runner.require_control(self):
+ return
+ elif test.runner.require_online(self):
+ return
+ elif test.runner.require_version(self, Requirement.EXTENDCIRCUIT_PATH_OPTIONAL):
+ return
runner = test.runner.get_runner()
@@ -596,8 +633,10 @@ class TestController(unittest.TestCase):
Tests Controller.get_streams().
"""
- if test.runner.require_control(self): return
- elif test.runner.require_online(self): return
+ if test.runner.require_control(self):
+ return
+ elif test.runner.require_online(self):
+ return
host = "38.229.72.14" # www.torproject.org
port = 443
@@ -622,8 +661,10 @@ class TestController(unittest.TestCase):
Tests Controller.close_stream with valid and invalid input.
"""
- if test.runner.require_control(self): return
- elif test.runner.require_online(self): return
+ if test.runner.require_control(self):
+ return
+ elif test.runner.require_online(self):
+ return
runner = test.runner.get_runner()
@@ -647,8 +688,10 @@ class TestController(unittest.TestCase):
self.assertRaises(stem.InvalidArguments, controller.close_stream, "blarg")
def test_mapaddress(self):
- if test.runner.require_control(self): return
- elif test.runner.require_online(self): return
+ if test.runner.require_control(self):
+ return
+ elif test.runner.require_online(self):
+ return
runner = test.runner.get_runner()
@@ -675,7 +718,8 @@ class TestController(unittest.TestCase):
runner = test.runner.get_runner()
descriptor_path = runner.get_test_dir("cached-descriptors")
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
elif not os.path.exists(descriptor_path):
test.runner.skip(self, "(no cached descriptors)")
return
@@ -711,7 +755,8 @@ class TestController(unittest.TestCase):
runner = test.runner.get_runner()
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with runner.get_tor_controller() as controller:
count = 0
@@ -725,7 +770,8 @@ class TestController(unittest.TestCase):
# while to do so).
count += 1
- if count > 10: break
+ if count > 10:
+ break
def test_get_network_status(self):
"""
@@ -735,7 +781,8 @@ class TestController(unittest.TestCase):
runner = test.runner.get_runner()
descriptor_path = runner.get_test_dir("cached-consensus")
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
elif not os.path.exists(descriptor_path):
test.runner.skip(self, "(no cached descriptors)")
return
@@ -777,7 +824,8 @@ class TestController(unittest.TestCase):
runner = test.runner.get_runner()
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with runner.get_tor_controller() as controller:
count = 0
@@ -787,12 +835,16 @@ class TestController(unittest.TestCase):
self.assertTrue(desc.nickname is not None)
count += 1
- if count > 10: break
+ if count > 10:
+ break
def test_attachstream(self):
- if test.runner.require_control(self): return
- elif test.runner.require_online(self): return
- elif test.runner.require_version(self, Requirement.EXTENDCIRCUIT_PATH_OPTIONAL): return
+ if test.runner.require_control(self):
+ return
+ elif test.runner.require_online(self):
+ return
+ elif test.runner.require_version(self, Requirement.EXTENDCIRCUIT_PATH_OPTIONAL):
+ return
circuit_id = None
@@ -823,9 +875,12 @@ class TestController(unittest.TestCase):
Fetches circuits via the get_circuits() method.
"""
- if test.runner.require_control(self): return
- elif test.runner.require_online(self): return
- elif test.runner.require_version(self, Requirement.EXTENDCIRCUIT_PATH_OPTIONAL): return
+ if test.runner.require_control(self):
+ return
+ elif test.runner.require_online(self):
+ return
+ elif test.runner.require_version(self, Requirement.EXTENDCIRCUIT_PATH_OPTIONAL):
+ return
runner = test.runner.get_runner()
with runner.get_tor_controller() as controller:
diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py
index a2bf144..1293b3c 100644
--- a/test/integ/descriptor/extrainfo_descriptor.py
+++ b/test/integ/descriptor/extrainfo_descriptor.py
@@ -139,7 +139,9 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
"""
# lengthy test and uneffected by targets, so only run once
- if test.runner.only_run_once(self, "test_cached_descriptor"): return
+
+ if test.runner.only_run_once(self, "test_cached_descriptor"):
+ return
descriptor_path = test.runner.get_runner().get_test_dir("cached-extrainfo")
diff --git a/test/integ/descriptor/networkstatus.py b/test/integ/descriptor/networkstatus.py
index ad2933e..862c166 100644
--- a/test/integ/descriptor/networkstatus.py
+++ b/test/integ/descriptor/networkstatus.py
@@ -21,7 +21,9 @@ class TestNetworkStatus(unittest.TestCase):
"""
# lengthy test and uneffected by targets, so only run once
- if test.runner.only_run_once(self, "test_cached_consensus"): return
+
+ if test.runner.only_run_once(self, "test_cached_consensus"):
+ return
consensus_path = test.runner.get_runner().get_test_dir("cached-consensus")
@@ -67,7 +69,9 @@ class TestNetworkStatus(unittest.TestCase):
"""
# lengthy test and uneffected by targets, so only run once
- if test.runner.only_run_once(self, "test_cached_microdesc_consensus"): return
+
+ if test.runner.only_run_once(self, "test_cached_microdesc_consensus"):
+ return
consensus_path = test.runner.get_runner().get_test_dir("cached-microdesc-consensus")
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 637583e..ba807f0 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -64,7 +64,8 @@ def _get_raw_tar_descriptors():
raw_descriptors.append(entry.read())
entry.close()
finally:
- if tar_file: tar_file.close()
+ if tar_file:
+ tar_file.close()
TAR_DESCRIPTORS = raw_descriptors
@@ -240,7 +241,9 @@ class TestDescriptorReader(unittest.TestCase):
# the saving functionality.
reader = stem.descriptor.reader.DescriptorReader(descriptor_path, persistence_path = persistence_path)
- with reader: self.assertEqual(1, len(list(reader)))
+
+ with reader:
+ self.assertEqual(1, len(list(reader)))
# check that we've saved reading example_descriptor
self.assertTrue(os.path.exists(persistence_path))
@@ -254,7 +257,9 @@ class TestDescriptorReader(unittest.TestCase):
# descriptor file. This in essence just tests its loading functionality.
reader = stem.descriptor.reader.DescriptorReader(descriptor_path, persistence_path = persistence_path)
- with reader: self.assertEqual(0, len(list(reader)))
+
+ with reader:
+ self.assertEqual(0, len(list(reader)))
def test_archived_uncompressed(self):
"""
@@ -299,7 +304,9 @@ class TestDescriptorReader(unittest.TestCase):
"""
# Skip on windows since SIGALRM is unavailable
- if system.is_windows(): test.runner.skip(self, "(SIGALRM unavailable)")
+
+ if system.is_windows():
+ test.runner.skip(self, "(SIGALRM unavailable)")
is_test_running = True
reader = stem.descriptor.reader.DescriptorReader("/usr")
@@ -335,7 +342,9 @@ class TestDescriptorReader(unittest.TestCase):
expected_results[path] = last_modified
reader = stem.descriptor.reader.DescriptorReader(DESCRIPTOR_TEST_DATA)
- with reader: list(reader) # iterates over all of the descriptors
+
+ with reader:
+ list(reader) # iterates over all of the descriptors
self.assertEquals(expected_results, reader.get_processed_files())
@@ -349,12 +358,14 @@ class TestDescriptorReader(unittest.TestCase):
reader = stem.descriptor.reader.DescriptorReader(DESCRIPTOR_TEST_DATA)
reader.register_skip_listener(skip_listener.listener)
- with reader: list(reader) # iterates over all of the descriptors
+ with reader:
+ list(reader) # iterates over all of the descriptors
self.assertEqual(4, len(skip_listener.results))
for skip_path, skip_exception in skip_listener.results:
- if skip_path.endswith(".swp"): continue # skip vim temp files
+ if skip_path.endswith(".swp"):
+ continue # skip vim temp files
if not os.path.basename(skip_path) in ("riddle", "tiny.png", "vote", "new_metrics_type"):
self.fail("Unexpected non-descriptor content: %s" % skip_path)
@@ -378,7 +389,9 @@ class TestDescriptorReader(unittest.TestCase):
reader.set_processed_files(initial_processed_files)
self.assertEquals(initial_processed_files, reader.get_processed_files())
- with reader: list(reader) # iterates over all of the descriptors
+
+ with reader:
+ list(reader) # iterates over all of the descriptors
self.assertEquals(1, len(skip_listener.results))
@@ -405,7 +418,9 @@ class TestDescriptorReader(unittest.TestCase):
skip_listener = SkipListener()
reader = stem.descriptor.reader.DescriptorReader(test_path)
reader.register_skip_listener(skip_listener.listener)
- with reader: list(reader) # iterates over all of the descriptors
+
+ with reader:
+ list(reader) # iterates over all of the descriptors
self.assertEqual(1, len(skip_listener.results))
@@ -437,7 +452,9 @@ class TestDescriptorReader(unittest.TestCase):
skip_listener = SkipListener()
reader = stem.descriptor.reader.DescriptorReader(test_path)
reader.register_skip_listener(skip_listener.listener)
- with reader: list(reader) # iterates over all of the descriptors
+
+ with reader:
+ list(reader) # iterates over all of the descriptors
self.assertEqual(1, len(skip_listener.results))
@@ -459,7 +476,9 @@ class TestDescriptorReader(unittest.TestCase):
skip_listener = SkipListener()
reader = stem.descriptor.reader.DescriptorReader(test_path)
reader.register_skip_listener(skip_listener.listener)
- with reader: list(reader) # iterates over all of the descriptors
+
+ with reader:
+ list(reader) # iterates over all of the descriptors
self.assertEqual(1, len(skip_listener.results))
@@ -477,7 +496,9 @@ class TestDescriptorReader(unittest.TestCase):
skip_listener = SkipListener()
reader = stem.descriptor.reader.DescriptorReader(test_path)
reader.register_skip_listener(skip_listener.listener)
- with reader: list(reader) # iterates over all of the descriptors
+
+ with reader:
+ list(reader) # iterates over all of the descriptors
self.assertEqual(1, len(skip_listener.results))
diff --git a/test/integ/descriptor/server_descriptor.py b/test/integ/descriptor/server_descriptor.py
index a2ee34a..b6b8e62 100644
--- a/test/integ/descriptor/server_descriptor.py
+++ b/test/integ/descriptor/server_descriptor.py
@@ -147,7 +147,9 @@ Qlx9HNCqCY877ztFRC624ja2ql6A2hBcuoYMbkHjcQ4=
"""
# lengthy test and uneffected by targets, so only run once
- if test.runner.only_run_once(self, "test_cached_descriptor"): return
+
+ if test.runner.only_run_once(self, "test_cached_descriptor"):
+ return
descriptor_path = test.runner.get_runner().get_test_dir("cached-descriptors")
diff --git a/test/integ/process.py b/test/integ/process.py
index ea8909a..6629575 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -45,7 +45,8 @@ class TestProcess(unittest.TestCase):
test.runner.skip(self, "(unable to kill subprocesses)")
return
- if test.runner.only_run_once(self, "test_launch_tor_with_config"): return
+ if test.runner.only_run_once(self, "test_launch_tor_with_config"):
+ return
# Launch tor without a torrc, but with a control port. Confirms that this
# works by checking that we're still able to access the new instance.
@@ -71,7 +72,9 @@ class TestProcess(unittest.TestCase):
getconf_response = control_socket.recv()
self.assertEquals("ControlPort=2778", str(getconf_response))
finally:
- if control_socket: control_socket.close()
+ if control_socket:
+ control_socket.close()
+
_kill_process(tor_process)
def test_launch_tor_with_timeout(self):
@@ -83,7 +86,8 @@ class TestProcess(unittest.TestCase):
test.runner.skip(self, "(unable to kill subprocesses)")
return
- if test.runner.only_run_once(self, "test_launch_tor_with_timeout"): return
+ if test.runner.only_run_once(self, "test_launch_tor_with_timeout"):
+ return
runner = test.runner.get_runner()
start_time = time.time()
@@ -106,8 +110,10 @@ class TestProcess(unittest.TestCase):
elif not stem.util.system.is_available("sleep"):
test.runner.skip(self, "('sleep' command is unavailable)")
return
- elif test.runner.only_run_once(self, "test_take_ownership_via_pid"): return
- elif test.runner.require_version(self, stem.version.Requirement.TAKEOWNERSHIP): return
+ elif test.runner.only_run_once(self, "test_take_ownership_via_pid"):
+ return
+ elif test.runner.require_version(self, stem.version.Requirement.TAKEOWNERSHIP):
+ return
# Have os.getpid provide the pid of a process we can safely kill. I hate
# needing to a _get_pid() helper but after much head scratching I haven't
@@ -148,8 +154,10 @@ class TestProcess(unittest.TestCase):
connects, then disconnects..
"""
- if test.runner.only_run_once(self, "test_take_ownership_via_controller"): return
- elif test.runner.require_version(self, stem.version.Requirement.TAKEOWNERSHIP): return
+ if test.runner.only_run_once(self, "test_take_ownership_via_controller"):
+ return
+ elif test.runner.require_version(self, stem.version.Requirement.TAKEOWNERSHIP):
+ return
tor_process = stem.process.launch_tor_with_config(
tor_cmd = test.runner.get_runner().get_tor_command(),
diff --git a/test/integ/response/protocolinfo.py b/test/integ/response/protocolinfo.py
index 2affe17..623ce48 100644
--- a/test/integ/response/protocolinfo.py
+++ b/test/integ/response/protocolinfo.py
@@ -30,7 +30,8 @@ class TestProtocolInfo(unittest.TestCase):
connection.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
control_socket = test.runner.get_runner().get_tor_socket(False)
control_socket.send("PROTOCOLINFO 1")
@@ -58,7 +59,8 @@ class TestProtocolInfo(unittest.TestCase):
with the 'RELATIVE' target.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
if test.runner.Torrc.PORT in test.runner.get_runner().get_options():
cwd_by_port_lookup_prefixes = (
@@ -93,7 +95,8 @@ class TestProtocolInfo(unittest.TestCase):
re-establish it.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket(False) as control_socket:
for _ in range(5):
@@ -106,7 +109,8 @@ class TestProtocolInfo(unittest.TestCase):
already disconnected it.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket(False) as control_socket:
# makes a couple protocolinfo queries outside of get_protocolinfo first
diff --git a/test/integ/socket/control_message.py b/test/integ/socket/control_message.py
index 2a358cb..5c78f1a 100644
--- a/test/integ/socket/control_message.py
+++ b/test/integ/socket/control_message.py
@@ -17,7 +17,8 @@ class TestControlMessage(unittest.TestCase):
Checks message parsing when we have a valid but unauthenticated socket.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
# If an unauthenticated connection gets a message besides AUTHENTICATE or
# PROTOCOLINFO then tor will give an 'Authentication required.' message and
@@ -59,7 +60,8 @@ class TestControlMessage(unittest.TestCase):
Parses the response for a command which doesn't exist.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket() as control_socket:
control_socket.send("blarg")
@@ -74,7 +76,8 @@ class TestControlMessage(unittest.TestCase):
Parses the response for a GETINFO query which doesn't exist.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket() as control_socket:
control_socket.send("GETINFO blarg")
@@ -89,7 +92,8 @@ class TestControlMessage(unittest.TestCase):
Parses the 'GETINFO config-file' response.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
torrc_dst = runner.get_torrc_path()
@@ -152,7 +156,8 @@ class TestControlMessage(unittest.TestCase):
Issues 'SETEVENTS BW' and parses a couple events.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket() as control_socket:
control_socket.send("SETEVENTS BW")
diff --git a/test/integ/socket/control_socket.py b/test/integ/socket/control_socket.py
index 2f2a4e7..13daaf4 100644
--- a/test/integ/socket/control_socket.py
+++ b/test/integ/socket/control_socket.py
@@ -23,7 +23,8 @@ class TestControlSocket(unittest.TestCase):
Sends multiple requests before receiving back any of the replies.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
tor_version = runner.get_tor_version()
@@ -42,7 +43,8 @@ class TestControlSocket(unittest.TestCase):
Sends a message after we've closed the connection.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket() as control_socket:
self.assertTrue(control_socket.is_alive())
@@ -61,7 +63,8 @@ class TestControlSocket(unittest.TestCase):
call. With a file socket, however, we'll also fail when calling send().
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket() as control_socket:
control_socket.send("QUIT")
@@ -83,7 +86,8 @@ class TestControlSocket(unittest.TestCase):
Receives a message after we've closed the connection.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket() as control_socket:
self.assertTrue(control_socket.is_alive())
@@ -98,7 +102,8 @@ class TestControlSocket(unittest.TestCase):
end.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket() as control_socket:
control_socket.send("QUIT")
@@ -117,7 +122,8 @@ class TestControlSocket(unittest.TestCase):
Checks that we can reconnect, use, and disconnect a socket repeatedly.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
with test.runner.get_runner().get_tor_socket(False) as control_socket:
for _ in range(10):
diff --git a/test/integ/version.py b/test/integ/version.py
index 9195126..9542c63 100644
--- a/test/integ/version.py
+++ b/test/integ/version.py
@@ -37,7 +37,8 @@ class TestVersion(unittest.TestCase):
test instance provides.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
runner = test.runner.get_runner()
system_tor_version = stem.version.get_system_tor_version(runner.get_tor_command())
@@ -49,7 +50,8 @@ class TestVersion(unittest.TestCase):
we can parse it.
"""
- if test.runner.require_control(self): return
+ if test.runner.require_control(self):
+ return
control_socket = test.runner.get_runner().get_tor_socket()
control_socket.send("GETINFO version")
diff --git a/test/mocking.py b/test/mocking.py
index ff314ee..1ebe88d 100644
--- a/test/mocking.py
+++ b/test/mocking.py
@@ -193,16 +193,25 @@ NETWORK_STATUS_DOCUMENT_FOOTER = (
)
def no_op():
- def _no_op(*args): pass
+ def _no_op(*args):
+ pass
+
return _no_op
def return_value(value):
- def _return_value(*args): return value
+ def _return_value(*args):
+ return value
+
return _return_value
-def return_true(): return return_value(True)
-def return_false(): return return_value(False)
-def return_none(): return return_value(None)
+def return_true():
+ return return_value(True)
+
+def return_false():
+ return return_value(False)
+
+def return_none():
+ return return_value(None)
def return_for_args(args_to_return_value, default = None, is_method = False):
"""
@@ -266,7 +275,9 @@ def return_for_args(args_to_return_value, default = None, is_method = False):
return _return_value
def raise_exception(exception):
- def _raise(*args): raise exception
+ def _raise(*args):
+ raise exception
+
return _raise
def support_with(obj):
@@ -425,7 +436,8 @@ def get_all_combinations(attr, include_empty = False):
# * itertools.product(attr, attr) => all two-element combinations
# * ... etc
- if include_empty: yield ()
+ if include_empty:
+ yield ()
seen = set()
for index in xrange(1, len(attr) + 1):
@@ -485,7 +497,9 @@ def get_message(content, reformat = True):
"""
if reformat:
- if not content.endswith("\n"): content += "\n"
+ if not content.endswith("\n"):
+ content += "\n"
+
content = content.replace("\n", "\r\n")
return stem.socket.recv_message(StringIO.StringIO(content))
@@ -547,18 +561,23 @@ def _get_descriptor_content(attr = None, exclude = (), header_template = (), foo
"""
header_content, footer_content = [], []
- if attr is None: attr = {}
+
+ if attr is None:
+ attr = {}
+
attr = dict(attr) # shallow copy since we're destructive
for content, template in ((header_content, header_template),
(footer_content, footer_template)):
for keyword, value in template:
- if keyword in exclude: continue
+ if keyword in exclude:
+ continue
elif keyword in attr:
value = attr[keyword]
del attr[keyword]
- if value is None: continue
+ if value is None:
+ continue
elif value == "":
content.append(keyword)
elif keyword == "onion-key" or keyword == "signing-key" or keyword == "router-signature":
@@ -569,8 +588,10 @@ def _get_descriptor_content(attr = None, exclude = (), header_template = (), foo
remainder = []
for k, v in attr.items():
- if v: remainder.append("%s %s" % (k, v))
- else: remainder.append(k)
+ if v:
+ remainder.append("%s %s" % (k, v))
+ else:
+ remainder.append(k)
return "\n".join(header_content + remainder + footer_content)
diff --git a/test/output.py b/test/output.py
index d79db70..cadf071 100644
--- a/test/output.py
+++ b/test/output.py
@@ -37,12 +37,16 @@ LINE_ATTR = {
}
def print_line(msg, *attr):
- if CONFIG["argument.no_color"]: print msg
- else: print term.format(msg, *attr)
+ if CONFIG["argument.no_color"]:
+ print msg
+ else:
+ print term.format(msg, *attr)
def print_noline(msg, *attr):
- if CONFIG["argument.no_color"]: sys.stdout.write(msg)
- else: sys.stdout.write(term.format(msg, *attr))
+ if CONFIG["argument.no_color"]:
+ sys.stdout.write(msg)
+ else:
+ sys.stdout.write(term.format(msg, *attr))
def print_divider(msg, is_header = False):
attr = HEADER_ATTR if is_header else CATEGORY_ATTR
@@ -98,7 +102,9 @@ def apply_filters(testing_output, *filters):
for result_filter in filters:
line = result_filter(line_type, line)
- if line is None: break
+
+ if line is None:
+ break
if line is not None:
results.append(line)
@@ -110,8 +116,10 @@ def colorize(line_type, line_content):
Applies escape sequences so each line is colored according to its type.
"""
- if CONFIG["argument.no_color"]: return line_content
- else: return term.format(line_content, *LINE_ATTR[line_type])
+ if CONFIG["argument.no_color"]:
+ return line_content
+ else:
+ return term.format(line_content, *LINE_ATTR[line_type])
def strip_module(line_type, line_content):
"""
@@ -120,7 +128,10 @@ def strip_module(line_type, line_content):
"""
m = re.match(".*( \(.*?\)).*", line_content)
- if m: line_content = line_content.replace(m.groups()[0], "", 1)
+
+ if m:
+ line_content = line_content.replace(m.groups()[0], "", 1)
+
return line_content
def align_results(line_type, line_content):
@@ -129,7 +140,8 @@ def align_results(line_type, line_content):
a bold attribute.
"""
- if line_type == LineType.CONTENT: return line_content
+ if line_type == LineType.CONTENT:
+ return line_content
# strip our current ending
for ending in LINE_ENDINGS:
diff --git a/test/prompt.py b/test/prompt.py
index 32e75ab..afbd743 100644
--- a/test/prompt.py
+++ b/test/prompt.py
@@ -63,7 +63,9 @@ def stop(prompt = False):
if tor_pid:
if prompt:
response = raw_input("\n" + STOP_CONFIRMATION)
- if not response.lower() in ("y", "yes"): return
+
+ if not response.lower() in ("y", "yes"):
+ return
os.kill(tor_pid, signal.SIGTERM)
@@ -84,7 +86,9 @@ def controller():
already running.
"""
- if not is_running(): start()
+ if not is_running():
+ start()
+
controller = stem.control.Controller.from_port(control_port = CONTROL_PORT)
controller.authenticate()
return controller
diff --git a/test/runner.py b/test/runner.py
index af5ed73..dbfed24 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -207,7 +207,10 @@ def get_runner():
"""
global INTEG_RUNNER
- if not INTEG_RUNNER: INTEG_RUNNER = Runner()
+
+ if not INTEG_RUNNER:
+ INTEG_RUNNER = Runner()
+
return INTEG_RUNNER
class _MockChrootFile(object):
@@ -255,7 +258,9 @@ class Runner(object):
with self._runner_lock:
# if we're holding on to a tor process (running or not) then clean up after
# it so we can start a fresh instance
- if self._tor_process: self.stop()
+
+ if self._tor_process:
+ self.stop()
test.output.print_line("Setting up a test instance...", *STATUS_ATTR)
@@ -273,7 +278,9 @@ class Runner(object):
if CONFIG["integ.target.relative_data_dir"]:
tor_cwd = os.path.dirname(self._test_dir)
- if not os.path.exists(tor_cwd): os.makedirs(tor_cwd)
+
+ if not os.path.exists(tor_cwd):
+ os.makedirs(tor_cwd)
os.chdir(tor_cwd)
data_dir_path = "./%s" % os.path.basename(self._test_dir)
@@ -330,7 +337,8 @@ class Runner(object):
os.kill(self._tor_process.pid, signal.SIGTERM)
else:
test.output.print_line("failed (unable to call kill() in python 2.5)", *ERROR_ATTR)
- except OSError: pass
+ except OSError:
+ pass
self._tor_process.communicate() # blocks until the process is done
@@ -508,7 +516,8 @@ class Runner(object):
control_socket = stem.socket.ControlPort(control_port = CONTROL_PORT)
elif Torrc.SOCKET in self._custom_opts:
control_socket = stem.socket.ControlSocketFile(CONTROL_SOCKET_PATH)
- else: raise TorInaccessable("Unable to connect to tor")
+ else:
+ raise TorInaccessable("Unable to connect to tor")
if authenticate:
stem.connection.authenticate(control_socket, CONTROL_PASSWORD, self.get_chroot())
@@ -547,7 +556,9 @@ class Runner(object):
tor_version = list(version_response)[0]
tor_version = tor_version[8:]
- if " " in tor_version: tor_version = tor_version.split(' ', 1)[0]
+
+ if " " in tor_version:
+ tor_version = tor_version.split(' ', 1)[0]
return stem.version.Version(tor_version)
except TorInaccessable:
@@ -575,7 +586,8 @@ class Runner(object):
with self._runner_lock:
if self.is_running():
return self.__dict__[attr]
- else: raise RunnerStopped()
+ else:
+ raise RunnerStopped()
def _run_setup(self):
"""
diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py
index 5d74678..9565702 100644
--- a/test/unit/descriptor/router_status_entry.py
+++ b/test/unit/descriptor/router_status_entry.py
@@ -208,7 +208,8 @@ class TestRouterStatusEntry(unittest.TestCase):
# is that our validation doesn't catch the new SP restriction on V3
# entries.
- if value == "": value = None
+ if value == "":
+ value = None
self._expect_invalid_attr(content, "nickname", value)
diff --git a/test/unit/exit_policy/policy.py b/test/unit/exit_policy/policy.py
index 12cc52a..dce4cb7 100644
--- a/test/unit/exit_policy/policy.py
+++ b/test/unit/exit_policy/policy.py
@@ -152,7 +152,8 @@ class TestExitPolicy(unittest.TestCase):
else:
self.fail()
except ValueError:
- if expect_success: self.fail()
+ if expect_success:
+ self.fail()
def test_microdescriptor_attributes(self):
# checks that its is_accept attribute is properly set
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index a3c5e5a..e780375 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -82,8 +82,10 @@ def mock_call(base_cmd, responses):
def _mock_call(base_cmd, responses, command):
if isinstance(responses, list):
- if base_cmd == command: return responses
- else: return None
+ if base_cmd == command:
+ return responses
+ else:
+ return None
else:
for cmd_completion in responses:
if command == base_cmd % cmd_completion:
1
0

07 Jan '13
commit 6cd814dcb3c24a301f5e4c6396388a424629fd3f
Author: Damian Johnson <atagar(a)torproject.org>
Date: Mon Jan 7 00:56:47 2013 -0800
Adding '--style' to run_tests.py's help output
---
test/settings.cfg | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/test/settings.cfg b/test/settings.cfg
index cf827cd..8c85e47 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -76,6 +76,7 @@ msg.help
|
| -u, --unit runs unit tests
| -i, --integ runs integration tests
+| -s, --style runs style checker
| -t, --target TARGET comma separated list of extra targets for integ tests
| --test TEST_NAME only run tests modules matching the given name prefix
| -l, --log RUNLEVEL includes logging output with test results, runlevels:
1
0