Polish Python 2 removal (#1070)

This commit is contained in:
Mickaël Schoentgen 2021-05-27 13:05:41 +02:00 committed by GitHub
parent 264d45cdf5
commit 464b5b4c1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 8 additions and 31 deletions

View File

@ -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:

View File

@ -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
# `original.msg` is a `http.client.HTTPMessage`
# `_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<CRLF>`.
headers.extend(h.strip() for h in original.msg.headers)
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

View File

@ -1,5 +1,3 @@
from __future__ import absolute_import
import json
from typing import Optional, Type

View File

@ -1,4 +1,3 @@
from __future__ import absolute_import
import json
from ...plugins import FormatterPlugin

View File

@ -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['

View File

@ -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)

View File

@ -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

View File

@ -1,4 +1,3 @@
# coding=utf-8
"""
Various unicode handling related tests.

View File

@ -1,4 +1,3 @@
# coding=utf-8
"""Utilities for HTTPie test suite."""
import re
import shlex