url#

通用 URL 实用程序。

#

Url

用于表示 URL 的对象。此对象的字符串表示形式是 URL 字符串。

函数#

hex_octal_to_int(ho)

percent_decode(path)

path_to_url(path)

urlparse(→ Url)

url_to_s3_info(url)

将 s3 URL 转换为 bucket 和 key 的元组。

is_url(url)

is_ipv4_address(string_ip)

is_ipv6_address(string_ip)

is_ip_address(string_ip)

join(*args)

has_scheme(value)

strip_scheme(url)

mask_anaconda_token(url)

split_anaconda_token(url)

split_platform(known_subdirs, url)

_split_platform_re(known_subdirs)

has_platform(url, known_subdirs)

split_scheme_auth_token(url)

split_conda_url_easy_parts(known_subdirs, url)

get_proxy_username_and_pass(scheme)

add_username_and_password(→ str)

usernamepassword 插入到提供的 url

maybe_add_auth(→ str)

如果 URL 当前没有身份验证,则添加身份验证。

maybe_unquote(url)

remove_auth(→ str)

从 URL 中删除嵌入式身份验证。

属性#

file_scheme

def url_to_path(url)

url_attrs

join_url

hex_octal_to_int(ho)#
percent_decode(path)#
file_scheme = 'file://'#

def url_to_path(url): assert url.startswith(file_scheme), "{} is not a file-scheme URL".format(url) decoded = percent_decode(url[len(file_scheme):]) if decoded.startswith('/') and decoded[2] == ':'

# Windows 路径。 decoded.replace('/', '')

return decoded

path_to_url(path)#
url_attrs = ('scheme', 'path', 'query', 'fragment', 'username', 'password', 'hostname', 'port')#
class Url#

基类: namedtuple('Url', url_attrs)

用于表示 URL 的对象。此对象的字符串表示形式是 URL 字符串。

此对象的设计灵感来自 urllib3 实现,因为它为您提供了一种从各个部分构造 URL 的方法。此对象背后的动机是创建一个与内置 urllib.parse.urlparse 函数互操作的东西,并且具有比内置 ParseResult 对象更多的功能。

初始化 self。有关准确的签名,请参阅 help(type(self))。

property auth#
property netloc#
__str__()#

返回 str(self)。

as_dict() dict#

为 namedtuple 的 _asdict 提供公共接口

replace(**kwargs) Url#

为 namedtuple 的 _replace 提供公共接口

classmethod from_parse_result(parse_result: urllib.parse.ParseResult) Url#
urlparse(url: str) Url#
url_to_s3_info(url)#

将 s3 URL 转换为 bucket 和 key 的元组。

示例

>>> url_to_s3_info("s3://bucket-name.bucket/here/is/the/key")
('bucket-name.bucket', '/here/is/the/key')
is_url(url)#

示例

>>> is_url(None)
False
>>> is_url("s3://some/bucket")
True
is_ipv4_address(string_ip)#

示例

>>> [is_ipv4_address(ip) for ip in ('8.8.8.8', '192.168.10.10', '255.255.255.255')]
[True, True, True]
>>> [is_ipv4_address(ip) for ip in ('8.8.8', '192.168.10.10.20', '256.255.255.255', '::1')]
[False, False, False, False]
is_ipv6_address(string_ip)#

示例

>> [is_ipv6_address(ip) for ip in ('::1', '2001:db8:85a3::370:7334', '1234:'*7+'1234')] [True, True, True] >> [is_ipv6_address(ip) for ip in ('192.168.10.10', '1234:'*8+'1234')] [False, False]

is_ip_address(string_ip)#

示例

>> is_ip_address('192.168.10.10') True >> is_ip_address('::1') True >> is_ip_address('www.google.com') False

join(*args)#
join_url#
has_scheme(value)#
strip_scheme(url)#

示例

>>> strip_scheme("https://www.conda.io")
'www.conda.io'
>>> strip_scheme("s3://some.bucket/plus/a/path.ext")
'some.bucket/plus/a/path.ext'
mask_anaconda_token(url)#
split_anaconda_token(url)#

示例

>>> split_anaconda_token("https://1.2.3.4/t/tk-123-456/path")
(u'https://1.2.3.4/path', u'tk-123-456')
>>> split_anaconda_token("https://1.2.3.4/t//path")
(u'https://1.2.3.4/path', u'')
>>> split_anaconda_token("https://some.domain/api/t/tk-123-456/path")
(u'https://some.domain/api/path', u'tk-123-456')
>>> split_anaconda_token("https://1.2.3.4/conda/t/tk-123-456/path")
(u'https://1.2.3.4/conda/path', u'tk-123-456')
>>> split_anaconda_token("https://1.2.3.4/path")
(u'https://1.2.3.4/path', None)
>>> split_anaconda_token("https://10.2.3.4:8080/conda/t/tk-123-45")
(u'https://10.2.3.4:8080/conda', u'tk-123-45')
split_platform(known_subdirs, url)#

示例

>>> from conda.base.constants import KNOWN_SUBDIRS
>>> split_platform(KNOWN_SUBDIRS, "https://1.2.3.4/t/tk-123/linux-ppc64le/path")
(u'https://1.2.3.4/t/tk-123/path', u'linux-ppc64le')
_split_platform_re(known_subdirs)#
has_platform(url, known_subdirs)#
split_scheme_auth_token(url)#

示例

>>> split_scheme_auth_token("https://u:[email protected]/t/x1029384756/more/path")
('conda.io/more/path', 'https', 'u:p', 'x1029384756')
>>> split_scheme_auth_token(None)
(None, None, None, None)
split_conda_url_easy_parts(known_subdirs, url)#
get_proxy_username_and_pass(scheme)#
add_username_and_password(url: str, username: str, password: str) str#

usernamepassword 插入到提供的 url

>>> add_username_and_password('https://anaconda.org', 'TestUser', 'Password')
'https://TestUser:[email protected]'
maybe_add_auth(url: str, auth: str, force=False) str#

如果 URL 当前没有身份验证,则添加身份验证。

默认情况下,如果身份验证已存在,则不替换身份验证。将 force 设置为 True 会覆盖此行为。

示例

>>> maybe_add_auth("https://www.conda.io", "user:passwd")
'https://user:[email protected]'
>>> maybe_add_auth("https://www.conda.io", "")
'https://www.conda.io'
maybe_unquote(url)#
remove_auth(url: str) str#

从 URL 中删除嵌入式身份验证。

>>> remove_auth("https://user:[email protected]")
'https://anaconda.com'