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

[tor-commits] [bridgedb/master] Fix Tests.randomIP*String() methods to enclose in brackets explicitly.



commit 2579092121744cf7a2fcc172e323953c5784d4d5
Author: Isis Lovecruft <isis@xxxxxxxxxxxxxx>
Date:   Fri Dec 20 03:44:14 2013 +0000

    Fix Tests.randomIP*String() methods to enclose in brackets explicitly.
    
    This was causing problems for the parsers, some of which expect an IPv6
    address without brackets, and others with brackets. It's easier if we're
    explicit about whether we're putting brackets around an address.
---
 lib/bridgedb/Tests.py |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/bridgedb/Tests.py b/lib/bridgedb/Tests.py
index 881463b..5c48cc4 100644
--- a/lib/bridgedb/Tests.py
+++ b/lib/bridgedb/Tests.py
@@ -47,20 +47,23 @@ def randomIP4():
     return ipaddr.IPv4Address(random.getrandbits(32))
 
 def randomIP4String():
-    return str(ipaddr.IPAddress(random.getrandbits(32)))
+    return randomIP4().compressed
 
 def randomIP6():
     return ipaddr.IPv6Address(random.getrandbits(128))
 
 def randomIP6String():
-    # as used by Tor, with enclosing []
-    return "[%s]" % randomIP6()
+    return bracketIP6(randomIP6().compressed)
 
 def randomIPString():
-    # as used by Tor, with enclosing [] for IPv6 addresses
-    if random.choice(xrange(2)): return randomIP4String()
+    if random.choice(xrange(2)):
+        return randomIP4String()
     return randomIP6String()
 
+def bracketIP6(ip):
+    """Put brackets around an IPv6 address, just as tor does."""
+    return "[%s]" % ip
+
 def random16IP():
     upper = "123.123." # same 16
     lower = ".".join([str(random.randrange(1,256)) for _ in xrange(2)]) 



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