<s> """<STR_LIT>""" <EOL> import binascii <EOL> import string <EOL> from openhtf . plugs . usb import usb_handle <EOL> class StubUsbHandle ( usb_handle . UsbHandle ) : <EOL> """<STR_LIT>""" <EOL> PRINTABLE_DATA = set ( string . printable ) - set ( string . whitespace ) <EOL> def __init__ ( self , ignore_writes = False ) : <EOL> super ( StubUsbHandle , self ) . __init__ ( '<STR_LIT>' , '<STR_LIT>' , <EOL> default_timeout_ms = <NUM_LIT:0> ) <EOL> self . expected_write_data = None if ignore_writes else [ ] <EOL> self . expected_read_data = [ ] <EOL> self . closed = False <EOL> @ classmethod <EOL> def _Dotify ( cls , data ) : <EOL> """<STR_LIT>""" <EOL> return '<STR_LIT>' . join ( char if char in cls . PRINTABLE_DATA else '<STR_LIT:.>' for char in data ) <EOL> def Write ( self , data , dummy = None ) : <EOL> """<STR_LIT>""" <EOL> assert not self . closed <EOL> if self . expected_write_data is None : <EOL> return <EOL> expected_data = self . expected_write_data . pop ( <NUM_LIT:0> ) <EOL> if expected_data != data : <EOL> raise ValueError ( '<STR_LIT>' % ( <EOL> self . _Dotify ( expected_data ) , binascii . hexlify ( data ) , <EOL> self . _Dotify ( data ) ) ) <EOL> def Read ( self , length , dummy = None ) : <EOL> """<STR_LIT>""" <EOL> assert not self . closed <EOL> data = self . expected_read_data . pop ( <NUM_LIT:0> ) <EOL> if length < len ( data ) : <EOL> raise ValueError ( <EOL> '<STR_LIT>' , <EOL> length , len ( data ) , self . _Dotify ( data ) ) <EOL> return data <EOL> def Close ( self ) : <EOL> """<STR_LIT>""" <EOL> self . closed = True <EOL> def IsClosed ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . closed <EOL> def ExpectWrite ( self , data ) : <EOL> """<STR_LIT>""" <EOL> assert self . expected_write_data is not None , '<STR_LIT>' <EOL> self . expected_write_data . append ( data ) <EOL> def ExpectRead ( self , data ) : <EOL> """<STR_LIT>""" <EOL> self . expected_read_data . append ( data ) </s>
