當前位置: 首頁>>代碼示例>>Python>>正文


Python urllib_parse.urlunparse方法代碼示例

本文整理匯總了Python中six.moves.urllib_parse.urlunparse方法的典型用法代碼示例。如果您正苦於以下問題:Python urllib_parse.urlunparse方法的具體用法?Python urllib_parse.urlunparse怎麽用?Python urllib_parse.urlunparse使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在six.moves.urllib_parse的用法示例。


在下文中一共展示了urllib_parse.urlunparse方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _idna_encode

# 需要導入模塊: from six.moves import urllib_parse [as 別名]
# 或者: from six.moves.urllib_parse import urlunparse [as 別名]
def _idna_encode(self, value):
        parsed = urllib_parse.urlparse(value)
        if parsed.port:
            netloc = (
                idna.encode(parsed.hostname) +
                ":{0}".format(parsed.port).encode("ascii")
            ).decode("ascii")
        else:
            netloc = idna.encode(parsed.hostname).decode("ascii")

        # Note that building a URL in this fashion means it should be
        # semantically indistinguishable from the original but is not
        # guaranteed to be exactly the same.
        return urllib_parse.urlunparse((
            parsed.scheme,
            netloc,
            parsed.path,
            parsed.params,
            parsed.query,
            parsed.fragment
        )) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:23,代碼來源:general_name.py

示例2: _idna_encode

# 需要導入模塊: from six.moves import urllib_parse [as 別名]
# 或者: from six.moves.urllib_parse import urlunparse [as 別名]
def _idna_encode(self, value):
        idna = _lazy_import_idna()
        parsed = urllib_parse.urlparse(value)
        if parsed.port:
            netloc = (
                idna.encode(parsed.hostname) +
                ":{}".format(parsed.port).encode("ascii")
            ).decode("ascii")
        else:
            netloc = idna.encode(parsed.hostname).decode("ascii")

        # Note that building a URL in this fashion means it should be
        # semantically indistinguishable from the original but is not
        # guaranteed to be exactly the same.
        return urllib_parse.urlunparse((
            parsed.scheme,
            netloc,
            parsed.path,
            parsed.params,
            parsed.query,
            parsed.fragment
        )) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:24,代碼來源:general_name.py

示例3: modify_start_url

# 需要導入模塊: from six.moves import urllib_parse [as 別名]
# 或者: from six.moves.urllib_parse import urlunparse [as 別名]
def modify_start_url(self, start_url):
        """
        Given a SAML redirect URL, parse it and change the ID to
        a consistent value, so the request is always identical.
        """
        # Parse the SAML Request URL to get the XML being sent to TestShib
        url_parts = urlparse(start_url)
        query = dict((k, v[0]) for (k, v) in
                     parse_qs(url_parts.query).items())
        xml = OneLogin_Saml2_Utils.decode_base64_and_inflate(
            query['SAMLRequest']
        )
        # Modify the XML:
        xml = xml.decode()
        xml, changed = re.subn(r'ID="[^"]+"', 'ID="TEST_ID"', xml)
        self.assertEqual(changed, 1)
        # Update the URL to use the modified query string:
        query['SAMLRequest'] = OneLogin_Saml2_Utils.deflate_and_base64_encode(
            xml
        )
        url_parts = list(url_parts)
        url_parts[4] = urlencode(query)
        return urlunparse(url_parts) 
開發者ID:BeanWei,項目名稱:Dailyfresh-B2C,代碼行數:25,代碼來源:test_saml.py

示例4: __init__

# 需要導入模塊: from six.moves import urllib_parse [as 別名]
# 或者: from six.moves.urllib_parse import urlunparse [as 別名]
def __init__(self, value):
        if not isinstance(value, six.text_type):
            raise TypeError("value must be a unicode string")

        parsed = urllib_parse.urlparse(value)
        if not parsed.hostname:
            netloc = ""
        elif parsed.port:
            netloc = (
                idna.encode(parsed.hostname) +
                ":{0}".format(parsed.port).encode("ascii")
            ).decode("ascii")
        else:
            netloc = idna.encode(parsed.hostname).decode("ascii")

        # Note that building a URL in this fashion means it should be
        # semantically indistinguishable from the original but is not
        # guaranteed to be exactly the same.
        uri = urllib_parse.urlunparse((
            parsed.scheme,
            netloc,
            parsed.path,
            parsed.params,
            parsed.query,
            parsed.fragment
        )).encode("ascii")

        self._value = value
        self._encoded = uri 
開發者ID:aliyun,項目名稱:oss-ftp,代碼行數:31,代碼來源:general_name.py

示例5: get_sample_data

# 需要導入模塊: from six.moves import urllib_parse [as 別名]
# 或者: from six.moves.urllib_parse import urlunparse [as 別名]
def get_sample_data(self, meter_name, parse_url, params, cache):

        extractor = self._get_extractor(meter_name)
        if extractor is None:
            # The way to getting meter is not implemented in this driver or
            # OpenDaylight REST API has not api to getting meter.
            return None

        iter = self._get_iter(meter_name)
        if iter is None:
            # The way to getting meter is not implemented in this driver or
            # OpenDaylight REST API has not api to getting meter.
            return None

        parts = urlparse.ParseResult(params.get('scheme', ['http'])[0],
                                     parse_url.netloc,
                                     parse_url.path,
                                     None,
                                     None,
                                     None)
        endpoint = urlparse.urlunparse(parts)

        data = self._prepare_cache(endpoint, params, cache)

        samples = []
        if data:
            for sample in iter(extractor, data):
                if sample is not None:
                    # set controller name to resource_metadata
                    sample[2]['controller'] = 'OpenDaylight_V2'
                    samples.append(sample)

        return samples 
