[pypy-commit] pypy default: allow the termios functions to take both file objects, as well as integer file descriptors. Originally filed as #16657 in Django.

alex_gaynor noreply at buildbot.pypy.org
Fri Aug 19 18:05:33 CEST 2011


Author: Alex Gaynor <alex.gaynor at gmail.com>
Branch: 
Changeset: r46644:9d4eac09ef21
Date: 2011-08-19 11:10 -0500
http://bitbucket.org/pypy/pypy/changeset/9d4eac09ef21/

Log:	allow the termios functions to take both file objects, as well as
	integer file descriptors. Originally filed as #16657 in Django.

diff --git a/pypy/module/termios/interp_termios.py b/pypy/module/termios/interp_termios.py
--- a/pypy/module/termios/interp_termios.py
+++ b/pypy/module/termios/interp_termios.py
@@ -19,8 +19,9 @@
     w_exception_class = space.fromcache(Cache).w_error
     return wrap_oserror(space, error, w_exception_class=w_exception_class)
 
- at unwrap_spec(fd=int, when=int)
-def tcsetattr(space, fd, when, w_attributes):
+ at unwrap_spec(when=int)
+def tcsetattr(space, w_fd, when, w_attributes):
+    fd = space.c_filedescriptor_w(w_fd)
     w_iflag, w_oflag, w_cflag, w_lflag, w_ispeed, w_ospeed, w_cc = \
              space.unpackiterable(w_attributes, expected_length=7)
     w_builtin = space.getbuiltinmodule('__builtin__')
@@ -40,8 +41,8 @@
     except OSError, e:
         raise convert_error(space, e)
 
- at unwrap_spec(fd=int)
-def tcgetattr(space, fd):
+def tcgetattr(space, w_fd):
+    fd = space.c_filedescriptor_w(w_fd)
     try:
         tup = rtermios.tcgetattr(fd)
     except OSError, e:
@@ -57,29 +58,32 @@
     l_w.append(w_cc)
     return space.newlist(l_w)
 
- at unwrap_spec(fd=int, duration=int)
-def tcsendbreak(space, fd, duration):
+ at unwrap_spec(duration=int)
+def tcsendbreak(space, w_fd, duration):
+    fd = space.c_filedescriptor_w(w_fd)
     try:
         termios.tcsendbreak(fd, duration)
     except OSError, e:
         raise convert_error(space, e)
 
- at unwrap_spec(fd=int)
-def tcdrain(space, fd):
+def tcdrain(space, w_fd):
+    fd = space.c_filedescriptor_w(w_fd)
     try:
         termios.tcdrain(fd)
     except OSError, e:
         raise convert_error(space, e)
 
- at unwrap_spec(fd=int, queue=int)
-def tcflush(space, fd, queue):
+ at unwrap_spec(queue=int)
+def tcflush(space, w_fd, queue):
+    fd = space.c_filedescriptor_w(w_fd)
     try:
         termios.tcflush(fd, queue)
     except OSError, e:
         raise convert_error(space, e)
 
- at unwrap_spec(fd=int, action=int)
-def tcflow(space, fd, action):
+ at unwrap_spec(action=int)
+def tcflow(space, w_fd, action):
+    fd = space.c_filedescriptor_w(w_fd)
     try:
         termios.tcflow(fd, action)
     except OSError, e:
diff --git a/pypy/module/termios/test/test_termios.py b/pypy/module/termios/test/test_termios.py
--- a/pypy/module/termios/test/test_termios.py
+++ b/pypy/module/termios/test/test_termios.py
@@ -62,8 +62,9 @@
 
     def test_tcsetattr(self):
         source = py.code.Source("""
+        import sys
         import termios
-        termios.tcsetattr(0, 1, [16640, 4, 191, 2608, 15, 15, ['\x03', '\x1c', '\x7f', '\x15', '\x04', 0, 1, '\x00', '\x11', '\x13', '\x1a', '\x00', '\x12', '\x0f', '\x17', '\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00']])
+        termios.tcsetattr(sys.stdin, 1, [16640, 4, 191, 2608, 15, 15, ['\x03', '\x1c', '\x7f', '\x15', '\x04', 0, 1, '\x00', '\x11', '\x13', '\x1a', '\x00', '\x12', '\x0f', '\x17', '\x16', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00', '\x00']])
         print 'ok!'
         """)
         f = udir.join("test_tcsetattr.py")


More information about the pypy-commit mailing list