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


Python parse.urlsplit方法代码示例

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


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

示例1: load_tests

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def load_tests(loader, tests, pattern):
    """Provide a TestSuite to the discovery process."""
    gnocchi_url = os.getenv('GNOCCHI_ENDPOINT')
    if gnocchi_url:
        parsed_url = urlparse.urlsplit(gnocchi_url)
        prefix = parsed_url.path.rstrip('/')  # turn it into a prefix

        # NOTE(chdent): gabbi requires a port be passed or it will
        # default to 8001, so we must dance a little dance to get
        # the right ports. Probably gabbi needs to change.
        # https://github.com/cdent/gabbi/issues/50
        port = 443 if parsed_url.scheme == 'https' else 80
        if parsed_url.port:
            port = parsed_url.port

        test_dir = os.path.join(os.path.dirname(__file__), TESTS_DIR)
        return driver.build_tests(test_dir, loader,
                                  host=parsed_url.hostname,
                                  port=port,
                                  prefix=prefix)
    elif os.getenv("GABBI_LIVE"):
        raise RuntimeError('"GNOCCHI_ENDPOINT" is not set') 
开发者ID:gnocchixyz,项目名称:gnocchi,代码行数:24,代码来源:test_gabbi_live.py

示例2: _get_session

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def _get_session(self, url):
        if self._connection_pool:
            magic_tuple = parse.urlsplit(url)
            scheme, netloc, path, query, frag = magic_tuple
            service_url = '%s://%s' % (scheme, netloc)
            if self._current_url != service_url:
                # Invalidate Session object in case the url is somehow changed
                if self._session:
                    self._session.close()
                self._current_url = service_url
                self._logger.debug(
                    "New session created for: (%s)" % service_url)
                self._session = requests.Session()
                self._session.mount(service_url,
                                    self._connection_pool.get(service_url))
            return self._session
        elif self._session:
            return self._session 
开发者ID:nttcom,项目名称:eclcli,代码行数:20,代码来源:client.py

示例3: _get_session

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def _get_session(self, url):
        if self._connection_pool:
            magic_tuple = parse.urlsplit(url)
            scheme, netloc, path, query, frag = magic_tuple
            service_url = '%s://%s' % (scheme, netloc)
            if self._current_url != service_url:
                # Invalidate Session object in case the url is somehow changed
                if self._session:
                    self._session.close()
                self._current_url = service_url
                self._logger.debug(
                    "New session created for: (%s)" % service_url)
                self._session = requests.Session()
                self._session.mount(service_url,
                                    self._connection_pool.get(service_url))
            return self._session
        elif self._session:
            return self._session

    # @set_headers_param 
开发者ID:nttcom,项目名称:eclcli,代码行数:22,代码来源:client.py

示例4: get_current_ver

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def get_current_ver(cls, election_url):
        election_url_parts = parse.urlsplit(cls._url_ensure_trailing_slash(election_url))
        if 'Web02' in election_url:
            cls.parsed_url = election_url_parts._replace(path="/".join(election_url_parts.path.split('/')[:3]) + "/current_ver.txt", fragment='')
            election_url_parts =  cls.parsed_url
        else:
            election_url_parts = election_url_parts._replace(path=election_url_parts.path + "current_ver.txt")

        current_ver_url = parse.urlunsplit(election_url_parts)

        current_ver_response = requests.get(current_ver_url)

        try:
            current_ver_response.raise_for_status()
        except requests.exceptions.HTTPError:
            return None

        return current_ver_response.text 
开发者ID:openelections,项目名称:clarify,代码行数:20,代码来源:jurisdiction.py

