Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
pyfs
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
OpenEdx
pyfs
Commits
0b8d5041
Commit
0b8d5041
authored
Sep 10, 2008
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added friendly exception if ZipFS is used after the zip file is closed...
parent
8d890abf
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
2 deletions
+18
-2
fs/zipfs.py
+18
-2
No files found.
fs/zipfs.py
View file @
0b8d5041
...
...
@@ -30,6 +30,17 @@ class _TempWriteFile(object):
self
.
_file
.
close
()
self
.
close_callback
(
self
.
filename
)
class
_ExceptionProxy
(
object
):
def
__getattr__
(
self
,
name
):
raise
ValueError
(
"Zip file has been closed"
)
def
__setattr__
(
self
,
name
,
value
):
raise
ValueError
(
"Zip file has been closed"
)
def
__nonzero__
(
self
):
return
False
class
ZipFS
(
FS
):
def
__init__
(
self
,
zip_file
,
mode
=
"r"
,
compression
=
"deflated"
,
allowZip64
=
False
):
...
...
@@ -56,15 +67,17 @@ class ZipFS(FS):
self
.
resource_list
=
self
.
zf
.
namelist
()
def
_get_resource_list
(
self
):
if
not
self
.
zf
:
raise
ValueError
(
"Zip file has been closed"
)
return
self
.
resource_list
or
self
.
zf
.
namelist
()
def
close
(
self
):
"""Finalizes the zip file so that it can be read.
No further operations will work after this method is called."""
if
self
.
zf
is
not
None
:
if
self
.
zf
:
self
.
zf
.
close
()
self
.
zf
=
None
self
.
zf
=
_ExceptionProxy
()
def
__del__
(
self
):
self
.
close
()
...
...
@@ -125,6 +138,9 @@ if __name__ == "__main__":
zfs
=
ZipFS
(
"t2.zip"
,
"r"
)
print
zfs
.
listdir
(
"/tagging-trunk"
)
print
zfs
.
listdir
(
"/"
)
zfs
.
close
()
zfs
.
open
(
"t.txt"
)
print
zfs
.
listdir
(
"/"
)
test2
()
#zfs.close()
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