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


Python util.parse_url方法代码示例

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


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

示例1: vendor_artifact

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import parse_url [as 别名]
def vendor_artifact(ctx, package, version=None):
    simple = requests.get("https://pypi.org/simple/{0}/".format(package))
    pkg_str = "{0}-{1}".format(package, version)
    soup = bs4.BeautifulSoup(simple.content)
    links = [
        a.attrs["href"] for a in soup.find_all("a") if a.getText().startswith(pkg_str)
    ]
    for link in links:
        dest_dir = _get_git_root(ctx) / "tests" / "pypi" / package
        if not dest_dir.exists():
            dest_dir.mkdir()
        _, _, dest_path = urllib3_parse(link).path.rpartition("/")
        dest_file = dest_dir / dest_path
        with io.open(dest_file.as_posix(), "wb") as target_handle:
            with open_file(link) as fp:
                shutil.copyfileobj(fp, target_handle) 
开发者ID:pypa,项目名称:pipenv,代码行数:18,代码来源:__init__.py

示例2: _get_parsed_url

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import parse_url [as 别名]
def _get_parsed_url(url):
    # type: (S) -> Url
    """
    This is a stand-in function for `urllib3.util.parse_url`

    The orignal function doesn't handle special characters very well, this simply splits
    out the authentication section, creates the parsed url, then puts the authentication
    section back in, bypassing validation.

    :return: The new, parsed URL object
    :rtype: :class:`~urllib3.util.url.Url`
    """

    try:
        parsed = urllib3_parse(url)
    except ValueError:
        scheme, _, url = url.partition("://")
        auth, _, url = url.rpartition("@")
        url = "{scheme}://{url}".format(scheme=scheme, url=url)
        parsed = urllib3_parse(url)._replace(auth=auth)
    return parsed 
开发者ID:pypa,项目名称:pipenv,代码行数:23,代码来源:utils.py

示例3: _get_parsed_url

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import parse_url [as 别名]
def _get_parsed_url(url):
    # type: (S) -> Url
    """This is a stand-in function for `urllib3.util.parse_url`

    The orignal function doesn't handle special characters very well, this simply splits
    out the authentication section, creates the parsed url, then puts the authentication
    section back in, bypassing validation.

    :return: The new, parsed URL object
    :rtype: :class:`~urllib3.util.url.Url`
    """

    try:
        parsed = urllib3_parse(url)
    except ValueError:
        scheme, _, url = url.partition("://")
        auth, _, url = url.rpartition("@")
        url = "{scheme}://{url}".format(scheme=scheme, url=url)
        parsed = urllib3_parse(url)._replace(auth=auth)
    if parsed.auth:
        return parsed._replace(auth=url_unquote(parsed.auth))
    return parsed 
开发者ID:pypa,项目名称:pipenv,代码行数:24,代码来源:url.py

示例4: __init__

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import parse_url [as 别名]
def __init__(
            self, base_url, token=None, identity=None,
            default_429_wait_ms=5000,
            use_authorization_header=True,
            connection_timeout=60
    ):
        try:
            scheme, auth, host, port, path, query, fragment = parse_url(base_url)
        except LocationParseError:
            raise MatrixError("Invalid homeserver url %s" % base_url)
        if not scheme:
            raise MatrixError("No scheme in homeserver url %s" % base_url)
        self._base_url = base_url

        self.token = token
        self.identity = identity
        self.txn_id = 0
        self.validate_cert = True
        self.session = Session()
        self.default_429_wait_ms = default_429_wait_ms
        self.use_authorization_header = use_authorization_header
        self.connection_timeout = connection_timeout 
开发者ID:saadnpq,项目名称:matrixcli,代码行数:24,代码来源:api.py

