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

[tor-commits] [stem/master] Moving Flag enum to stem's base module



commit a85aa8cfcdabfaf2176497abeaf0c90cb80a9624
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Thu Jan 17 08:43:17 2013 -0800

    Moving Flag enum to stem's base module
    
    I'm making an effort to put most general purpose enums in the base module.
    Oddly I never referenced the Flag enum in the descriptor pydocs...
---
 stem/__init__.py                                  |   42 ++++++++++++++++++++
 stem/descriptor/__init__.py                       |   43 ---------------------
 stem/descriptor/networkstatus.py                  |    2 +-
 stem/descriptor/router_status_entry.py            |    2 +-
 test/settings.cfg                                 |    2 +-
 test/unit/descriptor/networkstatus/document_v3.py |    2 +-
 test/unit/descriptor/router_status_entry.py       |    2 +-
 7 files changed, 47 insertions(+), 48 deletions(-)

diff --git a/stem/__init__.py b/stem/__init__.py
index 4ad7f78..a3ecf71 100644
--- a/stem/__init__.py
+++ b/stem/__init__.py
@@ -45,6 +45,30 @@ Library for working with the tor process.
   **CLEARDNSCACHE**         clears cached DNS results
   ========================= ===========
 
+.. data:: Flag (enum)
+
+  Flag assigned to tor relays by the authorities to indicate various
+  characteristics.
+
+  ================= ===========
+  Flag              Description
+  ================= ===========
+  **AUTHORITY**     relay is a directory authority
+  **BADEXIT**       relay shouldn't be used as an exit due to being either problematic or malicious (`https://trac.torproject.org/projects/tor/wiki/doc/badRelays`_)
+  **BADDIRECTORY**  relay shouldn't be used for directory information
+  **EXIT**          relay's exit policy makes it more useful as an exit rather than middle hop
+  **FAST**          relay's suitable for high-bandwidth circuits
+  **GUARD**         relay's suitable for being an entry guard (first hop)
+  **HSDIR**         relay is being used as a v2 hidden service directory
+  **NAMED**         relay can be referred to by its nickname
+  **RUNNING**       relay is currently usable
+  **STABLE**        relay's suitable for long-lived circuits
+  **UNNAMED**       relay isn't presently bound to a nickname
+  **V2DIR**         relay supports the v2 directory protocol
+  **V3DIR**         relay supports the v3 directory protocol
+  **VALID**         relay has been validated
+  ================= ===========
+
 .. data:: CircStatus (enum)
 
   Statuses that a circuit can be in. Tor may provide statuses not in this enum.
