<s> r"""<STR_LIT>""" <EOL> __author__ = '<STR_LIT>' <EOL> import operator <EOL> import array <EOL> from sys import hexversion <EOL> import usb . _interop as _interop <EOL> DESC_TYPE_DEVICE = <NUM_LIT> <EOL> DESC_TYPE_CONFIG = <NUM_LIT> <EOL> DESC_TYPE_STRING = <NUM_LIT> <EOL> DESC_TYPE_INTERFACE = <NUM_LIT> <EOL> DESC_TYPE_ENDPOINT = <NUM_LIT> <EOL> ENDPOINT_IN = <NUM_LIT> <EOL> ENDPOINT_OUT = <NUM_LIT> <EOL> ENDPOINT_TYPE_CTRL = <NUM_LIT> <EOL> ENDPOINT_TYPE_ISO = <NUM_LIT> <EOL> ENDPOINT_TYPE_BULK = <NUM_LIT> <EOL> ENDPOINT_TYPE_INTR = <NUM_LIT> <EOL> CTRL_TYPE_STANDARD = ( <NUM_LIT:0> << <NUM_LIT:5> ) <EOL> CTRL_TYPE_CLASS = ( <NUM_LIT:1> << <NUM_LIT:5> ) <EOL> CTRL_TYPE_VENDOR = ( <NUM_LIT:2> << <NUM_LIT:5> ) <EOL> CTRL_TYPE_RESERVED = ( <NUM_LIT:3> << <NUM_LIT:5> ) <EOL> CTRL_RECIPIENT_DEVICE = <NUM_LIT:0> <EOL> CTRL_RECIPIENT_INTERFACE = <NUM_LIT:1> <EOL> CTRL_RECIPIENT_ENDPOINT = <NUM_LIT:2> <EOL> CTRL_RECIPIENT_OTHER = <NUM_LIT:3> <EOL> CTRL_OUT = <NUM_LIT> <EOL> CTRL_IN = <NUM_LIT> <EOL> _ENDPOINT_ADDR_MASK = <NUM_LIT> <EOL> _ENDPOINT_DIR_MASK = <NUM_LIT> <EOL> _ENDPOINT_TRANSFER_TYPE_MASK = <NUM_LIT> <EOL> _CTRL_DIR_MASK = <NUM_LIT> <EOL> _dummy_s = '<STR_LIT:\x00>' . encode ( '<STR_LIT:utf-8>' ) <EOL> SPEED_LOW = <NUM_LIT:1> <EOL> SPEED_FULL = <NUM_LIT:2> <EOL> SPEED_HIGH = <NUM_LIT:3> <EOL> SPEED_SUPER = <NUM_LIT:4> <EOL> SPEED_UNKNOWN = <NUM_LIT:0> <EOL> def endpoint_address ( address ) : <EOL> r"""<STR_LIT>""" <EOL> return address & _ENDPOINT_ADDR_MASK <EOL> def endpoint_direction ( address ) : <EOL> r"""<STR_LIT>""" <EOL> return address & _ENDPOINT_DIR_MASK <EOL> def endpoint_type ( bmAttributes ) : <EOL> r"""<STR_LIT>""" <EOL> return bmAttributes & _ENDPOINT_TRANSFER_TYPE_MASK <EOL> def ctrl_direction ( bmRequestType ) : <EOL> r"""<STR_LIT>""" <EOL> return bmRequestType & _CTRL_DIR_MASK <EOL> def build_request_type ( direction , type , recipient ) : <EOL> r"""<STR_LIT>""" <EOL> return recipient | type | direction <EOL> def create_buffer ( length ) : <EOL> r"""<STR_LIT>""" <EOL> return array . array ( '<STR_LIT:B>' , _dummy_s * length ) <EOL> def find_descriptor ( desc , find_all = False , custom_match = None , ** args ) : <EOL> r"""<STR_LIT>""" <EOL> def desc_iter ( ** kwargs ) : <EOL> for d in desc : <EOL> tests = ( val == getattr ( d , key ) for key , val in kwargs . items ( ) ) <EOL> if _interop . _all ( tests ) and ( custom_match is None or custom_match ( d ) ) : <EOL> yield d <EOL> if find_all : <EOL> return desc_iter ( ** args ) <EOL> else : <EOL> try : <EOL> return _interop . _next ( desc_iter ( ** args ) ) <EOL> except StopIteration : <EOL> return None <EOL> def claim_interface ( device , interface ) : <EOL> r"""<STR_LIT>""" <EOL> device . _ctx . managed_claim_interface ( device , interface ) <EOL> def release_interface ( device , interface ) : <EOL> r"""<STR_LIT>""" <EOL> device . _ctx . managed_release_interface ( device , interface ) <EOL> def dispose_resources ( device ) : <EOL> r"""<STR_LIT>""" <EOL> device . _ctx . dispose ( device ) <EOL> def get_langids ( dev ) : <EOL> r"""<STR_LIT>""" <EOL> from usb . control import get_descriptor <EOL> buf = get_descriptor ( <EOL> dev , <EOL> <NUM_LIT> , <EOL> DESC_TYPE_STRING , <EOL> <NUM_LIT:0> <EOL> ) <EOL> if len ( buf ) < <NUM_LIT:4> or buf [ <NUM_LIT:0> ] < <NUM_LIT:4> or buf [ <NUM_LIT:0> ] & <NUM_LIT:1> != <NUM_LIT:0> : <EOL> return ( ) <EOL> return tuple ( map ( lambda x , y : x + ( y << <NUM_LIT:8> ) , buf [ <NUM_LIT:2> : buf [ <NUM_LIT:0> ] : <NUM_LIT:2> ] , buf [ <NUM_LIT:3> : buf [ <NUM_LIT:0> ] : <NUM_LIT:2> ] ) ) <EOL> def get_string ( dev , index , langid = None ) : <EOL> r"""<STR_LIT>""" <EOL> if <NUM_LIT:0> == index : <EOL> return None <EOL> from usb . control import get_descriptor <EOL> langids = dev . langids <EOL> if <NUM_LIT:0> == len ( langids ) : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> if langid is None : <EOL> langid = langids [ <NUM_LIT:0> ] <EOL> elif langid not in langids : <EOL> raise ValueError ( "<STR_LIT>" ) <EOL> buf = get_descriptor ( <EOL> dev , <EOL> <NUM_LIT:255> , <EOL> DESC_TYPE_STRING , <EOL> index , <EOL> langid <EOL> ) <EOL> if hexversion >= <NUM_LIT> : <EOL> return buf [ <NUM_LIT:2> : buf [ <NUM_LIT:0> ] ] . tobytes ( ) . decode ( '<STR_LIT>' ) <EOL> else : <EOL> return buf [ <NUM_LIT:2> : buf [ <NUM_LIT:0> ] ] . tostring ( ) . decode ( '<STR_LIT>' ) </s>
