File: support-urllib3-2.x_1.patch

package info (click to toggle)
python-wsgi-intercept 1.13.1-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 560 kB
  • sloc: python: 1,390; makefile: 57; sh: 5
file content (255 lines) | stat: -rw-r--r-- 9,578 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
From 005c8596cb94d2444fafc3be8b6f233ccda75ab4 Mon Sep 17 00:00:00 2001
From: Chris Dent <cdent@anticdent.org>
Date: Sat, 16 Mar 2024 16:29:27 +0000
Subject: [PATCH 1/6] get rid of six and python 2

---
 README.rst                                    | 18 ++++------
 setup.py                                      |  8 ++---
 tox.ini                                       |  4 +--
 wsgi_intercept/__init__.py                    | 27 +++++----------
 wsgi_intercept/_urllib3.py                    | 33 ++++++++++++++-----
 wsgi_intercept/interceptor.py                 |  2 +-
 wsgi_intercept/tests/test_interceptor.py      | 10 ++----
 wsgi_intercept/tests/test_response_headers.py |  6 +---
 wsgi_intercept/urllib3_intercept.py           |  3 --
 9 files changed, 48 insertions(+), 63 deletions(-)

Index: python-wsgi-intercept/setup.py
===================================================================
--- python-wsgi-intercept.orig/setup.py
+++ python-wsgi-intercept/setup.py
@@ -8,8 +8,6 @@ Environment :: Web Environment
 Intended Audience :: Developers
 License :: OSI Approved :: MIT License
 Operating System :: OS Independent
-Programming Language :: Python :: 2
-Programming Language :: Python :: 2.7
 Programming Language :: Python :: 3
 Programming Language :: Python :: 3.7
 Programming Language :: Python :: 3.8
