signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def startMenu ( translator , navigation , tag ) : """Drop - down menu - style navigation view . For each primary navigation element available , a copy of the I { tab } pattern will be loaded from the tag . It will have its I { href } slot filled with the URL for that navigation item . It will have its I { nam...
setTabURLs ( navigation , translator ) getp = IQ ( tag ) . onePattern def fillSlots ( tabs ) : for tab in tabs : if tab . children : kids = getp ( 'subtabs' ) . fillSlots ( 'kids' , fillSlots ( tab . children ) ) else : kids = '' yield dictFillSlots ( getp ( 'tab' ) ,...
def _update_plotting_params ( self , ** kwargs ) : """Some plotting parameters can be changed through the tool ; this updataes those plotting parameters ."""
scalars = kwargs . get ( 'scalars' , None ) if scalars is not None : old = self . display_params [ 'scalars' ] self . display_params [ 'scalars' ] = scalars if old != scalars : self . plotter . subplot ( * self . loc ) self . plotter . remove_actor ( self . _data_to_update , reset_camera = F...
def get_mean_values ( self , C , sites , rup , dists , a1100 ) : """Returns the mean values for a specific IMT"""
if isinstance ( a1100 , np . ndarray ) : # Site model defined temp_vs30 = sites . vs30 temp_z2pt5 = sites . z2pt5 else : # Default site and basin model temp_vs30 = 1100.0 * np . ones ( len ( sites . vs30 ) ) temp_z2pt5 = self . _select_basin_model ( 1100.0 ) * np . ones_like ( temp_vs30 ) return ( self ...
def diff ( name ) : '''Get information on changes made to container ' s filesystem since it was created . Equivalent to running the ` ` docker diff ` ` Docker CLI command . name Container name or ID * * RETURN DATA * * A dictionary containing any of the following keys : - ` ` Added ` ` - A list of paths...
changes = _client_wrapper ( 'diff' , name ) kind_map = { 0 : 'Changed' , 1 : 'Added' , 2 : 'Deleted' } ret = { } for change in changes : key = kind_map . get ( change [ 'Kind' ] , 'Unknown' ) ret . setdefault ( key , [ ] ) . append ( change [ 'Path' ] ) if 'Unknown' in ret : log . error ( 'Unknown changes d...
def generateRevision ( self ) : """Generates the revision file for this builder ."""
revpath = self . sourcePath ( ) if not os . path . exists ( revpath ) : return # determine the revision location revfile = os . path . join ( revpath , self . revisionFilename ( ) ) mode = '' # test for svn revision try : args = [ 'svn' , 'info' , revpath ] proc = subprocess . Popen ( args , stdout = subpro...
def send_mail_worker ( config , mail , event ) : """Worker task to send out an email , which blocks the process unless it is threaded"""
log = "" try : if config . mail_ssl : server = SMTP_SSL ( config . mail_server , port = config . mail_server_port , timeout = 30 ) else : server = SMTP ( config . mail_server , port = config . mail_server_port , timeout = 30 ) if config . mail_tls : log += 'Starting TLS\n' se...
def remove_if_same ( self , key , value ) : """Removes the entry for a key only if it is currently mapped to a given value . This is equivalent to : > > > if map . contains _ key ( key ) and map . get ( key ) . equals ( value ) : > > > map . remove ( key ) > > > return true > > > else : > > > return fal...
check_not_none ( key , "key can't be None" ) check_not_none ( value , "value can't be None" ) key_data = self . _to_data ( key ) value_data = self . _to_data ( value ) return self . _remove_if_same_internal_ ( key_data , value_data )
def _GenOpenApiSpec ( service_class_names , output_path , hostname = None , application_path = None , x_google_api_name = False ) : """Write openapi documents generated from the service classes to file . Args : service _ class _ names : A list of fully qualified ProtoRPC service names . output _ path : The di...
output_files = [ ] service_configs = GenApiConfig ( service_class_names , hostname = hostname , config_string_generator = openapi_generator . OpenApiGenerator ( ) , application_path = application_path , x_google_api_name = x_google_api_name ) for api_name_version , config in service_configs . iteritems ( ) : openap...
def to_array ( self , variables ) : """Converts the clamping to a 1 - D array with respect to the given variables Parameters variables : list [ str ] List of variables names Returns ` numpy . ndarray ` _ 1 - D array where position ` i ` correspond to the sign of the clamped variable at position ` i ` ...
arr = np . zeros ( len ( variables ) , np . int8 ) dc = dict ( self ) for i , var in enumerate ( variables ) : arr [ i ] = dc . get ( var , arr [ i ] ) return arr
def orbitproject ( x , y , inc , phi = 0 , psi = 0 ) : """Transform x , y planar coordinates into observer ' s coordinate frame . x , y are coordinates in z = 0 plane ( plane of the orbit ) observer is at ( inc , phi ) on celestial sphere ( angles in radians ) ; psi is orientation of final x - y axes about th...
x2 = x * np . cos ( phi ) + y * np . sin ( phi ) y2 = - x * np . sin ( phi ) + y * np . cos ( phi ) z2 = y2 * np . sin ( inc ) y2 = y2 * np . cos ( inc ) xf = x2 * np . cos ( psi ) - y2 * np . sin ( psi ) yf = x2 * np . sin ( psi ) + y2 * np . cos ( psi ) return ( xf , yf , z2 )
def _get_info ( self ) : """Reads the tool ' s output from its stderr stream , extracts the relevant information , and parses it ."""
out_parts = [ ] while True : line = self . proc . stderr . readline ( ) if not line : # EOF and data not found . raise CommunicationError ( "stream info not found" ) # In Python 3 , result of reading from stderr is bytes . if isinstance ( line , bytes ) : line = line . decode ( 'utf8' , ...
def get_layout ( name , * args , ** kwargs ) : """Retrieve a graph layout Some graph layouts accept extra options . Please refer to their documentation for more information . Parameters name : string The name of the layout . The variable ` AVAILABLE _ LAYOUTS ` contains all available layouts . * args ...
if name not in _layout_map : raise KeyError ( "Graph layout '%s' not found. Should be one of %s" % ( name , AVAILABLE_LAYOUTS ) ) layout = _layout_map [ name ] if inspect . isclass ( layout ) : layout = layout ( * args , ** kwargs ) return layout
def sh ( cmd , grid = False , infile = None , outfile = None , errfile = None , append = False , background = False , threaded = None , log = True , grid_opts = None , silent = False , shell = "/bin/bash" , check = False ) : """simple wrapper for system calls"""
if not cmd : return 1 if silent : outfile = errfile = "/dev/null" if grid : from jcvi . apps . grid import GridProcess pr = GridProcess ( cmd , infile = infile , outfile = outfile , errfile = errfile , threaded = threaded , grid_opts = grid_opts ) pr . start ( ) return pr . jobid else : if i...
def del_repo ( repo , ** kwargs ) : '''Remove an XBPS repository from the system . repo url of repo to remove ( persistent ) . CLI Examples : . . code - block : : bash salt ' * ' pkg . del _ repo < repo url >'''
try : _locate_repo_files ( repo , rewrite = True ) except IOError : return False else : return True
def get_cf_distribution_class ( ) : """Return the correct troposphere CF distribution class ."""
if LooseVersion ( troposphere . __version__ ) == LooseVersion ( '2.4.0' ) : cf_dist = cloudfront . Distribution cf_dist . props [ 'DistributionConfig' ] = ( DistributionConfig , True ) return cf_dist return cloudfront . Distribution
def export_jwks_as_json ( self , private = False , issuer = "" ) : """Export a JWKS as a JSON document . : param private : Whether it should be the private keys or the public : param issuer : The entity ID . : return : A JSON representation of a JWKS"""
return json . dumps ( self . export_jwks ( private , issuer ) )
def mark_offer_as_unclear ( self , offer_id ) : """Mark offer as unclear : param offer _ id : the offer id : return Response"""
return self . _create_put_request ( resource = OFFERS , billomat_id = offer_id , command = UNCLEAR , )
def focusOutEvent ( self , event ) : """Reimplement Qt method to close the widget when loosing focus ."""
event . ignore ( ) # Inspired from CompletionWidget . focusOutEvent ( ) in file # widgets / sourcecode / base . py line 212 if sys . platform == "darwin" : if event . reason ( ) != Qt . ActiveWindowFocusReason : self . close ( ) else : self . close ( )
def is_point ( nc , variable ) : '''Returns true if the variable is a point feature type : param netCDF4 . Dataset nc : An open netCDF dataset : param str variable : name of the variable to check'''
# x ( o ) , y ( o ) , z ( o ) , t ( o ) # X ( o ) dims = nc . variables [ variable ] . dimensions cmatrix = coordinate_dimension_matrix ( nc ) first_coord = None if 't' in cmatrix : first_coord = cmatrix [ 't' ] if len ( cmatrix [ 't' ] ) > 1 : return False if 'x' in cmatrix : if first_coord is None...
def manage_view ( request , semester , profile = None ) : """View all members ' preferences . This view also includes forms to create an entire semester ' s worth of weekly workshifts ."""
page_name = "Manage Workshift" pools = WorkshiftPool . objects . filter ( semester = semester ) full_management = utils . can_manage ( request . user , semester = semester ) edit_semester_form = None close_semester_form = None open_semester_form = None if not full_management : pools = pools . filter ( managers__inc...
def rm ( self , fname = None ) : """Remove a file , don ' t raise exception if file does not exist ."""
if fname is not None : return ( self / fname ) . rm ( ) try : self . remove ( ) except OSError : pass
def setup_coverage ( config , kernel , floc , output_loc = None ) : """Start coverage reporting in kernel . Currently supported kernel languages are : - Python"""
language = kernel . language if language . startswith ( 'python' ) : # Get the pytest - cov coverage object cov = get_cov ( config ) if cov : # If present , copy the data file location used by pytest - cov data_file = os . path . abspath ( cov . config . data_file ) else : # Fall back on output _ lo...
def _rdsignal ( fp , file_size , header_size , n_sig , bit_width , is_signed , cut_end ) : """Read the signal Parameters cut _ end : bool , optional If True , enables reading the end of files which appear to terminate with the incorrect number of samples ( ie . sample not present for all channels ) , by c...
# Cannot initially figure out signal length because there # are escape sequences . fp . seek ( header_size ) signal_size = file_size - header_size byte_width = int ( bit_width / 8 ) # numpy dtype dtype = str ( byte_width ) if is_signed : dtype = 'i' + dtype else : dtype = 'u' + dtype # big endian dtype = '>' + ...
def couple ( f , g ) : r"""Compose a function thate returns two arguments . Given a pair of functions that take the same arguments , return a single function that returns a pair consisting of the return values of each function . Notes Equivalent to : : lambda f , g : lambda * args , * * kwargs : ( f ( *...
def coupled ( * args , ** kwargs ) : return f ( * args , ** kwargs ) , g ( * args , ** kwargs ) return coupled
def immediateAssignmentExtended ( StartingTime_presence = 0 ) : """IMMEDIATE ASSIGNMENT EXTENDED Section 9.1.19"""
a = L2PseudoLength ( ) b = TpPd ( pd = 0x6 ) c = MessageType ( mesType = 0x39 ) # 00111001 d = PageModeAndSpareHalfOctets ( ) f = ChannelDescription ( ) g = RequestReference ( ) h = TimingAdvance ( ) i = MobileAllocation ( ) packet = a / b / c / d / f / g / h / i if StartingTime_presence is 1 : j = StartingTimeHdr ...
def _parse_contract_wages ( self , table ) : """Parse the wages on the contract . The wages are listed as the data points in the contract table . Any values that don ' t have a value which starts with a ' $ ' sign are likely not valid and should be dropped . Parameters table : PyQuery object A PyQuery o...
wages = [ i . text ( ) if i . text ( ) . startswith ( '$' ) else '' for i in table ( 'td' ) . items ( ) ] wages . remove ( '' ) return wages
def labelHealpix ( pixels , values , nside , threshold = 0 , xsize = 1000 ) : """Label contiguous regions of a ( sparse ) HEALPix map . Works by mapping HEALPix array to a Mollweide projection and applying scipy . ndimage . label Assumes non - nested HEALPix map . Parameters : pixels : Pixel values associat...
proj = healpy . projector . MollweideProj ( xsize = xsize ) vec = healpy . pix2vec ( nside , pixels ) xy = proj . vec2xy ( vec ) ij = proj . xy2ij ( xy ) xx , yy = proj . ij2xy ( ) # Convert to Mollweide searchims = [ ] if values . ndim < 2 : iterate = [ values ] else : iterate = values . T for i , value in enu...
def quit ( self ) : """Remove this user from all channels and reinitialize the user ' s list of joined channels ."""
for c in self . channels : c . users . remove ( self . nick ) self . channels = [ ]
def confidential_login ( credentials = None , client_id = None , client_secret = None , services = None , make_clients = True , token_dir = DEFAULT_CRED_PATH ) : """Log in to Globus services as a confidential client ( a client with its own login information ) . Arguments : credentials ( str or dict ) : A stri...
DEFAULT_CRED_FILENAME = "confidential_globus_login.json" # Read credentials if supplied if credentials : if type ( credentials ) is str : try : with open ( credentials ) as cred_file : creds = json . load ( cred_file ) except IOError : try : cr...
def _get_rnn_layer ( mode , num_layers , input_size , hidden_size , dropout , weight_dropout ) : """create rnn layer given specs"""
if mode == 'rnn_relu' : rnn_block = functools . partial ( rnn . RNN , activation = 'relu' ) elif mode == 'rnn_tanh' : rnn_block = functools . partial ( rnn . RNN , activation = 'tanh' ) elif mode == 'lstm' : rnn_block = rnn . LSTM elif mode == 'gru' : rnn_block = rnn . GRU block = rnn_block ( hidden_siz...
def register_actions ( self , shortcut_manager ) : """Register callback methods for triggered actions : param rafcon . gui . shortcut _ manager . ShortcutManager shortcut _ manager :"""
shortcut_manager . add_callback_for_action ( "undo" , self . undo ) shortcut_manager . add_callback_for_action ( "redo" , self . redo )
def _check_cmd ( call ) : '''Check the output of the cmd . run _ all function call .'''
if call [ 'retcode' ] != 0 : comment = '' std_err = call . get ( 'stderr' ) std_out = call . get ( 'stdout' ) if std_err : comment += std_err if std_out : comment += std_out raise CommandExecutionError ( 'Error running command: {0}' . format ( comment ) ) return call
def _prepare_output ( topics_with_wrong_rf , verbose ) : """Returns dict with ' raw ' and ' message ' keys filled ."""
out = { } topics_count = len ( topics_with_wrong_rf ) out [ 'raw' ] = { 'topics_with_wrong_replication_factor_count' : topics_count , } if topics_count == 0 : out [ 'message' ] = 'All topics have proper replication factor.' else : out [ 'message' ] = ( "{0} topic(s) have replication factor lower than specified ...
def get_ssh_gateway_config ( vm_ ) : '''Return the ssh _ gateway configuration .'''
ssh_gateway = config . get_cloud_config_value ( 'ssh_gateway' , vm_ , __opts__ , default = None , search_global = False ) # Check to see if a SSH Gateway will be used . if not isinstance ( ssh_gateway , six . string_types ) : return None # Create dictionary of configuration items # ssh _ gateway ssh_gateway_config ...
def list_huisnummers_by_straat ( self , straat , sort = 1 ) : '''List all ` huisnummers ` in a ` Straat ` . : param straat : The : class : ` Straat ` for which the ` huisnummers ` are wanted . : rtype : A : class : ` list ` of : class : ` Huisnummer `'''
try : id = straat . id except AttributeError : id = straat def creator ( ) : res = crab_gateway_request ( self . client , 'ListHuisnummersWithStatusByStraatnaamId' , id , sort ) try : return [ Huisnummer ( r . HuisnummerId , r . StatusHuisnummer , r . Huisnummer , id ) for r in res . HuisnummerW...
def install_handler ( self , event_type , handler , user_handle = None ) : """Installs handlers for event callbacks in this resource . : param event _ type : Logical event identifier . : param handler : Interpreted as a valid reference to a handler to be installed by a client application . : param user _ hand...
return self . visalib . install_visa_handler ( self . session , event_type , handler , user_handle )
def initialize_outlineexplorer ( self ) : """This method is called separately from ' set _ oulineexplorer ' to avoid doing unnecessary updates when there are multiple editor windows"""
for index in range ( self . get_stack_count ( ) ) : if index != self . get_stack_index ( ) : self . _refresh_outlineexplorer ( index = index )
def loop ( self , timeout = 1 ) : """Main loop ."""
rlist = [ self . sock ] wlist = [ ] if len ( self . out_packet ) > 0 : wlist . append ( self . sock ) to_read , to_write , _ = select . select ( rlist , wlist , [ ] , timeout ) if len ( to_read ) > 0 : ret , _ = self . loop_read ( ) if ret != NC . ERR_SUCCESS : return ret if len ( to_write ) > 0 : ...
def _ingest_response ( self , response ) : '''Takes a response object and ingests state , links , embedded documents and updates the self link of this navigator to correspond . This will only work if the response is valid JSON'''
self . response = response if self . _can_parse ( response . headers [ 'Content-Type' ] ) : hal_json = self . _parse_content ( response . text ) else : raise exc . HALNavigatorError ( message = "Unexpected content type! Wanted {0}, got {1}" . format ( self . headers . get ( 'Accept' , self . DEFAULT_CONTENT_TYP...
def set_color_temp ( self , color_temp ) : """Set device color ."""
if self . _json_state [ 'control_url' ] : url = CONST . INTEGRATIONS_URL + self . _device_uuid color_data = { 'action' : 'setcolortemperature' , 'colorTemperature' : int ( color_temp ) } response = self . _abode . send_request ( "post" , url , data = color_data ) response_object = json . loads ( respons...
def get_site_pattern ( agent ) : """Construct a dictionary of Monomer site states from an Agent . This crates the mapping to the associated PySB monomer from an INDRA Agent object ."""
if not isinstance ( agent , ist . Agent ) : return { } pattern = { } # Handle bound conditions for bc in agent . bound_conditions : # Here we make the assumption that the binding site # is simply named after the binding partner if bc . is_bound : pattern [ get_binding_site_name ( bc . agent ) ] = ANY ...
def run_command ( command , args ) : """Run all tasks registered in a command ."""
for category , commands in iteritems ( command_categories ) : for existing_command in commands : if existing_command . match ( command ) : existing_command . run ( args )
def channels_remove_moderator ( self , room_id , user_id , ** kwargs ) : """Removes the role of moderator from a user in the current channel ."""
return self . __call_api_post ( 'channels.removeModerator' , roomId = room_id , userId = user_id , kwargs = kwargs )
def _multi_take ( self , tup ) : """Create the indexers for the passed tuple of keys , and execute the take operation . This allows the take operation to be executed all at once - rather than once for each dimension - improving efficiency . Parameters tup : tuple Tuple of indexers , one per axis Returns...
# GH 836 o = self . obj d = { axis : self . _get_listlike_indexer ( key , axis ) for ( key , axis ) in zip ( tup , o . _AXIS_ORDERS ) } return o . _reindex_with_indexers ( d , copy = True , allow_dups = True )
def _warmup ( self , num_updates ) : """Returns linearly increasing fraction of base _ lr ."""
assert self . base_lr is not None if not self . warmup : return self . base_lr fraction = ( num_updates + 1 ) * self . base_lr / ( self . warmup + 1 ) if num_updates > self . last_warmup_log and num_updates % self . log_warmup_every_t == 0 : self . last_warmup_log = num_updates logger . info ( "Learning rat...
def short_text__str ( self , column_name , output_column_prefix ) : """Transforms short text into a dictionary of TFIDF - weighted 3 - gram character counts ."""
from . _ngram_counter import NGramCounter from . _tfidf import TFIDF return [ NGramCounter ( features = [ column_name ] , n = 3 , method = "character" , output_column_prefix = output_column_prefix ) , TFIDF ( features = [ column_name ] , min_document_frequency = 0.01 , max_document_frequency = 0.5 , output_column_prefi...
def bind ( * args ) : """bind a list of clients and servers together , top down ."""
if _debug : bind . _debug ( "bind %r" , args ) # generic bind is pairs of names if not args : # find unbound clients and bind them for cid , client in client_map . items ( ) : # skip those that are already bound if client . clientPeer : continue if not cid in server_map : ...
def _IndexedScan ( self , i , max_records = None ) : """Scan records starting with index i ."""
self . _ReadIndex ( ) # The record number that we will read next . idx = 0 # The timestamp that we will start reading from . start_ts = 0 if i >= self . _max_indexed : start_ts = max ( ( 0 , 0 ) , ( self . _index [ self . _max_indexed ] [ 0 ] , self . _index [ self . _max_indexed ] [ 1 ] - 1 ) ) idx = self . _m...
def parse_vmware_file ( path ) : """Parses a VMware file ( VMX , preferences or inventory ) . : param path : path to the VMware file : returns : dict"""
pairs = OrderedDict ( ) encoding = "utf-8" # get the first line to read the . encoding value with open ( path , "rb" ) as f : line = f . readline ( ) . decode ( encoding , errors = "ignore" ) if line . startswith ( "#!" ) : # skip the shebang line = f . readline ( ) . decode ( encoding , errors = "ignor...
def render ( self , ctx = None ) : '''Render only the mutated field ( or the first one if not in mutation ) : param ctx : rendering context in which the method was called : rtype : ` Bits ` : return : rendered value of the container'''
if ctx is None : ctx = RenderContext ( ) ctx . push ( self ) self . _initialize ( ) offset = self . offset if self . offset else 0 self . _fields [ self . _field_idx ] . set_offset ( offset ) rendered = self . _fields [ self . _field_idx ] . render ( ctx ) self . set_current_value ( rendered ) ctx . pop ( ) return ...
def initialize_means ( data , clusters , k ) : """Initializes the M matrix given the data and a set of cluster labels . Cluster centers are set to the mean of each cluster . Args : data ( array ) : genes x cells clusters ( array ) : 1d array of ints ( 0 . . . k - 1) k ( int ) : number of clusters"""
init_w = np . zeros ( ( data . shape [ 0 ] , k ) ) if sparse . issparse ( data ) : for i in range ( k ) : if data [ : , clusters == i ] . shape [ 1 ] == 0 : point = np . random . randint ( 0 , data . shape [ 1 ] ) init_w [ : , i ] = data [ : , point ] . toarray ( ) . flatten ( ) ...
def sinLdot_fc ( tfdata , pfdata ) : """Apply sin of theta times the L operator to the data in the Fourier domain ."""
dphi_fc ( tfdata ) sin_fc ( pfdata ) dtheta_fc ( pfdata ) return 1j * ( tfdata - pfdata )
def curve_reduce_approx ( curve , reduced ) : """Image for : meth : ` . curve . Curve . reduce ` docstring ."""
if NO_IMAGES : return ax = curve . plot ( 256 ) color = ax . lines [ - 1 ] . get_color ( ) add_patch ( ax , curve . _nodes , color , alpha = 0.25 , node_color = color ) reduced . plot ( 256 , ax = ax ) color = ax . lines [ - 1 ] . get_color ( ) add_patch ( ax , reduced . _nodes , color , alpha = 0.25 , node_color =...
def _parse_bands ( lines , n_start ) : """Parse band structure from cp2k output"""
kpoints = [ ] labels = [ ] bands_s1 = [ ] bands_s2 = [ ] known_kpoints = { } pattern = re . compile ( ".*?Nr.*?Spin.*?K-Point.*?" , re . DOTALL ) selected_lines = lines [ n_start : ] for current_line , line in enumerate ( selected_lines ) : splitted = line . split ( ) if "KPOINTS| Special K-Point" in line : ...
def post_events ( self , events ) : """Posts a single event to the Keen IO API . The write key must be set first . : param events : an Event to upload"""
url = "{0}/{1}/projects/{2}/events" . format ( self . base_url , self . api_version , self . project_id ) headers = utilities . headers ( self . write_key ) payload = json . dumps ( events ) response = self . fulfill ( HTTPMethods . POST , url , data = payload , headers = headers , timeout = self . post_timeout ) self ...
def VxLANTunnelState_originator_switch_info_switchVcsId ( self , ** kwargs ) : """Auto Generated Code"""
config = ET . Element ( "config" ) VxLANTunnelState = ET . SubElement ( config , "VxLANTunnelState" , xmlns = "http://brocade.com/ns/brocade-notification-stream" ) originator_switch_info = ET . SubElement ( VxLANTunnelState , "originator-switch-info" ) switchVcsId = ET . SubElement ( originator_switch_info , "switchVcs...
def _assert_relation_does_not_exists ( self ) : """Check if a relation with the current related _ name doesn ' t already exists for the related model"""
relations = self . database . _relations [ self . related_to ] existing = [ r for r in relations if r [ 2 ] == self . related_name ] if existing : error = ( "The related name defined for the field '%s.%s', named '%s', already exists " "on the model '%s' (tied to the field '%s.%s')" ) raise ImplementationError (...
def _upload ( self , archive , region ) : """Upload function source and return source url"""
# Generate source upload url url = self . client . execute_command ( 'generateUploadUrl' , { 'parent' : 'projects/{}/locations/{}' . format ( self . session . get_default_project ( ) , region ) } ) . get ( 'uploadUrl' ) log . debug ( "uploading function code %s" , url ) http = self . _get_http_client ( self . client ) ...
def _set_number_of_plots ( self , n ) : """Adjusts number of plots & curves to the desired value the gui ."""
# multi plot , right number of plots and curves = great ! if self . button_multi . is_checked ( ) and len ( self . _curves ) == len ( self . plot_widgets ) and len ( self . _curves ) == n : return # single plot , right number of curves = great ! if not self . button_multi . is_checked ( ) and len ( self . plot_widg...
def get_code ( self ) : """Returns code representation of value of widget"""
selection = self . GetSelection ( ) if selection == wx . NOT_FOUND : selection = 0 # Return code string return self . styles [ selection ] [ 1 ]
def rgbmap_cb ( self , rgbmap , channel ) : """This method is called when the RGBMap is changed . We update the ColorBar to match ."""
if not self . gui_up : return fitsimage = channel . fitsimage if fitsimage != self . fv . getfocus_fitsimage ( ) : return False self . change_cbar ( self . fv , channel )
def get_trg_ids ( self , src_ids : np . ndarray ) -> np . ndarray : """Lookup possible target ids for input sequence of source ids . : param src _ ids : Sequence ( s ) of source ids ( any shape ) . : return : Possible target ids for source ( unique sorted , always includes special symbols ) ."""
# TODO : When MXNet adds support for set operations , we can migrate to avoid conversions to / from NumPy . unique_src_ids = np . lib . arraysetops . unique ( src_ids ) trg_ids = np . lib . arraysetops . union1d ( self . always_allow , self . lex [ unique_src_ids , : ] . reshape ( - 1 ) ) return trg_ids
def _add_logger_by_name ( self , name ) : '''Handles POST requests for adding a new logger . Expects logger configuration to be passed in the request ' s query string . The logger name is included in the URL and the address components and connection type should be included as well . The loc attribute is def...
data = dict ( request . forms ) loc = data . pop ( 'loc' , '' ) port = data . pop ( 'port' , None ) conn_type = data . pop ( 'conn_type' , None ) if not port or not conn_type : e = 'Port and/or conn_type not set' raise ValueError ( e ) address = [ loc , int ( port ) ] if 'rotate_log' in data : data [ 'rotat...
def controller ( url_prefix_or_controller_cls : Union [ str , Type [ Controller ] ] , controller_cls : Optional [ Type [ Controller ] ] = None , * , rules : Optional [ Iterable [ Union [ Route , RouteGenerator ] ] ] = None , ) -> RouteGenerator : """This function is used to register a controller class ' s routes . ...
url_prefix , controller_cls = _normalize_args ( url_prefix_or_controller_cls , controller_cls , _is_controller_cls ) url_prefix = url_prefix or controller_cls . Meta . url_prefix routes = [ ] controller_routes = getattr ( controller_cls , CONTROLLER_ROUTES_ATTR ) if rules is None : routes = controller_routes . valu...
def _collect_dirty_tabs ( self , exept = None ) : """Collects the list of dirty tabs"""
widgets = [ ] filenames = [ ] for i in range ( self . count ( ) ) : widget = self . widget ( i ) try : if widget . dirty and widget != exept : widgets . append ( widget ) filenames . append ( widget . file . path ) except AttributeError : pass return widgets , filenam...
def concatenate_variables ( scope , variables , container ) : '''This function allocate operators to from a float tensor by concatenating all input variables . Notice that if all integer inputs would be converted to floats before concatenation .'''
# Check if it ' s possible to concatenate those inputs . type_set = set ( type ( variable . type ) for variable in variables ) number_type_set = { FloatType , FloatTensorType , Int64Type , Int64TensorType } if StringType in type_set and any ( number_type in type_set for number_type in number_type_set ) : raise Runt...
def p_speed_information_duration ( self , p ) : 'speed : information IN duration'
logger . debug ( 'speed = information %s in duration %s' , p [ 1 ] , p [ 3 ] ) p [ 0 ] = p [ 1 ] . in_duration ( p [ 3 ] )
def _run_cnvkit_cancer ( items , background ) : """Run CNVkit on a tumor / normal pair ."""
paired = vcfutils . get_paired_bams ( [ x [ "align_bam" ] for x in items ] , items ) normal_data = [ x for x in items if dd . get_sample_name ( x ) != paired . tumor_name ] tumor_ready , normal_ready = _match_batches ( paired . tumor_data , normal_data [ 0 ] if normal_data else None ) ckouts = _run_cnvkit_shared ( [ tu...
def is_symbol_wildcard ( term : Any ) -> bool : """Return True iff the given term is a subclass of : class : ` . Symbol ` ."""
return isinstance ( term , type ) and issubclass ( term , Symbol )
def parse ( self , xml_data ) : """Parse XML data"""
# parse tree try : root = ET . fromstring ( xml_data ) except StdlibParseError as e : raise ParseError ( str ( e ) ) self . origin = root . attrib [ 'origin' ] for child in root : component = Component ( ) component . parse ( child ) self . components [ component . id ] = component
def setHalfLife ( self , halfLife , timeUnit ) : """Set number of batches after which the centroids of that particular batch has half the weightage ."""
self . _timeUnit = timeUnit self . _decayFactor = exp ( log ( 0.5 ) / halfLife ) return self
def settimeout ( self , timeout ) : '''Set the timeout value for this socket .'''
if timeout is None : self . _block = True elif float ( timeout ) == 0.0 : self . _block = False else : self . _timeout = float ( timeout ) self . _block = True
def role_exists ( name , region = None , key = None , keyid = None , profile = None ) : '''Check to see if an IAM role exists . CLI Example : . . code - block : : bash salt myminion boto _ iam . role _ exists myirole'''
conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) try : conn . get_role ( name ) return True except boto . exception . BotoServerError : return False
def check_as_b_send_completion ( self ) : """Checks if the current asynchronous send job was completed and terminates immediately ."""
op_result = ctypes . c_int32 ( ) result = self . library . Par_CheckAsBSendCompletion ( self . pointer , ctypes . byref ( op_result ) ) return_values = { 0 : "job complete" , 1 : "job in progress" , - 2 : "invalid handled supplied" , } if result == - 2 : raise Snap7Exception ( "The Client parameter was invalid" ) r...
def containers ( self ) : """The containers that are connected to the network , as a list of : py : class : ` ~ docker . models . containers . Container ` objects ."""
return [ self . client . containers . get ( cid ) for cid in ( self . attrs . get ( 'Containers' ) or { } ) . keys ( ) ]
def grouping ( f = None , interaction = [ 'call' , 'text' ] , summary = 'default' , user_kwd = False ) : """` ` grouping ` ` is a decorator for indicator functions , used to simplify the source code . Parameters f : function The function to decorate user _ kwd : boolean If user _ kwd is True , the user ...
if f is None : return partial ( grouping , user_kwd = user_kwd , interaction = interaction , summary = summary ) def wrapper ( user , groupby = 'week' , interaction = interaction , summary = summary , split_week = False , split_day = False , filter_empty = True , datatype = None , ** kwargs ) : if interaction i...
def _radius_auth ( self , server , username , password ) : """Authenticate the given username / password against the RADIUS server described by ` server ` ."""
client = self . _get_client ( server ) packet = self . _get_auth_packet ( username , password , client ) return self . _perform_radius_auth ( client , packet )
def get_ip_prefixes_from_config ( config , services , ip_version ) : """Build a set of IP prefixes found in service configuration files . Arguments : config ( obg ) : A configparser object which holds our configuration . services ( list ) : A list of section names which are the name of the service checks . ...
ip_prefixes = set ( ) for service in services : ip_prefix = ipaddress . ip_network ( config . get ( service , 'ip_prefix' ) ) if ip_prefix . version == ip_version : ip_prefixes . add ( ip_prefix . with_prefixlen ) return ip_prefixes
def worker_workerfinished ( self , node ) : """Emitted when node executes its pytest _ sessionfinish hook . Removes the node from the scheduler . The node might not be in the scheduler if it had not emitted workerready before shutdown was triggered ."""
self . config . hook . pytest_testnodedown ( node = node , error = None ) if node . workeroutput [ "exitstatus" ] == 2 : # keyboard - interrupt self . shouldstop = "%s received keyboard-interrupt" % ( node , ) self . worker_errordown ( node , "keyboard-interrupt" ) return if node in self . sched . nodes : ...
def _list_locators ( self ) : """Lists locators . Returns : generator of tuple : locator name str , locator header dict"""
with _handle_client_error ( ) : response = self . client . list_buckets ( ) for bucket in response [ 'Buckets' ] : yield bucket . pop ( 'Name' ) , bucket
def get_info_of_object ( self , obj , selector = None ) : """return info dictionary of the * obj * The info example : u ' contentDescription ' : u ' ' , u ' checked ' : False , u ' scrollable ' : True , u ' text ' : u ' ' , u ' packageName ' : u ' com . android . launcher ' , u ' selected ' : False , ...
if selector : return obj . info . get ( selector ) else : return obj . info
def remove_elements ( parent_to_parse , element_paths , clear_empty = False ) : """Removes all elements named after each elements _ or _ paths . If clear _ empty is True , for each XPATH , empty parents are removed if all their children are removed . : see : remove _ element ( parent _ to _ parse , element _ pa...
element = get_element ( parent_to_parse ) removed = [ ] if element is None or not element_paths : return removed if isinstance ( element_paths , string_types ) : rem = remove_element ( element , element_paths , clear_empty ) removed . extend ( rem if isinstance ( rem , list ) else [ rem ] ) else : for x...
def do_directives ( self , line ) : """List all directives supported by the bot"""
for name , cmd in self . adapter . directives . items ( ) : with colorize ( 'blue' ) : print ( 'bot %s:' % name ) if cmd . __doc__ : for line in cmd . __doc__ . split ( '\n' ) : print ( ' %s' % line ) else : print ( )
def ellipsis ( source , max_length ) : """Truncates a string to be at most max _ length long ."""
if max_length == 0 or len ( source ) <= max_length : return source return source [ : max ( 0 , max_length - 3 ) ] + "..."
def update_user ( cls , username , email , password ) : """Edit user info"""
if cls . _check_email_changed ( username , email ) : # if we try to set the email to whatever it is already on SeAT , we get a HTTP422 error logger . debug ( "Updating SeAT username %s with email %s and password" % ( username , email ) ) ret = cls . exec_request ( 'user/{}' . format ( username ) , 'put' , email...
def get_urgent ( self , sensors ) : """Determine if any sensors should set the urgent flag ."""
if self . urgent_on not in ( 'warning' , 'critical' ) : raise Exception ( "urgent_on must be one of (warning, critical)" ) for sensor in sensors : if self . urgent_on == 'warning' and sensor . is_warning ( ) : return True elif self . urgent_on == 'critical' and sensor . is_critical ( ) : ret...
def rename ( self ) : """rename _ expr : : = rename param _ start rename _ parameters param _ stop expression rename _ parameters : : = relation _ name | paren _ left attribute _ list paren _ right | relation _ name paren _ left attribute _ list paren _ right"""
params = self . relation_name ^ ( Optional ( self . relation_name ) + self . parenthesize ( self . attribute_list ) ) return self . parametrize ( self . syntax . rename_op , params )
def write_genotypes ( self , genotypes ) : """Write genotypes to binary file . Args : genotypes ( numpy . ndarray ) : The genotypes to write in the BED file ."""
if self . _mode != "w" : raise UnsupportedOperation ( "not available in 'r' mode" ) # Initializing the number of samples if required if self . _nb_values is None : self . _nb_values = len ( genotypes ) # Checking the expected number of samples if self . _nb_values != len ( genotypes ) : raise ValueError ( "...
def get_endtime ( jid ) : '''Retrieve the stored endtime for a given job Returns False if no endtime is present'''
jid_dir = salt . utils . jid . jid_dir ( jid , _job_dir ( ) , __opts__ [ 'hash_type' ] ) etpath = os . path . join ( jid_dir , ENDTIME ) if not os . path . exists ( etpath ) : return False with salt . utils . files . fopen ( etpath , 'r' ) as etfile : endtime = salt . utils . stringutils . to_unicode ( etfile ....
def write ( self , vals ) : """Overrides orm write method . @ param self : The object pointer @ param vals : dictionary of fields value ."""
if 'isroom' in vals and vals [ 'isroom' ] is False : vals . update ( { 'color' : 2 , 'status' : 'occupied' } ) if 'isroom' in vals and vals [ 'isroom' ] is True : vals . update ( { 'color' : 5 , 'status' : 'available' } ) ret_val = super ( HotelRoom , self ) . write ( vals ) return ret_val
def extract_spectra_from_file ( log , pathToSpectrum , convertLumToFlux = False ) : """* Given a spectrum file this function shall convert the two columns ( wavelength and luminosity ) to a wavelegnth ( wavelengthArray ) and flux ( fluxArray ) array * * * Key Arguments : * * - ` ` log ` ` - - logger - ` ` pat...
# # # # # # > IMPORTS # # # # # # # STANDARD LIB # # import os # # THIRD PARTY # # import numpy as np # # LOCAL APPLICATION # # import dryxPython . astrotools as at # # # # # # > VARIABLE SETTINGS # # # # # # # # # # # > ACTION ( S ) # # # # # # USE numPy TO EXTRACT THE DATA FROM FILE pwd = os . getcwd ( ) log . debug ...
def update ( self , ** kwargs ) : """Update the list with the current object attributes . : param kwargs : Extra request options : type kwargs : : class : ` ~ python : dict ` : return : Boolean to indicate if the request was successful : rtype : : class : ` ~ python : bool `"""
item = self . _client [ 'users/*/lists/*' ] . update ( self . username , self . id , return_type = 'data' , ** kwargs ) if not item : return False self . _update ( item ) return True
def strip_dimensions ( self , text_lines , location , pid ) : """Calculate the dimension Returns out : types . SimpleNamespace A structure with all the coordinates required to draw the strip text and the background box ."""
dpi = 72 num_lines = len ( text_lines ) get_property = self . theme . themeables . property ax = self . axs [ pid ] bbox = ax . get_window_extent ( ) . transformed ( self . figure . dpi_scale_trans . inverted ( ) ) ax_width , ax_height = bbox . width , bbox . height # in inches strip_size = self . strip_size ( location...
def main ( ) : """Define the CLI inteface / commands ."""
arguments = docopt ( __doc__ ) cfg_filename = pkg_resources . resource_filename ( 'knowledge_base' , 'config/virtuoso.ini' ) kb = KnowledgeBase ( cfg_filename ) # the user has issued a ` find ` command if arguments [ "find" ] : search_string = arguments [ "<search_string>" ] try : urn = CTS_URN ( search...
def check_validity ( self , checks = None , report = True ) : """Runs a Symbol ' s validity checks . Parameters checks : str , [ str , ] , optional Only run certain checks . report : bool , optional If set to False , the method will return only the result of the check checks ( True / False ) . Set to Tr...
if report : reportpoints = [ ] allchecks = [ ] checks_specified = False if isinstance ( checks , ( str , unicode ) ) : checks = [ checks ] checks_specified = True elif isinstance ( checks , ( list , tuple ) ) : checks_specified = True else : checks = [ ] for val in self . validity : if ( val . v...
def get_file_paths_for_program ( program , dir_to_search ) : """Return an array of full paths matching the given program . If no directory is present , returns an empty list . Path is not guaranteed to exist . Just says where it should be if it existed . Paths must be fully expanded before being passed in ( i...
if dir_to_search is None : return [ ] else : wanted_file_name = program + EXAMPLE_FILE_SUFFIX result = [ ] for basedir , dirs , file_names in os . walk ( dir_to_search ) : for file_name in file_names : if file_name == wanted_file_name : result . append ( os . path . j...
def getPath ( self , suffix = None , extension = "jar" , separator = os . sep ) : """Returns the full path , relative to the root of a Maven repository , of the current artifact , using Maven ' s conventions . In particular , it will be : < groupId with " . " replaced by < separator > > [ < separator > < arti...
assert ( self . _groupId is not None ) resultComponents = [ self . _groupId . replace ( "." , separator ) ] if self . _artifactId is not None : resultComponents . append ( self . _artifactId ) version = self . _version if version is not None : resultComponents . append ( version . getRawString ( ) )...
def get_order_container ( self , quote_id ) : """Generate an order container from a quote object . : param quote _ id : ID number of target quote"""
quote = self . client [ 'Billing_Order_Quote' ] container = quote . getRecalculatedOrderContainer ( id = quote_id ) return container
def describe_policy_version ( policyName , policyVersionId , region = None , key = None , keyid = None , profile = None ) : '''Given a policy name and version describe its properties . Returns a dictionary of interesting properties . CLI Example : . . code - block : : bash salt myminion boto _ iot . describ...
try : conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) policy = conn . get_policy_version ( policyName = policyName , policyVersionId = policyVersionId ) if policy : keys = ( 'policyName' , 'policyArn' , 'policyDocument' , 'policyVersionId' , 'isDefaultVersion' ) ...
def _rows_date2int ( self , rows ) : """Replaces start and end dates in a row set with their integer representation : param list [ dict [ str , T ] ] rows : The list of rows ."""
for row in rows : # Determine the type of dates based on the first start date . if not self . _date_type : self . _date_type = self . _get_date_type ( row [ self . _key_start_date ] ) # Convert dates to integers . row [ self . _key_start_date ] = self . _date2int ( row [ self . _key_start_date ] ) ...