commit 0ba9dda5a67257c1de1d34837b928b99d8e476df Author: Robert Ransom rransom.8774@gmail.com Date: Mon Mar 23 11:41:54 2015 -0700
Avoid joining, then stripping the delimiter out --- lib/bridgedb/parse/addr.py | 8 ++------ lib/bridgedb/test/legacy_Tests.py | 5 +---- lib/bridgedb/test/test_parse_addr.py | 2 +- 3 files changed, 4 insertions(+), 11 deletions(-)
diff --git a/lib/bridgedb/parse/addr.py b/lib/bridgedb/parse/addr.py index af63192..96dc21e 100644 --- a/lib/bridgedb/parse/addr.py +++ b/lib/bridgedb/parse/addr.py @@ -429,7 +429,7 @@ def isValidIP(ip): reasons.append('cannot convert to ip')
if reasons: - explain = ', '.join([r for r in reasons]).strip(', ') + explain = ', '.join([r for r in reasons]) logging.debug("IP address %r is invalid! Reason(s): %s" % (ip, explain)) return False @@ -568,11 +568,7 @@ class PortList(object):
def __str__(self): """Returns a pretty string representation of this PortList.""" - ret = [] - for port in self.ports: - ret.append(',%s' % port) - ret = ''.join([piece for piece in ret]) - return ret.lstrip(",") + return ','.join(['%s' % port for port in self.ports])
def __repr__(self): """Returns a raw depiction of this PortList.""" diff --git a/lib/bridgedb/test/legacy_Tests.py b/lib/bridgedb/test/legacy_Tests.py index d416d22..bf4cf39 100644 --- a/lib/bridgedb/test/legacy_Tests.py +++ b/lib/bridgedb/test/legacy_Tests.py @@ -85,10 +85,7 @@ def randomPortSpec(): ports.append(random.randint(1,65535)) ports.sort(reverse=True)
- portspec = "" - for i in range(0,16): - portspec += "%d," % random.choice(ports) - portspec = portspec.rstrip(',') #remove trailing , + portspec = ",".join(["%d" % random.choice(ports) for i in range(0,16)]) return portspec
def randomCountry(): diff --git a/lib/bridgedb/test/test_parse_addr.py b/lib/bridgedb/test/test_parse_addr.py index 55f0f60..4659efb 100644 --- a/lib/bridgedb/test/test_parse_addr.py +++ b/lib/bridgedb/test/test_parse_addr.py @@ -671,7 +671,7 @@ class PortListTest(unittest.TestCase): tooMany = addr.PortList.PORTSPEC_LEN + 1 ports = [self.getRandomPort() for x in xrange(tooMany)] log.msg("Testing addr.PortList(%s))" - % ', '.join([type('')(port) for port in ports]).strip(', ')) + % ', '.join([type('')(port) for port in ports])) portList = addr.PortList(*ports) self.assertEqual(len(portList), tooMany)
tor-commits@lists.torproject.org