diff --git a/httpie/downloads.py b/httpie/downloads.py index 22e2d4a9..f9a66f5e 100644 --- a/httpie/downloads.py +++ b/httpie/downloads.py @@ -1,10 +1,7 @@ -# coding=utf-8 """ Download mode implementation. """ -from __future__ import division - import errno import mimetypes import os @@ -131,7 +128,7 @@ def filename_from_url(url: str, content_type: Optional[str]) -> str: else: ext = mimetypes.guess_extension(content_type) - if ext == '.htm': # Python 3 + if ext == '.htm': ext = '.html' if ext: diff --git a/httpie/models.py b/httpie/models.py index d496f81a..c30f06e1 100644 --- a/httpie/models.py +++ b/httpie/models.py @@ -63,16 +63,10 @@ class HTTPResponse(HTTPMessage): status_line = f'HTTP/{version} {original.status} {original.reason}' headers = [status_line] - try: - # `original.msg` is a `http.client.HTTPMessage` on Python 3 - # `_headers` is a 2-tuple - headers.extend( - '%s: %s' % header for header in original.msg._headers) - except AttributeError: - # and a `httplib.HTTPMessage` on Python 2.x - # `headers` is a list of `name: val`. - headers.extend(h.strip() for h in original.msg.headers) - + # `original.msg` is a `http.client.HTTPMessage` + # `_headers` is a 2-tuple + headers.extend( + f'{header[0]}: {header[1]}' for header in original.msg._headers) return '\r\n'.join(headers) @property @@ -116,10 +110,6 @@ class HTTPRequest(HTTPMessage): headers.insert(0, request_line) headers = '\r\n'.join(headers).strip() - - if isinstance(headers, bytes): - # Python < 3 - headers = headers.decode('utf8') return headers @property diff --git a/httpie/output/formatters/colors.py b/httpie/output/formatters/colors.py index 384eefdf..ff182d23 100644 --- a/httpie/output/formatters/colors.py +++ b/httpie/output/formatters/colors.py @@ -1,5 +1,3 @@ -from __future__ import absolute_import - import json from typing import Optional, Type diff --git a/httpie/output/formatters/json.py b/httpie/output/formatters/json.py index 63ce5930..65cbcd19 100644 --- a/httpie/output/formatters/json.py +++ b/httpie/output/formatters/json.py @@ -1,4 +1,3 @@ -from __future__ import absolute_import import json from ...plugins import FormatterPlugin diff --git a/httpie/output/writer.py b/httpie/output/writer.py index 83e478ce..380e62eb 100644 --- a/httpie/output/writer.py +++ b/httpie/output/writer.py @@ -58,7 +58,7 @@ def write_stream( ): """Write the output stream.""" try: - # Writing bytes so we use the buffer interface (Python 3). + # Writing bytes so we use the buffer interface. buf = outfile.buffer except AttributeError: buf = outfile @@ -76,7 +76,7 @@ def write_stream_with_colors_win_py3( ): """Like `write`, but colorized chunks are written as text directly to `outfile` to ensure it gets processed by colorama. - Applies only to Windows with Python 3 and colorized terminal output. + Applies only to Windows and colorized terminal output. """ color = b'\x1b[' diff --git a/httpie/utils.py b/httpie/utils.py index e7ebf68a..c7d1beab 100644 --- a/httpie/utils.py +++ b/httpie/utils.py @@ -1,5 +1,3 @@ -from __future__ import division - import json import mimetypes import time @@ -25,8 +23,6 @@ def humanize_bytes(n, precision=2): # URL: https://code.activestate.com/recipes/577081/ """Return a humanized string representation of a number of bytes. - Assumes `from __future__ import division`. - >>> humanize_bytes(1) '1 B' >>> humanize_bytes(1024, precision=1) diff --git a/tests/test_sessions.py b/tests/test_sessions.py index ce4c222e..5718832e 100644 --- a/tests/test_sessions.py +++ b/tests/test_sessions.py @@ -1,4 +1,3 @@ -# coding=utf-8 import json import os import shutil @@ -193,7 +192,7 @@ class TestSession(SessionTestBase): # FIXME: Authorization *sometimes* is not present on Python3 assert (r2.json['headers']['Authorization'] - == HTTPBasicAuth.make_header(u'test', UNICODE)) + == HTTPBasicAuth.make_header('test', UNICODE)) # httpbin doesn't interpret utf8 headers assert UNICODE in r2 diff --git a/tests/test_unicode.py b/tests/test_unicode.py index f5884301..4201e7fe 100644 --- a/tests/test_unicode.py +++ b/tests/test_unicode.py @@ -1,4 +1,3 @@ -# coding=utf-8 """ Various unicode handling related tests. diff --git a/tests/utils/__init__.py b/tests/utils/__init__.py index e336e759..b46b7794 100644 --- a/tests/utils/__init__.py +++ b/tests/utils/__init__.py @@ -1,4 +1,3 @@ -# coding=utf-8 """Utilities for HTTPie test suite.""" import re import shlex