Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
镜像
Python_Packaging_Authority
pip
提交
2d450936
P
pip
项目概览
镜像
/
Python_Packaging_Authority
/
pip
12 个月 前同步成功
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
P
pip
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
2d450936
编写于
5月 26, 2019
作者:
C
Chris Jerdonek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move path_to_url() from download.py to misc.py.
上级
30855ff9
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
33 addition
and
32 deletion
+33
-32
src/pip/_internal/download.py
src/pip/_internal/download.py
+2
-13
src/pip/_internal/utils/misc.py
src/pip/_internal/utils/misc.py
+12
-0
tests/unit/test_download.py
tests/unit/test_download.py
+0
-17
tests/unit/test_utils.py
tests/unit/test_utils.py
+19
-2
未找到文件。
src/pip/_internal/download.py
浏览文件 @
2d450936
...
...
@@ -37,8 +37,8 @@ from pip._internal.utils.glibc import libc_ver
from
pip._internal.utils.misc
import
(
ARCHIVE_EXTENSIONS
,
ask
,
ask_input
,
ask_password
,
ask_path_exists
,
backup_dir
,
consume
,
display_path
,
format_size
,
get_installed_version
,
remove_auth_from_url
,
rmtree
,
split_auth_netloc_from_url
,
splitext
,
unpack_file
,
path_to_url
,
remove_auth_from_url
,
rmtree
,
split_auth_netloc_from_url
,
splitext
,
unpack_file
,
)
from
pip._internal.utils.temp_dir
import
TempDirectory
from
pip._internal.utils.typing
import
MYPY_CHECK_RUNNING
...
...
@@ -693,17 +693,6 @@ def url_to_path(url):
return
path
def
path_to_url
(
path
):
# type: (Union[str, Text]) -> str
"""
Convert a path to a file: URL. The path will be made absolute and have
quoted path parts.
"""
path
=
os
.
path
.
normpath
(
os
.
path
.
abspath
(
path
))
url
=
urllib_parse
.
urljoin
(
'file:'
,
urllib_request
.
pathname2url
(
path
))
return
url
def
is_archive_file
(
name
):
# type: (str) -> bool
"""Return True if `name` is a considered as an archive file."""
...
...
src/pip/_internal/utils/misc.py
浏览文件 @
2d450936
...
...
@@ -25,6 +25,7 @@ from pip._vendor.retrying import retry # type: ignore
from
pip._vendor.six
import
PY2
from
pip._vendor.six.moves
import
input
,
shlex_quote
from
pip._vendor.six.moves.urllib
import
parse
as
urllib_parse
from
pip._vendor.six.moves.urllib
import
request
as
urllib_request
from
pip._vendor.six.moves.urllib.parse
import
unquote
as
urllib_unquote
from
pip._internal.exceptions
import
CommandError
,
InstallationError
...
...
@@ -931,6 +932,17 @@ def enum(*sequential, **named):
return
type
(
'Enum'
,
(),
enums
)
def
path_to_url
(
path
):
# type: (Union[str, Text]) -> str
"""
Convert a path to a file: URL. The path will be made absolute and have
quoted path parts.
"""
path
=
os
.
path
.
normpath
(
os
.
path
.
abspath
(
path
))
url
=
urllib_parse
.
urljoin
(
'file:'
,
urllib_request
.
pathname2url
(
path
))
return
url
def
split_auth_from_netloc
(
netloc
):
"""
Parse out and remove the auth information from a netloc.
...
...
tests/unit/test_download.py
浏览文件 @
2d450936
...
...
@@ -8,7 +8,6 @@ from tempfile import mkdtemp
import
pytest
from
mock
import
Mock
,
patch
from
pip._vendor.six.moves.urllib
import
request
as
urllib_request
import
pip
from
pip._internal.download
import
(
...
...
@@ -199,22 +198,6 @@ def test_unpack_http_url_bad_downloaded_checksum(mock_unpack_file):
rmtree
(
download_dir
)
@
pytest
.
mark
.
skipif
(
"sys.platform == 'win32'"
)
def
test_path_to_url_unix
():
assert
path_to_url
(
'/tmp/file'
)
==
'file:///tmp/file'
path
=
os
.
path
.
join
(
os
.
getcwd
(),
'file'
)
assert
path_to_url
(
'file'
)
==
'file://'
+
urllib_request
.
pathname2url
(
path
)
@
pytest
.
mark
.
skipif
(
"sys.platform != 'win32'"
)
def
test_path_to_url_win
():
assert
path_to_url
(
'c:/tmp/file'
)
==
'file:///C:/tmp/file'
assert
path_to_url
(
'c:
\\
tmp
\\
file'
)
==
'file:///C:/tmp/file'
assert
path_to_url
(
r
'\\unc\as\path'
)
==
'file://unc/as/path'
path
=
os
.
path
.
join
(
os
.
getcwd
(),
'file'
)
assert
path_to_url
(
'file'
)
==
'file:'
+
urllib_request
.
pathname2url
(
path
)
@
pytest
.
mark
.
parametrize
(
"url,win_expected,non_win_expected"
,
[
(
'file:tmp'
,
'tmp'
,
'tmp'
),
(
'file:c:/path/to/file'
,
r
'C:\path\to\file'
,
'c:/path/to/file'
),
...
...
tests/unit/test_utils.py
浏览文件 @
2d450936
...
...
@@ -18,6 +18,7 @@ from logging import DEBUG, ERROR, INFO, WARNING
import
pytest
from
mock
import
Mock
,
patch
from
pip._vendor.six.moves.urllib
import
request
as
urllib_request
from
pip._internal.exceptions
import
(
HashMismatch
,
HashMissing
,
InstallationError
,
...
...
@@ -27,8 +28,8 @@ from pip._internal.utils.glibc import check_glibc_version
from
pip._internal.utils.hashes
import
Hashes
,
MissingHashes
from
pip._internal.utils.misc
import
(
call_subprocess
,
egg_link_path
,
ensure_dir
,
format_command_args
,
get_installed_distributions
,
get_prog
,
normalize_path
,
redact_netloc
,
redact_password_from_url
,
remove_auth_from_url
,
rmtree
,
get_installed_distributions
,
get_prog
,
normalize_path
,
path_to_url
,
redact_
netloc
,
redact_
password_from_url
,
remove_auth_from_url
,
rmtree
,
split_auth_from_netloc
,
split_auth_netloc_from_url
,
untar_file
,
unzip_file
,
)
from
pip._internal.utils.temp_dir
import
AdjacentTempDirectory
,
TempDirectory
...
...
@@ -964,6 +965,22 @@ class TestCallSubprocess(object):
)
@
pytest
.
mark
.
skipif
(
"sys.platform == 'win32'"
)
def
test_path_to_url_unix
():
assert
path_to_url
(
'/tmp/file'
)
==
'file:///tmp/file'
path
=
os
.
path
.
join
(
os
.
getcwd
(),
'file'
)
assert
path_to_url
(
'file'
)
==
'file://'
+
urllib_request
.
pathname2url
(
path
)
@
pytest
.
mark
.
skipif
(
"sys.platform != 'win32'"
)
def
test_path_to_url_win
():
assert
path_to_url
(
'c:/tmp/file'
)
==
'file:///C:/tmp/file'
assert
path_to_url
(
'c:
\\
tmp
\\
file'
)
==
'file:///C:/tmp/file'
assert
path_to_url
(
r
'\\unc\as\path'
)
==
'file://unc/as/path'
path
=
os
.
path
.
join
(
os
.
getcwd
(),
'file'
)
assert
path_to_url
(
'file'
)
==
'file:'
+
urllib_request
.
pathname2url
(
path
)
@
pytest
.
mark
.
parametrize
(
'netloc, expected'
,
[
# Test a basic case.
(
'example.com'
,
(
'example.com'
,
(
None
,
None
))),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录