[pypy-svn] r79940 - in pypy/trunk/pypy: interpreter module/posix module/posix/test module/select
arigo at codespeak.net
arigo at codespeak.net
Thu Dec 9 18:53:54 CET 2010
Author: arigo
Date: Thu Dec 9 18:53:52 2010
New Revision: 79940
Modified:
pypy/trunk/pypy/interpreter/baseobjspace.py
pypy/trunk/pypy/module/posix/interp_posix.py
pypy/trunk/pypy/module/posix/test/test_posix2.py
pypy/trunk/pypy/module/select/interp_select.py
Log:
Thanks agaynor for pointing out that the select module
already had a similar function. Combine both versions
and move it as space.c_filedescriptor_w().
Modified: pypy/trunk/pypy/interpreter/baseobjspace.py
==============================================================================
--- pypy/trunk/pypy/interpreter/baseobjspace.py (original)
+++ pypy/trunk/pypy/interpreter/baseobjspace.py Thu Dec 9 18:53:52 2010
@@ -1183,6 +1183,27 @@
self.wrap("expected a 32-bit integer"))
return value
+ def c_filedescriptor_w(self, w_fd):
+ try:
+ fd = self.c_int_w(w_fd)
+ except OperationError, e:
+ if not e.match(self, self.w_TypeError):
+ raise
+ try:
+ w_fileno = self.getattr(w_fd, self.wrap('fileno'))
+ except OperationError, e:
+ if e.match(self, self.w_AttributeError):
+ raise OperationError(self.w_TypeError,
+ self.wrap("argument must be an int, "
+ "or have a fileno() method."))
+ raise
+ w_fd = self.call_function(w_fileno)
+ fd = self.c_int_w(w_fd)
+ if fd < 0:
+ raise operationerrfmt(self.w_ValueError,
+ "file descriptor cannot be a negative integer (%d)", fd)
+ return fd
+
def warn(self, msg, w_warningcls):
self.appexec([self.wrap(msg), w_warningcls], """(msg, warningcls):
import warnings
Modified: pypy/trunk/pypy/module/posix/interp_posix.py
==============================================================================
--- pypy/trunk/pypy/module/posix/interp_posix.py (original)
+++ pypy/trunk/pypy/module/posix/interp_posix.py Thu Dec 9 18:53:52 2010
@@ -152,21 +152,8 @@
raise wrap_oserror(space, e)
ftruncate.unwrap_spec = [ObjSpace, "c_int", r_longlong]
-def _as_filedescriptor(space, w_fd):
- try:
- fd = space.c_int_w(w_fd)
- except OperationError, e:
- if not e.match(space, space.w_TypeError):
- raise
- w_fd = space.call_method(w_fd, 'fileno')
- fd = space.c_int_w(w_fd)
- if fd < 0:
- raise operationerrfmt(space.w_ValueError,
- "file descriptor cannot be a negative integer (%d)", fd)
- return fd
-
def fsync(space, w_fd):
- fd = _as_filedescriptor(space, w_fd)
+ fd = space.c_filedescriptor_w(w_fd)
try:
os.fsync(fd)
except OSError, e:
@@ -174,7 +161,7 @@
fsync.unwrap_spec = [ObjSpace, W_Root]
def fdatasync(space, w_fd):
- fd = _as_filedescriptor(space, w_fd)
+ fd = space.c_filedescriptor_w(w_fd)
try:
os.fdatasync(fd)
except OSError, e:
Modified: pypy/trunk/pypy/module/posix/test/test_posix2.py
==============================================================================
--- pypy/trunk/pypy/module/posix/test/test_posix2.py (original)
+++ pypy/trunk/pypy/module/posix/test/test_posix2.py Thu Dec 9 18:53:52 2010
@@ -536,6 +536,7 @@
try:
fd = f.fileno()
os.fsync(fd)
+ os.fsync(long(fd))
os.fsync(f) # <- should also work with a file, or anything
finally: # with a fileno() method
f.close()
Modified: pypy/trunk/pypy/module/select/interp_select.py
==============================================================================
--- pypy/trunk/pypy/module/select/interp_select.py (original)
+++ pypy/trunk/pypy/module/select/interp_select.py Thu Dec 9 18:53:52 2010
@@ -12,37 +12,17 @@
unregistering file descriptors, and then polling them for I/O events."""
return Poll()
-def as_fd_w(space, w_fd):
- if not space.is_true(space.isinstance(w_fd, space.w_int)):
- try:
- w_fileno = space.getattr(w_fd, space.wrap('fileno'))
- except OperationError, e:
- if e.match(space, space.w_AttributeError):
- raise OperationError(space.w_TypeError,
- space.wrap("argument must be an int, or have a fileno() method."))
- raise
- w_fd = space.call_function(w_fileno)
- if not space.is_true(space.isinstance(w_fd, space.w_int)):
- raise OperationError(space.w_TypeError,
- space.wrap('filneo() return a non-integer'))
-
- fd = space.int_w(w_fd)
- if fd < 0:
- raise operationerrfmt(space.w_ValueError,
- "file descriptor cannot be a negative integer (%d)", fd)
- return fd
-
class Poll(Wrappable):
def __init__(self):
self.fddict = {}
def register(self, space, w_fd, events=defaultevents):
- fd = as_fd_w(space, w_fd)
+ fd = space.c_filedescriptor_w(w_fd)
self.fddict[fd] = events
register.unwrap_spec = ['self', ObjSpace, W_Root, int]
def unregister(self, space, w_fd):
- fd = as_fd_w(space, w_fd)
+ fd = space.c_filedescriptor_w(w_fd)
try:
del self.fddict[fd]
except KeyError:
@@ -113,9 +93,9 @@
iwtd_w = space.listview(w_iwtd)
owtd_w = space.listview(w_owtd)
ewtd_w = space.listview(w_ewtd)
- iwtd = [as_fd_w(space, w_f) for w_f in iwtd_w]
- owtd = [as_fd_w(space, w_f) for w_f in owtd_w]
- ewtd = [as_fd_w(space, w_f) for w_f in ewtd_w]
+ iwtd = [space.c_filedescriptor_w(w_f) for w_f in iwtd_w]
+ owtd = [space.c_filedescriptor_w(w_f) for w_f in owtd_w]
+ ewtd = [space.c_filedescriptor_w(w_f) for w_f in ewtd_w]
iwtd_d = {}
owtd_d = {}
ewtd_d = {}
More information about the Pypy-commit
mailing list