use hashlib instead of sha
This commit is contained in:
parent
d0d5ee8132
commit
3c6e12f3a9
3 changed files with 9 additions and 9 deletions
|
@ -2,9 +2,9 @@
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
# GPL 2008
|
# GPL 2008
|
||||||
import gzip
|
import gzip
|
||||||
import StringIO
|
import hashlib
|
||||||
import os
|
import os
|
||||||
import sha
|
import StringIO
|
||||||
import time
|
import time
|
||||||
import urlparse
|
import urlparse
|
||||||
import urllib2
|
import urllib2
|
||||||
|
@ -80,9 +80,9 @@ def _getCacheBase():
|
||||||
|
|
||||||
def _getUrlCacheFile(url, data=None, headers=DEFAULT_HEADERS):
|
def _getUrlCacheFile(url, data=None, headers=DEFAULT_HEADERS):
|
||||||
if data:
|
if data:
|
||||||
url_hash = sha.sha(url + '?' + data).hexdigest()
|
url_hash = hashlib.sha1(url + '?' + data).hexdigest()
|
||||||
else:
|
else:
|
||||||
url_hash = sha.sha(url).hexdigest()
|
url_hash = hashlib.sha1(url).hexdigest()
|
||||||
domain = ".".join(urlparse.urlparse(url)[1].split('.')[-2:])
|
domain = ".".join(urlparse.urlparse(url)[1].split('.')[-2:])
|
||||||
return os.path.join(_getCacheBase(), domain, url_hash[:2], url_hash[2:4], url_hash[4:6], url_hash)
|
return os.path.join(_getCacheBase(), domain, url_hash[:2], url_hash[2:4], url_hash[4:6], url_hash)
|
||||||
|
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
# vi:si:et:sw=4:sts=4:ts=4
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
# GPL 2008
|
# GPL 2008
|
||||||
import sha
|
|
||||||
import os
|
import os
|
||||||
|
import hashlib
|
||||||
|
|
||||||
def sha1sum(filename):
|
def sha1sum(filename):
|
||||||
sha1 = sha.new()
|
sha1 = hashlib.sha1()
|
||||||
file=open(filename)
|
file=open(filename)
|
||||||
buffer=file.read(4096)
|
buffer=file.read(4096)
|
||||||
while buffer:
|
while buffer:
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
# GPL 2007
|
# GPL 2007
|
||||||
|
|
||||||
from threading import Event
|
from threading import Event
|
||||||
import sha
|
import hashlib
|
||||||
from os import stat
|
from os import stat
|
||||||
|
|
||||||
from BitTornado.BT1.makemetafile import make_meta_file
|
from BitTornado.BT1.makemetafile import make_meta_file
|
||||||
|
@ -20,7 +20,7 @@ def getInfoHash(torrentFile):
|
||||||
metainfo_file = open(torrentFile, 'rb')
|
metainfo_file = open(torrentFile, 'rb')
|
||||||
metainfo = bdecode(metainfo_file.read())
|
metainfo = bdecode(metainfo_file.read())
|
||||||
info = metainfo['info']
|
info = metainfo['info']
|
||||||
return sha.sha(bencode(info)).hexdigest().upper()
|
return hashlib.sha1(bencode(info)).hexdigest().upper()
|
||||||
|
|
||||||
def getTorrentInfoFromFile(torrentFile):
|
def getTorrentInfoFromFile(torrentFile):
|
||||||
f = open(torrentFile, 'rb')
|
f = open(torrentFile, 'rb')
|
||||||
|
@ -51,7 +51,7 @@ def getTorrentInfo(data):
|
||||||
if key != 'info':
|
if key != 'info':
|
||||||
tinfo[key] = metainfo[key]
|
tinfo[key] = metainfo[key]
|
||||||
tinfo['size'] = file_length
|
tinfo['size'] = file_length
|
||||||
tinfo['hash'] = sha.sha(bencode(info)).hexdigest()
|
tinfo['hash'] = hashlib.sha1(bencode(info)).hexdigest()
|
||||||
tinfo['announce'] = metainfo['announce']
|
tinfo['announce'] = metainfo['announce']
|
||||||
return tinfo
|
return tinfo
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue