MCPcopy Index your code
hub / github.com/python/cpython / proxy_open

Method proxy_open

Lib/urllib/request.py:777–803  ·  view source on GitHub ↗
(self, req, proxy, type)

Source from the content-addressed store, hash-verified

775 meth(r, proxy, type))
776
777 def proxy_open(self, req, proxy, type):
778 orig_type = req.type
779 proxy_type, user, password, hostport = _parse_proxy(proxy)
780 if proxy_type is None:
781 proxy_type = orig_type
782
783 if req.host and proxy_bypass(req.host):
784 return None
785
786 if user and password:
787 user_pass = '%s:%s' % (unquote(user),
788 unquote(password))
789 creds = base64.b64encode(user_pass.encode()).decode("ascii")
790 req.add_header('Proxy-authorization', 'Basic ' + creds)
791 hostport = unquote(hostport)
792 req.set_proxy(hostport, proxy_type)
793 if orig_type == proxy_type or orig_type == 'https':
794 # let other handlers take care of it
795 return None
796 else:
797 # need to start over, because the other handlers don't
798 # grok the proxy's URL type
799 # e.g. if we have a constructor arg proxies like so:
800 # {'http': 'ftp://proxy.example.com'}, we may end up turning
801 # a request for http://acme.example.com/a into one for
802 # ftp://proxy.example.com/a
803 return self.parent.open(req, timeout=req.timeout)
804
805class HTTPPasswordMgr:
806

Callers

nothing calls this directly

Calls 8

unquoteFunction · 0.90
_parse_proxyFunction · 0.85
proxy_bypassFunction · 0.85
set_proxyMethod · 0.80
decodeMethod · 0.45
encodeMethod · 0.45
add_headerMethod · 0.45
openMethod · 0.45

Tested by

no test coverage detected