signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def j0_2 ( a = 1 ) : r"""Hankel transform pair J0_2 ( [ Ande75 ] _ ) ."""
def lhs ( x ) : return np . exp ( - a * x ) def rhs ( b ) : return 1 / np . sqrt ( b ** 2 + a ** 2 ) return Ghosh ( 'j0' , lhs , rhs )
def str2dict_keys ( str_in ) : '''Extracts the keys from a string that represents a dict and returns them sorted by key . Args : str _ in ( string ) that contains python dict Returns : ( list ) with keys or None if no valid dict was found Raises :'''
tmp_dict = str2dict ( str_in ) if tmp_dict is None : return None return sorted ( [ k for k in tmp_dict ] )
def sizeHint ( self , option , index ) : """Reimplements the : meth : ` QStyledItemDelegate . sizeHint ` method ."""
document = QTextDocument ( ) document . setDefaultFont ( option . font ) data = index . model ( ) . data ( index ) text = umbra . ui . common . QVariant_to_string ( data ) self . __label . setText ( text ) document . setHtml ( text ) return QSize ( document . idealWidth ( ) + self . __indent , option . fontMetrics . he...
def _filter_for_scenario ( self ) : """Find the scenario matching the provided scenario name and returns a list . : return : list"""
return [ c . scenario for c in self . _configs if c . scenario . name == self . _scenario_name ]
def main ( ) : '''i2a creates ASCII art from images right on your terminal .'''
arguments = docopt ( __doc__ , version = __version__ ) if arguments [ 'FILE' ] : display_output ( arguments ) else : print ( __doc__ )
def _check_box_toggled ( self , widget , data = None ) : """Function manipulates with entries and buttons ."""
active = widget . get_active ( ) arg_name = data if 'entry' in self . args [ arg_name ] : self . args [ arg_name ] [ 'entry' ] . set_sensitive ( active ) if 'browse_btn' in self . args [ arg_name ] : self . args [ arg_name ] [ 'browse_btn' ] . set_sensitive ( active ) self . path_window . show_all ( )
def enable_scanners_by_ids ( self , scanner_ids ) : """Enable a list of scanner IDs ."""
scanner_ids = ',' . join ( scanner_ids ) self . logger . debug ( 'Enabling scanners with IDs {0}' . format ( scanner_ids ) ) return self . zap . ascan . enable_scanners ( scanner_ids )
def serialize ( self , elt , sw , pyobj , name = None , orig = None , ** kw ) : '''Handles the start and end tags , and attributes . callout to get _ formatted _ content to get the textNode value . Parameters : elt - - ElementProxy / DOM element sw - - SoapWriter instance pyobj - - processed content Key...
objid = _get_idstr ( pyobj ) ns , n = self . get_name ( name , objid ) # nillable el = elt . createAppendElement ( ns , n ) if self . nillable is True and pyobj is Nilled : self . serialize_as_nil ( el ) return None # other attributes self . set_attributes ( el , pyobj ) # soap href attribute unique = self . un...
def alias_item ( self , item_id , alias_id ) : """Adds an ` ` Id ` ` to an ` ` Item ` ` for the purpose of creating compatibility . The primary ` ` Id ` ` of the ` ` Item ` ` is determined by the provider . The new ` ` Id ` ` is an alias to the primary ` ` Id ` ` . If the alias is a pointer to another item , ...
# Implemented from template for # osid . resource . ResourceAdminSession . alias _ resources _ template self . _alias_id ( primary_id = item_id , equivalent_id = alias_id )
def _getDeltas ( self , firstSub , secondSub ) : """Arguments must have " start " and " end " properties which are FrameTimes ."""
startDelta = max ( firstSub . start , secondSub . start ) - min ( firstSub . start , secondSub . start ) endDelta = max ( firstSub . end , secondSub . end ) - min ( firstSub . end , secondSub . end ) return ( startDelta , endDelta )
def cb ( self , elt , sw , pyobj , unsuppressedPrefixes = [ ] ) : """pyobj - - xml . dom . Node . ELEMENT _ NODE"""
# if sw . Known ( pyobj ) : # return if type ( pyobj ) in _stringtypes : elt . createAppendTextNode ( pyobj ) return # # grab document and import node , and append it doc = elt . getDocument ( ) node = doc . importNode ( pyobj , deep = 1 ) child = elt . node . appendChild ( node ) # # copy xmlns : attributes in...
def randomEarlyShared ( store , role ) : """If there are no explicitly - published public index pages to display , find a shared item to present to the user as first ."""
for r in role . allRoles ( ) : share = store . findFirst ( Share , Share . sharedTo == r , sort = Share . storeID . ascending ) if share is not None : return share . sharedItem raise NoSuchShare ( "Why, that user hasn't shared anything at all!" )
def level ( self , channel , axis , npts , * , verbose = True ) : """Subtract the average value of npts at the edge of a given axis . Parameters channel : int or str Channel to level . axis : int Axis to level along . npts : int Number of points to average for each slice . Positive numbers take poin...
warnings . warn ( "level" , category = wt_exceptions . EntireDatasetInMemoryWarning ) channel_index = wt_kit . get_index ( self . channel_names , channel ) channel = self . channels [ channel_index ] # verify npts not zero npts = int ( npts ) if npts == 0 : raise wt_exceptions . ValueError ( "npts must not be zero"...
def _read_gaf_nts ( self , fin_gaf , hdr_only , allow_missing_symbol ) : """Read GAF file . Store annotation data in a list of namedtuples ."""
nts = [ ] ver = None hdrobj = GafHdr ( ) datobj = None # pylint : disable = not - callable ntobj_make = None get_gafvals = None lnum = - 1 line = '' try : with open ( fin_gaf ) as ifstrm : for lnum , line in enumerate ( ifstrm , 1 ) : # Read data if get_gafvals : # print ( lnum , line ) ...
def get_instance_field ( self , field_name ) : """Return the field object with the given name ( works for a bound instance )"""
if not self . has_field ( field_name ) : raise AttributeError ( '"%s" is not a field for the model "%s"' % ( field_name , self . __class__ . __name__ ) ) field = getattr ( self , field_name ) return field
def search_fast ( self , text ) : """do a sloppy quick " search " via the json index"""
resp = self . impl . get ( "{base_url}/{text}/json" . format ( base_url = self . base_url , text = text ) ) return resp . json ( ) [ "info" ] [ "package_url" ]
def record_set ( self , train , labels = None , channel = "train" ) : """Build a : class : ` ~ RecordSet ` from a numpy : class : ` ~ ndarray ` matrix and label vector . For the 2D ` ` ndarray ` ` ` ` train ` ` , each row is converted to a : class : ` ~ Record ` object . The vector is stored in the " values " e...
s3 = self . sagemaker_session . boto_session . resource ( 's3' ) parsed_s3_url = urlparse ( self . data_location ) bucket , key_prefix = parsed_s3_url . netloc , parsed_s3_url . path key_prefix = key_prefix + '{}-{}/' . format ( type ( self ) . __name__ , sagemaker_timestamp ( ) ) key_prefix = key_prefix . lstrip ( '/'...
def xmoe2_v1_l4k ( ) : """With sequence length 4096."""
hparams = xmoe2_v1 ( ) hparams . batch_size = 32 hparams . max_length = 4096 hparams . split_to_length = 4096 hparams . reshape_logits_hack = True return hparams
def add_metadata_sectors ( self , vtoc , sector_list , header ) : """Add track / sector list"""
tslist = BaseSectorList ( header ) for start in range ( 0 , len ( sector_list ) , header . ts_pairs ) : end = min ( start + header . ts_pairs , len ( sector_list ) ) if _xd : log . debug ( "ts: %d-%d" % ( start , end ) ) s = Dos33TSSector ( header , sector_list , start , end ) s . ts_start , s ....
def get_session ( self , token = None ) : '''If provided , the ` token ` parameter is used to initialize an authenticated session , otherwise an unauthenticated session object is generated . Returns an instance of : attr : ` session _ obj ` . . : param token : A token with which to initilize the session . :...
if token is not None : session = self . session_obj ( self . client_id , self . client_secret , token , service = self ) else : # pragma : no cover session = self . session_obj ( self . client_id , self . client_secret , service = self ) return session
def after_this_websocket ( func : Callable ) -> Callable : """Schedule the func to be called after the current websocket . This is useful in situations whereby you want an after websocket function for a specific route or circumstance only , for example , . . note : : The response is an optional argument , a...
_websocket_ctx_stack . top . _after_websocket_functions . append ( func ) return func
def reset_alarm_ranges ( self , parameter ) : """Reset all alarm limits for the specified parameter to their original MDB value ."""
req = mdb_pb2 . ChangeParameterRequest ( ) req . action = mdb_pb2 . ChangeParameterRequest . RESET_ALARMS url = '/mdb/{}/{}/parameters/{}' . format ( self . _instance , self . _processor , parameter ) response = self . _client . post_proto ( url , data = req . SerializeToString ( ) )
def define ( self , key , value ) : """Defines the value for the inputted key by setting both its default and value to the inputted value . : param key | < str > value | < variant >"""
skey = nstr ( key ) self . _defaults [ skey ] = value self [ skey ] = value
def set_blend_equation ( self , mode_rgb , mode_alpha = None ) : """Specify the equation for RGB and alpha blending Parameters mode _ rgb : str Mode for RGB . mode _ alpha : str | None Mode for Alpha . If None , ` ` mode _ rgb ` ` is used . Notes See ` ` set _ blend _ equation ` ` for valid modes ."""
mode_alpha = mode_rgb if mode_alpha is None else mode_alpha self . glir . command ( 'FUNC' , 'glBlendEquationSeparate' , mode_rgb , mode_alpha )
def post_question_answer ( self , number : str , description : str , file_path : str ) -> bool : """上傳特定題目的作業"""
try : # 操作所需資訊 params = { 'hwId' : number } data = { 'FileDesc' : description } files = { 'hwFile' : open ( file_path , 'rb' ) } # 上傳作業 self . __session . get ( self . __url + '/upLoadHw' , params = params , timeout = 0.5 , verify = False ) response = self . __session . post ( self . __url + '/u...
def get_complexes ( self ) : """Extract INDRA Complex Statements from the BioPAX model . This method searches for org . biopax . paxtools . model . level3 . Complex objects which represent molecular complexes . It doesn ' t reuse BioPAX Pattern ' s org . biopax . paxtools . pattern . PatternBox . inComplexWit...
for obj in self . model . getObjects ( ) . toArray ( ) : bpe = _cast_biopax_element ( obj ) if not _is_complex ( bpe ) : continue ev = self . _get_evidence ( bpe ) members = self . _get_complex_members ( bpe ) if members is not None : if len ( members ) > 10 : logger . de...
def make_locations ( locations = None , verbose = True ) : '''Creates folders : param locations : A list of folders to create ( can be a dictionary , see note below ) : param verbose : Warn if any folders were created . . note : : * | params _ locations _ dict | * | param _ locations _ none |'''
from photon . util . structures import to_list from photon . util . system import shell_notify if not locations : locations = get_locations ( ) . values ( ) locations = to_list ( locations ) r = list ( ) for p in reversed ( sorted ( locations ) ) : if not _path . exists ( p ) : _makedirs ( p ) r...
def __get_segments_from_node ( node , graph ) : """Calculates the segments that can emanate from a particular node on the main cycle ."""
list_of_segments = [ ] node_object = graph . get_node ( node ) for e in node_object [ 'edges' ] : list_of_segments . append ( e ) return list_of_segments
def discover ( source ) : "Given a JavaScript file , find the sourceMappingURL line"
source = source . splitlines ( ) # Source maps are only going to exist at either the top or bottom of the document . # Technically , there isn ' t anything indicating * where * it should exist , so we # are generous and assume it ' s somewhere either in the first or last 5 lines . # If it ' s somewhere else in the docu...
def add_bookmark ( request ) : """This view serves and validates a bookmark form . If requested via ajax it also returns the drop bookmark form to replace the add bookmark form ."""
if request . method == "POST" : form = BookmarkForm ( user = request . user , data = request . POST ) if form . is_valid ( ) : bookmark = form . save ( ) if not request . is_ajax ( ) : messages . success ( request , 'Bookmark added' ) if request . POST . get ( 'next' ) : ...
def main ( ) : """MAIN"""
config = { "api" : { "services" : [ { "name" : "my_api" , "testkey" : "testval" , } , ] , "calls" : { "hello_world" : { "delay" : 5 , "priority" : 1 , "arguments" : None , } , "marco" : { "delay" : 1 , "priority" : 1 , } , "pollo" : { "delay" : 1 , "priority" : 1 , } , } } } app = AppBuilder ( [ MyAPI ] , Strategy ( Pr...
def stop ( self ) : """Stop this WriterProcessBase , and reset the cursor ."""
self . stop_flag . value = True with self . lock : ( Control ( ) . text ( C ( ' ' , style = 'reset_all' ) ) . pos_restore ( ) . move_column ( 1 ) . erase_line ( ) . write ( self . file ) )
def send_mail ( self , subject , to , template , ** template_ctx ) : """Utility method to send mail with the ` mail ` template context ."""
if not self . mail : from warnings import warn warn ( 'Attempting to send mail without the mail bundle installed! ' 'Please install it, or fix your configuration.' ) return self . mail . send ( subject , to , template , ** dict ( ** self . security . run_ctx_processor ( 'mail' ) , ** template_ctx ) )
def prop_or ( default , key , dct_or_obj ) : """Ramda propOr implementation . This also resolves object attributes , so key can be a dict prop or an attribute of dct _ or _ obj : param default : Value if dct _ or _ obj doesn ' t have key _ or _ prop or the resolved value is null : param key : : param dct _ ...
# Note that hasattr is a builtin and getattr is a ramda function , hence the different arg position if isinstance ( dict , dct_or_obj ) : value = dct_or_obj [ key ] if has ( key , dct_or_obj ) else default elif isinstance ( object , dct_or_obj ) : value = getattr ( key , dct_or_obj ) if hasattr ( dct_or_obj , k...
def parse_authn_request ( self , enc_request , binding = BINDING_HTTP_REDIRECT ) : """Parse a Authentication Request : param enc _ request : The request in its transport format : param binding : Which binding that was used to transport the message to this entity . : return : A request instance"""
return self . _parse_request ( enc_request , AuthnRequest , "single_sign_on_service" , binding )
def bills ( self , member_id , type = 'introduced' ) : "Same as BillsClient . by _ member"
path = "members/{0}/bills/{1}.json" . format ( member_id , type ) return self . fetch ( path )
def on_message ( self , con , event ) : """Handles messge stanzas"""
msg_type = event . getType ( ) nick = event . getFrom ( ) . getResource ( ) from_jid = event . getFrom ( ) . getStripped ( ) body = event . getBody ( ) if msg_type == 'chat' and body is None : return logger . debug ( 'msg_type[%s] from[%s] nick[%s] body[%s]' % ( msg_type , from_jid , nick , body , ) ) sender = filt...
def from_dataset ( cls , * args , ** kwargs ) : """Create an InteractiveList instance from the given base dataset Parameters % ( ArrayList . from _ dataset . parameters . no _ plotter ) s plotter : psyplot . plotter . Plotter The plotter instance that is used to visualize the data in this list make _ pl...
plotter = kwargs . pop ( 'plotter' , None ) make_plot = kwargs . pop ( 'make_plot' , True ) instance = super ( InteractiveList , cls ) . from_dataset ( * args , ** kwargs ) if plotter is not None : plotter . initialize_plot ( instance , make_plot = make_plot ) return instance
async def tag ( self , name : str , repo : str , * , tag : str = None ) -> bool : """Tag the given image so that it becomes part of a repository . Args : repo : the repository to tag in tag : the name for the new tag"""
params = { "repo" : repo } if tag : params [ "tag" ] = tag await self . docker . _query ( "images/{name}/tag" . format ( name = name ) , "POST" , params = params , headers = { "content-type" : "application/json" } , ) return True
def page_crawled ( self , page_resp ) : """Check if page has been crawled by hashing its text content . Add new pages to the page cache . Return whether page was found in cache ."""
page_text = utils . parse_text ( page_resp ) page_hash = utils . hash_text ( '' . join ( page_text ) ) if page_hash not in self . page_cache : utils . cache_page ( self . page_cache , page_hash , self . args [ 'cache_size' ] ) return False return True
def save_to_txt ( self , path = './' , name = None , include = [ 'Mod' , 'Cls' , 'Exp' , 'Name' ] , fmt = '%.18e' , delimiter = ' ' , footer = '' , encoding = None , verb = True , return_pfe = False ) : """Save the basic geometrical attributes only ( polygon and pos / extent ) The attributes are saved to a txt fi...
if name is None : name = self . Id . generate_SaveName ( include ) if path is None : path = self . Id . SavePath path = os . path . abspath ( path ) pfe = os . path . join ( path , name + '.txt' ) nPno = np . r_ [ self . Poly . shape [ 1 ] , self . noccur ] poly = self . Poly . T posext = np . vstack ( ( self ....
def tokenize_string ( source ) : """Tokenize a Python source code string . Parameters source : str A Python source code string"""
line_reader = StringIO ( source ) . readline token_generator = tokenize . generate_tokens ( line_reader ) # Loop over all tokens till a backtick ( ` ) is found . # Then , take all tokens till the next backtick to form a backtick quoted # string . for toknum , tokval , _ , _ , _ in token_generator : if tokval == '`'...
def bvlpdu_contents ( self , use_dict = None , as_class = dict ) : """Return the contents of an object as a dict ."""
# make / extend the dictionary of content if use_dict is None : use_dict = as_class ( ) # call the normal procedure key_value_contents ( use_dict = use_dict , as_class = as_class , key_values = ( ( 'function' , 'DistributeBroadcastToNetwork' ) , ) ) # this message has data PDUData . dict_contents ( self , use_dict ...
def compilable_sources ( self , sourcedir , absolute = False , recursive = True , excludes = [ ] ) : """Find all scss sources that should be compiled , aka all sources that are not " partials " Sass sources . Args : sourcedir ( str ) : Directory path to scan . Keyword Arguments : absolute ( bool ) : Retur...
filepaths = [ ] for root , dirs , files in os . walk ( sourcedir ) : # Sort structure to avoid arbitrary order dirs . sort ( ) files . sort ( ) for item in files : # Store relative directory but drop it if at root ( ' . ' ) relative_dir = os . path . relpath ( root , sourcedir ) if relative_...
def config_amend_key_ ( self , key , value ) : """This will take a stringified key representation and value and load it into the configuration file for furthur usage . The good part about this method is that it doesn ' t clobber , only appends when keys are missing ."""
cfg_i = self . _cfg keys = key . split ( '.' ) last_key = keys . pop ( ) trail = [ ] for e in keys : cfg_i . setdefault ( e , { } ) cfg_i = cfg_i [ e ] trail . append ( e ) if not isinstance ( cfg_i , dict ) : raise Exception ( '.' . join ( trail ) + ' has conflicting dict/scalar types!' ) cfg_i...
def _payload ( self , * args , ** kwargs ) : '''Find all unmanaged files . Returns maximum 1000 values . Parameters : * * * filter * * : Include only results which path starts from the filter string . * * * time * * : Display time in Unix ticks or format according to the configured TZ ( default ) Values : t...
def _size_format ( size , fmt ) : if fmt is None : return size fmt = fmt . lower ( ) if fmt == "b" : return "{0} Bytes" . format ( size ) elif fmt == "kb" : return "{0} Kb" . format ( round ( ( float ( size ) / 0x400 ) , 2 ) ) elif fmt == "mb" : return "{0} Mb" . form...
def generate ( env ) : """Add Builders and construction variables for the OS / 2 to an Environment ."""
cc . generate ( env ) env [ 'CC' ] = 'icc' env [ 'CCCOM' ] = '$CC $CFLAGS $CCFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET' env [ 'CXXCOM' ] = '$CXX $CXXFLAGS $CPPFLAGS $_CPPDEFFLAGS $_CPPINCFLAGS /c $SOURCES /Fo$TARGET' env [ 'CPPDEFPREFIX' ] = '/D' env [ 'CPPDEFSUFFIX' ] = '' env [ 'INCPREFIX' ] ...
def rename ( self , file_id , new_filename , session = None ) : """Renames the stored file with the specified file _ id . For example : : my _ db = MongoClient ( ) . test fs = GridFSBucket ( my _ db ) # Get _ id of file to rename file _ id = fs . upload _ from _ stream ( " test _ file " , " data I want to...
result = self . _files . update_one ( { "_id" : file_id } , { "$set" : { "filename" : new_filename } } , session = session ) if not result . matched_count : raise NoFile ( "no files could be renamed %r because none " "matched file_id %i" % ( new_filename , file_id ) )
def get_logger ( context = None , name = None ) : """Return a logger for * context * . Return a : class : ` ContextLogger ` instance . The instance implements the standard library ' s : class : ` logging . Logger ` interface ."""
# Many class instances have their own logger . Share them to save memory if # possible , i . e . when * context * is not set . if name is None : name = _logger_name if context is None and name in _logger_dict : return _logger_dict [ name ] if context is not None and not isinstance ( context , six . string_types...
def _addFlushBatch ( self ) : """Sends all waiting documents to Solr"""
if len ( self . _add_batch ) > 0 : language_batches = { } # Create command JSONs for each of language endpoints for lang in self . endpoints : # Append documents with languages without endpoint to default endpoint document_jsons = [ "\"add\":" + json . dumps ( data ) for data in self . _add_batch if...
def heartbeat_tick ( self , rate = 2 ) : """Send heartbeat packets , if necessary , and fail if none have been received recently . This should be called frequently , on the order of once per second . : keyword rate : Ignored"""
if not self . heartbeat : return # treat actual data exchange in either direction as a heartbeat sent_now = self . method_writer . bytes_sent recv_now = self . method_reader . bytes_recv if self . prev_sent is None or self . prev_sent != sent_now : self . last_heartbeat_sent = monotonic ( ) if self . prev_recv ...
def addService ( self , service , name = None , description = None , authenticator = None , expose_request = None , preprocessor = None ) : """Adds a service to the gateway . @ param service : The service to add to the gateway . @ type service : C { callable } , class instance , or a module @ param name : The...
if isinstance ( service , ( int , long , float , basestring ) ) : raise TypeError ( "Service cannot be a scalar value" ) allowed_types = ( types . ModuleType , types . FunctionType , types . DictType , types . MethodType , types . InstanceType , types . ObjectType ) if not python . callable ( service ) and not isin...
def cache_page ( ** kwargs ) : """This decorator is similar to ` django . views . decorators . cache . cache _ page `"""
cache_timeout = kwargs . pop ( 'cache_timeout' , None ) key_prefix = kwargs . pop ( 'key_prefix' , None ) cache_min_age = kwargs . pop ( 'cache_min_age' , None ) decorator = decorators . decorator_from_middleware_with_args ( CacheMiddleware ) ( cache_timeout = cache_timeout , key_prefix = key_prefix , cache_min_age = c...
def translated ( self , * language_codes , ** translated_fields ) : """Only return translated objects which of the given languages . When no language codes are given , only the currently active language is returned . . . note : : Due to Django ` ORM limitations < https : / / docs . djangoproject . com / en / ...
relname = self . model . _parler_meta . root_rel_name if not language_codes : language_codes = ( get_language ( ) , ) filters = { } for field_name , val in six . iteritems ( translated_fields ) : if field_name . startswith ( 'master__' ) : filters [ field_name [ 8 : ] ] = val # avoid translation...
def delete_action ( self , action , player_idx = 0 ) : """Return a new ` Player ` instance with the action ( s ) specified by ` action ` deleted from the action set of the player specified by ` player _ idx ` . Deletion is not performed in place . Parameters action : scalar ( int ) or array _ like ( int ) ...
payoff_array_new = np . delete ( self . payoff_array , action , player_idx ) return Player ( payoff_array_new )
def routeCoverage ( self , msisdn ) : """If the route coverage lookup encounters an error , we will treat it as " not covered " ."""
try : content = self . parseLegacy ( self . request ( 'utils/routeCoverage' , { 'msisdn' : msisdn } ) ) return { 'routable' : True , 'destination' : msisdn , 'charge' : float ( content [ 'Charge' ] ) } except Exception : # If we encounter any error , we will treat it like it ' s " not covered " # TODO perhaps c...
def handle ( self , * args , ** options ) : """Sets options common to all commands . Any command subclassing this object should implement its own handle method , as is standard in Django , and run this method via a super call to inherit its functionality ."""
# Create a data directory self . data_dir = os . path . join ( settings . BASE_DIR , 'data' ) if not os . path . exists ( self . data_dir ) : os . makedirs ( self . data_dir ) # Start the clock self . start_datetime = datetime . now ( )
def check_dependee_exists ( self , depender , dependee , dependee_id ) : """Checks whether a depended - on module is available ."""
shutit_global . shutit_global_object . yield_to_draw ( ) # If the module id isn ' t there , there ' s a problem . if dependee is None : return 'module: \n\n' + dependee_id + '\n\nnot found in paths: ' + str ( self . host [ 'shutit_module_path' ] ) + ' but needed for ' + depender . module_id + '\nCheck your --shutit...
async def nearest_by_coordinates ( self , latitude : float , longitude : float ) -> dict : """Get the nearest report ( with local and state info ) to a lat / lon ."""
# Since user data is more granular than state or CDC data , find the # user report whose coordinates are closest to the provided # coordinates : nearest_user_report = get_nearest_by_coordinates ( await self . user_reports ( ) , 'latitude' , 'longitude' , latitude , longitude ) try : # If the user report corresponds to ...
def getPhotos ( self , tags = '' , per_page = '' , page = '' ) : """Get a list of photo objects for this group"""
method = 'flickr.groups.pools.getPhotos' data = _doget ( method , group_id = self . id , tags = tags , per_page = per_page , page = page ) photos = [ ] for photo in data . rsp . photos . photo : photos . append ( _parse_photo ( photo ) ) return photos
def generate ( self , output_path = None , in_memory = False ) : """Executes the Statik project generator . Args : output _ path : The path to which to write output files . in _ memory : Whether or not to generate the results in memory . If True , this will generate the output result as a dictionary . If Fa...
result = dict ( ) if in_memory else 0 logger . info ( "Generating Statik build..." ) try : if output_path is None and not in_memory : raise InternalError ( "If project is not to be generated in-memory, an output path must be specified" ) self . error_context . update ( filename = self . config_file_path...
def _obtem_doctype ( self , xml ) : """Obtém DOCTYPE do XML Determina o tipo de arquivo que vai ser assinado , procurando pela tag correspondente ."""
doctype = None # XML da NF - e if '</NFe>' in xml : doctype = '<!DOCTYPE NFe [<!ATTLIST infNFe Id ID #IMPLIED>]>' elif '</cancNFe>' in xml : doctype = '<!DOCTYPE cancNFe [<!ATTLIST infCanc Id ID #IMPLIED>]>' elif '</inutNFe>' in xml : doctype = '<!DOCTYPE inutNFe [<!ATTLIST infInut Id ID #IMPLIED>]>' elif '...
def libvlc_media_player_set_rate ( p_mi , rate ) : '''Set movie play rate . @ param p _ mi : the Media Player . @ param rate : movie play rate to set . @ return : - 1 if an error was detected , 0 otherwise ( but even then , it might not actually work depending on the underlying media protocol ) .'''
f = _Cfunctions . get ( 'libvlc_media_player_set_rate' , None ) or _Cfunction ( 'libvlc_media_player_set_rate' , ( ( 1 , ) , ( 1 , ) , ) , None , ctypes . c_int , MediaPlayer , ctypes . c_float ) return f ( p_mi , rate )
def create_radius_stops ( breaks , min_radius , max_radius ) : """Convert a data breaks into a radius ramp"""
num_breaks = len ( breaks ) radius_breaks = scale_between ( min_radius , max_radius , num_breaks ) stops = [ ] for i , b in enumerate ( breaks ) : stops . append ( [ b , radius_breaks [ i ] ] ) return stops
def stop_instances ( self , instance_ids = None , force = False ) : """Stop the instances specified : type instance _ ids : list : param instance _ ids : A list of strings of the Instance IDs to stop : type force : bool : param force : Forces the instance to stop : rtype : list : return : A list of the ...
params = { } if force : params [ 'Force' ] = 'true' if instance_ids : self . build_list_params ( params , instance_ids , 'InstanceId' ) return self . get_list ( 'StopInstances' , params , [ ( 'item' , Instance ) ] , verb = 'POST' )
def end_y ( self ) : """Return the Y - position of the end point of this connector , in English Metric Units ( as a | Length | object ) ."""
cxnSp = self . _element y , cy , flipV = cxnSp . y , cxnSp . cy , cxnSp . flipV end_y = y if flipV else y + cy return Emu ( end_y )
def get_position_p ( self ) : """Get the P value of the current PID for position"""
data = [ ] data . append ( 0x09 ) data . append ( self . servoid ) data . append ( RAM_READ_REQ ) data . append ( POSITION_KP_RAM ) data . append ( BYTE2 ) send_data ( data ) rxdata = [ ] try : rxdata = SERPORT . read ( 13 ) return ( ord ( rxdata [ 10 ] ) * 256 ) + ( ord ( rxdata [ 9 ] ) & 0xff ) except Herkule...
def create ( self , ** kwargs ) : '''Create a cluster of BIG - IP ® devices . : param kwargs : dict - - keyword arguments for cluster manager'''
try : cluster = getattr ( self , "cluster" , None ) except NoClusterToManage : cluster = None if cluster is not None : msg = 'The ClusterManager is already managing a cluster.' raise AlreadyManagingCluster ( msg ) self . _check_device_number ( kwargs [ 'devices' ] ) self . trust_domain . create ( device...
def _dump ( config_instance , dict_type = OrderedDict ) : """Dumps an instance from ` ` instance ` ` to a dictionary type mapping . : param object instance : The instance to serialized to a dictionary : param object dict _ type : Some dictionary type , defaults to ` ` OrderedDict ` ` : return : Dumped diction...
if not is_config ( config_instance ) : raise ValueError ( f"cannot dump instance {config_instance!r} to dict, " "instance is not a config class" ) result = dict_type ( ) for var in attr . fields ( config_instance . __class__ ) : if not is_config_var ( var ) : continue entry = var . metadata [ CONFIG...
def addSuccess ( self , test , capt ) : """After test completion , we want to record testcase run information ."""
self . __insert_test_result ( constants . State . PASS , test )
def probe_enable ( cls , resource ) : """Activate a probe on a webaccelerator"""
oper = cls . call ( 'hosting.rproxy.probe.enable' , cls . usable_id ( resource ) ) cls . echo ( 'Activating probe on %s' % resource ) cls . display_progress ( oper ) cls . echo ( 'The probe have been activated' ) return oper
def mkdir_p ( path ) : """Emulates ' mkdir - p ' in bash : param path : ( str ) Path to create : return : None : raises CommandError"""
log = logging . getLogger ( mod_logger + '.mkdir_p' ) if not isinstance ( path , basestring ) : msg = 'path argument is not a string' log . error ( msg ) raise CommandError ( msg ) log . info ( 'Attempting to create directory: %s' , path ) try : os . makedirs ( path ) except OSError as e : if e . er...
def abi_to_fasta ( input , output ) : '''Converts ABI or AB1 files to FASTA format . Args : input ( str ) : Path to a file or directory containing abi / ab1 files or zip archives of abi / ab1 files output ( str ) : Path to a directory for the output FASTA files'''
direcs = [ input , ] # unzip any zip archives zip_files = list_files ( input , [ 'zip' ] ) if zip_files : direcs . extend ( _process_zip_files ( zip_files ) ) # convert files for d in direcs : files = list_files ( d , [ 'ab1' , 'abi' ] ) seqs = [ SeqIO . read ( open ( f , 'rb' ) , 'abi' ) for f in files ] ...
def contents ( self , path ) : """Reads the given path of current ref _ head and returns its content as utf - 8"""
try : out , code , err = self . command_exec ( [ 'cat-file' , '-p' , self . ref_head + ':' + path ] ) if not code : return out . decode ( 'utf-8' ) except Exception : pass return None
def disconnect ( self , cback , subscribers = None , instance = None ) : """Remove a previously added function or method from the set of the signal ' s handlers . : param cback : the callback ( or * handler * ) to be added to the set : returns : ` ` None ` ` or the value returned by the corresponding wrapper"...
if subscribers is None : subscribers = self . subscribers # wrapper if self . _fdisconnect is not None : def _disconnect ( cback ) : self . _disconnect ( subscribers , cback ) notify = partial ( self . _notify_one , instance ) if instance is not None : result = self . _fdisconnect ( inst...
def hourly_dew_point_values ( self , dry_bulb_condition ) : """Get a list of dew points ( C ) at each hour over the design day . args : dry _ bulb _ condition : The dry bulb condition for the day ."""
hourly_dew_point = [ ] max_dpt = self . dew_point ( dry_bulb_condition . dry_bulb_max ) for db in dry_bulb_condition . hourly_values : if db >= max_dpt : hourly_dew_point . append ( max_dpt ) else : hourly_dew_point . append ( db ) return hourly_dew_point
def add_schedule ( self , name , activation_date , day_period = 'one_time' , final_action = 'ALERT_FAILURE' , activated = True , minute_period = 'one_time' , day_mask = None , repeat_until_date = None , comment = None ) : """Add a schedule to an existing task . : param str name : name for this schedule : param ...
json = { 'name' : name , 'activation_date' : activation_date , 'day_period' : day_period , 'day_mask' : day_mask , 'activated' : activated , 'final_action' : final_action , 'minute_period' : minute_period , 'repeat_until_date' : repeat_until_date if repeat_until_date else None , 'comment' : comment } if 'daily' in day_...
def _multiseries ( self , col , x , y , ctype , rsum , rmean ) : """Chart multiple series from a column distinct values"""
self . autoprint = False x , y = self . _check_fields ( x , y ) chart = None series = self . split_ ( col ) for key in series : instance = series [ key ] if rsum is not None : instance . rsum ( rsum , index_col = x ) if rmean is not None : instance . rmean ( rmean , index_col = x ) insta...
def mils_standard ( T , K , P , f , g , c , d , h , a , M , UB , phi ) : """mils _ standard : standard formulation for the multi - item , multi - stage lot - sizing problem Parameters : - T : number of periods - K : set of resources - P : set of items - f [ t , p ] : set - up costs ( on period t , for pro...
model = Model ( "multi-stage lotsizing -- standard formulation" ) y , x , I = { } , { } , { } Ts = range ( 1 , T + 1 ) for p in P : for t in Ts : y [ t , p ] = model . addVar ( vtype = "B" , name = "y(%s,%s)" % ( t , p ) ) x [ t , p ] = model . addVar ( vtype = "C" , name = "x(%s,%s)" % ( t , p ) ) ...
def exists ( self , filename ) : """Report whether a file exists on the distribution point . Determines file type by extension . Args : filename : Filename you wish to check . ( No path ! e . g . : " AdobeFlashPlayer - 14.0.0.176 . pkg " )"""
if is_package ( filename ) : filepath = os . path . join ( self . connection [ "mount_point" ] , "Packages" , filename ) else : filepath = os . path . join ( self . connection [ "mount_point" ] , "Scripts" , filename ) return os . path . exists ( filepath )
def copy ( self ) : """Copy constructor for Sequence objects ."""
return Sequence ( self . name , self . sequenceData , self . start , self . end , self . strand , self . remaining , self . meta_data , self . mutableString )
def create_column_index ( annotations ) : """Create a pd . MultiIndex using the column names and any categorical rows . Note that also non - main columns will be assigned a default category ' ' ."""
_column_index = OrderedDict ( { 'Column Name' : annotations [ 'Column Name' ] } ) categorical_rows = annotation_rows ( 'C:' , annotations ) _column_index . update ( categorical_rows ) numerical_rows = { name : [ float ( x ) if x != '' else float ( 'NaN' ) for x in values ] for name , values in annotation_rows ( 'N:' , ...
def _sampleLocationOnSide ( self ) : """Helper method to sample from the lateral surface of a cylinder ."""
z = random . uniform ( - 1 , 1 ) * self . height / 2. sampledAngle = 2 * random . random ( ) * pi x , y = self . radius * cos ( sampledAngle ) , self . radius * sin ( sampledAngle ) return [ x , y , z ]
def addInkAnnot ( self , list ) : """Add a ' handwriting ' as a list of list of point - likes . Each sublist forms an independent stroke ."""
CheckParent ( self ) val = _fitz . Page_addInkAnnot ( self , list ) if not val : return val . thisown = True val . parent = weakref . proxy ( self ) self . _annot_refs [ id ( val ) ] = val return val
def libvlc_vlm_add_vod ( p_instance , psz_name , psz_input , i_options , ppsz_options , b_enabled , psz_mux ) : '''Add a vod , with one input . @ param p _ instance : the instance . @ param psz _ name : the name of the new vod media . @ param psz _ input : the input MRL . @ param i _ options : number of add...
f = _Cfunctions . get ( 'libvlc_vlm_add_vod' , None ) or _Cfunction ( 'libvlc_vlm_add_vod' , ( ( 1 , ) , ( 1 , ) , ( 1 , ) , ( 1 , ) , ( 1 , ) , ( 1 , ) , ( 1 , ) , ) , None , ctypes . c_int , Instance , ctypes . c_char_p , ctypes . c_char_p , ctypes . c_int , ListPOINTER ( ctypes . c_char_p ) , ctypes . c_int , ctypes...
def fft_mesh ( self , kpoint , band , spin = 0 , shift = True ) : """Places the coefficients of a wavefunction onto an fft mesh . Once the mesh has been obtained , a discrete fourier transform can be used to obtain real - space evaluation of the wavefunction . The output of this function can be passed directl...
mesh = np . zeros ( tuple ( self . ng ) , dtype = np . complex ) tcoeffs = self . coeffs [ spin ] [ kpoint ] [ band ] if self . spin == 2 else self . coeffs [ kpoint ] [ band ] for gp , coeff in zip ( self . Gpoints [ kpoint ] , tcoeffs ) : t = tuple ( gp . astype ( np . int ) + ( self . ng / 2 ) . astype ( np . in...
def highlight_block ( self , text ) : """Implement specific highlight for Python ."""
text = to_text_string ( text ) prev_state = tbh . get_state ( self . currentBlock ( ) . previous ( ) ) if prev_state == self . INSIDE_DQ3STRING : offset = - 4 text = r'""" ' + text elif prev_state == self . INSIDE_SQ3STRING : offset = - 4 text = r"''' " + text elif prev_state == self . INSIDE_DQSTRING :...
def get ( self , hook_id ) : """Get a webhook ."""
path = '/' . join ( [ 'notification' , 'webhook' , hook_id ] ) return self . rachio . get ( path )
def partial_results ( self ) : '''The results that the RPC has received * so far * This may also be the complete results if : attr : ` complete ` is ` ` True ` ` .'''
results = [ ] for r in self . _results : if isinstance ( r , Exception ) : results . append ( type ( r ) ( * deepcopy ( r . args ) ) ) elif hasattr ( r , "__iter__" ) and not hasattr ( r , "__len__" ) : # pass generators straight through results . append ( r ) else : results . append...
def _columns_for_table ( table_name ) : """Return all of the columns registered for a given table . Parameters table _ name : str Returns columns : dict of column wrappers Keys will be column names ."""
return { cname : col for ( tname , cname ) , col in _COLUMNS . items ( ) if tname == table_name }
def create_cancel_operation ( cls , cancel_operation , ** kwargs ) : """Create CancelOperation Create a new CancelOperation This method makes a synchronous HTTP request by default . To make an asynchronous HTTP request , please pass async = True > > > thread = api . create _ cancel _ operation ( cancel _ op...
kwargs [ '_return_http_data_only' ] = True if kwargs . get ( 'async' ) : return cls . _create_cancel_operation_with_http_info ( cancel_operation , ** kwargs ) else : ( data ) = cls . _create_cancel_operation_with_http_info ( cancel_operation , ** kwargs ) return data
def value ( self ) : """Return the current evaluation of a condition statement"""
return '' . join ( map ( str , self . evaluate ( self . trigger . user ) ) )
def _add_rule ( self , state , rule ) : """Parse rule and add it to machine ( for internal use ) ."""
if rule . strip ( ) == "-" : parsed_rule = None else : parsed_rule = rule . split ( ',' ) if ( len ( parsed_rule ) != 3 or parsed_rule [ 1 ] not in [ 'L' , 'N' , 'R' ] or len ( parsed_rule [ 2 ] ) > 1 ) : raise SyntaxError ( 'Wrong format of rule: ' + rule ) if parsed_rule [ 0 ] == "" : ...
def sg_log ( tensor , opt ) : r"""Log transform a dense tensor See ` tf . log ( ) ` in tensorflow . Args : tensor : A ` Tensor ` ( automatically given by chain ) opt : name : If provided , replace current tensor ' s name . Returns : A ` Tensor ` ."""
return tf . log ( tensor + tf . sg_eps , name = opt . name )
def instance ( self ) : """Content instance of the wrapped object"""
if self . _instance is None : logger . debug ( "SuperModel::instance: *Wakup object*" ) self . _instance = api . get_object ( self . brain ) return self . _instance
def remove ( self ) : '''a method to remove collection and all records in the collection : return : string with confirmation of deletion'''
_title = '%s.remove' % self . __class__ . __name__ # TODO error handling is turned off to avoid system blocking # fix potential to create artifacts in the system # remove collection tree try : import shutil shutil . rmtree ( self . collection_folder , ignore_errors = True ) except : raise Exception ( '%s fa...
def start ( self , num_processes : Optional [ int ] = 1 , max_restarts : int = None ) -> None : """Starts this server in the ` . IOLoop ` . By default , we run the server in this process and do not fork any additional child process . If num _ processes is ` ` None ` ` or < = 0 , we detect the number of cores ...
assert not self . _started self . _started = True if num_processes != 1 : process . fork_processes ( num_processes , max_restarts ) sockets = self . _pending_sockets self . _pending_sockets = [ ] self . add_sockets ( sockets )
def post ( self , url , post_params = None ) : """Make an HTTP POST request to the Parser API . : param url : url to which to make the request : param post _ params : POST data to send along . Expected to be a dict ."""
post_params [ 'token' ] = self . token params = urlencode ( post_params ) logger . debug ( 'Making POST request to %s with body %s' , url , params ) return requests . post ( url , data = params )
def _GetRow ( self , columns = None ) : """Returns the current row as a tuple ."""
row = self . _table [ self . _row_index ] if columns : result = [ ] for col in columns : if col not in self . header : raise TableError ( "Column header %s not known in table." % col ) result . append ( row [ self . header . index ( col ) ] ) row = result return row
def get_all_related_many_to_many_objects ( opts ) : """Django 1.8 changed meta api , see docstr in compat . get _ all _ related _ objects ( ) : param opts : Options instance : return : list of many - to - many relations"""
if django . VERSION < ( 1 , 9 ) : return opts . get_all_related_many_to_many_objects ( ) else : return [ r for r in opts . related_objects if r . field . many_to_many ]