signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
async def catch_up ( self ) : """" Catches up " on the missed updates while the client was offline . You should call this method after registering the event handlers so that the updates it loads can by processed by your script . This can also be used to forcibly fetch new updates if there are any ."""
pts , date = self . _state_cache [ None ] self . session . catching_up = True try : while True : d = await self ( functions . updates . GetDifferenceRequest ( pts , date , 0 ) ) if isinstance ( d , ( types . updates . DifferenceSlice , types . updates . Difference ) ) : if isinstance ( d...
def rgb_to_cmy ( r , g = None , b = None ) : """Convert the color from RGB coordinates to CMY . Parameters : The Red component value [ 0 . . . 1] The Green component value [ 0 . . . 1] The Blue component value [ 0 . . . 1] Returns : The color as an ( c , m , y ) tuple in the range : c [ 0 . . . 1 ] , ...
if type ( r ) in [ list , tuple ] : r , g , b = r return ( 1 - r , 1 - g , 1 - b )
def generate_sample ( self , initial_pos , num_samples , trajectory_length , stepsize = None ) : """Method returns a generator type object whose each iteration yields a sample using Hamiltonian Monte Carlo Parameters initial _ pos : A 1d array like object Vector representing values of parameter position , t...
self . accepted_proposals = 0 initial_pos = _check_1d_array_object ( initial_pos , 'initial_pos' ) _check_length_equal ( initial_pos , self . model . variables , 'initial_pos' , 'model.variables' ) if stepsize is None : stepsize = self . _find_reasonable_stepsize ( initial_pos ) lsteps = int ( max ( 1 , round ( tra...
def compose_matrix ( scale = None , shear = None , angles = None , translate = None , perspective = None ) : """Return transformation matrix from sequence of transformations . This is the inverse of the decompose _ matrix function . Sequence of transformations : scale : vector of 3 scaling factors shear : l...
M = np . identity ( 4 ) if perspective is not None : P = np . identity ( 4 ) P [ 3 , : ] = perspective [ : 4 ] M = np . dot ( M , P ) if translate is not None : T = np . identity ( 4 ) T [ : 3 , 3 ] = translate [ : 3 ] M = np . dot ( M , T ) if angles is not None : R = euler_matrix ( angles ...
def create ( self , request , * args , ** kwargs ) : """To create new push hook issue * * POST * * against * / api / hooks - push / * as an authenticated user . You should specify list of event _ types or event _ groups . Example of a request : . . code - block : : http POST / api / hooks - push / HTTP / 1....
return super ( PushHookViewSet , self ) . create ( request , * args , ** kwargs )
def _estimate_bkg_rms ( self , xmin , xmax , ymin , ymax ) : """Estimate the background noise mean and RMS . The mean is estimated as the median of data . The RMS is estimated as the IQR of data / 1.34896. Parameters xmin , xmax , ymin , ymax : int The bounding region over which the bkg / rms will be calc...
data = self . global_data . data_pix [ ymin : ymax , xmin : xmax ] pixels = np . extract ( np . isfinite ( data ) , data ) . ravel ( ) if len ( pixels ) < 4 : bkg , rms = np . NaN , np . NaN else : pixels . sort ( ) p25 = pixels [ int ( pixels . size / 4 ) ] p50 = pixels [ int ( pixels . size / 2 ) ] ...
def attachment ( self , attachment ) : """Add attachment ( s ) to this email : param attachment : Add attachment ( s ) to this email : type attachment : Attachment , list ( Attachment )"""
if isinstance ( attachment , list ) : for a in attachment : self . add_attachment ( a ) else : self . add_attachment ( attachment )
def _parse_errorbars ( self , label , err ) : """Look for error keyword arguments and return the actual errorbar data or return the error DataFrame / dict Error bars can be specified in several ways : Series : the user provides a pandas . Series object of the same length as the data ndarray : provides a n...
if err is None : return None def match_labels ( data , e ) : e = e . reindex ( data . index ) return e # key - matched DataFrame if isinstance ( err , ABCDataFrame ) : err = match_labels ( self . data , err ) # key - matched dict elif isinstance ( err , dict ) : pass # Series of error values elif is...
def show_edit_form ( obj , attrs = None , title = "" , toolTips = None ) : """Shows parameters editor modal form . Arguments : obj : object to extract attribute values from , or a dict - like attrs : list of attribute names title : toolTips :"""
if attrs is None : if hasattr ( obj , "keys" ) : attrs = list ( obj . keys ( ) ) else : raise RuntimeError ( "attrs is None and cannot determine it from obj" ) specs = [ ] for i , name in enumerate ( attrs ) : # Tries as attribute , then as key try : value = obj . __getattribute__ ( ...
def all_subs ( bounds ) : """given a list of tuples specifying the bounds of an array , all _ subs ( ) returns a list of all the tuples of subscripts for that array ."""
idx_list = [ ] for i in range ( len ( bounds ) ) : this_dim = bounds [ i ] lo , hi = this_dim [ 0 ] , this_dim [ 1 ] # bounds for this dimension this_dim_idxs = range ( lo , hi + 1 ) # indexes for this dimension idx_list . append ( this_dim_idxs ) return idx2subs ( idx_list )
def tag ( self , sentence , tokenize = True ) : """Tag a string ` sentence ` . : param str or list sentence : A string or a list of sentence strings . : param tokenize : ( optional ) If ` ` False ` ` string has to be tokenized before ( space separated string ) ."""
# : Do not process empty strings ( Issue # 3) if sentence . strip ( ) == "" : return [ ] # : Do not process strings consisting of a single punctuation mark ( Issue # 4) elif sentence . strip ( ) in PUNCTUATION : if self . include_punc : _sym = sentence . strip ( ) if _sym in tuple ( '.?!' ) : ...
def set_categories ( self ) : """Parses and set feed categories"""
self . categories = [ ] temp_categories = self . soup . findAll ( 'category' ) for category in temp_categories : category_text = category . string self . categories . append ( category_text )
def _prepare_colors ( color , values , limits_c , colormap , alpha , chan = None ) : """Return colors for all the channels based on various inputs . Parameters color : tuple 3 - , 4 - element tuple , representing RGB and alpha , between 0 and 1 values : ndarray array with values for each channel limits ...
if values is not None : if limits_c is None : limits_c = array ( [ - 1 , 1 ] ) * nanmax ( abs ( values ) ) norm_values = normalize ( values , * limits_c ) cm = get_colormap ( colormap ) colors = cm [ norm_values ] elif color is not None : colors = ColorArray ( color ) else : cm = get_col...
def get_port_channel_detail_output_lacp_aggr_member_interface_type ( self , ** kwargs ) : """Auto Generated Code"""
config = ET . Element ( "config" ) get_port_channel_detail = ET . Element ( "get_port_channel_detail" ) config = get_port_channel_detail output = ET . SubElement ( get_port_channel_detail , "output" ) lacp = ET . SubElement ( output , "lacp" ) aggr_member = ET . SubElement ( lacp , "aggr-member" ) interface_type = ET ....
async def executor ( func , * args , ** kwargs ) : '''Execute a function in an executor thread . Args : todo ( ( func , args , kwargs ) ) : A todo tuple .'''
def syncfunc ( ) : return func ( * args , ** kwargs ) loop = asyncio . get_running_loop ( ) return await loop . run_in_executor ( None , syncfunc )
def set_abort_pending ( self , newstate ) : """Method to set Abort state if something goes wrong during provisioning Method also used to finish provisioning process when all is completed Method : POST"""
self . logger . debug ( "set_abort_pending(" + "{})" . format ( newstate ) ) # NOT TO BE USED # default _ minimal _ cluster _ config = ' { " installationId " : null , " mdmIPs " : [ " 192.168.102.12 " , " 192.168.102.13 " ] , " mdmPassword " : " Scaleio123 " , " liaPassword " : " Scaleio123 " , " licenseKey " : null , ...
def validate ( self ) : """Validate that the OutputContextVertex is correctly representable ."""
super ( OutputContextVertex , self ) . validate ( ) if self . location . field is not None : raise ValueError ( u'Expected location at a vertex, but got: {}' . format ( self . location ) )
def _make_bz_instance ( opt ) : """Build the Bugzilla instance we will use"""
if opt . bztype != 'auto' : log . info ( "Explicit --bztype is no longer supported, ignoring" ) cookiefile = None tokenfile = None use_creds = False if opt . cache_credentials : cookiefile = opt . cookiefile or - 1 tokenfile = opt . tokenfile or - 1 use_creds = True bz = bugzilla . Bugzilla ( url = opt ...
def src_new ( converter_type , channels ) : """Initialise a new sample rate converter . Parameters converter _ type : int Converter to be used . channels : int Number of channels . Returns state An anonymous pointer to the internal state of the converter . error : int Error code ."""
error = ffi . new ( 'int*' ) state = _lib . src_new ( converter_type , channels , error ) return state , error [ 0 ]
def get_instance ( self , payload ) : """Build an instance of VerificationCheckInstance : param dict payload : Payload response from the API : returns : twilio . rest . preview . acc _ security . service . verification _ check . VerificationCheckInstance : rtype : twilio . rest . preview . acc _ security . se...
return VerificationCheckInstance ( self . _version , payload , service_sid = self . _solution [ 'service_sid' ] , )
def acquire ( self , timeout = None ) : """Acquire a connection : param timeout : If provided , seconds to wait for a connection before raising Queue . Empty . If not provided , blocks indefinitely . : returns : Returns a RethinkDB connection : raises Empty : No resources are available before timeout ."""
self . _pool_lock . acquire ( ) if timeout is None : conn_wrapper = self . _pool . get_nowait ( ) else : conn_wrapper = self . _pool . get ( True , timeout ) self . _current_acquired += 1 self . _pool_lock . release ( ) return conn_wrapper . connection
def _in ( field , value , document ) : """Returns True if document [ field ] is in the interable value . If the supplied value is not an iterable , then a MalformedQueryException is raised"""
try : values = iter ( value ) except TypeError : raise MalformedQueryException ( "'$in' must accept an iterable" ) return document . get ( field , None ) in values
def lc_score ( value ) : """Evaluates the accuracy of a predictive measure ( e . g . r - squared ) : param value : float , between 0.0 and 1.0. : return :"""
rebased = 2 * ( value - 0.5 ) if rebased == 0 : return 0 elif rebased > 0 : compliment = 1.0 - rebased score = - np . log2 ( compliment ) else : compliment = 1.0 + rebased score = np . log2 ( compliment ) return score
def _post_subject ( self , body ) : """Create new subjects and associated attributes . Example : acs . post _ subject ( [ " subjectIdentifier " : " / role / evangelist " , " parents " : [ ] , " attributes " : [ " issuer " : " default " , " name " : " role " , " value " : " developer evangelist " , ...
assert isinstance ( body , ( list ) ) , "POST requires body to be a list" uri = self . _get_subject_uri ( ) return self . service . _post ( uri , body )
def uploadItem ( self , filePath , description ) : """This operation uploads an item to the server . Each uploaded item is identified by a unique itemID . Since this request uploads a file , it must be a multi - part request as per IETF RFC1867. Inputs : filePath - the file to be uploaded . description - ...
import urlparse url = self . _url + "/upload" params = { "f" : "json" } files = { } files [ 'itemFile' ] = filePath return self . _post ( url = url , param_dict = params , files = files , securityHandler = self . _securityHandler , proxy_url = self . _proxy_url , proxy_port = self . _proxy_port )
def call_nowait ( self , cb_name ) : """pick a callback command and call it without waiting for it to finish"""
if self . bootstrapping : return if cb_name in ( ACTION_ON_START , ACTION_ON_STOP , ACTION_ON_RESTART , ACTION_ON_ROLE_CHANGE ) : self . __cb_called = True if self . callback and cb_name in self . callback : cmd = self . callback [ cb_name ] try : cmd = shlex . split ( self . callback [ cb_name ...
def paginate ( self , request , offset = 0 , limit = None ) : """Paginate queryset ."""
return self . collection . offset ( offset ) . limit ( limit ) , self . collection . count ( )
def send_message ( self , message ) : """Send chat message to this steam user : param message : message to send : type message : str"""
self . _steam . send ( MsgProto ( EMsg . ClientFriendMsg ) , { 'steamid' : self . steam_id , 'chat_entry_type' : EChatEntryType . ChatMsg , 'message' : message . encode ( 'utf8' ) , } )
def clone ( self , spawn_mapping = None ) : """Return an exact copy of this generator which behaves the same way ( i . e . , produces the same elements in the same order ) and which is automatically reset whenever the original generator is reset ."""
c = self . spawn ( spawn_mapping ) self . register_clone ( c ) c . register_parent ( self ) return c
def add_citations ( voevent , event_ivorns ) : """Add citations to other voevents . The schema mandates that the ' Citations ' section must either be entirely absent , or non - empty - hence we require this wrapper function for its creation prior to listing the first citation . Args : voevent ( : class : ...
if not voevent . xpath ( 'Citations' ) : etree . SubElement ( voevent , 'Citations' ) voevent . Citations . extend ( _listify ( event_ivorns ) )
def render ( self , ** kwargs ) : """Renders the HTML representation of the element ."""
for name , child in self . _children . items ( ) : child . render ( ** kwargs ) return self . _template . render ( this = self , kwargs = kwargs )
def _pdist ( x ) : """Calculate the pair - wise point distances of a matrix Parameters x : 2d - array An m - by - n array of scalars , where there are m points in n dimensions . Returns d : array A 1 - by - b array of scalars , where b = m * ( m - 1 ) / 2 . This array contains all the pair - wise poin...
x = np . atleast_2d ( x ) assert len ( x . shape ) == 2 , 'Input array must be 2d-dimensional' m , n = x . shape if m < 2 : return [ ] d = [ ] for i in range ( m - 1 ) : for j in range ( i + 1 , m ) : d . append ( ( sum ( ( x [ j , : ] - x [ i , : ] ) ** 2 ) ) ** 0.5 ) return np . array ( d )
def _create_symlink_cygwin ( self , initial_path , final_path ) : """Use cygqin to generate symbolic link"""
symlink_cmd = [ os . path . join ( self . _cygwin_bin_location , "ln.exe" ) , "-s" , self . _get_cygwin_path ( initial_path ) , self . _get_cygwin_path ( final_path ) ] process = Popen ( symlink_cmd , stdout = PIPE , stderr = PIPE , shell = False ) out , err = process . communicate ( ) if err : print ( err ) ra...
def MI_get_item ( self , key , index = 0 ) : 'return list of item'
index = _key_to_index_single ( force_list ( self . indices . keys ( ) ) , index ) if index != 0 : key = self . indices [ index ] [ key ] # always use first index key # key must exist value = super ( MIMapping , self ) . __getitem__ ( key ) N = len ( self . indices ) if N == 1 : return [ key ] if N == 2 : ...
def fxy ( z = "sin(3*x)*log(x-y)/3" , x = ( 0 , 3 ) , y = ( 0 , 3 ) , zlimits = ( None , None ) , showNan = True , zlevels = 10 , wire = False , c = "b" , bc = "aqua" , alpha = 1 , texture = "paper" , res = 100 , ) : """Build a surface representing the function : math : ` f ( x , y ) ` specified as a string or as...
if isinstance ( z , str ) : try : z = z . replace ( "math." , "" ) . replace ( "np." , "" ) namespace = locals ( ) code = "from math import*\ndef zfunc(x,y): return " + z exec ( code , namespace ) z = namespace [ "zfunc" ] except : vc . printc ( "Syntax Error in f...
def get_bytes ( num_bytes ) : """Returns a random string of num _ bytes length ."""
# Is this the way to do it ? # s = c _ ubyte ( ) # Or this ? s = create_string_buffer ( num_bytes ) # Used to keep track of status . 1 = success , 0 = error . ok = c_int ( ) # Provider ? hProv = c_ulong ( ) ok = windll . Advapi32 . CryptAcquireContextA ( byref ( hProv ) , None , None , PROV_RSA_FULL , 0 ) ok = windll ....
def get_all_objects ( self ) : "Return pointers to all GC tracked objects"
for i , generation in enumerate ( self . gc_generations ) : generation_head_ptr = pygc_head_ptr = generation . head . get_pointer ( ) generation_head_addr = generation_head_ptr . _value while True : # _ PyObjectBase _ GC _ UNTRACK macro says that # gc _ prev always points to some value # there is st...
def change_nick ( self , nick ) : """Update this user ' s nick in all joined channels ."""
old_nick = self . nick self . nick = IRCstr ( nick ) for c in self . channels : c . users . remove ( old_nick ) c . users . add ( self . nick )
def wait_for_click ( self , button , timeOut = 10.0 ) : """Wait for a mouse click Usage : C { mouse . wait _ for _ click ( self , button , timeOut = 10.0 ) } @ param button : they mouse button click to wait for as a button number , 1-9 @ param timeOut : maximum time , in seconds , to wait for the keypress to ...
button = int ( button ) w = iomediator . Waiter ( None , None , button , timeOut ) w . wait ( )
def formpivot ( self ) : '''- > # tag . match - > form : prop - > form'''
self . ignore ( whitespace ) self . nextmust ( '->' ) self . ignore ( whitespace ) if self . nextchar ( ) == '#' : match = self . tagmatch ( ) return s_ast . PivotToTags ( kids = ( match , ) ) # check for pivot out syntax if self . nextchar ( ) == '*' : self . offs += 1 return s_ast . PivotOut ( ) prop ...
def inverse_transform ( self , y , exogenous = None ) : """Inverse transform a transformed array Inverse the Box - Cox transformation on the transformed array . Note that if truncation happened in the ` ` transform ` ` method , invertibility will not be preserved , and the transformed array may not be perfect...
check_is_fitted ( self , "lam1_" ) lam1 = self . lam1_ lam2 = self . lam2_ y , exog = self . _check_y_exog ( y , exogenous ) if lam1 == 0 : return np . exp ( y ) - lam2 , exog numer = y * lam1 # remove denominator numer += 1. # add 1 back to it de_exp = numer ** ( 1. / lam1 ) # de - exponentiate return de_exp - lam...
def list_instances ( self , machine_state ) : """Returns the list of the instances in the Cloud . in machine _ state of type : class : ` CloudMachineState ` out return _ names of type str VM names . return return _ ids of type str VM ids ."""
if not isinstance ( machine_state , CloudMachineState ) : raise TypeError ( "machine_state can only be an instance of type CloudMachineState" ) ( return_ids , return_names ) = self . _call ( "listInstances" , in_p = [ machine_state ] ) return ( return_ids , return_names )
def deploy_to ( self , displays = None , exclude = [ ] , lock = [ ] ) : """Deploys page to listed display ( specify with display ) . If display is None , deploy to all display . Can specify exclude for which display to exclude . This overwrites the first argument ."""
if displays is None : signs = Sign . objects . all ( ) else : signs = Sign . objects . filter ( display__in = displays ) for sign in signs . exclude ( display__in = exclude ) : sign . pages . add ( self ) sign . save ( )
def new_issuer ( self , issuer_idx , info = None ) : """Add a new issuer to the dataset with the given data . Parameters : issuer _ idx ( str ) : The id to associate the issuer with . If None or already exists , one is generated . info ( dict , list ) : Additional info of the issuer . Returns : Issuer :...
new_issuer_idx = issuer_idx # Add index to idx if already existing if new_issuer_idx in self . _issuers . keys ( ) : new_issuer_idx = naming . index_name_if_in_list ( new_issuer_idx , self . _issuers . keys ( ) ) new_issuer = issuers . Issuer ( new_issuer_idx , info = info ) self . _issuers [ new_issuer_idx ] = new...
def list_sdbs ( self ) : """Return sdbs by Name"""
sdb_raw = self . get_sdbs ( ) sdbs = [ ] for s in sdb_raw : sdbs . append ( s [ 'name' ] ) return sdbs
def get_pixbeam_pixel ( self , x , y ) : """Determine the beam in pixels at the given location in pixel coordinates . Parameters x , y : float The pixel coordinates at which the beam is determined . Returns beam : : class : ` AegeanTools . fits _ image . Beam ` A beam object , with a / b / pa in pixel c...
ra , dec = self . pix2sky ( ( x , y ) ) return self . get_pixbeam ( ra , dec )
def next_unwrittable_on_col ( view , coords ) : """Return position of the next letter ( in column ) that is unwrittable"""
x , y = coords maxy = max ( view . keys ( ) , key = itemgetter ( 1 ) ) [ 1 ] for offset in range ( y + 1 , maxy ) : letter = view [ x , offset ] if letter not in REWRITABLE_LETTERS : return offset return None
def cumprod ( vari , axis = None ) : """Perform the cumulative product of a shapeable quantity over a given axis . Args : vari ( chaospy . poly . base . Poly , numpy . ndarray ) : Input data . axis ( int ) : Axis over which the sum is taken . By default ` ` axis ` ` is None , and all elements are summed...
if isinstance ( vari , Poly ) : if np . prod ( vari . shape ) == 1 : return vari . copy ( ) if axis is None : vari = chaospy . poly . shaping . flatten ( vari ) axis = 0 vari = chaospy . poly . shaping . rollaxis ( vari , axis ) out = [ vari [ 0 ] ] for poly in vari [ 1 : ] :...
def _build_command ( self , cmd , ** kwargs ) : """_ build _ command : string ( binary data ) . . . - > binary data _ build _ command will construct a command packet according to the specified command ' s specification in api _ commands . It will expect named arguments for all fields other than those with a d...
try : cmd_spec = self . api_commands [ cmd ] except AttributeError : raise NotImplementedError ( "API command specifications could not be " "found; use a derived class which defines" " 'api_commands'." ) packet = b'' for field in cmd_spec : try : # Read this field ' s name from the function arguments dict ...
def _redistribute_builder ( self , afi = 'ipv4' , source = None ) : """Build BGP redistribute method . Do not use this method directly . You probably want ` ` redistribute ` ` . Args : source ( str ) : Source for redistributing . ( connected ) afi ( str ) : Address family to configure . ( ipv4 , ipv6) Ret...
if source == 'connected' : return getattr ( self . _rbridge , 'rbridge_id_router_router_bgp_address_family_{0}_' '{0}_unicast_default_vrf_af_{0}_uc_and_vrf_cmds_' 'call_point_holder_redistribute_connected_' 'redistribute_connected' . format ( afi ) ) # TODO : Add support for ' static ' and ' ospf ' else : raise...
def stop_instance ( self , instance_id ) : """Stops the instance gracefully . : param str instance _ id : instance identifier : return : None"""
self . _restore_from_storage ( instance_id ) if self . _start_failed : raise Exception ( 'stop_instance for node %s: failing due to' ' previous errors.' % instance_id ) with self . _resource_lock : try : v_m = self . _qualified_name_to_vm ( instance_id ) if not v_m : err = "stop_inst...
def sip ( self , sip_url , username = None , password = None , url = None , method = None , status_callback_event = None , status_callback = None , status_callback_method = None , ** kwargs ) : """Create a < Sip > element : param sip _ url : SIP URL : param username : SIP Username : param password : SIP Passw...
return self . nest ( Sip ( sip_url , username = username , password = password , url = url , method = method , status_callback_event = status_callback_event , status_callback = status_callback , status_callback_method = status_callback_method , ** kwargs ) )
def flip ( self , axis = 0 , preserve_centroid = False ) : '''Flip the mesh across the given axis : 0 for x , 1 for y , 2 for z . When ` preserve _ centroid ` is True , translate after flipping to preserve the location of the centroid .'''
self . v [ : , axis ] *= - 1 if preserve_centroid : self . v [ : , axis ] -= 2 * self . centroid [ 0 ] self . flip_faces ( )
def g ( x , a , c ) : """Christophe ' s suggestion for residuals , G [ i ] = Sqrt ( Sum _ j ( x [ j ] - a [ i , j ] ) ^ 2 ) - C [ i ]"""
return np . sqrt ( ( ( x - a ) ** 2 ) . sum ( 1 ) ) - c
def mode ( data ) : """Return the most common data point from discrete or nominal data . ` ` mode ` ` assumes discrete data , and returns a single value . This is the standard treatment of the mode as commonly taught in schools : > > > mode ( [ 1 , 1 , 2 , 3 , 3 , 3 , 3 , 4 ] ) This also works with nominal ...
# Generate a table of sorted ( value , frequency ) pairs . hist = collections . Counter ( data ) top = hist . most_common ( 2 ) if len ( top ) == 1 : return top [ 0 ] [ 0 ] elif not top : raise StatisticsError ( 'no mode for empty data' ) elif top [ 0 ] [ 1 ] == top [ 1 ] [ 1 ] : raise StatisticsError ( 'no...
def children_rest_names ( self ) : """Gets the list of all possible children ReST names . Returns : list : list containing all possible rest names as string Example : > > > entity = NUEntity ( ) > > > entity . children _ rest _ names [ " foo " , " bar " ]"""
names = [ ] for fetcher in self . fetchers : names . append ( fetcher . __class__ . managed_object_rest_name ( ) ) return names
def _get_elements ( self , source ) : """Returns the list of HtmlElements for the source : param source : The source list to parse : type source : list : returns : A list of HtmlElements : rtype : list"""
return list ( chain ( * [ self . tree . xpath ( xpath ) for xpath in source ] ) )
def _fix_insert ( self , sql , params ) : """Wrap the passed SQL with IDENTITY _ INSERT statements and apply other necessary fixes ."""
meta = self . query . get_meta ( ) if meta . has_auto_field : if hasattr ( self . query , 'fields' ) : # django 1.4 replaced columns with fields fields = self . query . fields auto_field = meta . auto_field else : # < django 1.4 fields = self . query . columns auto_field = meta ....
def update ( self , key = values . unset , value = values . unset ) : """Update the VariableInstance : param unicode key : The key : param unicode value : The value : returns : Updated VariableInstance : rtype : twilio . rest . serverless . v1 . service . environment . variable . VariableInstance"""
data = values . of ( { 'Key' : key , 'Value' : value , } ) payload = self . _version . update ( 'POST' , self . _uri , data = data , ) return VariableInstance ( self . _version , payload , service_sid = self . _solution [ 'service_sid' ] , environment_sid = self . _solution [ 'environment_sid' ] , sid = self . _solutio...
def form_invalid ( self , post_form , attachment_formset , ** kwargs ) : """Processes invalid forms . Called if one of the forms is invalid . Re - renders the context data with the data - filled forms and errors ."""
if ( attachment_formset and not attachment_formset . is_valid ( ) and len ( attachment_formset . errors ) ) : messages . error ( self . request , self . attachment_formset_general_error_message ) return self . render_to_response ( self . get_context_data ( post_form = post_form , attachment_formset = attachment_for...
def train ( self , net_sizes , epochs , batchsize ) : """Initialize the base trainer"""
self . trainer = ClassificationTrainer ( self . data , self . targets , net_sizes ) self . trainer . learn ( epochs , batchsize ) return self . trainer . evaluate ( batchsize )
def invalid_pixel_mask ( self ) : """Returns a binary mask for the NaN - and zero - valued pixels . Serves as a mask for invalid pixels . Returns : obj : ` BinaryImage ` Binary image where a pixel value greater than zero indicates an invalid pixel ."""
# init mask buffer mask = np . zeros ( [ self . height , self . width , 1 ] ) . astype ( np . uint8 ) # update invalid pixels zero_pixels = self . zero_pixels ( ) nan_pixels = self . nan_pixels ( ) mask [ zero_pixels [ : , 0 ] , zero_pixels [ : , 1 ] ] = BINARY_IM_MAX_VAL mask [ nan_pixels [ : , 0 ] , nan_pixels [ : , ...
def _read_body_by_length ( self , response , file ) : '''Read the connection specified by a length . Coroutine .'''
_logger . debug ( 'Reading body by length.' ) file_is_async = hasattr ( file , 'drain' ) try : body_size = int ( response . fields [ 'Content-Length' ] ) if body_size < 0 : raise ValueError ( 'Content length cannot be negative.' ) except ValueError as error : _logger . warning ( __ ( _ ( 'Invalid co...
def load_fasta_file_as_dict_of_seqrecords ( filename ) : """Load a FASTA file and return the sequences as a dict of { ID : SeqRecord } Args : filename ( str ) : Path to the FASTA file to load Returns : dict : Dictionary of IDs to their SeqRecords"""
results = { } records = load_fasta_file ( filename ) for r in records : results [ r . id ] = r return results
def p_load_code ( p ) : """statement : load _ or _ verify expr ID | load _ or _ verify expr CODE | load _ or _ verify expr CODE expr | load _ or _ verify expr CODE expr COMMA expr"""
if p [ 2 ] . type_ != TYPE . string : api . errmsg . syntax_error_expected_string ( p . lineno ( 3 ) , p [ 2 ] . type_ ) if len ( p ) == 4 : if p [ 3 ] . upper ( ) not in ( 'SCREEN' , 'SCREEN$' , 'CODE' ) : syntax_error ( p . lineno ( 3 ) , 'Unexpected "%s" ID. Expected "SCREEN$" instead' % p [ 3 ] ) ...
def default ( ) : """Retrieves a default Context object , creating it if necessary . The default Context is a global shared instance used every time the default context is retrieved . Attempting to use a Context with no project _ id will raise an exception , so on first use set _ project _ id must be called...
credentials = _utils . get_credentials ( ) if Context . _global_context is None : project = _project . Projects . get_default_id ( credentials ) Context . _global_context = Context ( project , credentials ) else : # Always update the credentials in case the access token is revoked or expired Context . _glob...
def getLayer ( self , name ) : """Get the : class : ` BaseLayer ` with * * name * * . > > > layer = font . getLayer ( " My Layer 2 " )"""
name = normalizers . normalizeLayerName ( name ) if name not in self . layerOrder : raise ValueError ( "No layer with the name '%s' exists." % name ) layer = self . _getLayer ( name ) self . _setFontInLayer ( layer ) return layer
def check_has_docstring ( self , api ) : '''An API class must have a docstring .'''
if not api . __doc__ : msg = 'The Api class "{}" lacks a docstring.' return [ msg . format ( api . __name__ ) ]
def grant_token ( self ) : """获取 Access Token 。 : return : 返回的 JSON 数据包"""
return self . get ( url = "https://api.weixin.qq.com/cgi-bin/token" , params = { "grant_type" : "client_credential" , "appid" : self . appid , "secret" : self . appsecret } )
def get_content ( self , url ) : """Returns the content of a cached resource . Args : url : The url of the resource Returns : The content of the cached resource or None if not in the cache"""
cache_path = self . _url_to_path ( url ) try : with open ( cache_path , 'rb' ) as f : return f . read ( ) except IOError : return None
def train ( self ) : '''The ' train ' subcommand'''
# Initialize the train subcommand ' s argparser parser = argparse . ArgumentParser ( description = 'Train a dialogue model on a dialogue corpus or a dsrt dataset' ) self . init_train_args ( parser ) # Parse the args we got args = parser . parse_args ( sys . argv [ 2 : ] ) args . config = ConfigurationLoader ( args . co...
def prt_hier_down ( self , goid , prt = sys . stdout ) : """Write hierarchy for all GO IDs below GO ID in arg , goid ."""
wrhiercfg = self . _get_wrhiercfg ( ) obj = WrHierPrt ( self . gosubdag . go2obj , self . gosubdag . go2nt , wrhiercfg , prt ) obj . prt_hier_rec ( goid ) return obj . items_list
def _get_attrs ( self ) : """An internal helper for the representation methods"""
attrs = [ ] attrs . append ( ( "N Blocks" , self . n_blocks , "{}" ) ) bds = self . bounds attrs . append ( ( "X Bounds" , ( bds [ 0 ] , bds [ 1 ] ) , "{:.3f}, {:.3f}" ) ) attrs . append ( ( "Y Bounds" , ( bds [ 2 ] , bds [ 3 ] ) , "{:.3f}, {:.3f}" ) ) attrs . append ( ( "Z Bounds" , ( bds [ 4 ] , bds [ 5 ] ) , "{:.3f}...
def gadf ( y , method = "Quantiles" , maxk = 15 , pct = 0.8 ) : """Evaluate the Goodness of Absolute Deviation Fit of a Classifier Finds the minimum value of k for which gadf > pct Parameters y : array ( n , 1 ) values to be classified method : { ' Quantiles , ' Fisher _ Jenks ' , ' Maximum _ Breaks ' , '...
y = np . array ( y ) adam = ( np . abs ( y - np . median ( y ) ) ) . sum ( ) for k in range ( 2 , maxk + 1 ) : cl = kmethods [ method ] ( y , k ) gadf = 1 - cl . adcm / adam if gadf > pct : break return ( k , cl , gadf )
def get_basis_family ( basis_name , data_dir = None ) : '''Lookup a family by a basis set name'''
data_dir = fix_data_dir ( data_dir ) bs_data = _get_basis_metadata ( basis_name , data_dir ) return bs_data [ 'family' ]
def _assert_correct_model ( model_to_check , model_reference , obj_name ) : """Helper that asserts the model _ to _ check is the model _ reference or one of its subclasses . If not , raise an ImplementationError , using " obj _ name " to describe the name of the argument ."""
if not issubclass ( model_to_check , model_reference ) : raise ConfigurationException ( 'The %s model must be a subclass of %s' % ( obj_name , model_reference . __name__ ) )
def read_machine_header ( data ) : """Parse binary header . @ data - bytearray , contains binary header of file opened in ' rb ' mode @ return - parsed binary header"""
if isinstance ( data , ( bytes , bytearray ) ) : stream = io . BytesIO ( data ) elif isinstance ( data , io . BufferedReader ) : stream = data else : raise ValueError ( "data should be either bytearray or file 'rb' mode." ) header = dict ( ) header_type = stream . read ( 6 ) if header_type == b"#!\x00\x01@\...
def strip_and_uniq ( tab ) : """Strip every element of a list and keep a list of ordered unique values : param tab : list to strip : type tab : list : return : stripped list with unique values : rtype : list"""
_list = [ ] for elt in tab : val = elt . strip ( ) if val and val not in _list : _list . append ( val ) return _list
def list_assigned_licenses ( entity , entity_display_name , license_keys = None , service_instance = None ) : '''Lists the licenses assigned to an entity entity Dictionary representation of an entity . See ` ` _ get _ entity ` ` docstrings for format . entity _ display _ name Entity name used in logging ...
log . trace ( 'Listing assigned licenses of entity %s' , entity ) _validate_entity ( entity ) assigned_licenses = salt . utils . vmware . get_assigned_licenses ( service_instance , entity_ref = _get_entity ( service_instance , entity ) , entity_name = entity_display_name ) return [ { 'key' : l . licenseKey , 'name' : l...
def vectorial_decomp ( self , symbols ) : '''Compute the vectorial decomposition of the expression according to the given symbols . symbols is a list that represents the input of the resulting application . They are considerated as a flatten vector of bits . Args : symbols : TODO Returns : An : class : ...
try : symbols = [ s . vec for s in symbols ] N = sum ( map ( lambda s : len ( s ) , symbols ) ) symbols_ = Vector ( N ) i = 0 for v in symbols : for s in v : symbols_ [ i ] = s i += 1 symbols = symbols_ except TypeError : pass return self . mba . vectorial_dec...
def errors ( source , model , wcshelper ) : """Convert pixel based errors into sky coord errors Parameters source : : class : ` AegeanTools . models . SimpleSource ` The source which was fit . model : lmfit . Parameters The model which was fit . wcshelper : : class : ` AegeanTools . wcs _ helpers . WCSH...
# if the source wasn ' t fit then all errors are - 1 if source . flags & ( flags . NOTFIT | flags . FITERR ) : source . err_peak_flux = source . err_a = source . err_b = source . err_pa = ERR_MASK source . err_ra = source . err_dec = source . err_int_flux = ERR_MASK return source # copy the errors from the ...
def loadDHCPOptions ( self , address_family , options ) : """Create a high level DHCPOptions object : param str address _ family : Address family of the options . Can be either dhcpv4 or dhcpv6 : param dict options : Dictionary containing the option set to apply for this address family . Note : only those speci...
import ns1 . ipam return ns1 . ipam . DHCPOptions ( address_family , options )
def info ( package , long_description , classifiers , license ) : """Get info about a package or packages ."""
client = requests . Session ( ) for name_or_url in package : package = get_package ( name_or_url , client ) if not package : secho ( u'Invalid name or URL: "{name}"' . format ( name = name_or_url ) , fg = 'red' , file = sys . stderr ) continue # Name and summary try : info = pack...
def closeEvent ( self , event ) : """Send last file signal on close event : param event : The close event : type event : : returns : None : rtype : None : raises : None"""
lf = self . browser . get_current_selection ( ) if lf : self . last_file . emit ( lf ) return super ( GenesisWin , self ) . close ( )
def make_db_data_fetcher ( postgresql_conn_info , template_path , reload_templates , query_cfg , io_pool ) : """Returns an object which is callable with the zoom and unpadded bounds and which returns a list of rows ."""
sources = parse_source_data ( query_cfg ) queries_generator = make_queries_generator ( sources , template_path , reload_templates ) return DataFetcher ( postgresql_conn_info , queries_generator , io_pool )
def _get_var_array ( self , k , use_raw = False , layer = 'X' ) : """Get an array from the layer ( default layer = ' X ' ) along the variables dimension by first looking up ` ` var . keys ` ` and then ` ` obs . index ` ` ."""
in_raw_obs_names = k in self . raw . obs_names if self . raw is not None else False if use_raw and self . raw is None : raise ValueError ( '.raw doesn\'t exist' ) if k in self . var . keys ( ) : x = self . _var [ k ] elif in_raw_obs_names and use_raw and layer == 'X' : x = self . raw [ k ] . X elif k in sel...
def update ( self , friendly_name = values . unset , chat_service_sid = values . unset , channel_type = values . unset , contact_identity = values . unset , enabled = values . unset , integration_type = values . unset , integration_flow_sid = values . unset , integration_url = values . unset , integration_workspace_sid...
return self . _proxy . update ( friendly_name = friendly_name , chat_service_sid = chat_service_sid , channel_type = channel_type , contact_identity = contact_identity , enabled = enabled , integration_type = integration_type , integration_flow_sid = integration_flow_sid , integration_url = integration_url , integratio...
def change_column ( self , table , column_name , field ) : """Change column ."""
operations = [ self . alter_change_column ( table , column_name , field ) ] if not field . null : operations . extend ( [ self . add_not_null ( table , column_name ) ] ) return operations
def update ( self , app_id , data ) : """Update app identified by app _ id with data : params : * app _ id ( int ) id in the marketplace received with : method : ` create ` * data ( dict ) some keys are required : * * name * : the title of the app . Maximum length 127 characters . * * summary * : the su...
assert ( 'name' in data and data [ 'name' ] and 'summary' in data and 'categories' in data and data [ 'categories' ] and 'support_email' in data and data [ 'support_email' ] and 'device_types' in data and data [ 'device_types' ] and 'payment_type' in data and data [ 'payment_type' ] and 'privacy_policy' in data and dat...
def resolve_variable ( var_name , var_def , provided_variable , blueprint_name ) : """Resolve a provided variable value against the variable definition . Args : var _ name ( str ) : The name of the defined variable on a blueprint . var _ def ( dict ) : A dictionary representing the defined variables attribu...
try : var_type = var_def [ "type" ] except KeyError : raise VariableTypeRequired ( blueprint_name , var_name ) if provided_variable : if not provided_variable . resolved : raise UnresolvedVariable ( blueprint_name , provided_variable ) value = provided_variable . value else : # Variable value no...
def append ( self , obj ) : """Append an object to end . If the object is a string , appends a : class : ` Word < Word > ` object ."""
if isinstance ( obj , basestring ) : return self . _collection . append ( Word ( obj ) ) else : return self . _collection . append ( obj )
def write_to_path ( self , path , suffix = '' , format = 'png' , overwrite = False ) : """Output the data the dataframe ' s ' image ' column to a directory structured by project - > sample and named by frame Args : path ( str ) : Where to write the directory of images suffix ( str ) : for labeling the imaages...
if os . path . exists ( path ) and overwrite is False : raise ValueError ( "Error: use ovewrite=True to overwrite images" ) if not os . path . exists ( path ) : os . makedirs ( path ) for i , r in self . iterrows ( ) : spath = os . path . join ( path , r [ 'project_name' ] , r [ 'sample_name' ] ) if not...
def param ( name , value_info , is_required = True , label = None , desc = None ) : """Annotate a parameter of the action being defined . @ param name : name of the parameter defined . @ type name : unicode or str @ param value _ info : the parameter value information . @ type value _ info : value . IValueI...
_annotate ( "param" , name , value_info , is_required = is_required , label = label , desc = desc )
def wrapinstance ( ptr , base = None ) : """convert a pointer to a Qt class instance ( PySide / PyQt compatible )"""
if ptr is None : return None ptr = long ( ptr ) # Ensure type from wishlib . qt import active , QtCore , QtGui if active == "PySide" : import shiboken if base is None : qObj = shiboken . wrapInstance ( ptr , QtCore . QObject ) metaObj = qObj . metaObject ( ) cls = metaObj . className...
def socket_closed ( self , sock ) : """Return True if we know socket has been closed , False otherwise ."""
while True : try : if self . _poller : with self . _lock : self . _poller . register ( sock , _EVENT_MASK ) try : rd = self . _poller . poll ( 0 ) finally : self . _poller . unregister ( sock ) else :...
def head_title ( request ) : """{ % head _ title request % }"""
try : fragments = request . _feincms_fragments except : fragments = { } if '_head_title' in fragments and fragments . get ( "_head_title" ) : return fragments . get ( "_head_title" ) else : # append site name site_name = getattr ( settings , 'LEONARDO_SITE_NAME' , '' ) if site_name != '' : r...
def GetAdaptersAddresses ( AF = AF_UNSPEC ) : """Return all Windows Adapters addresses from iphlpapi"""
# We get the size first size = ULONG ( ) flags = GAA_FLAG_INCLUDE_PREFIX res = _GetAdaptersAddresses ( AF , flags , None , None , byref ( size ) ) if res != 0x6f : # BUFFER OVERFLOW - > populate size raise RuntimeError ( "Error getting structure length (%d)" % res ) # Now let ' s build our buffer pointer_type = POI...
def kendall_tau ( query_dic , mark ) : """Calculate kendall _ tau metric result of a method : param query _ dic : dict , key is qid , value is ( item , bleu ) tuple list , which will be ranked by ' item ' as key : param mark : string , which indicates which method is evaluated , also used as output file name he...
total = 0.0 with open ( kendall_tau_path + mark , 'w' ) as writer : for k in query_dic : candidate_lst = query_dic [ k ] ordered_lst = sorted ( candidate_lst , key = lambda a : a [ 0 ] , reverse = True ) rank_lst = [ can [ 1 ] for can in ordered_lst ] tau_value = calculate_lst_kendal...
def _init_prior_posterior ( self , rank , R , n_local_subj ) : """set prior for this subject Parameters rank : integer The rank of this process R : list of 2D arrays , element i has shape = [ n _ voxel , n _ dim ] Each element in the list contains the scanner coordinate matrix of fMRI data of one subjec...
if rank == 0 : idx = np . random . choice ( n_local_subj , 1 ) self . global_prior_ , self . global_centers_cov , self . global_widths_var = self . get_template ( R [ idx [ 0 ] ] ) self . global_centers_cov_scaled = self . global_centers_cov / float ( self . n_subj ) self . global_widths_var_scaled = se...
def OpenFileSystem ( cls , path_spec_object , resolver_context = None ) : """Opens a file system object defined by path specification . Args : path _ spec _ object ( PathSpec ) : path specification . resolver _ context ( Optional [ Context ] ) : resolver context , where None represents the built in context ...
if not isinstance ( path_spec_object , path_spec . PathSpec ) : raise TypeError ( 'Unsupported path specification type.' ) if resolver_context is None : resolver_context = cls . _resolver_context if path_spec_object . type_indicator == definitions . TYPE_INDICATOR_MOUNT : if path_spec_object . HasParent ( )...