<s> from __future__ import ( unicode_literals , division , absolute_import , print_function ) <EOL> import threading <EOL> from time import sleep <EOL> import pexpect <EOL> from tests . lib . vterm import VTerm <EOL> class ExpectProcess ( threading . Thread ) : <EOL> def __init__ ( self , lib , rows , cols , cmd , args , cwd = None , env = None ) : <EOL> super ( ExpectProcess , self ) . __init__ ( ) <EOL> self . vterm = VTerm ( lib , rows , cols ) <EOL> self . lock = threading . Lock ( ) <EOL> self . rows = rows <EOL> self . cols = cols <EOL> self . cmd = cmd <EOL> self . args = args <EOL> self . cwd = cwd <EOL> self . env = env <EOL> self . buffer = [ ] <EOL> self . child_lock = threading . Lock ( ) <EOL> def run ( self ) : <EOL> child = pexpect . spawn ( self . cmd , self . args , cwd = self . cwd , env = self . env ) <EOL> sleep ( <NUM_LIT:0.5> ) <EOL> child . setwinsize ( self . rows , self . cols ) <EOL> sleep ( <NUM_LIT:0.5> ) <EOL> self . child = child <EOL> status = None <EOL> while status is None : <EOL> try : <EOL> with self . child_lock : <EOL> s = child . read_nonblocking ( size = <NUM_LIT> , timeout = <NUM_LIT:0> ) <EOL> status = child . status <EOL> except pexpect . TIMEOUT : <EOL> pass <EOL> except pexpect . EOF : <EOL> break <EOL> else : <EOL> with self . lock : <EOL> self . vterm . push ( s ) <EOL> self . buffer . append ( s ) <EOL> def resize ( self , rows , cols ) : <EOL> with self . child_lock : <EOL> self . rows = rows <EOL> self . cols = cols <EOL> self . child . setwinsize ( rows , cols ) <EOL> self . vterm . resize ( rows , cols ) <EOL> def __getitem__ ( self , position ) : <EOL> with self . lock : <EOL> return self . vterm . vtscreen [ position ] <EOL> def read ( self ) : <EOL> with self . lock : <EOL> ret = b'<STR_LIT>' . join ( self . buffer ) <EOL> del self . buffer [ : ] <EOL> return ret <EOL> def send ( self , data ) : <EOL> with self . child_lock : <EOL> self . child . send ( data ) </s>
