From f271c9c3149e20d7feffb6429b135bbb6c09ddf4 Mon Sep 17 00:00:00 2001 From: Seth Michael Larson Date: Fri, 21 May 2021 09:29:56 -0500 Subject: [PATCH] Apply latest Black formatting --- dummyserver/handlers.py | 12 +++++------ dummyserver/server.py | 4 ++-- src/urllib3/connection.py | 4 ++-- src/urllib3/connectionpool.py | 2 +- src/urllib3/util/connection.py | 2 +- src/urllib3/util/retry.py | 6 +++--- src/urllib3/util/ssltransport.py | 2 +- test/__init__.py | 4 ++-- test/appengine/test_gae_manager.py | 2 +- test/test_retry.py | 16 +++++++-------- test/test_retry_deprecated.py | 16 +++++++-------- test/test_ssltransport.py | 10 +++++----- test/test_util.py | 2 +- test/with_dummyserver/test_connectionpool.py | 20 +++++++++---------- test/with_dummyserver/test_https.py | 4 ++-- .../test_proxy_poolmanager.py | 2 +- test/with_dummyserver/test_socketlevel.py | 4 ++-- 17 files changed, 56 insertions(+), 56 deletions(-) diff --git a/dummyserver/handlers.py b/dummyserver/handlers.py index c047094c4f..c90c2fce20 100644 --- a/dummyserver/handlers.py +++ b/dummyserver/handlers.py @@ -62,27 +62,27 @@ class TestingApp(RequestHandler): """ def get(self): - """ Handle GET requests """ + """Handle GET requests""" self._call_method() def post(self): - """ Handle POST requests """ + """Handle POST requests""" self._call_method() def put(self): - """ Handle PUT requests """ + """Handle PUT requests""" self._call_method() def options(self): - """ Handle OPTIONS requests """ + """Handle OPTIONS requests""" self._call_method() def head(self): - """ Handle HEAD requests """ + """Handle HEAD requests""" self._call_method() def _call_method(self): - """ Call the correct method in this class based on the incoming URI """ + """Call the correct method in this class based on the incoming URI""" req = self.request req.params = {} for k, v in req.arguments.items(): diff --git a/dummyserver/server.py b/dummyserver/server.py index 9ecde97f35..cc1964bc83 100755 --- a/dummyserver/server.py +++ b/dummyserver/server.py @@ -40,7 +40,7 @@ def _resolves_to_ipv6(host): - """ Returns True if the system resolves host to an IPv6 address by default. """ + """Returns True if the system resolves host to an IPv6 address by default.""" resolves_to_ipv6 = False try: for res in socket.getaddrinfo(host, None, socket.AF_UNSPEC): @@ -54,7 +54,7 @@ def _resolves_to_ipv6(host): def _has_ipv6(host): - """ Returns True if the system can bind an IPv6 address. """ + """Returns True if the system can bind an IPv6 address.""" sock = None has_ipv6 = False diff --git a/src/urllib3/connection.py b/src/urllib3/connection.py index 45580b7e1e..efa19af5bd 100644 --- a/src/urllib3/connection.py +++ b/src/urllib3/connection.py @@ -201,7 +201,7 @@ def connect(self): self._prepare_conn(conn) def putrequest(self, method, url, *args, **kwargs): - """""" + """ """ # Empty docstring because the indentation of CPython's implementation # is broken but we don't want this method in our documentation. match = _CONTAINS_CONTROL_CHAR_RE.search(method) @@ -214,7 +214,7 @@ def putrequest(self, method, url, *args, **kwargs): return _HTTPConnection.putrequest(self, method, url, *args, **kwargs) def putheader(self, header, *values): - """""" + """ """ if not any(isinstance(v, str) and v == SKIP_HEADER for v in values): _HTTPConnection.putheader(self, header, *values) elif six.ensure_str(header.lower()) not in SKIPPABLE_HEADERS: diff --git a/src/urllib3/connectionpool.py b/src/urllib3/connectionpool.py index 4708c5bfc7..40183214e2 100644 --- a/src/urllib3/connectionpool.py +++ b/src/urllib3/connectionpool.py @@ -318,7 +318,7 @@ def _prepare_proxy(self, conn): pass def _get_timeout(self, timeout): - """ Helper that always returns a :class:`urllib3.util.Timeout` """ + """Helper that always returns a :class:`urllib3.util.Timeout`""" if timeout is _Default: return self.timeout.clone() diff --git a/src/urllib3/util/connection.py b/src/urllib3/util/connection.py index cd57455748..bdc240c50c 100644 --- a/src/urllib3/util/connection.py +++ b/src/urllib3/util/connection.py @@ -118,7 +118,7 @@ def allowed_gai_family(): def _has_ipv6(host): - """ Returns True if the system can bind an IPv6 address. """ + """Returns True if the system can bind an IPv6 address.""" sock = None has_ipv6 = False diff --git a/src/urllib3/util/retry.py b/src/urllib3/util/retry.py index d25a41b42e..180e82b8cf 100644 --- a/src/urllib3/util/retry.py +++ b/src/urllib3/util/retry.py @@ -321,7 +321,7 @@ def new(self, **kw): @classmethod def from_int(cls, retries, redirect=True, default=None): - """ Backwards-compatibility for the old retries format.""" + """Backwards-compatibility for the old retries format.""" if retries is None: retries = default if default is not None else cls.DEFAULT @@ -374,7 +374,7 @@ def parse_retry_after(self, retry_after): return seconds def get_retry_after(self, response): - """ Get the value of Retry-After in seconds. """ + """Get the value of Retry-After in seconds.""" retry_after = response.getheader("Retry-After") @@ -468,7 +468,7 @@ def is_retry(self, method, status_code, has_retry_after=False): ) def is_exhausted(self): - """ Are we out of retries? """ + """Are we out of retries?""" retry_counts = ( self.total, self.connect, diff --git a/src/urllib3/util/ssltransport.py b/src/urllib3/util/ssltransport.py index 1e41354f5d..c2186bced9 100644 --- a/src/urllib3/util/ssltransport.py +++ b/src/urllib3/util/ssltransport.py @@ -193,7 +193,7 @@ def _wrap_ssl_read(self, len, buffer=None): raise def _ssl_io_loop(self, func, *args): - """ Performs an I/O loop between incoming/outgoing and the socket.""" + """Performs an I/O loop between incoming/outgoing and the socket.""" should_loop = True ret = None diff --git a/test/__init__.py b/test/__init__.py index c03cfac257..3675f48c29 100644 --- a/test/__init__.py +++ b/test/__init__.py @@ -54,7 +54,7 @@ def _can_resolve(host): - """ Returns True if the system can resolve host to an address. """ + """Returns True if the system can resolve host to an address.""" try: socket.getaddrinfo(host, None, socket.AF_UNSPEC) return True @@ -63,7 +63,7 @@ def _can_resolve(host): def has_alpn(ctx_cls=None): - """ Detect if ALPN support is enabled. """ + """Detect if ALPN support is enabled.""" ctx_cls = ctx_cls or util.SSLContext ctx = ctx_cls(protocol=ssl_.PROTOCOL_TLS) try: diff --git a/test/appengine/test_gae_manager.py b/test/appengine/test_gae_manager.py index 3047f249d4..30a9c1e387 100644 --- a/test/appengine/test_gae_manager.py +++ b/test/appengine/test_gae_manager.py @@ -129,7 +129,7 @@ def setup_method(self, method): self.pool = MockPool(self.host, self.port, self.manager) def test_default_method_whitelist_retried(self): - """ urllib3 should retry methods in the default method whitelist """ + """urllib3 should retry methods in the default method whitelist""" retry = urllib3.util.retry.Retry(total=1, status_forcelist=[418]) # Use HEAD instead of OPTIONS, as URLFetch doesn't support OPTIONS resp = self.pool.request( diff --git a/test/test_retry.py b/test/test_retry.py index cc36089796..8ff4cbd76b 100644 --- a/test/test_retry.py +++ b/test/test_retry.py @@ -26,7 +26,7 @@ def no_retry_deprecations(): class TestRetry(object): def test_string(self): - """ Retry string representation looks the way we expect """ + """Retry string representation looks the way we expect""" retry = Retry() assert ( str(retry) @@ -50,7 +50,7 @@ def test_retry_both_specified(self): assert e.value.reason == error def test_retry_higher_total_loses(self): - """ A lower connect timeout than the total is honored """ + """A lower connect timeout than the total is honored""" error = ConnectTimeoutError() retry = Retry(connect=2, total=3) retry = retry.increment(error=error) @@ -59,7 +59,7 @@ def test_retry_higher_total_loses(self): retry.increment(error=error) def test_retry_higher_total_loses_vs_read(self): - """ A lower read timeout than the total is honored """ + """A lower read timeout than the total is honored""" error = ReadTimeoutError(None, "/", "read timed out") retry = Retry(read=2, total=3) retry = retry.increment(method="GET", error=error) @@ -68,7 +68,7 @@ def test_retry_higher_total_loses_vs_read(self): retry.increment(method="GET", error=error) def test_retry_total_none(self): - """ if Total is none, connect error should take precedence """ + """if Total is none, connect error should take precedence""" error = ConnectTimeoutError() retry = Retry(connect=2, total=None) retry = retry.increment(error=error) @@ -85,7 +85,7 @@ def test_retry_total_none(self): assert not retry.is_exhausted() def test_retry_default(self): - """ If no value is specified, should retry connects 3 times """ + """If no value is specified, should retry connects 3 times""" retry = Retry() assert retry.total == 10 assert retry.connect is None @@ -107,7 +107,7 @@ def test_retry_default(self): assert not Retry(False).raise_on_redirect def test_retry_other(self): - """ If an unexpected error is raised, should retry other times """ + """If an unexpected error is raised, should retry other times""" other_error = SSLError() retry = Retry(connect=1) retry = retry.increment(error=other_error) @@ -121,7 +121,7 @@ def test_retry_other(self): assert e.value.reason == other_error def test_retry_read_zero(self): - """ No second chances on read timeouts, by default """ + """No second chances on read timeouts, by default""" error = ReadTimeoutError(None, "/", "read timed out") retry = Retry(read=0) with pytest.raises(MaxRetryError) as e: @@ -140,7 +140,7 @@ def test_status_counter(self): ) def test_backoff(self): - """ Backoff is computed correctly """ + """Backoff is computed correctly""" max_backoff = Retry.BACKOFF_MAX retry = Retry(total=100, backoff_factor=0.2) diff --git a/test/test_retry_deprecated.py b/test/test_retry_deprecated.py index 0c8de37661..c001e3dd67 100644 --- a/test/test_retry_deprecated.py +++ b/test/test_retry_deprecated.py @@ -28,7 +28,7 @@ def expect_retry_deprecation(): class TestRetry(object): def test_string(self): - """ Retry string representation looks the way we expect """ + """Retry string representation looks the way we expect""" retry = Retry() assert ( str(retry) @@ -52,7 +52,7 @@ def test_retry_both_specified(self): assert e.value.reason == error def test_retry_higher_total_loses(self): - """ A lower connect timeout than the total is honored """ + """A lower connect timeout than the total is honored""" error = ConnectTimeoutError() retry = Retry(connect=2, total=3) retry = retry.increment(error=error) @@ -61,7 +61,7 @@ def test_retry_higher_total_loses(self): retry.increment(error=error) def test_retry_higher_total_loses_vs_read(self): - """ A lower read timeout than the total is honored """ + """A lower read timeout than the total is honored""" error = ReadTimeoutError(None, "/", "read timed out") retry = Retry(read=2, total=3) retry = retry.increment(method="GET", error=error) @@ -70,7 +70,7 @@ def test_retry_higher_total_loses_vs_read(self): retry.increment(method="GET", error=error) def test_retry_total_none(self): - """ if Total is none, connect error should take precedence """ + """if Total is none, connect error should take precedence""" error = ConnectTimeoutError() retry = Retry(connect=2, total=None) retry = retry.increment(error=error) @@ -87,7 +87,7 @@ def test_retry_total_none(self): assert not retry.is_exhausted() def test_retry_default(self): - """ If no value is specified, should retry connects 3 times """ + """If no value is specified, should retry connects 3 times""" retry = Retry() assert retry.total == 10 assert retry.connect is None @@ -109,7 +109,7 @@ def test_retry_default(self): assert not Retry(False).raise_on_redirect def test_retry_other(self): - """ If an unexpected error is raised, should retry other times """ + """If an unexpected error is raised, should retry other times""" other_error = SSLError() retry = Retry(connect=1) retry = retry.increment(error=other_error) @@ -123,7 +123,7 @@ def test_retry_other(self): assert e.value.reason == other_error def test_retry_read_zero(self): - """ No second chances on read timeouts, by default """ + """No second chances on read timeouts, by default""" error = ReadTimeoutError(None, "/", "read timed out") retry = Retry(read=0) with pytest.raises(MaxRetryError) as e: @@ -142,7 +142,7 @@ def test_status_counter(self): ) def test_backoff(self): - """ Backoff is computed correctly """ + """Backoff is computed correctly""" max_backoff = Retry.BACKOFF_MAX retry = Retry(total=100, backoff_factor=0.2) diff --git a/test/test_ssltransport.py b/test/test_ssltransport.py index 36ce318350..56111f7422 100644 --- a/test/test_ssltransport.py +++ b/test/test_ssltransport.py @@ -101,7 +101,7 @@ def socket_handler(listener): @pytest.mark.timeout(PER_TEST_TIMEOUT) def test_start_closed_socket(self): - """ Errors generated from an unconnected socket should bubble up.""" + """Errors generated from an unconnected socket should bubble up.""" sock = socket.socket(socket.AF_INET) context = ssl.create_default_context() sock.close() @@ -110,7 +110,7 @@ def test_start_closed_socket(self): @pytest.mark.timeout(PER_TEST_TIMEOUT) def test_close_after_handshake(self): - """ Socket errors should be bubbled up """ + """Socket errors should be bubbled up""" self.start_dummy_server() sock = socket.create_connection((self.host, self.port)) @@ -123,7 +123,7 @@ def test_close_after_handshake(self): @pytest.mark.timeout(PER_TEST_TIMEOUT) def test_wrap_existing_socket(self): - """ Validates a single TLS layer can be established. """ + """Validates a single TLS layer can be established.""" self.start_dummy_server() sock = socket.create_connection((self.host, self.port)) @@ -187,7 +187,7 @@ def shutdown_handler(listener): @pytest.mark.timeout(PER_TEST_TIMEOUT) def test_ssl_object_attributes(self): - """ Ensures common ssl attributes are exposed """ + """Ensures common ssl attributes are exposed""" self.start_dummy_server() sock = socket.create_connection((self.host, self.port)) @@ -215,7 +215,7 @@ def test_ssl_object_attributes(self): @pytest.mark.timeout(PER_TEST_TIMEOUT) def test_socket_object_attributes(self): - """ Ensures common socket attributes are exposed """ + """Ensures common socket attributes are exposed""" self.start_dummy_server() sock = socket.create_connection((self.host, self.port)) diff --git a/test/test_util.py b/test/test_util.py index 827df42726..a5b68a084b 100644 --- a/test/test_util.py +++ b/test/test_util.py @@ -580,7 +580,7 @@ def test_disable_warnings(self): assert len(w) == 1 def _make_time_pass(self, seconds, timeout, time_mock): - """ Make some time pass for the timeout object """ + """Make some time pass for the timeout object""" time_mock.return_value = TIMEOUT_EPOCH timeout.start_connect() time_mock.return_value = TIMEOUT_EPOCH + seconds diff --git a/test/with_dummyserver/test_connectionpool.py b/test/with_dummyserver/test_connectionpool.py index f6a6618262..8ea2ccefb4 100644 --- a/test/with_dummyserver/test_connectionpool.py +++ b/test/with_dummyserver/test_connectionpool.py @@ -284,7 +284,7 @@ def test_unicode_upload(self): assert r.status == 200, r.data def test_nagle(self): - """ Test that connections have TCP_NODELAY turned on """ + """Test that connections have TCP_NODELAY turned on""" # This test needs to be here in order to be run. socket.create_connection actually tries # to connect to the host provided so we need a dummyserver to be running. with HTTPConnectionPool(self.host, self.port) as pool: @@ -354,7 +354,7 @@ def test_defaults_are_applied(self): s.close() def test_connection_error_retries(self): - """ ECONNREFUSED error should raise a connection error, with retries """ + """ECONNREFUSED error should raise a connection error, with retries""" port = find_unused_port() with HTTPConnectionPool(self.host, port) as pool: with pytest.raises(MaxRetryError) as e: @@ -794,13 +794,13 @@ def test_mixed_case_hostname(self): assert response.status == 200 def test_preserves_path_dot_segments(self): - """ ConnectionPool preserves dot segments in the URI """ + """ConnectionPool preserves dot segments in the URI""" with HTTPConnectionPool(self.host, self.port) as pool: response = pool.request("GET", "/echo_uri/seg0/../seg2") assert response.data == b"/echo_uri/seg0/../seg2" def test_default_user_agent_header(self): - """ ConnectionPool has a default user agent """ + """ConnectionPool has a default user agent""" default_ua = _get_default_user_agent() custom_ua = "I'm not a web scraper, what are you talking about?" custom_ua2 = "Yet Another User Agent" @@ -853,7 +853,7 @@ def test_user_agent_header_not_sent_twice(self, headers, chunked): assert request_headers["User-Agent"] == "key" def test_no_user_agent_header(self): - """ ConnectionPool can suppress sending a user agent header """ + """ConnectionPool can suppress sending a user agent header""" custom_ua = "I'm not a web scraper, what are you talking about?" with HTTPConnectionPool(self.host, self.port) as pool: # Suppress user agent in the request headers. @@ -1025,7 +1025,7 @@ def test_max_retry(self): pool.request("GET", "/redirect", fields={"target": "/"}, retries=0) def test_disabled_retry(self): - """ Disabled retries should disable redirect handling. """ + """Disabled retries should disable redirect handling.""" with HTTPConnectionPool(self.host, self.port) as pool: r = pool.request("GET", "/redirect", fields={"target": "/"}, retries=False) assert r.status == 303 @@ -1045,7 +1045,7 @@ def test_disabled_retry(self): pool.request("GET", "/test", retries=False) def test_read_retries(self): - """ Should retry for status codes in the whitelist """ + """Should retry for status codes in the whitelist""" with HTTPConnectionPool(self.host, self.port) as pool: retry = Retry(read=1, status_forcelist=[418]) resp = pool.request( @@ -1057,7 +1057,7 @@ def test_read_retries(self): assert resp.status == 200 def test_read_total_retries(self): - """ HTTP response w/ status code in the whitelist should be retried """ + """HTTP response w/ status code in the whitelist should be retried""" with HTTPConnectionPool(self.host, self.port) as pool: headers = {"test-name": "test_read_total_retries"} retry = Retry(total=1, status_forcelist=[418]) @@ -1079,7 +1079,7 @@ def test_retries_wrong_whitelist(self): assert resp.status == 418 def test_default_method_whitelist_retried(self): - """ urllib3 should retry methods in the default method whitelist """ + """urllib3 should retry methods in the default method whitelist""" with HTTPConnectionPool(self.host, self.port) as pool: retry = Retry(total=1, status_forcelist=[418]) resp = pool.request( @@ -1107,7 +1107,7 @@ def test_read_retries_unsuccessful(self): assert resp.status == 418 def test_retry_reuse_safe(self): - """ It should be possible to reuse a Retry object across requests """ + """It should be possible to reuse a Retry object across requests""" with HTTPConnectionPool(self.host, self.port) as pool: headers = {"test-name": "test_retry_safe"} retry = Retry(total=1, status_forcelist=[418]) diff --git a/test/with_dummyserver/test_https.py b/test/with_dummyserver/test_https.py index 92e23c93f8..ed50990b59 100644 --- a/test/with_dummyserver/test_https.py +++ b/test/with_dummyserver/test_https.py @@ -368,7 +368,7 @@ def test_no_ssl(self): assert isinstance(cm.value.reason, SSLError) def test_unverified_ssl(self): - """ Test that bare HTTPSConnection can connect, make requests """ + """Test that bare HTTPSConnection can connect, make requests""" with HTTPSConnectionPool(self.host, self.port, cert_reqs=ssl.CERT_NONE) as pool: with mock.patch("warnings.warn") as warn: r = pool.request("GET", "/") @@ -567,7 +567,7 @@ def test_https_timeout(self): https_pool.request("GET", "/") def test_tunnel(self): - """ test the _tunnel behavior """ + """test the _tunnel behavior""" timeout = Timeout(total=None) with HTTPSConnectionPool( self.host, self.port, timeout=timeout, cert_reqs="CERT_NONE" diff --git a/test/with_dummyserver/test_proxy_poolmanager.py b/test/with_dummyserver/test_proxy_poolmanager.py index c1535bd087..b9116c73d0 100644 --- a/test/with_dummyserver/test_proxy_poolmanager.py +++ b/test/with_dummyserver/test_proxy_poolmanager.py @@ -142,7 +142,7 @@ def test_https_proxy_forwarding_for_https(self): assert r.status == 200 def test_nagle_proxy(self): - """ Test that proxy connections do not have TCP_NODELAY turned on """ + """Test that proxy connections do not have TCP_NODELAY turned on""" with ProxyManager(self.proxy_url) as http: hc2 = http.connection_from_host(self.http_host, self.http_port) conn = hc2._get_conn() diff --git a/test/with_dummyserver/test_socketlevel.py b/test/with_dummyserver/test_socketlevel.py index 7c06875439..6e57d67214 100644 --- a/test/with_dummyserver/test_socketlevel.py +++ b/test/with_dummyserver/test_socketlevel.py @@ -467,7 +467,7 @@ def socket_handler(listener): timed_out.set() def test_https_connection_read_timeout(self): - """ Handshake timeouts should fail with a Timeout""" + """Handshake timeouts should fail with a Timeout""" timed_out = Event() def socket_handler(listener): @@ -630,7 +630,7 @@ def socket_handler(listener): response.read() def test_retry_weird_http_version(self): - """ Retry class should handle httplib.BadStatusLine errors properly """ + """Retry class should handle httplib.BadStatusLine errors properly""" def socket_handler(listener): sock = listener.accept()[0]