[pypy-commit] pypy default: simplify the call to wrap_oserror2
mattip
pypy.commits at gmail.com
Sun Feb 2 09:45:23 EST 2020
Author: Matti Picus <matti.picus at gmail.com>
Branch:
Changeset: r98627:2821b0633b53
Date: 2020-01-31 10:37 +0200
http://bitbucket.org/pypy/pypy/changeset/2821b0633b53/
Log: simplify the call to wrap_oserror2
diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -471,8 +471,7 @@
return OperationError(exc, w_error)
@specialize.arg(3)
-def wrap_oserror2(space, e, w_filename=None, exception_name='w_OSError',
- w_exception_class=None):
+def wrap_oserror2(space, e, w_filename=None, w_exception_class=None):
assert isinstance(e, OSError)
if _WINDOWS and isinstance(e, WindowsError):
@@ -488,7 +487,7 @@
except ValueError:
msg = 'error %d' % errno
if w_exception_class is None:
- exc = getattr(space, exception_name)
+ exc = getattr(space, 'w_OSError')
else:
exc = w_exception_class
if w_filename is not None:
@@ -500,15 +499,12 @@
return OperationError(exc, w_error)
@specialize.arg(3)
-def wrap_oserror(space, e, filename=None, exception_name='w_OSError',
- w_exception_class=None):
+def wrap_oserror(space, e, filename=None, w_exception_class=None):
if filename is not None:
return wrap_oserror2(space, e, space.newtext(filename),
- exception_name=exception_name,
w_exception_class=w_exception_class)
else:
return wrap_oserror2(space, e, None,
- exception_name=exception_name,
w_exception_class=w_exception_class)
def exception_from_errno(space, w_type, errno):
diff --git a/pypy/interpreter/test/test_error.py b/pypy/interpreter/test/test_error.py
--- a/pypy/interpreter/test/test_error.py
+++ b/pypy/interpreter/test/test_error.py
@@ -113,7 +113,7 @@
#
e = wrap_oserror(space, OSError(errno.EBADF, "foobar"),
filename = "test.py",
- exception_name = "w_EnvironmentError")
+ w_exception_class = space.w_EnvironmentError)
assert isinstance(e, OperationError)
assert e.w_type == [EnvironmentError]
assert e.get_w_value(space) == ([EnvironmentError], [errno.EBADF],
diff --git a/pypy/module/_io/interp_fileio.py b/pypy/module/_io/interp_fileio.py
--- a/pypy/module/_io/interp_fileio.py
+++ b/pypy/module/_io/interp_fileio.py
@@ -173,7 +173,7 @@
space, w_name, flags, 0666)
except OSError as e:
raise wrap_oserror2(space, e, w_name,
- exception_name='w_IOError')
+ w_exception_class=space.w_IOError)
finally:
fd_is_own = True
@@ -186,7 +186,7 @@
try:
os.lseek(self.fd, 0, os.SEEK_END)
except OSError as e:
- raise wrap_oserror(space, e, exception_name='w_IOError')
+ raise wrap_oserror(space, e, w_exception_class=space.w_IOError)
except:
if not fd_is_own:
self.fd = -1
@@ -235,8 +235,7 @@
try:
os.close(fd)
except OSError as e:
- raise wrap_oserror(space, e,
- exception_name='w_IOError')
+ raise wrap_oserror(space, e, w_exception_class=space.w_IOError)
def close_w(self, space):
try:
@@ -264,7 +263,7 @@
return
if stat.S_ISDIR(st.st_mode):
raise wrap_oserror2(space, OSError(errno.EISDIR, "fstat"),
- w_filename, exception_name='w_IOError')
+ w_filename, w_exception_class=space.w_IOError)
@unwrap_spec(pos=r_longlong, whence=int)
def seek_w(self, space, pos, whence=0):
@@ -273,7 +272,7 @@
pos = os.lseek(self.fd, pos, whence)
except OSError as e:
raise wrap_oserror(space, e,
- exception_name='w_IOError')
+ w_exception_class=space.w_IOError)
return space.newint(pos)
def tell_w(self, space):
@@ -282,7 +281,7 @@
pos = os.lseek(self.fd, 0, 1)
except OSError as e:
raise wrap_oserror(space, e,
- exception_name='w_IOError')
+ w_exception_class=space.w_IOError)
return space.newint(pos)
def readable_w(self, space):
@@ -315,7 +314,7 @@
try:
res = os.isatty(self.fd)
except OSError as e:
- raise wrap_oserror(space, e, exception_name='w_IOError')
+ raise wrap_oserror(space, e, w_exception_class=space.w_IOError)
return space.newbool(res)
def repr_w(self, space):
@@ -345,7 +344,7 @@
if e.errno == errno.EAGAIN:
return space.w_None
raise wrap_oserror(space, e,
- exception_name='w_IOError')
+ w_exception_class=space.w_IOError)
return space.newint(n)
@@ -363,7 +362,7 @@
if e.errno == errno.EAGAIN:
return space.w_None
raise wrap_oserror(space, e,
- exception_name='w_IOError')
+ w_exception_class=space.w_IOError)
return space.newbytes(s)
@@ -388,7 +387,7 @@
if e.errno == errno.EAGAIN:
return space.w_None
raise wrap_oserror(space, e,
- exception_name='w_IOError')
+ w_exception_class=space.w_IOError)
self.output_slice(space, rwbuffer, 0, buf)
return space.newint(len(buf))
else:
@@ -404,7 +403,7 @@
if err == errno.EAGAIN:
return space.w_None
e = OSError(err, "read failed")
- raise wrap_oserror(space, e, exception_name='w_IOError')
+ raise wrap_oserror(space, e, w_exception_class=space.w_IOError)
def readall_w(self, space):
self._check_closed(space)
@@ -427,7 +426,7 @@
if e.errno == errno.EAGAIN:
return space.w_None
raise wrap_oserror(space, e,
- exception_name='w_IOError')
+ w_exception_class=space.w_IOError)
if not chunk:
break
@@ -452,7 +451,7 @@
try:
self._truncate(space.r_longlong_w(w_size))
except OSError as e:
- raise wrap_oserror(space, e, exception_name='w_IOError')
+ raise wrap_oserror(space, e, w_exception_class=space.w_IOError)
return w_size
diff --git a/pypy/module/fcntl/interp_fcntl.py b/pypy/module/fcntl/interp_fcntl.py
--- a/pypy/module/fcntl/interp_fcntl.py
+++ b/pypy/module/fcntl/interp_fcntl.py
@@ -80,7 +80,7 @@
def _get_error(space, funcname):
errno = rposix.get_saved_errno()
return wrap_oserror(space, OSError(errno, funcname),
- exception_name = 'w_IOError')
+ w_exception_class = space.w_IOError)
@unwrap_spec(op=int, w_arg=WrappedDefault(0))
def fcntl(space, w_fd, op, w_arg):
diff --git a/pypy/module/posix/test/test_posix2.py b/pypy/module/posix/test/test_posix2.py
--- a/pypy/module/posix/test/test_posix2.py
+++ b/pypy/module/posix/test/test_posix2.py
@@ -1232,13 +1232,6 @@
assert f.read() == 'this is a rename test'
os.rename(unicode_name, fname)
- os.rename(bytes(fname, 'utf-8'), bytes(str_name, 'utf-8'))
- with open(str_name) as f:
- assert f.read() == 'this is a rename test'
- os.rename(str_name, fname)
- with open(fname) as f:
- assert f.read() == 'this is a rename test'
- os.unlink(fname)
class AppTestEnvironment(object):
diff --git a/pypy/module/select/interp_select.py b/pypy/module/select/interp_select.py
--- a/pypy/module/select/interp_select.py
+++ b/pypy/module/select/interp_select.py
@@ -40,7 +40,7 @@
fd = space.c_filedescriptor_w(w_fd)
if fd not in self.fddict:
raise wrap_oserror(space, OSError(errno.ENOENT, "poll.modify"),
- exception_name='w_IOError')
+ w_exception_class = space.w_IOError)
self.fddict[fd] = events
def unregister(self, space, w_fd):
More information about the pypy-commit
mailing list