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
b4f07bec
Commit
b4f07bec
authored
Apr 10, 2012
by
gcode@loowis.durge.org
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
memoryfs.MemoryFile read() and write() methods now respect the file's open
mode. Fixes Issue113.
parent
83370fc4
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
0 deletions
+12
-0
fs/memoryfs.py
+12
-0
No files found.
fs/memoryfs.py
View file @
b4f07bec
...
...
@@ -89,16 +89,22 @@ class MemoryFile(object):
pass
def
__iter__
(
self
):
if
'r'
not
in
self
.
mode
and
'+'
not
in
self
.
mode
:
raise
IOError
(
"File not open for reading"
)
self
.
mem_file
.
seek
(
self
.
pos
)
for
line
in
self
.
mem_file
:
yield
line
@seek_and_lock
def
next
(
self
):
if
'r'
not
in
self
.
mode
and
'+'
not
in
self
.
mode
:
raise
IOError
(
"File not open for reading"
)
return
self
.
mem_file
.
next
()
@seek_and_lock
def
readline
(
self
,
*
args
,
**
kwargs
):
if
'r'
not
in
self
.
mode
and
'+'
not
in
self
.
mode
:
raise
IOError
(
"File not open for reading"
)
return
self
.
mem_file
.
readline
(
*
args
,
**
kwargs
)
def
close
(
self
):
...
...
@@ -115,6 +121,8 @@ class MemoryFile(object):
@seek_and_lock
def
read
(
self
,
size
=
None
):
if
'r'
not
in
self
.
mode
and
'+'
not
in
self
.
mode
:
raise
IOError
(
"File not open for reading"
)
if
size
is
None
:
size
=
-
1
return
self
.
mem_file
.
read
(
size
)
...
...
@@ -129,10 +137,14 @@ class MemoryFile(object):
@seek_and_lock
def
truncate
(
self
,
*
args
,
**
kwargs
):
if
'r'
in
self
.
mode
and
'+'
not
in
self
.
mode
:
raise
IOError
(
"File not open for writing"
)
return
self
.
mem_file
.
truncate
(
*
args
,
**
kwargs
)
#@seek_and_lock
def
write
(
self
,
data
):
if
'r'
in
self
.
mode
and
'+'
not
in
self
.
mode
:
raise
IOError
(
"File not open for writing"
)
self
.
memory_fs
.
_on_modify_memory_file
(
self
.
path
)
self
.
_lock
.
acquire
()
try
:
...
...
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