signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def project_delete_notif ( self , tenant_id , tenant_name ) : """Tenant Delete notification ."""
if not self . fw_init : return rtr_name = '_' . join ( [ fw_constants . TENANT_EDGE_RTR , tenant_name ] ) self . os_helper . delete_router_by_name ( rtr_name , tenant_id )
def create_api_object_type ( self ) : """Get an instance of Api Vip Requests services facade ."""
return ApiObjectType ( self . networkapi_url , self . user , self . password , self . user_ldap )
def show_dbs ( ) : """return a list of all dbs and related collections . Return an empty list on error ."""
l = [ ] mc = client_connector ( ) if not mc : # The client couldn ' t connect return ( ) dbs = mc . database_names ( ) for d in dbs : dbc = mc [ d ] collections = dbc . collection_names ( ) collections = remove_values_from_list ( collections , "system.indexes" ) l . append ( { "name" : d , "collecti...
def make_trigrams ( i : Iterable [ T ] ) -> Iterable [ Tuple [ Optional [ T ] , Optional [ T ] , Optional [ T ] ] ] : """Compute all trigrams of an iterable and yield them . You probably want to do something like : > > > t = set ( make _ trigrams ( ' hi there ' ) )"""
q = deque ( [ None , None , None ] ) def nxt ( ) : q . append ( x ) q . popleft ( ) return tuple ( c if c is not None else ' ' for c in q ) for x in i : yield nxt ( ) if q [ - 1 ] is not None : x = None yield nxt ( )
def previous_day ( self ) : """Return the HDate for the previous day ."""
return HDate ( self . gdate + datetime . timedelta ( - 1 ) , self . diaspora , self . hebrew )
def get_max_counts ( samples ) : """Retrieve number of regions that can be processed in parallel from current samples ."""
counts = [ ] for data in ( x [ 0 ] for x in samples ) : count = tz . get_in ( [ "config" , "algorithm" , "callable_count" ] , data , 1 ) vcs = tz . get_in ( [ "config" , "algorithm" , "variantcaller" ] , data , [ ] ) if isinstance ( vcs , six . string_types ) : vcs = [ vcs ] if vcs : cou...
def reset_index ( self , level = None , drop = False , inplace = False , col_level = 0 , col_fill = '' ) : """Reset the index , or a level of it . Reset the index of the DataFrame , and use the default one instead . If the DataFrame has a MultiIndex , this method can remove one or more levels . Parameters ...
inplace = validate_bool_kwarg ( inplace , 'inplace' ) if inplace : new_obj = self else : new_obj = self . copy ( ) def _maybe_casted_values ( index , labels = None ) : values = index . _values if not isinstance ( index , ( PeriodIndex , DatetimeIndex ) ) : if values . dtype == np . object_ : ...
def format_obj_keys ( obj , formatter ) : """Take a dictionary with string keys and recursively convert all keys from one form to another using the formatting function . The dictionary may contain lists as values , and any nested dictionaries within those lists will also be converted . : param object obj : ...
if type ( obj ) == list : return [ format_obj_keys ( o , formatter ) for o in obj ] elif type ( obj ) == dict : return { formatter ( k ) : format_obj_keys ( v , formatter ) for k , v in obj . items ( ) } else : return obj
def load_mode ( node ) : """Load one observing mdode"""
obs_mode = ObservingMode ( ) obs_mode . __dict__ . update ( node ) # handle validator load_mode_validator ( obs_mode , node ) # handle builder load_mode_builder ( obs_mode , node ) # handle tagger : load_mode_tagger ( obs_mode , node ) return obs_mode
def hex_to_rgb ( self , h ) : """Converts a valid hex color string to an RGB array ."""
rgb = ( self . hex_to_red ( h ) , self . hex_to_green ( h ) , self . hex_to_blue ( h ) ) return rgb
def identity_factor ( self ) : """Returns the identity factor . Def : The identity factor of a factor has the same scope and cardinality as the original factor , but the values for all the assignments is 1 . When the identity factor is multiplied with the factor it returns the factor itself . Returns Disc...
return DiscreteFactor ( self . variables , self . cardinality , np . ones ( self . values . size ) )
def getEmbeddedKeyVal ( cfgFileName , kwdName , dflt = None ) : """Read a config file and pull out the value of a given keyword ."""
# Assume this is a ConfigObj file . Use that s / w to quickly read it and # put it in dict format . Assume kwd is at top level ( not in a section ) . # The input may also be a . cfgspc file . # Only use ConfigObj here as a tool to generate a dict from a file - do # not use the returned object as a ConfigObj per se . As...
def delete_persistent_attributes ( self ) : # type : ( ) - > None """Deletes the persistent attributes from the persistence layer . : rtype : None : raises : : py : class : ` ask _ sdk _ core . exceptions . AttributesManagerException ` if trying to delete persistence attributes without persistence adapter"""
if not self . _persistence_adapter : raise AttributesManagerException ( "Cannot delete PersistentAttributes without " "persistence adapter!" ) if self . _persistent_attributes_set : self . _persistence_adapter . delete_attributes ( request_envelope = self . _request_envelope ) self . _persistence_attributes...
def get_list_continuous_queries ( self ) : """Get the list of continuous queries in InfluxDB . : return : all CQs in InfluxDB : rtype : list of dictionaries : Example : > > cqs = client . get _ list _ cqs ( ) > > cqs u ' db1 ' : [ ] u ' db2 ' : [ u ' name ' : u ' vampire ' , u ' query ' : u ' CREA...
query_string = "SHOW CONTINUOUS QUERIES" return [ { sk [ 0 ] : list ( p ) } for sk , p in self . query ( query_string ) . items ( ) ]
def remove_bond ( self , idx1 , idx2 ) : """Remove a bond from an openbabel molecule Args : idx1 : The atom index of one of the atoms participating the in bond idx2 : The atom index of the other atom participating in the bond"""
for obbond in ob . OBMolBondIter ( self . _obmol ) : if ( obbond . GetBeginAtomIdx ( ) == idx1 and obbond . GetEndAtomIdx ( ) == idx2 ) or ( obbond . GetBeginAtomIdx ( ) == idx2 and obbond . GetEndAtomIdx ( ) == idx1 ) : self . _obmol . DeleteBond ( obbond )
def wrap_function_name ( self , name ) : """Split the function name on multiple lines ."""
if len ( name ) > 32 : ratio = 2.0 / 3.0 height = max ( int ( len ( name ) / ( 1.0 - ratio ) + 0.5 ) , 1 ) width = max ( len ( name ) / height , 32 ) # TODO : break lines in symbols name = textwrap . fill ( name , width , break_long_words = False ) # Take away spaces name = name . replace ( ", " , "...
def send ( self , api , force_send ) : """Send this item using api . : param api : D4S2Api sends messages to D4S2 : param force _ send : bool should we send even if the item already exists"""
item_id = self . get_existing_item_id ( api ) if not item_id : item_id = self . create_item_returning_id ( api ) api . send_item ( self . destination , item_id , force_send ) else : if force_send : api . send_item ( self . destination , item_id , force_send ) else : item_type = D4S2Api ....
def all_stats ( klass , account , ids , metric_groups , ** kwargs ) : """Pulls a list of metrics for a specified set of object IDs ."""
params = klass . _standard_params ( ids , metric_groups , ** kwargs ) resource = klass . RESOURCE_SYNC . format ( account_id = account . id ) response = Request ( account . client , 'get' , resource , params = params ) . perform ( ) return response . body [ 'data' ]
def get_subclass ( cls , name ) : """Get Benchmark subclass by name : param name : name returned by ` ` Benchmark . name ` ` property : return : instance of ` ` Benchmark ` ` class"""
for subclass in cls . __subclasses__ ( ) : if subclass . name == name : return subclass raise NameError ( "Not a valid Benchmark class: " + name )
def get_absorbing_atom_symbol_index ( absorbing_atom , structure ) : """Return the absorbing atom symboll and site index in the given structure . Args : absorbing _ atom ( str / int ) : symbol or site index structure ( Structure ) Returns : str , int : symbol and site index"""
if isinstance ( absorbing_atom , str ) : return absorbing_atom , structure . indices_from_symbol ( absorbing_atom ) [ 0 ] elif isinstance ( absorbing_atom , int ) : return str ( structure [ absorbing_atom ] . specie ) , absorbing_atom else : raise ValueError ( "absorbing_atom must be either specie symbol or...
def make_str_node ( rawtext , app , prefixed_name , obj , parent , modname , options ) : """Render a Python object to text using the repr ( ) function . : param rawtext : Text being replaced with link node . : param app : Sphinx application context : param prefixed _ name : The dotted Python name for obj . ...
text = str ( obj ) node = nodes . Text ( text , rawsource = rawtext ) return node
def get_subassistant_tree ( self ) : """Returns a tree - like structure representing the assistant hierarchy going down from this assistant to leaf assistants . For example : [ ( < This Assistant > , [ ( < Subassistant 1 > , [ . . . ] ) , ( < Subassistant 2 > , [ . . . ] ) ] Returns : a tree - like stru...
if '_tree' not in dir ( self ) : subassistant_tree = [ ] subassistants = self . get_subassistants ( ) for subassistant in subassistants : subassistant_tree . append ( subassistant . get_subassistant_tree ( ) ) self . _tree = ( self , subassistant_tree ) return self . _tree
def createStatus ( self , repo_user , repo_name , sha , state , target_url = None , context = None , issue = None , description = None ) : """: param repo _ user : GitHub user or organization : param repo _ name : Name of the repository : param issue : Pull request number : param state : one of the following ...
payload = { 'body' : description } return self . _http . post ( '/' . join ( [ '/repos' , repo_user , repo_name , 'issues' , issue , 'comments' ] ) , json = payload )
def indication ( self , pdu ) : """Requests are queued for delivery ."""
if _debug : TCPServer . _debug ( "indication %r" , pdu ) self . request += pdu . pduData
def times_to_ms ( h = 0 , m = 0 , s = 0 , ms = 0 ) : """Convert hours , minutes , seconds to milliseconds . Arguments may be positive or negative , int or float , need not be normalized ( ` ` s = 120 ` ` is okay ) . Returns : Number of milliseconds ( rounded to int ) ."""
ms += s * 1000 ms += m * 60000 ms += h * 3600000 return int ( round ( ms ) )
def do_unique ( environment , value , case_sensitive = False , attribute = None ) : """Returns a list of unique items from the the given iterable . . . sourcecode : : jinja { { [ ' foo ' , ' bar ' , ' foobar ' , ' FooBar ' ] | unique } } - > [ ' foo ' , ' bar ' , ' foobar ' ] The unique items are yielded in...
getter = make_attrgetter ( environment , attribute , postprocess = ignore_case if not case_sensitive else None ) seen = set ( ) for item in value : key = getter ( item ) if key not in seen : seen . add ( key ) yield item
def encap ( self , pkt ) : """encapsulate a frame using this Secure Association"""
if pkt . name != Ether ( ) . name : raise TypeError ( 'cannot encapsulate packet in MACsec, must be Ethernet' ) # noqa : E501 hdr = copy . deepcopy ( pkt ) payload = hdr . payload del hdr . payload tag = MACsec ( sci = self . sci , an = self . an , SC = self . send_sci , E = self . e_bit ( ) , C = self . c_bit ...
def _z2deriv ( self , R , z , phi = 0. , t = 0. ) : """NAME : _ z2deriv PURPOSE : evaluate the second vertical derivative for this potential INPUT : R - Galactocentric cylindrical radius z - vertical height phi - azimuth t - time OUTPUT : the second vertical derivative HISTORY : 2012-07-25 -...
sqrtbz = nu . sqrt ( self . _b2 + z ** 2. ) asqrtbz = self . _a + sqrtbz if isinstance ( R , float ) and sqrtbz == asqrtbz : return ( self . _b2 + R ** 2. - 2. * z ** 2. ) * ( self . _b2 + R ** 2. + z ** 2. ) ** - 2.5 else : return ( ( self . _a ** 3. * self . _b2 + self . _a ** 2. * ( 3. * self . _b2 - 2. * z ...
def value_comparisons ( self , values , comp = "=" , is_assignment = False ) : """Builds out a series of value comparisions . : values : can either be a dictionary , in which case the return will compare a name to a named placeholder , using the comp argument . I . E . values = { " first _ name " : " John " , "...
if isinstance ( values , dict ) : if self . sort_columns : keys = sorted ( values . keys ( ) ) else : keys = list ( values . keys ( ) ) params = zip ( keys , [ self . to_placeholder ( k ) for k in keys ] ) return [ self . to_expression ( i [ 0 ] , i [ 1 ] , comp if is_assignment else sel...
def sorted_fancy_indexing ( indexable , request ) : """Safe fancy indexing . Some objects , such as h5py datasets , only support list indexing if the list is sorted . This static method adds support for unsorted list indexing by sorting the requested indices , accessing the corresponding elements and re -...
if len ( request ) > 1 : indices = numpy . argsort ( request ) data = numpy . empty ( shape = ( len ( request ) , ) + indexable . shape [ 1 : ] , dtype = indexable . dtype ) data [ indices ] = indexable [ numpy . array ( request ) [ indices ] , ... ] else : data = indexable [ request ] return data
def register_or_check ( klass , finish , mean , between , refresh_presision , configuration ) : """Return the active configurations ."""
m , created = klass . objects . get_or_create ( finish = finish , configuration = configuration ) if created : m . mean = mean m . between = between m . refresh_presision = refresh_presision m . save ( ) else : diff = abs ( float ( m . mean ) - mean ) if not ( diff < 0.006 and m . between == bet...
def add_if_none_match ( self ) : """Add the if - none - match option to the request ."""
option = Option ( ) option . number = defines . OptionRegistry . IF_NONE_MATCH . number option . value = None self . add_option ( option )
def download_isbn ( ) : with open ( 'raw.json' ) as input : data = json . load ( input ) '''print ( " Loading index " ) md = readmetadata ( ) for record in data : id = record [ ' metadata ' ] [ ' id ' ] metadata = md [ id ] pprint ( metadata ) sys . exit ( 0) title = record [ ' book ' ] [ ...
url = 'http://www.librarything.com/api/thingTitle/' for record in data : title = record [ 'book' ] [ 'title' ] final_url = url + quote_plus ( title ) content = requests . get ( final_url ) . content soup = BeautifulSoup ( content ) extracted_title = soup . idlist . title . string isbn = soup . i...
def get_by_user_ldap ( self , user_name ) : """Get user by the ldap name . is _ more - If more than 3 of groups of users or no , to control expansion Screen . : return : Dictionary with the following structure : { ' usuario ' : [ { ' nome ' : < nome > , ' id ' : < id > , ' pwd ' : < pwd > , ' user ' : <...
url = 'user/get/ldap/' + str ( user_name ) + '/' code , xml = self . submit ( None , 'GET' , url ) return self . response ( code , xml )
def _flatten_output_shape ( input_shape , num_axis_to_keep = 1 ) : """Output shape of a flatten layer ."""
if num_axis_to_keep >= len ( input_shape ) : raise ValueError ( "num_axis_to_keep[%d] should be less than input's rank[%d]" % ( num_axis_to_keep , len ( input_shape ) ) ) return tuple ( input_shape [ : num_axis_to_keep ] ) + ( reduce ( op . mul , input_shape [ num_axis_to_keep : ] , 1 ) , )
def _merge_defaults ( self , data : dict ) -> dict : """Convenience method that calls : func : ` ~ notifiers . utils . helpers . merge _ dicts ` in order to merge default values : param data : Notification data : return : A merged dict of provided data with added defaults"""
log . debug ( "merging defaults %s into data %s" , self . defaults , data ) return merge_dicts ( data , self . defaults )
def get_terms ( desc , geneset , assoc , obo_dag , log ) : """Get the terms in the study group"""
_chk_gene2go ( assoc ) term2itemids = defaultdict ( set ) genes = [ g for g in geneset if g in assoc ] for gene in genes : for goid in assoc [ gene ] : if goid in obo_dag : term2itemids [ obo_dag [ goid ] . id ] . add ( gene ) if log is not None : num_stu = len ( genes ) num_pop = len ( ...
def timeout ( seconds ) : """Raises a TimeoutError if a function does not terminate within specified seconds ."""
def _timeout_error ( signal , frame ) : raise TimeoutError ( "Operation did not finish within \ {} seconds" . format ( seconds ) ) def timeout_decorator ( func ) : @ wraps ( func ) def timeout_wrapper ( * args , ** kwargs ) : signal . signal ( signal . SIGALRM , _timeout_error ) sign...
def subspace_detector_plot ( detector , stachans , size , ** kwargs ) : """Plotting for the subspace detector class . Plot the output basis vectors for the detector at the given dimension . Corresponds to the first n horizontal vectors of the V matrix . : type detector : : class : ` eqcorrscan . core . subspa...
import matplotlib . pyplot as plt if stachans == 'all' and not detector . multiplex : stachans = detector . stachans elif detector . multiplex : stachans = [ ( 'multi' , ' ' ) ] if np . isinf ( detector . dimension ) : msg = ' ' . join ( [ 'Infinite subspace dimension. Only plotting as many' , 'dimensions a...
def _setup_rpc ( self ) : """Setup the RPC client for the current agent ."""
self . _state_rpc = agent_rpc . PluginReportStateAPI ( topics . REPORTS ) report_interval = CONF . AGENT . report_interval if report_interval : heartbeat = loopingcall . FixedIntervalLoopingCall ( self . _report_state ) heartbeat . start ( interval = report_interval )
def place_visual ( self ) : """Places visual objects randomly until no collisions or max iterations hit ."""
index = 0 bin_pos = string_to_array ( self . bin2_body . get ( "pos" ) ) bin_size = self . bin_size for _ , obj_mjcf in self . visual_objects : bin_x_low = bin_pos [ 0 ] bin_y_low = bin_pos [ 1 ] if index == 0 or index == 2 : bin_x_low -= bin_size [ 0 ] / 2 if index < 2 : bin_y_low -= bi...
def com_google_fonts_check_family_panose_proportion ( ttFonts ) : """Fonts have consistent PANOSE proportion ?"""
failed = False proportion = None for ttFont in ttFonts : if proportion is None : proportion = ttFont [ 'OS/2' ] . panose . bProportion if proportion != ttFont [ 'OS/2' ] . panose . bProportion : failed = True if failed : yield FAIL , ( "PANOSE proportion is not" " the same accross this famil...
async def setChatStickerSet ( self , chat_id , sticker_set_name ) : """See : https : / / core . telegram . org / bots / api # setchatstickerset"""
p = _strip ( locals ( ) ) return await self . _api_request ( 'setChatStickerSet' , _rectify ( p ) )
def apriori ( transactions , ** kwargs ) : """Executes Apriori algorithm and returns a RelationRecord generator . Arguments : transactions - - A transaction iterable object ( eg . [ [ ' A ' , ' B ' ] , [ ' B ' , ' C ' ] ] ) . Keyword arguments : min _ support - - The minimum support of relations ( float )...
# Parse the arguments . min_support = kwargs . get ( 'min_support' , 0.1 ) min_confidence = kwargs . get ( 'min_confidence' , 0.0 ) min_lift = kwargs . get ( 'min_lift' , 0.0 ) max_length = kwargs . get ( 'max_length' , None ) # Check arguments . if min_support <= 0 : raise ValueError ( 'minimum support must be > 0...
def _open_sqlite ( db_file ) : """Opens database connection ."""
db_file = os . path . expanduser ( db_file ) try : with open ( db_file ) : # test that the file can be accessed pass return sqlite3 . connect ( db_file , detect_types = sqlite3 . PARSE_DECLTYPES ) except ( IOError , sqlite3 . Error ) as err : raise Dump2PolarionException ( "{}" . format ( err ) )
def has_listener ( self , evt_name , fn ) : """指定listener是否存在 : params evt _ name : 事件名称 : params fn : 要注册的触发函数函数"""
listeners = self . __get_listeners ( evt_name ) return fn in listeners
def delete_key ( self , key_id ) : """Delete user key pointed to by ` ` key _ id ` ` . : param int key _ id : ( required ) , unique id used by Github : returns : bool"""
key = self . key ( key_id ) if key : return key . delete ( ) return False
def rAsciiLine ( ifile ) : """Returns the next non - blank line in an ASCII file ."""
_line = ifile . readline ( ) . strip ( ) while len ( _line ) == 0 : _line = ifile . readline ( ) . strip ( ) return _line
def _import_PREFIXCC ( keyword = "" ) : """List models from web catalog ( prefix . cc ) and ask which one to import 2015-10-10 : originally part of main ontospy ; now standalone only 2016-06-19 : eliminated dependency on extras . import _ web"""
SOURCE = "http://prefix.cc/popular/all.file.vann" options = [ ] printDebug ( "----------\nReading source..." ) g = Ontospy ( SOURCE , verbose = False ) for x in g . all_ontologies : if keyword : if keyword in unicode ( x . prefix ) . lower ( ) or keyword in unicode ( x . uri ) . lower ( ) : opti...
def dump_request_and_response ( self , response ) : """Return a string containing a nicely formatted representation of the request and response objects for logging and debugging . - Note : Does not work if the request or response body is a MultipartEncoder object ."""
if response . reason is None : response . reason = "<unknown>" return d1_client . util . normalize_request_response_dump ( requests_toolbelt . utils . dump . dump_response ( response ) )
def load_files ( self , path ) : """Loads files in a given path and all its subdirectories"""
if self . verbose == 2 : print ( "Indexing {}" . format ( path ) ) for filename in os . listdir ( path ) : file_path = path + "/" + filename if os . path . isdir ( file_path ) : self . load_files ( file_path ) elif filename . endswith ( ".yaml" ) or filename . endswith ( ".yml" ) : self ...
def add_eager_constraints ( self , models ) : """Set the constraints for an eager load of the relation . : type models : list"""
self . _models = Collection . make ( models ) self . _build_dictionary ( models )
def set_auto_delete_disks ( self , auto_delete_disks ) : """Enable / disable use of auto delete disks : param auto _ delete _ disks : activate / deactivate auto delete disks ( boolean )"""
if auto_delete_disks : log . info ( 'Router "{name}" [{id}]: auto delete disks enabled' . format ( name = self . _name , id = self . _id ) ) else : log . info ( 'Router "{name}" [{id}]: auto delete disks disabled' . format ( name = self . _name , id = self . _id ) ) self . _auto_delete_disks = auto_delete_disks
def answer_challenge ( authzr , client , responders ) : """Complete an authorization using a responder . : param ~ acme . messages . AuthorizationResource auth : The authorization to complete . : param . Client client : The ACME client . : type responders : List [ ` ~ txacme . interfaces . IResponder ` ] ...
responder , challb = _find_supported_challenge ( authzr , responders ) response = challb . response ( client . key ) def _stop_responding ( ) : return maybeDeferred ( responder . stop_responding , authzr . body . identifier . value , challb . chall , response ) return ( maybeDeferred ( responder . start_responding ...
def encodeValue ( value ) : """TODO"""
if isinstance ( value , ( list , tuple ) ) : return [ common . AttributeValue ( string_value = str ( v ) ) for v in value ] else : return [ common . AttributeValue ( string_value = str ( value ) ) ]
def darklyrics ( song ) : """Returns the lyrics found in darklyrics for the specified mp3 file or an empty string if not found ."""
# Darklyrics relies on the album name if not hasattr ( song , 'album' ) or not song . album : song . fetch_album_name ( ) if not hasattr ( song , 'album' ) or not song . album : # If we don ' t have the name of the album , there ' s nothing we can do # on darklyrics return '' artist = song . artist ...
def add_callback ( self , callback : callable ) : """Add a callback on change : param callback : callable function : return : None"""
def internal_callback ( * args ) : try : callback ( ) except TypeError : callback ( self . get ( ) ) self . _var . trace ( 'w' , internal_callback )
def main ( ) : '''Main function to run the sensor with passed arguments'''
trig , echo , speed , samples = get_args ( ) print ( 'trig pin = gpio {}' . format ( trig ) ) print ( 'echo pin = gpio {}' . format ( echo ) ) print ( 'speed = {}' . format ( speed ) ) print ( 'samples = {}' . format ( samples ) ) print ( '' ) value = sensor . Measurement ( trig , echo ) raw_distance = value . raw_dist...
def _batch_norm_without_layers ( self , input_layer , decay , use_scale , epsilon ) : """Batch normalization on ` input _ layer ` without tf . layers ."""
shape = input_layer . shape num_channels = shape [ 3 ] if self . data_format == "NHWC" else shape [ 1 ] beta = self . get_variable ( "beta" , [ num_channels ] , tf . float32 , tf . float32 , initializer = tf . zeros_initializer ( ) ) if use_scale : gamma = self . get_variable ( "gamma" , [ num_channels ] , tf . flo...
def register ( self , callback_id : str , handler : Any , name : str = "*" ) -> None : """Register a new handler for a specific : class : ` slack . actions . Action ` ` callback _ id ` . Optional routing based on the action name too . The name argument is useful for actions of type ` interactive _ message ` to ...
LOG . info ( "Registering %s, %s to %s" , callback_id , name , handler ) if name not in self . _routes [ callback_id ] : self . _routes [ callback_id ] [ name ] = [ ] self . _routes [ callback_id ] [ name ] . append ( handler )
def timezones_choices ( ) : """Timezones values and their labels for current locale . : return : an iterable of ` ( code , label ) ` , code being a timezone code and label the timezone name in current locale ."""
utcnow = pytz . utc . localize ( datetime . utcnow ( ) ) locale = _get_locale ( ) for tz in sorted ( pytz . common_timezones ) : tz = get_timezone ( tz ) now = tz . normalize ( utcnow . astimezone ( tz ) ) label = "({}) {}" . format ( get_timezone_gmt ( now , locale = locale ) , tz . zone ) yield ( tz ,...
def nn_poll ( fds , timeout = - 1 ) : """nn _ pollfds : param fds : dict ( file descriptor = > pollmode ) : param timeout : timeout in milliseconds : return :"""
polls = [ ] for i , entry in enumerate ( fds . items ( ) ) : s = PollFds ( ) fd , event = entry s . fd = fd s . events = event s . revents = 0 polls . append ( s ) poll_array = ( PollFds * len ( fds ) ) ( * polls ) res = _nn_poll ( poll_array , len ( fds ) , int ( timeout ) ) if res <= 0 : r...
def create_case ( self , name , email , subject , description , businessImpact , priority , phone ) : """Send a case creation to SalesForces to create a ticket . @ param name of the person creating the case . @ param email of the person creating the case . @ param subject of the case . @ param description o...
if not ( '@' in parseaddr ( email ) [ 1 ] ) : raise ValueError ( 'invalid email: {}' . format ( email ) ) if '' == name or name is None : raise ValueError ( 'empty name' ) if '' == subject or subject is None : raise ValueError ( 'empty subject' ) if '' == description or description is None : raise Value...
def validate_field_name ( bases : List [ Type [ 'BaseModel' ] ] , field_name : str ) -> None : """Ensure that the field ' s name does not shadow an existing attribute of the model ."""
for base in bases : if getattr ( base , field_name , None ) : raise NameError ( f'Field name "{field_name}" shadows a BaseModel attribute; ' f'use a different field name with "alias=\'{field_name}\'".' )
def _invoke_request_handler ( self , function_name ) : """Request Handler for the Local Lambda Invoke path . This method is responsible for understanding the incoming request and invoking the Local Lambda Function Parameters function _ name str Name of the function to invoke Returns A Flask Response res...
flask_request = request request_data = flask_request . get_data ( ) if not request_data : request_data = b'{}' request_data = request_data . decode ( 'utf-8' ) stdout_stream = io . BytesIO ( ) stdout_stream_writer = StreamWriter ( stdout_stream , self . is_debugging ) try : self . lambda_runner . invoke ( funct...
def connectcomponents ( idf , components , fluid = None ) : """rename nodes so that the components get connected fluid is only needed if there are air and water nodes fluid is Air or Water or ' ' . if the fluid is Steam , use Water"""
if fluid is None : fluid = '' if len ( components ) == 1 : thiscomp , thiscompnode = components [ 0 ] initinletoutlet ( idf , thiscomp , thiscompnode , force = False ) outletnodename = getnodefieldname ( thiscomp , "Outlet_Node_Name" , fluid = fluid , startswith = thiscompnode ) thiscomp [ outletnod...
def _list_model ( self , model_cls : Type [ X ] ) -> List [ X ] : """List the models in this class ."""
return self . session . query ( model_cls ) . all ( )
def read ( self ) : """Reads the data stored in the files we have been initialized with . It will ignore files that cannot be read , possibly leaving an empty configuration : return : Nothing : raise IOError : if a file cannot be handled"""
if self . _is_initialized : return self . _is_initialized = True if not isinstance ( self . _file_or_files , ( tuple , list ) ) : files_to_read = [ self . _file_or_files ] else : files_to_read = list ( self . _file_or_files ) # end assure we have a copy of the paths to handle seen = set ( files_to_read ) nu...
def delete_stack ( self , stack_name ) : """Teardown a stack ."""
get_stack ( stack_name ) CLIENT . delete_stack ( StackName = stack_name ) DELETE_WAITER . wait ( StackName = stack_name )
def support_false_positive_count ( m , m_hat ) : """Count the number of false positive support elements in m _ hat in one triangle , not including the diagonal ."""
m_nnz , m_hat_nnz , intersection_nnz = _nonzero_intersection ( m , m_hat ) return int ( ( m_hat_nnz - intersection_nnz ) / 2.0 )
def _sanitize_to_unicode ( obj ) : """Convert all strings records of the object to unicode : param obj : object to sanitize to unicode . : type obj : object : return : Unicode string representation of the given object . : rtype : str"""
if isinstance ( obj , dict ) : return dict ( ( BaseGELFHandler . _sanitize_to_unicode ( k ) , BaseGELFHandler . _sanitize_to_unicode ( v ) ) for k , v in obj . items ( ) ) if isinstance ( obj , ( list , tuple ) ) : return obj . __class__ ( [ BaseGELFHandler . _sanitize_to_unicode ( i ) for i in obj ] ) if isins...
def chip_as_adjacency_list ( device : 'cirq.google.XmonDevice' , ) -> Dict [ GridQubit , List [ GridQubit ] ] : """Gives adjacency list representation of a chip . The adjacency list is constructed in order of above , left _ of , below and right _ of consecutively . Args : device : Chip to be converted . R...
c_set = set ( device . qubits ) c_adj = { } # type : Dict [ GridQubit , List [ GridQubit ] ] for n in device . qubits : c_adj [ n ] = [ ] for m in [ above ( n ) , left_of ( n ) , below ( n ) , right_of ( n ) ] : if m in c_set : c_adj [ n ] . append ( m ) return c_adj
def gen_checkbox_list ( sig_dic ) : '''For generating List view HTML file for CHECKBOX . for each item .'''
view_zuoxiang = '''<span class="iga_pd_val">''' dic_tmp = sig_dic [ 'dic' ] for key in dic_tmp . keys ( ) : tmp_str = '''{{% if "{0}" in postinfo.extinfo["{1}"] %}} {2} {{% end %}} ''' . format ( key , sig_dic [ 'en' ] , dic_tmp [ key ] ) view_zuoxiang += tmp_str view_zuoxiang += '''</span>''' return v...
def _load_area_def ( self , dsid , file_handlers ) : """Load the area definition of * dsid * ."""
area_defs = [ fh . get_area_def ( dsid ) for fh in file_handlers ] area_defs = [ area_def for area_def in area_defs if area_def is not None ] final_area = StackedAreaDefinition ( * area_defs ) return final_area . squeeze ( )
def commitreturn ( self , qstring , vals = ( ) ) : "commit and return result . This is intended for sql UPDATE . . . RETURNING"
with self . withcur ( ) as cur : cur . execute ( qstring , vals ) return cur . fetchone ( )
def GetParserFromFilename ( self , path ) : """Returns the appropriate parser class from the filename ."""
# Find the configuration parser . handler_name = path . split ( "://" ) [ 0 ] for parser_cls in itervalues ( GRRConfigParser . classes ) : if parser_cls . name == handler_name : return parser_cls # Handle the filename . extension = os . path . splitext ( path ) [ 1 ] if extension in [ ".yaml" , ".yml" ] : ...
def ssml_w ( self , words , role = None , ** kwargs ) : """Create a < W > element : param words : Words to speak : param role : Customize the pronunciation of words by specifying the word ’ s part of speech or alternate meaning : param kwargs : additional attributes : returns : < W > element"""
return self . nest ( SsmlW ( words , role = role , ** kwargs ) )
def convert_to_jbig2 ( pike , jbig2_groups , root , log , options ) : """Convert images to JBIG2 and insert into PDF . When the JBIG2 page group size is > 1 we do several JBIG2 images at once and build a symbol dictionary that will span several pages . Each JBIG2 image must reference to its symbol dictionary ...
_produce_jbig2_images ( jbig2_groups , root , log , options ) for group , xref_exts in jbig2_groups . items ( ) : prefix = f'group{group:08d}' jbig2_symfile = root / ( prefix + '.sym' ) if jbig2_symfile . exists ( ) : jbig2_globals_data = jbig2_symfile . read_bytes ( ) jbig2_globals = pikepd...
def Call ( func_name , args = None , prefix = None ) : """A function call"""
node = Node ( syms . power , [ func_name , ArgList ( args ) ] ) if prefix is not None : node . prefix = prefix return node
def parse_charset ( header_string ) : '''Parse a " Content - Type " string for the document encoding . Returns : str , None'''
match = re . search ( r'''charset[ ]?=[ ]?["']?([a-z0-9_-]+)''' , header_string , re . IGNORECASE ) if match : return match . group ( 1 )
async def run_asgi ( self ) : """Wrapper around the ASGI callable , handling exceptions and unexpected termination states ."""
try : result = await self . app ( self . scope , self . asgi_receive , self . asgi_send ) except BaseException as exc : self . closed_event . set ( ) msg = "Exception in ASGI application\n" self . logger . error ( msg , exc_info = exc ) if not self . handshake_started_event . is_set ( ) : se...
def determine_num_chunks ( chunk_size , file_size ) : """Figure out how many pieces we are sending the file in . NOTE : duke - data - service requires an empty chunk to be uploaded for empty files ."""
if file_size == 0 : return 1 return int ( math . ceil ( float ( file_size ) / float ( chunk_size ) ) )
def mentioned_in ( self , message ) : """Checks if the user is mentioned in the specified message . Parameters message : : class : ` Message ` The message to check if you ' re mentioned in ."""
if message . mention_everyone : return True for user in message . mentions : if user . id == self . id : return True return False
def _load ( self ) : """Load the database from its ` ` dbfile ` ` if it has one"""
if self . dbfile is not None : with open ( self . dbfile , 'r' ) as f : self . _db = json . loads ( f . read ( ) ) else : self . _db = { }
def install_json_output_variables ( self , ij = None ) : """Return install . json output variables in a dict with name param as key . Args : ij ( dict , optional ) : Defaults to None . The install . json contents . Returns : dict : A dictionary containing the install . json output variables with name as key...
if self . _install_json_output_variables is None or ij is not None : self . _install_json_output_variables = { } # TODO : currently there is no support for projects with multiple install . json files . if ij is None : ij = self . install_json for p in ij . get ( 'playbook' , { } ) . get ( 'outpu...
def AppConfigFlagHandler ( feature = None ) : """This is the default handler . It checks for feature flags in the current app ' s configuration . For example , to have ' unfinished _ feature ' hidden in production but active in development : config . py class ProductionConfig ( Config ) : FEATURE _ FLAGS = ...
if not current_app : log . warn ( u"Got a request to check for {feature} but we're outside the request context. Returning False" . format ( feature = feature ) ) return False try : return current_app . config [ FEATURE_FLAGS_CONFIG ] [ feature ] except ( AttributeError , KeyError ) : raise NoFeatureFlag...
def get_X_spline ( x , knots , n_bases = 10 , spline_order = 3 , add_intercept = True ) : """Returns : np . array of shape [ len ( x ) , n _ bases + ( add _ intercept ) ] # BSpline formula https : / / docs . scipy . org / doc / scipy / reference / generated / scipy . interpolate . BSpline . html # scipy . int...
if len ( x . shape ) is not 1 : raise ValueError ( "x has to be 1 dimentional" ) tck = [ knots , np . zeros ( n_bases ) , spline_order ] X = np . zeros ( [ len ( x ) , n_bases ] ) for i in range ( n_bases ) : vec = np . zeros ( n_bases ) vec [ i ] = 1.0 tck [ 1 ] = vec X [ : , i ] = si . splev ( x ,...
def safe_unicode ( string ) : """If Python 2 , replace non - ascii characters and return encoded string ."""
if not PY3 : uni = string . replace ( u'\u2019' , "'" ) return uni . encode ( 'utf-8' ) return string
def health ( self , indices = None , level = "cluster" , wait_for_status = None , wait_for_relocating_shards = None , timeout = 30 ) : """Check the current : ref : ` cluster health < es - guide - reference - api - admin - cluster - health > ` . Request Parameters The cluster health API accepts the following req...
if indices : path = make_path ( "_cluster" , "health" , "," . join ( indices ) ) else : path = make_path ( "_cluster" , "health" ) mapping = { } if level != "cluster" : if level not in [ "cluster" , "indices" , "shards" ] : raise ValueError ( "Invalid level: %s" % level ) mapping [ 'level' ] = l...
def select_db ( self , db ) : '''Set current db'''
yield self . _execute_command ( COMMAND . COM_INIT_DB , db ) yield self . _read_ok_packet ( )
def new ( self , attribute , operation = ChainOperator . AND ) : """Combine with a new query : param str attribute : attribute of new query : param ChainOperator operation : operation to combine to new query : rtype : Query"""
if isinstance ( operation , str ) : operation = ChainOperator ( operation ) self . _chain = operation self . _attribute = self . _get_mapping ( attribute ) if attribute else None self . _negation = False return self
def tag_related ( self , query , category = None ) : """Get related tags . Parameters : query ( str ) : The tag to find the related tags for . category ( str ) : If specified , show only tags of a specific category . Can be : General 0 , Artist 1 , Copyright 3 and Character 4."""
params = { 'query' : query , 'category' : category } return self . _get ( 'related_tag.json' , params )
def union ( self , rdds ) : """Build the union of a list of RDDs . This supports unions ( ) of RDDs with different serialized formats , although this forces them to be reserialized using the default serializer : > > > path = os . path . join ( tempdir , " union - text . txt " ) > > > with open ( path , " ...
first_jrdd_deserializer = rdds [ 0 ] . _jrdd_deserializer if any ( x . _jrdd_deserializer != first_jrdd_deserializer for x in rdds ) : rdds = [ x . _reserialize ( ) for x in rdds ] cls = SparkContext . _jvm . org . apache . spark . api . java . JavaRDD jrdds = SparkContext . _gateway . new_array ( cls , len ( rdds ...
def user_exists_in_group ( user_name , group_name , region = None , key = None , keyid = None , profile = None ) : '''Check if user exists in group . . . versionadded : : 2015.8.0 CLI Example : . . code - block : : bash salt myminion boto _ iam . user _ exists _ in _ group myuser mygroup'''
# TODO this should probably use boto . iam . get _ groups _ for _ user users = get_group_members ( group_name = group_name , region = region , key = key , keyid = keyid , profile = profile ) if users : for _user in users : if user_name == _user [ 'user_name' ] : log . debug ( 'IAM user %s is alr...
def delete ( self , space_no , * args ) : """delete tuple by primary key"""
d = self . replyQueue . get ( ) packet = RequestDelete ( self . charset , self . errors , d . _ipro_request_id , space_no , 0 , * args ) self . transport . write ( bytes ( packet ) ) return d . addCallback ( self . handle_reply , self . charset , self . errors , None )
def batch ( samples ) : """CWL : batch together per sample , joint and germline calls for ensemble combination . Sets up groups of same sample / batch variant calls for ensemble calling , as long as we have more than one caller per group ."""
samples = [ utils . to_single_data ( x ) for x in samples ] sample_order = [ dd . get_sample_name ( x ) for x in samples ] batch_groups = collections . defaultdict ( list ) for data in samples : batch_samples = tuple ( data . get ( "batch_samples" , [ dd . get_sample_name ( data ) ] ) ) batch_groups [ ( batch_s...
def _PrintAnalysisStatusHeader ( self , processing_status ) : """Prints the analysis status header . Args : processing _ status ( ProcessingStatus ) : processing status ."""
self . _output_writer . Write ( 'Storage file\t\t: {0:s}\n' . format ( self . _storage_file_path ) ) self . _PrintProcessingTime ( processing_status ) if processing_status and processing_status . events_status : self . _PrintEventsStatus ( processing_status . events_status ) self . _output_writer . Write ( '\n' )
def _AddEqualsMethod ( message_descriptor , cls ) : """Helper for _ AddMessageMethods ( ) ."""
def __eq__ ( self , other ) : if ( not isinstance ( other , message_mod . Message ) or other . DESCRIPTOR != self . DESCRIPTOR ) : return False if self is other : return True if self . DESCRIPTOR . full_name == _AnyFullTypeName : any_a = _InternalUnpackAny ( self ) any_b = _I...
def convert_sequence_to_motor_units ( cycles , unit_converter ) : """Converts a move sequence to motor units . Converts a move sequence to motor units using the provied converter . Parameters cycles : iterable of dicts The iterable of cycles of motion to do one after another . See ` ` compile _ sequence `...
# Make a deep copy of cycles so that the conversions don ' t damage # the original one . cv_cycles = copy . deepcopy ( cycles ) # Go through each cycle and do the conversions . for cycle in cv_cycles : # Go through each of the moves and do the conversions . for move in cycle [ 'moves' ] : move [ 'A' ] = uni...
def _format_subtree ( self , subtree ) : """Recursively format all subtrees ."""
subtree [ 'children' ] = list ( subtree [ 'children' ] . values ( ) ) for child in subtree [ 'children' ] : self . _format_subtree ( child ) return subtree