[tor-commits] [bridgedb/develop] Replace long with int

phw at torproject.org phw at torproject.org
Wed Feb 19 18:27:17 UTC 2020


commit 40b44a281b5b83ca6b240f201ea49f38ceaa0957
Author: Damian Johnson <atagar at torproject.org>
Date:   Fri Jan 10 14:20:22 2020 -0800

    Replace long with int
    
    Python 3.x no longer has a separate long integer type (integers handle this
    under the covers). This fixes exceptions such as...
    
      Traceback (most recent call last):
        File "/usr/local/lib/python3.5/dist-packages/twisted/trial/runner.py", line 823, in loadByName
          return self.suiteFactory([self.findByName(name, recurse=recurse)])
        File "/usr/local/lib/python3.5/dist-packages/twisted/trial/runner.py", line 702, in findByName
          __import__(name)
        File "/home/atagar/Desktop/tor/bridgedb/bridgedb/test/test_Storage.py", line 13, in <module>
          import bridgedb.Storage as Storage
        File "/home/atagar/Desktop/tor/bridgedb/bridgedb/Storage.py", line 16, in <module>
          from bridgedb.Stability import BridgeHistory
        File "/home/atagar/Desktop/tor/bridgedb/bridgedb/Stability.py", line 36, in <module>
          discountIntervalMillis = long(60*60*12*1000)
      builtins.NameError: name 'long' is not defined
    
    This didn't change the test results much...
    
      before: FAILED (skips=1, failures=7, errors=49, successes=255)
      after:  FAILED (skips=1, failures=7, errors=48, successes=256)
---
 bridgedb/Bridges.py              |  2 +-
 bridgedb/Stability.py            | 36 ++++++++++++++++++------------------
 bridgedb/bridgerequest.py        |  2 +-
 bridgedb/test/deprecated.py      |  2 +-
 bridgedb/test/legacy_Tests.py    |  6 +++---
 bridgedb/test/test_parse_addr.py |  2 +-
 6 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/bridgedb/Bridges.py b/bridgedb/Bridges.py
index 7ec60e6..20a78cb 100644
--- a/bridgedb/Bridges.py
+++ b/bridgedb/Bridges.py
@@ -374,7 +374,7 @@ class FixedBridgeSplitter(object):
     def insert(self, bridge):
         # Grab the first 4 bytes
         digest = self.hmac(bridge.identity)
-        pos = long( digest[:8], 16 )
+        pos = int( digest[:8], 16 )
         which = pos % len(self.rings)
         self.rings[which].insert(bridge)
 
diff --git a/bridgedb/Stability.py b/bridgedb/Stability.py
index f2f99ce..c7bd454 100644
--- a/bridgedb/Stability.py
+++ b/bridgedb/Stability.py
@@ -33,7 +33,7 @@ from bridgedb.schedule import toUnixSeconds
 
 # tunables 
 weighting_factor = float(19)/float(20)
-discountIntervalMillis = long(60*60*12*1000)
+discountIntervalMillis = 60*60*12*1000
 
 
 class BridgeHistory(object):
@@ -76,15 +76,15 @@ class BridgeHistory(object):
         self.fingerprint = fingerprint
         self.ip = ip 
         self.port = port
-        self.weightedUptime = long(weightedUptime)
-        self.weightedTime = long(weightedTime)
-        self.weightedRunLength = long(weightedRunLength)
+        self.weightedUptime = int(weightedUptime)
+        self.weightedTime = int(weightedTime)
+        self.weightedRunLength = int(weightedRunLength)
         self.totalRunWeights = float(totalRunWeights)
         self.lastSeenWithDifferentAddressAndPort = \
-                long(lastSeenWithDifferentAddressAndPort)
-        self.lastSeenWithThisAddressAndPort = long(lastSeenWithThisAddressAndPort)
-        self.lastDiscountedHistoryValues = long(lastDiscountedHistoryValues)
-        self.lastUpdatedWeightedTime = long(lastUpdatedWeightedTime)
+                int(lastSeenWithDifferentAddressAndPort)
+        self.lastSeenWithThisAddressAndPort = int(lastSeenWithThisAddressAndPort)
+        self.lastDiscountedHistoryValues = int(lastDiscountedHistoryValues)
+        self.lastUpdatedWeightedTime = int(lastUpdatedWeightedTime)
 
     def discountWeightedFractionalUptimeAndWeightedTime(self, discountUntilMillis):
         """ discount weighted times """
@@ -111,8 +111,8 @@ class BridgeHistory(object):
     @property
     def weightedFractionalUptime(self):
         """Weighted Fractional Uptime"""
-        if self.weightedTime <0.0001: return long(0)
-        return long(10000) * self.weightedUptime / self.weightedTime
+        if self.weightedTime <0.0001: return 0
+        return 10000 * self.weightedUptime / self.weightedTime
 
     @property
     def tosa(self):