示例5: get_commit_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [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

示例6: _add_query_parameters

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def _add_query_parameters(base_url, name_value_pairs):
    """Add one query parameter to a base URL.

    :type base_url: string
    :param base_url: Base URL (may already contain query parameters)

    :type name_value_pairs: list of (string, string) tuples.
    :param name_value_pairs: Names and values of the query parameters to add

    :rtype: string
    :returns: URL with additional query strings appended.
    """
    if len(name_value_pairs) == 0:
        return base_url

    scheme, netloc, path, query, frag = urlsplit(base_url)
    query = parse_qsl(query)
    query.extend(name_value_pairs)
    return urlunsplit((scheme, netloc, path, urlencode(query), frag)) 
开发者ID:googleapis,项目名称:python-storage,代码行数:21,代码来源:blob.py

示例7: _bucket_bound_hostname_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def _bucket_bound_hostname_url(host, scheme=None):
    """Helper to build bucket bound hostname URL.

    :type host: str
    :param host: Host name.

    :type scheme: str
    :param scheme: (Optional) Web scheme. If passed, use it
                   as a scheme in the result URL.

    :rtype: str
    :returns: A bucket bound hostname URL.
    """
    url_parts = urlsplit(host)
    if url_parts.scheme and url_parts.netloc:
        return host

    return "{scheme}://{host}/".format(scheme=scheme, host=host) 
开发者ID:googleapis,项目名称:python-storage,代码行数:20,代码来源:_helpers.py

示例8: remove_trailing_version_from_href

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def remove_trailing_version_from_href(href):
    """Removes the api version from the href.

    Given: 'http://www.masakari.com/ha/v1.1'
    Returns: 'http://www.masakari.com/ha'

    Given: 'http://www.masakari.com/v1.1'
    Returns: 'http://www.masakari.com'

    """
    parsed_url = urlparse.urlsplit(href)
    url_parts = parsed_url.path.rsplit('/', 1)

    # NOTE: this should match vX.X or vX
    expression = re.compile(r'^v([0-9]+|[0-9]+\.[0-9]+)(/.*|$)')
    if not expression.match(url_parts.pop()):
        LOG.debug('href %s does not contain version', href)
        raise ValueError(_('href %s does not contain version') % href)

    new_path = url_join(*url_parts)
    parsed_url = list(parsed_url)
    parsed_url[2] = new_path
    return urlparse.urlunsplit(parsed_url) 
开发者ID:openstack,项目名称:masakari,代码行数:25,代码来源:common.py

示例9: _build_url

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def _build_url(self, url):
        """Build a complete URL from a path by substituting in session parameters."""
        components = urlsplit(url)

        domain = components.netloc or self._settings['domain']

        # Add port if a non-standard port was specified
        if self._settings['port'] is not None and ':' not in domain:
            domain = '{}:{}'.format(domain, self._settings['port'])

        return urlunsplit([
            components.scheme or self._settings['protocol'],
            domain,
            components.path,
            components.query,
            components.fragment
        ]) 
开发者ID:sassoftware,项目名称:python-sasctl,代码行数:19,代码来源:core.py

示例10: append_warc

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def append_warc(self, dest, path):
        if not path.startswith('s3://'):
            logging.info('SKIPPING INVALID ' + path)
            return

        parts = urlsplit(path)

        src_bucket = self.s3conn.get_bucket(parts.netloc)

        stream = src_bucket.get_key(parts.path)

        stream.open_read()

        shutil.copyfileobj(stream, dest)

    # from BaseController 
开发者ID:Rhizome-Conifer,项目名称:conifer,代码行数:18,代码来源:migrate3.0.py

示例11: test_anon_record_redirect_and_delete

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def test_anon_record_redirect_and_delete(self):
        self.set_uuids('Recording', ['recording-session'])
        res = self.testapp.get('/record/mp_/http://example.com/')
        assert res.status_code == 302

        parts = urlsplit(res.headers['Location'])

        path_parts = parts.path.split('/', 2)
        assert self.anon_user == path_parts[1]

        assert self.anon_user.startswith(Session.temp_prefix)
        assert parts.path.endswith('/temp/recording-session/record/mp_/http://example.com/')

        # Delete this recording
        res = self.testapp.delete('/api/v1/recording/recording-session?user={user}&coll=temp'.format(user=self.anon_user))

        assert res.json == {'deleted_id': 'recording-session'}


        assert int(self.redis.hget(User.INFO_KEY.format(user=self.anon_user), Stats.DELETE_PROP)) > 0 
开发者ID:Rhizome-Conifer,项目名称:conifer,代码行数:22,代码来源:test_anon_workflow.py

示例12: _test_warc_write

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def _test_warc_write(self, url, user, coll, rec):
        parts = urlsplit(url)
        host = parts.netloc
        path = parts.path
        if parts.query:
            path += '?' + parts.query

        # Rec must be open
        #self.redis.hset('r:{user}:{coll}:{rec}:info'.format(user=user, coll=coll, rec=rec), 'id', rec)
        self.redis.setex('r:{rec}:open'.format(user=user, coll=coll, rec=rec), 30, 1)
        self.redis.hset('u:{user}:info'.format(user=user), 'size', 0)
        self.redis.hset('u:{user}:info'.format(user=user), 'max_size', 10000)

        req_url = '/record/live/resource/postreq?url={url}&param.recorder.user={user}&param.recorder.coll={coll}&param.recorder.rec={rec}'
        req_url = req_url.format(url=quote(url), user=user, coll=coll, rec=rec)
        resp = self.testapp.post(req_url, general_req_data.format(host=host, path=path).encode('utf-8'))

        while not self.wr_rec.recorder.write_queue.empty():
            self.wr_rec.recorder._write_one()

        assert resp.headers['Warcserver-Source-Coll'] == 'live'

        return resp 
开发者ID:Rhizome-Conifer,项目名称:conifer,代码行数:25,代码来源:test_rec.py

示例13: test_logged_out_wasapi_list_basic_auth

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def test_logged_out_wasapi_list_basic_auth(self):
        self.testapp.authorization = ('Basic', ('someuser', 'Password1'))
        res = self.testapp.get('/api/v1/download/webdata')
        self.testapp.authorization = None

        assert len(res.json['files']) == 3
        assert res.json['files'][0]['checksums']
        assert res.json['files'][0]['locations']

        assert sum((1 if val['is_active'] else 0 for val in res.json['files']), 0) == 2

        wasapi_filename = res.json['files'][0]['locations'][0]

        # 404 without basic auth
        res = self.testapp.head(urlsplit(wasapi_filename).path, status=404)

        # 200 with basic auth
        self.testapp.authorization = ('Basic', ('someuser', 'Password1'))
        res = self.testapp.head(urlsplit(wasapi_filename).path)
        assert res.headers['Content-Disposition'].startswith("attachment; filename*=UTF-8''rec-")
        self.testapp.authorization = None 
开发者ID:Rhizome-Conifer,项目名称:conifer,代码行数:23,代码来源:test_register_migrate.py

示例14: update_query_parameters

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def update_query_parameters(url, query_parameters):
    """
    Return url with updated query parameters.

    Arguments:
        url (str): Original url whose query parameters need to be updated.
        query_parameters (dict): A dictionary containing query parameters to be added to course selection url.

    Returns:
        (slug): slug identifier for the identity provider that can be used for identity verification of
            users associated the enterprise customer of the given user.

    """
    scheme, netloc, path, query_string, fragment = urlsplit(url)
    url_params = parse_qs(query_string)

    # Update url query parameters
    url_params.update(query_parameters)

    return urlunsplit(
        (scheme, netloc, path, urlencode(sorted(url_params.items()), doseq=True), fragment),
    ) 
开发者ID:edx,项目名称:edx-enterprise,代码行数:24,代码来源:utils.py

示例15: test_notify_alarm

# 需要导入模块: from six.moves.urllib import parse [as 别名]
# 或者: from six.moves.urllib.parse import urlsplit [as 别名]
def test_notify_alarm(self):
        data = {
            'actions': ['test://'],
            'alarm_id': 'foobar',
            'alarm_name': 'testalarm',
            'severity': 'critical',
            'previous': 'OK',
            'current': 'ALARM',
            'reason': 'Everything is on fire',
            'reason_data': {'fire': 'everywhere'}
        }
        self._msg_notifier.sample({}, 'alarm.update', data)
        time.sleep(1)
        notifications = self.service.notifiers['test'].obj.notifications
        self.assertEqual(1, len(notifications))
        self.assertEqual((urlparse.urlsplit(data['actions'][0]),
                          data['alarm_id'],
                          data['alarm_name'],
                          data['severity'],
                          data['previous'],
                          data['current'],
                          data['reason'],
                          data['reason_data']),
                         notifications[0]) 
开发者ID:openstack,项目名称:aodh,代码行数:26,代码来源:test_notifier.py


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