Merge pull request #15 from sanketsaurav/master

Fix issues to improve adherence to best practices
This commit is contained in:
2019-07-16 11:15:24 -04:00
committed by GitHub
12 changed files with 70 additions and 52 deletions
+20
View File
@@ -0,0 +1,20 @@
# generated by deepsource.io
version = 1
test_patterns = [
'tests/*.py'
]
exclude_patterns = [
'*/**/*_compat.py',
'requests3/core/_http/packages/six.py',
'setup.py'
]
[[analyzers]]
name = "python"
enabled = true
runtime_version = "3.x.x"
[analyzers.meta]
max_line_length = 100
+2 -2
View File
@@ -8,7 +8,7 @@ Data structures that power Requests.
import collections
from ._basics import basestring, OrderedDict
from ._basics import basestring
class CaseInsensitiveDict(collections.MutableMapping):
@@ -38,7 +38,7 @@ class CaseInsensitiveDict(collections.MutableMapping):
behavior is undefined.
"""
__slots__ = "_store"
__slots__ = ["_store"]
def __init__(self, data=None, **kwargs):
self._store = collections.OrderedDict()
+4 -4
View File
@@ -449,9 +449,9 @@ class HTTPResponse(io.IOBase):
def readinto(self, b):
# This method is required for `io` module compatibility.
temp = self.read(len(b))
if len(temp) == 0:
if not temp:
return 0
else:
b[: len(temp)] = temp
return len(temp)
b[: len(temp)] = temp
return len(temp)
@@ -1,5 +1,4 @@
import errno
import select
import socket
import ssl
from ..util.connection import create_connection
@@ -238,16 +238,16 @@ class TwistedSocket:
# the most that we ever generate. (If *we* were cancelled, then there
# will be 2 CancelledErrors, and that's fine; in that case we want to
# preserve 1 of them and then re-raise it.)
for i in range(len(failures)):
if isinstance(failures[i].value, CancelledError):
del failures[i]
for idx, failure in enumerate(failures):
if isinstance(failure.value, CancelledError):
del failures[idx]
break
# Now whatever's left is what we need to re-raise
if len(failures) == 0:
if not failures:
return
elif len(failures) == 1:
if len(failures) == 1:
failures[0].raiseException()
else:
raise DoubleError(*failures)
+4 -4
View File
@@ -449,9 +449,9 @@ class HTTPResponse(io.IOBase):
def readinto(self, b):
# This method is required for `io` module compatibility.
temp = self.read(len(b))
if len(temp) == 0:
if not temp:
return 0
else:
b[: len(temp)] = temp
return len(temp)
b[: len(temp)] = temp
return len(temp)
+25 -25
View File
@@ -3,17 +3,17 @@ from __future__ import absolute_import
# Base Exceptions
class HTTPError(Exception):
"Base exception used by this module."
"""Base exception used by this module."""
pass
class HTTPWarning(Warning):
"Base warning used by this module."
"""Base warning used by this module."""
pass
class PoolError(HTTPError):
"Base exception for errors caused within a pool."
"""Base exception for errors caused within a pool."""
def __init__(self, pool, message):
self.pool = pool
@@ -25,7 +25,7 @@ class PoolError(HTTPError):
class RequestError(PoolError):
"Base exception for PoolErrors that have associated URLs."
"""Base exception for PoolErrors that have associated URLs."""
def __init__(self, pool, url, message):
self.url = url
@@ -37,22 +37,22 @@ class RequestError(PoolError):
class SSLError(HTTPError):
"Raised when SSL certificate fails in an HTTPS connection."
"""Raised when SSL certificate fails in an HTTPS connection."""
pass
class ProxyError(HTTPError):
"Raised when the connection to a proxy fails."
"""Raised when the connection to a proxy fails."""
pass
class DecodeError(HTTPError):
"Raised when automatic decoding based on Content-Type fails."
"""Raised when automatic decoding based on Content-Type fails."""
pass
class ProtocolError(HTTPError):
"Raised when something unexpected happens mid-request/response."
"""Raised when something unexpected happens mid-request/response."""
pass
@@ -94,39 +94,39 @@ class TimeoutError(HTTPError):
class ReadTimeoutError(TimeoutError, RequestError):
"Raised when a socket timeout occurs while receiving data from a server"
"""Raised when a socket timeout occurs while receiving data from a server"""
pass
# This timeout error does not have a URL attached and needs to inherit from the
# base HTTPError
class ConnectTimeoutError(TimeoutError):
"Raised when a socket timeout occurs while connecting to a server"
"""Raised when a socket timeout occurs while connecting to a server"""
pass
class NewConnectionError(ConnectTimeoutError, PoolError):
"Raised when we fail to establish a new connection. Usually ECONNREFUSED."
"""Raised when we fail to establish a new connection. Usually ECONNREFUSED."""
pass
class EmptyPoolError(PoolError):
"Raised when a pool runs out of connections and no more are allowed."
"""Raised when a pool runs out of connections and no more are allowed."""
pass
class ClosedPoolError(PoolError):
"Raised when a request enters a pool after the pool has been closed."
"""Raised when a request enters a pool after the pool has been closed."""
pass
class LocationValueError(ValueError, HTTPError):
"Raised when there is something wrong with a given URL input."
"""Raised when there is something wrong with a given URL input."""
pass
class LocationParseError(LocationValueError):
"Raised when get_host or similar fails to parse the URL input."
"""Raised when get_host or similar fails to parse the URL input."""
def __init__(self, location):
message = "Failed to parse: %s" % location
@@ -135,38 +135,38 @@ class LocationParseError(LocationValueError):
class ResponseError(HTTPError):
"Used as a container for an error reason supplied in a MaxRetryError."
"""Used as a container for an error reason supplied in a MaxRetryError."""
GENERIC_ERROR = "too many error responses"
SPECIFIC_ERROR = "too many {status_code} error responses"
class SecurityWarning(HTTPWarning):
"Warned when perfoming security reducing actions"
"""Warned when perfoming security reducing actions"""
pass
class SubjectAltNameWarning(SecurityWarning):
"Warned when connecting to a host with a certificate missing a SAN."
"""Warned when connecting to a host with a certificate missing a SAN."""
pass
class InsecureRequestWarning(SecurityWarning):
"Warned when making an unverified HTTPS request."
"""Warned when making an unverified HTTPS request."""
pass
class SystemTimeWarning(SecurityWarning):
"Warned when system time is suspected to be wrong"
"""Warned when system time is suspected to be wrong"""
pass
class InsecurePlatformWarning(SecurityWarning):
"Warned when certain SSL configuration is not available on a platform."
"""Warned when certain SSL configuration is not available on a platform."""
pass
class SNIMissingWarning(HTTPWarning):
"Warned when making a HTTPS request without SNI available."
"""Warned when making a HTTPS request without SNI available."""
pass
@@ -195,7 +195,7 @@ class BadVersionError(ProtocolError):
class ProxySchemeUnknown(AssertionError, ValueError):
"ProxyManager does not support the supplied scheme"
"""ProxyManager does not support the supplied scheme"""
# TODO(t-8ch): Stop inheriting from AssertionError in v2.0.
def __init__(self, scheme):
@@ -204,7 +204,7 @@ class ProxySchemeUnknown(AssertionError, ValueError):
class HeaderParsingError(HTTPError):
"Raised by assert_header_parsing, but we convert it to a log.warning statement."
"""Raised by assert_header_parsing, but we convert it to a log.warning statement."""
def __init__(self, defects, unparsed_data):
message = "%s, unparsed data: %r" % (defects or "Unknown", unparsed_data)
@@ -212,7 +212,7 @@ class HeaderParsingError(HTTPError):
class UnrewindableBodyError(HTTPError):
"urllib3 encountered an error when trying to rewind a body"
"""urllib3 encountered an error when trying to rewind a body"""
pass
@@ -107,14 +107,14 @@ def match_hostname(cert, hostname):
try:
# Divergence from upstream: ipaddress can't handle byte str
host_ip = ipaddress.ip_address(_to_unicode(hostname))
except ValueError:
# Not an IP address (common case)
host_ip = None
except UnicodeError:
# Divergence from upstream: Have to deal with ipaddress not taking
# byte strings. addresses should be all ascii, so we consider it not
# an ipaddress in this case
host_ip = None
except ValueError:
# Not an IP address (common case)
host_ip = None
except AttributeError:
# Divergence from upstream: Make ipaddress library optional
if ipaddress is None:
+1 -1
View File
@@ -328,7 +328,7 @@ if hasattr(select, "select"):
def select(self, timeout=None):
# Selecting on empty lists on Windows errors out.
if not len(self._readers) and not len(self._writers):
if not (self._readers or self._writers):
return []
timeout = None if timeout is None else max(timeout, 0.0)
+5 -5
View File
@@ -6,17 +6,17 @@ requests.auth
This module contains the authentication handlers for Requests.
"""
import hashlib
import os
import re
import time
import hashlib
import threading
import time
import warnings
from base64 import b64encode
from ._basics import urlparse, str, basestring
from .http_cookies import extract_cookies_to_jar
from ._basics import basestring, str, urlparse
from ._internal_utils import to_native_string
from .http_cookies import extract_cookies_to_jar
from .http_utils import parse_dict_header
CONTENT_TYPE_FORM_URLENCODED = "application/x-www-form-urlencoded"
-1
View File
@@ -8,7 +8,6 @@ This module contains the primary objects that power Requests.
import datetime
import codecs
import sys
from typing import Mapping, Callable
# Import encoding now, to avoid implicit import later.
+1 -1
View File
@@ -8,6 +8,7 @@ that are also useful for external consumption.
"""
import codecs
import collections
import contextlib
import io
import os
@@ -15,7 +16,6 @@ import re
import cgi
import socket
import struct
import sys
import tempfile
import warnings
import typing