[tor-commits] [tor/maint-0.2.8] Avoid errors in updateFallbackDirs.py when there are no fallbacks
nickm at torproject.org
nickm at torproject.org
Wed Jun 22 12:20:27 UTC 2016
commit 40906122469e3be5421778ceded665fde40868d9
Author: teor (Tim Wilson-Brown) <teor2345 at gmail.com>
Date: Wed Jun 22 11:04:54 2016 +1000
Avoid errors in updateFallbackDirs.py when there are no fallbacks
---
scripts/maint/updateFallbackDirs.py | 12 ++++++++++--
1 file changed, 10 insertions(+), 2 deletions(-)
diff --git a/scripts/maint/updateFallbackDirs.py b/scripts/maint/updateFallbackDirs.py
index 7fcb365..d17e702 100755
--- a/scripts/maint/updateFallbackDirs.py
+++ b/scripts/maint/updateFallbackDirs.py
@@ -1408,7 +1408,11 @@ class CandidateList(dict):
def calculate_measured_bandwidth(self):
self.sort_fallbacks_by_cw_to_bw_factor()
median_fallback = self.fallback_median(True)
- median_cw_to_bw_factor = median_fallback.cw_to_bw_factor()
+ if median_fallback is not None:
+ median_cw_to_bw_factor = median_fallback.cw_to_bw_factor()
+ else:
+ # this will never be used, because there are no fallbacks
+ median_cw_to_bw_factor = None
for f in self.fallbacks:
f.set_measured_bandwidth(median_cw_to_bw_factor)
@@ -1593,7 +1597,11 @@ class CandidateList(dict):
# return a string that describes a/b as a percentage
@staticmethod
def describe_percentage(a, b):
- return '%d/%d = %.0f%%'%(a, b, (a*100.0)/b)
+ if b != 0:
+ return '%d/%d = %.0f%%'%(a, b, (a*100.0)/b)
+ else:
+ # technically, 0/0 is undefined, but 0.0% is a sensible result
+ return '%d/%d = %.0f%%'%(a, b, 0.0)
# return a dictionary of lists of fallbacks by IPv4 netblock
# the dictionary is keyed by the fingerprint of an arbitrary fallback
More information about the tor-commits
mailing list