[tor-commits] [bridgedb/develop] Move isValidRouterNickname to its own module.

isis at torproject.org isis at torproject.org
Thu Feb 19 02:21:13 UTC 2015


commit b1a9f792909e6def9abdc707f27a85854010ec9e
Author: Isis Lovecruft <isis at torproject.org>
Date:   Thu Dec 11 04:25:08 2014 +0000

    Move isValidRouterNickname to its own module.
---
 lib/bridgedb/parse/networkstatus.py |   19 --------------
 lib/bridgedb/parse/nickname.py      |   48 +++++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/lib/bridgedb/parse/networkstatus.py b/lib/bridgedb/parse/networkstatus.py
index 8592cd3..106edd9 100644
--- a/lib/bridgedb/parse/networkstatus.py
+++ b/lib/bridgedb/parse/networkstatus.py
@@ -47,25 +47,6 @@ class NetworkstatusParsingError(Exception):
 class InvalidNetworkstatusRouterIdentity(ValueError):
     """The ID field of a networkstatus document 'r'-line is invalid."""
 
-class InvalidRouterNickname(ValueError):
-    """Router nickname doesn't follow tor-spec."""
-
-
-def isValidRouterNickname(nickname):
-    """Determine if a router's given nickname meets the specification.
-
-    :param string nickname: An OR's nickname.
-    """
-    ALPHANUMERIC = string.letters + string.digits
-
-    if not (1 <= len(nickname) <= 19):
-        raise InvalidRouterNickname(
-            "Nicknames must be between 1 and 19 characters: %r" % nickname)
-    for letter in nickname:
-        if not letter in ALPHANUMERIC:
-            raise InvalidRouterNickname(
-                "Nicknames must only use [A-Za-z0-9]: %r" % nickname)
-    return True
 
 def parseRLine(line):
     """Parse an 'r'-line from a networkstatus document.
diff --git a/lib/bridgedb/parse/nickname.py b/lib/bridgedb/parse/nickname.py
new file mode 100644
index 0000000..b38bdb8
--- /dev/null
+++ b/lib/bridgedb/parse/nickname.py
@@ -0,0 +1,48 @@
+# -*- coding: utf-8 -*-
+#
+# This file is part of BridgeDB, a Tor bridge distribution system.
+#
+# :authors: Isis Lovecruft 0xA3ADB67A2CDB8B35 <isis at torproject.org>
+#           please also see AUTHORS file
+# :copyright: (c) 2013 Isis Lovecruft
+#             (c) 2007-2014, The Tor Project, Inc.
+#             (c) 2007-2014, all entities within the AUTHORS file
+# :license: 3-clause BSD, see included LICENSE for information
+
+"""Parsers for bridge nicknames.
+
+.. py:module:: bridgedb.parse.nickname
+   :synopsis: Parsers for Tor bridge nicknames.
+
+bridgedb.parse.nicknames
+========================
+::
+
+  nicknames
+   |_ isValidRouterNickname - Determine if a nickname is according to spec
+..
+"""
+
+import string
+
+
+class InvalidRouterNickname(ValueError):
+    """Router nickname doesn't follow tor-spec."""
+
+
+def isValidRouterNickname(nickname):
+    """Determine if a router's given nickname meets the specification.
+
+    :raises InvalidRouterNickname: if the nickname is invalid.
+    :param string nickname: An OR's nickname.
+    """
+    ALPHANUMERIC = string.letters + string.digits
+
+    if not (1 <= len(nickname) <= 19):
+        raise InvalidRouterNickname(
+            "Nicknames must be between 1 and 19 characters: %r" % nickname)
+    for letter in nickname:
+        if not letter in ALPHANUMERIC:
+            raise InvalidRouterNickname(
+                "Nicknames must only use [A-Za-z0-9]: %r" % nickname)
+    return True





More information about the tor-commits mailing list