Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c0c55af2
Commit
c0c55af2
authored
Oct 18, 2010
by
Hirokazu Yamamoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #5117: Fixed root directory related issue on posixpath.relpath() and
ntpath.relpath().
parent
714fd36b
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
26 additions
and
4 deletions
+26
-4
Lib/ntpath.py
Lib/ntpath.py
+2
-2
Lib/posixpath.py
Lib/posixpath.py
+2
-2
Lib/test/test_ntpath.py
Lib/test/test_ntpath.py
+10
-0
Lib/test/test_posixpath.py
Lib/test/test_posixpath.py
+9
-0
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/ntpath.py
View file @
c0c55af2
...
@@ -488,8 +488,8 @@ def relpath(path, start=curdir):
...
@@ -488,8 +488,8 @@ def relpath(path, start=curdir):
if
not
path
:
if
not
path
:
raise
ValueError
(
"no path specified"
)
raise
ValueError
(
"no path specified"
)
start_list
=
abspath
(
start
).
split
(
sep
)
start_list
=
[
x
for
x
in
abspath
(
start
).
split
(
sep
)
if
x
]
path_list
=
abspath
(
path
).
split
(
sep
)
path_list
=
[
x
for
x
in
abspath
(
path
).
split
(
sep
)
if
x
]
if
start_list
[
0
].
lower
()
!=
path_list
[
0
].
lower
():
if
start_list
[
0
].
lower
()
!=
path_list
[
0
].
lower
():
unc_path
,
rest
=
splitunc
(
path
)
unc_path
,
rest
=
splitunc
(
path
)
unc_start
,
rest
=
splitunc
(
start
)
unc_start
,
rest
=
splitunc
(
start
)
...
...
Lib/posixpath.py
View file @
c0c55af2
...
@@ -403,8 +403,8 @@ def relpath(path, start=curdir):
...
@@ -403,8 +403,8 @@ def relpath(path, start=curdir):
if
not
path
:
if
not
path
:
raise
ValueError
(
"no path specified"
)
raise
ValueError
(
"no path specified"
)
start_list
=
abspath
(
start
).
split
(
sep
)
start_list
=
[
x
for
x
in
abspath
(
start
).
split
(
sep
)
if
x
]
path_list
=
abspath
(
path
).
split
(
sep
)
path_list
=
[
x
for
x
in
abspath
(
path
).
split
(
sep
)
if
x
]
# Work out how much of the filepath is shared by start and path.
# Work out how much of the filepath is shared by start and path.
i
=
len
(
commonprefix
([
start_list
,
path_list
]))
i
=
len
(
commonprefix
([
start_list
,
path_list
]))
...
...
Lib/test/test_ntpath.py
View file @
c0c55af2
...
@@ -178,6 +178,16 @@ class TestNtpath(unittest.TestCase):
...
@@ -178,6 +178,16 @@ class TestNtpath(unittest.TestCase):
tester('
ntpath
.
relpath
(
"a"
,
"b/c"
)
', '
..
\\
..
\\
a
')
tester('
ntpath
.
relpath
(
"a"
,
"b/c"
)
', '
..
\\
..
\\
a
')
tester('
ntpath
.
relpath
(
"//conky/mountpoint/a"
,
"//conky/mountpoint/b/c"
)
', '
..
\\
..
\\
a
')
tester('
ntpath
.
relpath
(
"//conky/mountpoint/a"
,
"//conky/mountpoint/b/c"
)
', '
..
\\
..
\\
a
')
tester('
ntpath
.
relpath
(
"a"
,
"a"
)
', '
.
')
tester('
ntpath
.
relpath
(
"a"
,
"a"
)
', '
.
')
tester('
ntpath
.
relpath
(
"/foo/bar/bat"
,
"/x/y/z"
)
', '
..
\\
..
\\
..
\\
foo
\\
bar
\\
bat
')
tester('
ntpath
.
relpath
(
"/foo/bar/bat"
,
"/foo/bar"
)
', '
bat
')
tester('
ntpath
.
relpath
(
"/foo/bar/bat"
,
"/"
)
', '
foo
\\
bar
\\
bat
')
tester('
ntpath
.
relpath
(
"/"
,
"/foo/bar/bat"
)
', '
..
\\
..
\\
..
')
tester('
ntpath
.
relpath
(
"/foo/bar/bat"
,
"/x"
)
', '
..
\\
foo
\\
bar
\\
bat
')
tester('
ntpath
.
relpath
(
"/x"
,
"/foo/bar/bat"
)
', '
..
\\
..
\\
..
\\
x
')
tester('
ntpath
.
relpath
(
"/"
,
"/"
)
', '
.
')
tester('
ntpath
.
relpath
(
"/a"
,
"/a"
)
', '
.
')
tester('
ntpath
.
relpath
(
"/a/b"
,
"/a/b"
)
', '
.
')
tester('
ntpath
.
relpath
(
"c:/foo"
,
"C:/FOO"
)
', '
.
')
class NtCommonTest(test_genericpath.CommonTest):
class NtCommonTest(test_genericpath.CommonTest):
...
...
Lib/test/test_posixpath.py
View file @
c0c55af2
...
@@ -322,6 +322,15 @@ class PosixPathTest(unittest.TestCase):
...
@@ -322,6 +322,15 @@ class PosixPathTest(unittest.TestCase):
self
.
assertEqual
(
posixpath
.
relpath
(
"a/b"
,
"../c"
),
"../"
+
curdir
+
"/a/b"
)
self
.
assertEqual
(
posixpath
.
relpath
(
"a/b"
,
"../c"
),
"../"
+
curdir
+
"/a/b"
)
self
.
assertEqual
(
posixpath
.
relpath
(
"a"
,
"b/c"
),
"../../a"
)
self
.
assertEqual
(
posixpath
.
relpath
(
"a"
,
"b/c"
),
"../../a"
)
self
.
assertEqual
(
posixpath
.
relpath
(
"a"
,
"a"
),
"."
)
self
.
assertEqual
(
posixpath
.
relpath
(
"a"
,
"a"
),
"."
)
self
.
assertEqual
(
posixpath
.
relpath
(
"/foo/bar/bat"
,
"/x/y/z"
),
'../../../foo/bar/bat'
)
self
.
assertEqual
(
posixpath
.
relpath
(
"/foo/bar/bat"
,
"/foo/bar"
),
'bat'
)
self
.
assertEqual
(
posixpath
.
relpath
(
"/foo/bar/bat"
,
"/"
),
'foo/bar/bat'
)
self
.
assertEqual
(
posixpath
.
relpath
(
"/"
,
"/foo/bar/bat"
),
'../../..'
)
self
.
assertEqual
(
posixpath
.
relpath
(
"/foo/bar/bat"
,
"/x"
),
'../foo/bar/bat'
)
self
.
assertEqual
(
posixpath
.
relpath
(
"/x"
,
"/foo/bar/bat"
),
'../../../x'
)
self
.
assertEqual
(
posixpath
.
relpath
(
"/"
,
"/"
),
'.'
)
self
.
assertEqual
(
posixpath
.
relpath
(
"/a"
,
"/a"
),
'.'
)
self
.
assertEqual
(
posixpath
.
relpath
(
"/a/b"
,
"/a/b"
),
'.'
)
finally
:
finally
:
os
.
getcwd
=
real_getcwd
os
.
getcwd
=
real_getcwd
...
...
Misc/NEWS
View file @
c0c55af2
...
@@ -60,6 +60,9 @@ Core and Builtins
...
@@ -60,6 +60,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #5117: Fixed root directory related issue on posixpath.relpath() and
ntpath.relpath().
- Issue 9409: Fix the regex to match all kind of filenames, for interactive
- Issue 9409: Fix the regex to match all kind of filenames, for interactive
debugging in doctests.
debugging in doctests.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment