mirror of
https://github.com/httpie/cli.git
synced 2024-11-24 08:22:22 +02:00
Polish Python 2 removal (#1070)
This commit is contained in:
parent
264d45cdf5
commit
464b5b4c1d
@ -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:
|
||||
|
@ -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<CRLF>`.
|
||||
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
|
||||
|
@ -1,5 +1,3 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import json
|
||||
from typing import Optional, Type
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
from __future__ import absolute_import
|
||||
import json
|
||||
|
||||
from ...plugins import FormatterPlugin
|
||||
|
@ -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['
|
||||
|
@ -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)
|
||||
|
@ -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
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
# coding=utf-8
|
||||
"""
|
||||
Various unicode handling related tests.
|
||||
|
||||
|
@ -1,4 +1,3 @@
|
||||
# coding=utf-8
|
||||
"""Utilities for HTTPie test suite."""
|
||||
import re
|
||||
import shlex
|
||||
|
Loading…
Reference in New Issue
Block a user