mirror of
https://github.com/httpie/cli.git
synced 2024-11-07 16:34:35 +01: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.
|
Download mode implementation.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
from __future__ import division
|
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
@ -131,7 +128,7 @@ def filename_from_url(url: str, content_type: Optional[str]) -> str:
|
|||||||
else:
|
else:
|
||||||
ext = mimetypes.guess_extension(content_type)
|
ext = mimetypes.guess_extension(content_type)
|
||||||
|
|
||||||
if ext == '.htm': # Python 3
|
if ext == '.htm':
|
||||||
ext = '.html'
|
ext = '.html'
|
||||||
|
|
||||||
if ext:
|
if ext:
|
||||||
|
@ -63,16 +63,10 @@ class HTTPResponse(HTTPMessage):
|
|||||||
|
|
||||||
status_line = f'HTTP/{version} {original.status} {original.reason}'
|
status_line = f'HTTP/{version} {original.status} {original.reason}'
|
||||||
headers = [status_line]
|
headers = [status_line]
|
||||||
try:
|
# `original.msg` is a `http.client.HTTPMessage`
|
||||||
# `original.msg` is a `http.client.HTTPMessage` on Python 3
|
# `_headers` is a 2-tuple
|
||||||
# `_headers` is a 2-tuple
|
headers.extend(
|
||||||
headers.extend(
|
f'{header[0]}: {header[1]}' for header in original.msg._headers)
|
||||||
'%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)
|
|
||||||
|
|
||||||
return '\r\n'.join(headers)
|
return '\r\n'.join(headers)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -116,10 +110,6 @@ class HTTPRequest(HTTPMessage):
|
|||||||
|
|
||||||
headers.insert(0, request_line)
|
headers.insert(0, request_line)
|
||||||
headers = '\r\n'.join(headers).strip()
|
headers = '\r\n'.join(headers).strip()
|
||||||
|
|
||||||
if isinstance(headers, bytes):
|
|
||||||
# Python < 3
|
|
||||||
headers = headers.decode('utf8')
|
|
||||||
return headers
|
return headers
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
from typing import Optional, Type
|
from typing import Optional, Type
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
from __future__ import absolute_import
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from ...plugins import FormatterPlugin
|
from ...plugins import FormatterPlugin
|
||||||
|
@ -58,7 +58,7 @@ def write_stream(
|
|||||||
):
|
):
|
||||||
"""Write the output stream."""
|
"""Write the output stream."""
|
||||||
try:
|
try:
|
||||||
# Writing bytes so we use the buffer interface (Python 3).
|
# Writing bytes so we use the buffer interface.
|
||||||
buf = outfile.buffer
|
buf = outfile.buffer
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
buf = outfile
|
buf = outfile
|
||||||
@ -76,7 +76,7 @@ def write_stream_with_colors_win_py3(
|
|||||||
):
|
):
|
||||||
"""Like `write`, but colorized chunks are written as text
|
"""Like `write`, but colorized chunks are written as text
|
||||||
directly to `outfile` to ensure it gets processed by colorama.
|
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['
|
color = b'\x1b['
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
from __future__ import division
|
|
||||||
|
|
||||||
import json
|
import json
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import time
|
import time
|
||||||
@ -25,8 +23,6 @@ def humanize_bytes(n, precision=2):
|
|||||||
# URL: https://code.activestate.com/recipes/577081/
|
# URL: https://code.activestate.com/recipes/577081/
|
||||||
"""Return a humanized string representation of a number of bytes.
|
"""Return a humanized string representation of a number of bytes.
|
||||||
|
|
||||||
Assumes `from __future__ import division`.
|
|
||||||
|
|
||||||
>>> humanize_bytes(1)
|
>>> humanize_bytes(1)
|
||||||
'1 B'
|
'1 B'
|
||||||
>>> humanize_bytes(1024, precision=1)
|
>>> humanize_bytes(1024, precision=1)
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# coding=utf-8
|
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
@ -193,7 +192,7 @@ class TestSession(SessionTestBase):
|
|||||||
|
|
||||||
# FIXME: Authorization *sometimes* is not present on Python3
|
# FIXME: Authorization *sometimes* is not present on Python3
|
||||||
assert (r2.json['headers']['Authorization']
|
assert (r2.json['headers']['Authorization']
|
||||||
== HTTPBasicAuth.make_header(u'test', UNICODE))
|
== HTTPBasicAuth.make_header('test', UNICODE))
|
||||||
# httpbin doesn't interpret utf8 headers
|
# httpbin doesn't interpret utf8 headers
|
||||||
assert UNICODE in r2
|
assert UNICODE in r2
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# coding=utf-8
|
|
||||||
"""
|
"""
|
||||||
Various unicode handling related tests.
|
Various unicode handling related tests.
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
# coding=utf-8
|
|
||||||
"""Utilities for HTTPie test suite."""
|
"""Utilities for HTTPie test suite."""
|
||||||
import re
|
import re
|
||||||
import shlex
|
import shlex
|
||||||
|
Loading…
Reference in New Issue
Block a user