當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。