signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def add_subprocess ( self , name , proc ) : """Adds a single subprocess to this process . : param string name : name of the subprocess : param proc : a Process object : type proc : : class : ` ~ climlab . process . process . Process ` : raises : : exc : ` ValueError ` if ` ` proc ` ` is not a process : ...
if isinstance ( proc , Process ) : self . subprocess . update ( { name : proc } ) self . has_process_type_list = False # Add subprocess diagnostics to parent # ( if there are no name conflicts ) for diagname , value in proc . diagnostics . items ( ) : # if not ( diagname in self . diagnostics or has...
def active ( self ) : """Return the currently active : class : ` ~ opentracing . Scope ` which can be used to access the currently active : attr : ` Scope . span ` . : return : the : class : ` ~ opentracing . Scope ` that is active , or ` ` None ` ` if not available ."""
task = self . _get_task ( ) if not task : return super ( AsyncioScopeManager , self ) . active return self . _get_task_scope ( task )
def is_required ( self , name ) : """Return true iff the schema element with the given name is required ."""
return self . schema_element ( name ) . repetition_type == parquet_thrift . FieldRepetitionType . REQUIRED
def create_from_user_input ( raw_properties , jamfile_module , location ) : """Creates a property - set from the input given by the user , in the context of ' jamfile - module ' at ' location '"""
assert is_iterable_typed ( raw_properties , basestring ) assert isinstance ( jamfile_module , basestring ) assert isinstance ( location , basestring ) properties = property . create_from_strings ( raw_properties , True ) properties = property . translate_paths ( properties , location ) properties = property . translate...
def get_parallel_regions_block ( batch ) : """CWL target to retrieve block group of callable regions for parallelization . Uses blocking to handle multicore runs ."""
samples = [ utils . to_single_data ( d ) for d in batch ] regions = _get_parallel_regions ( samples [ 0 ] ) out = [ ] # Currently don ' t have core information here so aim for about 10 items per partition n = 10 for region_block in tz . partition_all ( n , regions ) : out . append ( { "region_block" : [ "%s:%s-%s" ...
def _restart_target ( self ) : """Restart our Target ."""
if self . _server : if self . _server . returncode is None : self . _server . kill ( ) time . sleep ( 0.2 ) self . _server = subprocess . Popen ( "python session_server.py" , stdout = subprocess . PIPE , stderr = subprocess . PIPE , shell = True ) time . sleep ( 0.2 )
def fontsize ( count , maxsize , minsize , maxcount ) : '''A formula for determining font sizes .'''
size = int ( maxsize - ( maxsize ) * ( ( float ( maxcount - count ) / maxcount ) ) ) if size < minsize : size = minsize return size
def name ( self , node , children ) : 'name = ~ " [ a - z ] + " _'
return self . env . get ( node . text . strip ( ) , - 1 )
def add_rule ( name , localport , protocol = 'tcp' , action = 'allow' , dir = 'in' , remoteip = 'any' ) : '''Add a new inbound or outbound rule to the firewall policy Args : name ( str ) : The name of the rule . Must be unique and cannot be " all " . Required . localport ( int ) : The port the rule applies ...
ret = { 'name' : name , 'result' : True , 'changes' : { } , 'comment' : '' } # Check if rule exists if not __salt__ [ 'firewall.rule_exists' ] ( name ) : ret [ 'changes' ] = { 'new rule' : name } else : ret [ 'comment' ] = 'A rule with that name already exists' return ret if __opts__ [ 'test' ] : ret [ ...
def g_coil ( FlowPlant , IDTube , RadiusCoil , Temp ) : """We need a reference for this . Karen ' s thesis likely has this equation and the reference ."""
return ( g_straight ( FlowPlant , IDTube ) . magnitude * ( 1 + 0.033 * np . log10 ( dean_number ( FlowPlant , IDTube , RadiusCoil , Temp ) ) ** 4 ) ** ( 1 / 2 ) )
def create ( self , body , total_fee , auth_code , client_ip = None , out_trade_no = None , detail = None , attach = None , fee_type = 'CNY' , goods_tag = None , device_info = None , limit_pay = None ) : """刷卡支付接口 : param device _ info : 可选 , 终端设备号 ( 商户自定义 , 如门店编号 ) : param body : 商品描述 : param detail : 可选 , 商...
now = datetime . now ( ) if not out_trade_no : out_trade_no = '{0}{1}{2}' . format ( self . mch_id , now . strftime ( '%Y%m%d%H%M%S' ) , random . randint ( 1000 , 10000 ) ) data = { 'appid' : self . appid , 'device_info' : device_info , 'body' : body , 'detail' : detail , 'attach' : attach , 'out_trade_no' : out_tr...
def _es_margin ( settings ) : """Extract margin formating related subset of widget settings ."""
return { k : settings [ k ] for k in ( ConsoleWidget . SETTING_MARGIN , ConsoleWidget . SETTING_MARGIN_LEFT , ConsoleWidget . SETTING_MARGIN_RIGHT , ConsoleWidget . SETTING_MARGIN_CHAR ) }
def search_tor_node ( self , ip ) : """Lookup an IP address to check if it is a known tor exit node . : param ip : The IP address to lookup : type ip : str : return : Data relative to the tor node . If ` ip ` is a tor exit node it will contain a ` node ` key with the hash of the node and a ` last _ status...
data = { } tmp = { } present = datetime . utcnow ( ) . replace ( tzinfo = pytz . utc ) for line in self . _get_raw_data ( ) . splitlines ( ) : params = line . split ( ' ' ) if params [ 0 ] == 'ExitNode' : tmp [ 'node' ] = params [ 1 ] elif params [ 0 ] == 'ExitAddress' : tmp [ 'last_status' ...
def printJobChildren ( self ) : """Takes a list of jobs , and prints their successors ."""
for job in self . jobsToReport : children = "CHILDREN_OF_JOB:%s " % job for level , jobList in enumerate ( job . stack ) : for childJob in jobList : children += "\t(CHILD_JOB:%s,PRECEDENCE:%i)" % ( childJob , level ) print ( children )
def get ( self , sid ) : """Constructs a IncomingPhoneNumberContext : param sid : The unique string that identifies the resource : returns : twilio . rest . api . v2010 . account . incoming _ phone _ number . IncomingPhoneNumberContext : rtype : twilio . rest . api . v2010 . account . incoming _ phone _ numbe...
return IncomingPhoneNumberContext ( self . _version , account_sid = self . _solution [ 'account_sid' ] , sid = sid , )
def network_xml ( identifier , xml , address = None ) : """Fills the XML file with the required fields . * name * uuid * bridge * ip * * dhcp"""
netname = identifier [ : 8 ] network = etree . fromstring ( xml ) subelement ( network , './/name' , 'name' , identifier ) subelement ( network , './/uuid' , 'uuid' , identifier ) subelement ( network , './/bridge' , 'bridge' , None , name = 'virbr-%s' % netname ) if address is not None : set_address ( network , ad...
def _add_or_remove_flag ( self , flag , add ) : """Add the given ` flag ` if ` add ` is True , remove it otherwise ."""
meth = self . add_flag if add else self . remove_flag meth ( flag )
def getcol ( self , columnname , startrow = 0 , nrow = - 1 , rowincr = 1 ) : """Get the contents of a column or part of it . It is returned as a numpy array . If the column contains arrays , they should all have the same shape . An exception is thrown if they differ in shape . In that case the method : func...
# try : # trial code to read using a vector of rownrs # nr = len ( startrow ) # if nrow < 0: # nrow = nr # if nrow = = 0: # return numpy . array ( ) # for inx in range ( nrow ) : # i = inx * # except : return self . _getcol ( columnname , startrow , nrow , rowincr )
def generate_return_periods ( qout_file , return_period_file , num_cpus = multiprocessing . cpu_count ( ) , storm_duration_days = 7 , method = 'weibull' ) : """Generate return period from RAPID Qout file"""
# get ERA Interim Data Analyzed with RAPIDDataset ( qout_file ) as qout_nc_file : print ( "Setting up Return Periods File ..." ) return_period_nc = Dataset ( return_period_file , 'w' ) return_period_nc . createDimension ( 'rivid' , qout_nc_file . size_river_id ) timeSeries_var = return_period_nc . creat...
def generate_iucv_authfile ( fn , client ) : """Generate the iucv _ authorized _ userid file"""
lines = [ '#!/bin/bash\n' , 'echo -n %s > /etc/iucv_authorized_userid\n' % client ] with open ( fn , 'w' ) as f : f . writelines ( lines )
def plotPlainImg ( sim , cam , rawdata , t , odir ) : """No subplots , just a plan http : / / stackoverflow . com / questions / 22408237 / named - colors - in - matplotlib"""
for R , C in zip ( rawdata , cam ) : fg = figure ( ) ax = fg . gca ( ) ax . set_axis_off ( ) # no ticks ax . imshow ( R [ t , : , : ] , origin = 'lower' , vmin = max ( C . clim [ 0 ] , 1 ) , vmax = C . clim [ 1 ] , cmap = 'gray' ) ax . text ( 0.05 , 0.075 , datetime . utcfromtimestamp ( C . tKeo...
def add_partitioning_metadata ( portal ) : """Add metadata columns required for partitioning machinery"""
logger . info ( "Adding partitioning metadata" ) add_metadata ( portal , CATALOG_ANALYSIS_REQUEST_LISTING , 'getRawParentAnalysisRequest' ) add_metadata ( portal , CATALOG_ANALYSIS_REQUEST_LISTING , "getDescendantsUIDs" )
def add_file_argument ( self , * args , mode = 'r' , buffering = 1 , filetype_options = None , ** kwargs ) : """Add a tab - completion safe FileType argument . This argument differs from a normal argparse . FileType based argument in that the value is a factory function that returns a file handle instead of p...
type_ = supplement . SafeFileType ( mode = mode , bufsize = buffering , ** filetype_options or { } ) return self . add_argument ( * args , type = type_ , ** kwargs )
def scan_ip84 ( self , region = 'mainland' , page = 1 ) : """Scan candidate proxies from http : / / ip84 . com Args : region : Either ' mainland ' or ' overseas ' . page : An integer indicating how many pages to be scanned ."""
self . logger . info ( 'start scanning http://ip84.com for proxy list...' ) for i in range ( 1 , page + 1 ) : if region == 'mainland' : url = 'http://ip84.com/dlgn/{}' . format ( i ) elif region == 'overseas' : url = 'http://ip84.com/gwgn/{}' . format ( i ) else : url = 'http://ip84....
def get_path_fields ( self , path , method , view ) : """Return a list of ` coreapi . Field ` instances corresponding to any templated path variables ."""
model = getattr ( getattr ( view , 'queryset' , None ) , 'model' , None ) fields = [ ] for variable in uritemplate . variables ( path ) : if variable == 'version' : continue title = '' description = '' schema_cls = coreschema . String kwargs = { } if model is not None : # Attempt to infe...
def set_noise_filter ( self , user_gpio , steady , active ) : """Sets a noise filter on a GPIO . Level changes on the GPIO are ignored until a level which has been stable for [ * steady * ] microseconds is detected . Level changes on the GPIO are then reported for [ * active * ] microseconds after which the...
# pigpio message format # I p1 user _ gpio # I p2 steady # I p3 4 # # extension # # # I active extents = [ struct . pack ( "I" , active ) ] res = yield from self . _pigpio_aio_command_ext ( _PI_CMD_FN , user_gpio , steady , 4 , extents ) return _u2i ( res )
def from_json ( cls , json ) : """Inherit doc ."""
key_range_iter_cls = _KEY_RANGE_ITERATORS [ json [ "key_range_iter_cls" ] ] obj = cls ( key_ranges . KeyRangesFactory . from_json ( json [ "key_ranges" ] ) , model . QuerySpec . from_json ( json [ "query_spec" ] ) , key_range_iter_cls ) current_iter = None if json [ "current_iter" ] : current_iter = key_range_iter_...
def add ( self , payload = None ) : """Adds a new document to the data store and returns its id . Args : payload ( dict ) : Dictionary of initial data that should be stored in the new document in the meta section . Raises : DataStoreNotConnected : If the data store is not connected to the server . Retur...
try : db = self . _client [ self . database ] col = db [ WORKFLOW_DATA_COLLECTION_NAME ] return str ( col . insert_one ( { DataStoreDocumentSection . Meta : payload if isinstance ( payload , dict ) else { } , DataStoreDocumentSection . Data : { } } ) . inserted_id ) except ConnectionFailure : raise Data...
def mk_tmpl ( self , path , tmpl , ctx , mode = None ) : """Create a file from a template if it doesn ' t already exist ."""
path = os . path . abspath ( path ) if os . path . isfile ( path ) : logger . warning ( "File %s already exists, not creating it." , tmpl ) with open ( path , 'w' ) as fd : fd . write ( tmpl . format ( ** ctx ) ) if mode : os . chmod ( path , mode )
def SetMaxPowerUpCurrent ( self , i ) : """Set the max power up current ."""
if i < 0 or i > 8 : raise MonsoonError ( ( "Target max current %sA, is out of acceptable " "range [0, 8]." ) % i ) val = 1023 - int ( ( i / 8 ) * 1023 ) self . _SendStruct ( "BBB" , 0x01 , 0x08 , val & 0xff ) self . _SendStruct ( "BBB" , 0x01 , 0x09 , val >> 8 )
def register_from_options ( options = None , template = None , extractor = None ) : """Register the spec codec using the provided options"""
if template is None : from noseOfYeti . plugins . support . spec_options import spec_options as template if extractor is None : from noseOfYeti . plugins . support . spec_options import extract_options_dict as extractor config = Config ( template ) config . setup ( options , extractor ) imports = determine_impo...
def locate_unlinked ( gn , size = 100 , step = 20 , threshold = .1 , blen = None ) : """Locate variants in approximate linkage equilibrium , where r * * 2 is below the given ` threshold ` . Parameters gn : array _ like , int8 , shape ( n _ variants , n _ samples ) Diploid genotypes at biallelic variants , c...
# check inputs if not hasattr ( gn , 'shape' ) or not hasattr ( gn , 'dtype' ) : gn = np . asarray ( gn , dtype = 'i1' ) if gn . ndim != 2 : raise ValueError ( 'gn must have two dimensions' ) # setup output loc = np . ones ( gn . shape [ 0 ] , dtype = 'u1' ) # compute in chunks to avoid loading big arrays into ...
def strip_praw_subscription ( subscription ) : """Parse through a subscription and return a dict with data ready to be displayed through the terminal ."""
data = { } data [ 'object' ] = subscription if isinstance ( subscription , praw . objects . Multireddit ) : data [ 'type' ] = 'Multireddit' data [ 'name' ] = subscription . path data [ 'title' ] = subscription . description_md else : data [ 'type' ] = 'Subscription' data [ 'name' ] = "/r/" + subscri...
def _handleBackspace ( self ) : """Handles backspace characters"""
if self . cursorPos > 0 : # print ( ' cp : ' , self . cursorPos , ' was : ' , self . inputBuffer ) self . inputBuffer = self . inputBuffer [ 0 : self . cursorPos - 1 ] + self . inputBuffer [ self . cursorPos : ] self . cursorPos -= 1 # print ( ' cp : ' , self . cursorPos , ' is : ' , self . inputBuffer ) ...
def is_signature_line ( line , sender , classifier ) : '''Checks if the line belongs to signature . Returns True or False .'''
data = numpy . array ( build_pattern ( line , features ( sender ) ) ) . reshape ( 1 , - 1 ) return classifier . predict ( data ) > 0
def validate_record_type ( self , cls ) : """Validate given record is acceptable . > > > s = teststore ( ) > > > s . validate _ record _ type ( ' tstoretest ' ) > > > s . validate _ record _ type ( ' bad ' ) Traceback ( most recent call last ) : ValueError : Unsupported record type " bad " """
if self . record_types and cls not in self . record_types : raise ValueError ( 'Unsupported record type "' + cls + '"' )
def imageurl ( self ) : """Return the URL of a png image of the 2D structure"""
if self . _imageurl is None : self . _imageurl = 'http://www.chemspider.com/ImagesHandler.ashx?id=%s' % self . csid return self . _imageurl
def P_conditional ( self , i , li , j , lj , y ) : """Compute the conditional probability P _ \t heta ( li | lj , y ) Z ^ { - 1 } exp ( theta _ { i | y } \ indpm { \ lambda _ i = Y } + \t heta _ { i , j } \ indpm { \ lambda _ i = \ lambda _ j } In other words , compute the conditional probability that LF ...
Z = np . sum ( [ self . _P ( i , _li , j , lj , y ) for _li in range ( self . k + 1 ) ] ) return self . _P ( i , li , j , lj , y ) / Z
def SetDecodedStreamSize ( self , decoded_stream_size ) : """Sets the decoded stream size . This function is used to set the decoded stream size if it can be determined separately . Args : decoded _ stream _ size ( int ) : size of the decoded stream in bytes . Raises : IOError : if the file - like objec...
if self . _is_open : raise IOError ( 'Already open.' ) if decoded_stream_size < 0 : raise ValueError ( ( 'Invalid decoded stream size: {0:d} value out of ' 'bounds.' ) . format ( decoded_stream_size ) ) self . _decoded_stream_size = decoded_stream_size
def key_hash_algo ( self , value ) : """A unicode string of the hash algorithm to use when creating the certificate identifier - " sha1 " ( default ) , or " sha256 " ."""
if value not in set ( [ 'sha1' , 'sha256' ] ) : raise ValueError ( _pretty_message ( ''' hash_algo must be one of "sha1", "sha256", not %s ''' , repr ( value ) ) ) self . _key_hash_algo = value
def system ( session ) : """Run the system test suite ."""
# Sanity check : Only run system tests if the environment variable is set . if not os . environ . get ( 'GOOGLE_APPLICATION_CREDENTIALS' , '' ) : session . skip ( 'Credentials must be set via environment variable.' ) # Use pre - release gRPC for system tests . session . install ( '--pre' , 'grpcio' ) # Install all ...
def formdata_post ( url , fields ) : """Send an HTTP request with a multipart / form - data body for the given URL and return the data returned by the server ."""
content_type , data = formdata_encode ( fields ) req = urllib2 . Request ( url , data ) req . add_header ( 'Content-Type' , content_type ) return urllib2 . urlopen ( req ) . read ( )
def replace_emoticons ( content , excluded_markups ) : """Replace the emoticons string by HTML images . If some markups should be excluded from replacement , BeautifulSoup will be used ."""
if not excluded_markups : return regexp_replace_emoticons ( content ) excluded_markups = excluded_markups . split ( ',' ) + [ '[document]' ] soup = BeautifulSoup ( content , 'html.parser' ) for content_string in list ( soup . strings ) : if content_string . parent . name not in excluded_markups : replac...
def _merge_list_of_dict ( first , second , prepend = True ) : '''Merge lists of dictionaries . Each element of the list is a dictionary having one single key . That key is then used as unique lookup . The first element list has higher priority than the second . When there ' s an overlap between the two list...
first = _cleanup ( first ) second = _cleanup ( second ) if not first and not second : return [ ] if not first and second : return second if first and not second : return first # Determine overlaps # So we dont change the position of the existing terms / filters overlaps = [ ] merged = [ ] appended = [ ] for...
def install_key ( self , key_data ) : """Install untrusted repo signing key"""
logger . info ( ( "importing repository signing key {0} " "{1}" . format ( self . key_info [ 'fingerprint' ] , self . key_info [ 'uids' ] [ 0 ] ) ) ) import_result = self . gpg . import_keys ( key_data ) logger . debug ( "import results: {0}" . format ( import_result . results ) )
def iter_search_nodes ( self , ** conditions ) : """Search nodes in an interative way . Matches are being yield as they are being found . This avoids to scan the full tree topology before returning the first matches . Useful when dealing with huge trees ."""
for n in self . traverse ( ) : conditions_passed = 0 for key , value in six . iteritems ( conditions ) : if hasattr ( n , key ) and getattr ( n , key ) == value : conditions_passed += 1 if conditions_passed == len ( conditions ) : yield n
def predict ( self , X ) : """Predict values using the model Parameters X : { array - like , sparse matrix } of shape [ n _ samples , n _ features ] Returns C : numpy array of shape [ n _ samples , n _ outputs ] Predicted values ."""
if self . _genelm_regressor is None : raise ValueError ( "SimpleELMRegressor not fitted" ) return self . _genelm_regressor . predict ( X )
def extend ( self , content , zorder ) : """Extends with a list and a z - order"""
if zorder not in self . _content : self . _content [ zorder ] = [ ] self . _content [ zorder ] . extend ( content )
def _cache_metrics_metadata ( self , instance ) : """Get all the performance counters metadata meaning name / group / description . . . from the server instance , attached with the corresponding ID"""
# # # < TEST - INSTRUMENTATION > t = Timer ( ) # # # < / TEST - INSTRUMENTATION > i_key = self . _instance_key ( instance ) self . metadata_cache . init_instance ( i_key ) self . log . info ( "Warming metrics metadata cache for instance {}" . format ( i_key ) ) server_instance = self . _get_server_instance ( instance )...
def copyfileobj ( src , dst , length = None , exception = OSError ) : """Copy length bytes from fileobj src to fileobj dst . If length is None , copy the entire content ."""
if length == 0 : return if length is None : shutil . copyfileobj ( src , dst ) return # BUFSIZE = 16 * 1024 blocks , remainder = divmod ( length , BUFSIZE ) # for b in range ( blocks ) : for _ in range ( blocks ) : buf = src . read ( BUFSIZE ) if len ( buf ) < BUFSIZE : raise exception ( "un...
def present ( name , auth = None , ** kwargs ) : '''Ensure an role exists name Name of the role description An arbitrary description of the role'''
ret = { 'name' : name , 'changes' : { } , 'result' : True , 'comment' : '' } kwargs = __utils__ [ 'args.clean_kwargs' ] ( ** kwargs ) __salt__ [ 'keystoneng.setup_clouds' ] ( auth ) kwargs [ 'name' ] = name role = __salt__ [ 'keystoneng.role_get' ] ( ** kwargs ) if not role : if __opts__ [ 'test' ] is True : ...
def read_i2c_block_data ( self , i2c_addr , register , length , force = None ) : """Read a block of byte data from a given register . : param i2c _ addr : i2c address : type i2c _ addr : int : param register : Start register : type register : int : param length : Desired block length : type length : int...
if length > I2C_SMBUS_BLOCK_MAX : raise ValueError ( "Desired block length over %d bytes" % I2C_SMBUS_BLOCK_MAX ) self . _set_address ( i2c_addr , force = force ) msg = i2c_smbus_ioctl_data . create ( read_write = I2C_SMBUS_READ , command = register , size = I2C_SMBUS_I2C_BLOCK_DATA ) msg . data . contents . byte =...
def WriteArtifact ( self , artifact ) : """Writes new artifact to the database ."""
name = str ( artifact . name ) if name in self . artifacts : raise db . DuplicatedArtifactError ( name ) self . artifacts [ name ] = artifact . Copy ( )
def _create_series ( ndschan , value , start , end , series_class = TimeSeries ) : """Create a timeseries to cover the specified [ start , end ) limits To cover a gap in data returned from NDS"""
channel = Channel . from_nds2 ( ndschan ) nsamp = int ( ( end - start ) * channel . sample_rate . value ) return series_class ( numpy_ones ( nsamp ) * value , t0 = start , sample_rate = channel . sample_rate , unit = channel . unit , channel = channel )
def to_etree ( source , root_tag = None ) : """Convert various representations of an XML structure to a etree Element Args : source - - The source object to be converted - ET . Element \ ElementTree , dict or string . Keyword args : root _ tag - - A optional parent tag in which to wrap the xml tree if no ro...
if hasattr ( source , 'get_root' ) : # XXX : return source . get_root ( ) elif isinstance ( source , type ( ET . Element ( 'x' ) ) ) : # XXX : # cElementTree . Element isn ' t exposed directly return source elif isinstance ( source , basestring ) : try : return ET . fromstring ( source ) except ...
def get_delta_TR ( tail_check_max , y_int ) : """input : tail _ check _ max , y _ intercept output : delta _ TR"""
if tail_check_max == 0 or numpy . isnan ( tail_check_max ) : return float ( 'nan' ) delta_TR = ( old_div ( tail_check_max , abs ( y_int ) ) ) * 100. return delta_TR
def update ( self , ** kwargs ) : """Update a resource by passing in modifications via keyword arguments ."""
data = self . _generate_input_dict ( ** kwargs ) self . load ( self . client . put ( '/' . join ( self . url . split ( '/' ) [ : - 1 ] ) + 's' , data = data ) ) return self
def state ( self , state ) : """Update the status of a build"""
state = state . lower ( ) if state not in valid_states : raise ValueError ( "Build state must have a value from:\n{}" . format ( ", " . join ( valid_state ) ) ) self . obj [ 'state' ] = state self . changes . append ( "Updating build:{}.state={}" . format ( self . obj [ 'name' ] , state ) ) return self
def canonical_fix_name ( fix , avail_fixes ) : """Examples : > > > canonical _ fix _ name ( ' fix _ wrap _ text _ literals ' ) ' libfuturize . fixes . fix _ wrap _ text _ literals ' > > > canonical _ fix _ name ( ' wrap _ text _ literals ' ) ' libfuturize . fixes . fix _ wrap _ text _ literals ' > > > can...
if ".fix_" in fix : return fix else : if fix . startswith ( 'fix_' ) : fix = fix [ 4 : ] # Infer the full module name for the fixer . # First ensure that no names clash ( e . g . # lib2to3 . fixes . fix _ blah and libfuturize . fixes . fix _ blah ) : found = [ f for f in avail_fixes if f...
def _maybe_convert_usecols ( usecols ) : """Convert ` usecols ` into a compatible format for parsing in ` parsers . py ` . Parameters usecols : object The use - columns object to potentially convert . Returns converted : object The compatible format of ` usecols ` ."""
if usecols is None : return usecols if is_integer ( usecols ) : warnings . warn ( ( "Passing in an integer for `usecols` has been " "deprecated. Please pass in a list of int from " "0 to `usecols` inclusive instead." ) , FutureWarning , stacklevel = 2 ) return lrange ( usecols + 1 ) if isinstance ( usecols ...
def get ( self , blueprint , user = None , user_id = None ) : """When you have a statement in your code that says " if < provider > . authorized : " ( for example " if twitter . authorized : " ) , a long string of function calls result in this function being used to check the Flask server ' s cache and databa...
# check cache cache_key = self . make_cache_key ( blueprint = blueprint , user = user , user_id = user_id ) token = self . cache . get ( cache_key ) if token : return token # if not cached , make database queries query = self . session . query ( self . model ) . filter_by ( provider = blueprint . name ) uid = first...
def download_setuptools ( version = DEFAULT_VERSION , download_base = DEFAULT_URL , to_dir = os . curdir , delay = 15 ) : """Download distribute from a specified location and return its filename ` version ` should be a valid distribute version number that is available as an egg for download under the ` download...
# making sure we use the absolute path to_dir = os . path . abspath ( to_dir ) try : from urllib . request import urlopen except ImportError : from urllib2 import urlopen tgz_name = "distribute-%s.tar.gz" % version url = download_base + tgz_name saveto = os . path . join ( to_dir , tgz_name ) src = dst = None i...
def _list_nodes ( full = False , for_output = False ) : '''Helper function to format and parse node data .'''
fetch = True page = 1 ret = { } while fetch : items = query ( method = 'droplets' , command = '?page=' + six . text_type ( page ) + '&per_page=200' ) for node in items [ 'droplets' ] : name = node [ 'name' ] ret [ name ] = { } if full : ret [ name ] = _get_full_output ( node ...
def sample_rate ( self ) : """0 means unknown"""
if self . sbrPresentFlag == 1 : return self . extensionSamplingFrequency elif self . sbrPresentFlag == 0 : return self . samplingFrequency else : # these are all types that support SBR aot_can_sbr = ( 1 , 2 , 3 , 4 , 6 , 17 , 19 , 20 , 22 ) if self . audioObjectType not in aot_can_sbr : return s...
def release_value_set ( self ) : """Release a reserved value set so that other executions can use it also ."""
if self . _remotelib : self . _remotelib . run_keyword ( 'release_value_set' , [ self . _my_id ] , { } ) else : _PabotLib . release_value_set ( self , self . _my_id )
def filter_published ( self , queryset ) : """Filter the given pages : class : ` QuerySet ` to obtain only published page ."""
if settings . PAGE_USE_SITE_ID : queryset = queryset . filter ( sites = global_settings . SITE_ID ) queryset = queryset . filter ( status = self . model . PUBLISHED ) if settings . PAGE_SHOW_START_DATE : queryset = queryset . filter ( publication_date__lte = get_now ( ) ) if settings . PAGE_SHOW_END_DATE : ...
def load_obj ( fn ) : """Load 3d mesh form . obj ' file . Args : fn : Input file name or file - like object . Returns : dictionary with the following keys ( some of which may be missing ) : position : np . float32 , ( n , 3 ) array , vertex positions uv : np . float32 , ( n , 2 ) array , vertex uv coord...
position = [ np . zeros ( 3 , dtype = np . float32 ) ] normal = [ np . zeros ( 3 , dtype = np . float32 ) ] uv = [ np . zeros ( 2 , dtype = np . float32 ) ] tuple2idx = OrderedDict ( ) trinagle_indices = [ ] input_file = open ( fn ) if isinstance ( fn , str ) else fn for line in input_file : line = line . strip ( )...
def get_cpu_info ( self ) : """Retrieves CPU info from client"""
info = snap7 . snap7types . S7CpuInfo ( ) result = self . library . Cli_GetCpuInfo ( self . pointer , byref ( info ) ) check_error ( result , context = "client" ) return info
def autozoom ( self , points ) : '''Fit the current view to the correct zoom level to display all * points * . The camera viewing direction and rotation pivot match the geometric center of the points and the distance from that point is calculated in order for all points to be in the field of view . This i...
points = np . asarray ( points ) extraoff = 0.01 # Project points on the plane defined by camera up and right # vector . This is achieved by using dot product on camera a # and b vectors abc = np . array ( [ self . a , self . b , self . c ] ) old_geom_center = points . sum ( axis = 0 ) / len ( points ) # Translate poin...
def request_callback_answer ( self , chat_id : Union [ int , str ] , message_id : int , callback_data : bytes ) : """Use this method to request a callback answer from bots . This is the equivalent of clicking an inline button containing callback data . Args : chat _ id ( ` ` int ` ` | ` ` str ` ` ) : Unique...
return self . send ( functions . messages . GetBotCallbackAnswer ( peer = self . resolve_peer ( chat_id ) , msg_id = message_id , data = callback_data ) , retries = 0 , timeout = 10 )
def foldx_dir ( self ) : """str : FoldX folder"""
if self . root_dir : return op . join ( self . root_dir , self . _foldx_dirname ) else : log . warning ( 'Root directory not set' ) return None
def change_host_modattr ( self , host , value ) : """Change host modified attributes Format of the line that triggers function call : : CHANGE _ HOST _ MODATTR ; < host _ name > ; < value > For boolean attributes , toggles the service attribute state ( enable / disable ) For non boolean attribute , only ind...
# todo : deprecate this # We need to change each of the needed attributes . previous_value = host . modified_attributes changes = int ( value ) # For all boolean and non boolean attributes for modattr in [ "MODATTR_NOTIFICATIONS_ENABLED" , "MODATTR_ACTIVE_CHECKS_ENABLED" , "MODATTR_PASSIVE_CHECKS_ENABLED" , "MODATTR_EV...
def create ( index_name , body , force , verbose ) : """Create a new index ."""
result = current_search_client . indices . create ( index = index_name , body = json . load ( body ) , ignore = [ 400 ] if force else None , ) if verbose : click . echo ( json . dumps ( result ) )
def remove_domain_user_role ( request , user , role , domain = None ) : """Removes a given single role for a user from a domain ."""
manager = keystoneclient ( request , admin = True ) . roles return manager . revoke ( role , user = user , domain = domain )
def get_set ( self , flag , new ) : """Return the boolean value of ' flag ' . If ' new ' is set , the flag is updated , and the value before update is returned ."""
old = self . _is_set ( flag ) if new is True : self . _set ( flag ) elif new is False : self . _clear ( flag ) return old
def ipostorder ( self ) : '''Depth - first post - order iteration of tree nodes'''
children = [ self , ] seen = set ( ) while children : cur_node = children [ - 1 ] if cur_node not in seen : seen . add ( cur_node ) children . extend ( reversed ( cur_node . children ) ) else : children . pop ( ) yield cur_node
def _create_server ( host , port ) : """Helper function . Creates a listening socket on the designated host and port . Modeled on the socket . create _ connection ( ) function ."""
exc = socket . error ( "getaddrinfo returns an empty list" ) for res in socket . getaddrinfo ( host , port , 0 , socket . SOCK_STREAM ) : af , socktype , proto , canonname , sa = res sock = None try : # Create the listening socket sock = socket . socket ( af , socktype , proto ) sock . setso...
def model_changed ( self , model , prop_name , info ) : """This method notifies the parent state about changes made to the state element"""
if self . parent is not None : self . parent . model_changed ( model , prop_name , info )
def get_object ( brain_or_object ) : """Get the full content object : param brain _ or _ object : A single catalog brain or content object : type brain _ or _ object : PortalObject / ATContentType / DexterityContentType / CatalogBrain : returns : The full object"""
if not is_object ( brain_or_object ) : fail ( "{} is not supported." . format ( repr ( brain_or_object ) ) ) if is_brain ( brain_or_object ) : return brain_or_object . getObject ( ) return brain_or_object
def addChild ( self , item ) : """When you add a child to a Node , you are adding yourself as a parent to the child You cannot have the same node as a child more than once . If you add a Node , it is used . If you add a non - node , a new child Node is created . Thus : You cannot add a child as an item which ...
if not isinstance ( item , Node ) : item = Node ( item ) if item in self . children : return item self . children . append ( item ) item . parents . add ( self ) return item
def location ( args ) : """% prog location bedfile fastafile Given SNP locations , summarize the locations in the sequences . For example , find out if there are more 3 ` - SNPs than 5 ` - SNPs ."""
from jcvi . formats . bed import BedLine from jcvi . graphics . histogram import stem_leaf_plot p = OptionParser ( location . __doc__ ) p . add_option ( "--dist" , default = 100 , type = "int" , help = "Distance cutoff to call 5` and 3` [default: %default]" ) opts , args = p . parse_args ( args ) if len ( args ) != 2 :...
def match_hail_size_step_distributions ( self , model_tracks , obs_tracks , track_pairings ) : """Given a matching set of observed tracks for each model track , Args : model _ tracks : obs _ tracks : track _ pairings : Returns :"""
label_columns = [ "Matched" , "Max_Hail_Size" , "Num_Matches" , "Shape" , "Location" , "Scale" ] s = 0 for m , model_track in enumerate ( model_tracks ) : model_track . observations = pd . DataFrame ( index = model_track . times , columns = label_columns , dtype = np . float64 ) model_track . observations . loc...
def start_serving ( self , delegate : httputil . HTTPServerConnectionDelegate ) -> None : """Starts serving requests on this connection . : arg delegate : a ` . HTTPServerConnectionDelegate `"""
assert isinstance ( delegate , httputil . HTTPServerConnectionDelegate ) fut = gen . convert_yielded ( self . _server_request_loop ( delegate ) ) self . _serving_future = fut # Register the future on the IOLoop so its errors get logged . self . stream . io_loop . add_future ( fut , lambda f : f . result ( ) )
def cudnnGetFilter4dDescriptor ( wDesc ) : """Get parameters of filter descriptor . This function queries the parameters of the previouly initialized filter descriptor object . Parameters wDesc : cudnnFilterDescriptor Handle to a previously created filter descriptor . Returns dataType : cudnnDataType ...
dataType = ctypes . c_int ( ) format = ctypes . c_int ( ) k = ctypes . c_int ( ) c = ctypes . c_int ( ) h = ctypes . c_int ( ) w = ctypes . c_int ( ) status = _libcudnn . cudnnGetFilter4dDescriptor ( wDesc , ctypes . byref ( dataType ) , ctypes . byref ( format ) , ctypes . byref ( k ) , ctypes . byref ( c ) , ctypes ....
def quickinfo ( self ) : """Returns a short string describing some of the options of the actor . : return : the info , None if not available : rtype : str"""
return "search: " + base . to_commandline ( self . config [ "search" ] ) + ", eval: " + base . to_commandline ( self . config [ "eval" ] )
def where ( self , where : str ) -> 'SASdata' : """This method returns a clone of the SASdata object , with the where attribute set . The original SASdata object is not affected . : param where : the where clause to apply : return : SAS data object"""
sd = SASdata ( self . sas , self . libref , self . table , dsopts = dict ( self . dsopts ) ) sd . HTML = self . HTML sd . dsopts [ 'where' ] = where return sd
def get_range ( element , ranges , dimension ) : """Computes the data , soft - and hard - range along a dimension given an element and a dictionary of ranges ."""
if dimension and dimension != 'categorical' : if ranges and dimension . name in ranges : drange = ranges [ dimension . name ] [ 'data' ] srange = ranges [ dimension . name ] [ 'soft' ] hrange = ranges [ dimension . name ] [ 'hard' ] else : drange = element . range ( dimension , d...
def count_missing ( self , data , output = "number" ) : """Parameters data : pd . DataFrame ( ) Input dataframe . output : str Sting indicating the output of function ( number or percent ) Returns int / float Count of missing data ( int or float )"""
count = self . _find_missing ( data , return_bool = False ) . sum ( ) if output == "number" : return count elif output == "percent" : return ( ( count / ( data . shape [ 0 ] ) ) * 100 )
def configuration ( self , plugin ) : """Get plugin configuration . Return a tuple of ( on | off | default , args )"""
conf = self . config . get ( plugin , "default;" ) . split ( ';' ) if len ( conf ) == 1 : conf . append ( '' ) return tuple ( conf )
def api_delete ( service , file_id , owner_token ) : """Delete a file already uploaded to Send"""
service += 'api/delete/%s' % file_id r = requests . post ( service , json = { 'owner_token' : owner_token , 'delete_token' : owner_token } ) r . raise_for_status ( ) if r . text == 'OK' : return True return False
def check_yaafe ( ) : "Check Aubio availability"
try : import yaafelib except ImportError : warnings . warn ( 'Yaafe librairy is not available' , ImportWarning , stacklevel = 2 ) _WITH_YAAFE = False else : _WITH_YAAFE = True del yaafelib return _WITH_YAAFE
def _to_rest_rels ( model , props ) : """Move the relationships to appropriate location in the props All to _ ones should be in a to _ one key while all to _ manys should be in a to _ many key ."""
props [ 'to_many' ] = { } props [ 'to_one' ] = { } for key in model . to_one : try : props [ 'to_one' ] [ key ] = props . pop ( key ) except KeyError : continue for key in model . to_many : try : props [ 'to_many' ] [ key ] = props . pop ( key ) except KeyError : continue
def get_plugin_info ( self , plugin_name ) : """Get plugin information"""
if plugin_name : for i in self . get_all_plugins : if i [ "plugin_name" ] == plugin_name : return i
def BuildApprovalUrn ( self , approval_id ) : """Builds approval object urn ."""
event = rdf_events . AuditEvent ( user = self . token . username , action = "CLIENT_APPROVAL_REQUEST" , client = self . subject_urn , description = self . reason ) events . Events . PublishEvent ( "Audit" , event , token = self . token ) return self . ApprovalUrnBuilder ( self . subject_urn . Path ( ) , self . token . ...
def __deserialize ( self , data , klass ) : """Deserializes dict , list , str into an object . : param data : dict , list or str . : param klass : class literal , or string of class name . : return : object ."""
if data is None : return None if type ( klass ) == str : if klass . startswith ( 'list[' ) : sub_kls = re . match ( 'list\[(.*)\]' , klass ) . group ( 1 ) return [ self . __deserialize ( sub_data , sub_kls ) for sub_data in data ] if klass . startswith ( 'dict(' ) : sub_kls = re . ma...
def clean ( self ) : """Clean response ."""
if self . response . type == 'application/json' : cleaned = copy . deepcopy ( self . response . data ) if self . cleaner is not None : cleaned = self . cleaner ( cleaned ) typed_response = { dict : DictResponse , int : IntResponse , } . get ( type ( cleaned ) , BaseResponse ) self . response = t...
def merge_options ( cls , groups , options = None , ** kwargs ) : """Given a full options dictionary and options groups specified as a keywords , return the full set of merged options : > > > options = { ' Curve ' : { ' style ' : dict ( color = ' b ' ) } } > > > style = { ' Curve ' : { ' linewidth ' : 10 } } ...
groups = set ( groups ) if ( options is not None and set ( options . keys ( ) ) <= groups ) : kwargs , options = options , None elif ( options is not None and any ( k in groups for k in options ) ) : raise Exception ( "All keys must be a subset of %s" % ', ' . join ( groups ) ) options = { } if ( options is Non...
def _load_multilinestring ( tokens , string ) : """Has similar inputs and return value to to : func : ` _ load _ point ` , except is for handling MULTILINESTRING geometry . : returns : A GeoJSON ` dict ` MultiLineString representation of the WKT ` ` string ` ` ."""
open_paren = next ( tokens ) if not open_paren == '(' : raise ValueError ( INVALID_WKT_FMT % string ) linestrs = [ ] while True : try : linestr = _load_linestring ( tokens , string ) linestrs . append ( linestr [ 'coordinates' ] ) t = next ( tokens ) if t == ')' : # we ' re done ...
def dusk ( self , date = None , local = True , use_elevation = True ) : """Calculates the dusk time ( the time in the evening when the sun is a certain number of degrees below the horizon . By default this is 6 degrees but can be changed by setting the : attr : ` solar _ depression ` property . ) : param da...
if local and self . timezone is None : raise ValueError ( "Local time requested but Location has no timezone set." ) if self . astral is None : self . astral = Astral ( ) if date is None : date = datetime . date . today ( ) elevation = self . elevation if use_elevation else 0 dusk = self . astral . dusk_utc...
def get_db_instances ( self ) : '''DB instance'''
if not self . connect_to_aws_rds ( ) : return False try : instances = self . rdsc . describe_db_instances ( ) . get ( 'DBInstances' ) except : return False else : return instances