diff options
author | Shubhendra Singh Chauhan <withshubh@gmail.com> | 2021-03-15 03:27:27 +0530 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-14 16:57:27 -0500 |
commit | 0caac2c0f34a153ba276cbc4ab388a808b422caa (patch) | |
tree | b169d410ce571f73188ba71a814b7a96cc76cbd8 | |
parent | d3bdb992a5f649a23302b35e0aa55b2ea14a6ea1 (diff) | |
download | urllib3-0caac2c0f34a153ba276cbc4ab388a808b422caa.tar.gz |
Many minor code quality and readability improvements
-rw-r--r-- | dummyserver/handlers.py | 2 | ||||
-rw-r--r-- | dummyserver/testcase.py | 2 | ||||
-rw-r--r-- | src/urllib3/contrib/securetransport.py | 2 | ||||
-rw-r--r-- | src/urllib3/response.py | 4 | ||||
-rw-r--r-- | src/urllib3/util/retry.py | 5 | ||||
-rw-r--r-- | src/urllib3/util/url.py | 2 |
6 files changed, 8 insertions, 9 deletions
diff --git a/dummyserver/handlers.py b/dummyserver/handlers.py index 1d79f641..df5a0865 100644 --- a/dummyserver/handlers.py +++ b/dummyserver/handlers.py @@ -107,7 +107,7 @@ class TestingApp(RequestHandler): def certificate(self, request): """Return the requester's certificate.""" cert = request.get_ssl_certificate() - subject = dict() + subject = {} if cert is not None: subject = {k: v for (k, v) in [y for z in cert["subject"] for y in z]} return Response(json.dumps(subject)) diff --git a/dummyserver/testcase.py b/dummyserver/testcase.py index 60f0e9da..9c24d21b 100644 --- a/dummyserver/testcase.py +++ b/dummyserver/testcase.py @@ -182,7 +182,7 @@ class HTTPDummyProxyTestCase: app, cls.io_loop, None, "http", cls.proxy_host ) - upstream_ca_certs = cls.https_certs.get("ca_certs", None) + upstream_ca_certs = cls.https_certs.get("ca_certs") app = web.Application( [(r".*", ProxyHandler)], upstream_ca_certs=upstream_ca_certs ) diff --git a/src/urllib3/contrib/securetransport.py b/src/urllib3/contrib/securetransport.py index b7f86536..190d32f2 100644 --- a/src/urllib3/contrib/securetransport.py +++ b/src/urllib3/contrib/securetransport.py @@ -757,7 +757,7 @@ class SecureTransportContext: @verify_mode.setter def verify_mode(self, value): - self._verify = True if value == ssl.CERT_REQUIRED else False + self._verify = value == ssl.CERT_REQUIRED def set_default_verify_paths(self): # So, this has to do something a bit weird. Specifically, what it does diff --git a/src/urllib3/response.py b/src/urllib3/response.py index 2db95089..e00eaea2 100644 --- a/src/urllib3/response.py +++ b/src/urllib3/response.py @@ -272,7 +272,7 @@ class BaseHTTPResponse(io.IOBase): for e in content_encoding.split(",") if e.strip() in self.CONTENT_DECODERS ] - if len(encodings): + if encodings: self._decoder = _get_decoder(content_encoding) def _decode(self, data: bytes, decode_content: bool, flush_decoder: bool) -> bytes: @@ -864,7 +864,7 @@ class HTTPResponse(BaseHTTPResponse): If the request that generated this response redirected, this method will return the final redirect location. """ - if self.retries is not None and len(self.retries.history): + if self.retries is not None and self.retries.history: return self.retries.history[-1].redirect_location else: return self._request_url diff --git a/src/urllib3/util/retry.py b/src/urllib3/util/retry.py index 87b4a45a..53a78080 100644 --- a/src/urllib3/util/retry.py +++ b/src/urllib3/util/retry.py @@ -204,7 +204,7 @@ class Retry: self.backoff_factor = backoff_factor self.raise_on_redirect = raise_on_redirect self.raise_on_status = raise_on_status - self.history = history or tuple() + self.history = history or () self.respect_retry_after_header = respect_retry_after_header self.remove_headers_on_redirect = frozenset( [h.lower() for h in remove_headers_on_redirect] @@ -274,8 +274,7 @@ class Retry: retry_date = email.utils.mktime_tz(retry_date_tuple) seconds = retry_date - time.time() - if seconds < 0: - seconds = 0 + seconds = max(seconds, 0) return seconds diff --git a/src/urllib3/util/url.py b/src/urllib3/util/url.py index 91ee9761..34912a1b 100644 --- a/src/urllib3/util/url.py +++ b/src/urllib3/util/url.py @@ -241,7 +241,7 @@ def _remove_path_dot_segments(path: str) -> str: if segment == ".": continue # Anything other than '..', should be appended to the output - elif segment != "..": + if segment != "..": output.append(segment) # In this case segment == '..', if we can, we should pop the last # element |