@@ -375,6 +399,7 @@ __all__ = [
   "SocketClosed",
   "Runlevel",
   "Signal",
+  "Flag",
   "CircStatus",
   "CircBuildFlag",
   "CircPurpose",
@@ -481,6 +506,23 @@ Runlevel = stem.util.enum.UppercaseEnum(
   "ERR",
 )
 
+Flag = stem.util.enum.Enum(
+  ("AUTHORITY", "Authority"),
+  ("BADEXIT", "BadExit"),
+  ("BADDIRECTORY", "BadDirectory"),
+  ("EXIT", "Exit"),
+  ("FAST", "Fast"),
+  ("GUARD", "Guard"),
+  ("HSDIR", "HSDir"),
+  ("NAMED", "Named"),
+  ("RUNNING", "Running"),
+  ("STABLE", "Stable"),
+  ("UNNAMED", "Unnamed"),
+  ("V2DIR", "V2Dir"),
+  ("V3DIR", "V3Dir"),
+  ("VALID", "Valid"),
+)
+
 Signal = stem.util.enum.UppercaseEnum(
   "RELOAD",
   "HUP",
diff --git a/stem/descriptor/__init__.py b/stem/descriptor/__init__.py
index 95cfeaf..aabf37e 100644
--- a/stem/descriptor/__init__.py
+++ b/stem/descriptor/__init__.py
@@ -10,30 +10,6 @@ Package for parsing and processing descriptor data.
     |- get_path - location of the descriptor on disk if it came from a file
     |- get_unrecognized_lines - unparsed descriptor content
     +- __str__ - string that the descriptor was made from
-
-.. data:: Flag (enum)
-
-  Flag assigned to tor relays by the authorities to indicate various
-  characteristics.
-
-  ================= ===========
-  Flag              Description
-  ================= ===========
-  **AUTHORITY**     relay is a directory authority
-  **BADEXIT**       relay shouldn't be used as an exit due to being either problematic or malicious (`https://trac.torproject.org/projects/tor/wiki/doc/badRelays`_)
-  **BADDIRECTORY**  relay shouldn't be used for directory information
-  **EXIT**          relay's exit policy makes it more useful as an exit rather than middle hop
-  **FAST**          relay's suitable for high-bandwidth circuits
-  **GUARD**         relay's suitable for being an entry guard (first hop)
-  **HSDIR**         relay is being used as a v2 hidden service directory
-  **NAMED**         relay can be referred to by its nickname
-  **RUNNING**       relay is currently usable
-  **STABLE**        relay's suitable for long-lived circuits
-  **UNNAMED**       relay isn't presently bound to a nickname
-  **V2DIR**         relay supports the v2 directory protocol
-  **V3DIR**         relay supports the v3 directory protocol
-  **VALID**         relay has been validated
-  ================= ===========
 """
 
 __all__ = [
@@ -50,8 +26,6 @@ __all__ = [
 import os
 import re
 
-import stem.util.enum
-
 try:
   # added in python 2.7
   from collections import OrderedDict
@@ -64,23 +38,6 @@ KEYWORD_LINE = re.compile("^([%s]+)(?:[%s]+(.*))?$" % (KEYWORD_CHAR, WHITESPACE)
 PGP_BLOCK_START = re.compile("^-----BEGIN ([%s%s]+)-----$" % (KEYWORD_CHAR, WHITESPACE))
 PGP_BLOCK_END = "-----END %s-----"
 
-Flag = stem.util.enum.Enum(
-  ("AUTHORITY", "Authority"),
-  ("BADEXIT", "BadExit"),
-  ("BADDIRECTORY", "BadDirectory"),
-  ("EXIT", "Exit"),
-  ("FAST", "Fast"),
-  ("GUARD", "Guard"),
-  ("HSDIR", "HSDir"),
-  ("NAMED", "Named"),
-  ("RUNNING", "Running"),
-  ("STABLE", "Stable"),
-  ("UNNAMED", "Unnamed"),
-  ("V2DIR", "V2Dir"),
-  ("V3DIR", "V3Dir"),
-  ("VALID", "Valid"),
-)
-
 
 def parse_file(path, descriptor_file):
   """
diff --git a/stem/descriptor/networkstatus.py b/stem/descriptor/networkstatus.py
index a056917..ef7e4a5 100644
--- a/stem/descriptor/networkstatus.py
+++ b/stem/descriptor/networkstatus.py
@@ -438,7 +438,7 @@ class NetworkStatusDocumentV3(NetworkStatusDocument):
     signatures from all authorities
   :var list client_versions: list of recommended client tor versions
   :var list server_versions: list of recommended server tor versions
-  :var list known_flags: **\*** list of known router flags
+  :var list known_flags: **\*** list of :data:`~stem.Flag` for the router's flags
   :var list params: **\*** dict of parameter(**str**) => value(**int**) mappings
   :var list directory_authorities: **\*** list of :class:`~stem.descriptor.networkstatus.DirectoryAuthority`
     objects that have generated this document
diff --git a/stem/descriptor/router_status_entry.py b/stem/descriptor/router_status_entry.py
index 5c7d735..aca72ed 100644
--- a/stem/descriptor/router_status_entry.py
+++ b/stem/descriptor/router_status_entry.py
@@ -104,7 +104,7 @@ class RouterStatusEntry(stem.descriptor.Descriptor):
   :var int or_port: **\*** router's ORPort
   :var int dir_port: **\*** router's DirPort
 
-  :var list flags: **\*** list of status flags
+  :var list flags: **\*** list of :data:`~stem.Flag` associated with the relay
 
   :var stem.version.Version version: parsed version of tor, this is **None** if
     the relay's using a new versioning scheme
diff --git a/test/settings.cfg b/test/settings.cfg
index 9b58f82..561c0c8 100644
--- a/test/settings.cfg
+++ b/test/settings.cfg
@@ -156,6 +156,6 @@ target.torrc RUN_PTRACE   => PORT, PTRACE
 pyflakes.ignore stem/prereq.py => 'RSA' imported but unused
 pyflakes.ignore stem/prereq.py => 'asn1' imported but unused
 pyflakes.ignore stem/prereq.py => 'long_to_bytes' imported but unused
-pyflakes.ignore stem/descriptor/__init__.py => redefinition of unused 'OrderedDict' from line 33
+pyflakes.ignore stem/descriptor/__init__.py => redefinition of unused 'OrderedDict' from line 31
 pyflakes.ignore test/unit/response/events.py => 'from stem import *' used; unable to detect undefined names
 
diff --git a/test/unit/descriptor/networkstatus/document_v3.py b/test/unit/descriptor/networkstatus/document_v3.py
index 4ea6347..c68549c 100644
--- a/test/unit/descriptor/networkstatus/document_v3.py
+++ b/test/unit/descriptor/networkstatus/document_v3.py
@@ -10,7 +10,7 @@ import unittest
 
 import stem.version
 
-from stem.descriptor import Flag
+from stem import Flag
 
 from stem.descriptor.networkstatus import HEADER_STATUS_DOCUMENT_FIELDS, \
                                           FOOTER_STATUS_DOCUMENT_FIELDS, \
diff --git a/test/unit/descriptor/router_status_entry.py b/test/unit/descriptor/router_status_entry.py
index b0fcc79..3f27663 100644
--- a/test/unit/descriptor/router_status_entry.py
+++ b/test/unit/descriptor/router_status_entry.py
@@ -5,7 +5,7 @@ Unit tests for stem.descriptor.router_status_entry.
 import datetime
 import unittest
 
-from stem.descriptor import Flag
+from stem import Flag
 from stem.descriptor.router_status_entry import RouterStatusEntryV3, _decode_fingerprint
 from stem.exit_policy import MicroExitPolicy
 from stem.version import Version



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