[tor-commits] [bridgedb/develop] Remove Bridges.parseDescFile() and its unittests.

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


commit 58718f5d6f287d6bf5effbd594295325606248e6
Author: Isis Lovecruft <isis at torproject.org>
Date:   Wed Feb 11 01:43:47 2015 +0000

    Remove Bridges.parseDescFile() and its unittests.
    
     * REMOVE bridgedb.Bridges.parseDescFile() function because it was
       replaced by bridgedb.parse.descriptors.parseServerDescriptorsFile().
     * REMOVE four unittests in legacy_Tests.ParseDescFileTests:
        - testSimpleDesc
        - testSingleOrAddress
        - testMultipleOrAddress
        - testConvolutedOrAddress
     * RENAME legacy_Tests.ParseDescFileTests class to
       ParseCountryBlockFileTests.
---
 lib/bridgedb/Bridges.py           |   56 ---------------------------------
 lib/bridgedb/test/legacy_Tests.py |   62 ++-----------------------------------
 2 files changed, 2 insertions(+), 116 deletions(-)

diff --git a/lib/bridgedb/Bridges.py b/lib/bridgedb/Bridges.py
index e92e23e..31b7cf6 100644
--- a/lib/bridgedb/Bridges.py
+++ b/lib/bridgedb/Bridges.py
@@ -41,62 +41,6 @@ ID_LEN = 20  # XXX Only used in commented out line in Storage.py
 DIGEST_LEN = 20
 PORTSPEC_LEN = 16
 
-
-def parseDescFile(f, bridge_purpose='bridge'):
-    """Generator. Parses a cached-descriptors file 'f' and yeilds a Bridge object
-       for every entry whose purpose matches bridge_purpose.
-       This Generator understands the new descriptor format described in 
-       186-multiple-orports.txt
-
-       The new specification provides for specifying multiple ORports as well
-       as supporting new address format for IPv6 addresses.
-
-       The router descriptor "or-address" may occur zero, one, or multiple times.
-       parseDescFile adds each ADDRESS:PORTSPEC to the Bridge.or_addresses list.
-
-       The "or-address" should not duplicate the address:port pair from the "router"
-       description. (Should we try to catch this case?)
-
-       A node may not list more than 8 or-address lines.
-         (should we try to enforce this too?)
-
-       Here is the new format:
-
-       or-address SP ADDRESS ":" PORTLIST NL
-       ADDRESS = IP6ADDR | IP4ADDR
-       IPV6ADDR = an ipv6 address, surrounded by square brackets.
-       IPV4ADDR = an ipv4 address, represented as a dotted quad.
-       PORTLIST = PORTSPEC | PORTSPEC "," PORTLIST
-       PORTSPEC = PORT
-       PORT = a number between 1 and 65535 inclusive.
-    """
-   
-    nickname = ip = orport = fingerprint = purpose = None
-    num_or_address_lines = 0
-    or_addresses = {}
-
-    for line in f:
-        line = line.strip()
-        if line.startswith("opt "):
-            line = line[4:]
-        if line.startswith("@purpose "):
-            items = line.split()
-            purpose = items[1]
-        elif line.startswith("router "):
-            items = line.split()
-            if len(items) >= 4:
-                nickname = items[1]
-                ip = items[2].strip('[]')
-                orport = int(items[3])
-        elif line.startswith("fingerprint "):
-            fingerprint = line[12:].replace(" ", "")
-        elif line.startswith("router-signature"):
-            purposeMatches = (purpose == bridge_purpose or bridge_purpose is None)
-            if purposeMatches and nickname and ip and orport and fingerprint:
-                yield (nickname, ipaddr.IPAddress(ip), orport, fingerprint)
-            nickname = ip = orport = fingerprint = purpose = None 
-
-
 re_ipv6 = re.compile("\[([a-fA-F0-9:]+)\]:(.*$)")
 re_ipv4 = re.compile("((?:\d{1,3}\.?){4}):(.*$)")
 
diff --git a/lib/bridgedb/test/legacy_Tests.py b/lib/bridgedb/test/legacy_Tests.py
index 6d55fce..7be5270 100644
--- a/lib/bridgedb/test/legacy_Tests.py
+++ b/lib/bridgedb/test/legacy_Tests.py
@@ -547,65 +547,7 @@ class SQLStorageTests(unittest.TestCase):
         db.cleanWarnedEmails(t+200)
         self.assertEquals(db.getWarnedEmail("def at example.com"), False)
 
-class ParseDescFileTests(unittest.TestCase):
-    def testSimpleDesc(self):
-        test = ""
-
-        for i in range(100):
-            test+= "".join(simpleDesc % (randomIP(), randomPort()))
-            test+=gettimestamp()
-            test+="router-signature\n"
-
-        bs = [b for b in bridgedb.Bridges.parseDescFile(test.split('\n'))]
-        self.assertEquals(len(bs), 100)
-
-        for b in bs:
-            b.assertOK()
-
-    def testSingleOrAddress(self):
-        test = ""
-
-        for i in range(100):
-            test+= simpleDesc % (randomIP(), randomPort())
-            test+= orAddress % (randomIP(),randomPort())
-            test+=gettimestamp()
-            test+= "router-signature\n"
-
-        bs = [b for b in bridgedb.Bridges.parseDescFile(test.split('\n'))]
-        self.assertEquals(len(bs), 100)
-
-        for b in bs:
-            b.assertOK()
-
-    def testMultipleOrAddress(self):
-        test = ""
-        for i in range(100):
-            test+= simpleDesc % (randomIPString(), randomPort())
-            for i in xrange(8):
-                test+= orAddress % (randomIPString(),randomPortSpec())
-            test+=gettimestamp()
-            test+= "router-signature\n"
-
-        bs = [b for b in bridgedb.Bridges.parseDescFile(test.split('\n'))]
-        self.assertEquals(len(bs), 100)
-
-        for b in bs:
-            b.assertOK()
-
-    def testConvolutedOrAddress(self):
-        test = ""
-        for i in range(100):
-            test+= simpleDesc % (randomIPString(), randomPort())
-            for i in xrange(8):
-                test+= orAddress % (randomIPString(),randomPortSpec())
-            test+=gettimestamp()
-            test+= "router-signature\n"
-
-        bs = [b for b in bridgedb.Bridges.parseDescFile(test.split('\n'))]
-        self.assertEquals(len(bs), 100)
-
-        for b in bs:
-            b.assertOK()
+class ParseCountryBlockFileTests(unittest.TestCase):
 
     def testParseCountryBlockFile(self):
         simpleBlock = "%s:%s %s\n"
@@ -765,7 +707,7 @@ def testSuite():
     loader = unittest.TestLoader()
 
     for klass in [IPBridgeDistTests, SQLStorageTests, EmailBridgeDistTests,
-                  ParseDescFileTests, BridgeStabilityTests]:
+                  ParseCountryBlockFileTests, BridgeStabilityTests]:
         suite.addTest(loader.loadTestsFromTestCase(klass))
 
     for module in [ bridgedb.Bridges,





More information about the tor-commits mailing list