[pypy-svn] r44208 - pypy/branch/kill-ctypes/pypy/rlib
fijal at codespeak.net
fijal at codespeak.net
Tue Jun 12 23:19:41 CEST 2007
Author: fijal
Date: Tue Jun 12 23:19:39 2007
New Revision: 44208
Added:
pypy/branch/kill-ctypes/pypy/rlib/rtermios.py
Log:
Add low-level implementation of termios
Added: pypy/branch/kill-ctypes/pypy/rlib/rtermios.py
==============================================================================
--- (empty file)
+++ pypy/branch/kill-ctypes/pypy/rlib/rtermios.py Tue Jun 12 23:19:39 2007
@@ -0,0 +1,32 @@
+# This are here only because it's always better safe than sorry.
+# The issue is that from-time-to-time CPython's termios.tcgetattr
+# returns list of mostly-strings of length one, but with few ints
+# inside, so we make sure it works
+
+import termios
+from termios import *
+
+def tcgetattr(fd):
+ # NOT_RPYTHON
+ lst = list(termios.tcgetattr(fd))
+ cc = lst[-1]
+ next_cc = []
+ for c in cc:
+ if isinstance(c, int):
+ next_cc.append(chr(c))
+ else:
+ next_cc.append(c)
+ lst[-1] = next_cc
+ return tuple(lst)
+
+def tcsetattr(fd, when, mode):
+ # NOT_RPYTHON
+ # there are some bizarre requirements for that, stealing directly
+ # from cpython
+ mode_l = list(mode)
+ if mode_l[3] & termios.ICANON:
+ cc = mode_l[-1]
+ cc[termios.VMIN] = ord(cc[termios.VMIN])
+ cc[termios.VTIME] = ord(cc[termios.VTIME])
+ mode_l[-1] = cc
+ return termios.tcsetattr(fd, when, mode_l)
More information about the pypy-svn
mailing list