idx int64 0 63k | question stringlengths 61 4.03k | target stringlengths 6 1.23k |
|---|---|---|
33,400 | def sense_ttf ( self , target ) : log . debug ( "polling for NFC-F technology" ) if target . brty not in ( "212F" , "424F" ) : message = "unsupported bitrate {0}" . format ( target . brty ) raise nfc . clf . UnsupportedTargetError ( message ) self . chipset . in_set_rf ( target . brty ) self . chipset . in_set_protocol... | Sense for a Type F Target is supported for 212 and 424 kbps . |
33,401 | def listen_ttf ( self , target , timeout ) : if target . brty not in ( '212F' , '424F' ) : info = "unsupported target bitrate: %r" % target . brty raise nfc . clf . UnsupportedTargetError ( info ) if target . sensf_res is None : raise ValueError ( "sensf_res is required" ) if len ( target . sensf_res ) != 19 : raise Va... | Listen as Type F Target is supported for either 212 or 424 kbps . |
33,402 | def request_response ( self ) : a , b , e = self . pmm [ 3 ] & 7 , self . pmm [ 3 ] >> 3 & 7 , self . pmm [ 3 ] >> 6 timeout = 302E-6 * ( b + 1 + a + 1 ) * 4 ** e data = self . send_cmd_recv_rsp ( 0x04 , '' , timeout , check_status = False ) if len ( data ) != 1 : log . debug ( "insufficient data received from tag" ) r... | Verify that a card is still present and get its operating mode . |
33,403 | def search_service_code ( self , service_index ) : log . debug ( "search service code index {0}" . format ( service_index ) ) a , e = self . pmm [ 3 ] & 7 , self . pmm [ 3 ] >> 6 timeout = max ( 302E-6 * ( a + 1 ) * 4 ** e , 0.002 ) data = pack ( "<H" , service_index ) data = self . send_cmd_recv_rsp ( 0x0A , data , ti... | Search for a service code that corresponds to an index . |
33,404 | def request_system_code ( self ) : log . debug ( "request system code list" ) a , e = self . pmm [ 3 ] & 7 , self . pmm [ 3 ] >> 6 timeout = max ( 302E-6 * ( a + 1 ) * 4 ** e , 0.002 ) data = self . send_cmd_recv_rsp ( 0x0C , '' , timeout , check_status = False ) if len ( data ) != 1 + data [ 0 ] * 2 : log . debug ( "i... | Return all system codes that are registered in the card . |
33,405 | def protect ( self , password = None , read_protect = False , protect_from = 0 ) : return super ( FelicaLite , self ) . protect ( password , read_protect , protect_from ) | Protect a FeliCa Lite Tag . |
33,406 | def format ( self , version = 0x10 , wipe = None ) : return super ( FelicaLite , self ) . format ( version , wipe ) | Format a FeliCa Lite Tag for NDEF . |
33,407 | def read_without_mac ( self , * blocks ) : log . debug ( "read {0} block(s) without mac" . format ( len ( blocks ) ) ) service_list = [ tt3 . ServiceCode ( 0 , 0b001011 ) ] block_list = [ tt3 . BlockCode ( n ) for n in blocks ] return self . read_without_encryption ( service_list , block_list ) | Read a number of data blocks without integrity check . |
33,408 | def read_with_mac ( self , * blocks ) : log . debug ( "read {0} block(s) with mac" . format ( len ( blocks ) ) ) if self . _sk is None or self . _iv is None : raise RuntimeError ( "authentication required" ) service_list = [ tt3 . ServiceCode ( 0 , 0b001011 ) ] block_list = [ tt3 . BlockCode ( n ) for n in blocks ] blo... | Read a number of data blocks with integrity check . |
33,409 | def write_without_mac ( self , data , block ) : assert len ( data ) == 16 and type ( block ) is int log . debug ( "write 1 block without mac" . format ( ) ) sc_list = [ tt3 . ServiceCode ( 0 , 0b001001 ) ] bc_list = [ tt3 . BlockCode ( block ) ] self . write_without_encryption ( sc_list , bc_list , data ) | Write a data block without integrity check . |
33,410 | def authenticate ( self , password ) : if super ( FelicaLiteS , self ) . authenticate ( password ) : self . _authenticated = False self . read_from_ndef_service = self . read_without_mac self . write_to_ndef_service = self . write_without_mac self . write_with_mac ( "\x01" + 15 * "\0" , 0x92 ) if self . read_with_mac (... | Mutually authenticate with a FeliCa Lite - S Tag . |
33,411 | def write_with_mac ( self , data , block ) : log . debug ( "write 1 block with mac" ) if len ( data ) != 16 : raise ValueError ( "data must be 16 octets" ) if type ( block ) is not int : raise ValueError ( "block number must be int" ) if self . _sk is None or self . _iv is None : raise RuntimeError ( "tag must be authe... | Write one data block with additional integrity check . |
33,412 | def _read ( self , f ) : try : self . header = ord ( f . read ( 1 ) ) except TypeError : log . debug ( "buffer underflow at offset {0}" . format ( f . tell ( ) ) ) raise LengthError ( "insufficient data to parse" ) mbf = bool ( self . header & 0x80 ) mef = bool ( self . header & 0x40 ) cff = bool ( self . header & 0x20... | Parse an NDEF record from a file - like object . |
33,413 | def _write ( self , f ) : log . debug ( "writing ndef record at offset {0}" . format ( f . tell ( ) ) ) record_type = self . type record_name = self . name record_data = self . data if record_type == '' : header_flags = 0 record_name = '' record_data = '' elif record_type . startswith ( "urn:nfc:wkt:" ) : header_flags ... | Serialize an NDEF record to a file - like object . |
33,414 | def pack ( self ) : sn , sa = self . number , self . attribute return pack ( "<H" , ( sn & 0x3ff ) << 6 | ( sa & 0x3f ) ) | Pack the service code for transmission . Returns a 2 byte string . |
33,415 | def pack ( self ) : bn , am , sx = self . number , self . access , self . service return chr ( bool ( bn < 256 ) << 7 | ( am & 0x7 ) << 4 | ( sx & 0xf ) ) + ( chr ( bn ) if bn < 256 else pack ( "<H" , bn ) ) | Pack the block code for transmission . Returns a 2 - 3 byte string . |
33,416 | def dump_service ( self , sc ) : def lprint ( fmt , data , index ) : ispchr = lambda x : x >= 32 and x <= 126 def print_bytes ( octets ) : return ' ' . join ( [ '%02x' % x for x in octets ] ) def print_chars ( octets ) : return '' . join ( [ chr ( x ) if ispchr ( x ) else '.' for x in octets ] ) return fmt . format ( i... | Read all data blocks of a given service . |
33,417 | def format ( self , version = None , wipe = None ) : return super ( Type3Tag , self ) . format ( version , wipe ) | Format and blank an NFC Forum Type 3 Tag . |
33,418 | def polling ( self , system_code = 0xffff , request_code = 0 , time_slots = 0 ) : log . debug ( "polling for system 0x{0:04x}" . format ( system_code ) ) if time_slots not in ( 0 , 1 , 3 , 7 , 15 ) : log . debug ( "invalid number of time slots: {0}" . format ( time_slots ) ) raise ValueError ( "invalid number of time s... | Aquire and identify a card . |
33,419 | def read_from_ndef_service ( self , * blocks ) : if self . sys == 0x12FC : sc_list = [ ServiceCode ( 0 , 0b001011 ) ] bc_list = [ BlockCode ( n ) for n in blocks ] return self . read_without_encryption ( sc_list , bc_list ) | Read block data from an NDEF compatible tag . |
33,420 | def write_without_encryption ( self , service_list , block_list , data ) : a , b , e = self . pmm [ 6 ] & 7 , self . pmm [ 6 ] >> 3 & 7 , self . pmm [ 6 ] >> 6 timeout = 302.1E-6 * ( ( b + 1 ) * len ( block_list ) + a + 1 ) * 4 ** e data = ( chr ( len ( service_list ) ) + '' . join ( [ sc . pack ( ) for sc in service_l... | Write data blocks to unencrypted services . |
33,421 | def write_to_ndef_service ( self , data , * blocks ) : if self . sys == 0x12FC : sc_list = [ ServiceCode ( 0 , 0b001001 ) ] bc_list = [ BlockCode ( n ) for n in blocks ] self . write_without_encryption ( sc_list , bc_list , data ) | Write block data to an NDEF compatible tag . |
33,422 | def close ( self ) : with self . lock : if self . device is not None : try : self . device . close ( ) except IOError : pass self . device = None | Close the contacless reader device . |
33,423 | def build ( self , root , schema ) : if schema . get ( "subcommands" ) and schema [ "subcommands" ] : for subcmd , childSchema in schema [ "subcommands" ] . items ( ) : child = CommandTree ( node = subcmd ) child = self . build ( child , childSchema ) root . children . append ( child ) root . help = schema . get ( "hel... | Build the syntax tree for kubectl command line |
33,424 | def parse_tokens ( self , tokens ) : if len ( tokens ) == 1 : return list ( ) , tokens , { "kubectl" : self . ast . help } else : tokens . reverse ( ) parsed , unparsed , suggestions = self . treewalk ( self . ast , parsed = list ( ) , unparsed = tokens ) if not suggestions and unparsed : logger . debug ( "unparsed tok... | Parse a sequence of tokens |
33,425 | def treewalk ( self , root , parsed , unparsed ) : suggestions = dict ( ) if not unparsed : logger . debug ( "no tokens left unparsed. returning %s, %s" , parsed , suggestions ) return parsed , unparsed , suggestions token = unparsed . pop ( ) . strip ( ) logger . debug ( "begin parsing at %s w/ tokens: %s" , root . no... | Recursively walks the syntax tree at root and returns the items parsed unparsed and possible suggestions |
33,426 | def evalOptions ( self , root , parsed , unparsed ) : logger . debug ( "parsing options at tree: %s with p:%s, u:%s" , root . node , parsed , unparsed ) suggestions = dict ( ) token = unparsed . pop ( ) . strip ( ) parts = token . partition ( '=' ) if parts [ - 1 ] != '' : token = parts [ 0 ] allFlags = root . localFla... | Evaluate only the options and return flags as suggestions |
33,427 | def setup_logging ( level , monchrome = False , log_file = None ) : if log_file : logging . basicConfig ( filename = log_file , filemode = 'w' , level = logging . DEBUG ) ch = logging . StreamHandler ( ) ch . setLevel ( logging . DEBUG ) formatter = ColoredFormatter ( "%(levelname)s: %(message)s" , monchrome ) ch . set... | Utility function for setting up logging . |
33,428 | def generate ( self , cache_root ) : generator_cwd = os . path . join ( cache_root , 'generated' , self . vlnv . sanitized_name ) generator_input_file = os . path . join ( generator_cwd , self . name + '_input.yml' ) logger . info ( 'Generating ' + str ( self . vlnv ) ) if not os . path . exists ( generator_cwd ) : os ... | Run a parametrized generator |
33,429 | def _range_check ( self , value , min_value , max_value ) : if value < min_value or value > max_value : raise ValueError ( '%s out of range - %s is not between %s and %s' % ( self . __class__ . __name__ , value , min_value , max_value ) ) | Utility method to check that the given value is between min_value and max_value . |
33,430 | def _get_default_arg ( args , defaults , arg_index ) : if not defaults : return DefaultArgSpec ( False , None ) args_with_no_defaults = len ( args ) - len ( defaults ) if arg_index < args_with_no_defaults : return DefaultArgSpec ( False , None ) else : value = defaults [ arg_index - args_with_no_defaults ] if ( type ( ... | Method that determines if an argument has default value or not and if yes what is the default value for the argument |
33,431 | def get_method_sig ( method ) : argspec = inspect . getargspec ( method ) arg_index = 0 args = [ ] for arg in argspec . args : default_arg = _get_default_arg ( argspec . args , argspec . defaults , arg_index ) if default_arg . has_default : val = default_arg . default_value if isinstance ( val , basestring ) : val = '"... | Given a function it returns a string that pretty much looks how the function signature would be written in python . |
33,432 | def group_by ( self , * args ) : for name in args : assert name in self . _fields or name in self . _calculated_fields , 'Cannot group by `%s` since it is not included in the query' % name qs = copy ( self ) qs . _grouping_fields = args return qs | This method lets you specify the grouping fields explicitly . The args must be names of grouping fields or calculated fields that this queryset was created with . |
33,433 | def select_fields_as_sql ( self ) : return comma_join ( list ( self . _fields ) + [ '%s AS %s' % ( v , k ) for k , v in self . _calculated_fields . items ( ) ] ) | Returns the selected fields or expressions as a SQL string . |
33,434 | def count ( self ) : sql = u'SELECT count() FROM (%s)' % self . as_sql ( ) raw = self . _database . raw ( sql ) return int ( raw ) if raw else 0 | Returns the number of rows after aggregation . |
33,435 | def set_database ( self , db ) : from . database import Database assert isinstance ( db , Database ) , "database must be database.Database instance" self . _database = db | Sets the Database that this model instance belongs to . This is done automatically when the instance is read from the database or written to it . |
33,436 | def from_tsv ( cls , line , field_names , timezone_in_use = pytz . utc , database = None ) : from six import next values = iter ( parse_tsv ( line ) ) kwargs = { } for name in field_names : field = getattr ( cls , name ) kwargs [ name ] = field . to_python ( next ( values ) , timezone_in_use ) obj = cls ( ** kwargs ) i... | Create a model instance from a tab - separated line . The line may or may not include a newline . The field_names list must match the fields defined in the model but does not have to include all of them . |
33,437 | def to_tsv ( self , include_readonly = True ) : data = self . __dict__ fields = self . fields ( writable = not include_readonly ) return '\t' . join ( field . to_db_string ( data [ name ] , quote = False ) for name , field in iteritems ( fields ) ) | Returns the instance s column values as a tab - separated line . A newline is not included . |
33,438 | def to_dict ( self , include_readonly = True , field_names = None ) : fields = self . fields ( writable = not include_readonly ) if field_names is not None : fields = [ f for f in fields if f in field_names ] data = self . __dict__ return { name : data [ name ] for name in fields } | Returns the instance s column values as a dict . |
33,439 | def import_submodules ( package_name ) : import importlib , pkgutil package = importlib . import_module ( package_name ) return { name : importlib . import_module ( package_name + '.' + name ) for _ , name , _ in pkgutil . iter_modules ( package . __path__ ) } | Import all submodules of a module . |
33,440 | def get_error_code_msg ( cls , full_error_message ) : for pattern in cls . ERROR_PATTERNS : match = pattern . match ( full_error_message ) if match : return int ( match . group ( 'code' ) ) , match . group ( 'msg' ) . strip ( ) return 0 , full_error_message | Extract the code and message of the exception that clickhouse - server generated . |
33,441 | def create_table ( self , model_class ) : if model_class . is_system_model ( ) : raise DatabaseException ( "You can't create system table" ) if getattr ( model_class , 'engine' ) is None : raise DatabaseException ( "%s class must define an engine" % model_class . __name__ ) self . _send ( model_class . create_table_sql... | Creates a table for the given model class if it does not exist already . |
33,442 | def drop_table ( self , model_class ) : if model_class . is_system_model ( ) : raise DatabaseException ( "You can't drop system table" ) self . _send ( model_class . drop_table_sql ( self ) ) | Drops the database table of the given model class if it exists . |
33,443 | def does_table_exist ( self , model_class ) : sql = "SELECT count() FROM system.tables WHERE database = '%s' AND name = '%s'" r = self . _send ( sql % ( self . db_name , model_class . table_name ( ) ) ) return r . text . strip ( ) == '1' | Checks whether a table for the given model class already exists . Note that this only checks for existence of a table with the expected name . |
33,444 | def insert ( self , model_instances , batch_size = 1000 ) : from six import next from io import BytesIO i = iter ( model_instances ) try : first_instance = next ( i ) except StopIteration : return model_class = first_instance . __class__ if first_instance . is_read_only ( ) or first_instance . is_system_model ( ) : rai... | Insert records into the database . |
33,445 | def count ( self , model_class , conditions = None ) : query = 'SELECT count() FROM $table' if conditions : query += ' WHERE ' + conditions query = self . _substitute ( query , model_class ) r = self . _send ( query ) return int ( r . text ) if r . text else 0 | Counts the number of records in the model s table . |
33,446 | def select ( self , query , model_class = None , settings = None ) : query += ' FORMAT TabSeparatedWithNamesAndTypes' query = self . _substitute ( query , model_class ) r = self . _send ( query , settings , True ) lines = r . iter_lines ( ) field_names = parse_tsv ( next ( lines ) ) field_types = parse_tsv ( next ( lin... | Performs a query and returns a generator of model instances . |
33,447 | def raw ( self , query , settings = None , stream = False ) : query = self . _substitute ( query , None ) return self . _send ( query , settings = settings , stream = stream ) . text | Performs a query and returns its output as text . |
33,448 | def paginate ( self , model_class , order_by , page_num = 1 , page_size = 100 , conditions = None , settings = None ) : count = self . count ( model_class , conditions ) pages_total = int ( ceil ( count / float ( page_size ) ) ) if page_num == - 1 : page_num = max ( pages_total , 1 ) elif page_num < 1 : raise ValueErro... | Selects records and returns a single page of model instances . |
33,449 | def migrate ( self , migrations_package_name , up_to = 9999 ) : from . migrations import MigrationHistory logger = logging . getLogger ( 'migrations' ) applied_migrations = self . _get_applied_migrations ( migrations_package_name ) modules = import_submodules ( migrations_package_name ) unapplied_migrations = set ( mod... | Executes schema migrations . |
33,450 | def _try_get_string ( dev , index , langid = None , default_str_i0 = "" , default_access_error = "Error Accessing String" ) : if index == 0 : string = default_str_i0 else : try : if langid is None : string = util . get_string ( dev , index ) else : string = util . get_string ( dev , index , langid ) except : string = d... | try to get a string but return a string no matter what |
33,451 | def _try_lookup ( table , value , default = "" ) : try : string = table [ value ] except KeyError : string = default return string | try to get a string from the lookup table return instead of key error |
33,452 | def find ( find_all = False , backend = None , custom_match = None , ** args ) : r def device_iter ( ** kwargs ) : for dev in backend . enumerate_devices ( ) : d = Device ( dev , backend ) tests = ( val == getattr ( d , key ) for key , val in kwargs . items ( ) ) if _interop . _all ( tests ) and ( custom_match is None ... | r Find an USB device and return it . |
33,453 | def show_devices ( verbose = False , ** kwargs ) : kwargs [ "find_all" ] = True devices = find ( ** kwargs ) strings = "" for device in devices : if not verbose : strings += "%s, %s\n" % ( device . _str ( ) , _try_lookup ( _lu . device_classes , device . bDeviceClass ) ) else : strings += "%s\n\n" % str ( device ) retu... | Show information about connected devices . |
33,454 | def langids ( self ) : if self . _langids is None : try : self . _langids = util . get_langids ( self ) except USBError : self . _langids = ( ) return self . _langids | Return the USB device s supported language ID codes . |
33,455 | def serial_number ( self ) : if self . _serial_number is None : self . _serial_number = util . get_string ( self , self . iSerialNumber ) return self . _serial_number | Return the USB device s serial number string descriptor . |
33,456 | def product ( self ) : if self . _product is None : self . _product = util . get_string ( self , self . iProduct ) return self . _product | Return the USB device s product string descriptor . |
33,457 | def parent ( self ) : if self . _has_parent is None : _parent = self . _ctx . backend . get_parent ( self . _ctx . dev ) self . _has_parent = _parent is not None if self . _has_parent : self . _parent = Device ( _parent , self . _ctx . backend ) else : self . _parent = None return self . _parent | Return the parent device . |
33,458 | def manufacturer ( self ) : if self . _manufacturer is None : self . _manufacturer = util . get_string ( self , self . iManufacturer ) return self . _manufacturer | Return the USB device s manufacturer string descriptor . |
33,459 | def set_interface_altsetting ( self , interface = None , alternate_setting = None ) : r self . _ctx . managed_set_interface ( self , interface , alternate_setting ) | r Set the alternate setting for an interface . |
33,460 | def reset ( self ) : r self . _ctx . managed_open ( ) self . _ctx . dispose ( self , False ) self . _ctx . backend . reset_device ( self . _ctx . handle ) self . _ctx . dispose ( self , True ) | r Reset the device . |
33,461 | def ctrl_transfer ( self , bmRequestType , bRequest , wValue = 0 , wIndex = 0 , data_or_wLength = None , timeout = None ) : r try : buff = util . create_buffer ( data_or_wLength ) except TypeError : buff = _interop . as_array ( data_or_wLength ) self . _ctx . managed_open ( ) recipient = bmRequestType & 3 rqtype = bmRe... | r Do a control transfer on the endpoint 0 . |
33,462 | def is_kernel_driver_active ( self , interface ) : r self . _ctx . managed_open ( ) return self . _ctx . backend . is_kernel_driver_active ( self . _ctx . handle , interface ) | r Determine if there is kernel driver associated with the interface . |
33,463 | def detach_kernel_driver ( self , interface ) : r self . _ctx . managed_open ( ) self . _ctx . backend . detach_kernel_driver ( self . _ctx . handle , interface ) | r Detach a kernel driver . |
33,464 | def load_library ( lib , name = None , lib_cls = None ) : try : if lib_cls : return lib_cls ( lib ) else : return ctypes . CDLL ( lib ) except Exception : if name : lib_msg = '%s (%s)' % ( name , lib ) else : lib_msg = lib lib_msg += ' could not be loaded' if sys . platform == 'cygwin' : lib_msg += ' in cygwin' _LOGGER... | Loads a library . Catches and logs exceptions . |
33,465 | def load_locate_library ( candidates , cygwin_lib , name , win_cls = None , cygwin_cls = None , others_cls = None , find_library = None , check_symbols = None ) : if sys . platform == 'cygwin' : if cygwin_lib : loaded_lib = load_library ( cygwin_lib , name , cygwin_cls ) else : raise NoLibraryCandidatesException ( name... | Locates and loads a library . |
33,466 | def get_status ( dev , recipient = None ) : r bmRequestType , wIndex = _parse_recipient ( recipient , util . CTRL_IN ) ret = dev . ctrl_transfer ( bmRequestType = bmRequestType , bRequest = 0x00 , wIndex = wIndex , data_or_wLength = 2 ) return ret [ 0 ] | ( ret [ 1 ] << 8 ) | r Return the status for the specified recipient . |
33,467 | def get_descriptor ( dev , desc_size , desc_type , desc_index , wIndex = 0 ) : r wValue = desc_index | ( desc_type << 8 ) bmRequestType = util . build_request_type ( util . CTRL_IN , util . CTRL_TYPE_STANDARD , util . CTRL_RECIPIENT_DEVICE ) return dev . ctrl_transfer ( bmRequestType = bmRequestType , bRequest = 0x06 ,... | r Return the specified descriptor . |
33,468 | def set_descriptor ( dev , desc , desc_type , desc_index , wIndex = None ) : r wValue = desc_index | ( desc_type << 8 ) bmRequestType = util . build_request_type ( util . CTRL_OUT , util . CTRL_TYPE_STANDARD , util . CTRL_RECIPIENT_DEVICE ) dev . ctrl_transfer ( bmRequestType = bmRequestType , bRequest = 0x07 , wValue ... | r Update an existing descriptor or add a new one . |
33,469 | def get_configuration ( dev ) : r bmRequestType = util . build_request_type ( util . CTRL_IN , util . CTRL_TYPE_STANDARD , util . CTRL_RECIPIENT_DEVICE ) return dev . ctrl_transfer ( bmRequestType , bRequest = 0x08 , data_or_wLength = 1 ) [ 0 ] | r Get the current active configuration of the device . |
33,470 | def get_interface ( dev , bInterfaceNumber ) : r bmRequestType = util . build_request_type ( util . CTRL_IN , util . CTRL_TYPE_STANDARD , util . CTRL_RECIPIENT_INTERFACE ) return dev . ctrl_transfer ( bmRequestType = bmRequestType , bRequest = 0x0a , wIndex = bInterfaceNumber , data_or_wLength = 1 ) [ 0 ] | r Get the current alternate setting of the interface . |
33,471 | def configInputQueue ( ) : def captureInput ( iqueue ) : while True : c = getch ( ) if c == '\x03' or c == '\x04' : log . debug ( "Break received (\\x{0:02X})" . format ( ord ( c ) ) ) iqueue . put ( c ) break log . debug ( "Input Char '{}' received" . format ( c if c != '\r' else '\\r' ) ) iqueue . put ( c ) input_que... | configure a queue for accepting characters and return the queue |
33,472 | def fmt_text ( text ) : PRINTABLE_CHAR = set ( list ( range ( ord ( ' ' ) , ord ( '~' ) + 1 ) ) + [ ord ( '\r' ) , ord ( '\n' ) ] ) newtext = ( "\\x{:02X}" . format ( c ) if c not in PRINTABLE_CHAR else chr ( c ) for c in text ) textlines = "\r\n" . join ( l . strip ( '\r' ) for l in "" . join ( newtext ) . split ( '\n... | convert characters that aren t printable to hex format |
33,473 | def ftdi_to_clkbits ( baudrate ) : clk = 48000000 clk_div = 16 frac_code = [ 0 , 3 , 2 , 4 , 1 , 5 , 6 , 7 ] actual_baud = 0 if baudrate >= clk / clk_div : encoded_divisor = 0 actual_baud = ( clk // clk_div ) elif baudrate >= clk / ( clk_div + clk_div / 2 ) : encoded_divisor = 1 actual_baud = clk // ( clk_div + clk_div... | 10 27 = > divisor = 10000 rate = 300 88 13 = > divisor = 5000 rate = 600 C4 09 = > divisor = 2500 rate = 1200 E2 04 = > divisor = 1250 rate = 2 400 71 02 = > divisor = 625 rate = 4 800 38 41 = > divisor = 312 . 5 rate = 9 600 D0 80 = > divisor = 208 . 25 rate = 14406 9C 80 = > divisor = 156 rate = 19 230 4E C0 = > divi... |
33,474 | def _read ( self ) : while self . _rxactive : try : rv = self . _ep_in . read ( self . _ep_in . wMaxPacketSize ) if self . _isFTDI : status = rv [ : 2 ] if status [ 0 ] != 1 or status [ 1 ] != 0x60 : log . info ( "USB Status: 0x{0:02X} 0x{1:02X}" . format ( * status ) ) rv = rv [ 2 : ] for rvi in rv : self . _rxqueue .... | check ep for data add it to queue and sleep for interval |
33,475 | def _resetFTDI ( self ) : if not self . _isFTDI : return txdir = 0 req_type = 2 recipient = 0 req_type = ( txdir << 7 ) + ( req_type << 5 ) + recipient self . device . ctrl_transfer ( bmRequestType = req_type , bRequest = 0 , wValue = 0 , wIndex = 1 , data_or_wLength = 0 ) | reset the FTDI device |
33,476 | def busses ( ) : r return ( Bus ( g ) for k , g in groupby ( sorted ( core . find ( find_all = True ) , key = lambda d : d . bus ) , lambda d : d . bus ) ) | r Returns a tuple with the usb busses . |
33,477 | def bulkWrite ( self , endpoint , buffer , timeout = 100 ) : r return self . dev . write ( endpoint , buffer , timeout ) | r Perform a bulk write request to the endpoint specified . |
33,478 | def bulkRead ( self , endpoint , size , timeout = 100 ) : r return self . dev . read ( endpoint , size , timeout ) | r Performs a bulk read request to the endpoint specified . |
33,479 | def interruptWrite ( self , endpoint , buffer , timeout = 100 ) : r return self . dev . write ( endpoint , buffer , timeout ) | r Perform a interrupt write request to the endpoint specified . |
33,480 | def interruptRead ( self , endpoint , size , timeout = 100 ) : r return self . dev . read ( endpoint , size , timeout ) | r Performs a interrupt read request to the endpoint specified . |
33,481 | def controlMsg ( self , requestType , request , buffer , value = 0 , index = 0 , timeout = 100 ) : r return self . dev . ctrl_transfer ( requestType , request , wValue = value , wIndex = index , data_or_wLength = buffer , timeout = timeout ) | r Perform a control request to the default control pipe on a device . |
33,482 | def claimInterface ( self , interface ) : r if isinstance ( interface , Interface ) : interface = interface . interfaceNumber util . claim_interface ( self . dev , interface ) self . __claimed_interface = interface | r Claims the interface with the Operating System . |
33,483 | def releaseInterface ( self ) : r util . release_interface ( self . dev , self . __claimed_interface ) self . __claimed_interface = - 1 | r Release an interface previously claimed with claimInterface . |
33,484 | def setConfiguration ( self , configuration ) : r if isinstance ( configuration , Configuration ) : configuration = configuration . value self . dev . set_configuration ( configuration ) | r Set the active configuration of a device . |
33,485 | def setAltInterface ( self , alternate ) : r if isinstance ( alternate , Interface ) : alternate = alternate . alternateSetting self . dev . set_interface_altsetting ( self . __claimed_interface , alternate ) | r Sets the active alternate setting of the current interface . |
33,486 | def getString ( self , index , length , langid = None ) : r return util . get_string ( self . dev , index , langid ) . encode ( 'ascii' ) | r Retrieve the string descriptor specified by index and langid from a device . |
33,487 | def getDescriptor ( self , desc_type , desc_index , length , endpoint = - 1 ) : r return control . get_descriptor ( self . dev , length , desc_type , desc_index ) | r Retrieves a descriptor from the device identified by the type and index of the descriptor . |
33,488 | def get_endpoint_descriptor ( self , dev , ep , intf , alt , config ) : r _not_implemented ( self . get_endpoint_descriptor ) | r Return an endpoint descriptor of the given device . |
33,489 | def bulk_write ( self , dev_handle , ep , intf , data , timeout ) : r _not_implemented ( self . bulk_write ) | r Perform a bulk write . |
33,490 | def bulk_read ( self , dev_handle , ep , intf , buff , timeout ) : r _not_implemented ( self . bulk_read ) | r Perform a bulk read . |
33,491 | def intr_write ( self , dev_handle , ep , intf , data , timeout ) : r _not_implemented ( self . intr_write ) | r Perform an interrupt write . |
33,492 | def intr_read ( self , dev_handle , ep , intf , size , timeout ) : r _not_implemented ( self . intr_read ) | r Perform an interrut read . |
33,493 | def iso_write ( self , dev_handle , ep , intf , data , timeout ) : r _not_implemented ( self . iso_write ) | r Perform an isochronous write . |
33,494 | def iso_read ( self , dev_handle , ep , intf , size , timeout ) : r _not_implemented ( self . iso_read ) | r Perform an isochronous read . |
33,495 | def ctrl_transfer ( self , dev_handle , bmRequestType , bRequest , wValue , wIndex , data , timeout ) : r _not_implemented ( self . ctrl_transfer ) | r Perform a control transfer on the endpoint 0 . |
33,496 | def find_descriptor ( desc , find_all = False , custom_match = None , ** args ) : r def desc_iter ( ** kwargs ) : for d in desc : tests = ( val == getattr ( d , key ) for key , val in kwargs . items ( ) ) if _interop . _all ( tests ) and ( custom_match is None or custom_match ( d ) ) : yield d if find_all : return desc... | r Find an inner descriptor . |
33,497 | def get_langids ( dev ) : r from usb . control import get_descriptor buf = get_descriptor ( dev , 254 , DESC_TYPE_STRING , 0 ) if len ( buf ) < 4 or buf [ 0 ] < 4 or buf [ 0 ] & 1 != 0 : return ( ) return tuple ( map ( lambda x , y : x + ( y << 8 ) , buf [ 2 : buf [ 0 ] : 2 ] , buf [ 3 : buf [ 0 ] : 2 ] ) ) | r Retrieve the list of supported Language IDs from the device . |
33,498 | def get_string ( dev , index , langid = None ) : r if 0 == index : return None from usb . control import get_descriptor langids = dev . langids if 0 == len ( langids ) : raise ValueError ( "The device has no langid" ) if langid is None : langid = langids [ 0 ] elif langid not in langids : raise ValueError ( "The device... | r Retrieve a string descriptor from the device . |
33,499 | def _set_translations ( self ) : pcell = PhonopyAtoms ( numbers = [ 1 ] , scaled_positions = [ [ 0 , 0 , 0 ] ] , cell = np . diag ( [ 1 , 1 , 1 ] ) ) smat = self . _supercell_matrix self . _trans_s = get_supercell ( pcell , smat ) . get_scaled_positions ( ) self . _trans_p = np . dot ( self . _trans_s , self . _superce... | Set primitive translations in supercell |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.