From 02694bd3ad681ed49319b277b33eff15eb30bac6 Mon Sep 17 00:00:00 2001
From: Chris Dent <cdent@anticdent.org>
Date: Tue, 19 Mar 2024 20:44:40 +0000
Subject: [PATCH 3/6] play around with arg manipulation

---
 wsgi_intercept/__init__.py | 20 +++++++++++++++++---
 wsgi_intercept/_urllib3.py | 10 ++--------
 2 files changed, 19 insertions(+), 11 deletions(-)

Index: python-wsgi-intercept/wsgi_intercept/__init__.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/__init__.py
+++ python-wsgi-intercept/wsgi_intercept/__init__.py
@@ -526,6 +526,23 @@ class WSGI_HTTPConnection(HTTPConnection
     Intercept all traffic to certain hosts & redirect into a WSGI
     application object.
     """
+
+    def __init__(self, *args, **kwargs):
+        print(f"args1 is {args}, kwargs is {kwargs}")
+        if 'host' in kwargs:
+            host = kwargs.pop('host')
+            if 'port' in kwargs:
+                port = kwargs.pop('port')
+            else:
+                port = None
+            print(f"args2 is {args}, kwargs is {kwargs}")
+            super().__init__(host, port, *args, **kwargs)
+        else:
+            if len(args) > 2:
+                args = args[0:2]
+            super().__init__(*args, **kwargs)
+
+
     def get_app(self, host, port):
         """
         Return the app object for the given (host, port).
@@ -579,9 +596,6 @@ class WSGI_HTTPSConnection(HTTPSConnecti
     application object.
     """
 
-    def __init__(self, *args, **kwargs):
-        print("getting %s ::: %s" % (args, kwargs))
-        super().__init__(*args, **kwargs)
 
     def get_app(self, host, port):
         """
Index: python-wsgi-intercept/wsgi_intercept/_urllib3.py
===================================================================
--- python-wsgi-intercept.orig/wsgi_intercept/_urllib3.py
+++ python-wsgi-intercept/wsgi_intercept/_urllib3.py
@@ -32,7 +32,6 @@ def make_urllib3_override(HTTPConnection
                           HTTPConnection, HTTPSConnection):
 
     class HTTP_WSGIInterceptor(WSGI_HTTPConnection, HTTPConnection):
-        print(f"http pre: {args} ::: {kwargs}")
         def __init__(self, *args, **kwargs):
             for kw in HTTP_KEYWORD_POPS:
                 kwargs.pop(kw, None)
@@ -43,19 +42,14 @@ def make_urllib3_override(HTTPConnection
         is_verified = True
 
         def __init__(self, *args, **kwargs):
-            print(f"https pre: {args} ::: {kwargs}")
+            print(f"{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)
-            print(f"https post: {args} ::: {kwargs}")
-            host = kwargs.pop('host')
-            port = kwargs.pop('port')
-            WSGI_HTTPSConnection.__init__(self, host, port, *args, **kwargs)
-            print("after wsgi")
+            WSGI_HTTPSConnection.__init__(self, *args, **kwargs)
             HTTPSConnection.__init__(self, *args, **kwargs)
-            print("after https")
 
     def install():
         if 'http_proxy' in os.environ or 'https_proxy' in os.environ:
