[stem/master] Fully qualifying util paths

commit 7c7bd6adeca59e593635d6eb21c6a9a0e7cf585e Author: Damian Johnson <atagar@torproject.org> Date: Wed Nov 9 10:23:07 2011 -0800 Fully qualifying util paths Changing the conventional usage of util imports from "from stem.util import X" to simple imports (not pulling them into our namespace). There's some exceptions to fully qualified util usage where it hurts readability (often the case with stem.util.term), but explite paths will be the more common case. --- run_tests.py | 7 +++++-- stem/process.py | 5 ++--- stem/util/proc.py | 4 ++-- stem/util/term.py | 10 +++++----- test/integ/system.py | 4 ++-- test/runner.py | 6 +++--- 6 files changed, 19 insertions(+), 17 deletions(-) diff --git a/run_tests.py b/run_tests.py index cd84d3f..0b86706 100755 --- a/run_tests.py +++ b/run_tests.py @@ -10,6 +10,7 @@ import time import getopt import logging import unittest + import test.runner import test.unit.types.control_message import test.unit.types.control_line @@ -17,7 +18,8 @@ import test.unit.types.version import test.integ.message import test.integ.system -from stem.util import enum, term +import stem.util.enum +import stem.util.term as term OPT = "uic:t:h" OPT_EXPANDED = ["unit", "integ", "config=", "targets=", "help"] @@ -36,7 +38,8 @@ INTEG_TESTS = (("stem.types.ControlMessage", test.integ.message.TestMessageFunct # TODO: drop targets? # Configurations that the intergration tests can be ran with. Attributs are # tuples of the test runner and description. -TARGETS = enum.Enum(*[(v, v) for v in ("NONE", "NO_CONTROL", "NO_AUTH", "COOKIE", "PASSWORD", "SOCKET")]) +TARGETS = stem.util.enum.Enum(*[(v, v) for v in ("NONE", "NO_CONTROL", "NO_AUTH", "COOKIE", "PASSWORD", "SOCKET")]) + TARGET_ATTR = { TARGETS.NONE: (None, "No running tor instance."), TARGETS.NO_CONTROL: (None, "Basic client, no control port or socket."), diff --git a/stem/process.py b/stem/process.py index 4eaf1f7..2974989 100644 --- a/stem/process.py +++ b/stem/process.py @@ -12,8 +12,7 @@ import signal import subprocess import stem.types - -from stem.util import system +import stem.util.system # number of seconds before we time out our attempt to start a tor instance DEFAULT_INIT_TIMEOUT = 90 @@ -38,7 +37,7 @@ def get_tor_version(tor_cmd = "tor"): if not tor_cmd in VERSION_CACHE: try: version_cmd = "%s --version" % tor_cmd - version_output = system.call(version_cmd) + version_output = stem.util.system.call(version_cmd) except OSError, exc: raise IOError(exc) diff --git a/stem/util/proc.py b/stem/util/proc.py index 505a3d4..30fab6a 100644 --- a/stem/util/proc.py +++ b/stem/util/proc.py @@ -20,14 +20,14 @@ import socket import base64 import logging -from stem.util import enum +import stem.util.enum LOGGER = logging.getLogger("stem") # cached system values IS_PROC_AVAILABLE, SYS_START_TIME, SYS_PHYSICAL_MEMORY = None, None, None CLOCK_TICKS = os.sysconf(os.sysconf_names["SC_CLK_TCK"]) -Stat = enum.Enum(("COMMAND", "command"), ("CPU_UTIME", "utime"), +Stat = stem.util.enum.Enum(("COMMAND", "command"), ("CPU_UTIME", "utime"), ("CPU_STIME", "stime"), ("START_TIME", "start time")) def is_available(): diff --git a/stem/util/term.py b/stem/util/term.py index a2465a2..99c37fc 100644 --- a/stem/util/term.py +++ b/stem/util/term.py @@ -2,13 +2,13 @@ Utilities for working with the terminal. """ -from stem.util import enum +import stem.util.enum TERM_COLORS = ("BLACK", "RED", "GREEN", "YELLOW", "BLUE", "MAGENTA", "CYAN", "WHITE") -Color = enum.Enum(*TERM_COLORS) -BgColor = enum.Enum(*["BG_" + color for color in TERM_COLORS]) -Attr = enum.Enum("BOLD", "UNDERLINE", "HILIGHT") +Color = stem.util.enum.Enum(*TERM_COLORS) +BgColor = stem.util.enum.Enum(*["BG_" + color for color in TERM_COLORS]) +Attr = stem.util.enum.Enum("BOLD", "UNDERLINE", "HILIGHT") # mappings of terminal attribute enums to their ANSI escape encoding FG_ENCODING = dict([(Color.values()[i], str(30 + i)) for i in range(8)]) @@ -45,7 +45,7 @@ def format(msg, *attr): encodings = [] for text_attr in attr: - text_attr, encoding = enum.to_camel_case(text_attr), None + text_attr, encoding = stem.util.enum.to_camel_case(text_attr), None encoding = FG_ENCODING.get(text_attr, encoding) encoding = BG_ENCODING.get(text_attr, encoding) encoding = ATTR_ENCODING.get(text_attr, encoding) diff --git a/test/integ/system.py b/test/integ/system.py index 39e2d3e..dc5b24c 100644 --- a/test/integ/system.py +++ b/test/integ/system.py @@ -3,9 +3,9 @@ Unit tests for the util.system functions in the context of a tor process. """ import unittest -import test.runner -from stem.util import system +import test.runner +import stem.util.system as system class TestSystemFunctions(unittest.TestCase): """ diff --git a/test/runner.py b/test/runner.py index feb19fb..21cf1e5 100644 --- a/test/runner.py +++ b/test/runner.py @@ -25,8 +25,8 @@ import tempfile import threading import stem.process - -from stem.util import conf, term +import stem.util.conf +import stem.util.term as term DEFAULT_CONFIG = { "test.integ.test_directory": "./test/data", @@ -281,7 +281,7 @@ class Runner: _print_status(" loading test configuration... skipped\n", STATUS_ATTR, quiet) else: # loads custom testing configuration - test_config = conf.get_config("test") + test_config = stem.util.conf.get_config("test") config_path = os.path.abspath(config_path) try:
participants (1)
-
atagar@torproject.org