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
33e067d6
Commit
33e067d6
authored
May 09, 2019
by
Jason R. Coombs
Committed by
Barry Warsaw
May 09, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add support for .parent and .joinpath in zipfile.Path (#13213)
parent
afd1e6d2
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
1 deletion
+24
-1
Lib/test/test_zipfile.py
Lib/test/test_zipfile.py
+14
-0
Lib/zipfile.py
Lib/zipfile.py
+10
-1
No files found.
Lib/test/test_zipfile.py
View file @
33e067d6
...
...
@@ -2481,6 +2481,14 @@ class TestPath(unittest.TestCase):
assert
a
.
read_text
()
==
"content of a"
assert
a
.
read_bytes
()
==
b"content of a"
def
test_joinpath
(
self
):
for
zipfile_abcde
in
self
.
zipfile_abcde
():
root
=
zipfile
.
Path
(
zipfile_abcde
)
a
=
root
.
joinpath
(
"a"
)
assert
a
.
is_file
()
e
=
root
.
joinpath
(
"b"
).
joinpath
(
"d"
).
joinpath
(
"e.txt"
)
assert
e
.
read_text
()
==
"content of e"
def
test_traverse_truediv
(
self
):
for
zipfile_abcde
in
self
.
zipfile_abcde
():
root
=
zipfile
.
Path
(
zipfile_abcde
)
...
...
@@ -2502,5 +2510,11 @@ class TestPath(unittest.TestCase):
root
=
zipfile
.
Path
(
zipfile_abcde
)
root
/
pathlib
.
Path
(
"a"
)
def
test_parent
(
self
):
for
zipfile_abcde
in
self
.
zipfile_abcde
():
root
=
zipfile
.
Path
(
zipfile_abcde
)
assert
(
root
/
'a'
).
parent
.
at
==
''
assert
(
root
/
'a'
/
'b'
).
parent
.
at
==
'a/'
if
__name__
==
"__main__"
:
unittest
.
main
()
Lib/zipfile.py
View file @
33e067d6
...
...
@@ -2218,12 +2218,14 @@ class Path:
def
__repr__
(
self
):
return
self
.
__repr
.
format
(
self
=
self
)
def
__truediv__
(
self
,
add
):
def
joinpath
(
self
,
add
):
next
=
posixpath
.
join
(
self
.
at
,
add
)
next_dir
=
posixpath
.
join
(
self
.
at
,
add
,
""
)
names
=
self
.
_names
()
return
self
.
_next
(
next_dir
if
next
not
in
names
and
next_dir
in
names
else
next
)
__truediv__
=
joinpath
@
staticmethod
def
_add_implied_dirs
(
names
):
return
names
+
[
...
...
@@ -2232,6 +2234,13 @@ class Path:
if
name
and
name
+
"/"
not
in
names
]
@
property
def
parent
(
self
):
parent_at
=
posixpath
.
dirname
(
self
.
at
)
if
parent_at
:
parent_at
+=
'/'
return
self
.
_next
(
parent_at
)
def
_names
(
self
):
return
self
.
_add_implied_dirs
(
self
.
root
.
namelist
())
...
...
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