Return (scheme, user, password, host/port) given a URL or an authority. If a URL is supplied, it must have an authority (host:port) component. According to RFC 3986, having an authority component means the URL must have two slashes after the scheme.
(proxy)
| 756 | |
| 757 | |
| 758 | def _parse_proxy(proxy): |
| 759 | """Return (scheme, user, password, host/port) given a URL or an authority. |
| 760 | |
| 761 | If a URL is supplied, it must have an authority (host:port) component. |
| 762 | According to RFC 3986, having an authority component means the URL must |
| 763 | have two slashes after the scheme. |
| 764 | """ |
| 765 | scheme, r_scheme = _splittype(proxy) |
| 766 | if not r_scheme.startswith("/"): |
| 767 | # authority |
| 768 | scheme = None |
| 769 | authority = proxy |
| 770 | else: |
| 771 | # URL |
| 772 | if not r_scheme.startswith("//"): |
| 773 | raise ValueError("proxy URL with no authority: %r" % proxy) |
| 774 | # We have an authority, so for RFC 3986-compliant URLs (by ss 3. |
| 775 | # and 3.3.), path is empty or starts with '/' |
| 776 | if '@' in r_scheme: |
| 777 | host_separator = r_scheme.find('@') |
| 778 | end = r_scheme.find("/", host_separator) |
| 779 | else: |
| 780 | end = r_scheme.find("/", 2) |
| 781 | if end == -1: |
| 782 | end = None |
| 783 | authority = r_scheme[2:end] |
| 784 | userinfo, hostport = _splituser(authority) |
| 785 | if userinfo is not None: |
| 786 | user, password = _splitpasswd(userinfo) |
| 787 | else: |
| 788 | user = password = None |
| 789 | return scheme, user, password, hostport |
| 790 | |
| 791 | class ProxyHandler(BaseHandler): |
| 792 | # Proxies must be in front |
no test coverage detected