summaryrefslogtreecommitdiffstats
path: root/Lib/io.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2008-11-20 22:06:22 (GMT)
committerBenjamin Peterson <benjamin@python.org>2008-11-20 22:06:22 (GMT)
commitad100c3acb566a8a9a6094a9ace96c6399fab394 (patch)
tree21dff80c1f818f11ab0bc4844f02fde2e30e2c10 /Lib/io.py
parentd3b5a7985d81fd28fe970ab5d7429fa57e723e2c (diff)
downloadcpython-ad100c3acb566a8a9a6094a9ace96c6399fab394.zip
cpython-ad100c3acb566a8a9a6094a9ace96c6399fab394.tar.gz
cpython-ad100c3acb566a8a9a6094a9ace96c6399fab394.tar.bz2
backport r67300
Diffstat (limited to 'Lib/io.py')
-rw-r--r--Lib/io.py25
1 files changed, 16 insertions, 9 deletions
diff --git a/Lib/io.py b/Lib/io.py
index 8462dd5..110804e 100644
--- a/Lib/io.py
+++ b/Lib/io.py
@@ -238,8 +238,6 @@ def open(file, mode="r", buffering=None, encoding=None, errors=None,
raise ValueError("invalid buffering size")
if buffering == 0:
if binary:
- raw._name = file
- raw._mode = mode
return raw
raise ValueError("can't have unbuffered text I/O")
if updating:
@@ -251,11 +249,8 @@ def open(file, mode="r", buffering=None, encoding=None, errors=None,
else:
raise ValueError("unknown mode: %r" % mode)
if binary:
- buffer.name = file
- buffer.mode = mode
return buffer
text = TextIOWrapper(buffer, encoding, errors, newline, line_buffering)
- text.name = file
text.mode = mode
return text
@@ -622,6 +617,10 @@ class FileIO(_fileio._FileIO, RawIOBase):
# that _fileio._FileIO inherits from io.RawIOBase (which would be hard
# 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):
_fileio._FileIO.close(self)
RawIOBase.close(self)
@@ -630,10 +629,6 @@ class FileIO(_fileio._FileIO, RawIOBase):
def name(self):
return self._name
- @property
- def mode(self):
- return self._mode
-
class BufferedIOBase(IOBase):
@@ -767,6 +762,14 @@ class _BufferedIOMixin(BufferedIOBase):
def closed(self):
return self.raw.closed
+ @property
+ def name(self):
+ return self.raw.name
+
+ @property
+ def mode(self):
+ return self.raw.mode
+
### Lower-level APIs ###
def fileno(self):
@@ -1473,6 +1476,10 @@ class TextIOWrapper(TextIOBase):
def closed(self):
return self.buffer.closed
+ @property
+ def name(self):
+ return self.buffer.name
+
def fileno(self):
return self.buffer.fileno()