From 27cf8f649898f934009ea9b884b80d767c75227e Mon Sep 17 00:00:00 2001 From: pictuga Date: Wed, 25 Feb 2015 12:02:53 +0800 Subject: [PATCH] 2to3: (iter)items to list --- morss/crawler.py | 2 +- morss/feeds.py | 2 +- morss/morss.py | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/morss/crawler.py b/morss/crawler.py index 57ff633..d8faefb 100644 --- a/morss/crawler.py +++ b/morss/crawler.py @@ -219,7 +219,7 @@ class MetaRedirectHandler(urllib2.BaseHandler): match = re.search(r'(?i)]*?url=(http.*?)["\']', data) if match: new_url = match.groups()[0] - new_headers = dict((k, v) for k, v in req.headers.items() + new_headers = dict((k, v) for k, v in list(req.headers.items()) if k.lower() not in ('content-length', 'content-type')) new = urllib2.Request(new_url, headers=new_headers, diff --git a/morss/feeds.py b/morss/feeds.py index 920be82..74ae74c 100644 --- a/morss/feeds.py +++ b/morss/feeds.py @@ -47,7 +47,7 @@ def tag_NS(tag, nsmap=NSMAP): match = re.search(r'^\{([^\}]+)\}(.*)$', tag) if match: match = match.groups() - for (key, url) in nsmap.iteritems(): + for (key, url) in nsmap.items(): if url == match[0]: return "%s:%s" % (key, match[1].lower()) else: diff --git a/morss/morss.py b/morss/morss.py index bf0d68c..055fd22 100644 --- a/morss/morss.py +++ b/morss/morss.py @@ -185,7 +185,7 @@ class Cache: if not os.path.exists(self._dir): os.makedirs(self._dir) - for i in self._cache.keys(): + for i in list(self._cache.keys()): if time.time() - self._cache[i]['last'] > self._lifespan > -1: del self._cache[i] @@ -685,7 +685,7 @@ def cgi_app(environ, start_response): options['last'] = int(environ['HTTP_IF_NONE_MATCH'][1:-1]) if not options.force and time.time() - options.last < DELAY: headers['status'] = '304 Not Modified' - start_response(headers['status'], headers.items()) + start_response(headers['status'], list(headers.items())) log(url) log('etag good') return [] @@ -719,7 +719,7 @@ def cgi_app(environ, start_response): if headers['content-type'] == 'text/xml': headers['content-type'] = rss.mimetype - start_response(headers['status'], headers.items()) + start_response(headers['status'], list(headers.items())) rss = Before(rss, options) rss = Gather(rss, url, cache, options) @@ -752,11 +752,11 @@ def cgi_wrapper(environ, start_response): if os.path.isfile(url): headers['status'] = '200 OK' headers['content-type'] = files[url] - start_response(headers['status'], headers.items()) + start_response(headers['status'], list(headers.items())) return open(url, 'rb').read() else: headers['status'] = '404 Not found' - start_response(headers['status'], headers.items()) + start_response(headers['status'], list(headers.items())) return '' # actual morss use @@ -766,7 +766,7 @@ def cgi_wrapper(environ, start_response): raise except Exception as e: headers = {'status': '500 Oops', 'content-type': 'text/plain'} - start_response(headers['status'], headers.items(), sys.exc_info()) + start_response(headers['status'], list(headers.items()), sys.exc_info()) log('ERROR <%s>: %s' % (url, e.message), force=True) return 'An error happened:\n%s' % e.message