Private GIT

Skip to content
Snippets Groups Projects
Commit 8c4278a5 authored by Kfir Hadas's avatar Kfir Hadas Committed by miigotu
Browse files

Restore `bencode` library to vanilla state (#3858)

* Restore lib `bencode` to vanilla state

* Update libs list

* Handle 'data after valid prefix' exception where bencode is used
parent dac68ac9
No related branches found
No related tags found
No related merge requests found
......@@ -18,6 +18,7 @@ Packages List
=========
```
beautifulsoup4==4.5.3
bencode==1.0
# certgen.py==d52975c # source: https://github.com/pyca/pyopenssl/blob/d52975cef3a36e18552aeb23de7c06aa73d76454/examples/certgen.py
html5lib==0.999999999
- six [required: Any, installed: 1.10.0]
......
......@@ -66,8 +66,8 @@ def bdecode(x):
r, l = decode_func[x[0]](x, 0)
except (IndexError, KeyError, ValueError):
raise BTFailure("not a valid bencoded string")
# if l != len(x):
# raise BTFailure("invalid bencoded value (data after valid prefix)")
if l != len(x):
raise BTFailure("invalid bencoded value (data after valid prefix)")
return r
from types import StringType, IntType, LongType, DictType, ListType, TupleType
......
......@@ -214,10 +214,15 @@ class GenericClient(object): # pylint: disable=too-many-instance-attributes
try:
torrent_bdecode = bencode.bdecode(result.content)
except (bencode.BTL.BTFailure, Exception) as error:
if (isinstance(error, bencode.BTL.BTFailure) and 'data after valid prefix' in error.message):
# Skip this specific exception
pass
else:
logger.log('Unable to bdecode torrent', logger.ERROR)
logger.log('Error is: {0}'.format(error), logger.DEBUG)
# logger.log('Torrent bencoded data: {0!r}'.format(result.content), logger.DEBUG)
raise
try:
info = torrent_bdecode[b'info']
except Exception:
......
......@@ -174,6 +174,10 @@ class TorrentRssProvider(TorrentProvider): # pylint: disable=too-many-instance-
try:
bencode.bdecode(torrent_file)
except (bencode.BTL.BTFailure, Exception) as error:
if (isinstance(error, bencode.BTL.BTFailure) and 'data after valid prefix' in error.message):
# Skip this specific exception
pass
else:
self.dumpHTML(torrent_file)
return False, 'Torrent link is not a valid torrent file: {0}'.format(error)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment