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


Python parse.urlunparse方法代码示例

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


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

示例1: _decorate_request

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def _decorate_request(self, filters, method, url, headers=None, body=None,
                          auth_data=None):
        if auth_data is None:
            auth_data = self.auth_data
        token, _ = auth_data
        base_url = self.base_url(filters=filters, auth_data=auth_data)
        # build authenticated request
        # returns new request, it does not touch the original values
        _headers = copy.deepcopy(headers) if headers is not None else {}
        _headers['X-Auth-Token'] = str(token)
        if url is None or url == "":
            _url = base_url
        else:
            # Join base URL and url, and remove multiple contiguous slashes
            _url = "/".join([base_url, url])
            parts = [x for x in urlparse.urlparse(_url)]
            parts[2] = re.sub("/{2,}", "/", parts[2])
            _url = urlparse.urlunparse(parts)
        # no change to method or body
        return str(_url), _headers, body 
开发者ID:openstack,项目名称:tempest-lib,代码行数:22,代码来源:auth.py

示例2: censor_connect_string

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def censor_connect_string(connect_string):
    """
    Take a SQLAlchemy connect string and return a sanitized version
    that can be written to the log without disclosing the password.
    The password is replaced with "xxxx".
    In case any error occurs, return "<error when censoring connect string>"
    """
    try:
        parsed = urlparse(connect_string)
        if parsed.password is not None:
            # We need to censor the ``netloc`` attribute: user:pass@host
            _, host = parsed.netloc.rsplit("@", 1)
            new_netloc = u'{}:{}@{}'.format(parsed.username, 'xxxx', host)
            # Convert the URL to six components. netloc is component #1.
            splitted = list(parsed)
            splitted[1] = new_netloc
            return urlunparse(splitted)
        return connect_string
    except Exception:
        return "<error when censoring connect string>" 
开发者ID:privacyidea,项目名称:privacyidea,代码行数:22,代码来源:__init__.py

示例3: __init__

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def __init__(
        self,
        host="localhost",
        port=9200,
        path="",
        scheme="http",
        user=None,
        password=None,
        context=None,
        **kwargs,
    ):
        netloc = f"{host}:{port}"
        path = path or "/"
        self.url = parse.urlunparse((scheme, netloc, path, None, None, None))
        self.context = context or {}
        self.closed = False
        self.cursors = []
        self.kwargs = kwargs
        # Subclass needs to initialize Elasticsearch
        self.es = None 
开发者ID:preset-io,项目名称:elasticsearch-dbapi,代码行数:22,代码来源:baseapi.py

示例4: _new_location

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def _new_location(self, old_location, url):
        store_name = old_location.store_name
        store_class = old_location.store_location.__class__
        image_id = old_location.image_id
        store_specs = old_location.store_specs
        # Note(sabari): The redirect url will have a scheme 'http(s)', but the
        # store only accepts url with scheme 'vsphere'. Thus, replacing with
        # store's scheme.
        parsed_url = urlparse.urlparse(url)
        new_url = parsed_url._replace(scheme='vsphere')
        vsphere_url = urlparse.urlunparse(new_url)
        return glance_store.location.Location(store_name,
                                              store_class,
                                              self.conf,
                                              uri=vsphere_url,
                                              image_id=image_id,
                                              store_specs=store_specs,
                                              backend=self.backend_group) 
开发者ID:openstack,项目名称:glance_store,代码行数:20,代码来源:vmware_datastore.py

示例5: validate_link

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def validate_link(self, link, bookmark=False):
        """Checks if the given link can get correct data."""
        # removes the scheme and net location parts of the link
        url_parts = list(urlparse.urlparse(link))
        url_parts[0] = url_parts[1] = ''

        # bookmark link should not have the version in the URL
        if bookmark and url_parts[2].startswith(PATH_PREFIX):
            return False

        full_path = urlparse.urlunparse(url_parts)
        try:
            self.get_json(full_path, path_prefix='')
            return True
        except Exception:
            return False 
开发者ID:openstack,项目名称:magnum,代码行数:18,代码来源:base.py

