2to3: (iter)items to list

master
pictuga 2015-02-25 12:02:53 +08:00
parent 3fb90cb7b4
commit 27cf8f6498
3 changed files with 8 additions and 8 deletions

View File

@ -219,7 +219,7 @@ class MetaRedirectHandler(urllib2.BaseHandler):
match = re.search(r'(?i)<meta http-equiv=.refresh[^>]*?url=(http.*?)["\']', data) match = re.search(r'(?i)<meta http-equiv=.refresh[^>]*?url=(http.*?)["\']', data)
if match: if match:
new_url = match.groups()[0] 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')) if k.lower() not in ('content-length', 'content-type'))
new = urllib2.Request(new_url, new = urllib2.Request(new_url,
headers=new_headers, headers=new_headers,

View File

@ -47,7 +47,7 @@ def tag_NS(tag, nsmap=NSMAP):
match = re.search(r'^\{([^\}]+)\}(.*)$', tag) match = re.search(r'^\{([^\}]+)\}(.*)$', tag)
if match: if match:
match = match.groups() match = match.groups()
for (key, url) in nsmap.iteritems(): for (key, url) in nsmap.items():
if url == match[0]: if url == match[0]:
return "%s:%s" % (key, match[1].lower()) return "%s:%s" % (key, match[1].lower())
else: else:

View File

@ -185,7 +185,7 @@ class Cache:
if not os.path.exists(self._dir): if not os.path.exists(self._dir):
os.makedirs(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: if time.time() - self._cache[i]['last'] > self._lifespan > -1:
del self._cache[i] del self._cache[i]
@ -685,7 +685,7 @@ def cgi_app(environ, start_response):
options['last'] = int(environ['HTTP_IF_NONE_MATCH'][1:-1]) options['last'] = int(environ['HTTP_IF_NONE_MATCH'][1:-1])
if not options.force and time.time() - options.last < DELAY: if not options.force and time.time() - options.last < DELAY:
headers['status'] = '304 Not Modified' headers['status'] = '304 Not Modified'
start_response(headers['status'], headers.items()) start_response(headers['status'], list(headers.items()))
log(url) log(url)
log('etag good') log('etag good')
return [] return []
@ -719,7 +719,7 @@ def cgi_app(environ, start_response):
if headers['content-type'] == 'text/xml': if headers['content-type'] == 'text/xml':
headers['content-type'] = rss.mimetype headers['content-type'] = rss.mimetype
start_response(headers['status'], headers.items()) start_response(headers['status'], list(headers.items()))
rss = Before(rss, options) rss = Before(rss, options)
rss = Gather(rss, url, cache, options) rss = Gather(rss, url, cache, options)
@ -752,11 +752,11 @@ def cgi_wrapper(environ, start_response):
if os.path.isfile(url): if os.path.isfile(url):
headers['status'] = '200 OK' headers['status'] = '200 OK'
headers['content-type'] = files[url] headers['content-type'] = files[url]
start_response(headers['status'], headers.items()) start_response(headers['status'], list(headers.items()))
return open(url, 'rb').read() return open(url, 'rb').read()
else: else:
headers['status'] = '404 Not found' headers['status'] = '404 Not found'
start_response(headers['status'], headers.items()) start_response(headers['status'], list(headers.items()))
return '' return ''
# actual morss use # actual morss use
@ -766,7 +766,7 @@ def cgi_wrapper(environ, start_response):
raise raise
except Exception as e: except Exception as e:
headers = {'status': '500 Oops', 'content-type': 'text/plain'} 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) log('ERROR <%s>: %s' % (url, e.message), force=True)
return 'An error happened:\n%s' % e.message return 'An error happened:\n%s' % e.message