1
0
mirror of https://github.com/httpie/cli.git synced 2024-11-24 08:22:22 +02:00

PEP8. clean-up

This commit is contained in:
Jakub Roztocil 2016-07-04 20:30:55 +02:00
parent 8c0f0b578c
commit aab5cd9da0
5 changed files with 35 additions and 29 deletions

View File

@ -1,6 +1,5 @@
import json
import sys
from pprint import pformat
import requests
from requests.adapters import HTTPAdapter

View File

@ -14,10 +14,14 @@ is_windows = 'win32' in str(sys.platform).lower()
if is_py2:
# noinspection PyShadowingBuiltins
bytes = str
# noinspection PyUnresolvedReferences,PyShadowingBuiltins
str = unicode
elif is_py3:
# noinspection PyShadowingBuiltins
str = str
# noinspection PyShadowingBuiltins
bytes = bytes
@ -32,7 +36,7 @@ try: # pragma: no cover
# noinspection PyCompatibility
from urllib.request import urlopen
except ImportError: # pragma: no cover
# noinspection PyCompatibility
# noinspection PyCompatibility,PyUnresolvedReferences
from urllib2 import urlopen
try: # pragma: no cover
@ -40,10 +44,10 @@ try: # pragma: no cover
except ImportError: # pragma: no cover
# Python 2.6 OrderedDict class, needed for headers, parameters, etc .###
# <https://pypi.python.org/pypi/ordereddict/1.1>
# noinspection PyCompatibility
# noinspection PyCompatibility,PyUnresolvedReferences
from UserDict import DictMixin
# noinspection PyShadowingBuiltins
# noinspection PyShadowingBuiltins,PyCompatibility
class OrderedDict(dict, DictMixin):
# Copyright (c) 2009 Raymond Hettinger
#
@ -115,6 +119,7 @@ except ImportError: # pragma: no cover
if not self:
raise KeyError('dictionary is empty')
if last:
# noinspection PyUnresolvedReferences
key = reversed(self).next()
else:
key = iter(self).next()

View File

@ -78,15 +78,15 @@ def parse_content_range(content_range, resumed_from):
# last-byte-pos value, is invalid. The recipient of an invalid
# byte-content-range- spec MUST ignore it and any content
# transferred along with it."
if (first_byte_pos >= last_byte_pos
or (instance_length is not None
and instance_length <= last_byte_pos)):
if (first_byte_pos >= last_byte_pos or
(instance_length is not None and
instance_length <= last_byte_pos)):
raise ContentRangeError(
'Invalid Content-Range returned: %r' % content_range)
if (first_byte_pos != resumed_from
or (instance_length is not None
and last_byte_pos + 1 != instance_length)):
if (first_byte_pos != resumed_from or
(instance_length is not None and
last_byte_pos + 1 != instance_length)):
# Not what we asked for.
raise ContentRangeError(
'Unexpected Content-Range returned (%r)'
@ -308,9 +308,9 @@ class Downloader(object):
@property
def interrupted(self):
return (
self.finished
and self.status.total_size
and self.status.total_size != self.status.downloaded
self.finished and
self.status.total_size and
self.status.total_size != self.status.downloaded
)
def chunk_downloaded(self, chunk):
@ -399,8 +399,8 @@ class ProgressReporterThread(threading.Thread):
if now - self._prev_time >= self._update_interval:
downloaded = self.status.downloaded
try:
speed = ((downloaded - self._prev_bytes)
/ (now - self._prev_time))
speed = ((downloaded - self._prev_bytes) /
(now - self._prev_time))
except ZeroDivisionError:
speed = 0
@ -434,11 +434,11 @@ class ProgressReporterThread(threading.Thread):
self._prev_bytes = downloaded
self.output.write(
CLEAR_LINE
+ ' '
+ SPINNER[self._spinner_pos]
+ ' '
+ self._status_line
CLEAR_LINE +
' ' +
SPINNER[self._spinner_pos] +
' ' +
self._status_line
)
self.output.flush()
@ -447,8 +447,8 @@ class ProgressReporterThread(threading.Thread):
else 0)
def sum_up(self):
actually_downloaded = (self.status.downloaded
- self.status.resumed_from)
actually_downloaded = (
self.status.downloaded - self.status.resumed_from)
time_taken = self.status.time_finished - self.status.time_started
self.output.write(CLEAR_LINE)
@ -463,8 +463,8 @@ class ProgressReporterThread(threading.Thread):
self.output.write(SUMMARY.format(
downloaded=humanize_bytes(actually_downloaded),
total=(self.status.total_size
and humanize_bytes(self.status.total_size)),
total=(self.status.total_size and
humanize_bytes(self.status.total_size)),
speed=humanize_bytes(speed),
time=time_taken,
))

View File

@ -309,9 +309,10 @@ class HTTPieArgumentParser(ArgumentParser):
self.args.url = self.args.method
# Infer the method
has_data = (
(not self.args.ignore_stdin and not self.env.stdin_isatty)
or any(item.sep in SEP_GROUP_DATA_ITEMS
for item in self.args.items)
(not self.args.ignore_stdin and
not self.env.stdin_isatty) or
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
@ -439,8 +440,8 @@ class SessionNameValidator(object):
def __call__(self, value):
# Session name can be a path or just a name.
if (os.path.sep not in value
and not VALID_SESSION_NAME_PATTERN.search(value)):
if (os.path.sep not in value and
not VALID_SESSION_NAME_PATTERN.search(value)):
raise ArgumentError(None, self.error_message)
return value

View File

@ -5,6 +5,7 @@ import requests.auth
from httpie.plugins.base import AuthPlugin
# noinspection PyAbstractClass
class BuiltinAuthPlugin(AuthPlugin):
package_name = '(builtin)'