@@ -36,15 +34,13 @@ META = {
     'license': 'MIT License',
     'classifiers': CLASSIFIERS,
     'packages': find_packages(),
-    'install_requires': [
-        'six',
-    ],
+    'python_requires': '>=3',
     'extras_require': {
         'testing': [
             'pytest>=2.4',
             'httplib2',
             'requests>=2.0.1',
-            'urllib3>=1.11.0,<2.0.0',
+            'urllib3<2.0.0',
         ],
         'docs': [
             'sphinx',
Index: python-wsgi-intercept/tox.ini
===================================================================
--- python-wsgi-intercept.orig/tox.ini
+++ python-wsgi-intercept/tox.ini
@@ -1,11 +1,11 @@
 [tox]
 minversion = 1.6
 skipsdist = True
-envlist = py27,py35,py36,py37,py38,py39,py310,py311,py312,pypy,pep8,docs,readme
+envlist = py37,py38,py39,py310,py311,py312,pypy,pep8,docs,readme
 
 [testenv]
 deps = .[testing]
-commands = py.test --tb=short wsgi_intercept/tests
+commands = py.test --tb=short wsgi_intercept/tests {posargs}
 passenv = WSGI_INTERCEPT_*
 
 [testenv:pep8]
Index: python-wsgi-intercept/wsgi_intercept/__init__.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/__init__.py
+++ python-wsgi-intercept/wsgi_intercept/__init__.py
@@ -144,15 +144,9 @@ import sys
 import traceback
 from io import BytesIO
 
-# Don't use six here because it is unquote_to_bytes that we want in
-# Python 3.
-try:
-    from urllib.parse import unquote_to_bytes as url_unquote
-except ImportError:
-    from urllib import unquote as url_unquote
+from urllib.parse import unquote_to_bytes as url_unquote
 
-import six
-from six.moves.http_client import HTTPConnection, HTTPSConnection
+from http.client import HTTPConnection, HTTPSConnection
 
 
 # Set this to True to cause response headers from the intercepted
@@ -227,8 +221,7 @@ def make_environ(inp, host, port, script
     environ = {}
 
     method_line = inp.readline()
-    if six.PY3:
-        method_line = method_line.decode('ISO-8859-1')
+    method_line = method_line.decode('ISO-8859-1')
 
     content_type = None
     content_length = None
@@ -302,13 +295,11 @@ def make_environ(inp, host, port, script
     # fill out our dictionary.
     #
 
-    # In Python3 turn the bytes of the path info into a string of
-    # latin-1 code points, because that's what the spec says we must
-    # do to be like a server. Later various libraries will be forced
-    # to decode and then reencode to get the UTF-8 that everyone
-    # wants.
-    if six.PY3:
-        path_info = path_info.decode('latin-1')
+    # Turn the bytes of the path info into a string of latin-1 code points,
+    # because that's what the spec says we must do to be like a server. Later
+    # various libraries will be forced to decode and then reencode to get the
+    # UTF-8 that everyone wants.
+    path_info = path_info.decode('latin-1')
 
     environ.update({
         "wsgi.version": (1, 0),
@@ -633,7 +624,7 @@ class WSGI_HTTPSConnection(HTTPSConnecti
                             else:
                                 self._context.verify_mode = ssl.VerifyMode[
                                     self.cert_reqs]
-                        elif isinstance(self.cert_reqs, six.string_types):
+                        elif isinstance(self.cert_reqs, str):
                             # Support for Python3.5 and below
                             self._context.verify_mode = getattr(ssl,
                                     self.cert_reqs,
Index: python-wsgi-intercept/wsgi_intercept/_urllib3.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/_urllib3.py
+++ python-wsgi-intercept/wsgi_intercept/_urllib3.py
@@ -8,16 +8,33 @@ from . import WSGI_HTTPConnection, WSGI_
 
 wsgi_fake_socket.settimeout = lambda self, timeout: None
 
+HTTP_KEYWORD_POPS = [
+    'strict',
+    'socket_options',
+    'server_hostname',
+]
+
+HTTPS_KEYWORD_POPS = HTTP_KEYWORD_POPS + [
+    'key_password',
+    'server_hostname',
+    'cert_reqs',
+    'ca_certs',
+    'ca_cert_dir',
+    'assert_hostname',
+    'assert_fingerprint',
+    'ssl_version',
+    'ssl_minimum_version',
+    'ssl_maximum_version',
+]
+
 
 def make_urllib3_override(HTTPConnectionPool, HTTPSConnectionPool,
                           HTTPConnection, HTTPSConnection):
 
     class HTTP_WSGIInterceptor(WSGI_HTTPConnection, HTTPConnection):
         def __init__(self, *args, **kwargs):
-            if 'strict' in kwargs and sys.version_info > (3, 0):
-                kwargs.pop('strict')
-            kwargs.pop('socket_options', None)
-            kwargs.pop('server_hostname', None)
+            for kw in HTTP_KEYWORD_POPS:
+                kwargs.pop(kw, None)
             WSGI_HTTPConnection.__init__(self, *args, **kwargs)
             HTTPConnection.__init__(self, *args, **kwargs)
 
@@ -25,12 +42,9 @@ def make_urllib3_override(HTTPConnection
         is_verified = True
 
         def __init__(self, *args, **kwargs):
-            if 'strict' in kwargs and sys.version_info > (3, 0):
-                kwargs.pop('strict')
-            kwargs.pop('socket_options', None)
-            kwargs.pop('key_password', None)
-            kwargs.pop('server_hostname', None)
-            kwargs.pop('ssl_context', None)
+            print(f"pre: {args} ::: {kwargs}")
+            for kw in HTTPS_KEYWORD_POPS:
+                kwargs.pop(kw, None)
             if sys.version_info > (3, 12):
                 kwargs.pop('key_file', None)
                 kwargs.pop('cert_file', None)
Index: python-wsgi-intercept/wsgi_intercept/interceptor.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/interceptor.py
+++ python-wsgi-intercept/wsgi_intercept/interceptor.py
@@ -4,7 +4,7 @@
 from importlib import import_module
 from uuid import uuid4
 
-from six.moves.urllib import parse as urlparse
+from urllib import parse as urlparse
 
 import wsgi_intercept
 
Index: python-wsgi-intercept/wsgi_intercept/tests/test_interceptor.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/tests/test_interceptor.py
+++ python-wsgi-intercept/wsgi_intercept/tests/test_interceptor.py
@@ -11,13 +11,9 @@ import pytest
 import requests
 import urllib3
 from httplib2 import Http, ServerNotFoundError
-# don't use six as the monkey patching gets confused
-try:
-    import http.client as http_client
-except ImportError:
-    import httplib as http_client
-from six.moves.urllib.request import urlopen
-from six.moves.urllib.error import URLError
+import http.client as http_client
+from urllib.request import urlopen
+from urllib.error import URLError
 
 from wsgi_intercept.interceptor import (
     Interceptor, HttpClientInterceptor, Httplib2Interceptor,
Index: python-wsgi-intercept/wsgi_intercept/tests/test_response_headers.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/tests/test_response_headers.py
+++ python-wsgi-intercept/wsgi_intercept/tests/test_response_headers.py
@@ -10,7 +10,6 @@ not the other way round. Let's write som
 
 import pytest
 import requests
-import six
 
 import wsgi_intercept
 from wsgi_intercept.interceptor import RequestsInterceptor
@@ -56,10 +55,7 @@ def test_header_app():
 def test_encoding_violation():
     """If the header is unicode we expect boom."""
     header_key = 'request-id'
-    if six.PY2:
-        header_value = u'alpha'
-    else:
-        header_value = b'alpha'
+    header_value = b'alpha'
     # we expect our http library to give us a str
     returned_header = 'alpha'
 
Index: python-wsgi-intercept/wsgi_intercept/urllib3_intercept.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/urllib3_intercept.py
+++ python-wsgi-intercept/wsgi_intercept/urllib3_intercept.py
@@ -1,8 +1,5 @@
 """Intercept HTTP connections that use
 `urllib3 <https://urllib3.readthedocs.org/>`_.
-
-Note that currently only urllib3 <2.0.0 is supported. 2.0.0 support
-is in progress.
 """
 
 from urllib3.connectionpool import HTTPConnectionPool, HTTPSConnectionPool