From 02694bd3ad681ed49319b277b33eff15eb30bac6 Mon Sep 17 00:00:00 2001 From: Chris Dent Date: Tue, 19 Mar 2024 20:44:40 +0000 Subject: [PATCH] play around with arg manipulation --- wsgi_intercept/__init__.py | 20 +++++++++++++++++--- wsgi_intercept/_urllib3.py | 10 ++-------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/wsgi_intercept/__init__.py b/wsgi_intercept/__init__.py index 3009115..8042205 100644 --- a/wsgi_intercept/__init__.py +++ b/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(HTTPSConnection, WSGI_HTTPConnection): application object. """ - def __init__(self, *args, **kwargs): - print("getting %s ::: %s" % (args, kwargs)) - super().__init__(*args, **kwargs) def get_app(self, host, port): """ diff --git a/wsgi_intercept/_urllib3.py b/wsgi_intercept/_urllib3.py index a7889ae..9b05cf4 100644 --- a/wsgi_intercept/_urllib3.py +++ b/wsgi_intercept/_urllib3.py @@ -32,7 +32,6 @@ def make_urllib3_override(HTTPConnectionPool, HTTPSConnectionPool, class HTTP_WSGIInterceptor(WSGI_HTTPConnection, HTTPConnection): def __init__(self, *args, **kwargs): - print(f"http pre: {args} ::: {kwargs}") for kw in HTTP_KEYWORD_POPS: kwargs.pop(kw, None) WSGI_HTTPConnection.__init__(self, *args, **kwargs) @@ -42,19 +41,14 @@ class HTTPS_WSGIInterceptor(WSGI_HTTPSConnection, HTTPSConnection): 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: