Small differences in between py2 and py3

This commit is contained in:
Phyks 2014-08-03 22:59:00 +02:00
parent f311de7043
commit 9ab00fdded

View File

@ -69,6 +69,9 @@ def download(url):
socket.socket = socks.socksocket socket.socket = socks.socksocket
try: try:
r = urlopen(url) r = urlopen(url)
try:
size = int(dict(r.info())['content-length'].strip())
except KeyError:
try: try:
size = int(dict(r.info())['Content-Length'].strip()) size = int(dict(r.info())['Content-Length'].strip())
except KeyError: except KeyError:
@ -87,10 +90,18 @@ def download(url):
else: else:
break break
contenttype = False contenttype = False
contenttype_req = None
try: try:
if 'pdf' in dict(r.info())['Content-Type']: contenttype_req = dict(r.info())['content-type']
except KeyError:
try:
contenttype_req = dict(r.info())['Content-Type']
except KeyError:
continue
try:
if 'pdf' in contenttype_req:
contenttype = 'pdf' contenttype = 'pdf'
elif 'djvu' in dict(r.info())['Content-Type']: elif 'djvu' in contenttype_req:
contenttype = 'djvu' contenttype = 'djvu'
except KeyError: except KeyError:
pass pass
@ -245,6 +256,12 @@ def doi2Bib(doi):
try: try:
r = urlopen(req) r = urlopen(req)
try:
if dict(r.info())['content-type'] == 'application/x-bibtex':
return r.read().decode('utf-8')
else:
return ''
except KeyError:
try: try:
if dict(r.info())['Content-Type'] == 'application/x-bibtex': if dict(r.info())['Content-Type'] == 'application/x-bibtex':
return r.read().decode('utf-8') return r.read().decode('utf-8')