Skip to content

Commit

Permalink
[script.module.urllib3] 1.26.16 (#2480)
Browse files Browse the repository at this point in the history
  • Loading branch information
L2501 authored Jul 13, 2023
1 parent 2955e79 commit 15931e6
Show file tree
Hide file tree
Showing 18 changed files with 292 additions and 148 deletions.
2 changes: 1 addition & 1 deletion script.module.urllib3/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2008-2020 Andrey Petrov and contributors (see CONTRIBUTORS.txt)
Copyright (c) 2008-2020 Andrey Petrov and contributors.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
111 changes: 0 additions & 111 deletions script.module.urllib3/README.md

This file was deleted.

2 changes: 1 addition & 1 deletion script.module.urllib3/addon.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="script.module.urllib3" name="urllib3" version="1.26.9" provider-name="urllib3">
<addon id="script.module.urllib3" name="urllib3" version="1.26.16" provider-name="urllib3">
<requires>
<import addon="xbmc.python" version="2.25.0"/>
</requires>
Expand Down
2 changes: 1 addition & 1 deletion script.module.urllib3/lib/urllib3/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# This file is protected via CODEOWNERS
__version__ = "1.26.9"
__version__ = "1.26.16"
7 changes: 6 additions & 1 deletion script.module.urllib3/lib/urllib3/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class BrokenPipeError(Exception):

# When it comes time to update this value as a part of regular maintenance
# (ie test_recent_date is failing) update it to ~6 months before the current date.
RECENT_DATE = datetime.date(2020, 7, 1)
RECENT_DATE = datetime.date(2022, 1, 1)

_CONTAINS_CONTROL_CHAR_RE = re.compile(r"[^-!#$%&'*+.^_`|~0-9a-zA-Z]")

Expand Down Expand Up @@ -229,6 +229,11 @@ def putheader(self, header, *values):
)

def request(self, method, url, body=None, headers=None):
# Update the inner socket's timeout value to send the request.
# This only triggers if the connection is re-used.
if getattr(self, "sock", None) is not None:
self.sock.settimeout(self.timeout)

if headers is None:
headers = {}
else:
Expand Down
44 changes: 34 additions & 10 deletions script.module.urllib3/lib/urllib3/connectionpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@
from .util.url import _normalize_host as normalize_host
from .util.url import get_host, parse_url

try: # Platform-specific: Python 3
import weakref

weakref_finalize = weakref.finalize
except AttributeError: # Platform-specific: Python 2
from .packages.backports.weakref_finalize import weakref_finalize

xrange = six.moves.xrange

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -220,6 +227,16 @@ def __init__(
self.conn_kw["proxy"] = self.proxy
self.conn_kw["proxy_config"] = self.proxy_config

# Do not pass 'self' as callback to 'finalize'.
# Then the 'finalize' would keep an endless living (leak) to self.
# By just passing a reference to the pool allows the garbage collector
# to free self if nobody else has a reference to it.
pool = self.pool

# Close all the HTTPConnections in the pool before the
# HTTPConnectionPool object is garbage collected.
weakref_finalize(self, _close_pool_connections, pool)

def _new_conn(self):
"""
Return a fresh :class:`HTTPConnection`.
Expand Down Expand Up @@ -379,7 +396,7 @@ def _make_request(

timeout_obj = self._get_timeout(timeout)
timeout_obj.start_connect()
conn.timeout = timeout_obj.connect_timeout
conn.timeout = Timeout.resolve_default_timeout(timeout_obj.connect_timeout)

# Trigger any extra validation we need to do.
try:
Expand Down Expand Up @@ -489,14 +506,8 @@ def close(self):
# Disable access to the pool
old_pool, self.pool = self.pool, None

try:
while True:
conn = old_pool.get(block=False)
if conn:
conn.close()

except queue.Empty:
pass # Done.
# Close all the HTTPConnections in the pool.
_close_pool_connections(old_pool)

def is_same_host(self, url):
"""
Expand Down Expand Up @@ -767,6 +778,8 @@ def _is_ssl_error_message_from_http_proxy(ssl_error):
isinstance(e, BaseSSLError)
and self.proxy
and _is_ssl_error_message_from_http_proxy(e)
and conn.proxy
and conn.proxy.scheme == "https"
):
e = ProxyError(
"Your proxy appears to only use HTTP and not HTTPS, "
Expand Down Expand Up @@ -860,7 +873,7 @@ def _is_ssl_error_message_from_http_proxy(ssl_error):
)

