commit 978323b132a39fd6d9e429d0cf25e8c0db1e55bd Author: Isis Lovecruft isis@torproject.org Date: Sun Dec 28 12:44:20 2014 +0000
Raise InvalidRouterNickname in b.p.descriptors.parseNetworkStatusFile().
For all other ValueErrors raised by Stem, we'll re-raise another ValueError that reuses Stem's error message.
* CHANGE bridgedb.parse.descriptors.parseNetworkStatusFile() to raise an InvalidRouterNickname exception if a router is parsed with a nickname which doesn't conform to torspec. --- lib/bridgedb/parse/descriptors.py | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/lib/bridgedb/parse/descriptors.py b/lib/bridgedb/parse/descriptors.py index ee0cea8..c1e4706 100644 --- a/lib/bridgedb/parse/descriptors.py +++ b/lib/bridgedb/parse/descriptors.py @@ -25,6 +25,7 @@ from stem.descriptor.router_status_entry import _parse_file as _parseNSFile from stem.descriptor.router_status_entry import RouterStatusEntryV3
from bridgedb import safelog +from bridgedb.parse.nickname import InvalidRouterNickname
class DescriptorWarning(Warning): @@ -85,6 +86,9 @@ def parseNetworkStatusFile(filename, validate=True, skipAnnotations=True, :param descriptorClass: A class (probably from :api:`stem.descriptors.router_status_entry`) which Stem will parse each descriptor it reads from **filename** into. + :raises InvalidRouterNickname: if one of the routers in the networkstatus + file had a nickname which does not conform to Tor's nickname + specification. :raises ValueError: if the contents of a descriptor are malformed and **validate** is ``True``. :raises IOError: if the file at **filename** can't be read. @@ -103,7 +107,15 @@ def parseNetworkStatusFile(filename, validate=True, skipAnnotations=True, logging.debug("Skipping %d bytes of networkstatus file." % position) fh.seek(position) document = _parseNSFile(fh, validate, entry_class=descriptorClass) - routers.extend(list(document)) + + try: + routers.extend(list(document)) + except ValueError as error: + if "nickname isn't valid" in str(error): + raise InvalidRouterNickname(str(error)) + else: + raise ValueError(str(error)) + logging.info("Closed networkstatus file: %s" % filename)
return routers
tor-commits@lists.torproject.org