use six to support python 2 and 3
This commit is contained in:
parent
1b1dcf1c58
commit
d4d09b56b6
28 changed files with 1730 additions and 1678 deletions
|
|
@ -6,7 +6,7 @@ from threading import Event
|
|||
from hashlib import sha1
|
||||
import os
|
||||
|
||||
from bencode import bencode, bdecode
|
||||
from .bencode import bencode, bdecode
|
||||
|
||||
__all__ = ['create_torrent', 'get_info_hash', 'get_torrent_info', 'get_files', 'get_torrent_size']
|
||||
|
||||
|
|
@ -24,9 +24,8 @@ def get_info_hash(torrentFile):
|
|||
return sha1(bencode(info)).hexdigest()
|
||||
|
||||
def get_torrent_info(data=None, file=None):
|
||||
from bencode import bencode
|
||||
if file:
|
||||
if isinstance(file, unicode):
|
||||
if not isinstance(file, bytes):
|
||||
file = file.encode('utf-8')
|
||||
with open(file, 'rb') as f:
|
||||
data = f.read()
|
||||
|
|
@ -36,7 +35,7 @@ def get_torrent_info(data=None, file=None):
|
|||
metainfo = bdecode(data)
|
||||
info = metainfo['info']
|
||||
piece_length = info['piece length']
|
||||
if info.has_key('length'):
|
||||
if 'length' in info:
|
||||
# let's assume we just have one file
|
||||
file_length = info['length']
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue