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)
| 727 | |
| 728 | |
| 729 | def _parse_proxy(proxy): |
| 730 | """Return (scheme, user, password, host/port) given a URL or an authority. |
| 731 | |
| 732 | If a URL is supplied, it must have an authority (host:port) component. |
| 733 | According to RFC 3986, having an authority component means the URL must |
| 734 | have two slashes after the scheme. |
| 735 | """ |
| 736 | scheme, r_scheme = _splittype(proxy) |
| 737 | if not r_scheme.startswith("/"): |
| 738 | # authority |
| 739 | scheme = None |
| 740 | authority = proxy |
| 741 | else: |
| 742 | # URL |
| 743 | if not r_scheme.startswith("//"): |
| 744 | raise ValueError("proxy URL with no authority: %r" % proxy) |
| 745 | # We have an authority, so for RFC 3986-compliant URLs (by ss 3. |
| 746 | # and 3.3.), path is empty or starts with '/' |
| 747 | if '@' in r_scheme: |
| 748 | host_separator = r_scheme.find('@') |
| 749 | end = r_scheme.find("/", host_separator) |
| 750 | else: |
| 751 | end = r_scheme.find("/", 2) |
| 752 | if end == -1: |
| 753 | end = None |
| 754 | authority = r_scheme[2:end] |
| 755 | userinfo, hostport = _splituser(authority) |
| 756 | if userinfo is not None: |
| 757 | user, password = _splitpasswd(userinfo) |
| 758 | else: |
| 759 | user = password = None |
| 760 | return scheme, user, password, hostport |
| 761 | |
| 762 | class ProxyHandler(BaseHandler): |
| 763 | # Proxies must be in front |
searching dependent graphs…