本文整理匯總了Python中urllib.parse.SplitResult方法的典型用法代碼示例。如果您正苦於以下問題:Python parse.SplitResult方法的具體用法?Python parse.SplitResult怎麽用?Python parse.SplitResult使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類urllib.parse
的用法示例。
在下文中一共展示了parse.SplitResult方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: urlparts
# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import SplitResult [as 別名]
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'), '')
示例2: delete
# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import SplitResult [as 別名]
def delete(url):
url = unquote(url)
match, project = Cache.match(url)
if match:
path = Cache.path(url, project, include_file=True)
# Rather then wait for last updated statistics to expire, remove the
# project cache if applicable.
if project:
apiurl, _ = Cache.spliturl(url)
if project.isdigit():
# Clear target project cache upon request acceptance.
project = osc.core.get_request(apiurl, project).actions[0].tgt_project
Cache.delete_project(apiurl, project)
if os.path.exists(path):
if conf.config['debug']: print('CACHE_DELETE', url, file=sys.stderr)
os.remove(path)
# Also delete version without query. This does not handle other
# variations using different query strings. Handy for PUT with ?force=1.
o = urlsplit(url)
if o.query != '':
url_plain = SplitResult(o.scheme, o.netloc, o.path, '', o.fragment).geturl()
Cache.delete(url_plain)
示例3: urlparts
# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import SplitResult [as 別名]
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'), '')
示例4: build_url_for_request
# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import SplitResult [as 別名]
def build_url_for_request(request=None, path="", query=None, fragment=""):
""" Builds a url from the base url relevant for the current request context
:request: An instance of django.http.HTTPRequest
:path: A str indicating the path
:query: A dictionary with any GET parameters
:fragment: A string indicating the fragment
:return: An instance of urllib.parse.SplitResult
"""
if request is None:
request = get_current_request()
return build_url(
netloc=request.get_host(),
scheme=request.scheme,
path=path,
query=query,
fragment=fragment,
)
示例5: urlparts
# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import SplitResult [as 別名]
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'), '')
示例6: fetch_api_description
# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import SplitResult [as 別名]
def fetch_api_description(
url: typing.Union[str, ParseResult, SplitResult], insecure: bool = False
):
"""Fetch the API description from the remote MAAS instance."""
url_describe = urljoin(_ensure_url_string(url), "describe/")
connector = aiohttp.TCPConnector(verify_ssl=(not insecure))
session = aiohttp.ClientSession(connector=connector)
async with session, session.get(url_describe) as response:
if response.status != HTTPStatus.OK:
raise RemoteError("{0} -> {1.status} {1.reason}".format(url, response))
elif response.content_type != "application/json":
raise RemoteError(
"Expected application/json, got: %s" % response.content_type
)
else:
return await response.json()
示例7: __init__
# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import SplitResult [as 別名]
def __init__(self, url: parse.SplitResult, location_type=None,
container_subvolume_relpath: str = None):
"""
c'tor
:param url: Location URL
"""
super().__init__(url)
self.__location_type = None
self.__uuid = None
self.__container_subvolume_relpath = None
self.__compress = False
self.__retention = None
self.__snapshots = []
self.__identical_filesystem = False
self.location_type = location_type
if self.location_type == JobLocation.TYPE_SOURCE and container_subvolume_relpath is None:
self.container_subvolume_relpath = _DEFAULT_CONTAINER_RELPATH
else:
self.container_subvolume_relpath = container_subvolume_relpath
示例8: __init__
# 需要導入模塊: from urllib import parse [as 別名]
# 或者: from urllib.parse import SplitResult [as 別名]
def __init__(self, schema, netloc, port, path, query, fragment, userinfo):
self._strict = False
if port:
netloc += ':{}'.format(port)
if userinfo:
netloc = yarl.quote(
userinfo, safe='@:',
protected=':', strict=False) + '@' + netloc
if path:
path = yarl.quote(path, safe='@:', protected='/', strict=False)
if query:
query = yarl.quote(
query, safe='=+&?/:@',
protected=yarl.PROTECT_CHARS, qs=True, strict=False)
if fragment:
fragment = yarl.quote(fragment, safe='?/:@', strict=False)
self._val = SplitResult(
schema or '', # scheme
netloc=netloc, path=path, query=query, fragment=fragment)
self._cache = {}