2to3: using unicode/str to please py3

This commit is contained in:
2015-03-11 01:05:02 +08:00
parent cbeb01e555
commit 656b29e0ef
3 changed files with 21 additions and 17 deletions

View File

@@ -182,6 +182,9 @@ class Cache:
return None
def set(self, key, content):
if sys.version > '3' and isinstance(content, bytes):
content = content.decode('utf-8')
self._cache[key] = {'last': time.time(), 'value': content}
__getitem__ = get
@@ -383,8 +386,7 @@ def Fill(item, cache, options, feedurl='/', fast=False):
# download
try:
url = link.encode('utf-8')
con = build_opener(*accept_handler(('html', 'text/*'), True)).open(url, timeout=TIMEOUT)
con = build_opener(*accept_handler(('html', 'text/*'), True)).open(link, timeout=TIMEOUT)
data = con.read()
except (IOError, HTTPException) as e:
log('http error: %s' % e.message)
@@ -423,6 +425,9 @@ def Init(url, cache_path, options):
url = url.replace(' ', '%20')
if isinstance(url, bytes):
url = url.decode()
# cache
cache = Cache(cache_path, url)
log(cache._hash)
@@ -464,7 +469,7 @@ def Fetch(url, cache, options):
if url.startswith('https://itunes.apple.com/lookup?id='):
style = 'itunes'
elif xml.startswith('<?xml') or contenttype in MIMETYPE['xml']:
elif xml.startswith(b'<?xml') or contenttype in MIMETYPE['xml']:
style = 'normal'
elif feedify.supported(url):
style = 'feedify'