当前位置: 首页>>代码示例>>Python>>正文


Python urlparse.SplitResult方法代码示例

本文整理汇总了Python中urlparse.SplitResult方法的典型用法代码示例。如果您正苦于以下问题:Python urlparse.SplitResult方法的具体用法?Python urlparse.SplitResult怎么用?Python urlparse.SplitResult使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在urlparse的用法示例。


在下文中一共展示了urlparse.SplitResult方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: urlparts

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse 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'), '') 
开发者ID:Autodesk,项目名称:arnold-usd,代码行数:18,代码来源:__init__.py

示例2: urlparts

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse 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('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'), '') 
开发者ID:zhangzhengde0225,项目名称:VaspCZ,代码行数:18,代码来源:bottle.py

示例3: urlparts

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse 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'), '') 
开发者ID:brycesub,项目名称:silvia-pi,代码行数:19,代码来源:bottle.py

示例4: urlparts

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse 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'), '') 
开发者ID:warriorframework,项目名称:warriorframework,代码行数:18,代码来源:bottle.py

示例5: resolve_adapter

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import SplitResult [as 别名]
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) 
开发者ID:llSourcell,项目名称:IOTA_demo,代码行数:39,代码来源:__init__.py

示例6: configure

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import SplitResult [as 别名]
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) 
开发者ID:llSourcell,项目名称:IOTA_demo,代码行数:11,代码来源:__init__.py

示例7: urlmatch

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import SplitResult [as 别名]
def urlmatch(scheme=None, netloc=None, path=None, method=None, params=None):
    def decorator(func):
        @wraps(func)
        def inner(self_or_url, url_or_request, *args, **kwargs):
            if isinstance(self_or_url, urlparse.SplitResult):
                url = self_or_url
                request = url_or_request
            else:
                url = url_or_request
                request = args[0]
            if scheme is not None and scheme != url.scheme:
                return
            if netloc is not None and not re.match(netloc, url.netloc):
                return
            if path is not None and not re.match(path, url.path):
                return
            if method is not None and method.upper() != request.method:
                return
            if method is not None and method.upper() != request.method:
                return
            if params is not None:
                if dict(urlparse.parse_qsl(url.query)) != params:
                    return
            print 'using mock response for path %s' % url.path
            return func(self_or_url, url_or_request, *args, **kwargs)
        return inner
    return decorator 
开发者ID:mbylstra,项目名称:django-wham,代码行数:29,代码来源:httmock.py

示例8: __init__

# 需要导入模块: import urlparse [as 别名]
# 或者: from urlparse import SplitResult [as 别名]
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 
开发者ID:llSourcell,项目名称:IOTA_demo,代码行数:50,代码来源:__init__.py


注:本文中的urlparse.SplitResult方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。