Example #1
0
 def runs_tcsetattr():
     tp = rtermios.tcgetattr(2)
     a, b, c, d, e, f, g = tp
     rtermios.tcsetattr(2, rtermios.TCSANOW, (a, b, c, d, e, f, g))
     time.sleep(1)
     tp = rtermios.tcgetattr(2)
     assert tp[5] == f
Example #2
0
 def runs_tcsetattr():
     tp = rtermios.tcgetattr(2)
     a, b, c, d, e, f, g = tp
     rtermios.tcsetattr(2, rtermios.TCSANOW, (a, b, c, d, e, f, g))
     time.sleep(1)
     tp = rtermios.tcgetattr(2)
     assert tp[5] == f
Example #3
0
def tcsetattr(space, fd, when, w_attributes):
    try:
        w_cc = space.getitem(w_attributes, space.wrap(-1))
        tup_w = space.getitem(w_attributes, space.newslice(
            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)
        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:
            rtermios.tcsetattr(fd, when, tup)
        except termios.error, e:
            e.errno = e.args[0]
            raise convert_error(space, e)
    except OperationError, e:
        if not e.match(space, space.w_TypeError):
            raise
        msg = "tcsetattr must be called with int, int and 7-arg tuple"
        raise OperationError(space.w_TypeError, space.wrap(str(msg)))
Example #4
0
 def test_tcsetattr_icanon(self):
     from pypy.rlib import rtermios
     import termios
     def check(fd, when, attributes):
         count = len([i for i in attributes[-1] if isinstance(i, int)])
         assert count == 2
     termios.tcsetattr = check
     attr = list(rtermios.tcgetattr(2))
     attr[3] |= termios.ICANON
     rtermios.tcsetattr(2, termios.TCSANOW, attr)
Example #5
0
def tcsetattr(space, fd, when, w_attributes):
    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__')
    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:
        rtermios.tcsetattr(fd, when, tup)
    except OSError, e:
        raise convert_error(space, e)
Example #6
0
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__')
    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:
        rtermios.tcsetattr(fd, when, tup)
    except OSError, e:
        raise convert_error(space, e)
Example #7
0
            space.w_TypeError,
            space.wrap("tcsetattr, arg 3: must be 7 element list"))
    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:
        rtermios.tcsetattr(fd, when, tup)
    except termios.error, e:
        e.errno = e.args[0]
        raise convert_error(space, e)
tcsetattr.unwrap_spec = [ObjSpace, int, int, W_Root]

def tcgetattr(space, fd):
    try:
        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
    cc_w = [space.wrap(i) for i in cc]