commit 57755d16f27a45a41a4f92191f597a34dae9f2b3 Author: aagbsn aagbsn@extc.org Date: Fri Jun 8 22:41:16 2012 -0700
5948 - Update usage of getConfigLine()
The 'needsIPv4' and 'needsIPv6' arguments are replaced with 'addressClass'. --- lib/bridgedb/Server.py | 18 +++++++++++++++--- lib/bridgedb/Tests.py | 8 ++++---- 2 files changed, 19 insertions(+), 7 deletions(-)
diff --git a/lib/bridgedb/Server.py b/lib/bridgedb/Server.py index 5dfe888..e6a63e1 100644 --- a/lib/bridgedb/Server.py +++ b/lib/bridgedb/Server.py @@ -161,8 +161,10 @@ class WebResource(twisted.web.resource.Resource): if ip: if ipv6: rules.append(filterBridgesByIP6) + addressClass = IPv6Address else: rules.append(filterBridgesByIP4) + addressClass = IPv4Address
bridges = self.distributor.getBridgesForIP(ip, interval, self.nBridgesToGive, @@ -171,7 +173,11 @@ class WebResource(twisted.web.resource.Resource):
if bridges: answer = "".join("%s %s\n" % ( - b.getConfigLine(self.includeFingerprints,needIPv6=ipv6), + b.getConfigLine( + includeFingerprint=self.includeFingerprints, + addressClass=addressClass, + request=bridgedb.Dist.uniformMap(ip) + ), (I18n.BRIDGEDB_TEXT[16] if b.isBlocked(countryCode) else "") ) for b in bridges) else: @@ -401,13 +407,16 @@ def getMailResponse(lines, ctx): # read subject, see if they want ipv6 ipv6 = False bridgeFilterRules = [] + addressClass = None for ln in lines: if "ipv6" in ln.strip().lower(): ipv6 = True bridgeFilterRules.append(filterBridgesByIP6) + addressClass = IPv6Address break else: bridgeFilterRules.append(filterBridgesByIP4) + addressClass = IPv4Address
try: interval = ctx.schedule.getInterval(time.time()) @@ -464,8 +473,11 @@ def getMailResponse(lines, ctx):
if bridges: with_fp = ctx.cfg.EMAIL_INCLUDE_FINGERPRINTS - answer = "".join(" %s\n" %b.getConfigLine(with_fp, - needIPv6=ipv6) for b in bridges) + answer = "".join(" %s\n" %b.getConfigLine( + includeFingerprint=with_fp, + addressClass=addressClass, + request=clientAddr + ) for b in bridges) else: answer = "(no bridges currently available)"
diff --git a/lib/bridgedb/Tests.py b/lib/bridgedb/Tests.py index 59536ce..648835a 100644 --- a/lib/bridgedb/Tests.py +++ b/lib/bridgedb/Tests.py @@ -218,7 +218,7 @@ class IPBridgeDistTests(unittest.TestCase): for i in xrange(500): b = d.getBridgesForIP(randomIP(), "x", 1, bridgeFilterRules=[filterBridgesByIP6]) address, portlist = bridgedb.Bridges.parseORAddressLine( - random.choice(b).getConfigLine(needIPv6=True)[7:]) + random.choice(b).getConfigLine(addressClass=ipaddr.IPv6Address)[7:]) assert type(address) is ipaddr.IPv6Address assert filterBridgesByIP6(random.choice(b))
@@ -231,7 +231,7 @@ class IPBridgeDistTests(unittest.TestCase): for i in xrange(500): b = d.getBridgesForIP(randomIP(), "x", 1, bridgeFilterRules=[filterBridgesByIP4]) address, portlist = bridgedb.Bridges.parseORAddressLine( - random.choice(b).getConfigLine(needIPv4=True)[7:]) + random.choice(b).getConfigLine(addressClass=ipaddr.IPv4Address)[7:]) assert type(address) is ipaddr.IPv4Address
assert filterBridgesByIP4(random.choice(b)) @@ -250,10 +250,10 @@ class IPBridgeDistTests(unittest.TestCase): assert filterBridgesByIP4(t) assert filterBridgesByIP6(t) address, portlist = bridgedb.Bridges.parseORAddressLine( - t.getConfigLine(needIPv4=True)[7:]) + t.getConfigLine(addressClass=ipaddr.IPv4Address)[7:]) assert type(address) is ipaddr.IPv4Address address, portlist = bridgedb.Bridges.parseORAddressLine( - t.getConfigLine(needIPv6=True)[7:]) + t.getConfigLine(addressClass=ipaddr.IPv6Address)[7:]) assert type(address) is ipaddr.IPv6Address