開發者ID:openstack,項目名稱:networking-odl,代碼行數:35,代碼來源:driver.py

示例6: get_odl_url

# 需要導入模塊: from six.moves import urllib_parse [as 別名]
# 或者: from six.moves.urllib_parse import urlunparse [as 別名]
def get_odl_url(path=''):
    '''Make a URL for some ODL resource (path)'''
    purl = urlparse.urlsplit(cfg.CONF.ml2_odl.url)
    features_url = urlparse.urlunparse((
        purl.scheme, purl.netloc, path, '', '', ''))
    return features_url 
開發者ID:openstack,項目名稱:networking-odl,代碼行數:8,代碼來源:utils.py

示例7: strip_netloc

# 需要導入模塊: from six.moves import urllib_parse [as 別名]
# 或者: from six.moves.urllib_parse import urlunparse [as 別名]
def strip_netloc(url):
    """Return absolute-URI path from URL.

    Strip the scheme and host from the URL, returning the
    server-absolute portion.

    Useful for wrapping an absolute-URI for which only the
    path is expected (such as in calls to :py:meth:`WebCase.getPage`).

    >>> strip_netloc('https://google.com/foo/bar?bing#baz')
    '/foo/bar?bing'

    >>> strip_netloc('//google.com/foo/bar?bing#baz')
    '/foo/bar?bing'

    >>> strip_netloc('/foo/bar?bing#baz')
    '/foo/bar?bing'
    """
    parsed = urllib_parse.urlparse(url)
    scheme, netloc, path, params, query, fragment = parsed
    stripped = '', '', path, params, query, ''
    return urllib_parse.urlunparse(stripped)


# Add any exceptions which your web framework handles
# normally (that you don't want server_error to trap). 
開發者ID:cherrypy,項目名稱:cheroot,代碼行數:28,代碼來源:webtest.py

示例8: parse_connection_string

# 需要導入模塊: from six.moves import urllib_parse [as 別名]
# 或者: from six.moves.urllib_parse import urlunparse [as 別名]
def parse_connection_string(value):
    """Original Governor stores connection strings for each cluster members if a following format:
        postgres://{username}:{password}@{connect_address}/postgres
    Since each of our patroni instances provides own REST API endpoint it's good to store this information
    in DCS among with postgresql connection string. In order to not introduce new keys and be compatible with
    original Governor we decided to extend original connection string in a following way:
        postgres://{username}:{password}@{connect_address}/postgres?application_name={api_url}
    This way original Governor could use such connection string as it is, because of feature of `libpq` library.

    This method is able to split connection string stored in DCS into two parts, `conn_url` and `api_url`"""

    scheme, netloc, path, params, query, fragment = urlparse(value)
    conn_url = urlunparse((scheme, netloc, path, params, '', fragment))
    api_url = ([v for n, v in parse_qsl(query) if n == 'application_name'] or [None])[0]
    return conn_url, api_url 
開發者ID:zalando,項目名稱:patroni,代碼行數:17,代碼來源:__init__.py

示例9: __call__

# 需要導入模塊: from six.moves import urllib_parse [as 別名]
# 或者: from six.moves.urllib_parse import urlunparse [as 別名]
def __call__(self, member, method='GET', endpoint=None, data=None, **kwargs):
        url = member.api_url
        if endpoint:
            scheme, netloc, _, _, _, _ = urlparse(url)
            url = urlunparse((scheme, netloc, endpoint, '', '', ''))
        return self.request(method, url, data, **kwargs) 
開發者ID:zalando,項目名稱:patroni,代碼行數:8,代碼來源:request.py

示例10: strip_netloc

# 需要導入模塊: from six.moves import urllib_parse [as 別名]
# 或者: from six.moves.urllib_parse import urlunparse [as 別名]
def strip_netloc(url):
    """Return absolute-URI path from URL.

    Strip the scheme and host from the URL, returning the
    server-absolute portion.

    Useful for wrapping an absolute-URI for which only the
    path is expected (such as in calls to getPage).

    >>> strip_netloc('https://google.com/foo/bar?bing#baz')
    '/foo/bar?bing'

    >>> strip_netloc('//google.com/foo/bar?bing#baz')
    '/foo/bar?bing'

    >>> strip_netloc('/foo/bar?bing#baz')
    '/foo/bar?bing'
    """
    parsed = urllib_parse.urlparse(url)
    scheme, netloc, path, params, query, fragment = parsed
    stripped = '', '', path, params, query, ''
    return urllib_parse.urlunparse(stripped)


# Add any exceptions which your web framework handles
# normally (that you don't want server_error to trap). 
開發者ID:Tautulli,項目名稱:Tautulli,代碼行數:28,代碼來源:webtest.py


注:本文中的six.moves.urllib_parse.urlunparse方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。