@@ -127,7 +127,7 @@ class BridgeHistory(object):
         more recently than it, or if it has been around for a Weighted Time of 8 days.
         """
         # if this bridge has been around longer than 8 days
-        if self.weightedTime >= long(8 * 24 * 60 * 60):
+        if self.weightedTime >= 8 * 24 * 60 * 60:
             return True
 
         # return True if self.weightedTime is greater than the weightedTime
@@ -146,10 +146,10 @@ class BridgeHistory(object):
         """Weighted Mean Time Between Address Change"""
         totalRunLength = self.weightedRunLength + \
                 ((self.lastSeenWithThisAddressAndPort -
-                self.lastSeenWithDifferentAddressAndPort) / long(1000))
+                self.lastSeenWithDifferentAddressAndPort) / 1000)
 
         totalWeights = self.totalRunWeights + 1.0
-        if totalWeights <  0.0001: return long(0)
+        if totalWeights <  0.0001: return 0
         assert(isinstance(long,totalRunLength))
         assert(isinstance(long,totalWeights))
         return totalRunlength / totalWeights
@@ -159,9 +159,9 @@ def addOrUpdateBridgeHistory(bridge, timestamp):
         bhe = db.getBridgeHistory(bridge.fingerprint)
         if not bhe:
             # This is the first status, assume 60 minutes.
-            secondsSinceLastStatusPublication = long(60*60)
-            lastSeenWithDifferentAddressAndPort = timestamp * long(1000)
-            lastSeenWithThisAddressAndPort = timestamp * long(1000)
+            secondsSinceLastStatusPublication = 60*60
+            lastSeenWithDifferentAddressAndPort = timestamp * 1000
+            lastSeenWithThisAddressAndPort = timestamp * 1000
     
             bhe = BridgeHistory(
                     bridge.fingerprint, bridge.address, bridge.orPort,
@@ -179,9 +179,9 @@ def addOrUpdateBridgeHistory(bridge, timestamp):
         # Calculate the seconds since the last parsed status.  If this is
         # the first status or we haven't seen a status for more than 60
         # minutes, assume 60 minutes.
-        statusPublicationMillis = long(timestamp * 1000)
+        statusPublicationMillis = timestamp * 1000
         if (statusPublicationMillis - bhe.lastSeenWithThisAddressAndPort) > 60*60*1000:
-            secondsSinceLastStatusPublication = long(60*60)
+            secondsSinceLastStatusPublication = 60*60
             logging.debug("Capping secondsSinceLastStatusPublication to 1 hour")
         # otherwise, roll with it
         else:
diff --git a/bridgedb/bridgerequest.py b/bridgedb/bridgerequest.py
index 7bd7b64..821bd7c 100644
--- a/bridgedb/bridgerequest.py
+++ b/bridgedb/bridgerequest.py
@@ -164,7 +164,7 @@ class BridgeRequestBase(object):
         # Get an HMAC with the key of the client identifier:
         digest = getHMACFunc(key)(client)
         # Take the lower 8 bytes of the digest and convert to a long:
-        position = long(digest[:8], 16)
+        position = int(digest[:8], 16)
         return position
 
     def isValid(self, valid=None):
diff --git a/bridgedb/test/deprecated.py b/bridgedb/test/deprecated.py
index ab7c502..1a71bf1 100644
--- a/bridgedb/test/deprecated.py
+++ b/bridgedb/test/deprecated.py
@@ -126,7 +126,7 @@ class Bridge(object):
 
         if not request: request = 'default'
         digest = getHMACFunc('Order-Or-Addresses')(request)
-        pos = long(digest[:8], 16) # lower 8 bytes -> long
+        pos = int(digest[:8], 16) # lower 8 bytes -> int
 
         # default address type
         if not addressClass: addressClass = ipaddr.IPv4Address
diff --git a/bridgedb/test/legacy_Tests.py b/bridgedb/test/legacy_Tests.py
index 37bce70..93b52a7 100644
--- a/bridgedb/test/legacy_Tests.py
+++ b/bridgedb/test/legacy_Tests.py
@@ -229,7 +229,7 @@ class BridgeStabilityTests(unittest.TestCase):
             for i in range(61):
                 yield (i+1)*60*30 + x # 30 minute intervals
         now = time.time()
-        time_on_address = long(60*30*60) # 30 hours
+        time_on_address = 60*30*60 # 30 hours
         downtime = 60*60*random.randint(0,4) # random hours of downtime
 
         for t in timestampSeries(now):
@@ -258,8 +258,8 @@ class BridgeStabilityTests(unittest.TestCase):
             [ bridgedb.Stability.addOrUpdateBridgeHistory(b, t) for t in ts ]
             b = db.getBridgeHistory(b.fingerprint)
             assert b.tosa == ts[-1] - last_seen
-            assert (long(last_seen*1000) == b.lastSeenWithDifferentAddressAndPort)
-            assert (long(ts[-1]*1000) == b.lastSeenWithThisAddressAndPort)
+            assert (last_seen*1000 == b.lastSeenWithDifferentAddressAndPort)
+            assert (ts[-1]*1000 == b.lastSeenWithThisAddressAndPort)
 
     def testFamiliar(self):
         # create some bridges
diff --git a/bridgedb/test/test_parse_addr.py b/bridgedb/test/test_parse_addr.py
index 124ea0f..8183167 100644
--- a/bridgedb/test/test_parse_addr.py
+++ b/bridgedb/test/test_parse_addr.py
@@ -735,7 +735,7 @@ class PortListTest(unittest.TestCase):
         """Test ``__getitem__`` with a string."""
         ports = (443, 9001, 9030)
         portList = addr.PortList(*ports)
-        self.assertEqual(portList.__getitem__(long(0)), 9001)
+        self.assertEqual(portList.__getitem__(0), 9001)
 
     def test_mixedArgs(self):
         """Create a :class:`addr.PortList` with mixed type parameters."""





More information about the tor-commits mailing list