示例6: get_commit_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def get_commit_url(commit, pkg):
    try:
        upstream_url = parse.urlsplit(pkg["upstream"])

        if upstream_url.netloc == "git.openstack.org":
            commit_url = ("http",
                          upstream_url.netloc,
                          "/cgit%s/commit/?id=" % upstream_url.path,
                          "", "", "")
            commit_url = parse.urlunparse(commit_url)
        elif upstream_url.netloc == "github.com":
            commit_url = ("https",
                          upstream_url.netloc,
                          "%s/commit/" % upstream_url.path,
                          "", "", "")
            commit_url = parse.urlunparse(commit_url)
        else:
            # Fallback when no cgit URL can be defined
            commit_url = pkg["upstream"]
    except KeyError:
        # This should not happen, but pkg['upstream'] may not be present
        # after some error in the gitrepo driver
        commit_url = ''

    return commit_url 
开发者ID:softwarefactory-project,项目名称:DLRN,代码行数:27,代码来源:reporting.py

示例7: create_server

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def create_server(conn):
    token = id_client.get_scoped_token_v3("user")
    _url = urlparse.urlunparse(CONF.syntribos.endpoint)
    endpoint = urlparse.urlunparse(
        (_url.scheme,
         _url.hostname + ":9292",
         _url.path,
         _url.params,
         _url.query,
         _url.fragment))
    _gc = GC(endpoint=endpoint, token=token)
    image = _gc.images.get(get_image_id())
    flavor = conn.flavors.get(get_flavor_id())
    server = conn.servers.create(
        name="test", flavor=flavor, image=image)

    return server.id 
开发者ID:openstack-archive,项目名称:syntribos,代码行数:19,代码来源:client.py

示例8: get_image_id

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def get_image_id():
    token = id_client.get_scoped_token_v3("user")
    _url = urlparse.urlparse(CONF.syntribos.endpoint)
    endpoint = urlparse.urlunparse(
        (_url.scheme,
         _url.hostname + ":9292",
         _url.path,
         _url.params,
         _url.query,
         _url.fragment))
    _gc = GC(endpoint=endpoint, token=token)
    image_ids = [image.id for image in _gc.images.list()]
    if not image_ids:
        image_ids.append(_gc.images.create(name="test"))

    return image_ids[-1] 
开发者ID:openstack-archive,项目名称:syntribos,代码行数:18,代码来源:client.py

示例9: __init__

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def __init__(self, connection_str, index_name="osprofiler-notifications",
                 project=None, service=None, host=None, conf=cfg.CONF,
                 **kwargs):
        """Elasticsearch driver for OSProfiler."""

        super(ElasticsearchDriver, self).__init__(connection_str,
                                                  project=project,
                                                  service=service,
                                                  host=host,
                                                  conf=conf,
                                                  **kwargs)
        try:
            from elasticsearch import Elasticsearch
        except ImportError:
            raise exc.CommandError(
                "To use OSProfiler with ElasticSearch driver, "
                "please install `elasticsearch` library. "
                "To install with pip:\n `pip install elasticsearch`.")

        client_url = parser.urlunparse(parser.urlparse(self.connection_str)
                                       ._replace(scheme="http"))
        self.conf = conf
        self.client = Elasticsearch(client_url)
        self.index_name = index_name
        self.index_name_error = "osprofiler-notifications-error" 
开发者ID:openstack,项目名称:osprofiler,代码行数:27,代码来源:elasticsearch_driver.py

示例10: requote_uri

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def requote_uri(uri):
    """Requote uri if it contains non-ascii chars, spaces etc.
    """
    # To reduce tabulator import time
    import requests.utils
    if six.PY2:
        def url_encode_non_ascii(bytes):
            pattern = '[\x80-\xFF]'
            replace = lambda c: ('%%%02x' % ord(c.group(0))).upper()
            return re.sub(pattern, replace, bytes)
        parts = urlparse(uri)
        uri = urlunparse(
            part.encode('idna') if index == 1
            else url_encode_non_ascii(part.encode('utf-8'))
            for index, part in enumerate(parts))
    return requests.utils.requote_uri(uri) 
开发者ID:frictionlessdata,项目名称:tabulator-py,代码行数:18,代码来源:helpers.py

