signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def resolve_spec_identifier ( self , obj_name ) : """Find reference name based on spec identifier Spec identifiers are used in parameter and return type definitions , but should be a user - friendly version instead . Use docfx ` ` references ` ` lookup mapping for resolution . If the spec identifier referen...
ref = self . references . get ( obj_name ) if ref is None : return obj_name resolved = ref . get ( "fullName" , obj_name ) spec = ref . get ( "spec.csharp" , [ ] ) parts = [ ] for part in spec : if part . get ( "name" ) == "<" : parts . append ( "{" ) elif part . get ( "name" ) == ">" : part...
def create_csv ( filename , csv_data , mode = "w" ) : """Create a CSV file with the given data and store it in the file with the given name . : param filename : name of the file to store the data in : pram csv _ data : the data to be stored in the file : param mode : the mode in which we have to open the fi...
with open ( filename , mode ) as f : csv_data . replace ( "_" , r"\_" ) f . write ( csv_data )
def get_es_action_item ( data_item , action_settings , es_type , id_field = None ) : '''This method will return an item formated and ready to append to the action list'''
action_item = dict . copy ( action_settings ) if id_field is not None : id_val = first ( list ( get_dict_key ( data_item , id_field ) ) ) if id_val is not None : action_item [ '_id' ] = id_val elif data_item . get ( 'id' ) : if data_item [ 'id' ] . startswith ( "%s/" % action_settings [ '_index' ] )...
def decode ( self , value ) : """The decoder for this schema . Tries each decoder in order of the types specified for this schema ."""
# Use the default value unless the field accepts None types has_null_encoder = bool ( encode_decode_null in self . _decoders ) if value is None and self . _default is not None and not has_null_encoder : value = self . _default for decoder in self . _decoders : try : return decoder ( value ) except V...
def predict ( self , quadruplets ) : """Predicts the ordering between sample distances in input quadruplets . For each quadruplet , returns 1 if the quadruplet is in the right order ( first pair is more similar than second pair ) , and - 1 if not . Parameters quadruplets : array - like , shape = ( n _ quadr...
check_is_fitted ( self , 'transformer_' ) quadruplets = check_input ( quadruplets , type_of_inputs = 'tuples' , preprocessor = self . preprocessor_ , estimator = self , tuple_size = self . _tuple_size ) return np . sign ( self . decision_function ( quadruplets ) )
def run_func ( self , func_path , * func_args , ** kwargs ) : """Run a function in Matlab and return the result . Parameters func _ path : str Name of function to run or a path to an m - file . func _ args : object , optional Function args to send to the function . nargout : int , optional Desired num...
if not self . started : raise ValueError ( 'Session not started, use start()' ) nargout = kwargs . pop ( 'nargout' , 1 ) func_args += tuple ( item for pair in zip ( kwargs . keys ( ) , kwargs . values ( ) ) for item in pair ) dname = os . path . dirname ( func_path ) fname = os . path . basename ( func_path ) func_...
def delete_user_contact_list ( self , id , contact_list_id , ** data ) : """DELETE / users / : id / contact _ lists / : contact _ list _ id / Deletes the contact list . Returns ` ` { " deleted " : true } ` ` ."""
return self . delete ( "/users/{0}/contact_lists/{0}/" . format ( id , contact_list_id ) , data = data )
def verify ( self , obj ) : """Verify that the object conforms to this verifier ' s schema Args : obj ( object ) : A python object to verify Returns : bytes or byterray : The decoded byte buffer Raises : ValidationError : If there is a problem verifying the object , a ValidationError is thrown with at...
if self . encoding == 'none' and not isinstance ( obj , ( bytes , bytearray ) ) : raise ValidationError ( 'Byte object was not either bytes or a bytearray' , type = obj . __class__ . __name__ ) elif self . encoding == 'base64' : try : data = base64 . b64decode ( obj ) return data except Type...
def validate_uncle ( cls , block : BaseBlock , uncle : BaseBlock , uncle_parent : BaseBlock ) -> None : """Validate the given uncle in the context of the given block ."""
if uncle . block_number >= block . number : raise ValidationError ( "Uncle number ({0}) is higher than block number ({1})" . format ( uncle . block_number , block . number ) ) if uncle . block_number != uncle_parent . block_number + 1 : raise ValidationError ( "Uncle number ({0}) is not one above ancestor's num...
def change_sample ( self , old_samp_name , new_samp_name , new_site_name = None , new_er_data = None , new_pmag_data = None , replace_data = False ) : """Find actual data objects for sample and site . Then call Sample class change method to update sample name and data . ."""
sample = self . find_by_name ( old_samp_name , self . samples ) if not sample : print ( '-W- {} is not a currently existing sample, so it cannot be updated' . format ( old_samp_name ) ) return False if new_site_name : new_site = self . find_by_name ( new_site_name , self . sites ) if not new_site : ...
def vn ( x ) : """value or none , returns none if x is an empty list"""
if x == [ ] : return None if isinstance ( x , list ) : return '|' . join ( x ) if isinstance ( x , datetime ) : return x . isoformat ( ) return x
def read_command ( self ) : """Read a command from the user line by line . Returns a code object suitable for execution ."""
reader = self . reader line = yield from reader . readline ( ) if line == b'' : # lost connection raise ConnectionResetError ( ) try : # skip the newline to make CommandCompiler work as advertised codeobj = self . attempt_compile ( line . rstrip ( b'\n' ) ) except SyntaxError : yield from self . send_except...
def remove_sites ( self , indices ) : """Delete sites with at indices . Args : indices : Sequence of indices of sites to delete ."""
self . _sites = [ self . _sites [ i ] for i in range ( len ( self . _sites ) ) if i not in indices ]
def _get_variable_names ( arr ) : """Return the variable names of an array"""
if VARIABLELABEL in arr . dims : return arr . coords [ VARIABLELABEL ] . tolist ( ) else : return arr . name
def get_class_field ( cls , field_name ) : """Add management of dynamic fields : if a normal field cannot be retrieved , check if it can be a dynamic field and in this case , create a copy with the given name and associate it to the model ."""
try : field = super ( ModelWithDynamicFieldMixin , cls ) . get_class_field ( field_name ) except AttributeError : # the " has _ field " returned True but getattr raised . . . we have a DynamicField dynamic_field = cls . _get_dynamic_field_for ( field_name ) field = cls . _add_dynamic_field_to_model ( dynami...
def hsts_header ( self ) : """Returns the proper HSTS policy ."""
hsts_policy = 'max-age={0}' . format ( self . hsts_age ) if self . hsts_include_subdomains : hsts_policy += '; includeSubDomains' return hsts_policy
def random_sample ( self , num_samples , df = None , replace = False , weights = None , random_state = 100 , axis = 'row' ) : '''Return random sample of matrix .'''
if df is None : df = self . dat_to_df ( ) if axis == 'row' : axis = 0 if axis == 'col' : axis = 1 df = self . export_df ( ) df = df . sample ( n = num_samples , replace = replace , weights = weights , random_state = random_state , axis = axis ) self . load_df ( df )
def auto_key ( ) : """This method attempts to auto - generate a unique cryptographic key based on the hardware ID . It should * NOT * be used in production , or to replace a proper key , but it can help get will running in local and test environments more easily ."""
import uuid import time import random import hashlib node = uuid . getnode ( ) h = hashlib . md5 ( ) h . update ( str ( "%s" % node ) . encode ( 'utf-8' ) ) key1 = h . hexdigest ( ) time . sleep ( random . uniform ( 0 , 0.5 ) ) node = uuid . getnode ( ) h = hashlib . md5 ( ) h . update ( str ( "%s" % node ) . encode ( ...
def filter ( self ) : """Called when parallelize is False . This function will generate the file names in a directory tree by walking the tree either top - down or bottom - up . For each directory in the tree rooted at directory top ( including top itself ) , it yields a 3 - tuple ( dirpath , dirnames , filen...
self . _printer ( 'Standard Walk' ) count = Counter ( length = 3 ) for directory in self . directory : self . _printer ( 'Searching ' + directory ) for root , directories , files in os . walk ( directory , topdown = self . topdown ) : root = root [ len ( str ( directory ) ) + 1 : ] self . _print...
def archive_basename ( filename ) : '''returns the basename ( name without extension ) of a recognized archive file'''
for archive in archive_formats : if filename . endswith ( archive_formats [ archive ] [ 'suffix' ] ) : return filename . rstrip ( '.' + archive_formats [ archive ] [ 'suffix' ] ) return False
def _ParseStringOption ( cls , options , argument_name , default_value = None ) : """Parses a string command line argument . Args : options ( argparse . Namespace ) : parser options . argument _ name ( str ) : name of the command line argument . default _ value ( Optional [ str ] ) : default value of the co...
argument_value = getattr ( options , argument_name , None ) if argument_value is None : return default_value if isinstance ( argument_value , py2to3 . BYTES_TYPE ) : encoding = sys . stdin . encoding # Note that sys . stdin . encoding can be None . if not encoding : encoding = locale . getprefer...
def rsdl_rn ( self , AX , Y ) : """Compute primal residual normalisation term ."""
# The primal residual normalisation term is # max ( | | A x ^ ( k ) | | _ 2 , | | B y ^ ( k ) | | _ 2 ) and B = - ( I I I . . . ) ^ T . # The scaling by sqrt ( Nb ) of the l2 norm of Y accounts for the # block replication introduced by multiplication by B return max ( ( np . linalg . norm ( AX ) , np . sqrt ( self . Nb...
def get_protocol_from_name ( name ) : """Returns the protocol class for the protocol with the given name . : type name : str : param name : The name of the protocol . : rtype : Protocol : return : The protocol class ."""
cls = protocol_map . get ( name ) if not cls : raise ValueError ( 'Unsupported protocol "%s".' % name ) return cls
def checks ( similarities , verbose = False ) : """Check that a matrix is a proper similarity matrix and bring appropriate changes if applicable . Parameters similarities : array of shape ( n _ samples , n _ samples ) A matrix of pairwise similarities between ( sub ) - samples of the data - set . verbose ...
if similarities . size == 0 : raise ValueError ( "\nERROR: Cluster_Ensembles: checks: the similarities " "matrix provided as input happens to be empty.\n" ) elif np . where ( np . isnan ( similarities ) ) [ 0 ] . size != 0 : raise ValueError ( "\nERROR: Cluster_Ensembles: checks: input similarities " "matrix co...
def pool_revert ( self , pool_id , version_id ) : """Function to revert a specific pool ( Requires login ) ( UNTESTED ) . Parameters : pool _ id ( int ) : Where pool _ id is the pool id . version _ id ( int ) :"""
return self . _get ( 'pools/{0}/revert.json' . format ( pool_id ) , { 'version_id' : version_id } , method = 'PUT' , auth = True )
def load_model_from_path ( model_path , meta = False , ** overrides ) : """Load a model from a data directory path . Creates Language class with pipeline from meta . json and then calls from _ disk ( ) with path ."""
from . tokenizer_loader import TokenizerLoader if not meta : meta = get_model_meta ( model_path ) tokenizer_loader = TokenizerLoader ( meta = meta , ** overrides ) tokenizers = meta . get ( 'tokenizers' , [ ] ) disable = overrides . get ( 'disable' , [ ] ) if tokenizers is True : tokenizers = TokenizerLoader . ...
def set_title ( self , title : str , url : str = None ) -> None : """Sets the title of the embed . Parameters title : str Title of the embed . url : str or None , optional URL hyperlink of the title ."""
self . title = title self . url = url
def install_exception_handler ( handler ) : """Installs an exception handler . Args : handler : ExceptionHandler , the exception handler to install . Raises : TypeError : Raised when the handler was not of the correct type . All installed exception handlers will be called if main ( ) exits via an abnorm...
if not isinstance ( handler , ExceptionHandler ) : raise TypeError ( 'handler of type %s does not inherit from ExceptionHandler' % type ( handler ) ) EXCEPTION_HANDLERS . append ( handler )
def add_entity ( self , domain , ** kwargs ) : '''Add a new Entity to tracking .'''
# Set the entity ' s mapping func if one was specified map_func = kwargs . get ( 'map_func' , None ) if map_func is not None and not callable ( kwargs [ 'map_func' ] ) : if self . entity_mapper is None : raise ValueError ( "Mapping function '%s' specified for Entity " "'%s', but no entity mapper was passed ...
def jcrop_css ( css_url = None ) : """Load jcrop css file . : param css _ url : The custom CSS URL ."""
if css_url is None : if current_app . config [ 'AVATARS_SERVE_LOCAL' ] : css_url = url_for ( 'avatars.static' , filename = 'jcrop/css/jquery.Jcrop.min.css' ) else : css_url = 'https://cdn.jsdelivr.net/npm/jcrop-0.9.12@0.9.12/css/jquery.Jcrop.min.css' return Markup ( '<link rel="stylesheet" href=...
def update ( self , force = False ) : """Fetch new posts from the server . Arguments : force ( bool ) : Force a thread update , even if thread has 404 ' d . Returns : int : How many new posts have been fetched ."""
# The thread has already 404 ' ed , this function shouldn ' t do anything anymore . if self . is_404 and not force : return 0 if self . _last_modified : headers = { 'If-Modified-Since' : self . _last_modified } else : headers = None # random connection errors , just return 0 and try again later try : re...
def reset_index ( self , ** kwargs ) : """Removes all levels from index and sets a default level _ 0 index . Returns : A new QueryCompiler with updated data and reset index ."""
drop = kwargs . get ( "drop" , False ) new_index = pandas . RangeIndex ( len ( self . index ) ) if not drop : if isinstance ( self . index , pandas . MultiIndex ) : # TODO ( devin - petersohn ) ensure partitioning is properly aligned new_column_names = pandas . Index ( self . index . names ) new_col...
def get_page_numbers ( current_page , num_pages ) : """Default callable for page listing . Produce a Digg - style pagination ."""
if current_page <= 2 : start_page = 1 else : start_page = current_page - 2 if num_pages <= 4 : end_page = num_pages else : end_page = start_page + 4 if end_page > num_pages : end_page = num_pages pages = [ ] if current_page != 1 : pages . append ( 'first' ) pages . append ( 'previous...
def do_operation ( database , keys , table , operation , latencies_ms ) : """Does a single operation and records latency ."""
key = random . choice ( keys ) start = timeit . default_timer ( ) if operation == 'read' : read ( database , table , key ) elif operation == 'update' : update ( database , table , key ) else : raise ValueError ( 'Unknown operation: %s' % operation ) end = timeit . default_timer ( ) latencies_ms [ operation ...
def build_full_toctree ( builder , docname , prune , collapse ) : """Return a single toctree starting from docname containing all sub - document doctrees ."""
env = builder . env doctree = env . get_doctree ( env . config . master_doc ) toctrees = [ ] for toctreenode in doctree . traverse ( addnodes . toctree ) : toctree = env . resolve_toctree ( docname , builder , toctreenode , collapse = collapse , prune = prune , ) toctrees . append ( toctree ) if not toctrees : ...
def json_success_response ( data , response ) : """Formats the response of a successful token request as JSON . Also adds default headers and status code ."""
response . body = json . dumps ( data ) response . status_code = 200 response . add_header ( "Content-Type" , "application/json" ) response . add_header ( "Cache-Control" , "no-store" ) response . add_header ( "Pragma" , "no-cache" )
def get_all_reserved_instances ( self , reserved_instances_id = None , filters = None ) : """Describes Reserved Instance offerings that are available for purchase . : type reserved _ instance _ ids : list : param reserved _ instance _ ids : A list of the reserved instance ids that will be returned . If not pr...
params = { } if reserved_instances_id : self . build_list_params ( params , reserved_instances_id , 'ReservedInstancesId' ) if filters : self . build_filter_params ( params , filters ) return self . get_list ( 'DescribeReservedInstances' , params , [ ( 'item' , ReservedInstance ) ] , verb = 'POST' )
def _update_pwm ( self ) : """Update the pwm values of the driver regarding the current state ."""
if self . _is_on : values = self . _get_pwm_values ( ) else : values = [ 0 ] * len ( self . _driver . pins ) self . _driver . set_pwm ( values )
def get_network ( network_id , summary = False , include_data = 'N' , scenario_ids = None , template_id = None , ** kwargs ) : """Return a whole network as a dictionary . network _ id : ID of the network to retrieve include _ data : ' Y ' or ' N ' . Indicate whether scenario data is to be returned . This has ...
log . debug ( "getting network %s" % network_id ) user_id = kwargs . get ( 'user_id' ) network_id = int ( network_id ) try : log . debug ( "Querying Network %s" , network_id ) net_i = db . DBSession . query ( Network ) . filter ( Network . id == network_id ) . options ( noload ( 'scenarios' ) ) . options ( nolo...
def response_body_to_dict ( http_requests_response , content_type , xml_root_element_name = None , is_list = False ) : """Convert a XML or JSON response in a Python dict : param http _ requests _ response : ' Requests ( lib ) ' response : param content _ type : Expected content - type header value ( Accept head...
logger . info ( "Converting response body from API (XML or JSON) to Python dict" ) if HEADER_REPRESENTATION_JSON == content_type : try : return http_requests_response . json ( ) except Exception , e : logger . error ( "Error parsing the response to JSON. Exception:" + str ( e ) ) raise e...
def scaleBy ( self , value , origin = None , width = False , height = False ) : """* * width * * indicates if the glyph ' s width should be scaled . * * height * * indicates if the glyph ' s height should be scaled . The origin must not be specified when scaling the width or height ."""
value = normalizers . normalizeTransformationScale ( value ) if origin is None : origin = ( 0 , 0 ) origin = normalizers . normalizeCoordinateTuple ( origin ) if origin != ( 0 , 0 ) and ( width or height ) : raise FontPartsError ( ( "The origin must not be set when " "scaling the width or height." ) ) super ( B...
def user ( self , email : str ) -> models . User : """Fetch a user from the database ."""
return self . User . query . filter_by ( email = email ) . first ( )
def alert ( text = '' , title = '' , button = OK_TEXT , root = None , timeout = None ) : """Displays a simple message box with text and a single OK button . Returns the text of the button clicked on ."""
assert TKINTER_IMPORT_SUCCEEDED , 'Tkinter is required for pymsgbox' return _buttonbox ( msg = text , title = title , choices = [ str ( button ) ] , root = root , timeout = timeout )
def del_group ( self ) : """Delete current group ."""
idx = self . tabs . currentIndex ( ) self . tabs . removeTab ( idx ) self . apply ( )
def _start_monitoring ( self ) : """Internal method that monitors the directory for changes"""
# Grab all the timestamp info before = self . _file_timestamp_info ( self . path ) while True : gevent . sleep ( 1 ) after = self . _file_timestamp_info ( self . path ) added = [ fname for fname in after . keys ( ) if fname not in before . keys ( ) ] removed = [ fname for fname in before . keys ( ) if f...
def extract ( fileobj , keywords , comment_tags , options ) : """Extracts translation messages from underscore template files . This method does also extract django templates . If a template does not contain any django translation tags we always fallback to underscore extraction . This is a plugin to Babel , ...
encoding = options . get ( 'encoding' , 'utf-8' ) original_position = fileobj . tell ( ) text = fileobj . read ( ) . decode ( encoding ) if django . VERSION [ : 2 ] >= ( 1 , 9 ) : tokens = Lexer ( text ) . tokenize ( ) else : tokens = Lexer ( text , None ) . tokenize ( ) vars = [ token . token_type != TOKEN_TEX...
def _ssh_forward_accept ( ssh_session , timeout_ms ) : """Waiting for an incoming connection from a reverse forwarded port . Note that this results in a kernel block until a connection is received ."""
ssh_channel = c_ssh_forward_accept ( c_void_p ( ssh_session ) , c_int ( timeout_ms ) ) if ssh_channel is None : raise SshTimeoutException ( ) return ssh_channel
def uninstall ( ) : """Uninstall data and resource locations"""
_check_root ( ) response = _ask ( "This will delete all data of your HFOS installations! Type" "YES to continue:" , default = "N" , show_hint = False ) if response == 'YES' : shutil . rmtree ( '/var/lib/hfos' ) shutil . rmtree ( '/var/cache/hfos' )
def _normalize ( val ) : '''Fix Salt ' s yaml - ification of on / off , and otherwise normalize the on / off values to be used in writing the options file'''
if isinstance ( val , bool ) : return 'on' if val else 'off' return six . text_type ( val ) . lower ( )
def what_task ( self , token_id , presented_pronunciation , index , phonemes , phonemes_probability , warn = True , default = True ) : """Provide the prediction of the what task . This function is used to predict the probability of a given phoneme being reported at a given index for a given token . : param to...
if phonemes_probability is not None and not 0. < phonemes_probability < 1. and warn : logging . warning ( 'Setting a probability of [{}] to phonemes [{}] for token [{}].\n ' 'Using probabilities of 0.0 or 1.0 ' 'may lead to likelihoods of -Infinity' . format ( phonemes_probability , phonemes , token_id ) ) default_...
def amplify_gmfs ( imts , vs30s , gmfs ) : """Amplify the ground shaking depending on the vs30s"""
n = len ( vs30s ) out = [ amplify_ground_shaking ( im . period , vs30s [ i ] , gmfs [ m * n + i ] ) for m , im in enumerate ( imts ) for i in range ( n ) ] return numpy . array ( out )
def call_member ( obj , f , * args , ** kwargs ) : """Calls the specified method , property or attribute of the given object Parameters obj : object The object that will be used f : str or function Name of or reference to method , property or attribute failfast : bool If True , will raise an exception...
# get function name if not isinstance ( f , str ) : fname = f . __func__ . __name__ else : fname = f # get the method ref method = getattr ( obj , fname ) # handle cases if inspect . ismethod ( method ) : return method ( * args , ** kwargs ) # attribute or property return method
def unzip ( self , remotepath , subpath = '/' , start = 0 , limit = 1000 ) : '''Usage : unzip < remotepath > [ < subpath > [ < start > [ < limit > ] ] ]'''
rpath = get_pcs_path ( remotepath ) return self . __panapi_unzip_file ( rpath , subpath , start , limit ) ;
def list ( self , pattern = '*' ) : """Returns a list of resource descriptors that match the filters . Args : pattern : An optional pattern to further filter the descriptors . This can include Unix shell - style wildcards . E . g . ` ` " aws * " ` ` , ` ` " * cluster * " ` ` . Returns : A list of Resource...
if self . _descriptors is None : self . _descriptors = self . _client . list_resource_descriptors ( filter_string = self . _filter_string ) return [ resource for resource in self . _descriptors if fnmatch . fnmatch ( resource . type , pattern ) ]
def get_cluster_assignment ( self ) : """Fetch the cluster layout in form of assignment from zookeeper"""
plan = self . get_cluster_plan ( ) assignment = { } for elem in plan [ 'partitions' ] : assignment [ ( elem [ 'topic' ] , elem [ 'partition' ] ) ] = elem [ 'replicas' ] return assignment
def copy ( self , * args , ** kwargs ) : '''Returns a copy of the current data object : param flag : if an argument is provided , this returns an updated copy of current object ( ie . equivalent to obj . copy ( ) ; obj . update ( flag ) ) , optimising the memory ( : keyword True deep : deep copies the object ( ...
deep = kwargs . get ( 'deep' , True ) if len ( args ) > 0 : return self . updated_copy ( * args ) else : return copy . deepcopy ( self ) if deep else copy . copy ( self )
def _euler_to_q ( self , euler ) : """Create q array from euler angles : param euler : array [ roll , pitch , yaw ] in rad : returns : array q which represents a quaternion [ w , x , y , z ]"""
assert ( len ( euler ) == 3 ) phi = euler [ 0 ] theta = euler [ 1 ] psi = euler [ 2 ] c_phi_2 = np . cos ( phi / 2 ) s_phi_2 = np . sin ( phi / 2 ) c_theta_2 = np . cos ( theta / 2 ) s_theta_2 = np . sin ( theta / 2 ) c_psi_2 = np . cos ( psi / 2 ) s_psi_2 = np . sin ( psi / 2 ) q = np . zeros ( 4 ) q [ 0 ] = ( c_phi_2...
def __script ( self , mode , filestem ) : """Makes the script file to be run by yap ."""
scriptPath = '%s/%s' % ( self . tmpdir , Aleph . SCRIPT ) script = open ( scriptPath , 'w' ) # Permit the owner to execute and read this script os . chmod ( scriptPath , S_IREAD | S_IEXEC ) cat = lambda x : script . write ( x + '\n' ) cat ( ":- initialization(run_aleph)." ) cat ( "run_aleph :- " ) cat ( "consult(aleph)...
def _validate_id_types ( self ) : '''Check that the ID types are integers for Rosetta , SEQRES , and UniParc sequences and 6 - character PDB IDs for the ATOM sequences .'''
for sequences in [ self . uniparc_sequences , self . fasta_sequences , self . seqres_sequences , self . rosetta_sequences ] : for chain_id , sequence in sequences . iteritems ( ) : sequence_id_types = set ( map ( type , sequence . ids ( ) ) ) if sequence_id_types : assert ( len ( sequenc...
def elcm_request ( irmc_info , method , path , ** kwargs ) : """send an eLCM request to the server : param irmc _ info : dict of iRMC params to access the server node ' irmc _ address ' : host , ' irmc _ username ' : user _ id , ' irmc _ password ' : password , ' irmc _ port ' : 80 or 443 , default is 443...
host = irmc_info [ 'irmc_address' ] port = irmc_info . get ( 'irmc_port' , 443 ) auth_method = irmc_info . get ( 'irmc_auth_method' , 'basic' ) userid = irmc_info [ 'irmc_username' ] password = irmc_info [ 'irmc_password' ] client_timeout = irmc_info . get ( 'irmc_client_timeout' , 60 ) # Request headers , params , and...
def add_patchs_to_build_without_pkg_config ( self , lib_dir , include_dir ) : """Add patches to remove pkg - config command and rpm . pc part . Replace with given library _ path : lib _ dir and include _ path : include _ dir without rpm . pc file ."""
additional_patches = [ { 'src' : r"pkgconfig\('--libs-only-L'\)" , 'dest' : "['{0}']" . format ( lib_dir ) , } , # Considering - libs - only - l and - libs - only - L # https : / / github . com / rpm - software - management / rpm / pull / 327 { 'src' : r"pkgconfig\('--libs(-only-l)?'\)" , 'dest' : "['rpm', 'rpmio']" , ...
def _fixPermissions ( tool , workDir ) : """Deprecated . Fix permission of a mounted Docker directory by reusing the tool to change ownership . Docker natively runs as a root inside the container , and files written to the mounted directory are implicitly owned by root . : param list baseDockerCall : Docker...
if os . geteuid ( ) == 0 : # we ' re running as root so this chown is redundant return baseDockerCall = [ 'docker' , 'run' , '--log-driver=none' , '-v' , os . path . abspath ( workDir ) + ':/data' , '--rm' , '--entrypoint=chown' ] stat = os . stat ( workDir ) command = baseDockerCall + [ tool ] + [ '-R' , '{}:{}' ....
def nvmlEventSetCreate ( ) : r"""* Create an empty set of events . * Event set should be freed by \ ref nvmlEventSetFree * For Fermi & tm ; or newer fully supported devices . * @ param set Reference in which to return the event handle * @ return * - \ ref NVML _ SUCCESS if the event has been set * - \ r...
fn = _nvmlGetFunctionPointer ( "nvmlEventSetCreate" ) eventSet = c_nvmlEventSet_t ( ) ret = fn ( byref ( eventSet ) ) _nvmlCheckReturn ( ret ) return eventSet
def rename_attribute ( self , attribute : str , new_name : str ) -> None : """Renames an attribute . Use only if is _ mapping ( ) returns true . If the attribute does not exist , this will do nothing . Args : attribute : The ( old ) name of the attribute to rename . new _ name : The new name to rename it ...
for key_node , _ in self . yaml_node . value : if key_node . value == attribute : key_node . value = new_name break
def mtx_refl ( nv , reps = 1 ) : """Generate block - diagonal reflection matrix about nv . reps must be > = 1 and indicates the number of times the reflection matrix should be repeated along the block diagonal . Typically this will be the number of atoms in a geometry . . . todo : : Complete mtx _ refl docs...
# Imports import numpy as np from scipy import linalg as spla from . . const import PRM # Ensure | nv | is large enough for confident directionality if spla . norm ( nv ) < PRM . ZERO_VEC_TOL : raise ValueError ( "Norm of 'nv' is too small." ) # # end if # Ensure nv is a normalized np . float64 3 - vector nv = make...
def cube ( f ) : """Read a full cube from a file Takes an open segy file ( created with segyio . open ) or a file name . If the file is a prestack file , the cube returned has the dimensions ` ` ( fast , slow , offset , sample ) ` ` . If it is post - stack ( only the one offset ) , the dimensions are normal...
if not isinstance ( f , segyio . SegyFile ) : with segyio . open ( f ) as fl : return cube ( fl ) ilsort = f . sorting == segyio . TraceSortingFormat . INLINE_SORTING fast = f . ilines if ilsort else f . xlines slow = f . xlines if ilsort else f . ilines fast , slow , offs = len ( fast ) , len ( slow ) , le...
def get_method_descriptor ( self , class_name , method_name , descriptor ) : """Return the specific method : param class _ name : the class name of the method : type class _ name : string : param method _ name : the name of the method : type method _ name : string : param descriptor : the descriptor of th...
key = class_name + method_name + descriptor if self . __cache_methods is None : self . __cache_methods = { } for i in self . get_classes ( ) : for j in i . get_methods ( ) : self . __cache_methods [ j . get_class_name ( ) + j . get_name ( ) + j . get_descriptor ( ) ] = j return self . __cach...
def unstar ( self ) : """Un - star this gist . : returns : bool - - True if successful , False otherwise"""
url = self . _build_url ( 'star' , base_url = self . _api ) return self . _boolean ( self . _delete ( url ) , 204 , 404 )
def sometimesish ( fn ) : """Has a 50/50 chance of calling a function"""
def wrapped ( * args , ** kwargs ) : if random . randint ( 1 , 2 ) == 1 : return fn ( * args , ** kwargs ) return wrapped
def load_nouns ( self , file ) : """Load dict from file for random words . : param str file : filename"""
with open ( os . path . join ( main_dir , file + '.dat' ) , 'r' ) as f : self . nouns = json . load ( f )
def _kmp_search_first ( self , pInput_sequence , pPattern ) : """use KMP algorithm to search the first occurrence in the input _ sequence of the pattern . both arguments are integer arrays . return the position of the occurence if found ; otherwise , - 1."""
input_sequence , pattern = pInput_sequence , [ len ( bin ( e ) ) for e in pPattern ] n , m = len ( input_sequence ) , len ( pattern ) d = p = 0 next = self . _kmp_construct_next ( pattern ) while d < n and p < m : p = next [ len ( bin ( input_sequence [ d ] ) ) ] [ p ] d += 1 if p == m : return d - p else :...
def _normalize ( self , address ) : """Normalize prefixes , suffixes and other to make matching original to returned easier ."""
normalized_address = [ ] if self . logger : self . logger . debug ( "Normalizing Address: {0}" . format ( address ) ) for token in address . split ( ) : if token . upper ( ) in self . parser . suffixes . keys ( ) : normalized_address . append ( self . parser . suffixes [ token . upper ( ) ] . lower ( ) ...
def create_rot2d ( angle ) : """Create 2D rotation matrix"""
ca = math . cos ( angle ) sa = math . sin ( angle ) return np . array ( [ [ ca , - sa ] , [ sa , ca ] ] )
def _get_pgtiou ( pgt ) : """Returns a PgtIOU object given a pgt . The PgtIOU ( tgt ) is set by the CAS server in a different request that has completed before this call , however , it may not be found in the database by this calling thread , hence the attempt to get the ticket is retried for up to 5 second...
pgtIou = None retries_left = 5 if not settings . CAS_PGT_FETCH_WAIT : retries_left = 1 while not pgtIou and retries_left : try : return PgtIOU . objects . get ( tgt = pgt ) except PgtIOU . DoesNotExist : if settings . CAS_PGT_FETCH_WAIT : time . sleep ( 1 ) retries_left -...
def watermark_text ( image , text , corner = 2 ) : '''Adds a text watermark to an instance of a PIL Image . The text will be sized so that the height of the text is roughly 1/20th the height of the base image . The text will be white with a thin black outline . Args : image : An instance of a PIL Image . ...
# Load Font FONT_PATH = '' if resource_exists ( __name__ , 'resources/fonts/SourceSansPro-Regular.ttf' ) : FONT_PATH = resource_filename ( __name__ , 'resources/fonts/SourceSansPro-Regular.ttf' ) padding = 5 was_P = image . mode == 'P' was_L = image . mode == 'L' # Fix PIL palette issue by converting palette images...
def _resolve_number_of_copies ( self , items ) : """For the given objects generate as many copies as the desired number of stickers . : param items : list of objects whose stickers are going to be previewed . : type items : list : returns : list containing n copies of each object in the items list : rtype...
copied_items = [ ] for obj in items : for copy in range ( self . get_copies_count ( ) ) : copied_items . append ( obj ) return copied_items
def find_sinks ( obj ) : """Returns a dictionary of sink methods found on this object , keyed on method name . Sink methods are identified by ( self , context ) arguments on this object . For example : def f ( self , context ) : is a sink method , but def f ( self , ctx ) : is not ."""
SINK_ARGSPEC = [ 'self' , 'context' ] return { n : m for n , m in inspect . getmembers ( obj , inspect . ismethod ) if inspect . getargspec ( m ) [ 0 ] == SINK_ARGSPEC }
def from_json ( self , json ) : """Create resource out of JSON data . : param json : JSON dict . : return : Resource with a type defined by the given JSON data ."""
res_type = json [ 'sys' ] [ 'type' ] if ResourceType . Array . value == res_type : return self . create_array ( json ) elif ResourceType . Entry . value == res_type : return self . create_entry ( json ) elif ResourceType . Asset . value == res_type : return ResourceFactory . create_asset ( json ) elif Resou...
def valueFromString ( self , value , context = None ) : """Re - implements the orb . Column . valueFromString method to lookup a reference object based on the given value . : param value : < str > : param context : < orb . Context > | | None : return : < orb . Model > | | None"""
model = self . referenceModel ( ) return model ( value , context = context )
def density ( self ) : """The percent of non - ` ` fill _ value ` ` points , as decimal . Examples > > > s = SparseArray ( [ 0 , 0 , 1 , 1 , 1 ] , fill _ value = 0) > > > s . density 0.6"""
r = float ( self . sp_index . npoints ) / float ( self . sp_index . length ) return r
def aggregate ( self , aggregates = None , drilldowns = None , cuts = None , order = None , page = None , page_size = None , page_max = None ) : """Main aggregation function . This is used to compute a given set of aggregates , grouped by a given set of drilldown dimensions ( i . e . dividers ) . The query can ...
def prep ( cuts , drilldowns = False , aggregates = False , columns = None ) : q = select ( columns ) bindings = [ ] cuts , q , bindings = Cuts ( self ) . apply ( q , bindings , cuts ) attributes = None if drilldowns is not False : attributes , q , bindings = Drilldowns ( self ) . apply ( q ...
def resolve_symbol ( self , symbol , bCaseSensitive = False ) : """Resolves a debugging symbol ' s address . @ type symbol : str @ param symbol : Name of the symbol to resolve . @ type bCaseSensitive : bool @ param bCaseSensitive : C { True } for case sensitive matches , C { False } for case insensitive ....
if bCaseSensitive : for ( SymbolName , SymbolAddress , SymbolSize ) in self . iter_symbols ( ) : if symbol == SymbolName : return SymbolAddress for ( SymbolName , SymbolAddress , SymbolSize ) in self . iter_symbols ( ) : try : SymbolName = win32 . UnDecorateSymbolName ( S...
def of ( cls , value ) : """Given either a dictionary or a ` ConfigSource ` object , return a ` ConfigSource ` object . This lets a function accept either type of object as an argument ."""
if isinstance ( value , ConfigSource ) : return value elif isinstance ( value , dict ) : return ConfigSource ( value ) else : raise TypeError ( u'source value must be a dict' )
def dedup ( args ) : """% prog dedup scaffolds . fasta Remove redundant contigs with CD - HIT . This is run prior to assembly . sspace . embed ( ) ."""
from jcvi . formats . fasta import gaps from jcvi . apps . cdhit import deduplicate , ids p = OptionParser ( dedup . __doc__ ) p . set_align ( pctid = GoodPct ) p . set_mingap ( default = 10 ) opts , args = p . parse_args ( args ) if len ( args ) != 1 : sys . exit ( not p . print_help ( ) ) scaffolds , = args minga...
def convolve_sep3 ( data , hx , hy , hz , res_g = None , sub_blocks = ( 1 , 1 , 1 ) , tmp_g = None ) : """convolves 3d data with kernel h = outer ( hx , hy , hz ) boundary conditions are clamping to edge . data , hx , hy . . . . are either np array or a gpu buffer ( OCLArray )"""
if isinstance ( data , np . ndarray ) : data = np . ascontiguousarray ( data ) if sub_blocks == ( 1 , 1 , 1 ) or sub_blocks is None : return _convolve_sep3_numpy ( data , hx , hy , hz ) else : # cut the image into tile and operate on every of them N_sub = [ int ( np . ceil ( 1. * n / s ) ) f...
def get ( dataset , ** kwargs ) : """Return dataframe of requested dataset from Quandl . : param dataset : str or list , depending on single dataset usage or multiset usage Dataset codes are available on the Quandl website : param str api _ key : Downloads are limited to 50 unless api _ key is specified : p...
_convert_params_to_v3 ( kwargs ) data_format = kwargs . pop ( 'returns' , 'pandas' ) ApiKeyUtil . init_api_key_from_args ( kwargs ) # Check whether dataset is given as a string # ( for a single dataset ) or an array ( for a multiset call ) # Unicode String if isinstance ( dataset , string_types ) : dataset_args = _...
def _get_variable_from_filepath ( self ) : """Determine the file variable from the filepath . Returns str Best guess of variable name from the filepath"""
try : return self . regexp_capture_variable . search ( self . filepath ) . group ( 1 ) except AttributeError : self . _raise_cannot_determine_variable_from_filepath_error ( )
def connect_iam ( aws_access_key_id = None , aws_secret_access_key = None , ** kwargs ) : """: type aws _ access _ key _ id : string : param aws _ access _ key _ id : Your AWS Access Key ID : type aws _ secret _ access _ key : string : param aws _ secret _ access _ key : Your AWS Secret Access Key : rtype :...
from boto . iam import IAMConnection return IAMConnection ( aws_access_key_id , aws_secret_access_key , ** kwargs )
def decode ( self , data ) : """Parses the file , creating a CWRFile from it . It requires a dictionary with two values : - filename , containing the filename - contents , containing the file contents : param data : dictionary with the data to parse : return : a CWRFile instance"""
file_name = self . _filename_decoder . decode ( data [ 'filename' ] ) file_data = data [ 'contents' ] i = 0 max_size = len ( file_data ) while file_data [ i : i + 1 ] != 'H' and i < max_size : i += 1 if i > 0 : data [ 'contents' ] = file_data [ i : ] transmission = self . _file_decoder . decode ( data [ 'conten...
def add_nodes_from ( self , nodes , ** attr ) : """Add multiple nodes . Parameters nodes : iterable container A container of nodes ( list , dict , set , etc . ) . OR A container of ( node , attribute dict ) tuples . Node attributes are updated using the attribute dict . attr : keyword arguments , opti...
additional_attribs = attr # will be added to each node for n in nodes : try : # check , if n is a node _ id or a ( node _ id , attrib dict ) tuple newnode = n not in self . succ # is node in the graph , yet ? except TypeError : # n is a ( node _ id , attribute dict ) tuple node_id , ndic...
def patch_for ( self , path ) : """Returns the ` ` Patch ` ` for the target path , creating it if necessary . : param str path : The absolute module path to the target . : return : The mapped ` ` Patch ` ` . : rtype : Patch"""
if path not in self . _patches : self . _patches [ path ] = Patch ( path ) return self . _patches [ path ]
def _ExpandUsersVariablePathSegments ( cls , path_segments , path_separator , user_accounts ) : """Expands path segments with a users variable , e . g . % % users . homedir % % . Args : path _ segments ( list [ str ] ) : path segments . path _ separator ( str ) : path segment separator . user _ accounts ( l...
if not path_segments : return [ ] path_segments_lower = [ path_segment . lower ( ) for path_segment in path_segments ] if path_segments_lower [ 0 ] in ( '%%users.homedir%%' , '%%users.userprofile%%' ) : return cls . _ExpandUsersHomeDirectoryPathSegments ( path_segments , path_separator , user_accounts ) path_ex...
def wind_shear ( shear : str , unit_alt : str = 'ft' , unit_wind : str = 'kt' ) -> str : """Format wind shear string into a spoken word string"""
unit_alt = SPOKEN_UNITS . get ( unit_alt , unit_alt ) unit_wind = SPOKEN_UNITS . get ( unit_wind , unit_wind ) return translate . wind_shear ( shear , unit_alt , unit_wind , spoken = True ) or 'Wind shear unknown'
def download_results ( self , savedir = None , raw = True , calib = False , index = None ) : """Download the previously found and stored Opus obsids . Parameters savedir : str or pathlib . Path , optional If the database root folder as defined by the config . ini should not be used , provide a different sav...
obsids = self . obsids if index is None else [ self . obsids [ index ] ] for obsid in obsids : pm = io . PathManager ( obsid . img_id , savedir = savedir ) pm . basepath . mkdir ( exist_ok = True ) to_download = [ ] if raw is True : to_download . extend ( obsid . raw_urls ) if calib is True ...
def check_for_invalid_columns ( problems : List , table : str , df : DataFrame ) -> List : """Check for invalid columns in the given GTFS DataFrame . Parameters problems : list A four - tuple containing 1 . A problem type ( string ) equal to ` ` ' error ' ` ` or ` ` ' warning ' ` ` ; ` ` ' error ' ` ` mea...
r = cs . GTFS_REF valid_columns = r . loc [ r [ "table" ] == table , "column" ] . values for col in df . columns : if col not in valid_columns : problems . append ( [ "warning" , f"Unrecognized column {col}" , table , [ ] ] ) return problems
def ip_to_url ( ip_addr ) : """Resolve a hostname based off an IP address . This is very limited and will probably not return any results if it is a shared IP address or an address with improperly setup DNS records . . . code : : python reusables . ip _ to _ url ( ' 93.184.216.34 ' ) # example . com # N...
try : return socket . gethostbyaddr ( ip_addr ) [ 0 ] except ( socket . gaierror , socket . herror ) : logger . exception ( "Could not resolve hostname" )
def _handleSelectAllAxes ( self , evt ) : """Called when the ' select all axes ' menu item is selected ."""
if len ( self . _axisId ) == 0 : return for i in range ( len ( self . _axisId ) ) : self . _menu . Check ( self . _axisId [ i ] , True ) self . _toolbar . set_active ( self . getActiveAxes ( ) ) evt . Skip ( )
def reset ( name ) : '''Force power down and restart an existing VM'''
ret = { } client = salt . client . get_local_client ( __opts__ [ 'conf_file' ] ) data = vm_info ( name , quiet = True ) if not data : __jid_event__ . fire_event ( { 'message' : 'Failed to find VM {0} to reset' . format ( name ) } , 'progress' ) return 'fail' host = next ( six . iterkeys ( data ) ) try : cmd...
def seq_sha512 ( seq , normalize = True ) : """returns unicode sequence sha512 hexdigest for sequence ` seq ` . > > > seq _ sha512 ( ' ' ) ' cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e ' > > > seq _ sha512 ( ' ACGT ' ) '68a...
seq = normalize_sequence ( seq ) if normalize else seq bseq = seq . encode ( "ascii" ) return hashlib . sha512 ( bseq ) . hexdigest ( )
async def enable ( ) : """Get the data from a * hole instance ."""
async with aiohttp . ClientSession ( ) as session : data = Hole ( '192.168.0.215' , loop , session , api_token = API_TOKEN ) await data . enable ( )