signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
async def on_raw_error ( self , message ) : """Server encountered an error and will now close the connection ."""
error = protocol . ServerError ( ' ' . join ( message . params ) ) await self . on_data_error ( error )
def system_procRet ( str_command , b_echoCommand = 0 ) : """Run the < str _ command > on the underlying shell . Any stderr stream is lost . RETURN Tuple ( retcode , str _ stdout ) o retcode : the system return code o str _ stdout : the standard output stream"""
if b_echoCommand : printf ( '<p>str_command = %s</p>' , str_command ) str_stdout = os . popen ( str_command ) . read ( ) retcode = os . popen ( str_command ) . close ( ) return retcode , str_stdout
def fundb ( self , fields = None , min_volume = 0 , min_discount = 0 , forever = False ) : """以字典形式返回分级B数据 : param fields : 利率范围 , 形如 [ ' + 3.0 % ' , ' 6.0 % ' ] : param min _ volume : 最小交易量 , 单位万元 : param min _ discount : 最小折价率 , 单位 % : param forever : 是否选择永续品种 , 默认 False"""
if fields is None : fields = [ ] # 添加当前的ctime self . __fundb_url = self . __fundb_url . format ( ctime = int ( time . time ( ) ) ) # 请求数据 rep = requests . get ( self . __fundb_url ) # 获取返回的json字符串 fundbjson = json . loads ( rep . text ) # 格式化返回的json字符串 data = self . formatfundbjson ( fundbjson ) # 过滤小于指定交易量的数据 if m...
def get_response ( sock , buffer_size = 4096 ) : """Helper method for retrieving a response from a given socket . Returns two values in a tuple , the first is the reponse line and the second is any extra data after the newline ."""
response = "" extra = "" while True : try : chunk = sock . recv ( buffer_size ) if chunk : response += chunk except socket . error as e : if e . errno not in [ errno . EAGAIN , errno . EINTR ] : raise if not response : break if "\n" in response : ...
def draw_text ( self , text : str , x : float , y : float , * , font_name : str , font_size : float , fill : Color ) -> None : """Draws the given text at x , y ."""
pass
def info ( self ) : """Retrieves the design document view information data , returns dictionary GET databasename / _ design / { ddoc } / _ info"""
ddoc_info = self . r_session . get ( '/' . join ( [ self . document_url , '_info' ] ) ) ddoc_info . raise_for_status ( ) return response_to_json_dict ( ddoc_info )
def section_lengths ( neurites , neurite_type = NeuriteType . all ) : '''section lengths in a collection of neurites'''
return map_sections ( _section_length , neurites , neurite_type = neurite_type )
def convertToNative ( self , aVal ) : """Convert to native bool ; interpret certain strings ."""
if aVal is None : return None if isinstance ( aVal , bool ) : return aVal # otherwise interpret strings return str ( aVal ) . lower ( ) in ( '1' , 'on' , 'yes' , 'true' )
def on_purchase_completed ( self , mapping = { 'payload' : 'payload' , 'name' : 'name' , 'status' : 'status' , 'token' : 'token' } , convert = { } , default = { } ) : """Decorator routes an Connections . Response to the wrapped function . Request is sent when Alexa completes the purchase flow . See https : / / ...
def decorator ( f ) : self . _intent_view_funcs [ 'Connections.Response' ] = f self . _intent_mappings [ 'Connections.Response' ] = mapping self . _intent_converts [ 'Connections.Response' ] = convert self . _intent_defaults [ 'Connections.Response' ] = default @ wraps ( f ) def wrapper ( * args...
def forwards ( self , orm ) : "Write your forwards methods here ."
projects = orm [ 'samples.Project' ] . objects . exclude ( name = DEFAULT_PROJECT_NAME ) for project in projects : cohort = orm [ 'samples.Cohort' ] ( name = project . label , autocreated = True ) cohort . project = project cohort . save ( ) cohort_bulk_add ( orm , cohort , orm [ 'samples.Sample' ] . ob...
def palette ( hues , saturations , values ) : """Generate a palette . Parameters hues : ` int ` Number of hues . saturations : ` int ` Number of saturations . values : ` int ` Number of values . Raises ValueError If ` hues ` * ` saturations ` * ` values ` > 256 or min ( ` hues ` , ` saturation...
size = hues * saturations * values if size > 256 : raise ValueError ( 'palette size > 256: {0}' . format ( size ) ) if min ( hues , saturations , values ) < 1 : raise ValueError ( 'invalid palette size: {0} {1} {2}' . format ( hues , saturations , values ) ) ret = [ ] if hues == 1 and saturations == 1 : if ...
def getIndicesFromBigIndex ( self , bigIndex ) : """Get index set from given big index @ param bigIndex @ return index set @ note no checks are performed to ensure that the returned big index is valid"""
indices = numpy . array ( [ 0 for i in range ( self . ndims ) ] ) for i in range ( self . ndims ) : indices [ i ] = bigIndex // self . dimProd [ i ] % self . dims [ i ] return indices
def encode_arc ( self , coords ) : """Appends commands to _ geometry to create an arc . - Returns False if nothing was added - Returns True and moves _ last _ x , _ last _ y if some points where added"""
last_x , last_y = self . _last_x , self . _last_y float_x , float_y = next ( coords ) x , y = self . coords_on_grid ( float_x , float_y ) dx , dy = x - last_x , y - last_y cmd_encoded = encode_cmd_length ( CMD_MOVE_TO , 1 ) commands = [ cmd_encoded , zigzag ( dx ) , zigzag ( dy ) , CMD_FAKE ] pairs_added = 0 last_x , l...
def setup ( self , ** kwargs ) : '''This is called during production de - trending , prior to calling the : py : obj : ` Detrender . run ( ) ` method . : param str parent _ model : The name of the model to operate on . Default ` nPLD `'''
# Load the parent model self . parent_model = kwargs . get ( 'parent_model' , 'nPLD' ) if not self . load_model ( self . parent_model ) : raise Exception ( 'Unable to load parent model.' ) # Save static copies of the de - trended flux , # the outlier mask and the lambda array self . _norm = np . array ( self . flux...
def clone ( self ) : """Returns : Todo : an exact copy of self"""
clone = copy . copy ( self ) clone . _unused = clone . _unused . clone ( ) clone . alarms = copy . copy ( self . alarms ) return clone
def populateFromFile ( self , dataUrl ) : """Populates the instance variables of this RnaQuantificationSet from the specified data URL ."""
self . _dbFilePath = dataUrl self . _db = SqliteRnaBackend ( self . _dbFilePath ) self . addRnaQuants ( )
def get_hashes ( self , all_hashes = False ) : """Returns a list of hashes in hashcat - firendly format for tickets with encryption type 23 ( which is RC4) all _ hashes : overrides the encryption type filtering and returns hash for all tickets"""
hashes = [ ] for cred in self . credentials : res = Ticket . load ( cred . ticket . to_asn1 ( ) ) . native if int ( res [ 'enc-part' ] [ 'etype' ] ) == 23 or all_hashes == True : hashes . append ( cred . to_hash ( ) ) return hashes
def put ( self , session ) : """Return a session to the pool . Never blocks : if the pool is full , raises . : type session : : class : ` ~ google . cloud . spanner _ v1 . session . Session ` : param session : the session being returned . : raises : : exc : ` six . moves . queue . Full ` if the queue is ful...
self . _sessions . put_nowait ( ( _NOW ( ) + self . _delta , session ) )
def publish_server_opened ( self , server_address , topology_id ) : """Publish a ServerOpeningEvent to all server listeners . : Parameters : - ` server _ address ` : The address ( host / port pair ) of the server . - ` topology _ id ` : A unique identifier for the topology this server is a part of ."""
event = ServerOpeningEvent ( server_address , topology_id ) for subscriber in self . __server_listeners : try : subscriber . opened ( event ) except Exception : _handle_exception ( )
def mnist_extract_labels ( filename , num_images ) : """Extract the labels into a 1 - hot matrix [ image index , label index ] ."""
print ( 'Extracting' , filename ) with gzip . open ( filename ) as bytestream : bytestream . read ( 8 ) buf = bytestream . read ( 1 * num_images ) labels = np . frombuffer ( buf , dtype = np . uint8 ) # Convert to dense 1 - hot representation . return ( np . arange ( 10 ) == labels [ : , None ] ) . astype (...
def _find_func ( self , operation ) : """Find the function to use to configure the given operation . The input might be an ` Operation ` enum or a string ."""
if isinstance ( operation , Operation ) : operation_name = operation . name . lower ( ) else : operation_name = operation . lower ( ) return getattr ( self , "configure_{}" . format ( operation_name ) )
def md5sum_is_current ( src_file ) : """Checks whether src _ file has the same md5 hash as the one on disk"""
src_md5 = get_md5sum ( src_file ) src_md5_file = src_file + '.md5' if os . path . exists ( src_md5_file ) : with open ( src_md5_file , 'r' ) as file_checksum : ref_md5 = file_checksum . read ( ) return src_md5 == ref_md5 return False
def read_pixel_register ( self , pix_regs = None , dcs = range ( 40 ) , overwrite_config = False ) : '''The function reads the pixel register , interprets the data and returns a masked numpy arrays with the data for the chosen pixel register . Pixels without any data are masked . Parameters pix _ regs : itera...
if pix_regs is None : pix_regs = [ "EnableDigInj" , "Imon" , "Enable" , "C_High" , "C_Low" , "TDAC" , "FDAC" ] self . register_utils . send_commands ( self . register . get_commands ( "ConfMode" ) ) result = [ ] for pix_reg in pix_regs : pixel_data = np . ma . masked_array ( np . zeros ( shape = ( 80 , 336 ) , ...
def sqlvm_group_create ( client , cmd , sql_virtual_machine_group_name , resource_group_name , location , sql_image_offer , sql_image_sku , domain_fqdn , cluster_operator_account , sql_service_account , storage_account_url , storage_account_key , cluster_bootstrap_account = None , file_share_witness_path = None , ou_pa...
tags = tags or { } # Create the windows server failover cluster domain profile object . wsfc_domain_profile_object = WsfcDomainProfile ( domain_fqdn = domain_fqdn , ou_path = ou_path , cluster_bootstrap_account = cluster_bootstrap_account , cluster_operator_account = cluster_operator_account , sql_service_account = sql...
def pss ( self ) : """Peirce ( Hansen - Kuipers , True ) Skill Score ( ad - bc ) / ( ( a + c ) ( b + d ) )"""
return ( self . table [ 0 , 0 ] * self . table [ 1 , 1 ] - self . table [ 0 , 1 ] * self . table [ 1 , 0 ] ) / ( ( self . table [ 0 , 0 ] + self . table [ 1 , 0 ] ) * ( self . table [ 0 , 1 ] + self . table [ 1 , 1 ] ) )
def _elbv2_load_balancer ( self , lookup ) : """Args : lookup : the friendly name of the V2 elb to look up Returns : A dict with the load balancer description Raises : botocore . exceptions . ClientError : no such load - balancer"""
client = EFAwsResolver . __CLIENTS [ 'elbv2' ] elbs = client . describe_load_balancers ( Names = [ lookup ] ) # getting the first one , since we requested only one lb elb = elbs [ 'LoadBalancers' ] [ 0 ] return elb
def _delete ( self , ) : """Internal implementation for deleting a reftrack . This will just delete the reftrack , set the children to None , update the status , and the rootobject . If the object is an alien , it will also set the parent to None , so it dissapears from the model . : returns : None : rtyp...
refobjinter = self . get_refobjinter ( ) refobjinter . delete ( self . get_refobj ( ) ) self . set_refobj ( None , setParent = False ) if self . alien ( ) : # it should not be in the scene # so also remove it from the model # so we cannot load it again parent = self . get_parent ( ) if parent : parent ....
def grid ( metadata , layout , params ) : """layout : numpy arrays x , y metadata : user - defined numpy arrays with metadata n _ layer : number of cells in the layer ( squared ) n _ tile : number of cells in the tile ( squared )"""
x = layout [ "x" ] y = layout [ "y" ] x_min = np . min ( x ) x_max = np . max ( x ) y_min = np . min ( y ) y_max = np . max ( y ) # this creates the grid bins = np . linspace ( x_min , x_max , params [ "n_layer" ] - 1 ) xd = np . digitize ( x , bins ) bins = np . linspace ( y_min , y_max , params [ "n_layer" ] - 1 ) yd...
def waitForNetworkCoverage ( self , timeout = None ) : """Block until the modem has GSM network coverage . This method blocks until the modem is registered with the network and the signal strength is greater than 0 , optionally timing out if a timeout was specified : param timeout : Maximum time to wait for...
block = [ True ] if timeout != None : # Set up a timeout mechanism def _cancelBlock ( ) : block [ 0 ] = False t = threading . Timer ( timeout , _cancelBlock ) t . start ( ) ss = - 1 checkCreg = True while block [ 0 ] : if checkCreg : cregResult = lineMatching ( r'^\+CREG:\s*(\d),(\d)$' ,...
def cli ( env , identifier , hardware_identifier , virtual_identifier ) : """Attach devices to a ticket ."""
ticket_mgr = SoftLayer . TicketManager ( env . client ) if hardware_identifier and virtual_identifier : raise exceptions . ArgumentError ( "Cannot attach hardware and a virtual server at the same time" ) if hardware_identifier : hardware_mgr = SoftLayer . HardwareManager ( env . client ) hardware_id = helpe...
def _makeJobSuccessorReadyToRun ( self , jobGraph , jobNode ) : """make a successor job ready to run , returning False if they should not yet be run"""
successorJobStoreID = jobNode . jobStoreID # Build map from successor to predecessors . if successorJobStoreID not in self . toilState . successorJobStoreIDToPredecessorJobs : self . toilState . successorJobStoreIDToPredecessorJobs [ successorJobStoreID ] = [ ] self . toilState . successorJobStoreIDToPredecessorJob...
def init_parser ( cls , parser ) : """Initialize argument parser"""
subparsers = parser . add_subparsers ( title = 'Search domain' ) # Compound subcommand parser_compound = subparsers . add_parser ( 'compound' , help = 'Search in compounds' ) parser_compound . set_defaults ( which = 'compound' ) parser_compound . add_argument ( '--id' , '-i' , dest = 'id' , metavar = 'id' , action = Fi...
def _make_set ( var ) : '''Force var to be a set'''
if var is None : return set ( ) if not isinstance ( var , list ) : if isinstance ( var , six . string_types ) : var = var . split ( ) else : var = list ( var ) return set ( var )
def _encode_list ( name , value , check_keys , opts ) : """Encode a list / tuple ."""
lname = gen_list_name ( ) data = b"" . join ( [ _name_value_to_bson ( next ( lname ) , item , check_keys , opts ) for item in value ] ) return b"\x04" + name + _PACK_INT ( len ( data ) + 5 ) + data + b"\x00"
def unload ( self , core ) : """http : / / wiki . apache . org / solr / CoreAdmin # head - f5055a885932e2c25096a8856de840b06764d143"""
params = { 'action' : 'UNLOAD' , 'core' : core , } return self . _get_url ( self . url , params = params )
def set_user_presence ( self , userid , presence ) : '''set presence of user'''
response , status_code = self . __pod__ . Presence . post_v2_user_uid_presence ( sessionToken = self . __session__ , uid = userid , presence = presence ) . result ( ) self . logger . debug ( '%s: %s' % ( status_code , response ) ) return status_code , response
def send ( self , datum ) : """Send * datum * ( e . g . a sentence or MRS ) to ACE . Warning : Sending data without reading ( e . g . , via : meth : ` receive ` ) can fill the buffer and cause data to be lost . Use the : meth : ` interact ` method for most data - processing tasks with ACE ."""
try : self . _p . stdin . write ( ( datum . rstrip ( ) + '\n' ) ) self . _p . stdin . flush ( ) except ( IOError , OSError ) : # ValueError if file was closed manually logging . info ( 'Attempted to write to a closed process; attempting to reopen' ) self . _open ( ) self . _p . stdin . write ( ( dat...
def which ( program ) : """Locate ` program ` in PATH Arguments : program ( str ) : Name of program , e . g . " python " """
def is_exe ( fpath ) : if os . path . isfile ( fpath ) and os . access ( fpath , os . X_OK ) : return True return False for path in os . environ [ "PATH" ] . split ( os . pathsep ) : for ext in os . getenv ( "PATHEXT" , "" ) . split ( os . pathsep ) : fname = program + ext . lower ( ) ...
def find_by_id ( self , project_membership , params = { } , ** options ) : """Returns the project membership record . Parameters project _ membership : { Id } Globally unique identifier for the project membership . [ params ] : { Object } Parameters for the request"""
path = "/project_memberships/%s" % ( project_membership ) return self . client . get ( path , params , ** options )
async def _wrap_gen ( self , ID : str ) : """异步迭代器包装 . Parameters : ID ( str ) : - 任务ID Yield : ( Any ) : - 从异步迭代器结果队列中获取的结果 Raise : ( StopAsyncIteration ) : - 异步迭代器终止时抛出该异常"""
while True : result = await self . _gens_queue [ ID ] . get ( ) if isinstance ( result , StopAsyncIteration ) : del self . _gens_queue [ ID ] break else : yield result
def file_delete ( context , id , file_id ) : """file _ delete ( context , id , path ) Delete a component file > > > dcictl component - file - delete [ OPTIONS ] : param string id : ID of the component to delete file [ required ] : param string file _ id : ID for the file to delete [ required ]"""
component . file_delete ( context , id = id , file_id = file_id )
def get_rrsets_by_type_owner ( self , zone_name , rtype , owner_name , q = None , ** kwargs ) : """Returns the list of RRSets in the specified zone of the specified type . Arguments : zone _ name - - The name of the zone . rtype - - The type of the RRSets . This can be numeric ( 1 ) or if a well - known nam...
uri = "/v1/zones/" + zone_name + "/rrsets/" + rtype + "/" + owner_name params = build_params ( q , kwargs ) return self . rest_api_connection . get ( uri , params )
def smt_dataset ( directory = 'data/' , train = False , dev = False , test = False , train_filename = 'train.txt' , dev_filename = 'dev.txt' , test_filename = 'test.txt' , extracted_name = 'trees' , check_files = [ 'trees/train.txt' ] , url = 'http://nlp.stanford.edu/sentiment/trainDevTestTrees_PTB.zip' , fine_grained ...
download_file_maybe_extract ( url = url , directory = directory , check_files = check_files ) ret = [ ] splits = [ ( train , train_filename ) , ( dev , dev_filename ) , ( test , test_filename ) ] splits = [ f for ( requested , f ) in splits if requested ] for filename in splits : full_path = os . path . join ( dire...
def extract_client_auth ( request ) : """Get client credentials using HTTP Basic Authentication method . Or try getting parameters via POST . See : http : / / tools . ietf . org / html / rfc6750 # section - 2.1 Return a tuple ` ( client _ id , client _ secret ) ` ."""
auth_header = request . META . get ( 'HTTP_AUTHORIZATION' , '' ) if re . compile ( '^Basic\s{1}.+$' ) . match ( auth_header ) : b64_user_pass = auth_header . split ( ) [ 1 ] try : user_pass = b64decode ( b64_user_pass ) . decode ( 'utf-8' ) . split ( ':' ) client_id , client_secret = tuple ( use...
def validate_and_store_body_data ( self , data ) : """Attempts simple body data validation by comparining incoming data to the content length header . If passes store the data into self . _ buffer . Parameters : data ( bytes ) : Incoming client data to be added to the body Raises : HTTPErrorBadRequest :...
# add data to end of buffer self . body_buffer [ - 1 : ] = data if len ( self . body_buffer ) > self . content_length : problem = "Content length exceeds expected value (%d > %d)" % ( len ( self . body_buffer ) , self . content_length ) raise HTTPErrorBadRequest ( phrase = problem )
def emit ( self , data_frame ) : """Use this function in emit data into the store . : param data _ frame : DataFrame to be recorded ."""
if self . result is not None : raise MultipleEmitsError ( ) data_frame . columns = [ self . prefix + '__' + c for c in data_frame . columns ] self . result = data_frame
def handle_headers ( self , message_header , block_headers_message ) : """Handle a ' headers ' message . NOTE : we request headers in order , so we will expect to receive them in order here . Verify that we do so ."""
log . debug ( "handle headers (%s)" % len ( block_headers_message . headers ) ) block_headers = block_headers_message . headers serializer = BlockHeaderSerializer ( ) # verify that the local header chain connects to this sequence current_height = SPVClient . height ( self . path ) if current_height is None : assert...
def val_accuracy ( show_swap ) : """http : / / wiki . apache . org / spamassassin / TopSharedMemoryBug"""
kv = kernel_ver ( ) pid = os . getpid ( ) swap_accuracy = - 1 if kv [ : 2 ] == ( 2 , 4 ) : if proc . open ( 'meminfo' ) . read ( ) . find ( "Inact_" ) == - 1 : return 1 , swap_accuracy return 0 , swap_accuracy elif kv [ : 2 ] == ( 2 , 6 ) : if os . path . exists ( proc . path ( pid , 'smaps' ) ) : ...
def overlap_add ( blk_sig , size = None , hop = None , wnd = None , normalize = True ) : """Overlap - add algorithm using Numpy arrays . Parameters blk _ sig : An iterable of blocks ( sequences ) , such as the ` ` Stream . blocks ` ` result . size : Block size for each ` ` blk _ sig ` ` element , in sampl...
import numpy as np # Finds the size from data , if needed if size is None : blk_sig = Stream ( blk_sig ) size = len ( blk_sig . peek ( ) ) if hop is None : hop = size # Find the right windowing function to be applied if wnd is None : wnd = np . ones ( size ) elif callable ( wnd ) and not isinstance ( wn...
def uri_query ( self , value ) : """Adds a query . : param value : the query"""
del self . uri_query queries = value . split ( "&" ) for q in queries : option = Option ( ) option . number = defines . OptionRegistry . URI_QUERY . number option . value = str ( q ) self . add_option ( option )
def short_url ( self , long_url ) : """长链接转短链接 : param long _ url : 长链接 : return : 返回的结果数据"""
data = { 'appid' : self . appid , 'long_url' : long_url , } return self . _post ( 'tools/shorturl' , data = data )
async def dump_blob ( writer , elem , elem_type , params = None ) : """Dumps blob to a binary stream : param writer : : param elem : : param elem _ type : : param params : : return :"""
elem_is_blob = isinstance ( elem , x . BlobType ) data = bytes ( getattr ( elem , x . BlobType . DATA_ATTR ) if elem_is_blob else elem ) await dump_varint ( writer , len ( elem ) ) await writer . awrite ( data )
def deleteRows ( self , login , tableName , startRow , endRow ) : """Parameters : - login - tableName - startRow - endRow"""
self . send_deleteRows ( login , tableName , startRow , endRow ) self . recv_deleteRows ( )
def create ( self , sid , seedList ) : """Create a new named ( sid ) Seed from a list of seed URLs : param sid : the name to assign to the new seed list : param seedList : the list of seeds to use : return : the created Seed object"""
seedUrl = lambda uid , url : { "id" : uid , "url" : url } if not isinstance ( seedList , tuple ) : seedList = ( seedList , ) seedListData = { "id" : "12345" , "name" : sid , "seedUrls" : [ seedUrl ( uid , url ) for uid , url in enumerate ( seedList ) ] } # As per resolution of https : / / issues . apache . org / ji...
async def reset ( self ) : """Synchronously reset a tile . This method must be called from the emulation loop and will synchronously shut down all background tasks running this tile , clear it to reset state and then restart the initialization background task ."""
await self . _device . emulator . stop_tasks ( self . address ) self . _handle_reset ( ) self . _logger . info ( "Tile at address %d has reset itself." , self . address ) self . _logger . info ( "Starting main task for tile at address %d" , self . address ) self . _device . emulator . add_task ( self . address , self ....
def subnets_list ( virtual_network , resource_group , ** kwargs ) : '''. . versionadded : : 2019.2.0 List all subnets within a virtual network . : param virtual _ network : The virtual network name to list subnets within . : param resource _ group : The resource group name assigned to the virtual network . ...
result = { } netconn = __utils__ [ 'azurearm.get_client' ] ( 'network' , ** kwargs ) try : subnets = __utils__ [ 'azurearm.paged_object_to_list' ] ( netconn . subnets . list ( resource_group_name = resource_group , virtual_network_name = virtual_network ) ) for subnet in subnets : result [ subnet [ 'nam...
def toString ( self ) : """Connection information as a string ."""
string = "" if self . toLayer . _verbosity > 4 : string += "wed: from '" + self . fromLayer . name + "' to '" + self . toLayer . name + "'\n" string += " " for j in range ( self . toLayer . size ) : string += " " + self . toLayer . name + "[" + str ( j ) + "]" string += '\n' ...
def _populate_worksheet ( self , workbook , worksheet ) : """Write chart data contents to * worksheet * in the bubble chart layout . Write the data for each series to a separate three - column table with X values in column A , Y values in column B , and bubble sizes in column C . Place the series label in the...
chart_num_format = workbook . add_format ( { 'num_format' : self . _chart_data . number_format } ) for series in self . _chart_data : series_num_format = ( workbook . add_format ( { 'num_format' : series . number_format } ) ) offset = self . series_table_row_offset ( series ) # write X values worksheet ...
def scan_forever ( queue , * args , ** kwargs ) : """Return an infinite iterator over an fsq queue that blocks waiting for the queue trigger . Work is yielded as FSQWorkItem objects when available , assuming the default generator ( FSQScanGenerator ) is in use . Essentially , this function wraps fsq . scan ...
process_once_now = kwargs . get ( 'process_once_now' , True ) if process_once_now : for work in scan ( queue , * args , ** kwargs ) : yield work while True : with open ( fsq_path . trigger ( queue ) , 'rb' ) as t : t . read ( 1 ) for work in scan ( queue , * args , ** kwargs ) : yiel...
def set_textcolor ( self , color ) : """set color for labels and axis text"""
self . textcolor = color self . relabel ( ) if callable ( self . theme_color_callback ) : self . theme_color_callback ( color , 'text' )
def shift ( self , * args , ** kwargs ) : """shift ( hours , minutes , seconds , milliseconds , ratio ) Shift ` start ` and ` end ` attributes of each items of file either by applying a ratio or by adding an offset . ` ratio ` should be either an int or a float . Example to convert subtitles from 23.9 fps t...
for item in self : item . shift ( * args , ** kwargs )
def generate_observation_from_state ( self , state_index ) : """Generate a single synthetic observation data from a given state . Parameters state _ index : int Index of the state from which observations are to be generated . Returns observation : float A single observation from the given state . Exam...
# generate random generator ( note that this is inefficient - better use one of the next functions import scipy . stats gen = scipy . stats . rv_discrete ( values = ( range ( len ( self . _output_probabilities [ state_index ] ) ) , self . _output_probabilities [ state_index ] ) ) gen . rvs ( size = 1 )
def transformToNative ( obj ) : """Turn obj . value into a list ."""
if obj . isNative : return obj obj . isNative = True obj . value = splitFields ( obj . value ) return obj
def performAction ( self , action ) : """Perform an action on the world that changes it ' s internal state ."""
gs = [ g for g in self . case . online_generators if g . bus . type != REFERENCE ] assert len ( action ) == len ( gs ) logger . info ( "Action: %s" % list ( action ) ) # Set the output of each ( non - reference ) generator . for i , g in enumerate ( gs ) : g . p = action [ i ] # Compute power flows and slack genera...
def generate_image_commands ( ) : '''The Image client holds the Singularity image command group , mainly deprecated commands ( image . import ) and additional command helpers that are commonly use but not provided by Singularity The levels of verbosity ( debug and quiet ) are passed from the main client via...
class ImageClient ( object ) : group = "image" from spython . main . base . logger import println from spython . main . base . command import ( init_command , run_command ) from . utils import ( compress , decompress ) from . create import create from . importcmd import importcmd from . export import export ImageCl...
def create_bwa_index_from_fasta_file ( fasta_in , params = None ) : """Create a BWA index from an input fasta file . fasta _ in : the input fasta file from which to create the index params : dict of bwa index specific paramters This method returns a dictionary where the keys are the various output suffixes ...
if params is None : params = { } # Instantiate the app controller index = BWA_index ( params ) # call the application , passing the fasta file in results = index ( { 'fasta_in' : fasta_in } ) return results
def modify ( self , api_action , sgid , other , proto_spec ) : """Make a change to a security group . api _ action is an EC2 API name . Other is one of : - a group ( sg - nnnnn ) - a group with account ( < user id > / sg - nnnnn ) - a CIDR block ( n . n . n . n / n ) Proto spec is a triplet ( < proto > , ...
params = { 'group_id' : sgid , 'ip_permissions' : [ ] } perm = { } params [ 'ip_permissions' ] . append ( perm ) proto , from_port , to_port = proto_spec perm [ 'IpProtocol' ] = proto perm [ 'FromPort' ] = from_port or 0 perm [ 'ToPort' ] = to_port or from_port or 65535 if other . startswith ( "sg-" ) : perm [ 'Use...
def rewrite_tg ( env , tg_name , code ) : """Re - write a transform generating function pipe specification by extracting the tranform generating part , and replacing it with the generated transform . so : tgen ( a , b , c ) . foo . bar becomes : tg = tgen ( a , b , c ) tg . foo . bar"""
visitor = ReplaceTG ( env , tg_name ) assert visitor . tg_name tree = visitor . visit ( ast . parse ( code ) ) if visitor . loc : loc = ' #' + visitor . loc else : loc = file_loc ( ) # The AST visitor didn ' t match a call node if visitor . trans_gen : tg = meta . dump_python_source ( visitor . trans_gen ) ...
def _send_update_port_statuses ( self , port_ids , status ) : """Sends update notifications to set the operational status of the list of router ports provided . To make each notification doesn ' t exceed the RPC length , each message contains a maximum of MAX _ PORTS _ IN _ BATCH port ids . : param port _ i...
if not port_ids : return MAX_PORTS_IN_BATCH = 50 list_chunks_ports = [ port_ids [ i : i + MAX_PORTS_IN_BATCH ] for i in six . moves . range ( 0 , len ( port_ids ) , MAX_PORTS_IN_BATCH ) ] for chunk_ports in list_chunks_ports : self . plugin_rpc . send_update_port_statuses ( self . context , chunk_ports , status...
def atlas_zonefile_path ( zonefile_dir , zonefile_hash ) : """Calculate the on - disk path to storing a zonefile ' s information , given the zone file hash . If the zonefile hash is abcdef1234567890 , then the path will be $ zonefile _ dir / ab / cd / abcdef1234567890 . txt Returns the path ."""
# split into directories , but not too many zonefile_dir_parts = [ ] interval = 2 for i in xrange ( 0 , min ( len ( zonefile_hash ) , 4 ) , interval ) : zonefile_dir_parts . append ( zonefile_hash [ i : i + interval ] ) zonefile_path = os . path . join ( zonefile_dir , '/' . join ( zonefile_dir_parts ) , '{}.txt' ....
def send_email_template ( slug , base_url = None , context = None , user = None , to = None , cc = None , bcc = None , attachments = None , headers = None , connection = None , fail_silently = False ) : """Shortcut to send an email template ."""
email_template = EmailTemplate . objects . get_for_slug ( slug ) email = email_template . get_email_message ( base_url , context , user , to = to , cc = cc , bcc = bcc , attachments = attachments , headers = headers , connection = connection ) return email . send ( fail_silently = fail_silently )
def save_schedule ( self ) : '''Save the current schedule'''
self . persist ( ) # Fire the complete event back along with the list of schedule evt = salt . utils . event . get_event ( 'minion' , opts = self . opts , listen = False ) evt . fire_event ( { 'complete' : True } , tag = '/salt/minion/minion_schedule_saved' )
def _get_websocket ( self , reuse = True ) : """Reuse existing connection or create a new connection ."""
# Check if still connected if self . ws and reuse : if self . ws . connected : return self . ws logging . debug ( "Stale connection, reconnecting." ) self . ws = self . _create_connection ( ) return self . ws
def get_provides_by_kind ( self , kind ) : """Returns an array of provides of a certain kind"""
provs = [ ] for p in self . provides : if p . kind == kind : provs . append ( p ) return provs
def count ( self , data ) : """Compute histogram of data . Counts the number of elements from array ` ` data ` ` in each bin of the histogram . Results are returned in an array , call it ` ` h ` ` , of length ` ` nbin + 2 ` ` where ` ` h [ 0 ] ` ` is the number of data elements that fall below the range of ...
if isinstance ( data , float ) or isinstance ( data , int ) : hist = numpy . zeros ( self . nbin + 2 , float ) if data > self . bins [ - 1 ] : hist [ - 1 ] = 1. elif data < self . bins [ 0 ] : hist [ 0 ] = 1. elif data == self . bins [ - 1 ] : if self . nbin > 1 : his...
def find_place ( client , input , input_type , fields = None , location_bias = None , language = None ) : """A Find Place request takes a text input , and returns a place . The text input can be any kind of Places data , for example , a name , address , or phone number . : param input : The text input specify...
params = { "input" : input , "inputtype" : input_type } if input_type != "textquery" and input_type != "phonenumber" : raise ValueError ( "Valid values for the `input_type` param for " "`find_place` are 'textquery' or 'phonenumber', " "the given value is invalid: '%s'" % input_type ) if fields : invalid_fields ...
def transitions ( self ) : """Dense [ k - 1 ] x4 transition frequency matrix"""
if self . _transitions is not None : return self . _transitions transitions = self . array . astype ( np . float ) transitions /= transitions . sum ( 1 ) [ : , np . newaxis ] self . _transitions = transitions return transitions
def initialized ( self , value ) : """Setter for * * self . _ _ initialized * * attribute . : param value : Attribute value . : type value : bool"""
if value is not None : assert type ( value ) is bool , "'{0}' attribute: '{1}' type is not 'bool'!" . format ( "initialized" , value ) self . component_initialized . emit ( ) if value else self . component_uninitialized . emit ( ) self . __initialized = value
def build_valid_keywords_grammar ( keywords = None ) : """Update parser grammar to add a list of allowed keywords ."""
from invenio_query_parser . parser import KeywordQuery , KeywordRule , NotKeywordValue , SimpleQuery , ValueQuery if keywords : KeywordRule . grammar = attr ( 'value' , re . compile ( r"(\d\d\d\w{{0,3}}|{0})\b" . format ( "|" . join ( keywords ) , re . I ) ) ) NotKeywordValue . grammar = attr ( 'value' , re . c...
def delete_table ( self , tablename ) : """Deletes a table from the database ."""
self . tables = filter ( lambda x : x . name != tablename , self . tables )
def screen_to_latlon ( self , x , y ) : """Return the latitude and longitude corresponding to a screen point : param x : screen x : param y : screen y : return : latitude and longitude at x , y"""
xtile = 1. * x / TILE_SIZE + self . xtile ytile = 1. * y / TILE_SIZE + self . ytile return self . num2deg ( xtile , ytile , self . zoom )
def _bfd_rx ( self , ** kwargs ) : """Return the BFD minimum receive interval XML . You should not use this method . You probably want ` BGP . bfd ` . Args : min _ rx ( str ) : BFD receive interval in milliseconds ( 300 , 500 , etc ) delete ( bool ) : Remove the configuration if ` ` True ` ` . Returns :...
method_name = 'rbridge_id_router_router_bgp_router_bgp_attributes_' 'bfd_interval_min_rx' bfd_rx = getattr ( self . _rbridge , method_name ) config = bfd_rx ( ** kwargs ) if kwargs [ 'delete' ] : tag = 'min-rx' config . find ( './/*%s' % tag ) . set ( 'operation' , 'delete' ) pass return config
def output_domain ( gandi , domain , output_keys , justify = 12 ) : """Helper to output a domain information ."""
if 'nameservers' in domain : domain [ 'nameservers' ] = format_list ( domain [ 'nameservers' ] ) if 'services' in domain : domain [ 'services' ] = format_list ( domain [ 'services' ] ) if 'tags' in domain : domain [ 'tags' ] = format_list ( domain [ 'tags' ] ) output_generic ( gandi , domain , output_keys ,...
def set_in_bounds ( self , obj , val ) : """Set to the given value , but cropped to be within the legal bounds . All objects are accepted , and no exceptions will be raised . See crop _ to _ bounds for details on how cropping is done ."""
if not callable ( val ) : bounded_val = self . crop_to_bounds ( val ) else : bounded_val = val super ( Number , self ) . __set__ ( obj , bounded_val )
def _to_dict ( self ) : """Return a json dictionary representing this model ."""
_dict = { } if hasattr ( self , 'class_name' ) and self . class_name is not None : _dict [ 'class' ] = self . class_name return _dict
def _ensure_click ( self ) : """Ensures a click gets made , because Selenium can be a bit buggy about clicks This method gets added to the selenium element returned in ' _ _ ensure _ element _ by _ xpath ' . We should probably add it to more selenium methods , such as all the ' find * * ' methods though . I w...
# We ensure the element is scrolled into the middle of the viewport to ensure that # it is clickable . There are two main ways an element may not be clickable : # - It is outside of the viewport # - It is under a banner or toolbar # This script solves both cases script = ( "var viewPortHeight = Math.max(" "document.doc...
def load_data ( self , filename , transpose = True , save_sparse_file = 'h5ad' , sep = ',' , ** kwargs ) : """Loads the specified data file . The file can be a table of read counts ( i . e . ' . csv ' or ' . txt ' ) , with genes as rows and cells as columns by default . The file can also be a pickle file ( outp...
if filename . split ( '.' ) [ - 1 ] == 'p' : raw_data , all_cell_names , all_gene_names = ( pickle . load ( open ( filename , 'rb' ) ) ) if ( transpose ) : raw_data = raw_data . T if raw_data . getformat ( ) == 'csc' : print ( "Converting sparse matrix to csr format..." ) ...
def splitPolygon ( self , polygon , coplanarFront , coplanarBack , front , back ) : """Split ` polygon ` by this plane if needed , then put the polygon or polygon fragments in the appropriate lists . Coplanar polygons go into either ` coplanarFront ` or ` coplanarBack ` depending on their orientation with res...
COPLANAR = 0 # all the vertices are within EPSILON distance from plane FRONT = 1 # all the vertices are in front of the plane BACK = 2 # all the vertices are at the back of the plane SPANNING = 3 # some vertices are in front , some in the back # Classify each point as well as the entire polygon into one of the above # ...
def list_snapshots ( config = 'root' ) : '''List available snapshots CLI example : . . code - block : : bash salt ' * ' snapper . list _ snapshots config = myconfig'''
try : snapshots = snapper . ListSnapshots ( config ) return [ _snapshot_to_data ( s ) for s in snapshots ] except dbus . DBusException as exc : raise CommandExecutionError ( 'Error encountered while listing snapshots: {0}' . format ( _dbus_exception_to_reason ( exc , locals ( ) ) ) )
def get_field_type ( info ) : """A field python type"""
type_ = info . get_type ( ) cls = get_field_class ( type_ ) field = cls ( info , type_ , None ) field . setup ( ) return field . py_type
def run ( self ) : """The main entry point , performs the appropriate action for the given arguments ."""
self . _unlock_keychain ( ) item = self . keychain . item ( self . arguments . item , fuzzy_threshold = self . _fuzzy_threshold ( ) , ) if item is not None : self . stdout . write ( "%s\n" % item . password ) else : self . stderr . write ( "1pass: Could not find an item named '%s'\n" % ( self . arguments . item...
def _check_parameters ( self ) : """Internal function to verify the basic parameters of the SOM ."""
if self . _map_type != "planar" and self . _map_type != "toroid" : raise Exception ( "Invalid parameter for _map_type: " + self . _map_type ) if self . _grid_type != "rectangular" and self . _grid_type != "hexagonal" : raise Exception ( "Invalid parameter for _grid_type: " + self . _grid_type ) if self . _neigh...
def estimate_descendents ( self ) : """Estimate from the descendent ( child ) tasks . : returns : deferred that when fired returns a datetime object for the estimated , or actual datetime , or None if there is no support for this task method . Currently the only supported methods here are " build " and " im...
child_method = None if self . method == 'build' : child_method = 'buildArch' if self . method == 'image' : child_method = 'createImage' if child_method is None : defer . returnValue ( None ) # Find the open child task and estimate that . subtasks = yield self . descendents ( method = child_method , state = ...
def load_secret ( self , secret ) : """Ask YubiHSM to load a pre - existing YubiKey secret . The data is stored internally in the YubiHSM in temporary memory - this operation would typically be followed by one or more L { generate _ aead } commands to actually retreive the generated secret ( in encrypted form...
if isinstance ( secret , pyhsm . aead_cmd . YHSM_YubiKeySecret ) : secret = secret . pack ( ) return pyhsm . buffer_cmd . YHSM_Cmd_Buffer_Load ( self . stick , secret ) . execute ( )
def erase_line ( self ) : # < ESC > [ 2K '''Erases the entire current line .'''
self . fill_region ( self . cur_r , 1 , self . cur_r , self . cols )
def parse ( self , tokens ) : """Sequence ( a ) - > b Applies the parser to a sequence of tokens producing a parsing result . It provides a way to invoke a parser hiding details related to the parser state . Also it makes error messages more readable by specifying the position of the rightmost token that ha...
try : ( tree , _ ) = self . run ( tokens , State ( ) ) return tree except NoParseError , e : max = e . state . max if len ( tokens ) > max : tok = tokens [ max ] else : tok = u'<EOF>' raise NoParseError ( u'%s: %s' % ( e . msg , tok ) , e . state )
def build_fasttext_cc_embedding_obj ( embedding_type ) : """FastText pre - trained word vectors for 157 languages , with 300 dimensions , trained on Common Crawl and Wikipedia . Released in 2018 , it succeesed the 2017 FastText Wikipedia embeddings . It ' s recommended to use the same tokenizer for your data that w...
lang = embedding_type . split ( '.' ) [ 2 ] return { 'file' : 'cc.{}.300.vec.gz' . format ( lang ) , 'url' : 'https://dl.fbaipublicfiles.com/fasttext/vectors-crawl/cc.{}.300.vec.gz' . format ( lang ) , 'extract' : False }
def hide_routemap_holder_route_map_content_set_tag_tag_rms ( self , ** kwargs ) : """Auto Generated Code"""
config = ET . Element ( "config" ) hide_routemap_holder = ET . SubElement ( config , "hide-routemap-holder" , xmlns = "urn:brocade.com:mgmt:brocade-ip-policy" ) route_map = ET . SubElement ( hide_routemap_holder , "route-map" ) name_key = ET . SubElement ( route_map , "name" ) name_key . text = kwargs . pop ( 'name' ) ...
def _live_receivers ( self , sender ) : """Filter sequence of receivers to get resolved , live receivers . This checks for weak references and resolves them , then returning only live receivers ."""
receivers = None if self . use_caching and not self . _dead_receivers : receivers = self . sender_receivers_cache . get ( sender ) # We could end up here with NO _ RECEIVERS even if we do check this case in # . send ( ) prior to calling _ live _ receivers ( ) due to concurrent . send ( ) call . if recei...
def validate_functions ( ast : BELAst , bo ) : """Recursively validate function signatures Determine if function matches one of the available signatures . Also , 1 . Add entity types to AST NSArg , e . g . Abundance , . . . 2 . Add optional to AST Arg ( optional means it is not a fixed , required argument a...
if isinstance ( ast , Function ) : log . debug ( f"Validating: {ast.name}, {ast.function_type}, {ast.args}" ) function_signatures = bo . spec [ "functions" ] [ "signatures" ] [ ast . name ] [ "signatures" ] function_name = ast . name ( valid_function , messages ) = check_function_args ( ast . args , fun...