# Check if we should retry the HTTP response.
has_retry_after = bool(response.getheader("Retry-After"))
has_retry_after = bool(response.headers.get("Retry-After"))
if retries.is_retry(method, response.status, has_retry_after):
try:
retries = retries.increment(method, url, response=response, _pool=self)
Expand Down Expand Up @@ -1106,3 +1119,14 @@ def _normalize_host(host, scheme):
if host.startswith("[") and host.endswith("]"):
host = host[1:-1]
return host


def _close_pool_connections(pool):
"""Drains a queue of connections and closes each one."""
try:
while True:
conn = pool.get(block=False)
if conn:
conn.close()
except queue.Empty:
pass # Done.
2 changes: 1 addition & 1 deletion script.module.urllib3/lib/urllib3/contrib/appengine.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def urlopen(
)

# Check if we should retry the HTTP response.
has_retry_after = bool(http_response.getheader("Retry-After"))
has_retry_after = bool(http_response.headers.get("Retry-After"))
if retries.is_retry(method, http_response.status, has_retry_after):
retries = retries.increment(method, url, response=http_response, _pool=self)
log.debug("Retry: %s", url)
Expand Down
4 changes: 2 additions & 2 deletions script.module.urllib3/lib/urllib3/contrib/ntlmpool.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def _new_conn(self):
log.debug("Request headers: %s", headers)
conn.request("GET", self.authurl, None, headers)
res = conn.getresponse()
reshdr = dict(res.getheaders())
reshdr = dict(res.headers)
log.debug("Response status: %s %s", res.status, res.reason)
log.debug("Response headers: %s", reshdr)
log.debug("Response data: %s [...]", res.read(100))
Expand Down Expand Up @@ -101,7 +101,7 @@ def _new_conn(self):
conn.request("GET", self.authurl, None, headers)
res = conn.getresponse()
log.debug("Response status: %s %s", res.status, res.reason)
log.debug("Response headers: %s", dict(res.getheaders()))
log.debug("Response headers: %s", dict(res.headers))
log.debug("Response data: %s [...]", res.read()[:100])
if res.status != 200:
if res.status == 401:
Expand Down
17 changes: 12 additions & 5 deletions script.module.urllib3/lib/urllib3/contrib/pyopenssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,10 @@
"""
from __future__ import absolute_import

import OpenSSL.crypto
import OpenSSL.SSL
from cryptography import x509
from cryptography.hazmat.backends.openssl import backend as openssl_backend
from cryptography.hazmat.backends.openssl.x509 import _Certificate

try:
from cryptography.x509 import UnsupportedExtension
Expand All @@ -73,11 +73,20 @@ class UnsupportedExtension(Exception):
import logging
import ssl
import sys
import warnings

from .. import util
from ..packages import six
from ..util.ssl_ import PROTOCOL_TLS_CLIENT

warnings.warn(
"'urllib3.contrib.pyopenssl' module is deprecated and will be removed "
"in a future release of urllib3 2.x. Read more in this issue: "
"https://github.com/urllib3/urllib3/issues/2680",
category=DeprecationWarning,
stacklevel=2,
)

__all__ = ["inject_into_urllib3", "extract_from_urllib3"]

# SNI always works.
Expand Down Expand Up @@ -219,9 +228,8 @@ def get_subj_alt_name(peer_cert):
if hasattr(peer_cert, "to_cryptography"):
cert = peer_cert.to_cryptography()
else:
# This is technically using private APIs, but should work across all
# relevant versions before PyOpenSSL got a proper API for this.
cert = _Certificate(openssl_backend, peer_cert._x509)
der = OpenSSL.crypto.dump_certificate(OpenSSL.crypto.FILETYPE_ASN1, peer_cert)
cert = x509.load_der_x509_certificate(der, openssl_backend)

# We want to find the SAN extension. Ask Cryptography to locate it (it's
# faster than looping in Python)
Expand Down Expand Up @@ -406,7 +414,6 @@ def makefile(self, mode, bufsize=-1):
self._makefile_refs += 1
return _fileobject(self, mode, bufsize, close=True)


else: # Platform-specific: Python 3
makefile = backport_makefile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -770,7 +770,6 @@ def makefile(self, mode, bufsize=-1):
self._makefile_refs += 1
return _fileobject(self, mode, bufsize, close=True)


else: # Platform-specific: Python 3

def makefile(self, mode="r", buffering=None, *args, **kwargs):
Expand Down
Loading

0 comments on commit 15931e6

Please sign in to comment.