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
40e8246f
Commit
40e8246f
authored
Nov 20, 2008
by
Barry Warsaw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix for bug 4362 "FileIO object in io module"; Patch by amaury.forgeotdarc.
parent
91cc8fb9
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
10 deletions
+47
-10
Lib/io.py
Lib/io.py
+16
-10
Lib/test/test_io.py
Lib/test/test_io.py
+31
-0
No files found.
Lib/io.py
View file @
40e8246f
...
@@ -239,8 +239,6 @@ def open(file, mode="r", buffering=None, encoding=None, errors=None,
...
@@ -239,8 +239,6 @@ def open(file, mode="r", buffering=None, encoding=None, errors=None,
raise
ValueError
(
"invalid buffering size"
)
raise
ValueError
(
"invalid buffering size"
)
if
buffering
==
0
:
if
buffering
==
0
:
if
binary
:
if
binary
:
raw
.
_name
=
file
raw
.
_mode
=
mode
return
raw
return
raw
raise
ValueError
(
"can't have unbuffered text I/O"
)
raise
ValueError
(
"can't have unbuffered text I/O"
)
if
updating
:
if
updating
:
...
@@ -252,11 +250,8 @@ def open(file, mode="r", buffering=None, encoding=None, errors=None,
...
@@ -252,11 +250,8 @@ def open(file, mode="r", buffering=None, encoding=None, errors=None,
else
:
else
:
raise
ValueError
(
"unknown mode: %r"
%
mode
)
raise
ValueError
(
"unknown mode: %r"
%
mode
)
if
binary
:
if
binary
:
buffer
.
name
=
file
buffer
.
mode
=
mode
return
buffer
return
buffer
text
=
TextIOWrapper
(
buffer
,
encoding
,
errors
,
newline
,
line_buffering
)
text
=
TextIOWrapper
(
buffer
,
encoding
,
errors
,
newline
,
line_buffering
)
text
.
name
=
file
text
.
mode
=
mode
text
.
mode
=
mode
return
text
return
text
...
@@ -616,6 +611,10 @@ class FileIO(_fileio._FileIO, RawIOBase):
...
@@ -616,6 +611,10 @@ class FileIO(_fileio._FileIO, RawIOBase):
# that _fileio._FileIO inherits from io.RawIOBase (which would be hard
# that _fileio._FileIO inherits from io.RawIOBase (which would be hard
# to do since _fileio.c is written in C).
# to do since _fileio.c is written in C).
def
__init__
(
self
,
name
,
mode
=
"r"
,
closefd
=
True
):
_fileio
.
_FileIO
.
__init__
(
self
,
name
,
mode
,
closefd
)
self
.
_name
=
name
def
close
(
self
):
def
close
(
self
):
_fileio
.
_FileIO
.
close
(
self
)
_fileio
.
_FileIO
.
close
(
self
)
RawIOBase
.
close
(
self
)
RawIOBase
.
close
(
self
)
...
@@ -624,11 +623,6 @@ class FileIO(_fileio._FileIO, RawIOBase):
...
@@ -624,11 +623,6 @@ class FileIO(_fileio._FileIO, RawIOBase):
def
name
(
self
):
def
name
(
self
):
return
self
.
_name
return
self
.
_name
# XXX(gb): _FileIO already has a mode property
@
property
def
mode
(
self
):
return
self
.
_mode
class
BufferedIOBase
(
IOBase
):
class
BufferedIOBase
(
IOBase
):
...
@@ -762,6 +756,14 @@ class _BufferedIOMixin(BufferedIOBase):
...
@@ -762,6 +756,14 @@ class _BufferedIOMixin(BufferedIOBase):
def
closed
(
self
):
def
closed
(
self
):
return
self
.
raw
.
closed
return
self
.
raw
.
closed
@
property
def
name
(
self
):
return
self
.
raw
.
name
@
property
def
mode
(
self
):
return
self
.
raw
.
mode
### Lower-level APIs ###
### Lower-level APIs ###
def
fileno
(
self
):
def
fileno
(
self
):
...
@@ -1464,6 +1466,10 @@ class TextIOWrapper(TextIOBase):
...
@@ -1464,6 +1466,10 @@ class TextIOWrapper(TextIOBase):
def
closed
(
self
):
def
closed
(
self
):
return
self
.
buffer
.
closed
return
self
.
buffer
.
closed
@
property
def
name
(
self
):
return
self
.
buffer
.
name
def
fileno
(
self
):
def
fileno
(
self
):
return
self
.
buffer
.
fileno
()
return
self
.
buffer
.
fileno
()
...
...
Lib/test/test_io.py
View file @
40e8246f
...
@@ -1249,6 +1249,9 @@ class TextIOWrapperTest(unittest.TestCase):
...
@@ -1249,6 +1249,9 @@ class TextIOWrapperTest(unittest.TestCase):
class
MiscIOTest
(
unittest
.
TestCase
):
class
MiscIOTest
(
unittest
.
TestCase
):
def
tearDown
(
self
):
support
.
unlink
(
support
.
TESTFN
)
def
testImport__all__
(
self
):
def
testImport__all__
(
self
):
for
name
in
io
.
__all__
:
for
name
in
io
.
__all__
:
obj
=
getattr
(
io
,
name
,
None
)
obj
=
getattr
(
io
,
name
,
None
)
...
@@ -1261,6 +1264,34 @@ class MiscIOTest(unittest.TestCase):
...
@@ -1261,6 +1264,34 @@ class MiscIOTest(unittest.TestCase):
self
.
assert_
(
issubclass
(
obj
,
io
.
IOBase
))
self
.
assert_
(
issubclass
(
obj
,
io
.
IOBase
))
def
test_attributes
(
self
):
f
=
io
.
open
(
support
.
TESTFN
,
"wb"
,
buffering
=
0
)
self
.
assertEquals
(
f
.
mode
,
"w"
)
f
.
close
()
f
=
io
.
open
(
support
.
TESTFN
,
"U"
)
self
.
assertEquals
(
f
.
name
,
support
.
TESTFN
)
self
.
assertEquals
(
f
.
buffer
.
name
,
support
.
TESTFN
)
self
.
assertEquals
(
f
.
buffer
.
raw
.
name
,
support
.
TESTFN
)
self
.
assertEquals
(
f
.
mode
,
"U"
)
self
.
assertEquals
(
f
.
buffer
.
mode
,
"r"
)
self
.
assertEquals
(
f
.
buffer
.
raw
.
mode
,
"r"
)
f
.
close
()
f
=
io
.
open
(
support
.
TESTFN
,
"w+"
)
self
.
assertEquals
(
f
.
mode
,
"w+"
)
self
.
assertEquals
(
f
.
buffer
.
mode
,
"r+"
)
# Does it really matter?
self
.
assertEquals
(
f
.
buffer
.
raw
.
mode
,
"r+"
)
g
=
io
.
open
(
f
.
fileno
(),
"wb"
,
closefd
=
False
)
self
.
assertEquals
(
g
.
mode
,
"w"
)
self
.
assertEquals
(
g
.
raw
.
mode
,
"w"
)
self
.
assertEquals
(
g
.
name
,
f
.
fileno
())
self
.
assertEquals
(
g
.
raw
.
name
,
f
.
fileno
())
f
.
close
()
g
.
close
()
def
test_main
():
def
test_main
():
support
.
run_unittest
(
IOTest
,
BytesIOTest
,
StringIOTest
,
support
.
run_unittest
(
IOTest
,
BytesIOTest
,
StringIOTest
,
BufferedReaderTest
,
BufferedWriterTest
,
BufferedReaderTest
,
BufferedWriterTest
,
...
...
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