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
|
From dd4107f9f036a283337853c832f03f6a761e551e Mon Sep 17 00:00:00 2001
From: Chris Dent <cdent@anticdent.org>
Date: Wed, 20 Mar 2024 21:59:39 +0000
Subject: [PATCH 5/6] pep8 and readme fixes
---
README.rst | 7 ++++---
wsgi_intercept/__init__.py | 21 +++++++-------------
wsgi_intercept/_urllib3.py | 1 +
wsgi_intercept/http_client_intercept.py | 19 +++++-------------
wsgi_intercept/tests/test_http_client.py | 5 +----
wsgi_intercept/tests/test_urllib.py | 5 +----
wsgi_intercept/tests/test_urllib3.py | 2 +-
wsgi_intercept/tests/test_wsgi_compliance.py | 5 +----
wsgi_intercept/tests/wsgi_app.py | 5 -----
wsgi_intercept/urllib_intercept.py | 5 +----
10 files changed, 22 insertions(+), 53 deletions(-)
Index: python-wsgi-intercept/wsgi_intercept/__init__.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/__init__.py
+++ python-wsgi-intercept/wsgi_intercept/__init__.py
@@ -13,8 +13,8 @@ threads to test your Web app.
Supported Libaries
==================
-``wsgi_intercept`` works with a variety of HTTP clients in Python 2.7,
-3.7 and beyond, and in pypy.
+``wsgi_intercept`` works with a variety of HTTP clients in Python 3.7
+and beyond, and in pypy.
* urllib2
* urllib.request
@@ -22,7 +22,7 @@ Supported Libaries
* http.client
* httplib2
* requests
-* urllib3 (<2.0.0, urllib3 2 support is in progress)
+* urllib3
How Does It Work?
=================
@@ -88,14 +88,9 @@ Packages Intercepted
Unfortunately each of the HTTP client libraries use their own specific
mechanism for making HTTP call-outs, so individual implementations are
needed. At this time there are implementations for ``httplib2``,
-``urllib3`` (<2.0.0) and ``requests`` in both Python 2 and 3, ``urllib2`` and
-``httplib`` in Python 2 and ``urllib.request`` and ``http.client``
+``urllib3``, ``requests``, ``urllib.request`` and ``http.client``
in Python 3.
-If you are using Python 2 and need support for a different HTTP
-client, require a version of ``wsgi_intercept<0.6``. Earlier versions
-include support for ``webtest``, ``webunit`` and ``zope.testbrowser``.
-
The best way to figure out how to use interception is to inspect
`the tests`_. More comprehensive documentation available upon
request.
@@ -115,9 +110,9 @@ it into all of the *other* Python Web te
The Python 2 version of wsgi-intercept was the result. Kumar McMillan
later took over maintenance.
-The current version is tested with Python 2.7, 3.5-3.11, and pypy and pypy3.
-It was assembled by `Chris Dent`_. Testing and documentation improvements
-from `Sasha Hart`_.
+The current version is tested with Python 3.7-3.12, and pypy3. It was
+assembled by `Chris Dent`_. Testing and documentation improvements from
+`Sasha Hart`_.
.. _"best Web testing framework":
http://blog.ianbicking.org/best-of-the-web-app-test-frameworks.html
@@ -546,7 +541,6 @@ class WSGI_HTTPConnection(HTTPConnection
args = args[0:2]
super().__init__(*args, **kwargs)
-
def get_app(self, host, port):
"""
Return the app object for the given (host, port).
@@ -600,7 +594,6 @@ class WSGI_HTTPSConnection(HTTPSConnecti
application object.
"""
-
def get_app(self, host, port):
"""
Return the app object for the given (host, port).
Index: python-wsgi-intercept/wsgi_intercept/http_client_intercept.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/http_client_intercept.py
+++ python-wsgi-intercept/wsgi_intercept/http_client_intercept.py
@@ -1,23 +1,14 @@
"""Intercept HTTP connections that use httplib (Py2) or http.client (Py3).
"""
-try:
- import http.client as http_lib
-except ImportError:
- import httplib as http_lib
+import http.client as http_lib
from . import WSGI_HTTPConnection, WSGI_HTTPSConnection
-try:
- from http.client import (
- HTTPConnection as OriginalHTTPConnection,
- HTTPSConnection as OriginalHTTPSConnection
- )
-except ImportError:
- from httplib import (
- HTTPConnection as OriginalHTTPConnection,
- HTTPSConnection as OriginalHTTPSConnection
- )
+from http.client import (
+ HTTPConnection as OriginalHTTPConnection,
+ HTTPSConnection as OriginalHTTPSConnection
+)
class HTTP_WSGIInterceptor(WSGI_HTTPConnection, http_lib.HTTPConnection):
Index: python-wsgi-intercept/wsgi_intercept/tests/test_http_client.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/tests/test_http_client.py
+++ python-wsgi-intercept/wsgi_intercept/tests/test_http_client.py
@@ -2,10 +2,7 @@ import pytest
from wsgi_intercept import http_client_intercept, WSGIAppError
from . import wsgi_app
from .install import installer_class, skipnetwork
-try:
- import http.client as http_lib
-except ImportError:
- import httplib as http_lib
+import http.client as http_lib
HOST = 'some_hopefully_nonexistant_domain'
Index: python-wsgi-intercept/wsgi_intercept/tests/test_urllib.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/tests/test_urllib.py
+++ python-wsgi-intercept/wsgi_intercept/tests/test_urllib.py
@@ -3,10 +3,7 @@ import pytest
from wsgi_intercept import urllib_intercept, WSGIAppError
from . import wsgi_app
from .install import installer_class, skipnetwork
-try:
- import urllib.request as url_lib
-except ImportError:
- import urllib2 as url_lib
+import urllib.request as url_lib
HOST = 'some_hopefully_nonexistant_domain'
Index: python-wsgi-intercept/wsgi_intercept/tests/test_urllib3.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/tests/test_urllib3.py
+++ python-wsgi-intercept/wsgi_intercept/tests/test_urllib3.py
@@ -54,7 +54,7 @@ def test_proxy_handling():
del os.environ['http_proxy']
-def test_https_meo():
+def test_https():
with InstalledApp(wsgi_app.simple_app, host=HOST, port=443) as app:
resp = http.request(
'GET', 'https://some_hopefully_nonexistant_domain:443/')
Index: python-wsgi-intercept/wsgi_intercept/tests/test_wsgi_compliance.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/tests/test_wsgi_compliance.py
+++ python-wsgi-intercept/wsgi_intercept/tests/test_wsgi_compliance.py
@@ -1,9 +1,6 @@
import sys
import pytest
-try:
- from urllib.parse import unquote
-except ImportError:
- from urllib import unquote
+from urllib.parse import unquote
from wsgi_intercept import httplib2_intercept
from . import wsgi_app
from .install import installer_class
Index: python-wsgi-intercept/wsgi_intercept/tests/wsgi_app.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/tests/wsgi_app.py
+++ python-wsgi-intercept/wsgi_intercept/tests/wsgi_app.py
@@ -4,11 +4,6 @@ Simple WSGI applications for testing.
from pprint import pformat
-try:
- bytes
-except ImportError:
- bytes = str
-
def simple_app(environ, start_response):
"""Simplest possible application object"""
Index: python-wsgi-intercept/wsgi_intercept/urllib_intercept.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/urllib_intercept.py
+++ python-wsgi-intercept/wsgi_intercept/urllib_intercept.py
@@ -4,10 +4,7 @@ aka urllib2 (Python 2).
import os
-try:
- import urllib.request as url_lib
-except ImportError:
- import urllib2 as url_lib
+import urllib.request as url_lib
from . import WSGI_HTTPConnection, WSGI_HTTPSConnection
|