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

@ -70,9 +70,12 @@ def download(url):
try: try:
r = urlopen(url) r = urlopen(url)
try: try:
size = int(dict(r.info())['Content-Length'].strip()) size = int(dict(r.info())['content-length'].strip())
except KeyError: except KeyError:
size = 1 try:
size = int(dict(r.info())['Content-Length'].strip())
except KeyError:
size = 1
dl = b"" dl = b""
dl_size = 0 dl_size = 0
while True: while True:
@ -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
@ -246,12 +257,18 @@ def doi2Bib(doi):
r = urlopen(req) r = urlopen(req)
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')
else: else:
return '' return ''
except KeyError: except KeyError:
return '' try:
if dict(r.info())['Content-Type'] == 'application/x-bibtex':
return r.read().decode('utf-8')
else:
return ''
except KeyError:
return ''
except URLError: except URLError:
tools.warning('Unable to contact remote server to get the bibtex ' + tools.warning('Unable to contact remote server to get the bibtex ' +
'entry for doi '+doi) 'entry for doi '+doi)