idx
int64
0
252k
question
stringlengths
48
5.28k
target
stringlengths
5
1.23k
230,800
def add_membership_listener ( self , member_added = None , member_removed = None , fire_for_existing = False ) : self . membership_listeners . append ( ( member_added , member_removed , fire_for_existing ) ) return self
Helper method for adding membership listeners
230,801
def set_custom_serializer ( self , _type , serializer ) : validate_type ( _type ) validate_serializer ( serializer , StreamSerializer ) self . _custom_serializers [ _type ] = serializer
Assign a serializer for the type .
230,802
def get ( self , property ) : return self . _properties . get ( property . name ) or os . getenv ( property . name ) or property . default_value
Gets the value of the given property . First checks client config properties then environment variables and lastly fall backs to the default value of the property .
230,803
def get_bool ( self , property ) : value = self . get ( property ) if isinstance ( value , bool ) : return value return value . lower ( ) == "true"
Gets the value of the given property as boolean .
230,804
def get_seconds ( self , property ) : return TimeUnit . to_seconds ( self . get ( property ) , property . time_unit )
Gets the value of the given property in seconds . If the value of the given property is not a number throws TypeError .
230,805
def get_seconds_positive_or_default ( self , property ) : seconds = self . get_seconds ( property ) return seconds if seconds > 0 else TimeUnit . to_seconds ( property . default_value , property . time_unit )
Gets the value of the given property in seconds . If the value of the given property is not a number throws TypeError . If the value of the given property in seconds is not positive tries to return the default value in seconds .
230,806
def start ( self ) : self . logger . debug ( "Starting partition service" , extra = self . _logger_extras ) def partition_updater ( ) : self . _do_refresh ( ) self . timer = self . _client . reactor . add_timer ( PARTITION_UPDATE_INTERVAL , partition_updater ) self . timer = self . _client . reactor . add_timer ( PARTI...
Starts the partition service .
230,807
def get_partition_owner ( self , partition_id ) : if partition_id not in self . partitions : self . _do_refresh ( ) return self . partitions . get ( partition_id , None )
Gets the owner of the partition if it s set . Otherwise it will trigger partition assignment .
230,808
def get_partition_id ( self , key ) : data = self . _client . serialization_service . to_data ( key ) count = self . get_partition_count ( ) if count <= 0 : return 0 return hash_to_index ( data . get_partition_hash ( ) , count )
Returns the partition id for a Data key .
230,809
def murmur_hash3_x86_32 ( data , offset , size , seed = 0x01000193 ) : key = bytearray ( data [ offset : offset + size ] ) length = len ( key ) nblocks = int ( length / 4 ) h1 = seed c1 = 0xcc9e2d51 c2 = 0x1b873593 for block_start in range ( 0 , nblocks * 4 , 4 ) : k1 = key [ block_start + 3 ] << 24 | key [ block_start...
murmur3 hash function to determine partition
230,810
def add ( self , item ) : check_not_none ( item , "Value can't be None" ) element_data = self . _to_data ( item ) return self . _encode_invoke ( list_add_codec , value = element_data )
Adds the specified item to the end of this list .
230,811
def add_at ( self , index , item ) : check_not_none ( item , "Value can't be None" ) element_data = self . _to_data ( item ) return self . _encode_invoke ( list_add_with_index_codec , index = index , value = element_data )
Adds the specified item at the specific position in this list . Element in this position and following elements are shifted to the right if any .
230,812
def add_all ( self , items ) : check_not_none ( items , "Value can't be None" ) data_items = [ ] for item in items : check_not_none ( item , "Value can't be None" ) data_items . append ( self . _to_data ( item ) ) return self . _encode_invoke ( list_add_all_codec , value_list = data_items )
Adds all of the items in the specified collection to the end of this list . The order of new elements is determined by the specified collection s iterator .
230,813
def add_all_at ( self , index , items ) : check_not_none ( items , "Value can't be None" ) data_items = [ ] for item in items : check_not_none ( item , "Value can't be None" ) data_items . append ( self . _to_data ( item ) ) return self . _encode_invoke ( list_add_all_with_index_codec , index = index , value_list = dat...
Adds all of the elements in the specified collection into this list at the specified position . Elements in this positions and following elements are shifted to the right if any . The order of new elements is determined by the specified collection s iterator .
230,814
def contains_all ( self , items ) : check_not_none ( items , "Items can't be None" ) data_items = [ ] for item in items : check_not_none ( item , "item can't be None" ) data_items . append ( self . _to_data ( item ) ) return self . _encode_invoke ( list_contains_all_codec , values = data_items )
Determines whether this list contains all of the items in specified collection or not .
230,815
def index_of ( self , item ) : check_not_none ( item , "Value can't be None" ) item_data = self . _to_data ( item ) return self . _encode_invoke ( list_index_of_codec , value = item_data )
Returns the first index of specified items s occurrences in this list . If specified item is not present in this list returns - 1 .
230,816
def last_index_of ( self , item ) : check_not_none ( item , "Value can't be None" ) item_data = self . _to_data ( item ) return self . _encode_invoke ( list_last_index_of_codec , value = item_data )
Returns the last index of specified items s occurrences in this list . If specified item is not present in this list returns - 1 .
230,817
def remove ( self , item ) : check_not_none ( item , "Value can't be None" ) item_data = self . _to_data ( item ) return self . _encode_invoke ( list_remove_codec , value = item_data )
Removes the specified element s first occurrence from the list if it exists in this list .
230,818
def remove_all ( self , items ) : check_not_none ( items , "Value can't be None" ) data_items = [ ] for item in items : check_not_none ( item , "Value can't be None" ) data_items . append ( self . _to_data ( item ) ) return self . _encode_invoke ( list_compare_and_remove_all_codec , values = data_items )
Removes all of the elements that is present in the specified collection from this list .
230,819
def retain_all ( self , items ) : check_not_none ( items , "Value can't be None" ) data_items = [ ] for item in items : check_not_none ( item , "Value can't be None" ) data_items . append ( self . _to_data ( item ) ) return self . _encode_invoke ( list_compare_and_retain_all_codec , values = data_items )
Retains only the items that are contained in the specified collection . It means items which are not present in the specified collection are removed from this list .
230,820
def set_at ( self , index , item ) : check_not_none ( item , "Value can't be None" ) element_data = self . _to_data ( item ) return self . _encode_invoke ( list_set_codec , index = index , value = element_data )
Replaces the specified element with the element at the specified position in this list .
230,821
def add_index ( self , attribute , ordered = False ) : return self . _encode_invoke ( map_add_index_codec , attribute = attribute , ordered = ordered )
Adds an index to this map for the specified entries so that queries can run faster .
230,822
def add_interceptor ( self , interceptor ) : return self . _encode_invoke ( map_add_interceptor_codec , interceptor = self . _to_data ( interceptor ) )
Adds an interceptor for this map . Added interceptor will intercept operations and execute user defined methods .
230,823
def entry_set ( self , predicate = None ) : if predicate : predicate_data = self . _to_data ( predicate ) return self . _encode_invoke ( map_entries_with_predicate_codec , predicate = predicate_data ) else : return self . _encode_invoke ( map_entry_set_codec )
Returns a list clone of the mappings contained in this map .
230,824
def evict ( self , key ) : check_not_none ( key , "key can't be None" ) key_data = self . _to_data ( key ) return self . _evict_internal ( key_data )
Evicts the specified key from this map .
230,825
def execute_on_entries ( self , entry_processor , predicate = None ) : if predicate : return self . _encode_invoke ( map_execute_with_predicate_codec , entry_processor = self . _to_data ( entry_processor ) , predicate = self . _to_data ( predicate ) ) return self . _encode_invoke ( map_execute_on_all_keys_codec , entry...
Applies the user defined EntryProcessor to all the entries in the map or entries in the map which satisfies the predicate if provided . Returns the results mapped by each key in the map .
230,826
def execute_on_key ( self , key , entry_processor ) : check_not_none ( key , "key can't be None" ) key_data = self . _to_data ( key ) return self . _execute_on_key_internal ( key_data , entry_processor )
Applies the user defined EntryProcessor to the entry mapped by the key . Returns the object which is the result of EntryProcessor s process method .
230,827
def execute_on_keys ( self , keys , entry_processor ) : key_list = [ ] for key in keys : check_not_none ( key , "key can't be None" ) key_list . append ( self . _to_data ( key ) ) if len ( keys ) == 0 : return ImmediateFuture ( [ ] ) return self . _encode_invoke ( map_execute_on_keys_codec , entry_processor = self . _t...
Applies the user defined EntryProcessor to the entries mapped by the collection of keys . Returns the results mapped by each key in the collection .
230,828
def force_unlock ( self , key ) : check_not_none ( key , "key can't be None" ) key_data = self . _to_data ( key ) return self . _encode_invoke_on_key ( map_force_unlock_codec , key_data , key = key_data , reference_id = self . reference_id_generator . get_and_increment ( ) )
Releases the lock for the specified key regardless of the lock owner . It always successfully unlocks the key never blocks and returns immediately .
230,829
def get_all ( self , keys ) : check_not_none ( keys , "keys can't be None" ) if not keys : return ImmediateFuture ( { } ) partition_service = self . _client . partition_service partition_to_keys = { } for key in keys : check_not_none ( key , "key can't be None" ) key_data = self . _to_data ( key ) partition_id = partit...
Returns the entries for the given keys .
230,830
def get_entry_view ( self , key ) : check_not_none ( key , "key can't be None" ) key_data = self . _to_data ( key ) return self . _encode_invoke_on_key ( map_get_entry_view_codec , key_data , key = key_data , thread_id = thread_id ( ) )
Returns the EntryView for the specified key .
230,831
def is_locked ( self , key ) : check_not_none ( key , "key can't be None" ) key_data = self . _to_data ( key ) return self . _encode_invoke_on_key ( map_is_locked_codec , key_data , key = key_data )
Checks the lock for the specified key . If the lock is acquired it returns true . Otherwise it returns false .
230,832
def key_set ( self , predicate = None ) : if predicate : predicate_data = self . _to_data ( predicate ) return self . _encode_invoke ( map_key_set_with_predicate_codec , predicate = predicate_data ) else : return self . _encode_invoke ( map_key_set_codec )
Returns a List clone of the keys contained in this map or the keys of the entries filtered with the predicate if provided .
230,833
def load_all ( self , keys = None , replace_existing_values = True ) : if keys : key_data_list = list ( map ( self . _to_data , keys ) ) return self . _load_all_internal ( key_data_list , replace_existing_values ) else : return self . _encode_invoke ( map_load_all_codec , replace_existing_values = replace_existing_valu...
Loads all keys from the store at server side or loads the given keys if provided .
230,834
def put_if_absent ( self , key , value , ttl = - 1 ) : check_not_none ( key , "key can't be None" ) check_not_none ( value , "value can't be None" ) key_data = self . _to_data ( key ) value_data = self . _to_data ( value ) return self . _put_if_absent_internal ( key_data , value_data , ttl )
Associates the specified key with the given value if it is not already associated . If ttl is provided entry will expire and get evicted after the ttl .
230,835
def remove_if_same ( self , key , value ) : check_not_none ( key , "key can't be None" ) check_not_none ( value , "value can't be None" ) key_data = self . _to_data ( key ) value_data = self . _to_data ( value ) return self . _remove_if_same_internal_ ( key_data , value_data )
Removes the entry for a key only if it is currently mapped to a given value .
230,836
def replace ( self , key , value ) : check_not_none ( key , "key can't be None" ) check_not_none ( value , "value can't be None" ) key_data = self . _to_data ( key ) value_data = self . _to_data ( value ) return self . _replace_internal ( key_data , value_data )
Replaces the entry for a key only if it is currently mapped to some value .
230,837
def replace_if_same ( self , key , old_value , new_value ) : check_not_none ( key , "key can't be None" ) check_not_none ( old_value , "old_value can't be None" ) check_not_none ( new_value , "new_value can't be None" ) key_data = self . _to_data ( key ) old_value_data = self . _to_data ( old_value ) new_value_data = s...
Replaces the entry for a key only if it is currently mapped to a given value .
230,838
def set ( self , key , value , ttl = - 1 ) : check_not_none ( key , "key can't be None" ) check_not_none ( value , "value can't be None" ) key_data = self . _to_data ( key ) value_data = self . _to_data ( value ) return self . _set_internal ( key_data , value_data , ttl )
Puts an entry into this map . Similar to the put operation except that set doesn t return the old value which is more efficient . If ttl is provided entry will expire and get evicted after the ttl .
230,839
def try_put ( self , key , value , timeout = 0 ) : check_not_none ( key , "key can't be None" ) check_not_none ( value , "value can't be None" ) key_data = self . _to_data ( key ) value_data = self . _to_data ( value ) return self . _try_put_internal ( key_data , value_data , timeout )
Tries to put the given key and value into this map and returns immediately if timeout is not provided . If timeout is provided operation waits until it is completed or timeout is reached .
230,840
def try_remove ( self , key , timeout = 0 ) : check_not_none ( key , "key can't be None" ) key_data = self . _to_data ( key ) return self . _try_remove_internal ( key_data , timeout )
Tries to remove the given key from this map and returns immediately if timeout is not provided . If timeout is provided operation waits until it is completed or timeout is reached .
230,841
def unlock ( self , key ) : check_not_none ( key , "key can't be None" ) key_data = self . _to_data ( key ) return self . _encode_invoke_on_key ( map_unlock_codec , key_data , key = key_data , thread_id = thread_id ( ) , reference_id = self . reference_id_generator . get_and_increment ( ) )
Releases the lock for the specified key . It never blocks and returns immediately . If the current thread is the holder of this lock then the hold count is decremented . If the hold count is zero then the lock is released .
230,842
def values ( self , predicate = None ) : if predicate : predicate_data = self . _to_data ( predicate ) return self . _encode_invoke ( map_values_with_predicate_codec , predicate = predicate_data ) else : return self . _encode_invoke ( map_values_codec )
Returns a list clone of the values contained in this map or values of the entries which are filtered with the predicate if provided .
230,843
def new_transaction ( self , timeout , durability , transaction_type ) : connection = self . _connect ( ) return Transaction ( self . _client , connection , timeout , durability , transaction_type )
Creates a Transaction object with given timeout durability and transaction type .
230,844
def begin ( self ) : if hasattr ( self . _locals , 'transaction_exists' ) and self . _locals . transaction_exists : raise TransactionError ( "Nested transactions are not allowed." ) if self . state != _STATE_NOT_STARTED : raise TransactionError ( "Transaction has already been started." ) self . _locals . transaction_ex...
Begins this transaction .
230,845
def commit ( self ) : self . _check_thread ( ) if self . state != _STATE_ACTIVE : raise TransactionError ( "Transaction is not active." ) try : self . _check_timeout ( ) request = transaction_commit_codec . encode_request ( self . id , self . thread_id ) self . client . invoker . invoke_on_connection ( request , self ....
Commits this transaction .
230,846
def rollback ( self ) : self . _check_thread ( ) if self . state not in ( _STATE_ACTIVE , _STATE_PARTIAL_COMMIT ) : raise TransactionError ( "Transaction is not active." ) try : if self . state != _STATE_PARTIAL_COMMIT : request = transaction_rollback_codec . encode_request ( self . id , self . thread_id ) self . clien...
Rollback of this current transaction .
230,847
def load_addresses ( self ) : try : return list ( self . cloud_discovery . discover_nodes ( ) . keys ( ) ) except Exception as ex : self . logger . warning ( "Failed to load addresses from Hazelcast.cloud: {}" . format ( ex . args [ 0 ] ) , extra = self . _logger_extras ) return [ ]
Loads member addresses from Hazelcast . cloud endpoint .
230,848
def translate ( self , address ) : if address is None : return None public_address = self . _private_to_public . get ( address ) if public_address : return public_address self . refresh ( ) return self . _private_to_public . get ( address )
Translates the given address to another address specific to network or service .
230,849
def refresh ( self ) : try : self . _private_to_public = self . cloud_discovery . discover_nodes ( ) except Exception as ex : self . logger . warning ( "Failed to load addresses from Hazelcast.cloud: {}" . format ( ex . args [ 0 ] ) , extra = self . _logger_extras )
Refreshes the internal lookup table if necessary .
230,850
def get_host_and_url ( properties , cloud_token ) : host = properties . get ( HazelcastCloudDiscovery . CLOUD_URL_BASE_PROPERTY . name , HazelcastCloudDiscovery . CLOUD_URL_BASE_PROPERTY . default_value ) host = host . replace ( "https://" , "" ) host = host . replace ( "http://" , "" ) return host , HazelcastCloudDisc...
Helper method to get host and url that can be used in HTTPSConnection .
230,851
def try_set_count ( self , count ) : check_not_negative ( count , "count can't be negative" ) return self . _encode_invoke ( count_down_latch_try_set_count_codec , count = count )
Sets the count to the given value if the current count is zero . If count is not zero this method does nothing and returns false .
230,852
def destroy ( self ) : self . _on_destroy ( ) return self . _client . proxy . destroy_proxy ( self . service_name , self . name )
Destroys this proxy .
230,853
def add_listener ( self , member_added = None , member_removed = None , fire_for_existing = False ) : registration_id = str ( uuid . uuid4 ( ) ) self . listeners [ registration_id ] = ( member_added , member_removed ) if fire_for_existing : for member in self . get_member_list ( ) : member_added ( member ) return regis...
Adds a membership listener to listen for membership updates it will be notified when a member is added to cluster or removed from cluster . There is no check for duplicate registrations so if you register the listener twice it will get events twice .
230,854
def remove_listener ( self , registration_id ) : try : self . listeners . pop ( registration_id ) return True except KeyError : return False
Removes the specified membership listener .
230,855
def get_member_by_uuid ( self , member_uuid ) : for member in self . get_member_list ( ) : if member . uuid == member_uuid : return member
Returns the member with specified member uuid .
230,856
def get_members ( self , selector ) : members = [ ] for member in self . get_member_list ( ) : if selector . select ( member ) : members . append ( member ) return members
Returns the members that satisfy the given selector .
230,857
def is_after ( self , other ) : any_timestamp_greater = False for replica_id , other_timestamp in other . entry_set ( ) : local_timestamp = self . _replica_timestamps . get ( replica_id ) if local_timestamp is None or local_timestamp < other_timestamp : return False elif local_timestamp > other_timestamp : any_timestam...
Returns true if this vector clock is causally strictly after the provided vector clock . This means that it the provided clock is neither equal to greater than or concurrent to this vector clock .
230,858
def contains ( self , item ) : check_not_none ( item , "Value can't be None" ) item_data = self . _to_data ( item ) return self . _encode_invoke ( set_contains_codec , value = item_data )
Determines whether this set contains the specified item or not .
230,859
def contains_all ( self , items ) : check_not_none ( items , "Value can't be None" ) data_items = [ ] for item in items : check_not_none ( item , "Value can't be None" ) data_items . append ( self . _to_data ( item ) ) return self . _encode_invoke ( set_contains_all_codec , items = data_items )
Determines whether this set contains all of the items in the specified collection or not .
230,860
def alter ( self , function ) : check_not_none ( function , "function can't be None" ) return self . _encode_invoke ( atomic_long_alter_codec , function = self . _to_data ( function ) )
Alters the currently stored value by applying a function on it .
230,861
def alter_and_get ( self , function ) : check_not_none ( function , "function can't be None" ) return self . _encode_invoke ( atomic_long_alter_and_get_codec , function = self . _to_data ( function ) )
Alters the currently stored value by applying a function on it and gets the result .
230,862
def get_and_alter ( self , function ) : check_not_none ( function , "function can't be None" ) return self . _encode_invoke ( atomic_long_get_and_alter_codec , function = self . _to_data ( function ) )
Alters the currently stored value by applying a function on it on and gets the old value .
230,863
def main ( jlink_serial , device ) : buf = StringIO . StringIO ( ) jlink = pylink . JLink ( log = buf . write , detailed_log = buf . write ) jlink . open ( serial_no = jlink_serial ) jlink . set_tif ( pylink . enums . JLinkInterfaces . SWD ) jlink . connect ( device , verbose = True ) sys . stdout . write ( 'ARM Id: %d...
Prints the core s information .
230,864
def acquire ( self ) : if os . path . exists ( self . path ) : try : pid = None with open ( self . path , 'r' ) as f : line = f . readline ( ) . strip ( ) pid = int ( line ) if not psutil . pid_exists ( pid ) : os . remove ( self . path ) except ValueError as e : os . remove ( self . path ) except IOError as e : pass t...
Attempts to acquire a lock for the J - Link lockfile .
230,865
def release ( self ) : if not self . acquired : return False os . close ( self . fd ) if os . path . exists ( self . path ) : os . remove ( self . path ) self . acquired = False return True
Cleans up the lockfile if it was acquired .
230,866
def calculate_parity ( n ) : if not is_natural ( n ) : raise ValueError ( 'Expected n to be a positive integer.' ) y = 0 n = abs ( n ) while n : y += n & 1 n = n >> 1 return y & 1
Calculates and returns the parity of a number .
230,867
def pack ( value , nbits = None ) : if nbits is None : nbits = pack_size ( value ) * BITS_PER_BYTE elif nbits <= 0 : raise ValueError ( 'Given number of bits must be greater than 0.' ) buf_size = int ( math . ceil ( nbits / float ( BITS_PER_BYTE ) ) ) buf = ( ctypes . c_uint8 * buf_size ) ( ) for ( idx , _ ) in enumera...
Packs a given value into an array of 8 - bit unsigned integers .
230,868
def long_description ( ) : cwd = os . path . abspath ( os . path . dirname ( __file__ ) ) readme_path = os . path . join ( cwd , 'README.md' ) if not os . path . exists ( readme_path ) : return pylink . __long_description__ try : import pypandoc return pypandoc . convert ( readme_path , 'rst' ) except ( IOError , Impor...
Reads and returns the contents of the README .
230,869
def finalize_options ( self ) : self . cwd = os . path . abspath ( os . path . dirname ( __file__ ) ) self . build_dirs = [ os . path . join ( self . cwd , 'build' ) , os . path . join ( self . cwd , 'htmlcov' ) , os . path . join ( self . cwd , 'dist' ) , os . path . join ( self . cwd , 'pylink_square.egg-info' ) ] se...
Populate the attributes .
230,870
def finalize_options ( self ) : self . cwd = os . path . abspath ( os . path . dirname ( __file__ ) ) self . test_dir = os . path . join ( self . cwd , 'tests' )
Finalizes the command s options .
230,871
def unlock_kinetis_identified ( identity , flags ) : if flags . version_code != identity . version_code : return False if flags . part_no != identity . part_no : return False return flags . valid
Checks whether the given flags are a valid identity .
230,872
def unlock_kinetis_abort_clear ( ) : flags = registers . AbortRegisterFlags ( ) flags . STKCMPCLR = 1 flags . STKERRCLR = 1 flags . WDERRCLR = 1 flags . ORUNERRCLR = 1 return flags . value
Returns the abort register clear code .
230,873
def unlock_kinetis_read_until_ack ( jlink , address ) : request = swd . ReadRequest ( address , ap = True ) response = None while True : response = request . send ( jlink ) if response . ack ( ) : break elif response . wait ( ) : continue raise KinetisException ( 'Read exited with status: %s' , response . status ) retu...
Polls the device until the request is acknowledged .
230,874
def unlock_kinetis_swd ( jlink ) : SWDIdentity = Identity ( 0x2 , 0xBA01 ) jlink . power_on ( ) jlink . coresight_configure ( ) flags = registers . IDCodeRegisterFlags ( ) flags . value = jlink . coresight_read ( 0x0 , False ) if not unlock_kinetis_identified ( SWDIdentity , flags ) : return False flags = registers . C...
Unlocks a Kinetis device over SWD .
230,875
def unlock_kinetis ( jlink ) : if not jlink . connected ( ) : raise ValueError ( 'No target to unlock.' ) method = UNLOCK_METHODS . get ( jlink . tif , None ) if method is None : raise NotImplementedError ( 'Unsupported target interface for unlock.' ) return method ( jlink )
Unlock for Freescale Kinetis K40 or K60 device .
230,876
def minimum_required ( version ) : def _minimum_required ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : if list ( self . version ) < list ( version ) : raise errors . JLinkException ( 'Version %s required.' % version ) return func ( self , * args , ** kwargs ) return wrapper return ...
Decorator to specify the minimum SDK version required .
230,877
def open_required ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : if not self . opened ( ) : raise errors . JLinkException ( 'J-Link DLL is not open.' ) elif not self . connected ( ) : raise errors . JLinkException ( 'J-Link connection has been lost.' ) return func ( self , * args , ...
Decorator to specify that the J - Link DLL must be opened and a J - Link connection must be established .
230,878
def connection_required ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : if not self . target_connected ( ) : raise errors . JLinkException ( 'Target is not connected.' ) return func ( self , * args , ** kwargs ) return wrapper
Decorator to specify that a target connection is required in order for the given method to be used .
230,879
def interface_required ( interface ) : def _interface_required ( func ) : @ functools . wraps ( func ) def wrapper ( self , * args , ** kwargs ) : if self . tif != interface : raise errors . JLinkException ( 'Unsupported for current interface.' ) return func ( self , * args , ** kwargs ) return wrapper return _interfac...
Decorator to specify that a particular interface type is required for the given method to be used .
230,880
def log_handler ( self , handler ) : if not self . opened ( ) : handler = handler or util . noop self . _log_handler = enums . JLinkFunctions . LOG_PROTOTYPE ( handler ) self . _dll . JLINKARM_EnableLog ( self . _log_handler )
Setter for the log handler function .
230,881
def detailed_log_handler ( self , handler ) : if not self . opened ( ) : handler = handler or util . noop self . _detailed_log_handler = enums . JLinkFunctions . LOG_PROTOTYPE ( handler ) self . _dll . JLINKARM_EnableLogCom ( self . _detailed_log_handler )
Setter for the detailed log handler function .
230,882
def error_handler ( self , handler ) : if not self . opened ( ) : handler = handler or util . noop self . _error_handler = enums . JLinkFunctions . LOG_PROTOTYPE ( handler ) self . _dll . JLINKARM_SetErrorOutHandler ( self . _error_handler )
Setter for the error handler function .
230,883
def warning_handler ( self , handler ) : if not self . opened ( ) : handler = handler or util . noop self . _warning_handler = enums . JLinkFunctions . LOG_PROTOTYPE ( handler ) self . _dll . JLINKARM_SetWarnOutHandler ( self . _warning_handler )
Setter for the warning handler function .
230,884
def connected_emulators ( self , host = enums . JLinkHost . USB ) : res = self . _dll . JLINKARM_EMU_GetList ( host , 0 , 0 ) if res < 0 : raise errors . JLinkException ( res ) num_devices = res info = ( structs . JLinkConnectInfo * num_devices ) ( ) num_found = self . _dll . JLINKARM_EMU_GetList ( host , info , num_de...
Returns a list of all the connected emulators .
230,885
def supported_device ( self , index = 0 ) : if not util . is_natural ( index ) or index >= self . num_supported_devices ( ) : raise ValueError ( 'Invalid index.' ) info = structs . JLinkDeviceInfo ( ) result = self . _dll . JLINKARM_DEVICE_GetInfo ( index , ctypes . byref ( info ) ) return info
Gets the device at the given index .
230,886
def close ( self ) : self . _dll . JLINKARM_Close ( ) if self . _lock is not None : del self . _lock self . _lock = None return None
Closes the open J - Link .
230,887
def sync_firmware ( self ) : serial_no = self . serial_number if self . firmware_newer ( ) : try : self . invalidate_firmware ( ) self . update_firmware ( ) except errors . JLinkException as e : pass res = self . open ( serial_no = serial_no ) if self . firmware_newer ( ) : raise errors . JLinkException ( 'Failed to sy...
Syncs the emulator s firmware version and the DLL s firmware .
230,888
def exec_command ( self , cmd ) : err_buf = ( ctypes . c_char * self . MAX_BUF_SIZE ) ( ) res = self . _dll . JLINKARM_ExecCommand ( cmd . encode ( ) , err_buf , self . MAX_BUF_SIZE ) err_buf = ctypes . string_at ( err_buf ) . decode ( ) if len ( err_buf ) > 0 : raise errors . JLinkException ( err_buf . strip ( ) ) ret...
Executes the given command .
230,889
def jtag_configure ( self , instr_regs = 0 , data_bits = 0 ) : if not util . is_natural ( instr_regs ) : raise ValueError ( 'IR value is not a natural number.' ) if not util . is_natural ( data_bits ) : raise ValueError ( 'Data bits is not a natural number.' ) self . _dll . JLINKARM_ConfigJTAG ( instr_regs , data_bits ...
Configures the JTAG scan chain to determine which CPU to address .
230,890
def coresight_configure ( self , ir_pre = 0 , dr_pre = 0 , ir_post = 0 , dr_post = 0 , ir_len = 0 , perform_tif_init = True ) : if self . tif == enums . JLinkInterfaces . SWD : res = self . _dll . JLINKARM_CORESIGHT_Configure ( '' ) if res < 0 : raise errors . JLinkException ( res ) return None config_string = 'IRPre=%...
Prepares target and J - Link for CoreSight function usage .
230,891
def connect ( self , chip_name , speed = 'auto' , verbose = False ) : if verbose : self . exec_command ( 'EnableRemarks = 1' ) self . exec_command ( 'Device = %s' % chip_name ) if speed == 'auto' : self . set_speed ( auto = True ) elif speed == 'adaptive' : self . set_speed ( adaptive = True ) else : self . set_speed (...
Connects the J - Link to its target .
230,892
def compile_date ( self ) : result = self . _dll . JLINKARM_GetCompileDateTime ( ) return ctypes . cast ( result , ctypes . c_char_p ) . value . decode ( )
Returns a string specifying the date and time at which the DLL was translated .
230,893
def version ( self ) : version = int ( self . _dll . JLINKARM_GetDLLVersion ( ) ) major = version / 10000 minor = ( version / 100 ) % 100 rev = version % 100 rev = '' if rev == 0 else chr ( rev + ord ( 'a' ) - 1 ) return '%d.%02d%s' % ( major , minor , rev )
Returns the device s version .
230,894
def compatible_firmware_version ( self ) : identifier = self . firmware_version . split ( 'compiled' ) [ 0 ] buf_size = self . MAX_BUF_SIZE buf = ( ctypes . c_char * buf_size ) ( ) res = self . _dll . JLINKARM_GetEmbeddedFWString ( identifier . encode ( ) , buf , buf_size ) if res < 0 : raise errors . JLinkException ( ...
Returns the DLL s compatible J - Link firmware version .
230,895
def firmware_outdated ( self ) : datefmt = ' %b %d %Y %H:%M:%S' compat_date = self . compatible_firmware_version . split ( 'compiled' ) [ 1 ] compat_date = datetime . datetime . strptime ( compat_date , datefmt ) fw_date = self . firmware_version . split ( 'compiled' ) [ 1 ] fw_date = datetime . datetime . strptime ( f...
Returns whether the J - Link s firmware version is older than the one that the DLL is compatible with .
230,896
def hardware_info ( self , mask = 0xFFFFFFFF ) : buf = ( ctypes . c_uint32 * 32 ) ( ) res = self . _dll . JLINKARM_GetHWInfo ( mask , ctypes . byref ( buf ) ) if res != 0 : raise errors . JLinkException ( res ) return list ( buf )
Returns a list of 32 integer values corresponding to the bitfields specifying the power consumption of the target .
230,897
def hardware_status ( self ) : stat = structs . JLinkHardwareStatus ( ) res = self . _dll . JLINKARM_GetHWStatus ( ctypes . byref ( stat ) ) if res == 1 : raise errors . JLinkException ( 'Error in reading hardware status.' ) return stat
Retrieves and returns the hardware status .
230,898
def hardware_version ( self ) : version = self . _dll . JLINKARM_GetHardwareVersion ( ) major = version / 10000 % 100 minor = version / 100 % 100 return '%d.%02d' % ( major , minor )
Returns the hardware version of the connected J - Link as a major . minor string .
230,899
def firmware_version ( self ) : buf = ( ctypes . c_char * self . MAX_BUF_SIZE ) ( ) self . _dll . JLINKARM_GetFirmwareString ( buf , self . MAX_BUF_SIZE ) return ctypes . string_at ( buf ) . decode ( )
Returns a firmware identification string of the connected J - Link .