+from builtins import object
import errno
-import md5
+import hashlib
import os
import tempfile
import time
def _clean(self, threshold=0):
for ent in os.listdir(self._dir):
fnm = os.path.join(self._dir, ent)
- if os.path.isdir(fnm):
+ if os.path.isdir(fnm) or not fnm.endswith('.tmp'):
continue
stat = os.lstat(fnm)
if stat.st_mtime < threshold:
return self._dir
def _filename(self, url):
- return os.path.join(self._dir, md5.new(url).hexdigest()+'.tmp')
+ return os.path.join(self._dir, hashlib.md5(url.encode('utf-8')).hexdigest()+'.tmp')
def get(self, url):
filename = self._filename(url)
try:
with open(filename, 'rb') as f:
return f.read()
- except IOError, OSError:
+ except (IOError, OSError):
return None
def set(self, url, content):
return None
try:
try:
- f = os.fdopen(fd, 'w')
+ f = os.fdopen(fd, 'wb')
except:
os.close(fd)
raise