[pypy-svn] r18629 - pypy/dist/pypy/lib
arigo at codespeak.net
arigo at codespeak.net
Sat Oct 15 15:19:49 CEST 2005
Author: arigo
Date: Sat Oct 15 15:19:49 2005
New Revision: 18629
Modified:
pypy/dist/pypy/lib/_file.py
pypy/dist/pypy/lib/_sio.py
Log:
* turn the file's OSErrors into IOErrors.
* minor bug with _closed not defined if the file fails to open.
Modified: pypy/dist/pypy/lib/_file.py
==============================================================================
--- pypy/dist/pypy/lib/_file.py (original)
+++ pypy/dist/pypy/lib/_file.py Sat Oct 15 15:19:49 2005
@@ -78,6 +78,8 @@
Note: open() is an alias for file().
"""
+ _closed = True # Until the file is successfully opened
+
def __init__(self, name, mode='r', buffering=None):
self.fd = None
self._name = name
@@ -122,7 +124,10 @@
flag |= O_BINARY
if self.fd is None:
- self.fd = os.open(self.name, flag)
+ try:
+ self.fd = os.open(self.name, flag)
+ except OSError, e:
+ raise IOError(*e.args)
if basemode == 'a':
try:
os.lseek(self.fd, 0, 2)
@@ -132,8 +137,6 @@
reading = basemode == 'r' or plus
writing = basemode != 'r' or plus
- self._closed = True # Until the file is successfully opened
-
self.softspace = 0 # Required according to file object docs
self.encoding = None # This is not used internally by file objects
Modified: pypy/dist/pypy/lib/_sio.py
==============================================================================
--- pypy/dist/pypy/lib/_sio.py (original)
+++ pypy/dist/pypy/lib/_sio.py Sat Oct 15 15:19:49 2005
@@ -99,25 +99,42 @@
self.fd = fd
def seek(self, offset, whence=0):
- os.lseek(self.fd, offset, whence)
+ try:
+ os.lseek(self.fd, offset, whence)
+ except OSError, e:
+ raise IOError(*e.args)
def tell(self):
- return os.lseek(self.fd, 0, 1)
+ try:
+ return os.lseek(self.fd, 0, 1)
+ except OSError, e:
+ raise IOError(*e.args)
def read(self, n):
- return os.read(self.fd, n)
+ try:
+ return os.read(self.fd, n)
+ except OSError, e:
+ raise IOError(*e.args)
def write(self, data):
- while data:
- n = os.write(self.fd, data)
- data = data[n:]
+ try:
+ while data:
+ n = os.write(self.fd, data)
+ data = data[n:]
+ except OSError, e:
+ raise IOError(*e.args)
def close(self):
- os.close(self.fd)
+ try:
+ os.close(self.fd)
+ except OSError, e:
+ raise IOError(*e.args)
def truncate(self, size):
try:
os.ftruncate(self.fd, size)
+ except OSError, e:
+ raise IOError(*e.args)
except AttributeError:
raise NotImplementedError
More information about the Pypy-commit
mailing list