aboutsummaryrefslogtreecommitdiffstats
path: root/netlib/http/headers.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2016-10-17 15:15:22 +1300
committerAldo Cortesi <aldo@nullcube.com>2016-10-17 15:18:47 +1300
commit8360f70024330eeeb5c53d29e4a05194f872b511 (patch)
tree6bbdcfe54fcce1e41660ca07c9470f42debdec5b /netlib/http/headers.py
parent4918feb7252c76c95d85cd8b2b0334a22aaae274 (diff)
downloadmitmproxy-8360f70024330eeeb5c53d29e4a05194f872b511.tar.gz
mitmproxy-8360f70024330eeeb5c53d29e4a05194f872b511.tar.bz2
mitmproxy-8360f70024330eeeb5c53d29e4a05194f872b511.zip
First-order conversion to Python3-only
- Zap various occurrences of Python2 in docs and scripts - Remove six from netlib, and some other places where obvious project-wide search and replace works.
Diffstat (limited to 'netlib/http/headers.py')
-rw-r--r--netlib/http/headers.py28
1 files changed, 9 insertions, 19 deletions
diff --git a/netlib/http/headers.py b/netlib/http/headers.py
index b55874ca..7d46a88e 100644
--- a/netlib/http/headers.py
+++ b/netlib/http/headers.py
@@ -3,26 +3,19 @@ from __future__ import absolute_import, print_function, division
import re
import collections
-import six
from netlib import multidict
from netlib import strutils
# See also: http://lucumr.pocoo.org/2013/7/2/the-updated-guide-to-unicode/
-if six.PY2: # pragma: no cover
- def _native(x):
- return x
- def _always_bytes(x):
- strutils.always_bytes(x, "utf-8", "replace") # raises a TypeError if x != str/bytes/None.
- return x
-else:
- # While headers _should_ be ASCII, it's not uncommon for certain headers to be utf-8 encoded.
- def _native(x):
- return x.decode("utf-8", "surrogateescape")
+# While headers _should_ be ASCII, it's not uncommon for certain headers to be utf-8 encoded.
+def _native(x):
+ return x.decode("utf-8", "surrogateescape")
- def _always_bytes(x):
- return strutils.always_bytes(x, "utf-8", "surrogateescape")
+
+def _always_bytes(x):
+ return strutils.always_bytes(x, "utf-8", "surrogateescape")
class Headers(multidict.MultiDict):
@@ -93,7 +86,7 @@ class Headers(multidict.MultiDict):
# content_type -> content-type
headers = {
_always_bytes(name).replace(b"_", b"-"): _always_bytes(value)
- for name, value in six.iteritems(headers)
+ for name, value in headers.items()
}
self.update(headers)
@@ -113,9 +106,6 @@ class Headers(multidict.MultiDict):
else:
return b""
- if six.PY2: # pragma: no cover
- __str__ = __bytes__
-
def __delitem__(self, key):
key = _always_bytes(key)
super(Headers, self).__delitem__(key)
@@ -167,9 +157,9 @@ class Headers(multidict.MultiDict):
Returns:
The number of replacements made.
"""
- if isinstance(pattern, six.text_type):
+ if isinstance(pattern, str):
pattern = strutils.escaped_str_to_bytes(pattern)
- if isinstance(repl, six.text_type):
+ if isinstance(repl, str):
repl = strutils.escaped_str_to_bytes(repl)
pattern = re.compile(pattern, flags)
replacements = 0