2to3: fix urllib header retrieval
This commit is contained in:
		@@ -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()
 | 
			
		||||
 
 | 
			
		||||
@@ -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'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user