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
 
