diff --git a/deluge/bencode.py b/deluge/bencode.py index 2760c758b..8c00a15c8 100644 --- a/deluge/bencode.py +++ b/deluge/bencode.py @@ -15,6 +15,10 @@ from types import DictType, IntType, ListType, LongType, StringType, TupleType +class BTFailure(Exception): + pass + + def decode_int(x, f): f += 1 newf = x.index('e', f) @@ -71,9 +75,7 @@ def bdecode(x): try: r, l = decode_func[x[0]](x, 0) except (IndexError, KeyError, ValueError): - raise Exception("not a valid bencoded string") - if l != len(x): - raise Exception("invalid bencoded value (data after valid prefix)") + raise BTFailure("not a valid bencoded string") return r diff --git a/deluge/ui/common.py b/deluge/ui/common.py index 94e531d2d..461fa2dc2 100644 --- a/deluge/ui/common.py +++ b/deluge/ui/common.py @@ -74,7 +74,7 @@ class TorrentInfo(object): with open(filename, "rb") as _file: self.__m_filedata = _file.read() self.__m_metadata = bencode.bdecode(self.__m_filedata) - except Exception as ex: + except bencode.BTFailure as ex: log.warning("Unable to open %s: %s", filename, ex) raise ex