From cbeb01e5554c8354b2e916f63ef655a62427f049 Mon Sep 17 00:00:00 2001 From: pictuga Date: Wed, 11 Mar 2015 01:03:16 +0800 Subject: [PATCH] 2to3: fix urllib header retrieval --- morss/crawler.py | 8 ++++---- morss/morss.py | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/morss/crawler.py b/morss/crawler.py index 794acbf..aa52fc8 100644 --- a/morss/crawler.py +++ b/morss/crawler.py @@ -132,8 +132,8 @@ class GZIPHandler(BaseHandler): def detect_encoding(data, con=None): - if con is not None and con.headers.getparam('charset'): - return con.headers.getparam('charset') + if con is not None and con.info().get('charset'): + return con.info().get('charset') match = re.search('charset=["\']?([0-9a-zA-Z-]+)', data[:1000]) if match: @@ -148,7 +148,7 @@ def detect_encoding(data, con=None): class EncodingFixHandler(BaseHandler): def http_response(self, req, resp): - maintype = resp.info()['Content-Type'].split('/')[0] + maintype = resp.info().get('Content-Type', '').split('/')[0] if 200 <= resp.code < 300 and maintype == 'text': data = resp.read() enc = detect_encoding(data, resp) @@ -227,7 +227,7 @@ class ContentNegociationHandler(BaseHandler): #FIXME class MetaRedirectHandler(BaseHandler): def http_response(self, req, resp): - contenttype = resp.info()['Content-Type'].split(';')[0] + contenttype = resp.info().get('Content-Type', '').split(';')[0] if 200 <= resp.code < 300 and contenttype.startswith('text/'): if contenttype in MIMETYPE['html']: data = resp.read() diff --git a/morss/morss.py b/morss/morss.py index 96c9b31..6e0590f 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -391,7 +391,7 @@ def Fill(item, cache, options, feedurl='/', fast=False): cache.set(link, 'error-http') return True - contenttype = con.info()['Content-Type'].split(';')[0] + contenttype = con.info().get('Content-Type', '').split(';')[0] if contenttype not in MIMETYPE['html'] and contenttype != 'text/plain': log('non-text page') cache.set(link, 'error-type') @@ -457,10 +457,10 @@ def Fetch(url, cache, options): raise MorssException('Error downloading feed') cache.set('xml', xml) - cache.set('etag', con.headers.getheader('etag')) - cache.set('lastmodified', con.headers.getheader('last-modified')) + cache.set('etag', con.info().get('etag')) + cache.set('lastmodified', con.info().get('last-modified')) - contenttype = con.info()['Content-Type'].split(';')[0] + contenttype = con.info().get('Content-Type', '').split(';')[0] if url.startswith('https://itunes.apple.com/lookup?id='): style = 'itunes'