[pypy-svn] r44213 - in pypy/branch/kill-ctypes/pypy/module/termios: . test
fijal at codespeak.net
fijal at codespeak.net
Tue Jun 12 23:23:47 CEST 2007
Author: fijal
Date: Tue Jun 12 23:23:47 2007
New Revision: 44213
Modified:
pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py
pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py
Log:
Fix the termios module
Modified: pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py (original)
+++ pypy/branch/kill-ctypes/pypy/module/termios/interp_termios.py Tue Jun 12 23:23:47 2007
@@ -8,6 +8,7 @@
from pypy.rpython.module import ll_termios
from pypy.rlib.objectmodel import we_are_translated
import os
+from pypy.rlib import rtermios
import termios
# proper semantics are to have termios.error, but since it's not documented
@@ -33,16 +34,20 @@
space.wrap(0), space.wrap(-1), space.wrap(1)))
w_iflag, w_oflag, w_cflag, w_lflag, w_ispeed, w_ospeed = \
space.unpackiterable(tup_w)
- cc = [space.str_w(space.call_function(space.getattr(w_c,
- space.wrap('__str__')))) for w_c in space.unpackiterable(w_cc)]
+ w_builtin = space.getbuiltinmodule('__builtin__')
+ cc = []
+ for w_c in space.unpackiterable(w_cc):
+ if space.is_true(space.isinstance(w_c, space.w_int)):
+ ch = space.call_function(space.getattr(w_builtin,
+ space.wrap('chr')), w_c)
+ cc.append(space.str_w(ch))
+ else:
+ cc.append(space.str_w(w_c))
tup = (space.int_w(w_iflag), space.int_w(w_oflag),
space.int_w(w_cflag), space.int_w(w_lflag),
space.int_w(w_ispeed), space.int_w(w_ospeed), cc)
try:
- if we_are_translated():
- termios.tcsetattr(fd, when, tup)
- else:
- termios.tcsetattr(fd, when, list(tup))
+ rtermios.tcsetattr(fd, when, tup)
except termios.error, e:
e.errno = e.args[0]
raise convert_error(space, e)
@@ -55,14 +60,18 @@
def tcgetattr(space, fd):
try:
- tup = termios.tcgetattr(fd)
+ tup = rtermios.tcgetattr(fd)
except termios.error, e:
e.errno = e.args[0]
raise convert_error(space, e)
iflag, oflag, cflag, lflag, ispeed, ospeed, cc = tup
l_w = [space.wrap(i) for i in [iflag, oflag, cflag, lflag, ispeed, ospeed]]
# last one need to be chosen carefully
- w_cc = space.newlist([space.wrap(i) for i in cc])
+ cc_w = [space.wrap(i) for i in cc]
+ if lflag & termios.ICANON:
+ cc_w[termios.VMIN] = space.wrap(ord(cc[termios.VMIN]))
+ cc_w[termios.VTIME] = space.wrap(ord(cc[termios.VTIME]))
+ w_cc = space.newlist(cc_w)
l_w.append(w_cc)
return space.newlist(l_w)
tcgetattr.unwrap_spec = [ObjSpace, int]
Modified: pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py
==============================================================================
--- pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py (original)
+++ pypy/branch/kill-ctypes/pypy/module/termios/test/test_termios.py Tue Jun 12 23:23:47 2007
@@ -84,6 +84,25 @@
child = self.spawn(['--withmod-termios', '--withmod-fcntl', str(f)])
child.expect('ok!')
+ def test_icanon(self):
+ source = py.code.Source("""
+ import termios
+ import fcntl
+ import termios
+ f = termios.tcgetattr(2)
+ f[3] |= termios.ICANON
+ termios.tcsetattr(2, termios.TCSANOW, f)
+ f = termios.tcgetattr(2)
+ assert len([i for i in f[-1] if isinstance(i, int)]) == 2
+ assert isinstance(f[-1][termios.VMIN], int)
+ assert isinstance(f[-1][termios.VTIME], int)
+ print 'ok!'
+ """)
+ f = udir.join("test_ioctl_termios.py")
+ f.write(source)
+ child = self.spawn(['--withmod-termios', '--withmod-fcntl', str(f)])
+ child.expect('ok!')
+
class AppTestTermios(object):
def setup_class(cls):
cls.space = gettestobjspace(usemodules=['termios'])
More information about the Pypy-commit
mailing list