示例11: __init__

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def __init__(self, conf):
        self.conf = conf
        db_name = 'aodh_%s' % uuidutils.generate_uuid(dashed=False)
        import sqlalchemy
        self._engine = sqlalchemy.create_engine(conf.database.connection)
        self._conn = self._engine.connect()
        self._create_db(self._conn, db_name)
        self._conn.close()
        self._engine.dispose()
        parsed = list(urlparse.urlparse(conf.database.connection))
        # NOTE(jd) We need to set an host otherwise urlunparse() will not
        # construct a proper URL
        if parsed[1] == '':
            parsed[1] = 'localhost'
        parsed[2] = '/' + db_name
        self.url = urlparse.urlunparse(parsed) 
开发者ID:openstack,项目名称:aodh,代码行数:18,代码来源:db.py

示例12: _ping_indexer

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def _ping_indexer(self, search_engine):
        # App Engine makes HTTP requests to tasks, so building a URL based on
        # the request will use HTTP instead of HTTPS, but we want to send search
        # engines HTTPS URLs.
        sitemap_url = self.build_absolute_uri('/global/sitemap')
        sitemap_url_parts = list(urlparse.urlparse(sitemap_url))
        sitemap_url_parts[0] = 'https'  # 0 is the index of the scheme part.
        sitemap_url = urlparse.urlunparse(sitemap_url_parts)
        ping_url = _INDEXER_MAP[search_engine] % urllib.parse.quote(sitemap_url)
        response = requests.get(ping_url)
        if response.status_code == 200:
            return True
        else:
            # TODO(nworden): Retry or email konbit-personfinder on failure.
            logging.error('Received %d pinging %s',
                          response.status_code, ping_url)
            return False 
开发者ID:google,项目名称:personfinder,代码行数:19,代码来源:sitemap_ping.py

示例13: proxy_with_warning_page_mock

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def proxy_with_warning_page_mock(url, *args, **kwargs):
    cookies = kwargs.get('cookies') or {}
    proxy_cookie = cookies.get('proxy_cookie')
    url_parts = list(urlparse(url))
    query = dict(parse_qsl(url_parts[4]))
    if proxy_cookie and query.get('proxyapproved') == 'true':
        del query['proxyapproved']
        url_parts[4] = urlencode(query)
        return standalone_requests_get_mock(urlunparse(url_parts), *args[1:], **kwargs)
    else:
        # Display the html warning page with the redirect link
        query['proxyapproved'] = 'true'
        url_parts[4] = urlencode(query)
        with open(os.path.join(FIXTURE_DIR, 'html_warning_page'), 'r') as f:
            body = f.read().replace('$REDIRECT_URL$', urlunparse(url_parts))
            cookies['proxy_cookie'] = 'foo'
            return MockedResponse(body, 200, cookies) 
开发者ID:DataDog,项目名称:integrations-core,代码行数:19,代码来源:test_spark.py

示例14: __str__

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def __str__(self):
        parsed = urlparse.urlparse(self.conf.indexer.url)
        url = urlparse.urlunparse((
            parsed.scheme,
            "***:***@%s%s" % (parsed.hostname,
                              ":%s" % parsed.port if parsed.port else ""),
            parsed.path,
            parsed.params,
            parsed.query,
            parsed.fragment))
        return "%s: %s" % (self.__class__.__name__, url) 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:13,代码来源:sqlalchemy.py

示例15: _build_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlunparse [as 别名]
def _build_url(url, _params):
    """Build the actual URL to use."""

    # Support for unicode domain names and paths.
    scheme, netloc, path, params, query, fragment = urlparse(url)
    netloc = netloc.encode('idna').decode('utf-8')
    if not path:
        path = '/'

    if six.PY2:
        if isinstance(scheme, six.text_type):
            scheme = scheme.encode('utf-8')
        if isinstance(netloc, six.text_type):
            netloc = netloc.encode('utf-8')
        if isinstance(path, six.text_type):
            path = path.encode('utf-8')
        if isinstance(params, six.text_type):
            params = params.encode('utf-8')
        if isinstance(query, six.text_type):
            query = query.encode('utf-8')
        if isinstance(fragment, six.text_type):
            fragment = fragment.encode('utf-8')

    enc_params = _encode_params(_params)
    if enc_params:
        if query:
            query = '%s&%s' % (query, enc_params)
        else:
            query = enc_params
    url = (urlunparse([scheme, netloc, path, params, query, fragment]))
    return url 
开发者ID:binux,项目名称:pyspider,代码行数:33,代码来源:url.py


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