33
44import urllib .parse
55import urllib .request
6- import simpleproxy as root
76import urlvalidator as uv
87from dataclasses import dataclass
98import html .parser
9+ import debug
10+ from typing import TYPE_CHECKING
11+
12+ if TYPE_CHECKING :
13+ from simpleproxy import ProxyHandler
14+
1015
1116
1217@dataclass (frozen = True )
@@ -21,7 +26,7 @@ class UrlReqResp:
2126 contentData : str = ""
2227
2328
24- def handle_urlreq (ph : root . ProxyHandler , pr : urllib .parse .ParseResult , tag : str ):
29+ def handle_urlreq (ph : ' ProxyHandler' , pr : urllib .parse .ParseResult , tag : str ):
2530 """
2631 Common part of the url request handling used by both urlraw and urltext.
2732
@@ -58,13 +63,13 @@ def handle_urlreq(ph: root.ProxyHandler, pr: urllib.parse.ParseResult, tag: str)
5863 contentData = response .read ().decode ('utf-8' )
5964 statusCode = response .status or 200
6065 contentType = response .getheader ('Content-Type' ) or 'text/html'
61- root . debug_dump ({ 'url' : req .full_url , 'headers' : req .headers , 'ctype' : contentType }, { 'cdata' : contentData })
66+ debug . dump ({ 'url' : req .full_url , 'headers' : req .headers , 'ctype' : contentType }, { 'cdata' : contentData })
6267 return UrlReqResp (True , statusCode , "" , contentType , contentData )
6368 except Exception as exc :
6469 return UrlReqResp (False , 502 , f"WARN:{ tag } :Failed:{ exc } " )
6570
6671
67- def handle_urlraw (ph : root . ProxyHandler , pr : urllib .parse .ParseResult ):
72+ def handle_urlraw (ph : ' ProxyHandler' , pr : urllib .parse .ParseResult ):
6873 try :
6974 # Get requested url
7075 got = handle_urlreq (ph , pr , "HandleUrlRaw" )
@@ -159,7 +164,7 @@ def get_stripped_text(self):
159164 return self .textStripped
160165
161166
162- def handle_urltext (ph : root . ProxyHandler , pr : urllib .parse .ParseResult ):
167+ def handle_urltext (ph : ' ProxyHandler' , pr : urllib .parse .ParseResult ):
163168 try :
164169 # Get requested url
165170 got = handle_urlreq (ph , pr , "HandleUrlText" )
@@ -176,6 +181,6 @@ def handle_urltext(ph: root.ProxyHandler, pr: urllib.parse.ParseResult):
176181 ph .send_header ('Access-Control-Allow-Origin' , '*' )
177182 ph .end_headers ()
178183 ph .wfile .write (textHtml .get_stripped_text ().encode ('utf-8' ))
179- root . debug_dump ({ 'RawText' : 'yes' , 'StrippedText' : 'yes' }, { 'RawText' : textHtml .text , 'StrippedText' : textHtml .get_stripped_text () })
184+ debug . dump ({ 'RawText' : 'yes' , 'StrippedText' : 'yes' }, { 'RawText' : textHtml .text , 'StrippedText' : textHtml .get_stripped_text () })
180185 except Exception as exc :
181186 ph .send_error (502 , f"WARN:UrlTextFailed:{ exc } " )
0 commit comments