summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-04-22 03:13:04 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-04-22 03:13:04 +0200
commitcf959fa2e95a4e6b265839f6f62c00b57b456e6c (patch)
tree63143d05cdba8ec793de6e2b9cc54fcbc352290a
parent916a56715c777e39461627ea564bc0625712c733 (diff)
downloadpaste-git-cf959fa2e95a4e6b265839f6f62c00b57b456e6c.tar.gz
Port proxy to Python 3
Use Message.items() method instead of HTTPMessage.headers attribute.
-rw-r--r--paste/proxy.py46
1 files changed, 26 insertions, 20 deletions
diff --git a/paste/proxy.py b/paste/proxy.py
index b315265..67d4b1b 100644
--- a/paste/proxy.py
+++ b/paste/proxy.py
@@ -32,6 +32,7 @@ TODO:
from six.moves import http_client as httplib
from six.moves.urllib import parse as urlparse
from six.moves.urllib.parse import quote
+import six
from paste import httpexceptions
from paste.util.converters import aslist
@@ -251,26 +252,31 @@ def parse_headers(message):
Turn a Message object into a list of WSGI-style headers.
"""
headers_out = []
- for full_header in message.headers:
- if not full_header:
- # Shouldn't happen, but we'll just ignore
- continue
- if full_header[0].isspace():
- # Continuation line, add to the last header
- if not headers_out:
- raise ValueError(
- "First header starts with a space (%r)" % full_header)
- last_header, last_value = headers_out.pop()
- value = last_value + ' ' + full_header.strip()
- headers_out.append((last_header, value))
- continue
- try:
- header, value = full_header.split(':', 1)
- except:
- raise ValueError("Invalid header: %r" % full_header)
- value = value.strip()
- if header.lower() not in filtered_headers:
- headers_out.append((header, value))
+ if six.PY3:
+ for header, value in message.items():
+ if header.lower() not in filtered_headers:
+ headers_out.append((header, value))
+ else:
+ for full_header in message.headers:
+ if not full_header:
+ # Shouldn't happen, but we'll just ignore
+ continue
+ if full_header[0].isspace():
+ # Continuation line, add to the last header
+ if not headers_out:
+ raise ValueError(
+ "First header starts with a space (%r)" % full_header)
+ last_header, last_value = headers_out.pop()
+ value = last_value + ' ' + full_header.strip()
+ headers_out.append((last_header, value))
+ continue
+ try:
+ header, value = full_header.split(':', 1)
+ except:
+ raise ValueError("Invalid header: %r" % full_header)
+ value = value.strip()
+ if header.lower() not in filtered_headers:
+ headers_out.append((header, value))
return headers_out
def make_transparent_proxy(