[pypy-svn] r7580 - pypy/trunk/src/pypy/appspace
jacob at codespeak.net
jacob at codespeak.net
Mon Nov 22 19:46:12 CET 2004
Author: jacob
Date: Mon Nov 22 19:46:10 2004
New Revision: 7580
Modified:
pypy/trunk/src/pypy/appspace/_file.py
pypy/trunk/src/pypy/appspace/sio.py
Log:
Fixing readonly.
Modified: pypy/trunk/src/pypy/appspace/_file.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/_file.py (original)
+++ pypy/trunk/src/pypy/appspace/_file.py Mon Nov 22 19:46:10 2004
@@ -38,12 +38,18 @@
if bufsize < 0:
bufsize = None
if not self.writing and (bufsize is None or bufsize > 0):
+ "Read only buffered stream."
self.fd = sio.BufferingInputStream(self.fd, bufsize)
if not self.reading:
if bufsize is None or bufsize > 1:
+ "Write only buffered stream."
self.fd = sio.BufferingOutputStream(self.fd, bufsize)
elif bufsize == 1:
self.fd = sio.LineBufferingOutputStream(self.fd)
+ if self.reading and self.writing:
+ if bufsize > 2:
+ "Read and write buffered stream."
+ self.fd = sio.BufferingInputOutputStream(self.fd, bufsize)
return self.fd
def __getattr__(self, name):
@@ -54,8 +60,8 @@
"""
return getattr(self.fd, name)
- def __setattr__(self, name):
+ def __setattr__(self, attr, val):
"Make some attributes readonly."
- if name in ['mode', 'name', 'closed']:
- raise TypeError('readonly attribute')
- return setattr(self, name)
+ if attr in ['mode', 'name', 'closed', 'encoding']:
+ raise TypeError('readonly attribute: %s' % attr)
+ self.__dict__[attr] = val
Modified: pypy/trunk/src/pypy/appspace/sio.py
==============================================================================
--- pypy/trunk/src/pypy/appspace/sio.py (original)
+++ pypy/trunk/src/pypy/appspace/sio.py Mon Nov 22 19:46:10 2004
@@ -34,7 +34,9 @@
import os
import mmap
+
class Stream(object):
+ "All streams except the base ones need to inherit from this class."
def __getattr__(self, name):
"""
Delegate all other methods to the underlying file object.
@@ -309,6 +311,10 @@
self.buf = ''
self.write(data[self.bufsize-buflen:])
+ def writelines(self, sequence):
+ for s in sequence:
+ self.write(s)
+
def close(self):
self.do_write(self.buf)
self.buf = ''
@@ -589,6 +595,10 @@
class DiskFile(object):
"""Standard I/O basis stream using os.open/close/read/write/lseek"""
+
+ # This is not quite correct, since more letters are allowed after
+ # these. However, the following are the only starting strings allowed
+ # in the mode parameter.
modes = {
'r' : os.O_RDONLY,
'rb' : os.O_RDONLY,
@@ -655,6 +665,12 @@
else:
raise NotImplementedError
+ def isatty(self):
+ if os.name == 'posix':
+ return os.isatty(self.fd)
+ else:
+ raise NotImplementedError
+
def fileno():
return self.fd
More information about the Pypy-commit
mailing list