signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def get_tweet ( self , id ) : """Get an existing tweet . : param id : ID of the tweet in question : return : Tweet object . None if not found"""
try : return Tweet ( self . _client . get_status ( id = id ) . _json ) except TweepError as e : if e . api_code == TWITTER_TWEET_NOT_FOUND_ERROR : return None raise
def pack ( self , value = None ) : """Pack the struct in a binary representation . Merge some fields to ensure correct packing . If no arguments are set for a particular instance , it is interpreted as abscence of VLAN information , and the pack ( ) method will return an empty binary string . Returns : ...
if isinstance ( value , type ( self ) ) : return value . pack ( ) if self . pcp is None and self . cfi is None and self . vid is None : return b'' self . pcp = self . pcp if self . pcp is not None else 0 self . cfi = self . cfi if self . cfi is not None else 0 self . vid = self . vid if self . vid is not None e...
def colorize ( img , heatmap ) : """img : bgr , [ 0,255] heatmap : [ 0,1]"""
heatmap = viz . intensity_to_rgb ( heatmap , cmap = 'jet' ) [ : , : , : : - 1 ] return img * 0.5 + heatmap * 0.5
def requests_retry_session ( retries = 3 , backoff_factor = 0.3 , status_forcelist = ( 500 , 502 , 504 ) , session = None ) : """Create a requests session that handles errors by retrying . Parameters retries : ` int ` , optional Number of retries to attempt . backoff _ factor : ` float ` , optional Backof...
session = session or requests . Session ( ) retry = Retry ( total = retries , read = retries , connect = retries , backoff_factor = backoff_factor , status_forcelist = status_forcelist , ) adapter = HTTPAdapter ( max_retries = retry ) session . mount ( 'http://' , adapter ) session . mount ( 'https://' , adapter ) retu...
def survey_basis ( self , keys = None , alias = None , step = None ) : """Look at the basis of all the curves in ` ` well . data ` ` and return a basis with the minimum start , maximum depth , and minimum step . Args : keys ( list ) : List of strings : the keys of the data items to survey , if not all of th...
if keys is None : keys = [ k for k , v in self . data . items ( ) if isinstance ( v , Curve ) ] else : keys = utils . flatten_list ( keys ) starts , stops , steps = [ ] , [ ] , [ ] for k in keys : d = self . get_curve ( k , alias = alias ) if keys and ( d is None ) : continue try : s...
def build_js ( ctx , force = False ) : """Build all javascript files ."""
for fname in JSX_FILENAMES : jstools . babel ( ctx , '{pkg.source_js}/' + fname , '{pkg.django_static}/{pkg.name}/js/' + fname + '.js' , force = force )
def generate_filename ( self , mark , ** kwargs ) : """Comes up with a good filename for the watermarked image"""
kwargs = kwargs . copy ( ) kwargs [ 'opacity' ] = int ( kwargs [ 'opacity' ] * 100 ) kwargs [ 'st_mtime' ] = kwargs [ 'fstat' ] . st_mtime kwargs [ 'st_size' ] = kwargs [ 'fstat' ] . st_size params = [ '%(original_basename)s' , 'wm' , 'w%(watermark)i' , 'o%(opacity)i' , 'gs%(greyscale)i' , 'r%(rotation)i' , 'fm%(st_mti...
def __get_agent_host_port ( self ) : """Iterates the the various ways the host and port of the Instana host agent may be configured : default , env vars , sensor options . . ."""
host = AGENT_DEFAULT_HOST port = AGENT_DEFAULT_PORT if "INSTANA_AGENT_HOST" in os . environ : host = os . environ [ "INSTANA_AGENT_HOST" ] if "INSTANA_AGENT_PORT" in os . environ : port = int ( os . environ [ "INSTANA_AGENT_PORT" ] ) elif "INSTANA_AGENT_IP" in os . environ : # Deprecated : INSTANA _ AGE...
def get_tool_filepath ( self , tool_alias ) : """Given a visible tool alias , return the full path to the executable . Args : tool _ alias ( str ) : Tool alias to search for . Returns : ( str ) : Filepath of executable , or None if the tool is not in the suite . May also return None because this suite has...
tools_dict = self . get_tools ( ) if tool_alias in tools_dict : if self . tools_path is None : return None else : return os . path . join ( self . tools_path , tool_alias ) else : return None
def _select_broker_pair ( self , rg_destination , victim_partition ) : """Select best - fit source and destination brokers based on partition count and presence of partition over the broker . * Get overloaded and underloaded brokers Best - fit Selection Criteria : Source broker : Select broker containing th...
broker_source = self . _elect_source_broker ( victim_partition ) broker_destination = rg_destination . _elect_dest_broker ( victim_partition ) return broker_source , broker_destination
def QA_indicator_MA ( DataFrame , * args , ** kwargs ) : """MA Arguments : DataFrame { [ type ] } - - [ description ] Returns : [ type ] - - [ description ]"""
CLOSE = DataFrame [ 'close' ] return pd . DataFrame ( { 'MA{}' . format ( N ) : MA ( CLOSE , N ) for N in list ( args ) } )
def vector_normalize ( mat , max_vec_norm = 1. ) : """Normalize each column vector in mat to length max _ vec _ norm if it is longer than max _ vec _ norm"""
assert mat . flags . c_contiguous n , m = mat . shape vector_normalize_kernel . prepared_call ( ( m , 1 , 1 ) , ( 32 , 1 , 1 ) , mat . gpudata , np . float32 ( max_vec_norm ) , np . int32 ( m ) , np . int32 ( n ) )
def derivative ( self , t = None , n = 1 ) : """returns the nth derivative of the segment at t ."""
assert self . end != self . start if n == 1 : return self . end - self . start elif n > 1 : return 0 else : raise ValueError ( "n should be a positive integer." )
def ensure_directory ( path ) : """Ensure directory exists for a given file path ."""
dirname = os . path . dirname ( path ) if not os . path . exists ( dirname ) : os . makedirs ( dirname )
def get_emails ( self , mailinglist_dir , all , exclude_lists ) : """Generator function that get the emails from each mailing list dump dirctory . If ` all ` is set to True all the emails in the mbox will be imported if not it will just resume from the last message previously imported . The lists set in ` exc...
self . log ( "Getting emails dumps from: %s" % mailinglist_dir ) # Get the list of directories ending with . mbox mailing_lists_mboxes = ( mbox for mbox in os . listdir ( mailinglist_dir ) if mbox . endswith ( '.mbox' ) ) # Get messages from each mbox for mbox in mailing_lists_mboxes : mbox_path = os . path . join ...
def plot_roc ( y_true , y_probas , title = 'ROC Curves' , plot_micro = True , plot_macro = True , classes_to_plot = None , ax = None , figsize = None , cmap = 'nipy_spectral' , title_fontsize = "large" , text_fontsize = "medium" ) : """Generates the ROC curves from labels and predicted scores / probabilities Args...
y_true = np . array ( y_true ) y_probas = np . array ( y_probas ) classes = np . unique ( y_true ) probas = y_probas if classes_to_plot is None : classes_to_plot = classes if ax is None : fig , ax = plt . subplots ( 1 , 1 , figsize = figsize ) ax . set_title ( title , fontsize = title_fontsize ) fpr_dict = dict...
def fetch ( self ) : """Fetch a AvailablePhoneNumberCountryInstance : returns : Fetched AvailablePhoneNumberCountryInstance : rtype : twilio . rest . api . v2010 . account . available _ phone _ number . AvailablePhoneNumberCountryInstance"""
params = values . of ( { } ) payload = self . _version . fetch ( 'GET' , self . _uri , params = params , ) return AvailablePhoneNumberCountryInstance ( self . _version , payload , account_sid = self . _solution [ 'account_sid' ] , country_code = self . _solution [ 'country_code' ] , )
def get_version ( cls ) : """Return the version number of the tool ."""
cmd_pieces = [ cls . tool , '--version' ] process = Popen ( cmd_pieces , stdout = PIPE , stderr = PIPE ) out , err = process . communicate ( ) if err : return '' else : return out . splitlines ( ) [ 0 ] . strip ( )
def get_authorization_lookup_session_for_vault ( self , vault_id , proxy ) : """Gets the ` ` OsidSession ` ` associated with the authorization lookup service for the given vault . arg : vault _ id ( osid . id . Id ) : the ` ` Id ` ` of the vault arg : proxy ( osid . proxy . Proxy ) : a proxy return : ( osid ....
if not self . supports_authorization_lookup ( ) : raise errors . Unimplemented ( ) # Also include check to see if the catalog Id is found otherwise raise errors . NotFound # pylint : disable = no - member return sessions . AuthorizationLookupSession ( vault_id , proxy , self . _runtime )
def rand_str ( length , allowed = CHARSET_ALPHA_DIGITS ) : """Generate fixed - length random string from your allowed character pool . : param length : total length of this string . : param allowed : allowed charset . Example : : > > > import string > > > rand _ str ( 32) H6ExQPNLzb4Vp3YZtfpyzLNPFwdfnwz...
res = list ( ) for _ in range ( length ) : res . append ( random . choice ( allowed ) ) return "" . join ( res )
def physical_cpus ( ) : """Get cpus identifiers , for instance set ( [ " 0 " , " 1 " , " 2 " , " 3 " ] ) : return Number of physical CPUs available : rtype : int"""
if platform . system ( ) == 'Darwin' : ncores = subprocess . check_output ( [ '/usr/sbin/sysctl' , '-n' , 'hw.ncpu' ] , shell = False ) return int ( ncores . strip ( ) ) sockets = set ( ) with open ( '/proc/cpuinfo' ) as istr : for line in istr : if line . startswith ( 'physical id' ) : ...
def this_month ( self ) : """Access the this _ month : returns : twilio . rest . api . v2010 . account . usage . record . this _ month . ThisMonthList : rtype : twilio . rest . api . v2010 . account . usage . record . this _ month . ThisMonthList"""
if self . _this_month is None : self . _this_month = ThisMonthList ( self . _version , account_sid = self . _solution [ 'account_sid' ] , ) return self . _this_month
def find_smallest ( num1 , num2 ) : """A Python function to return the smallest of two given numbers . Arguments : num1 , num2 : Two numbers to compare Returns : The smallest number among num1 and num2 Examples : > > > find _ smallest ( 1 , 2) > > > find _ smallest ( ( - 5 ) , ( - 4 ) ) > > > find _...
return num1 if num1 <= num2 else num2
def get_latex ( self ) : """Bibliographic entry in LaTeX format ."""
if len ( self . authors ) > 1 : authors = _list_authors ( self . authors ) else : a = self . authors authors = ' ' . join ( [ a . given_name , a . surname ] ) if self . volume and self . issueIdentifier : volissue = '\\textbf{{{}({})}}' . format ( self . volume , self . issueIdentifier ) elif self . vol...
def save_connection_settings ( self ) : """Save user ' s kernel connection settings ."""
if not self . save_layout . isChecked ( ) : return is_ssh_key = bool ( self . kf_radio . isChecked ( ) ) connection_settings = { "json_file_path" : self . cf . text ( ) , "is_remote" : self . rm_group . isChecked ( ) , "username" : self . un . text ( ) , "hostname" : self . hn . text ( ) , "port" : self . pn . text...
def _adjust_axis ( self , axis ) : """Return raw axis / axes corresponding to apparent axis / axes . This method adjusts user provided ' axis ' parameter , for some of the cube operations , mainly ' margin ' . The user never sees the MR selections dimension , and treats all MRs as single dimensions . Thus we ...
if not self . _is_axis_allowed ( axis ) : ca_error_msg = "Direction {} not allowed (items dimension)" raise ValueError ( ca_error_msg . format ( axis ) ) if isinstance ( axis , int ) : # If single axis was provided , create a list out of it , so that # we can do the subsequent iteration . axis = list ( [ ax...
def scenario_risk ( riskinputs , riskmodel , param , monitor ) : """Core function for a scenario computation . : param riskinput : a of : class : ` openquake . risklib . riskinput . RiskInput ` object : param riskmodel : a : class : ` openquake . risklib . riskinput . CompositeRiskModel ` instance : param...
E = param [ 'E' ] L = len ( riskmodel . loss_types ) result = dict ( agg = numpy . zeros ( ( E , L ) , F32 ) , avg = [ ] , all_losses = AccumDict ( accum = { } ) ) for ri in riskinputs : for out in riskmodel . gen_outputs ( ri , monitor , param [ 'epspath' ] ) : r = out . rlzi weight = param [ 'weig...
def _pop_async_request ( self , msg_id , msg_name ) : """Pop the set of callbacks for a request . Return tuple of Nones if callbacks already popped ( or don ' t exist ) ."""
assert get_thread_ident ( ) == self . ioloop_thread_id if msg_id is None : msg_id = self . _msg_id_for_name ( msg_name ) if msg_id in self . _async_queue : callback_tuple = self . _async_queue [ msg_id ] del self . _async_queue [ msg_id ] self . _async_id_stack [ callback_tuple [ 0 ] . name ] . remove (...
def create ( self , table_id , schema ) : """Create a table in Google BigQuery given a table and schema Parameters table : str Name of table to be written schema : str Use the generate _ bq _ schema to generate your table schema from a dataframe ."""
from google . cloud . bigquery import SchemaField from google . cloud . bigquery import Table if self . exists ( table_id ) : raise TableCreationError ( "Table {0} already " "exists" . format ( table_id ) ) if not _Dataset ( self . project_id , credentials = self . credentials ) . exists ( self . dataset_id ) : ...
def kill ( timeout = 15 ) : '''Kill the salt minion . timeout int seconds to wait for the minion to die . If you have a monitor that restarts ` ` salt - minion ` ` when it dies then this is a great way to restart after a minion upgrade . CLI example : : > $ salt minion [ 12 ] minion . kill minion1: ...
ret = { 'killed' : None , 'retcode' : 1 , } comment = [ ] pid = __grains__ . get ( 'pid' ) if not pid : comment . append ( 'Unable to find "pid" in grains' ) ret [ 'retcode' ] = salt . defaults . exitcodes . EX_SOFTWARE else : if 'ps.kill_pid' not in __salt__ : comment . append ( 'Missing command: p...
def _check ( self , mode = None ) : """Check if TarFile is still open , and if the operation ' s mode corresponds to TarFile ' s mode ."""
if self . closed : raise IOError ( "%s is closed" % self . __class__ . __name__ ) if mode is not None and self . mode not in mode : raise IOError ( "bad operation for mode %r" % self . mode )
def verify_components ( components ) : """Verify values returned from : meth : ` make _ components ` . Used internally during the : meth : ` build ` process . : param components : value returned from : meth : ` make _ components ` : type components : : class : ` dict ` : raises ValueError : if verification ...
# verify returned type from user - defined function if not isinstance ( components , dict ) : raise ValueError ( "invalid type returned by make_components(): %r (must be a dict)" % components ) # check types for ( name , component ) pairs in dict for ( name , component ) in components . items ( ) : # name is a stri...
def errtrapz ( x , yerr ) : """Error of the trapezoid formula Inputs : x : the abscissa yerr : the error of the dependent variable Outputs : the error of the integral"""
x = np . array ( x ) assert isinstance ( x , np . ndarray ) yerr = np . array ( yerr ) return 0.5 * np . sqrt ( ( x [ 1 ] - x [ 0 ] ) ** 2 * yerr [ 0 ] ** 2 + np . sum ( ( x [ 2 : ] - x [ : - 2 ] ) ** 2 * yerr [ 1 : - 1 ] ** 2 ) + ( x [ - 1 ] - x [ - 2 ] ) ** 2 * yerr [ - 1 ] ** 2 )
def indent_xml ( elem , level = 0 , more_sibs = False ) : """Indent an xml element object to prepare for pretty printing . To avoid changing the contents of the original Element , it is recommended that a copy is made to send to this function . Args : elem : Element to indent . level : Int indent level ( ...
i = "\n" pad = " " if level : i += ( level - 1 ) * pad num_kids = len ( elem ) if num_kids : if not elem . text or not elem . text . strip ( ) : elem . text = i + pad if level : elem . text += pad count = 0 for kid in elem : if kid . tag == "data" : kid...
def make_http_credentials ( username = None , password = None ) : """Build auth part for api _ url ."""
credentials = '' if username is None : return credentials if username is not None : if ':' in username : return credentials credentials += username if credentials and password is not None : credentials += ":%s" % password return "%s@" % credentials
def configure_defaults ( ) : """This function is executed immediately after ROOT ' s finalSetup"""
log . debug ( "configure_defaults()" ) global initialized initialized = True if use_rootpy_handler : # Need to do it again here , since it is overridden by ROOT . set_error_handler ( python_logging_error_handler ) if os . environ . get ( 'ROOTPY_BATCH' , False ) or IN_NOSETESTS : ROOT . gROOT . SetBatch ( True ...
def stop ( self ) : """Stop the camera process ."""
if not self . _started : raise Exception ( "Cannot stop a video recorder before starting it!" ) self . _started = False if self . _actual_camera . is_running : self . _actual_camera . stop ( ) if self . _camera is not None : try : self . _camera . terminate ( ) except : pass
def wfdb_strptime ( time_string ) : """Given a time string in an acceptable wfdb format , return a datetime . time object . Valid formats : SS , MM : SS , HH : MM : SS , all with and without microsec ."""
n_colons = time_string . count ( ':' ) if n_colons == 0 : time_fmt = '%S' elif n_colons == 1 : time_fmt = '%M:%S' elif n_colons == 2 : time_fmt = '%H:%M:%S' if '.' in time_string : time_fmt += '.%f' return datetime . datetime . strptime ( time_string , time_fmt ) . time ( )
def _update_pods_metrics ( self , instance , pods ) : """Reports the number of running pods on this node , tagged by service and creator We go though all the pods , extract tags then count them by tag list , sorted and serialized in a pipe - separated string ( it is an illegar character for tags )"""
tags_map = defaultdict ( int ) for pod in pods [ 'items' ] : pod_meta = pod . get ( 'metadata' , { } ) pod_tags = self . kubeutil . get_pod_creator_tags ( pod_meta , legacy_rep_controller_tag = True ) services = self . kubeutil . match_services_for_pod ( pod_meta ) if isinstance ( services , list ) : ...
def table_dataset_database_table ( table = None , include_attributes = None , rows_limit = None , print_progress = False , ) : """Create a pyprel table contents list from a database table of the module dataset . Attributes to be included in the table can be specified ; by default , all attributes are included ....
if print_progress : import shijian progress = shijian . Progress ( ) progress . engage_quick_calculation_mode ( ) number_of_rows = len ( table ) if include_attributes : columns = include_attributes else : columns = table . columns table_contents = [ columns ] for index_row , row in enumerate ( t...
def _try_reconnect ( self ) : """Try to recover an interrupted connection ."""
try : if self . connection_interrupted : self . connect_direct ( self . connection_string , force = True ) self . connection_interrupted = False self . connected = True # Reenable streaming interface if that was open before as well if self . _reports is not None : ...
def _create_data_loader ( self , data , ** kwargs ) : """Converts input data into a DataLoader"""
if data is None : return None # Set DataLoader config # NOTE : Not applicable if data is already a DataLoader config = { ** self . config [ "train_config" ] [ "data_loader_config" ] , ** kwargs , "pin_memory" : self . config [ "device" ] != "cpu" , } # Return data as DataLoader if isinstance ( data , DataLoader ) :...
def verify_webhook ( signature , body ) : '''Verify the webhook signature from travisci signature The signature header from the webhook header body The full payload body from the webhook post . . note : : The body needs to be the urlencoded version of the body . CLI Example : . . code - block : : bash...
# get public key setup public_key = __utils__ [ 'http.query' ] ( 'https://api.travis-ci.org/config' ) [ 'config' ] [ 'notifications' ] [ 'webhook' ] [ 'public_key' ] pkey_public_key = OpenSSL . crypto . load_publickey ( OpenSSL . crypto . FILETYPE_PEM , public_key ) certificate = OpenSSL . crypto . X509 ( ) certificate...
def set_page_load_timeout ( self , time_to_wait ) : """Set the amount of time to wait for a page load to complete before throwing an error . : Args : - time _ to _ wait : The amount of time to wait : Usage : driver . set _ page _ load _ timeout ( 30)"""
try : self . execute ( Command . SET_TIMEOUTS , { 'pageLoad' : int ( float ( time_to_wait ) * 1000 ) } ) except WebDriverException : self . execute ( Command . SET_TIMEOUTS , { 'ms' : float ( time_to_wait ) * 1000 , 'type' : 'page load' } )
def getIds ( self , query = '*:*' , fq = None , start = 0 , rows = 1000 ) : """Returns a dictionary of : matches : number of matches failed : if true , then an exception was thrown start : starting index ids : [ id , id , . . . ] See also the SOLRSearchResponseIterator class"""
params = { 'q' : query , 'start' : str ( start ) , 'rows' : str ( rows ) , 'wt' : 'python' } if fq is not None : params [ 'fq' ] = fq request = urllib . parse . urlencode ( params , doseq = True ) data = None response = { 'matches' : 0 , 'start' : start , 'failed' : True , 'ids' : [ ] } try : rsp = self . doPos...
def makeadistu_inlets ( data , commdct ) : """make the dict adistu _ inlets"""
adistus = getadistus ( data , commdct ) # assume that the inlet node has the words " Air Inlet Node Name " airinletnode = "Air Inlet Node Name" adistu_inlets = { } for adistu in adistus : objkey = adistu . upper ( ) objindex = data . dtls . index ( objkey ) objcomm = commdct [ objindex ] airinlets = [ ]...
def _parse_in_batches ( cmd_array ) : """Find patterns that match to ` in _ batches _ pat ` and replace them into ` STDIN ` or ` TMPFILE ` . : param cmd _ array : ` shlex . split ` - ed command : rtype : ( [ cmd _ array ] , ( batch _ to _ file , batch _ to _ file , . . . ) ) : returns : Modified ` cmd _ array...
res_cmd_array = cmd_array [ : ] res_batch_to_file_s = [ ] in_batches_cmdidx = BatchCommand . _in_batches_cmdidx ( cmd_array ) for batch_id , cmdidx in enumerate ( in_batches_cmdidx ) : if cmdidx > 0 and cmd_array [ cmdidx - 1 ] == '<' : # e . g . ` < IN _ BATCH0 ` res_batch_to_file_s . append ( BatchToFile ...
def _check_type_and_load_cert ( self , msg , key_type , cert_type ) : """Perform message type - checking & optional certificate loading . This includes fast - forwarding cert ` ` msg ` ` objects past the nonce , so that the subsequent fields are the key numbers ; thus the caller may expect to treat the messag...
# Normalization ; most classes have a single key type and give a string , # but eg ECDSA is a 1 : N mapping . key_types = key_type cert_types = cert_type if isinstance ( key_type , string_types ) : key_types = [ key_types ] if isinstance ( cert_types , string_types ) : cert_types = [ cert_types ] # Can ' t do m...
def master ( cls , cluster_id_label ) : """Show the details of the master of the cluster with id / label ` cluster _ id _ label ` ."""
cluster_status = cls . status ( cluster_id_label ) if cluster_status . get ( "state" ) == 'UP' : return list ( filter ( lambda x : x [ "role" ] == "master" , cluster_status . get ( "nodes" ) ) ) [ 0 ] else : return cluster_status
def _mm ( n_items , data , initial_params , alpha , max_iter , tol , mm_fun ) : """Iteratively refine MM estimates until convergence . Raises RuntimeError If the algorithm does not converge after ` max _ iter ` iterations ."""
if initial_params is None : params = np . zeros ( n_items ) else : params = initial_params converged = NormOfDifferenceTest ( tol = tol , order = 1 ) for _ in range ( max_iter ) : nums , denoms = mm_fun ( n_items , data , params ) params = log_transform ( ( nums + alpha ) / ( denoms + alpha ) ) if c...
def com_google_fonts_check_family_equal_unicode_encodings ( ttFonts ) : """Fonts have equal unicode encodings ?"""
encoding = None failed = False for ttFont in ttFonts : cmap = None for table in ttFont [ 'cmap' ] . tables : if table . format == 4 : cmap = table break # Could a font lack a format 4 cmap table ? # If we ever find one of those , it would crash the check here . # Then...
def validate_union ( datum , schema , parent_ns = None , raise_errors = True ) : """Check that the data is a list type with possible options to validate as True . Parameters datum : Any Data being validated schema : dict Schema parent _ ns : str parent namespace raise _ errors : bool If true , r...
if isinstance ( datum , tuple ) : ( name , datum ) = datum for candidate in schema : if extract_record_type ( candidate ) == 'record' : if name == candidate [ "name" ] : return validate ( datum , schema = candidate , field = parent_ns , raise_errors = raise_errors ) else ...
def convertdistmethod ( method_str ) : """Convert distance method to h , v , p , and s ."""
if StringClass . string_match ( method_str , 'Horizontal' ) : return 'h' elif StringClass . string_match ( method_str , 'Vertical' ) : return 'v' elif StringClass . string_match ( method_str , 'Pythagoras' ) : return 'p' elif StringClass . string_match ( method_str , 'Surface' ) : return 's' elif method...
def zmq_version ( ) : '''ZeroMQ python bindings > = 2.1.9 are required'''
try : import zmq except Exception : # Return True for local mode return True ver = zmq . __version__ # The last matched group can be None if the version # is something like 3.1 and that will work properly match = re . match ( r'^(\d+)\.(\d+)(?:\.(\d+))?' , ver ) # Fallthrough and hope for the best if not match ...
def account_list ( self , wallet ) : """Lists all the accounts inside * * wallet * * : param wallet : Wallet to get account list for : type wallet : str : raises : : py : exc : ` nano . rpc . RPCException ` > > > rpc . account _ list ( . . . wallet = " 000D1BAEC8EC208142C99059B393051BAC8380F9B5A2E6B2489A2...
wallet = self . _process_value ( wallet , 'wallet' ) payload = { "wallet" : wallet } resp = self . call ( 'account_list' , payload ) return resp . get ( 'accounts' ) or [ ]
def snapped_speed_limits ( client , path ) : """Returns the posted speed limit ( in km / h ) for given road segments . The provided points will first be snapped to the most likely roads the vehicle was traveling along . : param path : The path of points to be snapped . : type path : a single location , or a...
params = { "path" : convert . location_list ( path ) } return client . _request ( "/v1/speedLimits" , params , base_url = _ROADS_BASE_URL , accepts_clientid = False , extract_body = _roads_extract )
def islice_extended ( iterable , * args ) : """An extension of : func : ` itertools . islice ` that supports negative values for * stop * , * start * , and * step * . > > > iterable = iter ( ' abcdefgh ' ) > > > list ( islice _ extended ( iterable , - 4 , - 1 ) ) [ ' e ' , ' f ' , ' g ' ] Slices with nega...
s = slice ( * args ) start = s . start stop = s . stop if s . step == 0 : raise ValueError ( 'step argument must be a non-zero integer or None.' ) step = s . step or 1 it = iter ( iterable ) if step > 0 : start = 0 if ( start is None ) else start if ( start < 0 ) : # Consume all but the last - start items ...
def _FormatIPCPermToken ( self , token_data ) : """Formats an IPC permissions token as a dictionary of values . Args : token _ data ( bsm _ token _ data _ ipc _ perm ) : AUT _ IPC _ PERM token data . Returns : dict [ str , str ] : token values ."""
return { 'user_id' : token_data . user_identifier , 'group_id' : token_data . group_identifier , 'creator_user_id' : token_data . creator_user_identifier , 'creator_group_id' : token_data . creator_group_identifier , 'access' : token_data . access_mode }
def resolve_path ( self , path , root_id = '0' , objects = False ) : '''Return id ( or metadata ) of an object , specified by chain ( iterable or fs - style path string ) of " name " attributes of it ' s ancestors , or raises DoesNotExists error . Requires a lot of calls to resolve each name in path , so use ...
if path : if isinstance ( path , types . StringTypes ) : path = filter ( None , path . split ( os . sep ) ) if path : try : for i , name in enumerate ( path ) : root_id = dict ( it . imap ( op . itemgetter ( 'name' , 'id' ) , ( yield self . listdir ( root_id ) ) ) ) [...
def _create_clone ( self , parent , part , ** kwargs ) : """Create a new ` Part ` clone under the ` Parent ` . . . versionadded : : 2.3 : param parent : parent part : type parent : : class : ` models . Part ` : param part : part to be cloned : type part : : class : ` models . Part ` : param kwargs : ( o...
if part . category == Category . MODEL : select_action = 'clone_model' else : select_action = 'clone_instance' data = { "part" : part . id , "parent" : parent . id , "suppress_kevents" : kwargs . pop ( 'suppress_kevents' , None ) } # prepare url query parameters query_params = kwargs query_params [ 'select_acti...
def trimmomatic_barplot ( self ) : """Make the HighCharts HTML to plot the trimmomatic rates"""
# Specify the order of the different possible categories keys = OrderedDict ( ) keys [ 'surviving' ] = { 'color' : '#437bb1' , 'name' : 'Surviving Reads' } keys [ 'both_surviving' ] = { 'color' : '#f7a35c' , 'name' : 'Both Surviving' } keys [ 'forward_only_surviving' ] = { 'color' : '#e63491' , 'name' : 'Forward Only S...
def issueQueingServiceJobs ( self ) : """Issues any queuing service jobs up to the limit of the maximum allowed ."""
while len ( self . serviceJobsToBeIssued ) > 0 and self . serviceJobsIssued < self . config . maxServiceJobs : self . issueJob ( self . serviceJobsToBeIssued . pop ( ) ) self . serviceJobsIssued += 1 while len ( self . preemptableServiceJobsToBeIssued ) > 0 and self . preemptableServiceJobsIssued < self . confi...
def inheritance_patch ( attrs ) : """Patch tango objects before they are processed by the metaclass ."""
for key , obj in attrs . items ( ) : if isinstance ( obj , attribute ) : if getattr ( obj , 'attr_write' , None ) == AttrWriteType . READ_WRITE : if not getattr ( obj , 'fset' , None ) : method_name = obj . write_method_name or "write_" + key obj . fset = attrs . ...
def get_alignment_summary_metrics ( self , barcode ) : """Parses the metrics in a $ { barcode } alignment _ summary _ metrics file in the DNAnexus project ( usually in the qc folder ) . This contains metrics produced by Picard Tools ' s CollectAlignmentSummaryMetrics program ."""
filename = barcode + ".alignment_summary_metrics" # In the call to dxpy . find _ one _ data _ object ( ) below , I ' d normally set the # more _ ok parameter to False , but this blows - up in Python 3.7 - giving me a RuntimeError . # So , I just won ' t set it for now . I think dxpy is still mainly a Python 2.7 library...
def clear ( self ) : """Clear and reset to orignal state"""
WhereQuery . clear ( self ) self . _table = None self . _parameters = [ ] self . _sql = None
def _handle_tag_defineshape4 ( self ) : """Handle the DefineShape4 tag ."""
obj = _make_object ( "DefineShape4" ) obj . ShapeId = unpack_ui16 ( self . _src ) obj . ShapeBounds = self . _get_struct_rect ( ) obj . EdgeBounds = self . _get_struct_rect ( ) bc = BitConsumer ( self . _src ) bc . u_get ( 5 ) # reserved obj . UsesFillWindingRule = bc . u_get ( 1 ) obj . UsesNonScalingStrokes = bc . u_...
def connect ( self , protocol = None , mode = None , disposition = None ) : """Connect to card . @ param protocol : a bit mask of the protocols to use , from L { CardConnection . T0 _ protocol } , L { CardConnection . T1 _ protocol } , L { CardConnection . RAW _ protocol } , L { CardConnection . T15 _ protoco...
Observable . setChanged ( self ) Observable . notifyObservers ( self , CardConnectionEvent ( 'connect' ) )
def commit_state_create ( self , nameop , current_block_number ) : """Commit a state - creation operation ( works for name _ registration , namespace _ reveal , name _ import ) . Returns the sequence of dicts of fields to serialize . DO NOT CALL THIS DIRECTLY"""
# have to have read - write disposition if self . disposition != DISPOSITION_RW : log . error ( "FATAL: borrowing violation: not a read-write connection" ) traceback . print_stack ( ) os . abort ( ) cur = self . db . cursor ( ) opcode = nameop . get ( 'opcode' , None ) try : assert state_create_is_valid...
def add_rect ( self , width , height , rid = None ) : """Add rectangle of widthxheight dimensions . Arguments : width ( int , float ) : Rectangle width height ( int , float ) : Rectangle height rid : Optional rectangle user id Returns : Rectangle : Rectangle with placemente coordinates None : If the r...
assert ( width > 0 and height > 0 ) # Search best position and orientation rect , _ = self . _select_position ( width , height ) if not rect : return None # Subdivide all the max rectangles intersecting with the selected # rectangle . self . _split ( rect ) # Remove any max _ rect contained by another self . _remov...
def draw_build_target ( self , surf ) : """Draw the build target ."""
round_half = lambda v , cond : round ( v - 0.5 ) + 0.5 if cond else round ( v ) queued_action = self . _queued_action if queued_action : radius = queued_action . footprint_radius if radius : pos = self . get_mouse_pos ( ) if pos : pos = point . Point ( round_half ( pos . world_pos . ...
def retrieve_old_notifications ( self ) : """Retrieve notifications older than X days , where X is specified in settings"""
date = ago ( days = DELETE_OLD ) return Notification . objects . filter ( added__lte = date )
def _process_content_streams ( * , pdf , container , shorthand = None ) : """Find all individual instances of images drawn in the container Usually the container is a page , but it may also be a Form XObject . On a typical page images are stored inline or as regular images in an XObject . Form XObjects may ...
if container . get ( '/Type' ) == '/Page' and '/Contents' in container : initial_shorthand = shorthand or UNIT_SQUARE elif container . get ( '/Type' ) == '/XObject' and container [ '/Subtype' ] == '/Form' : # Set the CTM to the state it was when the " Do " operator was # encountered that is drawing this instance of...
def getApplicationsTransitionStateNameFromEnum ( self , state ) : """Returns a string for an application transition state"""
fn = self . function_table . getApplicationsTransitionStateNameFromEnum result = fn ( state ) return result
def _ensure_panel_ids ( dashboard ) : '''Assign panels auto - incrementing IDs .'''
panel_id = 1 for row in dashboard . get ( 'rows' , [ ] ) : for panel in row . get ( 'panels' , [ ] ) : panel [ 'id' ] = panel_id panel_id += 1
def pop ( self , sexp ) : '''Notes : Sequence works a bit different than other nodes . This method ( like others ) expectes a list . However , sequence matches against the list , whereas other nodes try to match against elements of the list .'''
for t in self . terms : sexp = t . pop ( sexp ) return sexp
def get_relationship_query_session ( self , proxy = None ) : """Gets the ` ` OsidSession ` ` associated with the relationship query service . arg : proxy ( osid . proxy . Proxy ) : a proxy return : ( osid . relationship . RelationshipQuerySession ) - a ` ` RelationshipQuerySession ` ` raise : NullArgument -...
if not self . supports_relationship_query ( ) : raise Unimplemented ( ) try : from . import sessions except ImportError : raise OperationFailed ( ) proxy = self . _convert_proxy ( proxy ) try : session = sessions . RelationshipQuerySession ( proxy = proxy , runtime = self . _runtime ) except AttributeEr...
def select_by_name ( self , name ) : """shows a tab identified by the name"""
for a , li , holder in self . _tabs . values ( ) : if a . children [ 'text' ] == name : self . _on_tab_pressed ( a , li , holder ) return
def FloatProperty ( name , default = 0.0 , readonly = False , docs = None ) : ''': name : string - property name : default : float - property default value : readonly : boolean - if True , setter method is NOT generated Returns a property object that can be used to initialize a class instance variable as a ...
private_name = '_' + name def getf ( self ) : if not hasattr ( self , private_name ) : setattr ( self , private_name , default ) return getattr ( self , private_name ) if readonly : setf = None else : def setf ( self , newValue ) : def epsilon_set ( v ) : # epsilon _ set : creates a floa...
def build ( self , parent_step = None , force_sequence = None ) : """Build a factory instance ."""
# TODO : Handle " batch build " natively pre , post = parse_declarations ( self . extras , base_pre = self . factory_meta . pre_declarations , base_post = self . factory_meta . post_declarations , ) if force_sequence is not None : sequence = force_sequence elif self . force_init_sequence is not None : sequence ...
def _read_oem ( string ) : """Args : string ( str ) : String containing the OEM Return : Ephem :"""
ephems = [ ] required = ( 'REF_FRAME' , 'CENTER_NAME' , 'TIME_SYSTEM' , 'OBJECT_ID' , 'OBJECT_NAME' ) mode = None for line in string . splitlines ( ) : if not line or line . startswith ( "COMMENT" ) : # pragma : no cover continue elif line . startswith ( "META_START" ) : mode = "meta" ep...
def build_default_link ( self ) : '''Called when ' link ' is not defined in the settings'''
attrs = { } attrs [ "rel" ] = "stylesheet" attrs [ "href" ] = "{}?{:x}" . format ( os . path . join ( settings . STATIC_URL , self . filepath ) . replace ( os . path . sep , '/' ) , self . version_id , ) attrs . update ( self . options [ 'link_attrs' ] ) attrs [ "data-context" ] = self . provider_run . uid # can ' t be...
def translate ( self , tx , ty ) : """Applies a translation by : obj : ` tx ` , : obj : ` ty ` to the transformation in this matrix . The effect of the new transformation is to first translate the coordinates by : obj : ` tx ` and : obj : ` ty ` , then apply the original transformation to the coordinates . ...
cairo . cairo_matrix_translate ( self . _pointer , tx , ty )
def get_passphrase ( self , prompt = 'Passphrase:' ) : """Ask the user for passphrase ."""
passphrase = None if self . cached_passphrase_ack : passphrase = self . cached_passphrase_ack . get ( ) if passphrase is None : passphrase = interact ( title = '{} passphrase' . format ( self . device_name ) , prompt = prompt , description = None , binary = self . passphrase_entry_binary , options = self . opti...
def parse_variable_definition ( lexer : Lexer ) -> VariableDefinitionNode : """VariableDefinition : Variable : Type DefaultValue ? Directives [ Const ] ?"""
start = lexer . token return VariableDefinitionNode ( variable = parse_variable ( lexer ) , type = expect_token ( lexer , TokenKind . COLON ) and parse_type_reference ( lexer ) , default_value = parse_value_literal ( lexer , True ) if expect_optional_token ( lexer , TokenKind . EQUALS ) else None , directives = parse_d...
def find_applications_on_system ( ) : """Collect maya version from Autodesk PATH if exists , else try looking for custom executable paths from config file ."""
# First we collect maya versions from the Autodesk folder we presume # is addeed to the system environment " PATH " path_env = os . getenv ( 'PATH' ) . split ( os . pathsep ) versions = { } for each in path_env : path = Path ( os . path . expandvars ( each ) ) if not path . exists ( ) : continue if ...
def get_bank_ids_by_item ( self , item_id ) : """Gets the list of ` ` Bank ` ` ` ` Ids ` ` mapped to an ` ` Item ` ` . arg : item _ id ( osid . id . Id ) : ` ` Id ` ` of an ` ` Item ` ` return : ( osid . id . IdList ) - list of bank ` ` Ids ` ` raise : NotFound - ` ` item _ id ` ` is not found raise : NullA...
# Implemented from template for # osid . resource . ResourceBinSession . get _ bin _ ids _ by _ resource mgr = self . _get_provider_manager ( 'ASSESSMENT' , local = True ) lookup_session = mgr . get_item_lookup_session ( proxy = self . _proxy ) lookup_session . use_federated_bank_view ( ) item = lookup_session . get_it...
def _deck_from_smoothie ( self , smoothie_pos : Dict [ str , float ] ) -> Dict [ Axis , float ] : """Build a deck - abs position store from the smoothie ' s position This should take the smoothie style position { ' X ' : float , etc } and turn it into the position dict used here { Axis . X : float } in deck -...
with_enum = { Axis [ k ] : v for k , v in smoothie_pos . items ( ) } plunger_axes = { k : v for k , v in with_enum . items ( ) if k not in Axis . gantry_axes ( ) } right = ( with_enum [ Axis . X ] , with_enum [ Axis . Y ] , with_enum [ Axis . by_mount ( top_types . Mount . RIGHT ) ] ) # Tell apply _ transform to just d...
def set_authentication_predicate ( predicate , params = ( ) ) : """Assign a new authentication predicate to an RPC method . This is the most generic decorator used to implement authentication . Predicate is a standard function with the following signature : . . code : : python def my _ predicate ( request ,...
def wrapper ( rpc_method ) : if hasattr ( rpc_method , 'modernrpc_auth_predicates' ) : rpc_method . modernrpc_auth_predicates . append ( predicate ) rpc_method . modernrpc_auth_predicates_params . append ( params ) else : rpc_method . modernrpc_auth_predicates = [ predicate ] rpc...
def save ( self ) : """save PlayerRecord settings to disk"""
data = str . encode ( json . dumps ( self . simpleAttrs , indent = 4 , sort_keys = True ) ) with open ( self . filename , "wb" ) as f : f . write ( data )
def main ( ) : """Mainloop for the application"""
logging . basicConfig ( level = logging . INFO ) app = RunSnakeRunApp ( 0 ) app . MainLoop ( )
async def _runJob ( self , user , appt ) : '''Actually run the storm query , updating the appropriate statistics and results'''
count = 0 appt . isrunning = True appt . laststarttime = time . time ( ) appt . startcount += 1 await self . _storeAppt ( appt ) with s_provenance . claim ( 'cron' , iden = appt . iden ) : logger . info ( 'Agenda executing for iden=%s, user=%s, query={%s}' , appt . iden , user . name , appt . query ) starttime ...
def add_hypermedia ( self , obj ) : '''Adds HATEOAS links to the resource . Adds href link to self . Override in subclasses to include additional functionality'''
if hasattr ( self , 'pk' ) : obj [ '_links' ] = { 'self' : { 'href' : '{}{}/' . format ( self . get_resource_uri ( ) , obj [ self . pk ] ) } }
def reverse_ip ( self , domain = None , limit = None , ** kwargs ) : """Pass in a domain name ."""
return self . _results ( 'reverse-ip' , '/v1/{0}/reverse-ip' . format ( domain ) , limit = limit , ** kwargs )
def get_elements ( self , json_string , expr ) : """Get list of elements from _ json _ string _ , matching [ http : / / goessner . net / articles / JsonPath / | JSONPath ] expression . * Args : * \n _ json _ string _ - JSON string ; \n _ expr _ - JSONPath expression ; * Returns : * \n List of found elemen...
load_input_json = self . string_to_json ( json_string ) # parsing jsonpath jsonpath_expr = parse ( expr ) # list of returned elements value_list = [ ] for match in jsonpath_expr . find ( load_input_json ) : value_list . append ( match . value ) if not value_list : return None else : return value_list
def GetZoneGroupState ( self , * args , ** kwargs ) : """Overrides default handling to use the global shared zone group state cache , unless another cache is specified ."""
kwargs [ 'cache' ] = kwargs . get ( 'cache' , zone_group_state_shared_cache ) return self . send_command ( 'GetZoneGroupState' , * args , ** kwargs )
def post_save_update_cache ( sender , instance , created , raw , ** kwargs ) : """Update the cache when an instance is created or modified ."""
if raw : return name = sender . __name__ if name in cached_model_names : delay_cache = getattr ( instance , '_delay_cache' , False ) if not delay_cache : from . tasks import update_cache_for_instance update_cache_for_instance ( name , instance . pk , instance )
def create ( self , name , ** params ) : """Creates a new role . This function makes two roundtrips to the server , plus at most two more if the ` ` autologin ` ` field of : func : ` connect ` is set to ` ` True ` ` . : param name : Name for the role . : type name : ` ` string ` ` : param params : Addit...
if not isinstance ( name , six . string_types ) : raise ValueError ( "Invalid role name: %s" % str ( name ) ) name = name . lower ( ) self . post ( name = name , ** params ) # splunkd doesn ' t return the user in the POST response body , # so we have to make a second round trip to fetch it . response = self . get (...
def stats_for_satellite_image ( self , metaimage ) : """Retrieves statistics for the satellite image described by the provided metadata . This is currently only supported ' EVI ' and ' NDVI ' presets : param metaimage : the satellite image ' s metadata , in the form of a ` MetaImage ` subtype instance : type ...
if metaimage . preset != PresetEnum . EVI and metaimage . preset != PresetEnum . NDVI : raise ValueError ( "Unsupported image preset: should be EVI or NDVI" ) if metaimage . stats_url is None : raise ValueError ( "URL for image statistics is not defined" ) status , data = self . http_client . get_json ( metaima...
def create_unsigned_transaction ( cls , * , nonce : int , gas_price : int , gas : int , to : Address , value : int , data : bytes ) -> 'BaseUnsignedTransaction' : """Create an unsigned transaction ."""
raise NotImplementedError ( "Must be implemented by subclasses" )
def main ( args , stop = False ) : """Arguments parsing , etc . ."""
daemon = AMQPDaemon ( con_param = getConParams ( settings . RABBITMQ_ANTIVIRUS_VIRTUALHOST ) , queue = settings . RABBITMQ_ANTIVIRUS_INPUT_QUEUE , out_exch = settings . RABBITMQ_ANTIVIRUS_EXCHANGE , out_key = settings . RABBITMQ_ANTIVIRUS_OUTPUT_KEY , react_fn = reactToAMQPMessage , glob = globals ( ) # used in deseria...