From 8360f70024330eeeb5c53d29e4a05194f872b511 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Mon, 17 Oct 2016 15:15:22 +1300 Subject: 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. --- netlib/http/headers.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) (limited to 'netlib/http/headers.py') 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 -- cgit v1.2.3