mirror of
https://github.com/httpie/cli.git
synced 2025-02-16 17:40:51 +01:00
PEP8. clean-up
This commit is contained in:
parent
8c0f0b578c
commit
aab5cd9da0
@ -1,6 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from pprint import pformat
|
|
||||||
|
|
||||||
import requests
|
import requests
|
||||||
from requests.adapters import HTTPAdapter
|
from requests.adapters import HTTPAdapter
|
||||||
|
@ -14,10 +14,14 @@ is_windows = 'win32' in str(sys.platform).lower()
|
|||||||
|
|
||||||
|
|
||||||
if is_py2:
|
if is_py2:
|
||||||
|
# noinspection PyShadowingBuiltins
|
||||||
bytes = str
|
bytes = str
|
||||||
|
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
|
||||||
str = unicode
|
str = unicode
|
||||||
elif is_py3:
|
elif is_py3:
|
||||||
|
# noinspection PyShadowingBuiltins
|
||||||
str = str
|
str = str
|
||||||
|
# noinspection PyShadowingBuiltins
|
||||||
bytes = bytes
|
bytes = bytes
|
||||||
|
|
||||||
|
|
||||||
@ -32,7 +36,7 @@ try: # pragma: no cover
|
|||||||
# noinspection PyCompatibility
|
# noinspection PyCompatibility
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
except ImportError: # pragma: no cover
|
except ImportError: # pragma: no cover
|
||||||
# noinspection PyCompatibility
|
# noinspection PyCompatibility,PyUnresolvedReferences
|
||||||
from urllib2 import urlopen
|
from urllib2 import urlopen
|
||||||
|
|
||||||
try: # pragma: no cover
|
try: # pragma: no cover
|
||||||
@ -40,10 +44,10 @@ try: # pragma: no cover
|
|||||||
except ImportError: # pragma: no cover
|
except ImportError: # pragma: no cover
|
||||||
# Python 2.6 OrderedDict class, needed for headers, parameters, etc .###
|
# Python 2.6 OrderedDict class, needed for headers, parameters, etc .###
|
||||||
# <https://pypi.python.org/pypi/ordereddict/1.1>
|
# <https://pypi.python.org/pypi/ordereddict/1.1>
|
||||||
# noinspection PyCompatibility
|
# noinspection PyCompatibility,PyUnresolvedReferences
|
||||||
from UserDict import DictMixin
|
from UserDict import DictMixin
|
||||||
|
|
||||||
# noinspection PyShadowingBuiltins
|
# noinspection PyShadowingBuiltins,PyCompatibility
|
||||||
class OrderedDict(dict, DictMixin):
|
class OrderedDict(dict, DictMixin):
|
||||||
# Copyright (c) 2009 Raymond Hettinger
|
# Copyright (c) 2009 Raymond Hettinger
|
||||||
#
|
#
|
||||||
@ -115,6 +119,7 @@ except ImportError: # pragma: no cover
|
|||||||
if not self:
|
if not self:
|
||||||
raise KeyError('dictionary is empty')
|
raise KeyError('dictionary is empty')
|
||||||
if last:
|
if last:
|
||||||
|
# noinspection PyUnresolvedReferences
|
||||||
key = reversed(self).next()
|
key = reversed(self).next()
|
||||||
else:
|
else:
|
||||||
key = iter(self).next()
|
key = iter(self).next()
|
||||||
|
@ -78,15 +78,15 @@ def parse_content_range(content_range, resumed_from):
|
|||||||
# last-byte-pos value, is invalid. The recipient of an invalid
|
# last-byte-pos value, is invalid. The recipient of an invalid
|
||||||
# byte-content-range- spec MUST ignore it and any content
|
# byte-content-range- spec MUST ignore it and any content
|
||||||
# transferred along with it."
|
# transferred along with it."
|
||||||
if (first_byte_pos >= last_byte_pos
|
if (first_byte_pos >= last_byte_pos or
|
||||||
or (instance_length is not None
|
(instance_length is not None and
|
||||||
and instance_length <= last_byte_pos)):
|
instance_length <= last_byte_pos)):
|
||||||
raise ContentRangeError(
|
raise ContentRangeError(
|
||||||
'Invalid Content-Range returned: %r' % content_range)
|
'Invalid Content-Range returned: %r' % content_range)
|
||||||
|
|
||||||
if (first_byte_pos != resumed_from
|
if (first_byte_pos != resumed_from or
|
||||||
or (instance_length is not None
|
(instance_length is not None and
|
||||||
and last_byte_pos + 1 != instance_length)):
|
last_byte_pos + 1 != instance_length)):
|
||||||
# Not what we asked for.
|
# Not what we asked for.
|
||||||
raise ContentRangeError(
|
raise ContentRangeError(
|
||||||
'Unexpected Content-Range returned (%r)'
|
'Unexpected Content-Range returned (%r)'
|
||||||
@ -308,9 +308,9 @@ class Downloader(object):
|
|||||||
@property
|
@property
|
||||||
def interrupted(self):
|
def interrupted(self):
|
||||||
return (
|
return (
|
||||||
self.finished
|
self.finished and
|
||||||
and self.status.total_size
|
self.status.total_size and
|
||||||
and self.status.total_size != self.status.downloaded
|
self.status.total_size != self.status.downloaded
|
||||||
)
|
)
|
||||||
|
|
||||||
def chunk_downloaded(self, chunk):
|
def chunk_downloaded(self, chunk):
|
||||||
@ -399,8 +399,8 @@ class ProgressReporterThread(threading.Thread):
|
|||||||
if now - self._prev_time >= self._update_interval:
|
if now - self._prev_time >= self._update_interval:
|
||||||
downloaded = self.status.downloaded
|
downloaded = self.status.downloaded
|
||||||
try:
|
try:
|
||||||
speed = ((downloaded - self._prev_bytes)
|
speed = ((downloaded - self._prev_bytes) /
|
||||||
/ (now - self._prev_time))
|
(now - self._prev_time))
|
||||||
except ZeroDivisionError:
|
except ZeroDivisionError:
|
||||||
speed = 0
|
speed = 0
|
||||||
|
|
||||||
@ -434,11 +434,11 @@ class ProgressReporterThread(threading.Thread):
|
|||||||
self._prev_bytes = downloaded
|
self._prev_bytes = downloaded
|
||||||
|
|
||||||
self.output.write(
|
self.output.write(
|
||||||
CLEAR_LINE
|
CLEAR_LINE +
|
||||||
+ ' '
|
' ' +
|
||||||
+ SPINNER[self._spinner_pos]
|
SPINNER[self._spinner_pos] +
|
||||||
+ ' '
|
' ' +
|
||||||
+ self._status_line
|
self._status_line
|
||||||
)
|
)
|
||||||
self.output.flush()
|
self.output.flush()
|
||||||
|
|
||||||
@ -447,8 +447,8 @@ class ProgressReporterThread(threading.Thread):
|
|||||||
else 0)
|
else 0)
|
||||||
|
|
||||||
def sum_up(self):
|
def sum_up(self):
|
||||||
actually_downloaded = (self.status.downloaded
|
actually_downloaded = (
|
||||||
- self.status.resumed_from)
|
self.status.downloaded - self.status.resumed_from)
|
||||||
time_taken = self.status.time_finished - self.status.time_started
|
time_taken = self.status.time_finished - self.status.time_started
|
||||||
|
|
||||||
self.output.write(CLEAR_LINE)
|
self.output.write(CLEAR_LINE)
|
||||||
@ -463,8 +463,8 @@ class ProgressReporterThread(threading.Thread):
|
|||||||
|
|
||||||
self.output.write(SUMMARY.format(
|
self.output.write(SUMMARY.format(
|
||||||
downloaded=humanize_bytes(actually_downloaded),
|
downloaded=humanize_bytes(actually_downloaded),
|
||||||
total=(self.status.total_size
|
total=(self.status.total_size and
|
||||||
and humanize_bytes(self.status.total_size)),
|
humanize_bytes(self.status.total_size)),
|
||||||
speed=humanize_bytes(speed),
|
speed=humanize_bytes(speed),
|
||||||
time=time_taken,
|
time=time_taken,
|
||||||
))
|
))
|
||||||
|
@ -309,9 +309,10 @@ class HTTPieArgumentParser(ArgumentParser):
|
|||||||
self.args.url = self.args.method
|
self.args.url = self.args.method
|
||||||
# Infer the method
|
# Infer the method
|
||||||
has_data = (
|
has_data = (
|
||||||
(not self.args.ignore_stdin and not self.env.stdin_isatty)
|
(not self.args.ignore_stdin and
|
||||||
or any(item.sep in SEP_GROUP_DATA_ITEMS
|
not self.env.stdin_isatty) or
|
||||||
for item in self.args.items)
|
any(item.sep in SEP_GROUP_DATA_ITEMS
|
||||||
|
for item in self.args.items)
|
||||||
)
|
)
|
||||||
self.args.method = HTTP_POST if has_data else HTTP_GET
|
self.args.method = HTTP_POST if has_data else HTTP_GET
|
||||||
|
|
||||||
@ -439,8 +440,8 @@ class SessionNameValidator(object):
|
|||||||
|
|
||||||
def __call__(self, value):
|
def __call__(self, value):
|
||||||
# Session name can be a path or just a name.
|
# Session name can be a path or just a name.
|
||||||
if (os.path.sep not in value
|
if (os.path.sep not in value and
|
||||||
and not VALID_SESSION_NAME_PATTERN.search(value)):
|
not VALID_SESSION_NAME_PATTERN.search(value)):
|
||||||
raise ArgumentError(None, self.error_message)
|
raise ArgumentError(None, self.error_message)
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
@ -5,6 +5,7 @@ import requests.auth
|
|||||||
from httpie.plugins.base import AuthPlugin
|
from httpie.plugins.base import AuthPlugin
|
||||||
|
|
||||||
|
|
||||||
|
# noinspection PyAbstractClass
|
||||||
class BuiltinAuthPlugin(AuthPlugin):
|
class BuiltinAuthPlugin(AuthPlugin):
|
||||||
|
|
||||||
package_name = '(builtin)'
|
package_name = '(builtin)'
|
||||||
|
Loading…
Reference in New Issue
Block a user