我们从Python开源项目中,提取了以下47个代码示例,用于说明如何使用urllib.parse.SplitResult()。
def urlparts(self): """ The :attr:`url` string as an :class:`urlparse.SplitResult` tuple. The tuple contains (scheme, host, path, query_string and fragment), but the fragment is always empty because it is not visible to the server. """ env = self.environ http = env.get('HTTP_X_FORWARDED_PROTO') \ or env.get('wsgi.url_scheme', 'http') host = env.get('HTTP_X_FORWARDED_HOST') or env.get('HTTP_HOST') if not host: # HTTP 1.1 requires a Host-header. This is for HTTP/1.0 clients. host = env.get('SERVER_NAME', '127.0.0.1') port = env.get('SERVER_PORT') if port and port != ('80' if http == 'http' else '443'): host += ':' + port path = urlquote(self.fullpath) return UrlSplitResult(http, host, path, env.get('QUERY_STRING'), '')
def urlparts(self): ''' The :attr:`url` string as an :class:`urlparse.SplitResult` tuple. The tuple contains (scheme, host, path, query_string and fragment), but the fragment is always empty because it is not visible to the server. ''' env = self.environ http = env.get('HTTP_X_FORWARDED_PROTO') or env.get('wsgi.url_scheme', 'http') host = env.get('HTTP_X_FORWARDED_HOST') or env.get('HTTP_HOST') if not host: # HTTP 1.1 requires a Host-header. This is for HTTP/1.0 clients. host = env.get('SERVER_NAME', '127.0.0.1') port = env.get('SERVER_PORT') if port and port != ('80' if http == 'http' else '443'): host += ':' + port path = urlquote(self.fullpath) return UrlSplitResult(http, host, path, env.get('QUERY_STRING'), '')
def urlparts(self): """ The :attr:`url` string as an :class:`urlparse.SplitResult` tuple. The tuple contains (scheme, host, path, query_string and fragment), but the fragment is always empty because it is not visible to the server. """ env = self.environ http = env.get('HTTP_X_FORWARDED_PROTO') or env.get('wsgi.url_scheme', 'http') host = env.get('HTTP_X_FORWARDED_HOST') or env.get('HTTP_HOST') if not host: # HTTP 1.1 requires a Host-header. This is for HTTP/1.0 clients. host = env.get('SERVER_NAME', '127.0.0.1') port = env.get('SERVER_PORT') if port and port != ('80' if http == 'http' else '443'): host += ':' + port path = urlquote(self.fullpath) return UrlSplitResult(http, host, path, env.get('QUERY_STRING'), '')
def _urlsplit(data): """ Args: data (str|tuple) Returns: parse.SplitResult: ??????? """ if utils.like_list(data): assert len(data) == 5 # noinspection PyArgumentList return parse.SplitResult(*data) elif isinstance(data, six.string_types): data = utils.ensure_unicode(data) return parse.urlsplit(data) elif isinstance(data, Url): return data.split() else: raise TypeError("unknown type: {}, need str or tuple".format(type(data)))
def test_split_result_non_decoded(): with pytest.raises(ValueError): URL(SplitResult('http', 'example.com', 'path', 'qs', 'frag'))
def __init__(self, status_code: int, response: Any): self.headers: dict = None self.body: str = None self.path: str = None self.params: dict = None @urlmatch(netloc=mock_uri, path='^/kb/.*/graql$', method='POST') def grakn_mock(url: SplitResult, request: PreparedRequest): self.headers = request.headers self.body = request.body self.path = url.path self.params = parse_qs(url.query) return httmock.response(status_code, json.dumps(response)) self._httmock: HTTMock = HTTMock(grakn_mock)
def resolve_adapter(uri): # type: (AdapterSpec) -> BaseAdapter """ Given a URI, returns a properly-configured adapter instance. """ if isinstance(uri, BaseAdapter): return uri parsed = compat.urllib_parse.urlsplit(uri) # type: SplitResult if not parsed.scheme: raise with_context( exc = InvalidUri( 'URI must begin with "<protocol>://" (e.g., "udp://").', ), context = { 'parsed': parsed, 'uri': uri, }, ) try: adapter_type = adapter_registry[parsed.scheme] except KeyError: raise with_context( exc = InvalidUri('Unrecognized protocol {protocol!r}.'.format( protocol = parsed.scheme, )), context = { 'parsed': parsed, 'uri': uri, }, ) return adapter_type.configure(parsed)
def configure(cls, parsed): # type: (Union[Text, SplitResult]) -> HttpAdapter """ Creates a new instance using the specified URI. :param parsed: Result of :py:func:`urllib.parse.urlsplit`. """ return cls(parsed)
def __init__(self): self.splitted = SplitResult("", "", "", "", "") self.query = list()
def split(self): # noinspection PyArgumentList return parse.SplitResult(self.scheme, self.netloc, self.path, self.query_string, self.fragment)
def construct_stock_request(self, **kwargs): if not self.request_buffer["path"].endswith(".js"): self.request_buffer["path"] += ".js" return {"url": urlunsplit(SplitResult(**self.request_buffer)), "method": "GET", "params": urlencode(kwargs)}
def construct_trade_request(self, **kwargs): query_args = {**kwargs, "method": basename(self.request_buffer["path"])} extra = query_args.pop("extra", {}) query_args.setdefault("created", int(time())) query_args["sign"] = self.sign(**query_args) query_args.update(extra) return {"url": urlunsplit(SplitResult(**self.request_buffer)), "method": "POST", "params": urlencode(query_args)}
def __init__(self, url): if isinstance(url, ParseResult) or isinstance(url, SplitResult): self.url_parsed = url self.url_raw = None else: self.url_raw = url self.url_parsed = None
def __init__(self, uri): # type: (Union[Text, SplitResult]) -> None super(HttpAdapter, self).__init__() if isinstance(uri, text_type): uri = compat.urllib_parse.urlsplit(uri) # type: SplitResult if uri.scheme not in self.supported_protocols: raise with_context( exc = InvalidUri('Unsupported protocol {protocol!r}.'.format( protocol = uri.scheme, )), context = { 'uri': uri, }, ) if not uri.hostname: raise with_context( exc = InvalidUri( 'Empty hostname in URI {uri!r}.'.format( uri = uri.geturl(), ), ), context = { 'uri': uri, }, ) try: # noinspection PyStatementEffect uri.port except ValueError: raise with_context( exc = InvalidUri( 'Non-numeric port in URI {uri!r}.'.format( uri = uri.geturl(), ), ), context = { 'uri': uri, }, ) self.uri = uri