signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def from_json_file ( file : TextIO , check_version = True ) -> BELGraph : """Build a graph from the Node - Link JSON contained in the given file ."""
graph_json_dict = json . load ( file ) return from_json ( graph_json_dict , check_version = check_version )
def peer ( name ) : '''Add another node into the peer list . name The remote host to probe . CLI Example : . . code - block : : bash salt ' one . gluster . * ' glusterfs . peer two GLUSTER direct CLI example ( to show what salt is sending to gluster ) : $ gluster peer probe ftp2 GLUSTER CLI 3.4.4 re...
if salt . utils . cloud . check_name ( name , 'a-zA-Z0-9._-' ) : raise SaltInvocationError ( 'Invalid characters in peer name "{0}"' . format ( name ) ) cmd = 'peer probe {0}' . format ( name ) return _gluster ( cmd )
def call_webhook ( event , webhook , payload ) : """Build request from event , webhook , payoad and parse response ."""
started_at = time ( ) request = _build_request_for_calling_webhook ( event , webhook , payload ) logger . info ( 'REQUEST %(uuid)s %(method)s %(url)s %(payload)s' % dict ( uuid = str ( event [ 'uuid' ] ) , url = request [ 'url' ] , method = request [ 'method' ] , payload = payload , ) ) try : content = dispatch_web...
def decode_chain_list ( in_bytes ) : """Convert a list of bytes to a list of strings . Each string is of length mmtf . CHAIN _ LEN : param in _ bytes : the input bytes : return the decoded list of strings"""
tot_strings = len ( in_bytes ) // mmtf . utils . constants . CHAIN_LEN out_strings = [ ] for i in range ( tot_strings ) : out_s = in_bytes [ i * mmtf . utils . constants . CHAIN_LEN : i * mmtf . utils . constants . CHAIN_LEN + mmtf . utils . constants . CHAIN_LEN ] out_strings . append ( out_s . decode ( "ascii...
def encode ( self , value ) : """Encodes the given value according to this FieldDefinition ."""
if type ( value ) == str and self . enum and value in self . enum : value = self . enum [ value ] if type ( value ) == int : if self . shift > 0 : value <<= self . shift if self . mask is not None : value &= self . mask return self . type . encode ( value ) if self . type else bytearray ( )
def _rhoTilde ( self , r , N , L ) : """NAME : _ rhoTilde PURPOSE : Evaluate rho _ tilde as defined in equation 3.9 and 2.24 for 0 < = n < N and 0 < = l < L INPUT : r - Evaluate at radius r N - size of the N dimension L - size of the L dimension OUTPUT : rho tilde HISTORY : 2016-05-17 - Writte...
xi = self . _calculateXi ( r ) CC = _C ( xi , N , L ) a = self . _a rho = nu . zeros ( ( N , L ) , float ) n = nu . arange ( 0 , N , dtype = float ) [ : , nu . newaxis ] l = nu . arange ( 0 , L , dtype = float ) [ nu . newaxis , : ] K = 0.5 * n * ( n + 4 * l + 3 ) + ( l + 1. ) * ( 2 * l + 1 ) rho [ : , : ] = K * ( ( a ...
def explain ( self , bindVars = { } , allPlans = False ) : """Returns an explanation of the query . Setting allPlans to True will result in ArangoDB returning all possible plans . False returns only the optimal plan"""
return self . database . explainAQLQuery ( self . query , bindVars , allPlans )
def _seg ( chars ) : """按是否是汉字进行分词"""
s = '' # 保存一个词 ret = [ ] # 分词结果 flag = 0 # 上一个字符是什么 ? 0 : 汉字 , 1 : 不是汉字 for n , c in enumerate ( chars ) : if RE_HANS . match ( c ) : # 汉字 , 确定 flag 的初始值 if n == 0 : # 第一个字符 flag = 0 if flag == 0 : s += c else : # 上一个字符不是汉字 , 分词 ret . append ( s ) ...
def burstColumn ( self , column , columnMatchingSegments , prevActiveCells , prevWinnerCells , learn ) : """Activates all of the cells in an unpredicted active column , chooses a winner cell , and , if learning is turned on , learns on one segment , growing a new segment if necessary . @ param column ( int ) ...
start = self . cellsPerColumn * column # Strip out destroyed cells before passing along to base _ burstColumn ( ) cellsForColumn = [ cellIdx for cellIdx in xrange ( start , start + self . cellsPerColumn ) if cellIdx not in self . deadCells ] return self . _burstColumn ( self . connections , self . _random , self . last...
def add_watcher_to_issue ( self , issue , JIRAUsername ) : """Adds a user to a specified issue ' s watcher list . Arguments : | issue ( string ) | A JIRA Issue that a watcher needs added to , can be an issue ID or Key | | JIRAUsername ( string ) | A JIRA Username to add as a watcher to an issue | Example : ...
self . jira . add_watcher ( issue = issue , watcher = JIRAUsername )
def _generate_relative_positions_embeddings ( length_q , length_k , depth , max_relative_position , name , cache = False ) : """Generates tensor of size [ 1 if cache else length _ q , length _ k , depth ] ."""
with tf . variable_scope ( name ) : relative_positions_matrix = _generate_relative_positions_matrix ( length_q , length_k , max_relative_position , cache = cache ) vocab_size = max_relative_position * 2 + 1 # Generates embedding for each relative position of dimension depth . embeddings_table = tf . get...
def _progressbar ( self , msg , iter_num ) : """Display a progress bar with current loss . Parameters msg : str Message to print alongside the progress bar iter _ num : int Iteration number . Progress is only printed if this is a multiple of ` self . display _ progress ` ."""
if self . display_progress and ( iter_num + 1 ) % self . display_progress == 0 : sys . stderr . write ( '\r' ) sys . stderr . write ( "Iteration {}: {}" . format ( iter_num + 1 , msg ) ) sys . stderr . flush ( )
def list_versions ( self ) : """Filterable list of versions of a layer , always ordered newest to oldest . If the version ’ s source supports revisions , you can get a specific revision using ` ` . filter ( data _ _ source _ _ revision = value ) ` ` . Specific values depend on the source type . Use ` ` data _...
target_url = self . _client . get_url ( 'VERSION' , 'GET' , 'multi' , { 'layer_id' : self . id } ) return base . Query ( self . _manager , target_url , valid_filter_attributes = ( 'data' , ) , valid_sort_attributes = ( ) )
def DeleteUserDefinedFunction ( self , udf_link , options = None ) : """Deletes a user defined function . : param str udf _ link : The link to the user defined function . : param dict options : The request options for the request . : return : The deleted UDF . : rtype : dict"""
if options is None : options = { } path = base . GetPathFromLink ( udf_link ) udf_id = base . GetResourceIdOrFullNameFromLink ( udf_link ) return self . DeleteResource ( path , 'udfs' , udf_id , None , options )
def deriv_H ( state , z , x , y , fase ) : r"""Calculate generic partial derivative : math : ` \ left . \ frac { \ partial z } { \ partial x } \ right | _ { y } ` from a fundamental helmholtz free energy equation of state Parameters state : any python object Only need to define P and T properties , non ph...
# We use the relation between rho and v and his partial derivative # ∂ v / ∂ b | c = - 1 / ρ2 ∂ ρ / ∂ b | c # ∂ a / ∂ v | c = - ρ2 ∂ a / ∂ ρ | c mul = 1 if z == "rho" : mul = - fase . rho ** 2 z = "v" if x == "rho" : mul = - 1 / fase . rho ** 2 x = "v" if y == "rho" : y = "v" dT = { "P" : state . P ...
def iter_fasta_qual ( fastafile , qualfile , defaultqual = OKQUAL , modify = False ) : """used by trim , emits one SeqRecord with quality values in it"""
from Bio . SeqIO . QualityIO import PairedFastaQualIterator if not qualfile : qualfile = make_qual ( fastafile , score = defaultqual ) rec_iter = PairedFastaQualIterator ( open ( fastafile ) , open ( qualfile ) ) for rec in rec_iter : yield rec if not modify else modify_qual ( rec )
def pattern2re ( pattern ) : """Makes a unicode regular expression from a pattern . Returns ` ` ( start , full _ re , int _ re ) ` ` where : * ` start ` is either empty or the subdirectory in which to start searching , * ` full _ re ` is a regular expression object that matches the requested files , i . e ....
pattern_segs = filter ( None , pattern . split ( '/' ) ) # This anchors the first component either at the start of the string or at # the start of a path component if not pattern : return '' , re . compile ( '' ) , None elif '/' in pattern : full_regex = '^' # Start at beginning of path int_regex = [ ] ...
def reject ( self , f , * args ) : """Like ' match ' , but throw a parse error if ' f ' matches . This is useful when a parser wants to be strict about specific things being prohibited . For example , DottySQL bans the use of SQL keywords as variable names ."""
match = self . match ( f , * args ) if match : token = self . peek ( 0 ) raise errors . EfilterParseError ( query = self . tokenizer . source , token = token , message = "Was not expecting a %s here." % token . name )
def display_hook ( fn ) : """A decorator to wrap display hooks that return a MIME bundle or None . Additionally it handles adding output to the notebook archive , saves files specified with the output magic and handles tracebacks ."""
@ wraps ( fn ) def wrapped ( element ) : global FULL_TRACEBACK if Store . current_backend is None : return { } , { } try : max_frames = OutputSettings . options [ 'max_frames' ] mimebundle = fn ( element , max_frames = max_frames ) if mimebundle is None : return {...
def loadNetworkFromFile ( filename , mode = 'pickle' ) : """Deprecated . Use loadNetwork instead ."""
if mode == 'pickle' : import pickle fp = open ( filename ) network = pickle . load ( fp ) fp . close ( ) return network elif mode in [ 'plain' , 'conx' ] : fp = open ( filename , "r" ) line = fp . readline ( ) network = None while line : if line . startswith ( "layer," ) : # ...
def load_config ( self ) : """Loads the configuration ."""
config = dict ( [ ( key , value ) for key , value in iteritems ( self . options ) if key in self . cfg . settings and value is not None ] ) for key , value in iteritems ( config ) : self . cfg . set ( key . lower ( ) , value )
def get_scratch_predictions ( self , path_to_scratch , results_dir , scratch_basename = 'scratch' , num_cores = 1 , exposed_buried_cutoff = 25 , custom_gene_mapping = None ) : """Run and parse ` ` SCRATCH ` ` results to predict secondary structure and solvent accessibility . Annotations are stored in the protein ...
if not self . genome_path : # Write all sequences as one file all_seqs = self . write_representative_sequences_file ( outname = self . id ) # Runs SCRATCH or loads existing results in results _ dir scratch = SCRATCH ( project_name = scratch_basename , seq_file = self . genome_path ) scratch . run_scratch ( path_to_...
def promise_method ( func ) : """A decorator which ensures that once a method has been marked as resolved ( via Class . _ _ resolved ) ) will then propagate the attribute ( function ) call upstream ."""
name = func . __name__ @ wraps ( func ) def wrapped ( self , * args , ** kwargs ) : cls_name = type ( self ) . __name__ if getattr ( self , '_%s__resolved' % ( cls_name , ) ) : return getattr ( getattr ( self , '_%s__wrapped' % ( cls_name , ) ) , name ) ( * args , ** kwargs ) return func ( self , * ...
def pop_aggregations_params ( self ) : """Pop and return aggregation params from query string params . Aggregation params are expected to be prefixed ( nested under ) by any of ` self . _ aggregations _ keys ` ."""
from nefertari . view import BaseView self . _query_params = BaseView . convert_dotted ( self . view . _query_params ) for key in self . _aggregations_keys : if key in self . _query_params : return self . _query_params . pop ( key ) else : raise KeyError ( 'Missing aggregation params' )
def validate_wrap ( self , value ) : '''Validates the type and length of ` ` value ` `'''
if not isinstance ( value , basestring ) : self . _fail_validation_type ( value , basestring ) if self . regex . match ( value ) is None : self . _fail_validation ( value , 'Value does not match regular expression' )
def mouseDown ( self , button ) : """Send a mouse button down at the last set position button : int : [ 1 - n ]"""
log . debug ( 'mouseDown %s' , button ) self . buttons |= 1 << ( button - 1 ) self . pointerEvent ( self . x , self . y , buttonmask = self . buttons ) return self
def send ( self , request , stream = False , timeout = None , verify = True , cert = None , proxies = None ) : """Sends PreparedRequest object . Returns Response object . : param request : The : class : ` PreparedRequest < PreparedRequest > ` being sent . : param stream : ( optional ) Whether to stream the requ...
raise NotImplementedError
def _make_admin_link_to_similar ( primary_field , * fields , name = None ) : """Create a function that links to a changelist of all objects with similar field values ."""
fields = ( primary_field , ) + fields url_template = '<a href="{url}">{name_or_value}</a>' def field_link ( self , obj ) : value = getattr ( obj , primary_field , None ) name_or_value = name or value filters = { field_name : getattr ( obj , field_name ) for field_name in fields } url = _build_admin_filt...
def maximize ( func , parameter_dict , args = { } , verbose = False , population_size = 50 , gene_mutation_prob = 0.1 , gene_crossover_prob = 0.5 , tournament_size = 3 , generations_number = 10 , gene_type = None , n_jobs = 1 , error_score = 'raise' ) : """Same as _ fit in EvolutionarySearchCV but without fitting d...
toolbox = base . Toolbox ( ) _check_param_grid ( parameter_dict ) if isinstance ( n_jobs , int ) : # If n _ jobs is an int , greater than 1 or less than 0 ( indicating to use as # many jobs as possible ) then we are going to create a default pool . # Windows users need to be warned of this feature as it only works prop...
def object_isinstance ( node , class_or_seq , context = None ) : """Check if a node ' isinstance ' any node in class _ or _ seq : param node : A given node : param class _ or _ seq : Union [ nodes . NodeNG , Sequence [ nodes . NodeNG ] ] : rtype : bool : raises AstroidTypeError : if the given ` ` classes _ ...
obj_type = object_type ( node , context ) if obj_type is util . Uninferable : return util . Uninferable return _object_type_is_subclass ( obj_type , class_or_seq , context = context )
def get_calling_namespaces ( ) : """Return the locals and globals for the function that called into this module in the current call stack ."""
try : 1 // 0 except ZeroDivisionError : # Don ' t start iterating with the current stack - frame to # prevent creating reference cycles ( f _ back is safe ) . frame = sys . exc_info ( ) [ 2 ] . tb_frame . f_back # Find the first frame that * isn ' t * from this file . This means # that we expect all of the SCon...
def _ParseDataObject ( self , file_object , file_offset ) : """Parses a data object . Args : file _ object ( dfvfs . FileIO ) : a file - like object . file _ offset ( int ) : offset of the data object relative to the start of the file - like object . Returns : bytes : data . Raises : ParseError : if...
data_object_map = self . _GetDataTypeMap ( 'systemd_journal_data_object' ) try : data_object , _ = self . _ReadStructureFromFileObject ( file_object , file_offset , data_object_map ) except ( ValueError , errors . ParseError ) as exception : raise errors . ParseError ( ( 'Unable to parse data object at offset: ...
def getRole ( self , label ) : """Get the : class : ` rtcclient . models . Role ` object by the label name : param label : the label name of the role : return : the : class : ` rtcclient . models . Role ` object : rtype : : class : ` rtcclient . models . Role `"""
if not isinstance ( label , six . string_types ) or not label : excp_msg = "Please specify a valid role label" self . log . error ( excp_msg ) raise exception . BadValue ( excp_msg ) roles = self . getRoles ( ) if roles is not None : for role in roles : if role . label == label : sel...
def _construct_arrow_tip ( self , pos ) : """returns arrow tip as ( width , widget )"""
arrow_tip = None width = 0 if self . _arrow_tip_char : txt = urwid . Text ( self . _arrow_tip_char ) arrow_tip = urwid . AttrMap ( txt , self . _arrow_tip_att or self . _arrow_att ) width = len ( self . _arrow_tip_char ) return width , arrow_tip
def train_model ( self , balance , * args , ** kwargs ) : """Args : balance : A 1d arraylike that sums to 1 , corresponding to the ( possibly estimated ) class balance ."""
self . balance = np . array ( balance )
def ftp_walk ( ftpconn : FTP , rootpath = '' ) : """Recursively traverse an ftp directory to discovery directory listing ."""
current_directory = rootpath try : directories , files = directory_listing ( ftpconn , current_directory ) except ftplib . error_perm : return # Yield before recursion yield current_directory , directories , files # Recurse into sub - directories for name in directories : new_path = os . path . join ( curre...
def _init_state ( self , initial_state : Union [ int , np . ndarray ] ) : """Initializes a the shard wavefunction and sets the initial state ."""
state = np . reshape ( sim . to_valid_state_vector ( initial_state , self . _num_qubits ) , ( self . _num_shards , self . _shard_size ) ) state_handle = mem_manager . SharedMemManager . create_array ( state . view ( dtype = np . float32 ) ) self . _shared_mem_dict [ 'state_handle' ] = state_handle
def delete ( self , id , project_id = None ) : """delete ."""
result = db . session . query ( Result ) . filter_by ( id = id ) . first ( ) if result is None : response = jsonify ( { 'result' : None , 'message' : 'No interface defined for URL.' } ) return response , 404 db . session . delete ( result ) db . session . commit ( ) return jsonify ( { 'result' : result . serial...
def read_ckan_catalog ( portal_url ) : """Convierte los metadatos de un portal disponibilizados por la Action API v3 de CKAN al estándar data . json . Args : portal _ url ( str ) : URL de un portal de datos CKAN que soporte la API v3. Returns : dict : Representación interna de un catálogo para uso en l...
portal = RemoteCKAN ( portal_url ) try : status = portal . call_action ( 'status_show' , requests_kwargs = { "verify" : False } ) packages_list = portal . call_action ( 'package_list' , requests_kwargs = { "verify" : False } ) groups_list = portal . call_action ( 'group_list' , requests_kwargs = { "verify" ...
def stop_capture_handler ( self , name ) : '''Remove all handlers with a given name Args : name : The name of the handler ( s ) to remove .'''
empty_capturers_indeces = [ ] for k , sc in self . _stream_capturers . iteritems ( ) : stream_capturer = sc [ 0 ] stream_capturer . remove_handler ( name ) if stream_capturer . handler_count == 0 : self . _pool . killone ( sc [ 1 ] ) empty_capturers_indeces . append ( k ) for i in empty_capt...
def _id_for_pc ( self , name ) : """Given the name of the PC , return the database identifier ."""
if not name in self . pc2id_lut : self . c . execute ( "INSERT INTO pcs (name) VALUES ( ? )" , ( name , ) ) self . pc2id_lut [ name ] = self . c . lastrowid self . id2pc_lut [ self . c . lastrowid ] = name return self . pc2id_lut [ name ]
def wheel_libs ( wheel_fname , filt_func = None ) : """Return analysis of library dependencies with a Python wheel Use this routine for a dump of the dependency tree . Parameters wheel _ fname : str Filename of wheel filt _ func : None or callable , optional If None , inspect all files for library depen...
with TemporaryDirectory ( ) as tmpdir : zip2dir ( wheel_fname , tmpdir ) lib_dict = tree_libs ( tmpdir , filt_func ) return stripped_lib_dict ( lib_dict , realpath ( tmpdir ) + os . path . sep )
def get_dependants ( project_name ) : """Yield dependants of ` project _ name ` ."""
for package in get_installed_distributions ( user_only = ENABLE_USER_SITE ) : if is_dependant ( package , project_name ) : yield package . project_name
def register_uri_backend ( uri_scheme , create_method , module , c14n_uri_method , escape , cast , is_connected ) : """This method is intended to be used by backends only . It lets them register their services , identified by the URI scheme , at import time . The associated method create _ method must take one ...
try : delta_api = __compare_api_level ( module . apilevel , any_apilevel ) mod_paramstyle = module . paramstyle mod_threadsafety = module . threadsafety except NameError : raise NotImplementedError ( "This module does not support registration " "of non DBAPI services of at least apilevel 2.0" ) if delta...
def send ( self , confirmation_email , send_date = "immediately" ) : """Sends this campaign ."""
body = { "ConfirmationEmail" : confirmation_email , "SendDate" : send_date } response = self . _post ( self . uri_for ( "send" ) , json . dumps ( body ) )
def format_parameter ( element ) : """Formats a particular parameter . Essentially the same as built - in formatting except using ' i ' instead of ' j ' for the imaginary number . : param element : { int , float , long , complex , Parameter } Formats a parameter for Quil output ."""
if isinstance ( element , integer_types ) or isinstance ( element , np . int_ ) : return repr ( element ) elif isinstance ( element , float ) : return _check_for_pi ( element ) elif isinstance ( element , complex ) : out = '' r = element . real i = element . imag if i == 0 : return repr ...
def interpolate ( self , target , extent ) : """Move this vector towards the given towards the target by the given extent . The extent should be between 0 and 1."""
target = cast_anything_to_vector ( target ) self += extent * ( target - self )
def assert_instance_created ( self , model_class , ** kwargs ) : """Checks if a model instance was created in the database . For example : : > > > with self . assert _ instance _ created ( Article , slug = ' lorem - ipsum ' ) : . . . Article . objects . create ( slug = ' lorem - ipsum ' )"""
return _InstanceContext ( self . assert_instance_does_not_exist , self . assert_instance_exists , model_class , ** kwargs )
def options ( self , urls = None , ** overrides ) : """Sets the acceptable HTTP method to OPTIONS"""
if urls is not None : overrides [ 'urls' ] = urls return self . where ( accept = 'OPTIONS' , ** overrides )
def irafcrop ( self , irafcropstring ) : """This is a wrapper around crop ( ) , similar to iraf imcopy , using iraf conventions ( 100:199 will be 100 pixels , not 99 ) ."""
irafcropstring = irafcropstring [ 1 : - 1 ] # removing the [ ] ranges = irafcropstring . split ( "," ) xr = ranges [ 0 ] . split ( ":" ) yr = ranges [ 1 ] . split ( ":" ) xmin = int ( xr [ 0 ] ) xmax = int ( xr [ 1 ] ) + 1 ymin = int ( yr [ 0 ] ) ymax = int ( yr [ 1 ] ) + 1 self . crop ( xmin , xmax , ymin , ymax )
def save ( self ) : """Pushes the current dispatch table on the stack and re - initializes the current dispatch table to the default ."""
self . stack . append ( self . dispatch_table ) self . dispatch_table = self . default_table . copy ( )
def cpp_spec ( ) : """C + + specification , provided for example , and java compatible ."""
return { INDENTATION : '\t' , BEG_BLOCK : '{' , END_BLOCK : '}' , BEG_LINE : '' , END_LINE : '\n' , BEG_ACTION : '' , END_ACTION : ';' , BEG_CONDITION : 'if(' , END_CONDITION : ')' , LOGICAL_AND : ' && ' , LOGICAL_OR : ' || ' }
def check_supported_function ( func , check_func ) : """Decorator implementation that wraps a check around an ESPLoader bootloader function to check if it ' s supported . This is used to capture the multidimensional differences in functionality between the ESP8266 & ESP32 ROM loaders , and the software stub...
def inner ( * args , ** kwargs ) : obj = args [ 0 ] if check_func ( obj ) : return func ( * args , ** kwargs ) else : raise NotImplementedInROMError ( obj , func ) return inner
def templates ( self ) : """Generate a dictionary with template names and file paths ."""
templates = { } result = [ ] if self . entry_point_group_templates : result = self . load_entry_point_group_templates ( self . entry_point_group_templates ) or [ ] for template in result : for name , path in template . items ( ) : templates [ name ] = path return templates
def _add_loss_summaries ( total_loss ) : """Add summaries for losses in CIFAR - 10 model . Generates moving average for all losses and associated summaries for visualizing the performance of the network . Args : total _ loss : Total loss from loss ( ) . Returns : loss _ averages _ op : op for generating...
# Compute the moving average of all individual losses and the total loss . loss_averages = tf . train . ExponentialMovingAverage ( 0.9 , name = 'avg' ) losses = tf . get_collection ( 'losses' ) loss_averages_op = loss_averages . apply ( losses + [ total_loss ] ) # Attach a scalar summary to all individual losses and th...
def has_library ( compiler , libname ) : """Return a boolean indicating whether a library is found ."""
with tempfile . NamedTemporaryFile ( "w" , suffix = ".cpp" ) as srcfile : srcfile . write ( "int main (int argc, char **argv) { return 0; }" ) srcfile . flush ( ) outfn = srcfile . name + ".so" try : compiler . link_executable ( [ srcfile . name ] , outfn , libraries = [ libname ] , ) except...
def float_to_latex ( x , format = "%.2g" ) : # pylint : disable = redefined - builtin # pylint : disable = anomalous - backslash - in - string r"""Convert a floating point number to a latex representation . In particular , scientific notation is handled gracefully : e - > 10 ^ Parameters x : ` float ` the n...
if x == 0. : return '0' base_str = format % x if "e" not in base_str : return base_str mantissa , exponent = base_str . split ( "e" ) if float ( mantissa ) . is_integer ( ) : mantissa = int ( float ( mantissa ) ) exponent = exponent . lstrip ( "0+" ) if exponent . startswith ( '-0' ) : exponent = '-' + ...
def _validate_optional_key ( key , missing , value , validated , optional ) : """Validate an optional key ."""
try : validated [ key ] = optional [ key ] ( value ) except NotValid as ex : return [ '%r: %s' % ( key , arg ) for arg in ex . args ] if key in missing : missing . remove ( key ) return [ ]
def _ready_gzip_fastq ( in_files , data , require_bgzip = False ) : """Check if we have gzipped fastq and don ' t need format conversion or splitting . Avoid forcing bgzip if we don ' t need indexed files ."""
all_gzipped = all ( [ not x or x . endswith ( ".gz" ) for x in in_files ] ) if require_bgzip and all_gzipped : all_gzipped = all ( [ not x or not _check_gzipped_input ( x , data ) [ 0 ] for x in in_files ] ) needs_convert = dd . get_quality_format ( data ) . lower ( ) == "illumina" needs_trim = dd . get_trim_ends (...
def from_array ( array ) : """Deserialize a new PassportElementErrorFiles from a given dictionary . : return : new PassportElementErrorFiles instance . : rtype : PassportElementErrorFiles"""
if array is None or not array : return None # end if assert_type_or_raise ( array , dict , parameter_name = "array" ) data = { } data [ 'source' ] = u ( array . get ( 'source' ) ) data [ 'type' ] = u ( array . get ( 'type' ) ) data [ 'file_hashes' ] = PassportElementErrorFiles . _builtin_from_array_list ( required_...
def get_canonical_query_params ( self ) : """Return the canonical query params ( used in signing ) ."""
result = [ ] for key , value in self . sorted_params ( ) : result . append ( "%s=%s" % ( self . encode ( key ) , self . encode ( value ) ) ) return "&" . join ( result )
def _get_pos ( self ) : """Get current position for scroll bar ."""
if self . _canvas . height >= self . _max_height : return 0 else : return self . _canvas . start_line / ( self . _max_height - self . _canvas . height + 1 )
def to_valid_state_vector ( state_rep : Union [ int , np . ndarray ] , num_qubits : int , dtype : Type [ np . number ] = np . complex64 ) -> np . ndarray : """Verifies the state _ rep is valid and converts it to ndarray form . This method is used to support passing in an integer representing a computational bas...
if isinstance ( state_rep , np . ndarray ) : if len ( state_rep ) != 2 ** num_qubits : raise ValueError ( 'initial state was of size {} ' 'but expected state for {} qubits' . format ( len ( state_rep ) , num_qubits ) ) state = state_rep elif isinstance ( state_rep , int ) : if state_rep < 0 : ...
def phoneid ( self , phone_number , ** params ) : """The PhoneID API provides a cleansed phone number , phone type , and telecom carrier information to determine the best communication method - SMS or voice . See https : / / developer . telesign . com / docs / phoneid - api for detailed API documentation ."""
return self . post ( PHONEID_RESOURCE . format ( phone_number = phone_number ) , ** params )
def parent ( self ) : """The parent directory of this path ."""
p = self . _lib . dirname ( self . path ) p = self . __class__ ( p ) return p
def examples ( directory ) : """Generate example strategies to target folder"""
source_dir = os . path . join ( os . path . dirname ( os . path . realpath ( __file__ ) ) , "examples" ) try : shutil . copytree ( source_dir , os . path . join ( directory , "examples" ) ) except OSError as e : if e . errno == errno . EEXIST : six . print_ ( "Folder examples is exists." )
def find_enriched ( sample_entities = None , background_entities = None , object_category = None , ** kwargs ) : """Given a sample set of sample _ entities ( e . g . overexpressed genes ) and a background set ( e . g . all genes assayed ) , and a category of descriptor ( e . g . phenotype , function ) , return en...
if sample_entities is None : sample_entites = [ ] ( sample_counts , sample_results ) = get_counts ( entities = sample_entities , object_category = object_category , min_count = 2 , ** kwargs ) print ( str ( sample_counts ) ) sample_fcs = sample_results [ 'facet_counts' ] taxon_count_dict = sample_fcs [ M . SUBJECT_...
def format_tsv_line ( source , edge , target , value = None , metadata = None ) : """Render a single line for TSV file with data flow described : type source str : type edge str : type target str : type value float : type metadata str : rtype : str"""
return '{source}\t{edge}\t{target}\t{value}\t{metadata}' . format ( source = source , edge = edge , target = target , value = '{:.4f}' . format ( value ) if value is not None else '' , metadata = metadata or '' ) . rstrip ( ' \t' )
def getPeopleFilters ( self ) : """Return an iterator of L { IPeopleFilter } providers available to this organizer ' s store ."""
yield AllPeopleFilter ( ) yield VIPPeopleFilter ( ) for getPeopleFilters in self . _gatherPluginMethods ( 'getPeopleFilters' ) : for peopleFilter in getPeopleFilters ( ) : yield peopleFilter for tag in sorted ( self . getPeopleTags ( ) ) : yield TaggedPeopleFilter ( tag )
def encrypt_variable ( variable , build_repo , * , tld = '.org' , public_key = None , travis_token = None , ** login_kwargs ) : """Encrypt an environment variable for ` ` build _ repo ` ` for Travis ` ` variable ` ` should be a bytes object , of the form ` ` b ' ENV = value ' ` ` . ` ` build _ repo ` ` is the r...
if not isinstance ( variable , bytes ) : raise TypeError ( "variable should be bytes" ) if not b"=" in variable : raise ValueError ( "variable should be of the form 'VARIABLE=value'" ) if not public_key : _headers = { 'Content-Type' : 'application/json' , 'User-Agent' : 'MyClient/1.0.0' , } headersv2 = ...
def put_property ( elt , key , value , ttl = None , ctx = None ) : """Put properties in elt . : param elt : properties elt to put . Not None methods . : param number ttl : If not None , property time to leave . : param ctx : elt ctx from where put properties . Equals elt if None . It allows to get function ...
return put_properties ( elt = elt , properties = { key : value } , ttl = ttl , ctx = ctx )
def getAvailableTemplates ( self ) : """Returns an array with the templates of stickers available . Each array item is a dictionary with the following structure : { ' id ' : < template _ id > , ' title ' : < teamplate _ title > , ' selected : True / False ' }"""
# Getting adapters for current context . those adapters will return # the desired sticker templates for the current context : try : adapters = getAdapters ( ( self . context , ) , IGetStickerTemplates ) except ComponentLookupError : logger . info ( "No IGetStickerTemplates adapters found." ) adapters = None...
def forum_topic_delete ( self , topic_id ) : """Delete a topic ( Login Requires ) ( Moderator + ) ( UNTESTED ) . Parameters : topic _ id ( int ) : Where topic _ id is the topic id ."""
return self . _get ( 'forum_topics/{0}.json' . format ( topic_id ) , method = 'DELETE' , auth = True )
def get_mchirp ( h5group ) : """Calculate the chipr mass column for this PyCBC HDF5 table group"""
mass1 = h5group [ 'mass1' ] [ : ] mass2 = h5group [ 'mass2' ] [ : ] return ( mass1 * mass2 ) ** ( 3 / 5. ) / ( mass1 + mass2 ) ** ( 1 / 5. )
def random_square_mask ( shape , fraction ) : """Create a numpy array with specified shape and masked fraction . Args : shape : tuple , shape of the mask to create . fraction : float , fraction of the mask area to populate with ` mask _ scalar ` . Returns : numpy . array : A numpy array storing the mask ....
mask = np . ones ( shape ) patch_area = shape [ 0 ] * shape [ 1 ] * fraction patch_dim = np . int ( math . floor ( math . sqrt ( patch_area ) ) ) if patch_area == 0 or patch_dim == 0 : return mask x = np . random . randint ( shape [ 0 ] - patch_dim ) y = np . random . randint ( shape [ 1 ] - patch_dim ) mask [ x : ...
def _serialize_v2 ( self , macaroon ) : '''Serialize the macaroon in JSON format v2. @ param macaroon the macaroon to serialize . @ return JSON macaroon in v2 format .'''
serialized = { } _add_json_binary_field ( macaroon . identifier_bytes , serialized , 'i' ) _add_json_binary_field ( binascii . unhexlify ( macaroon . signature_bytes ) , serialized , 's' ) if macaroon . location : serialized [ 'l' ] = macaroon . location if macaroon . caveats : serialized [ 'c' ] = [ _caveat_v2...
def update ( self , callback = None , errback = None , ** kwargs ) : """Update zone configuration . Pass a list of keywords and their values to update . For the list of keywords available for zone configuration , see : attr : ` ns1 . rest . zones . Zones . INT _ FIELDS ` and : attr : ` ns1 . rest . zones . Zo...
if not self . data : raise ZoneException ( 'zone not loaded' ) def success ( result , * args ) : self . data = result if callback : return callback ( self ) else : return self return self . _rest . update ( self . zone , callback = success , errback = errback , ** kwargs )
def create_paired_dir ( output_dir , meta_id , static = False , needwebdir = True ) : """Creates the meta or static dirs . Adds an " even " or " odd " subdirectory to the static path based on the meta - id ."""
# get the absolute root path root_path = os . path . abspath ( output_dir ) # if it ' s a static directory , add even and odd if static : # determine whether meta - id is odd or even if meta_id [ - 1 ] . isdigit ( ) : last_character = int ( meta_id [ - 1 ] ) else : last_character = ord ( meta_id...
def post_stats ( cls , stats_url , stats , timeout = 2 , auth_provider = None ) : """POST stats to the given url . : return : True if upload was successful , False otherwise ."""
def error ( msg ) : # Report aleady closed , so just print error . print ( 'WARNING: Failed to upload stats to {}. due to {}' . format ( stats_url , msg ) , file = sys . stderr ) return False # TODO ( benjy ) : The upload protocol currently requires separate top - level params , with JSON # values . Probably be...
def skip_whitespace ( self ) : """Consume input until a non - whitespace character is encountered . The non - whitespace character is then ungotten , and the number of whitespace characters consumed is returned . If the tokenizer is in multiline mode , then newlines are whitespace . @ rtype : int"""
skipped = 0 while True : c = self . _get_char ( ) if c != ' ' and c != '\t' : if ( c != '\n' ) or not self . multiline : self . _unget_char ( c ) return skipped skipped += 1
def pin_in_object_store ( obj ) : """Pin an object in the object store . It will be available as long as the pinning process is alive . The pinned object can be retrieved by calling get _ pinned _ object on the identifier returned by this call ."""
obj_id = ray . put ( _to_pinnable ( obj ) ) _pinned_objects . append ( ray . get ( obj_id ) ) return "{}{}" . format ( PINNED_OBJECT_PREFIX , base64 . b64encode ( obj_id . binary ( ) ) . decode ( "utf-8" ) )
def release_filter ( self , value ) : """Validate the release filter ."""
compiled_pattern = coerce_pattern ( value ) if compiled_pattern . groups > 1 : raise ValueError ( compact ( """ Release filter regular expression pattern is expected to have zero or one capture group, but it has {count} instead! """ , count = compiled_pattern . groups ) )...
def uninstall_pgpm_from_db ( self ) : """Removes pgpm from db and all related metadata ( _ pgpm schema ) . Install packages are left as they are : return : 0 if successful and error otherwise"""
drop_schema_cascade_script = 'DROP SCHEMA {schema_name} CASCADE;' if self . _conn . closed : self . _conn = psycopg2 . connect ( self . _connection_string , connection_factory = pgpm . lib . utils . db . MegaConnection ) cur = self . _conn . cursor ( ) # get current user cur . execute ( pgpm . lib . utils . db . Sq...
def get_plugin_info ( plugin ) : """Fetch information about the given package on PyPI and return it as a dict . If the package cannot be found on PyPI , : exc : ` NameError ` will be raised ."""
url = 'https://pypi.python.org/pypi/{}/json' . format ( plugin ) try : resp = request . urlopen ( url ) except HTTPError as e : if e . code == 404 : raise NameError ( "Plugin {} could not be found." . format ( plugin ) ) else : raise ValueError ( "Checking plugin status on {} returned HTTP c...
def set_epsilon_greedy_rate ( self , value ) : '''setter'''
if isinstance ( value , float ) is True : self . __epsilon_greedy_rate = value else : raise TypeError ( "The type of __epsilon_greedy_rate must be float." )
def composition ( self ) : """( Composition ) Returns the composition"""
elmap = collections . defaultdict ( float ) for site in self : for species , occu in site . species . items ( ) : elmap [ species ] += occu return Composition ( elmap )
def writeString ( self , s ) : """Writes a string to the stream . It will be B { UTF - 8 } encoded ."""
s = self . context . getBytesForString ( s ) self . writeBytes ( s )
def next_stop ( self ) : """Return the next stop for this bus ."""
p = self . api . predictions ( vid = self . vid ) [ 'prd' ] pobj = Prediction . fromapi ( self . api , p [ 0 ] ) pobj . _busobj = self return pobj
def message_with_options ( self , * , args = None , kwargs = None , ** options ) : """Build a message with an arbitray set of processing options . This method is useful if you want to compose actors . See the actor composition documentation for details . Parameters : args ( tuple ) : Positional arguments th...
for name in [ "on_failure" , "on_success" ] : callback = options . get ( name ) if isinstance ( callback , Actor ) : options [ name ] = callback . actor_name elif not isinstance ( callback , ( type ( None ) , str ) ) : raise TypeError ( name + " value must be an Actor" ) return Message ( que...
def _add ( self , handler , allow_dupe = False , send_event = True ) : """Add handler instance and attach any events to it . : param object handler : handler instance : param bool allow _ dupe : If True , allow registering a handler more than once . : return object : The handler you added is given back so thi...
if not allow_dupe and handler in self . handlers : raise ValueError ( "Handler already present: %s" % handler ) self . handlers . append ( handler ) self . _attach_handler_events ( handler ) if send_event : self . on_handler_add ( handler )
def _create_window_function ( name , doc = '' ) : """Create a window function by name"""
def _ ( ) : sc = SparkContext . _active_spark_context jc = getattr ( sc . _jvm . functions , name ) ( ) return Column ( jc ) _ . __name__ = name _ . __doc__ = 'Window function: ' + doc return _
def is_present ( self , locator ) : """Tests to see if an element is present @ type locator : webdriverwrapper . support . locator . Locator @ param locator : locator used in search @ rtype : bool @ return : True if present , False if not present"""
return self . driver_wrapper . is_present ( locator , search_object = self . element )
def _next_seg ( self ) : """Get next seg ."""
if self . _seg : self . _seg . close ( ) self . _seg_index += 1 if self . _seg_index > self . _last_seg_index : self . _seg = None return filename = self . _seg_prefix + str ( self . _seg_index ) stat = cloudstorage . stat ( filename ) writer = output_writers . _GoogleCloudStorageOutputWriter if writer . _V...
def com_google_fonts_check_wght_valid_range ( ttFont ) : """The variable font ' wght ' ( Weight ) axis coordinate must be within spec range of 1 to 1000 on all instances ."""
Failed = False for instance in ttFont [ 'fvar' ] . instances : if 'wght' in instance . coordinates : value = instance . coordinates [ 'wght' ] if value < 1 or value > 1000 : Failed = True yield FAIL , ( f"Found a bad wght coordinate with value '{value}'" " outside of the vali...
def set_not_found_handler ( self , handler , version = None ) : """Sets the not _ found handler for the specified version of the api"""
if not self . not_found_handlers : self . _not_found_handlers = { } self . not_found_handlers [ version ] = handler
def from_bank_code ( cls , country_code , bank_code ) : """Create a new BIC object from country - and bank - code . Examples : > > > bic = BIC . from _ bank _ code ( ' DE ' , ' 20070000 ' ) > > > bic . country _ code ' DE ' > > > bic . bank _ code ' DEUT ' > > > bic . location _ code ' HH ' > > > ...
try : return cls ( registry . get ( 'bank_code' ) [ ( country_code , bank_code ) ] [ 'bic' ] ) except KeyError : raise ValueError ( "Invalid bank code {!r} for country {!r}" . format ( bank_code , country_code ) )
def quote ( code ) : """Returns quoted code if not already quoted and if possible Parameters code : String \t Code thta is quoted"""
try : code = code . rstrip ( ) except AttributeError : # code is not a string , may be None - - > There is no code to quote return code if code and code [ 0 ] + code [ - 1 ] not in ( '""' , "''" , "u'" , '"' ) and '"' not in code : return 'u"' + code + '"' else : return code
def get_line_value ( self , context_type ) : """Get the values defined on this line . : param context _ type : " ENV " or " LABEL " : return : values of given type defined on this line"""
if context_type . upper ( ) == "ENV" : return self . line_envs elif context_type . upper ( ) == "LABEL" : return self . line_labels
def searches ( self ) : """* The search - block ( if any ) associated with this document * * * Usage : * * . . code - block : : python # DOCUMENT SEARCHES docSearchBlock = doc . searches"""
return self . _get_object ( regex = re . compile ( r'((?<=\n)|(?<=^))(?P<title>\[Searches\]:) *(?P<tagString>( *?@\S*(\(.*?\))?)+)?(?P<content>(\n( |\t).*)*)' , re . UNICODE ) , objectType = "searchBlock" , content = None )
def Build ( self ) : """Builds a client config dictionary used in the OAuth 2.0 flow ."""
if all ( ( self . client_type , self . client_id , self . client_secret , self . auth_uri , self . token_uri ) ) : client_config = { self . client_type : { 'client_id' : self . client_id , 'client_secret' : self . client_secret , 'auth_uri' : self . auth_uri , 'token_uri' : self . token_uri } } else : raise Val...