示例5: __init__

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import parse_url [as 别名]
def __init__(
            self, base_url, token=None, identity=None,
            default_429_wait_ms=5000,
            use_authorization_header=True
    ):
        try:
            scheme, auth, host, port, path, query, fragment = parse_url(base_url)
        except LocationParseError:
            raise MatrixError("Invalid homeserver url %s" % base_url)
        if not scheme:
            raise MatrixError("No scheme in homeserver url %s" % base_url)
        self._base_url = base_url

        self.token = token
        self.identity = identity
        self.txn_id = 0
        self.validate_cert = True
        self.session = Session()
        self.default_429_wait_ms = default_429_wait_ms
        self.use_authorization_header = use_authorization_header 
开发者ID:matrix-org,项目名称:matrix-python-sdk,代码行数:22,代码来源:api.py

示例6: start_download

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import parse_url [as 别名]
def start_download(self):
        import uuid
        log.info('download-start', name=self.name)
        if not self.parse_url():
            self._download_failed()
            log.info('failed url parsing', name=self.name)
            return
            #returnValue('failed url parsing')

        self._download_state = ImageDownload.DOWNLOAD_STARTED
        self._failure_reason = ImageDownload.NO_ERROR

        #send msg to oltd to start download
        self.image_cfg_msg_send(IMAGE_CMD_DOWNLOAD)
        
        log.info('start download *************', name=self.name)
        self._chech_deferred = reactor.callLater(120, self.check_download_status)
        return self._chech_deferred 
开发者ID:opencord,项目名称:voltha,代码行数:20,代码来源:download.py

示例7: get_connection

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import parse_url [as 别名]
def get_connection(self, url, proxies=None):
        """Returns a urllib3 connection for the given URL. This should not be
        called from user code, and is only exposed for use when subclassing the
        :class:`HTTPAdapter <requests.adapters.HTTPAdapter>`.

        :param url: The URL to connect to.
        :param proxies: (optional) A Requests-style dictionary of proxies used on this request.
        :rtype: urllib3.ConnectionPool
        """
        proxy = select_proxy(url, proxies)

        if proxy:
            proxy = prepend_scheme_if_needed(proxy, 'http')
            proxy_url = parse_url(proxy)
            if not proxy_url.host:
                raise InvalidProxyURL("Please check proxy URL. It is malformed"
                                      " and could be missing the host.")
            proxy_manager = self.proxy_manager_for(proxy)
            conn = proxy_manager.connection_from_url(url)
        else:
            # Only scheme should be lower case
            parsed = urlparse(url)
            url = parsed.geturl()
            conn = self.poolmanager.connection_from_url(url)

        return conn 
开发者ID:danielecook,项目名称:gist-alfred,代码行数:28,代码来源:adapters.py

示例8: get_schema_and_host

# 需要导入模块: from urllib3 import util [as 别名]
# 或者: from urllib3.util import parse_url [as 别名]
def get_schema_and_host(
    url: str, require_url_encoding: bool = False
) -> Tuple[Optional[str], Optional[str], Optional[str]]:
    """
    Return URL scheme and host and cleaned URL.

    Parameters
    ----------
    url : str
        Input URL
    require_url_encoding : bool
        Set to True if url needs encoding. Defualt is False.

    Returns
    -------
    Tuple[Optional[str], Optional[str], Optional[str]
        Tuple of URL, scheme, host

    """
    clean_url = None
    scheme = None
    host = None
    try:
        scheme, _, host, _, _, _, _ = parse_url(url)
        clean_url = url
    except LocationParseError:
        # Try to clean URL and re-check
        cleaned_url = _clean_url(url)
        if cleaned_url is not None:
            try:
                scheme, _, host, _, _, _, _ = parse_url(cleaned_url)
                clean_url = cleaned_url
            except LocationParseError:
                pass
    if require_url_encoding and clean_url:
        clean_url = quote_plus(clean_url)
    return clean_url, scheme, host 
开发者ID:microsoft,项目名称:msticpy,代码行数:39,代码来源:ti_provider_base.py


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