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
69aed4c7
Commit
69aed4c7
authored
Nov 13, 2010
by
willmcgugan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed meta form zip files, and added some more error handling
parent
d4a910f9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
18 additions
and
7 deletions
+18
-7
fs/zipfs.py
+18
-7
No files found.
fs/zipfs.py
View file @
69aed4c7
...
...
@@ -71,8 +71,8 @@ class ZipFS(FS):
_meta
=
{
'virtual'
:
False
,
'read_only'
:
False
,
'unicode_paths'
:
os
.
path
.
supports_unicode_filenames
,
'case_insensitive_paths'
:
os
.
path
.
normcase
(
'Aa'
)
==
'aa'
,
'unicode_paths'
:
True
,
'case_insensitive_paths'
:
False
,
}
def
__init__
(
self
,
zip_file
,
mode
=
"r"
,
compression
=
"deflated"
,
allow_zip_64
=
False
,
encoding
=
"CP437"
,
thread_synchronize
=
True
):
...
...
@@ -113,8 +113,7 @@ class ZipFS(FS):
raise
ZipNotFoundError
(
"Zip file not found (
%
s)"
%
str
(
zip_file
),
details
=
ioe
)
self
.
zip_path
=
str
(
zip_file
)
self
.
zip_path
=
str
(
zip_file
)
self
.
temp_fs
=
None
if
mode
in
'wa'
:
self
.
temp_fs
=
tempfs
.
TempFS
()
...
...
@@ -122,8 +121,8 @@ class ZipFS(FS):
self
.
_path_fs
=
MemoryFS
()
if
mode
in
'ra'
:
self
.
_parse_resource_list
()
self
.
_meta
[
'read_only'
]
=
self
.
zip_mode
!=
'w'
self
.
read_only
=
mode
==
'r'
def
__str__
(
self
):
return
"<ZipFS:
%
s>"
%
self
.
zip_path
...
...
@@ -147,6 +146,12 @@ class ZipFS(FS):
f
=
self
.
_path_fs
.
open
(
path
,
'w'
)
f
.
close
()
def
getmeta
(
self
,
meta_name
,
default
=
Ellipsis
):
if
meta_name
==
'read_only'
:
return
self
.
read_only
return
super
(
ZipFS
,
self
)
.
getmeta
(
meta_name
,
default
)
def
close
(
self
):
"""Finalizes the zip file so that it can be read.
No further operations will work after this method is called."""
...
...
@@ -161,7 +166,9 @@ class ZipFS(FS):
if
'r'
in
mode
:
if
self
.
zip_mode
not
in
'ra'
:
raise
OperationFailedError
(
"open file"
,
path
=
path
,
msg
=
"Zip file must be opened for reading ('r') or appending ('a')"
)
raise
OperationFailedError
(
"open file"
,
path
=
path
,
msg
=
"Zip file must be opened for reading ('r') or appending ('a')"
)
try
:
contents
=
self
.
zf
.
read
(
path
.
encode
(
self
.
encoding
))
except
KeyError
:
...
...
@@ -169,6 +176,10 @@ class ZipFS(FS):
return
StringIO
(
contents
)
if
'w'
in
mode
:
if
self
.
zip_mode
not
in
'wa'
:
raise
OperationFailedError
(
"open file"
,
path
=
path
,
msg
=
"Zip file must be opened for writing ('w') or appending ('a')"
)
dirname
,
filename
=
pathsplit
(
path
)
if
dirname
:
self
.
temp_fs
.
makedir
(
dirname
,
recursive
=
True
,
allow_recreate
=
True
)
...
...
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