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
ee47991d
Commit
ee47991d
authored
Jul 10, 2012
by
willmcgugan@gmail.com
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added closing context manager to files returned by open
parent
0dc13500
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
6 deletions
+8
-6
fs/zipfs.py
+8
-6
No files found.
fs/zipfs.py
View file @
ee47991d
...
@@ -8,6 +8,7 @@ A FS object that represents the contents of a Zip file
...
@@ -8,6 +8,7 @@ A FS object that represents the contents of a Zip file
import
datetime
import
datetime
import
os.path
import
os.path
from
contextlib
import
closing
from
fs.base
import
*
from
fs.base
import
*
from
fs.path
import
*
from
fs.path
import
*
...
@@ -32,7 +33,6 @@ class ZipNotFoundError(CreateFailedError):
...
@@ -32,7 +33,6 @@ class ZipNotFoundError(CreateFailedError):
class
_TempWriteFile
(
object
):
class
_TempWriteFile
(
object
):
"""Proxies a file object and calls a callback when the file is closed."""
"""Proxies a file object and calls a callback when the file is closed."""
def
__init__
(
self
,
fs
,
filename
,
close_callback
):
def
__init__
(
self
,
fs
,
filename
,
close_callback
):
...
@@ -54,9 +54,14 @@ class _TempWriteFile(object):
...
@@ -54,9 +54,14 @@ class _TempWriteFile(object):
def
flush
(
self
):
def
flush
(
self
):
self
.
_file
.
flush
()
self
.
_file
.
flush
()
def
__enter__
(
self
):
return
self
class
_ExceptionProxy
(
object
):
def
__exit__
(
self
,
type
,
value
,
traceback
):
self
.
close
()
class
_ExceptionProxy
(
object
):
"""A placeholder for an object that may no longer be used."""
"""A placeholder for an object that may no longer be used."""
def
__getattr__
(
self
,
name
):
def
__getattr__
(
self
,
name
):
...
@@ -70,7 +75,6 @@ class _ExceptionProxy(object):
...
@@ -70,7 +75,6 @@ class _ExceptionProxy(object):
class
ZipFS
(
FS
):
class
ZipFS
(
FS
):
"""A FileSystem that represents a zip file."""
"""A FileSystem that represents a zip file."""
_meta
=
{
'thread_safe'
:
True
,
_meta
=
{
'thread_safe'
:
True
,
...
@@ -177,7 +181,6 @@ class ZipFS(FS):
...
@@ -177,7 +181,6 @@ class ZipFS(FS):
return
self
.
read_only
return
self
.
read_only
return
super
(
ZipFS
,
self
)
.
getmeta
(
meta_name
,
default
)
return
super
(
ZipFS
,
self
)
.
getmeta
(
meta_name
,
default
)
def
close
(
self
):
def
close
(
self
):
"""Finalizes the zip file so that it can be read.
"""Finalizes the zip file so that it can be read.
No further operations will work after this method is called."""
No further operations will work after this method is called."""
...
@@ -202,7 +205,7 @@ class ZipFS(FS):
...
@@ -202,7 +205,7 @@ class ZipFS(FS):
contents
=
self
.
zf
.
read
(
self
.
_encode_path
(
path
))
contents
=
self
.
zf
.
read
(
self
.
_encode_path
(
path
))
except
KeyError
:
except
KeyError
:
raise
ResourceNotFoundError
(
path
)
raise
ResourceNotFoundError
(
path
)
return
StringIO
(
contents
)
return
closing
(
StringIO
(
contents
)
)
if
'w'
in
mode
:
if
'w'
in
mode
:
if
self
.
zip_mode
not
in
'wa'
:
if
self
.
zip_mode
not
in
'wa'
:
...
@@ -215,7 +218,6 @@ class ZipFS(FS):
...
@@ -215,7 +218,6 @@ class ZipFS(FS):
self
.
_add_resource
(
path
)
self
.
_add_resource
(
path
)
f
=
_TempWriteFile
(
self
.
temp_fs
,
path
,
self
.
_on_write_close
)
f
=
_TempWriteFile
(
self
.
temp_fs
,
path
,
self
.
_on_write_close
)
return
f
return
f
raise
ValueError
(
"Mode must contain be 'r' or 'w'"
)
raise
ValueError
(
"Mode must contain be 'r' or 'w'"
)
...
...
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