Skip to content

Commit 4f46237

Browse files
SNOW-926289 updating vendored libraries (#1793)
* updating vendored requests to 2.31.0 * updating vendored urllib3 to 1.26.18 * putting back urllib3 pin * adding changelog entry --------- Co-authored-by: Sophie Tan <[email protected]>
1 parent 16931b5 commit 4f46237

File tree

14 files changed

+253
-24
lines changed

14 files changed

+253
-24
lines changed

DESCRIPTION.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ Source code is also available at: https://github.com/snowflakedb/snowflake-conne
99
# Release Notes
1010

1111

12+
- v3.4.1(TBD)
13+
14+
- Bumped vendored `urllib3` to 1.26.18
15+
- Bumped vendored `requests` to 2.31.0
16+
1217
- v3.4.0(November 03,2023)
1318

1419
- Added support for `use_logical_type` in `write_pandas`.

setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ install_requires =
5353
packaging
5454
charset_normalizer>=2,<4
5555
idna>=2.5,<4
56-
urllib3>=1.21.1,<1.27
56+
urllib3>=1.21.1,<2.0.0
5757
certifi>=2017.4.17
5858
typing_extensions>=4.3,<5
5959
filelock>=3.5,<4

src/snowflake/connector/vendored/requests/__init__.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def check_compatibility(urllib3_version, chardet_version, charset_normalizer_ver
6666
# Check urllib3 for compatibility.
6767
major, minor, patch = urllib3_version # noqa: F811
6868
major, minor, patch = int(major), int(minor), int(patch)
69-
# urllib3 >= 1.21.1, <= 1.26
70-
assert major == 1
71-
assert minor >= 21
72-
assert minor <= 26
69+
# urllib3 >= 1.21.1
70+
assert major >= 1
71+
if major == 1:
72+
assert minor >= 21
7373

7474
# Check charset_normalizer for compatibility.
7575
if chardet_version:

src/snowflake/connector/vendored/requests/__version__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
__title__ = "requests"
66
__description__ = "Python HTTP for Humans."
77
__url__ = "https://requests.readthedocs.io"
8-
__version__ = "2.29.0"
9-
__build__ = 0x022900
8+
__version__ = "2.31.0"
9+
__build__ = 0x023100
1010
__author__ = "Kenneth Reitz"
1111
__author_email__ = "[email protected]"
1212
__license__ = "Apache 2.0"

src/snowflake/connector/vendored/requests/adapters.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,6 @@ def init_poolmanager(
193193
num_pools=connections,
194194
maxsize=maxsize,
195195
block=block,
196-
strict=True,
197196
**pool_kwargs,
198197
)
199198

src/snowflake/connector/vendored/requests/sessions.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -324,7 +324,9 @@ def rebuild_proxies(self, prepared_request, proxies):
324324
except KeyError:
325325
username, password = None, None
326326

327-
if username and password:
327+
# urllib3 handles proxy authorization for us in the standard adapter.
328+
# Avoid appending this to TLS tunneled requests where it may be leaked.
329+
if not scheme.startswith('https') and username and password:
328330
headers["Proxy-Authorization"] = _basic_auth_str(username, password)
329331

330332
return new_proxies

src/snowflake/connector/vendored/urllib3/_collections.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,24 @@ def getlist(self, key, default=__marker):
268268
else:
269269
return vals[1:]
270270

271+
def _prepare_for_method_change(self):
272+
"""
273+
Remove content-specific header fields before changing the request
274+
method to GET or HEAD according to RFC 9110, Section 15.4.
275+
"""
276+
content_specific_headers = [
277+
"Content-Encoding",
278+
"Content-Language",
279+
"Content-Location",
280+
"Content-Type",
281+
"Content-Length",
282+
"Digest",
283+
"Last-Modified",
284+
]
285+
for header in content_specific_headers:
286+
self.discard(header)
287+
return self
288+
271289
# Backwards compatibility for httplib
272290
getheaders = getlist
273291
getallmatchingheaders = getlist
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
# This file is protected via CODEOWNERS
2-
__version__ = "1.26.15"
2+
__version__ = "1.26.18"

src/snowflake/connector/vendored/urllib3/connectionpool.py

Lines changed: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from socket import error as SocketError
1010
from socket import timeout as SocketTimeout
1111

12+
from ._collections import HTTPHeaderDict
1213
from .connection import (
1314
BaseSSLError,
1415
BrokenPipeError,
@@ -50,6 +51,13 @@
5051
from .util.url import _normalize_host as normalize_host
5152
from .util.url import get_host, parse_url
5253

54+
try: # Platform-specific: Python 3
55+
import weakref
56+
57+
weakref_finalize = weakref.finalize
58+
except AttributeError: # Platform-specific: Python 2
59+
from .packages.backports.weakref_finalize import weakref_finalize
60+
5361
xrange = six.moves.xrange
5462

5563
log = logging.getLogger(__name__)
@@ -220,6 +228,16 @@ def __init__(
220228
self.conn_kw["proxy"] = self.proxy
221229
self.conn_kw["proxy_config"] = self.proxy_config
222230

231+
# Do not pass 'self' as callback to 'finalize'.
232+
# Then the 'finalize' would keep an endless living (leak) to self.
233+
# By just passing a reference to the pool allows the garbage collector
234+
# to free self if nobody else has a reference to it.
235+
pool = self.pool
236+
237+
# Close all the HTTPConnections in the pool before the
238+
# HTTPConnectionPool object is garbage collected.
239+
weakref_finalize(self, _close_pool_connections, pool)
240+
223241
def _new_conn(self):
224242
"""
225243
Return a fresh :class:`HTTPConnection`.
@@ -489,14 +507,8 @@ def close(self):
489507
# Disable access to the pool
490508
old_pool, self.pool = self.pool, None
491509

492-
try:
493-
while True:
494-
conn = old_pool.get(block=False)
495-
if conn:
496-
conn.close()
497-
498-
except queue.Empty:
499-
pass # Done.
510+
# Close all the HTTPConnections in the pool.
511+
_close_pool_connections(old_pool)
500512

501513
def is_same_host(self, url):
502514
"""
@@ -832,7 +844,11 @@ def _is_ssl_error_message_from_http_proxy(ssl_error):
832844
redirect_location = redirect and response.get_redirect_location()
833845
if redirect_location:
834846
if response.status == 303:
847+
# Change the method according to RFC 9110, Section 15.4.4.
835848
method = "GET"
849+
# And lose the body not to transfer anything sensitive.
850+
body = None
851+
headers = HTTPHeaderDict(headers)._prepare_for_method_change()
836852

837853
try:
838854
retries = retries.increment(method, url, response=response, _pool=self)
@@ -1108,3 +1124,14 @@ def _normalize_host(host, scheme):
11081124
if host.startswith("[") and host.endswith("]"):
11091125
host = host[1:-1]
11101126
return host
1127+
1128+
1129+
def _close_pool_connections(pool):
1130+
"""Drains a queue of connections and closes each one."""
1131+
try:
1132+
while True:
1133+
conn = pool.get(block=False)
1134+
if conn:
1135+
conn.close()
1136+
except queue.Empty:
1137+
pass # Done.

src/snowflake/connector/vendored/urllib3/contrib/securetransport.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,8 @@
6464
import threading
6565
import weakref
6666

67-
import six
68-
6967
from .. import util
68+
from ..packages import six
7069
from ..util.ssl_ import PROTOCOL_TLS_CLIENT
7170
from ._securetransport.bindings import CoreFoundation, Security, SecurityConst
7271
from ._securetransport.low_level import (

0 commit comments

Comments
 (0)