[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Merging _compat.py into __init__.py



commit 5e0a7cbb083fe3e41a5251d9e23c3dd5e684f406
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Sat Jan 3 17:07:20 2015 -0800

    Merging _compat.py into __init__.py
    
    No reason to have a separate module for this. Just a few lines that could
    belong just as well in our __init__.py.
---
 stem/__init__.py                                  |    9 +++++++++
 stem/_compat.py                                   |   16 ----------------
 stem/control.py                                   |    3 +--
 stem/descriptor/__init__.py                       |    3 ++-
 stem/descriptor/reader.py                         |    3 ++-
 stem/descriptor/server_descriptor.py              |    2 +-
 stem/exit_policy.py                               |    2 +-
 stem/response/events.py                           |    2 +-
 stem/util/connection.py                           |    2 +-
 stem/util/enum.py                                 |    2 +-
 stem/util/str_tools.py                            |    3 ++-
 stem/util/system.py                               |    3 +--
 test/unit/descriptor/microdescriptor.py           |    2 +-
 test/unit/descriptor/networkstatus/document_v3.py |    3 +--
 test/unit/descriptor/reader.py                    |    2 +-
 test/unit/descriptor/server_descriptor.py         |    2 +-
 test/unit/tutorial_examples.py                    |    2 +-
 test/unit/util/system.py                          |    2 +-
 18 files changed, 28 insertions(+), 35 deletions(-)

diff --git a/stem/__init__.py b/stem/__init__.py
index baa2ef8..725bca5 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -491,6 +491,15 @@ __all__ = [
   'TimeoutSetType',
 ]
 
+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
 
 # Constant to indicate an undefined argument default. Usually we'd use None for
diff --git a/stem/_compat.py b/stem/_compat.py
deleted file mode 100644
index e0ba489..0000000
--- a/stem/_compat.py
+++ /dev/null
@@ -1,16 +0,0 @@
-import sys
-
-PY27 = sys.version_info >= (2, 7)
-PY3 = sys.version_info[0] >= 3
-PY33 = sys.version_info >= (3, 3)
-PY34 = sys.version_info >= (3, 4)
-
-if PY3:
-    str_type = str
-else:
-    str_type = unicode  # NOQA
-
-if PY3:
-    int_type = int
-else:
-    int_type = long  # NOQA
diff --git a/stem/control.py b/stem/control.py
index 6c34671..55cb05e 100644
--- a/stem/control.py
+++ b/stem/control.py
@@ -256,9 +256,8 @@ import stem.util.system
 import stem.util.tor_tools
 import stem.version
 
-from stem import UNDEFINED, CircStatus, Signal
+from stem import UNDEFINED, CircStatus, Signal, str_type
 from stem.util import log
-from stem._compat import str_type
 
 # state changes a control socket can have
 
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 6f4653f..2221807 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -58,7 +58,8 @@ import stem.prereq
 import stem.util.enum
 import stem.util.str_tools
 import stem.util.system
-from stem._compat import str_type
+
+from stem import str_type
 
 try:
   # added in python 2.7
diff --git a/stem/descriptor/reader.py b/stem/descriptor/reader.py
index 743771b..4865119 100644
--- a/stem/descriptor/reader.py
+++ b/stem/descriptor/reader.py
@@ -90,7 +90,8 @@ except ImportError:
 import stem.descriptor
 import stem.prereq
 import stem.util.system
-from stem._compat import str_type
+
+from stem 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 7a46a16..6726077 100644
--- a/stem/descriptor/server_descriptor.py
+++ b/stem/descriptor/server_descriptor.py
@@ -45,8 +45,8 @@ import stem.util.str_tools
 import stem.util.tor_tools
 import stem.version
 
+from stem import str_type
 from stem.util import log
-from stem._compat import str_type
 
 from stem.descriptor import (
   PGP_BLOCK_END,
diff --git a/stem/exit_policy.py b/stem/exit_policy.py
index afcd81d..53d0043 100644
--- a/stem/exit_policy.py
+++ b/stem/exit_policy.py
@@ -75,7 +75,7 @@ import stem.util.connection
 import stem.util.enum
 import stem.util.str_tools
 
-from stem._compat import str_type
+from stem import str_type
 
 try:
   # added in python 3.2
diff --git a/stem/response/events.py b/stem/response/events.py
index 3e54281..930f9bd 100644
--- a/stem/response/events.py
+++ b/stem/response/events.py
@@ -11,8 +11,8 @@ 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._compat import str_type, int_type
 
 # 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/connection.py b/stem/util/connection.py
index 2165b45..a7b979a 100644
--- a/stem/util/connection.py
+++ b/stem/util/connection.py
@@ -50,8 +50,8 @@ import re
 import stem.util.proc
 import stem.util.system
 
+from stem import str_type
 from stem.util import conf, enum, log
-from stem._compat import str_type
 
 # 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 d641789..bcf66ee 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._compat import str_type
+from stem import str_type
 
 
 def UppercaseEnum(*args):
diff --git a/stem/util/str_tools.py b/stem/util/str_tools.py
index 63b66b0..d62bccd 100644
--- a/stem/util/str_tools.py
+++ b/stem/util/str_tools.py
@@ -28,11 +28,12 @@ import sys
 
 import stem.prereq
 import stem.util.enum
-from stem._compat import str_type
 
+from stem import str_type
 
 # label conversion tuples of the form...
 # (bits / bytes / seconds, short label, long label)
+
 SIZE_UNITS_BITS = (
   (140737488355328.0, ' Pb', ' Petabit'),
   (137438953472.0, ' Tb', ' Terabit'),
diff --git a/stem/util/system.py b/stem/util/system.py
index 66f46a9..8485595 100644
--- a/stem/util/system.py
+++ b/stem/util/system.py
@@ -54,9 +54,8 @@ import time
 import stem.util.proc
 import stem.util.str_tools
 
-from stem import UNDEFINED
+from stem import UNDEFINED, str_type
 from stem.util import log
-from stem._compat import str_type
 
 # 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 0873fbb..8fe0937 100644
--- a/test/unit/descriptor/microdescriptor.py
+++ b/test/unit/descriptor/microdescriptor.py
@@ -8,8 +8,8 @@ import stem.exit_policy
 
 import stem.descriptor
 
+from stem import str_type
 from stem.descriptor.microdescriptor import Microdescriptor
-from stem._compat import str_type
 
 from test.mocking import (
   get_microdescriptor,
diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py
index 9e6f510..4b8efc4 100644
--- a/test/unit/descriptor/networkstatus/document_v3.py
+++ b/test/unit/descriptor/networkstatus/document_v3.py
@@ -9,8 +9,7 @@ import unittest
 import stem.descriptor
 import stem.version
 
-from stem import Flag
-from stem._compat import str_type
+from stem import Flag, 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 85c3118..d220557 100644
--- a/test/unit/descriptor/reader.py
+++ b/test/unit/descriptor/reader.py
@@ -17,8 +17,8 @@ import stem.descriptor.reader
 import test.runner
 import test.unit.descriptor
 
+from stem import str_type
 from stem.util import system
-from stem._compat import str_type
 
 try:
   # added in python 3.3
diff --git a/test/unit/descriptor/server_descriptor.py b/test/unit/descriptor/server_descriptor.py
index a83dfba..c57c476 100644
--- a/test/unit/descriptor/server_descriptor.py
+++ b/test/unit/descriptor/server_descriptor.py
@@ -13,8 +13,8 @@ import stem.prereq
 import stem.version
 import stem.util.str_tools
 
+from stem import str_type
 from stem.descriptor.server_descriptor import RelayDescriptor, BridgeDescriptor
-from stem._compat import str_type
 
 from test.mocking import (
   get_relay_server_descriptor,
diff --git a/test/unit/tutorial_examples.py b/test/unit/tutorial_examples.py
index d1f8673..fac6fbb 100644
--- a/test/unit/tutorial_examples.py
+++ b/test/unit/tutorial_examples.py
@@ -13,9 +13,9 @@ except ImportError:
 import stem.response
 import stem.descriptor.remote
 
+from stem import str_type
 from stem.control import Controller
 from stem.descriptor.remote import DIRECTORY_AUTHORITIES
-from stem._compat import str_type
 
 from test import mocking
 from test.mocking import (
diff --git a/test/unit/util/system.py b/test/unit/util/system.py
index f9fbb10..3b4f035 100644
--- a/test/unit/util/system.py
+++ b/test/unit/util/system.py
@@ -10,8 +10,8 @@ import ntpath
 import posixpath
 import unittest
 
+from stem import str_type
 from stem.util import system
-from stem._compat import str_type
 
 try:
   # added in python 3.3



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits