[tor-commits] [stem/master] Move str_type and int_type to stem.util
atagar at torproject.org
atagar at torproject.org
Sun Jul 3 18:09:35 UTC 2016
commit 9df0bd0a595cba93eb8c51a7839a1a484e5b9475
Author: Damian Johnson <atagar at torproject.org>
Date: Sat Jul 2 12:34:47 2016 -0700
Move str_type and int_type to stem.util
Either spot works but I prefer to keep the base stem module strictly about tor
type enums.
---
stem/__init__.py | 9 ---------
stem/control.py | 4 ++--
stem/descriptor/__init__.py | 2 +-
stem/descriptor/reader.py | 2 +-
stem/descriptor/server_descriptor.py | 2 +-
stem/exit_policy.py | 3 +--
stem/response/events.py | 3 +--
stem/util/__init__.py | 7 +++++++
stem/util/connection.py | 3 +--
stem/util/enum.py | 2 +-
stem/util/str_tools.py | 2 +-
stem/util/system.py | 4 ++--
test/unit/descriptor/microdescriptor.py | 2 +-
test/unit/descriptor/networkstatus/document_v3.py | 3 ++-
test/unit/descriptor/reader.py | 3 +--
test/unit/descriptor/server_descriptor.py | 2 +-
test/unit/tutorial_examples.py | 2 +-
test/unit/util/system.py | 3 +--
18 files changed, 26 insertions(+), 32 deletions(-)
diff --git a/stem/__init__.py b/stem/__init__.py
index 1f61075..feb156a 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -468,15 +468,6 @@ Library for working with the tor process.
================= ===========
"""
-import stem.prereq
-
-if stem.prereq.is_python_3():
- str_type = str
- int_type = int
-else:
- str_type = unicode
- int_type = long
-
import stem.util.enum
__version__ = '1.4.1-dev'
diff --git a/stem/control.py b/stem/control.py
index f29fb71..9101cc1 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -274,8 +274,8 @@ import stem.util.system
import stem.util.tor_tools
import stem.version
-from stem import UNDEFINED, CircStatus, Signal, str_type
-from stem.util import log
+from stem import UNDEFINED, CircStatus, Signal
+from stem.util import str_type, log
# state changes a control socket can have
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 05c6087..fc44843 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -50,7 +50,7 @@ import stem.util.enum
import stem.util.str_tools
import stem.util.system
-from stem import str_type
+from stem.util import str_type
try:
# added in python 2.7
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index d047fb0..acfce67 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -91,7 +91,7 @@ import stem.descriptor
import stem.prereq
import stem.util.system
-from stem import str_type
+from stem.util import str_type
# flag to indicate when the reader thread is out of descriptor files to read
FINISHED = 'DONE'
diff --git a/stem/descriptor/server_descriptor.py b/stem/descriptor/server_descriptor.py
index 931601a..9f7d8d1 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -43,7 +43,7 @@ import stem.util.str_tools
import stem.util.tor_tools
import stem.version
-from stem import str_type
+from stem.util import str_type
from stem.descriptor import (
PGP_BLOCK_END,
diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index e84a456..9379d9c 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -75,8 +75,7 @@ import stem.util.connection
import stem.util.enum
import stem.util.str_tools
-from stem import str_type
-from stem.util import _hash_attr
+from stem.util import _hash_attr, str_type
try:
# added in python 3.2
diff --git a/stem/response/events.py b/stem/response/events.py
index 22adc25..86ed2b4 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -11,8 +11,7 @@ import stem.descriptor.router_status_entry
import stem.response
import stem.version
-from stem import str_type, int_type
-from stem.util import connection, log, str_tools, tor_tools
+from stem.util import str_type, int_type, connection, log, str_tools, tor_tools
# Matches keyword=value arguments. This can't be a simple "(.*)=(.*)" pattern
# because some positional arguments, like circuit paths, can have an equal
diff --git a/stem/util/__init__.py b/stem/util/__init__.py
index 63609d9..fd5bfad 100644
--- a/stem/util/__init__.py
+++ b/stem/util/__init__.py
@@ -24,6 +24,13 @@ __all__ = [
'datetime_to_unix',
]
+if stem.prereq.is_python_3():
+ str_type = str
+ int_type = int
+else:
+ str_type = unicode
+ int_type = long
+
def datetime_to_unix(timestamp):
"""
diff --git a/stem/util/connection.py b/stem/util/connection.py
index 4c64cc3..49a410b 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -53,8 +53,7 @@ import re
import stem.util.proc
import stem.util.system
-from stem import str_type
-from stem.util import conf, enum, log
+from stem.util import str_type, conf, enum, log
# Connection resolution is risky to log about since it's highly likely to
# contain sensitive information. That said, it's also difficult to get right in
diff --git a/stem/util/enum.py b/stem/util/enum.py
index 0927b4b..e6b62c8 100644
--- a/stem/util/enum.py
+++ b/stem/util/enum.py
@@ -40,7 +40,7 @@ constructed as simple type listings...
+- __iter__ - iterator over our enum keys
"""
-from stem import str_type
+from stem.util import str_type
def UppercaseEnum(*args):
diff --git a/stem/util/str_tools.py b/stem/util/str_tools.py
index a01eb8a..6d59303 100644
--- a/stem/util/str_tools.py
+++ b/stem/util/str_tools.py
@@ -29,7 +29,7 @@ import sys
import stem.prereq
import stem.util.enum
-from stem import str_type
+from stem.util import str_type
# label conversion tuples of the form...
# (bits / bytes / seconds, short label, long label)
diff --git a/stem/util/system.py b/stem/util/system.py
index 5ef61c6..7798048 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -62,8 +62,8 @@ import time
import stem.util.proc
import stem.util.str_tools
-from stem import UNDEFINED, str_type
-from stem.util import log
+from stem import UNDEFINED
+from stem.util import str_type, log
# Mapping of commands to if they're available or not.
diff --git a/test/unit/descriptor/microdescriptor.py b/test/unit/descriptor/microdescriptor.py
index f21e518..10ccd15 100644
--- a/test/unit/descriptor/microdescriptor.py
+++ b/test/unit/descriptor/microdescriptor.py
@@ -8,7 +8,7 @@ import stem.exit_policy
import stem.descriptor
-from stem import str_type
+from stem.util import str_type
from stem.descriptor.microdescriptor import Microdescriptor
from test.mocking import (
diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py
index aaf857a..cb4a1a0 100644
--- a/test/unit/descriptor/networkstatus/document_v3.py
+++ b/test/unit/descriptor/networkstatus/document_v3.py
@@ -9,7 +9,8 @@ import unittest
import stem.descriptor
import stem.version
-from stem import Flag, str_type
+from stem import Flag
+from stem.util import str_type
from stem.descriptor.networkstatus import (
HEADER_STATUS_DOCUMENT_FIELDS,
diff --git a/test/unit/descriptor/reader.py b/test/unit/descriptor/reader.py
index f21ea75..fe9c9e7 100644
--- a/test/unit/descriptor/reader.py
+++ b/test/unit/descriptor/reader.py
@@ -17,8 +17,7 @@ import stem.descriptor.reader
import test.runner
import test.unit.descriptor
-from stem import str_type
-from stem.util import system
+from stem.util import str_type, system
try:
# added in python 3.3
diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py
index c9d606f..834d1ea 100644
--- a/test/unit/descriptor/server_descriptor.py
+++ b/test/unit/descriptor/server_descriptor.py
@@ -14,7 +14,7 @@ import stem.prereq
import stem.version
import stem.util.str_tools
-from stem import str_type
+from stem.util import str_type
from stem.descriptor.server_descriptor import RelayDescriptor, BridgeDescriptor
from test.mocking import (
diff --git a/test/unit/tutorial_examples.py b/test/unit/tutorial_examples.py
index a21937f..e316766 100644
--- a/test/unit/tutorial_examples.py
+++ b/test/unit/tutorial_examples.py
@@ -17,8 +17,8 @@ import stem.prereq
import test.runner
-from stem import str_type
from stem.control import Controller
+from stem.util import str_type
from stem.descriptor.remote import DIRECTORY_AUTHORITIES
from test import mocking
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index 242a7fb..0bb59f3 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -12,8 +12,7 @@ import posixpath
import tempfile
import unittest
-from stem import str_type
-from stem.util import system
+from stem.util import str_type, system
try:
# added in python 3.3
More information about the tor-commits
mailing list