commit e831ea05fd833d1490e71edb7565720b6f51a5ff Author: Isis Lovecruft isis@torproject.org Date: Wed Mar 18 00:24:44 2015 +0000
Handle bridgedb.proxy.loadProxiesFromFile() errors when missing files.
* FIXES a problem found during #14797, introduced during #4405 (but actually present before that in the legacy code, see branch https://gitweb.torproject.org/user/isis/bridgedb.git/log/?h=hotfix/0.2.4-147...). --- lib/bridgedb/proxy.py | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-)
diff --git a/lib/bridgedb/proxy.py b/lib/bridgedb/proxy.py index 6b6f6ac..fe575b3 100644 --- a/lib/bridgedb/proxy.py +++ b/lib/bridgedb/proxy.py @@ -82,18 +82,21 @@ def loadProxiesFromFile(filename, proxySet=None, removeStale=False): if proxySet: oldProxySet = proxySet.copy()
- with open(filename, 'r') as proxyFile: - for line in proxyFile.readlines(): - line = line.strip() - if proxySet: - # ProxySet.add() will validate the IP address - if proxySet.add(line, tag=filename): - logging.info("Added %s to the proxy list." % line) - addresses.append(line) - else: - ip = isIPAddress(line) - if ip: - addresses.append(ip) + try: + with open(filename, 'r') as proxyFile: + for line in proxyFile.readlines(): + line = line.strip() + if proxySet: + # ProxySet.add() will validate the IP address + if proxySet.add(line, tag=filename): + logging.info("Added %s to the proxy list." % line) + addresses.append(line) + else: + ip = isIPAddress(line) + if ip: + addresses.append(ip) + except Exception as error: + logging.warn("Error while reading a proxy list file: %s" % str(error))
if proxySet: stale = list(oldProxySet.difference(addresses))
tor-commits@lists.torproject.org