[tor-commits] [stem/master] Pylint fixes
atagar at torproject.org
atagar at torproject.org
Sun Jul 22 05:48:17 UTC 2012
commit fd2da106d0f90061532f8880702138b297ca4230
Author: Damian Johnson <atagar at torproject.org>
Date: Fri Jul 20 18:19:29 2012 -0700
Pylint fixes
Variety of issues, most of them caught by pylint.
---
run_tests.py | 2 +-
stem/connection.py | 4 ++--
stem/control.py | 4 ++--
stem/descriptor/reader.py | 2 +-
stem/descriptor/server_descriptor.py | 1 -
stem/response/__init__.py | 2 +-
stem/response/authchallenge.py | 1 -
stem/util/conf.py | 4 ++--
stem/util/enum.py | 2 +-
stem/util/system.py | 4 ++--
stem/version.py | 7 ++-----
test/integ/__init__.py | 3 ++-
test/integ/control/base_controller.py | 8 ++++----
test/integ/descriptor/extrainfo_descriptor.py | 6 ------
test/integ/descriptor/reader.py | 2 +-
test/integ/process.py | 4 ++--
test/integ/response/protocolinfo.py | 2 +-
test/integ/socket/control_socket.py | 6 +++---
test/integ/util/__init__.py | 2 +-
test/mocking.py | 2 +-
test/output.py | 3 +--
test/runner.py | 5 ++---
test/unit/__init__.py | 1 +
test/unit/exit_policy/policy.py | 4 ----
test/unit/util/__init__.py | 9 ++++++++-
25 files changed, 41 insertions(+), 49 deletions(-)
diff --git a/run_tests.py b/run_tests.py
index 3b36046..8a9a37d 100755
--- a/run_tests.py
+++ b/run_tests.py
@@ -152,7 +152,7 @@ def load_user_configuration(test_config):
arg_overrides, config_path = {}, None
try:
- opts, args = getopt.getopt(sys.argv[1:], OPT, OPT_EXPANDED)
+ opts = getopt.getopt(sys.argv[1:], OPT, OPT_EXPANDED)[0]
except getopt.GetoptError, exc:
print "%s (for usage provide --help)" % exc
sys.exit(1)
diff --git a/stem/connection.py b/stem/connection.py
index 52037a3..6f32972 100644
--- a/stem/connection.py
+++ b/stem/connection.py
@@ -173,7 +173,7 @@ def _connect(control_socket, password, chroot_path, controller):
try: password = getpass.getpass("Controller password: ")
except KeyboardInterrupt: return None
- return _connect(control_socket, password, controller)
+ return _connect(control_socket, password, chroot_path, controller)
except AuthenticationFailure, exc:
control_socket.close()
print "Unable to authenticate: %s" % exc
@@ -694,7 +694,7 @@ def get_protocolinfo(controller):
# attempt to expand relative cookie paths
if protocolinfo_response.cookie_path:
- stem.connection._expand_cookie_path(protocolinfo_response, stem.util.system.get_pid_by_name, "tor")
+ _expand_cookie_path(protocolinfo_response, stem.util.system.get_pid_by_name, "tor")
# attempt to expand relative cookie paths via the control port or socket file
diff --git a/stem/control.py b/stem/control.py
index e2bf282..d7d90c9 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -76,7 +76,7 @@ MAPPED_CONFIG_KEYS = {
# 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 compatability.
-class BaseController:
+class BaseController(object):
"""
Controller for the tor process. This is a minimal base class for other
controllers, providing basic process communication and event listing. Don't
@@ -757,7 +757,7 @@ class Controller(BaseController):
elif response.code in ("513", "553"):
raise stem.socket.InvalidRequest(response.code, response.message)
else:
- raise stem.socket.ProtocolError("%s returned unexpected status code" % command)
+ raise stem.socket.ProtocolError("Returned unexpected status code: %s" % response.code)
def load_conf(self, configtext):
"""
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index ed07c88..84ce695 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -195,7 +195,7 @@ def save_processed_files(path, processed_files):
output_file.write("%s %i\n" % (path, timestamp))
-class DescriptorReader:
+class DescriptorReader(object):
"""
Iterator for the descriptor data on the local file system. This can process
text files, tarball archives (gzip or bzip2), or recurse directories.
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 730709f..f54d5b1 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -37,7 +37,6 @@ import stem.descriptor
import stem.descriptor.extrainfo_descriptor
import stem.exit_policy
import stem.version
-import stem.util.log as log
import stem.util.connection
import stem.util.tor_tools
diff --git a/stem/response/__init__.py b/stem/response/__init__.py
index 5a665b6..14a0280 100644
--- a/stem/response/__init__.py
+++ b/stem/response/__init__.py
@@ -100,7 +100,7 @@ def convert(response_type, message, **kwargs):
message.__class__ = response_class
message._parse_message(**kwargs)
-class ControlMessage:
+class ControlMessage(object):
"""
Message from the control socket. This is iterable and can be stringified for
individual message components stripped of protocol formatting. Messages are
diff --git a/stem/response/authchallenge.py b/stem/response/authchallenge.py
index 84df58f..fa60339 100644
--- a/stem/response/authchallenge.py
+++ b/stem/response/authchallenge.py
@@ -1,4 +1,3 @@
-import re
import binascii
import stem.socket
diff --git a/stem/util/conf.py b/stem/util/conf.py
index 79291c0..8ffcc8e 100644
--- a/stem/util/conf.py
+++ b/stem/util/conf.py
@@ -72,7 +72,7 @@ import stem.util.log as log
CONFS = {} # mapping of identifier to singleton instances of configs
-class SyncListener:
+class SyncListener(object):
def __init__(self, config_dict, interceptor):
self.config_dict = config_dict
self.interceptor = interceptor
@@ -121,7 +121,7 @@ def get_config(handle):
if not handle in CONFS: CONFS[handle] = Config()
return CONFS[handle]
-class Config():
+class Config(object):
"""
Handler for easily working with custom configurations, providing persistence
to and from files. All operations are thread safe.
diff --git a/stem/util/enum.py b/stem/util/enum.py
index 8b21100..50f6728 100644
--- a/stem/util/enum.py
+++ b/stem/util/enum.py
@@ -75,7 +75,7 @@ def UppercaseEnum(*args):
return Enum(*[(v, v) for v in args])
-class Enum:
+class Enum(object):
"""
Basic enumeration.
"""
diff --git a/stem/util/system.py b/stem/util/system.py
index 799219b..798f5ff 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -541,9 +541,9 @@ def expand_path(path, cwd = None):
relative_path = ""
if relative_path == "":
- relative_path = cwd
+ relative_path = cwd
else:
- relative_path = os.path.join(cwd, relative_path)
+ relative_path = os.path.join(cwd, relative_path)
return relative_path
diff --git a/stem/version.py b/stem/version.py
index d0228b1..bc377af 100644
--- a/stem/version.py
+++ b/stem/version.py
@@ -80,7 +80,7 @@ def get_system_tor_version(tor_cmd = "tor"):
return VERSION_CACHE[tor_cmd]
-class Version:
+class Version(object):
"""
Comparable tor version. These are constructed from strings that conform to
the 'new' style in the `tor version-spec
@@ -159,14 +159,11 @@ class Version:
if my_version > other_version: return 1
elif my_version < other_version: return -1
- my_status = self.status if self.status else ""
- other_status = other.status if other.status else ""
-
# not including tags in comparisons because the spec declares them to be
# 'purely informational'
return 0
-class VersionRequirements:
+class VersionRequirements(object):
"""
Series of version constraints that can be compared to. For instance, it
allows for comparisons like 'if I'm greater than version X in the 0.2.2
diff --git a/test/integ/__init__.py b/test/integ/__init__.py
index 3cc4a7f..d57f031 100644
--- a/test/integ/__init__.py
+++ b/test/integ/__init__.py
@@ -6,9 +6,10 @@ __all__ = [
"connection",
"control",
"descriptor",
- "process",
+ "response",
"socket",
"util",
+ "process",
"version",
]
diff --git a/test/integ/control/base_controller.py b/test/integ/control/base_controller.py
index 4104075..22cd7a8 100644
--- a/test/integ/control/base_controller.py
+++ b/test/integ/control/base_controller.py
@@ -14,7 +14,7 @@ import stem.socket
import stem.util.system
import test.runner
-class StateObserver:
+class StateObserver(object):
"""
Simple container for listening to ControlSocket state changes and
rembembering them for the test.
@@ -49,7 +49,7 @@ class TestBaseController(unittest.TestCase):
with test.runner.get_runner().get_tor_socket() as control_socket:
controller = stem.control.BaseController(control_socket)
- for i in xrange(250):
+ for _ in xrange(250):
controller.connect()
controller.close()
@@ -103,7 +103,7 @@ class TestBaseController(unittest.TestCase):
controller = stem.control.BaseController(control_socket)
def run_getinfo():
- for i in xrange(150):
+ for _ in xrange(150):
try:
controller.msg("GETINFO version")
controller.msg("GETINFO blarg")
@@ -113,7 +113,7 @@ class TestBaseController(unittest.TestCase):
message_threads = []
- for i in xrange(5):
+ for _ in xrange(5):
msg_thread = threading.Thread(target = run_getinfo)
message_threads.append(msg_thread)
msg_thread.setDaemon(True)
diff --git a/test/integ/descriptor/extrainfo_descriptor.py b/test/integ/descriptor/extrainfo_descriptor.py
index d960055..fd9a4cf 100644
--- a/test/integ/descriptor/extrainfo_descriptor.py
+++ b/test/integ/descriptor/extrainfo_descriptor.py
@@ -94,12 +94,6 @@ k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
DirResponses.BUSY: 0,
}
- expected_signature = """-----BEGIN SIGNATURE-----
-K5FSywk7qvw/boA4DQcqkls6Ize5vcBYfhQ8JnOeRQC9+uDxbnpm3qaYN9jZ8myj
-k0d2aofcVbHr4fPQOSST0LXDrhFl5Fqo5um296zpJGvRUeO6S44U/EfJAGShtqWw
-7LZqklu+gVvhMKREpchVqlAwXkWR44VENm24Hs+mT3M=
------END SIGNATURE-----"""
-
desc = stem.descriptor.extrainfo_descriptor.BridgeExtraInfoDescriptor(descriptor_contents)
self.assertEquals("ec2bridgereaac65a3", desc.nickname)
self.assertEquals("1EC248422B57D9C0BD751892FE787585407479A4", desc.fingerprint)
diff --git a/test/integ/descriptor/reader.py b/test/integ/descriptor/reader.py
index 6ecfa72..03fb8fe 100644
--- a/test/integ/descriptor/reader.py
+++ b/test/integ/descriptor/reader.py
@@ -171,7 +171,7 @@ class TestDescriptorReader(unittest.TestCase):
descriptor_entries.append(descriptor_file.read())
# running this test multiple times to flush out concurrency issues
- for i in xrange(15):
+ for _ in xrange(15):
remaining_entries = list(descriptor_entries)
with stem.descriptor.reader.DescriptorReader(descriptor_path) as reader:
diff --git a/test/integ/process.py b/test/integ/process.py
index 58440e0..5396756 100644
--- a/test/integ/process.py
+++ b/test/integ/process.py
@@ -20,7 +20,7 @@ class TestProcess(unittest.TestCase):
"""
if not stem.prereq.is_python_26() and stem.util.system.is_windows():
- test.runner.skip("(unable to kill subprocesses)")
+ test.runner.skip(self, "(unable to kill subprocesses)")
return
if test.runner.only_run_once(self, "test_launch_tor_with_config"): return
@@ -64,7 +64,7 @@ class TestProcess(unittest.TestCase):
"""
if not stem.prereq.is_python_26() and stem.util.system.is_windows():
- test.runner.skip("(unable to kill subprocesses)")
+ test.runner.skip(self, "(unable to kill subprocesses)")
return
if test.runner.only_run_once(self, "test_launch_tor_with_timeout"): return
diff --git a/test/integ/response/protocolinfo.py b/test/integ/response/protocolinfo.py
index 4f13e7b..a223510 100644
--- a/test/integ/response/protocolinfo.py
+++ b/test/integ/response/protocolinfo.py
@@ -95,7 +95,7 @@ class TestProtocolInfo(unittest.TestCase):
if test.runner.require_control(self): return
with test.runner.get_runner().get_tor_socket(False) as control_socket:
- for i in range(5):
+ for _ in range(5):
protocolinfo_response = stem.connection.get_protocolinfo(control_socket)
self.assert_matches_test_config(protocolinfo_response)
diff --git a/test/integ/socket/control_socket.py b/test/integ/socket/control_socket.py
index 2e81599..ad253d1 100644
--- a/test/integ/socket/control_socket.py
+++ b/test/integ/socket/control_socket.py
@@ -29,10 +29,10 @@ class TestControlSocket(unittest.TestCase):
tor_version = runner.get_tor_version()
with runner.get_tor_socket() as control_socket:
- for i in range(100):
+ for _ in range(100):
control_socket.send("GETINFO version")
- for i in range(100):
+ for _ in range(100):
response = control_socket.recv()
self.assertTrue(str(response).startswith("version=%s" % tor_version))
self.assertTrue(str(response).endswith("\nOK"))
@@ -120,7 +120,7 @@ class TestControlSocket(unittest.TestCase):
if test.runner.require_control(self): return
with test.runner.get_runner().get_tor_socket(False) as control_socket:
- for i in range(10):
+ for _ in range(10):
# this will raise if the PROTOCOLINFO query fails
stem.connection.get_protocolinfo(control_socket)
diff --git a/test/integ/util/__init__.py b/test/integ/util/__init__.py
index 95e5870..3d275b8 100644
--- a/test/integ/util/__init__.py
+++ b/test/integ/util/__init__.py
@@ -2,5 +2,5 @@
Integration tests for stem.util.* contents.
"""
-__all__ = ["conf", "system"]
+__all__ = ["conf", "proc", "system"]
diff --git a/test/mocking.py b/test/mocking.py
index 94d519e..f4198ec 100644
--- a/test/mocking.py
+++ b/test/mocking.py
@@ -228,7 +228,7 @@ def get_all_combinations(attr, include_empty = False):
seen = set()
for i in xrange(1, len(attr) + 1):
- product_arg = [attr for j in xrange(i)]
+ product_arg = [attr for _ in xrange(i)]
for item in itertools.product(*product_arg):
# deduplicate, sort, and only provide if we haven't seen it yet
diff --git a/test/output.py b/test/output.py
index bf7de7e..084a79a 100644
--- a/test/output.py
+++ b/test/output.py
@@ -5,7 +5,6 @@ together for improved readability.
import re
import sys
-import logging
import stem.util.conf
import stem.util.enum
@@ -156,7 +155,7 @@ def align_results(line_type, line_content):
else:
return "%-61s[%s]" % (line_content, term.format(new_ending, term.Attr.BOLD))
-class ErrorTracker:
+class ErrorTracker(object):
"""
Stores any failure or error results we've encountered.
"""
diff --git a/test/runner.py b/test/runner.py
index d4d3eec..0d7ba2f 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -37,7 +37,6 @@ about the tor test instance they're running against.
from __future__ import with_statement
import os
-import sys
import time
import stat
import shutil
@@ -192,7 +191,7 @@ def get_runner():
if not INTEG_RUNNER: INTEG_RUNNER = Runner()
return INTEG_RUNNER
-class _MockChrootFile:
+class _MockChrootFile(object):
"""
Wrapper around a file object that strips given content from readline()
responses. This is used to simulate a chroot setup by removing the restign
@@ -206,7 +205,7 @@ class _MockChrootFile:
def readline(self):
return self.wrapped_file.readline().replace(self.strip_text, "")
-class Runner:
+class Runner(object):
def __init__(self):
self._runner_lock = threading.RLock()
diff --git a/test/unit/__init__.py b/test/unit/__init__.py
index 6bbec07..15a6b88 100644
--- a/test/unit/__init__.py
+++ b/test/unit/__init__.py
@@ -5,6 +5,7 @@ Unit tests for the stem library.
__all__ = [
"connection",
"descriptor",
+ "exit_policy",
"socket",
"util",
"version",
diff --git a/test/unit/exit_policy/policy.py b/test/unit/exit_policy/policy.py
index 6ce0e4f..6f4b5a9 100644
--- a/test/unit/exit_policy/policy.py
+++ b/test/unit/exit_policy/policy.py
@@ -3,14 +3,10 @@ Unit tests for the stem.exit_policy.ExitPolicy class.
"""
import unittest
-import stem.exit_policy
-import stem.util.system
from stem.exit_policy import ExitPolicy, \
MicrodescriptorExitPolicy, \
ExitPolicyRule
-import test.mocking as mocking
-
class TestExitPolicy(unittest.TestCase):
def test_example(self):
# tests the ExitPolicy and MicrodescriptorExitPolicy pydoc examples
diff --git a/test/unit/util/__init__.py b/test/unit/util/__init__.py
index 17a4deb..d0eeda3 100644
--- a/test/unit/util/__init__.py
+++ b/test/unit/util/__init__.py
@@ -2,5 +2,12 @@
Unit tests for stem.util.* contents.
"""
-__all__ = ["conf", "connection", "enum", "system", "tor_tools"]
+__all__ = [
+ "conf",
+ "connection",
+ "enum",
+ "proc",
+ "system",
+ "tor_tools",
+]
More information about the tor-commits
mailing list