signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
async def get_constraints ( self ) : """Return the machine constraints for this model . : returns : A ` ` dict ` ` of constraints ."""
constraints = { } client_facade = client . ClientFacade . from_connection ( self . connection ( ) ) result = await client_facade . GetModelConstraints ( ) # GetModelConstraints returns GetConstraintsResults which has a # ' constraints ' attribute . If no constraints have been set # GetConstraintsResults . constraints i...
def dictfetchone ( cursor : Cursor ) -> Optional [ Dict [ str , Any ] ] : """Return the next row from a cursor as an : class : ` OrderedDict ` , or ` ` None ` ` ."""
columns = get_fieldnames_from_cursor ( cursor ) row = cursor . fetchone ( ) if not row : return None return OrderedDict ( zip ( columns , row ) )
def get_default_bios_settings ( self , only_allowed_settings = True ) : """Get default BIOS settings . : param : only _ allowed _ settings : True when only allowed BIOS settings are to be returned . If False , All the BIOS settings supported by iLO are returned . : return : a dictionary of default BIOS sett...
headers_bios , bios_uri , bios_settings = self . _check_bios_resource ( ) # Get the BaseConfig resource . try : base_config_uri = bios_settings [ 'links' ] [ 'BaseConfigs' ] [ 'href' ] except KeyError : msg = ( "BaseConfigs resource not found. Couldn't apply the BIOS " "Settings." ) raise exception . IloCom...
def convert_raw_data_to_universes ( raw_data ) -> tuple : """converts the raw data to a readable universes tuple . The raw _ data is scanned from index 0 and has to have 16 - bit numbers with high byte first . The data is converted from the start to the beginning ! : param raw _ data : the raw data to convert ...
if len ( raw_data ) % 2 != 0 : raise TypeError ( 'The given data has not a length that is a multiple of 2!' ) rtrnList = [ ] for i in range ( 0 , len ( raw_data ) , 2 ) : rtrnList . append ( two_bytes_to_int ( raw_data [ i ] , raw_data [ i + 1 ] ) ) return tuple ( rtrnList )
def createAppendElement ( self , namespaceURI , localName , prefix = None ) : '''Create a new element ( namespaceURI , name ) , append it to current node , and return the newly created node . Keyword arguments : namespaceURI - - namespace of element to create localName - - local name of new element prefix...
declare = False qualifiedName = localName if namespaceURI : try : prefix = self . getPrefix ( namespaceURI ) except : declare = True prefix = prefix or self . _getUniquePrefix ( ) if prefix : qualifiedName = '%s:%s' % ( prefix , localName ) node = self . createElementNS ( nam...
def get_dev_details ( ip_address ) : """Takes string input of IP address to issue RESTUL call to HP IMC : param ip _ address : string object of dotted decimal notation of IPv4 address : return : dictionary of device details > > > get _ dev _ details ( ' 10.101.0.1 ' ) { ' symbolLevel ' : ' 2 ' , ' typeName ...
# checks to see if the imc credentials are already available if auth is None or url is None : set_imc_creds ( ) global r get_dev_details_url = "/imcrs/plat/res/device?resPrivilegeFilter=false&ip=" + str ( ip_address ) + "&start=0&size=1000&orderBy=id&desc=false&total=false" f_url = url + get_dev_details_url payload...
def _get_free_vpcids_on_switches ( switch_ip_list ) : '''Get intersect list of free vpcids in list of switches .'''
session = bc . get_reader_session ( ) prev_view = aliased ( nexus_models_v2 . NexusVPCAlloc ) query = session . query ( prev_view . vpc_id ) prev_swip = switch_ip_list [ 0 ] for ip in switch_ip_list [ 1 : ] : cur_view = aliased ( nexus_models_v2 . NexusVPCAlloc ) cur_swip = ip query = query . join ( cur_vie...
def create ( self ) : """Create the required directory structure and admin metadata ."""
self . _storage_broker . create_structure ( ) self . _storage_broker . put_admin_metadata ( self . _admin_metadata )
def run ( ) : """Use preconfigured settings to optimize files ."""
# Setup Multiprocessing # manager = multiprocessing . Manager ( ) Settings . pool = multiprocessing . Pool ( Settings . jobs ) # Optimize Files record_dirs , bytes_in , bytes_out , nag_about_gifs , errors = _walk_all_files ( ) # Shut down multiprocessing Settings . pool . close ( ) Settings . pool . join ( ) # Write ti...
def lists ( self , column , key = None ) : """Get a list with the values of a given column : param column : The column to get the values for : type column : str : param key : The key : type key : str : return : The list of values : rtype : list or dict"""
results = self . _query . lists ( column , key ) if self . _model . has_get_mutator ( column ) : if isinstance ( results , dict ) : for key , value in results . items ( ) : fill = { column : value } results [ key ] = self . _model . new_from_builder ( fill ) . column else : ...
def complete_scopes ( cls , scope_infos ) : """Expand a set of scopes to include all enclosing scopes . E . g . , if the set contains ` foo . bar . baz ` , ensure that it also contains ` foo . bar ` and ` foo ` . Also adds any deprecated scopes ."""
ret = { GlobalOptionsRegistrar . get_scope_info ( ) } original_scopes = dict ( ) for si in scope_infos : ret . add ( si ) if si . scope in original_scopes : raise cls . DuplicateScopeError ( 'Scope `{}` claimed by {}, was also claimed by {}.' . format ( si . scope , si , original_scopes [ si . scope ] )...
def get_limits ( self , coord = 'data' ) : """Get the bounding box of the viewer extents . Returns limits : tuple Bounding box in coordinates of type ` coord ` in the form of ` ` ( ll _ pt , ur _ pt ) ` ` ."""
limits = self . t_ [ 'limits' ] if limits is None : # No user defined limits . If there is an image loaded # use its dimensions as the limits image = self . get_image ( ) if image is not None : wd , ht = image . get_size ( ) limits = ( ( self . data_off , self . data_off ) , ( float ( wd - 1 + s...
def makeicons ( source ) : """Create all the neccessary icons from source image"""
im = Image . open ( source ) for name , ( _ , w , h , func ) in icon_sizes . iteritems ( ) : print ( 'Making icon %s...' % name ) tn = func ( im , ( w , h ) ) bg = Image . new ( 'RGBA' , ( w , h ) , ( 255 , 255 , 255 ) ) x = ( w / 2 ) - ( tn . size [ 0 ] / 2 ) y = ( h / 2 ) - ( tn . size [ 1 ] / 2 )...
def get_stp_brief_info_output_has_more ( self , ** kwargs ) : """Auto Generated Code"""
config = ET . Element ( "config" ) get_stp_brief_info = ET . Element ( "get_stp_brief_info" ) config = get_stp_brief_info output = ET . SubElement ( get_stp_brief_info , "output" ) has_more = ET . SubElement ( output , "has-more" ) has_more . text = kwargs . pop ( 'has_more' ) callback = kwargs . pop ( 'callback' , sel...
def add_or_update ( self , section , key , value ) : """Update the key or , if no previous value existed , add it . Returns : int : Number of updated lines ."""
updates = self . update ( section , key , value ) if updates == 0 : self . add ( section , key , value ) return updates
def main ( params = None ) : """Main function to launch phonefy . The function is created in this way so as to let other applications make use of the full configuration capabilities of the application . The parameters received are used as parsed by this modules ` getParser ( ) ` . Args : params : A list w...
if params == None : parser = getParser ( ) args = parser . parse_args ( params ) else : args = params results = [ ] # Recovering the logger # Calling the logger when being imported logSet . setupLogger ( loggerName = "osrframework.entify" , verbosity = args . verbose , logFolder = args . logfolder ) # From ...
def persistent_object_context_changed ( self ) : """Override from PersistentObject ."""
super ( ) . persistent_object_context_changed ( ) def register ( ) : if self . __source is not None and self . __target is not None : assert not self . __binding self . __binding = Binding . PropertyBinding ( self . __source , self . source_property ) self . __binding . target_setter = self ...
def _get_site_dummy_variables ( self , vs30 ) : """Returns the Eurocode 8 site class dummy variable"""
s_b = np . zeros_like ( vs30 ) s_c = np . zeros_like ( vs30 ) s_d = np . zeros_like ( vs30 ) s_b [ np . logical_and ( vs30 >= 360. , vs30 < 800. ) ] = 1.0 s_c [ np . logical_and ( vs30 >= 180. , vs30 < 360. ) ] = 1.0 s_d [ vs30 < 180 ] = 1.0 return s_b , s_c , s_d
def validator_for ( schema , default = _LATEST_VERSION ) : """Retrieve the validator class appropriate for validating the given schema . Uses the : validator : ` $ schema ` property that should be present in the given schema to look up the appropriate validator class . Arguments : schema ( collections . Map...
if schema is True or schema is False or u"$schema" not in schema : return default if schema [ u"$schema" ] not in meta_schemas : warn ( ( "The metaschema specified by $schema was not found. " "Using the latest draft to validate, but this will raise " "an error in the future." ) , DeprecationWarning , stacklevel...
def time_to_str ( timestamp : int ) -> str : """Convert seconds past Epoch to human readable string ."""
datetimestamp = datetime . datetime . fromtimestamp ( timestamp ) return '{:04d}-{:02d}-{:02d}-{:02d}-{:02d}-{:02d}' . format ( datetimestamp . year , datetimestamp . month , datetimestamp . day , datetimestamp . hour , datetimestamp . minute , datetimestamp . second )
def delete ( self , path , data = None , headers = None , params = None ) : """Deletes resources at given paths . : rtype : dict : return : Empty dictionary to have consistent interface . Some of Atlassian REST resources don ' t return any content ."""
self . request ( 'DELETE' , path = path , data = data , headers = headers , params = params )
def is_real_iterable ( raise_ex : bool = False , summary : bool = True , ** items : Any ) -> ValidationReturn : """Tests if the given items are iterables ( collections ) but no strings . Per default this function yields whether ` ` True ` ` or ` ` False ` ` depending on the fact if all items withstand the valid...
return Validator . __test_all ( condition = lambda _ , val : hasattr ( val , '__iter__' ) and not isinstance ( val , str ) , formatter = lambda name , _ : "'{varname}' is not an iterable" . format ( varname = name ) , raise_ex = raise_ex , summary = summary , ** items )
def compute_steadystate ( self , nnc = 2 ) : """Computes the non - stochastic steady - state of the economy . Parameters nnc : array _ like ( float ) nnc is the location of the constant in the state vector x _ t"""
zx = np . eye ( self . A0 . shape [ 0 ] ) - self . A0 self . zz = nullspace ( zx ) self . zz /= self . zz [ nnc ] self . css = self . Sc . dot ( self . zz ) self . sss = self . Ss . dot ( self . zz ) self . iss = self . Si . dot ( self . zz ) self . dss = self . Sd . dot ( self . zz ) self . bss = self . Sb . dot ( sel...
def _set_ra_dns_server ( self , v , load = False ) : """Setter method for ra _ dns _ server , mapped from YANG variable / routing _ system / interface / ve / ipv6 / ipv6 _ nd _ ra / ipv6 _ intf _ cmds / nd / ra _ dns _ server ( list ) If this variable is read - only ( config : false ) in the source YANG file , ...
if hasattr ( v , "_utype" ) : v = v . _utype ( v ) try : t = YANGDynClass ( v , base = YANGListType ( "dns_server_prefix" , ra_dns_server . ra_dns_server , yang_name = "ra-dns-server" , rest_name = "ra-dns-server" , parent = self , is_container = 'list' , user_ordered = False , path_helper = self . _path_helper...
def stop ( self , container , ** kwargs ) : """Identical to : meth : ` dockermap . client . base . DockerClientWrapper . stop ` with additional logging ."""
self . push_log ( "Stopping container '{0}'." . format ( container ) ) super ( DockerFabricClient , self ) . stop ( container , ** kwargs )
def defer ( callable ) : '''Defers execution of the callable to a thread . For example : > > > def foo ( ) : . . . print ( ' bar ' ) > > > join = defer ( foo ) > > > join ( )'''
t = threading . Thread ( target = callable ) t . start ( ) return t . join
def ClientFromConfig ( engine , config , database , logger = None , verbose = True ) : """Return new database client from valid [ couchdb ] or [ couchbase ] config section . engine < str > defines which engine to use , currently supports " couchdb " and " couchbase " config < dict > [ couchdb ] or [ couchbase...
if type ( config ) == list : config = dict ( config ) if engine == "couchbase" : return Client ( engine = engine , host = config . get ( "host" ) , auth = config . get ( "bucket_%s" % database ) , logger = logger , verbose = verbose ) elif engine == "couchdb" : if config . get ( "admin_user" ) and config . ...
def update ( self , reconfigure = False ) : """update the environment"""
try : self . phase = PHASE . UPDATE self . logger . info ( "Updating environment %s..." % self . namespace ) self . install_sandboxes ( ) self . instantiate_features ( ) # We don ' t grab inputs , only on install # updates inputs are grabbed on demand # self . grab _ inputs ( reconfigure = r...
def auto_disable ( enabled : Optional [ bool ] = True , fds : Optional [ Sequence [ IO ] ] = ( sys . stdout , sys . stderr ) ) -> None : """Automatically decide whether to disable color codes if stdout or stderr are not ttys . Arguments : enabled : Whether to automatically disable color codes . When set to ...
if enabled : if not all ( getattr ( f , 'isatty' , lambda : False ) ( ) for f in fds ) : disable ( ) else : enable ( )
def qteBindKeyApplet ( self , keysequence , macroName : str , appletObj : QtmacsApplet ) : """Bind ` ` macroName ` ` to all widgets in ` ` appletObj ` ` . This method does not affect the key bindings of other applets , or other instances of the same applet . The ` ` keysequence ` ` can be specified either as ...
# Convert the key sequence into a QtmacsKeysequence object , or # raise a QtmacsKeysequenceError if the conversion is # impossible . keysequence = QtmacsKeysequence ( keysequence ) # Verify that Qtmacs knows a macro named ' macroName ' . if not self . qteIsMacroRegistered ( macroName ) : msg = ( 'Cannot bind key be...
def set_default_identity_by_index ( self , index : int ) : """This interface is used to set default account by given an index value . : param index : an int value that indicate the position of an account object in account list ."""
identities_len = len ( self . identities ) if index >= identities_len : raise SDKException ( ErrorCode . param_error ) for i in range ( identities_len ) : self . identities [ i ] . is_default = False if i == index : self . identities [ index ] . is_default = True
def association_pivot ( self , association_resource ) : """Pivot point on association for this resource . This method will return all * resources * ( group , indicators , task , victims , etc ) for this resource that are associated with the provided resource . * * Example Endpoints URI ' s * * | METHOD | AP...
resource = self . copy ( ) resource . _request_uri = '{}/{}' . format ( association_resource . request_uri , resource . _request_uri ) return resource
def recursive_asdict ( d ) : """Convert Suds object into serializable format ."""
out = { } for k , v in asdict ( d ) . iteritems ( ) : if hasattr ( v , '__keylist__' ) : out [ k ] = recursive_asdict ( v ) elif isinstance ( v , list ) : out [ k ] = [ ] for item in v : if hasattr ( item , '__keylist__' ) : out [ k ] . append ( recursive_asdi...
def build_dependencies ( self ) : '''build _ dependencies High - level api : Briefly compile all yang files and find out dependency infomation of all modules . Returns None Nothing returns .'''
cmd_list = [ 'pyang' , '--plugindir' , self . pyang_plugins ] cmd_list += [ '-p' , self . dir_yang ] cmd_list += [ '-f' , 'pyimport' ] cmd_list += [ self . dir_yang + '/*.yang' ] logger . info ( 'Building dependencies: {}' . format ( ' ' . join ( cmd_list ) ) ) p = Popen ( ' ' . join ( cmd_list ) , shell = True , stdou...
def option_group_exists ( name , tags = None , region = None , key = None , keyid = None , profile = None ) : '''Check to see if an RDS option group exists . CLI example : : salt myminion boto _ rds . option _ group _ exists myoptiongr region = us - east - 1'''
conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile ) try : rds = conn . describe_option_groups ( OptionGroupName = name ) return { 'exists' : bool ( rds ) } except ClientError as e : return { 'error' : __utils__ [ 'boto3.get_error' ] ( e ) }
def set_number ( self , key , value ) : """set a key ' s value"""
storage = self . storage if not isinstance ( value , int ) : logger . error ( "set_number: Value must be an integer" ) return try : lock . acquire ( ) storage [ key ] = value finally : self . storage . _p_changed = True lock . release ( ) return storage [ key ]
def projects ( self ) : """* All child projects of this taskpaper object * * * Usage : * * Given a taskpaper document object ( ` doc ` ) , to get a list of the project objects found within the document use : . . code - block : : python docProjects = doc . projects The same is true of project objects which...
return self . _get_object ( regex = re . compile ( r'((?<=\n)|(?<=^))(?P<title>(?!\[Searches\]|- )\S.*?:(?!\S)) *(?P<tagString>( *?@[^(\s]+(\([^)]*\))?)+)?(?P<content>(\n(( |\t)+\S.*)|\n( |\t)*|\n)+)' , re . UNICODE ) , objectType = "project" , content = None )
def load ( self , fname ) : """loads a ASCII text file grid to self"""
# get height and width of grid from file self . grid_width = 4 self . grid_height = 4 # re - read the file and load it self . grid = [ [ 0 for dummy_l in range ( self . grid_width ) ] for dummy_l in range ( self . grid_height ) ] with open ( fname , 'r' ) as f : for row_num , row in enumerate ( f ) : if row...
def _fromdata ( self , code , dtype , count , value , name = None ) : """Initialize instance from arguments ."""
self . code = int ( code ) self . name = name if name else str ( code ) self . dtype = TIFF_DATA_TYPES [ dtype ] self . count = int ( count ) self . value = value
def hex_color_to_rgba ( hex_color , normalize_to = 255 ) : '''Convert a hex - formatted number ( i . e . , ` " # RGB [ A ] " ` or ` " # RRGGBB [ AA ] " ` ) to an RGBA tuple ( i . e . , ` ( < r > , < g > , < b > , < a > ) ` ) . Args : hex _ color ( str ) : hex - formatted number ( e . g . , ` " # 2fc " ` , ` "...
color_pattern_one_digit = ( r'#(?P<R>[\da-fA-F])(?P<G>[\da-fA-F])' r'(?P<B>[\da-fA-F])(?P<A>[\da-fA-F])?' ) color_pattern_two_digit = ( r'#(?P<R>[\da-fA-F]{2})(?P<G>[\da-fA-F]{2})' r'(?P<B>[\da-fA-F]{2})(?P<A>[\da-fA-F]{2})?' ) # First try to match ` # rrggbb [ aa ] ` . match = re . match ( color_pattern_two_digit , he...
def random_split ( self , fraction , seed = None ) : """Randomly split the rows of an SArray into two SArrays . The first SArray contains * M * rows , sampled uniformly ( without replacement ) from the original SArray . * M * is approximately the fraction times the original number of rows . The second SArray ...
from . sframe import SFrame temporary_sf = SFrame ( ) temporary_sf [ 'X1' ] = self ( train , test ) = temporary_sf . random_split ( fraction , seed ) return ( train [ 'X1' ] , test [ 'X1' ] )
def configure_rmq_ssl_on ( self , sentry_units , deployment , port = None , max_wait = 60 ) : """Turn ssl charm config option on , with optional non - default ssl port specification . Confirm that it is enabled on every unit . : param sentry _ units : list of sentry units : param deployment : amulet deploym...
self . log . debug ( 'Setting ssl charm config option: on' ) # Enable RMQ SSL config = { 'ssl' : 'on' } if port : config [ 'ssl_port' ] = port deployment . d . configure ( 'rabbitmq-server' , config ) # Wait for unit status self . rmq_wait_for_cluster ( deployment ) # Confirm tries = 0 ret = self . validate_rmq_ss...
def update_pypsa_timeseries ( network , loads_to_update = None , generators_to_update = None , storages_to_update = None , timesteps = None ) : """Updates load , generator , storage and bus time series in pypsa network . See functions : func : ` update _ pypsa _ load _ timeseries ` , : func : ` update _ pypsa _...
update_pypsa_load_timeseries ( network , loads_to_update = loads_to_update , timesteps = timesteps ) update_pypsa_generator_timeseries ( network , generators_to_update = generators_to_update , timesteps = timesteps ) update_pypsa_storage_timeseries ( network , storages_to_update = storages_to_update , timesteps = times...
def postprocess_alignment ( data ) : """Perform post - processing steps required on full BAM files . Prepares list of callable genome regions allowing subsequent parallelization ."""
data = cwlutils . normalize_missing ( utils . to_single_data ( data ) ) data = cwlutils . unpack_tarballs ( data , data ) bam_file = data . get ( "align_bam" ) or data . get ( "work_bam" ) ref_file = dd . get_ref_file ( data ) if vmulti . bam_needs_processing ( data ) and bam_file and bam_file . endswith ( ".bam" ) : ...
def add_cmd_output ( self , cmds , suggest_filename = None , root_symlink = None , timeout = 300 , stderr = True , chroot = True , runat = None , env = None , binary = False , sizelimit = None , pred = None ) : """Run a program or a list of programs and collect the output"""
if isinstance ( cmds , six . string_types ) : cmds = [ cmds ] if len ( cmds ) > 1 and ( suggest_filename or root_symlink ) : self . _log_warn ( "ambiguous filename or symlink for command list" ) if sizelimit is None : sizelimit = self . get_option ( "log_size" ) for cmd in cmds : self . _add_cmd_output ...
def generate_rsa_key_pair ( ) : """Create public and private ssh - keys ."""
key = rsa . generate_private_key ( backend = default_backend ( ) , public_exponent = 65537 , key_size = 2048 ) public_key = key . public_key ( ) . public_bytes ( serialization . Encoding . OpenSSH , serialization . PublicFormat . OpenSSH ) . decode ( "utf-8" ) pem = key . private_bytes ( encoding = serialization . Enco...
def modify ( self , service_name , json , ** kwargs ) : """Modify an AppNexus object"""
return self . _send ( requests . put , service_name , json , ** kwargs )
def raise_204 ( instance ) : """Abort the current request with a 204 ( No Content ) response code . Clears out the body of the response . : param instance : Resource instance ( used to access the response ) : type instance : : class : ` webob . resource . Resource ` : raises : : class : ` webob . exceptions...
instance . response . status = 204 instance . response . body = '' instance . response . body_raw = None raise ResponseException ( instance . response )
def _get_app_auth_headers ( self ) : """Set the correct auth headers to authenticate against GitHub ."""
now = datetime . now ( timezone . utc ) expiry = now + timedelta ( minutes = 5 ) data = { "iat" : now , "exp" : expiry , "iss" : self . app_id } app_token = jwt . encode ( data , self . app_key , algorithm = "RS256" ) . decode ( "utf-8" ) headers = { "Accept" : PREVIEW_JSON_ACCEPT , "Authorization" : "Bearer {}" . form...
def fix_facets ( self ) : """This function convert date _ histogram facets to datetime"""
facets = self . facets for key in list ( facets . keys ( ) ) : _type = facets [ key ] . get ( "_type" , "unknown" ) if _type == "date_histogram" : for entry in facets [ key ] . get ( "entries" , [ ] ) : for k , v in list ( entry . items ( ) ) : if k in [ "count" , "max" , "mi...
def finddefaultreference ( self ) : """Find the default reference for text offsets : The parent of the current textcontent ' s parent ( counting only Structure Elements and Subtoken Annotation Elements ) Note : This returns not a TextContent element , but its parent . Whether the textcontent actually exists is ...
depth = 0 e = self while True : if e . parent : e = e . parent # pylint : disable = redefined - variable - type else : # no parent , breaking return False if isinstance ( e , AbstractStructureElement ) or isinstance ( e , AbstractSubtokenAnnotation ) : depth += 1 if d...
def save_figure ( self , event = None , transparent = False , dpi = 600 ) : """save figure image to file"""
file_choices = "PNG (*.png)|*.png|SVG (*.svg)|*.svg|PDF (*.pdf)|*.pdf" try : ofile = self . conf . title . strip ( ) except : ofile = 'Image' if len ( ofile ) > 64 : ofile = ofile [ : 63 ] . strip ( ) if len ( ofile ) < 1 : ofile = 'plot' for c in ' :";|/\\' : ofile = ofile . replace ( c , '_' ) ofi...
def _process_kill ( self ) : """Kill the fake executable process if it ' s still running ."""
if self . _process . poll ( ) is None : # pragma : no cover self . _process . kill ( ) self . _process . wait ( timeout = 5 )
def sanitize_label ( self , label ) : """Converts a label taken from user input into a well - formed label . @ type label : str @ param label : Label taken from user input . @ rtype : str @ return : Sanitized label ."""
( module , function , offset ) = self . split_label_fuzzy ( label ) label = self . parse_label ( module , function , offset ) return label
def get_service_by_name ( self , service_name ) : """Get a specific service by name ."""
content = self . _fetch ( "/service/search?name=%s" % service_name ) return FastlyService ( self , content )
def FindUnspentCoinsByAsset ( self , asset_id , from_addr = None , use_standard = False , watch_only_val = 0 ) : """Finds unspent coin objects in the wallet limited to those of a certain asset type . Args : asset _ id ( UInt256 ) : a bytearray ( len 32 ) representing an asset on the blockchain . from _ addr (...
coins = self . FindUnspentCoins ( from_addr = from_addr , use_standard = use_standard , watch_only_val = watch_only_val ) return [ coin for coin in coins if coin . Output . AssetId == asset_id ]
def init_huang ( X , n_clusters , dissim , random_state ) : """Initialize centroids according to method by Huang [ 1997 ] ."""
n_attrs = X . shape [ 1 ] centroids = np . empty ( ( n_clusters , n_attrs ) , dtype = 'object' ) # determine frequencies of attributes for iattr in range ( n_attrs ) : freq = defaultdict ( int ) for curattr in X [ : , iattr ] : freq [ curattr ] += 1 # Sample centroids using the probabilities of attr...
def validate ( self , raw_data , ** kwargs ) : """Convert the raw _ data to a float ."""
try : converted_data = float ( raw_data ) super ( FloatField , self ) . validate ( converted_data , ** kwargs ) return raw_data except ValueError : raise ValidationException ( self . messages [ 'invalid' ] , repr ( raw_data ) )
def GetAnnotatedMethods ( cls ) : """Returns a dictionary of annotated router methods ."""
result = { } # We want methods with the highest call - order to be processed last , # so that their annotations have precedence . for i_cls in reversed ( inspect . getmro ( cls ) ) : for name in compatibility . ListAttrs ( i_cls ) : cls_method = getattr ( i_cls , name ) if not callable ( cls_method ...
def get_canonical_host ( self ) : """Return the canonical host as for the Host HTTP header specification ."""
host = self . host . lower ( ) if self . port is not None : host = "%s:%s" % ( host , self . port ) return host
def automodsumm_to_autosummary_lines ( fn , app ) : """Generates lines from a file with an " automodsumm " entry suitable for feeding into " autosummary " . Searches the provided file for ` automodsumm ` directives and returns a list of lines specifying the ` autosummary ` commands for the modules requested...
fullfn = os . path . join ( app . builder . env . srcdir , fn ) with open ( fullfn ) as fr : if 'astropy_helpers.sphinx.ext.automodapi' in app . _extensions : from astropy_helpers . sphinx . ext . automodapi import automodapi_replace # Must do the automodapi on the source to get the automodsumm ...
def etag ( self ) : """Get the ETag option of the message . : rtype : list : return : the ETag values or [ ] if not specified by the request"""
value = [ ] for option in self . options : if option . number == defines . OptionRegistry . ETAG . number : value . append ( option . value ) return value
def proximal_step ( self , grad = None ) : """Compute proximal update ( gradient descent + regularization ) ."""
if grad is None : grad = self . eval_grad ( ) V = self . Y - ( 1. / self . L ) * grad self . X = self . eval_proxop ( V ) return grad
def register_setting ( name = None , label = None , editable = False , description = None , default = None , choices = None , append = False , translatable = False ) : """Registers a setting that can be edited via the admin . This mostly equates to storing the given args as a dict in the ` ` registry ` ` dict b...
if name is None : raise TypeError ( "yacms.conf.register_setting requires the " "'name' keyword argument." ) if editable and default is None : raise TypeError ( "yacms.conf.register_setting requires the " "'default' keyword argument when 'editable' is True." ) # append is True when called from an app ( typicall...
def _set_view ( self , v , load = False ) : """Setter method for view , mapped from YANG variable / snmp _ server / view ( list ) If this variable is read - only ( config : false ) in the source YANG file , then _ set _ view is considered as a private method . Backends looking to populate this variable should...
if hasattr ( v , "_utype" ) : v = v . _utype ( v ) try : t = YANGDynClass ( v , base = YANGListType ( "viewname mibtree" , view . view , yang_name = "view" , rest_name = "view" , parent = self , is_container = 'list' , user_ordered = False , path_helper = self . _path_helper , yang_keys = 'viewname mibtree' , e...
def add_star ( self , component = None , ** kwargs ) : """Shortcut to : meth : ` add _ component ` but with kind = ' star '"""
kwargs . setdefault ( 'component' , component ) return self . add_component ( 'star' , ** kwargs )
def fail ( self , err = 'MockupDB query failure' , * args , ** kwargs ) : """Reply to a query with the QueryFailure flag and an ' $ err ' key . Returns True so it is suitable as an ` ~ MockupDB . autoresponds ` handler ."""
kwargs . setdefault ( 'flags' , 0 ) kwargs [ 'flags' ] |= REPLY_FLAGS [ 'QueryFailure' ] kwargs [ '$err' ] = err self . replies ( * args , ** kwargs ) return True
def send_mail ( to_addr , subj_msg , body_msg , attach_path , serv_addr , serv_port , from_addr , passwd ) : """Send an e - mail message using smtplib and email standard python libraries . IMPORTANT ! Password is stored as plain text ! Do NOT use with your personal account ! Args : to _ addr ( str ) : Recip...
msg = MIMEMultipart ( ) if attach_path is not None : with open ( attach_path , "rb" ) as fin : part = MIMEBase ( "application" , "octet-stream" ) part . set_payload ( fin . read ( ) ) encoders . encode_base64 ( part ) part . add_header ( "Content-Disposition" , "attachment; filename=...
def mask ( x , indices ) : """The same as x [ indices ] , but return an empty array if indices are empty , instead of returning all x elements , and handles sparse " vectors " ."""
indices_shape = ( [ len ( indices ) ] if isinstance ( indices , list ) else indices . shape ) if not indices_shape [ 0 ] : return np . array ( [ ] ) elif is_sparse_vector ( x ) and len ( indices_shape ) == 1 : return x [ 0 , indices ] . toarray ( ) [ 0 ] else : return x [ indices ]
def strace_set_buffer_size ( self , size ) : """Sets the STRACE buffer size . Args : self ( JLink ) : the ` ` JLink ` ` instance . Returns : ` ` None ` ` Raises : JLinkException : on error ."""
size = ctypes . c_uint32 ( size ) res = self . _dll . JLINK_STRACE_Control ( enums . JLinkStraceCommand . SET_BUFFER_SIZE , size ) if res < 0 : raise errors . JLinkException ( 'Failed to set the STRACE buffer size.' ) return None
def _filter_ignored ( self , entries , selector = None ) : """Given an opaque entry list , filter any ignored entries . : param entries : A list or generator that produces entries to filter . : param selector : A function that computes a path for an entry relative to the root of the ProjectTree , or None to u...
selector = selector or ( lambda x : x ) prefixed_entries = [ ( self . _append_slash_if_dir_path ( selector ( entry ) ) , entry ) for entry in entries ] ignored_paths = set ( self . ignore . match_files ( path for path , _ in prefixed_entries ) ) return [ entry for path , entry in prefixed_entries if path not in ignored...
def in1d_events ( ar1 , ar2 ) : """Does the same than np . in1d but uses the fact that ar1 and ar2 are sorted and the c + + library . Is therefore much much faster ."""
ar1 = np . ascontiguousarray ( ar1 ) # change memory alignement for c + + library ar2 = np . ascontiguousarray ( ar2 ) # change memory alignement for c + + library tmp = np . empty_like ( ar1 , dtype = np . uint8 ) # temporary result array filled by c + + library , bool type is not supported with cython / numpy return ...
def next ( self ) -> mx . io . DataBatch : """Returns the next batch from the data iterator ."""
if not self . iter_next ( ) : raise StopIteration i , j = self . batch_indices [ self . curr_batch_index ] self . curr_batch_index += 1 batch_size = self . bucket_batch_sizes [ i ] . batch_size source = self . data . source [ i ] [ j : j + batch_size ] target = self . data . target [ i ] [ j : j + batch_size ] data...
def parse ( cls , op ) : """Gets the enum for the op code Args : op : value of the op code ( will be casted to int ) Returns : The enum that matches the op code"""
for event in cls : if event . value == int ( op ) : return event return None
def genome_info ( genome , info ) : """return genome info for choosing representative if ggKbase table provided - choose rep based on SCGs and genome length - priority for most SCGs - extra SCGs , then largest genome otherwise , based on largest genome"""
try : scg = info [ '#SCGs' ] dups = info [ '#SCG duplicates' ] length = info [ 'genome size (bp)' ] return [ scg - dups , length , genome ] except : return [ False , False , info [ 'genome size (bp)' ] , genome ]
def set_environment ( self , name , value ) : """Set environment ` ` $ tmux set - environment < name > < value > ` ` . Parameters name : str the environment variable name . such as ' PATH ' . option : str environment value ."""
args = [ 'set-environment' ] if self . _add_option : args += [ self . _add_option ] args += [ name , value ] proc = self . cmd ( * args ) if proc . stderr : if isinstance ( proc . stderr , list ) and len ( proc . stderr ) == int ( 1 ) : proc . stderr = proc . stderr [ 0 ] raise ValueError ( 'tmux se...
def make_declarative_base ( self , model , metadata = None ) : """Creates the declarative base that all models will inherit from . : param model : base model class ( or a tuple of base classes ) to pass to : func : ` ~ sqlalchemy . ext . declarative . declarative _ base ` . Or a class returned from ` ` declar...
if not isinstance ( model , DeclarativeMeta ) : model = declarative_base ( cls = model , name = 'Model' , metadata = metadata , metaclass = DefaultMeta ) # if user passed in a declarative base and a metaclass for some reason , # make sure the base uses the metaclass if metadata is not None and model . metadata is n...
def run ( self , redirects = [ ] ) : """Runs the pipelines with the specified redirects and returns a RunningPipeline instance ."""
if not isinstance ( redirects , redir . Redirects ) : redirects = redir . Redirects ( self . _env . _redirects , * redirects ) with copy . copy_session ( ) as sess : self = copy . deepcopy ( self ) processes = self . _run ( redirects , sess ) pipeline = RunningPipeline ( processes , self ) self . _env . las...
def unregisterChecker ( self , checker ) : """Remove a checker from the list of registered checkers . @ param checker : the checker to remove"""
self . linter . _checkers [ checker . name ] . remove ( checker ) if checker in self . linter . _reports : del self . linter . _reports [ checker ] if checker in self . linter . options_providers : self . linter . options_providers . remove ( checker )
def lexeme ( p ) : """From a parser ( or string ) , make a parser that consumes whitespace on either side ."""
if isinstance ( p , str ) : p = string ( p ) return regex ( r'\s*' ) >> p << regex ( r'\s*' )
def _print_result ( case , summary ) : """Show some statistics from the run"""
for case , case_data in summary . items ( ) : for dof , data in case_data . items ( ) : print ( " " + case + " " + dof ) print ( " -------------------" ) for header , val in data . items ( ) : print ( " " + header + " : " + str ( val ) ) print ( "" )
def ostree_init ( self , release ) : """Initialize the OSTree for a release"""
out = release [ 'output_dir' ] . rstrip ( '/' ) base = os . path . dirname ( out ) if not os . path . isdir ( base ) : self . log . info ( 'Creating %s' , base ) os . makedirs ( base , mode = 0755 ) if not os . path . isdir ( out ) : self . mock_chroot ( release , release [ 'ostree_init' ] )
def fit ( self ) : """Fit MCMC AgeDepthModel"""
self . _mcmcfit = self . mcmcsetup . run ( ) self . _mcmcfit . burnin ( self . burnin ) dmin = min ( self . _mcmcfit . depth_segments ) dmax = max ( self . _mcmcfit . depth_segments ) self . _thick = ( dmax - dmin ) / len ( self . mcmcfit . depth_segments ) self . _depth = np . arange ( dmin , dmax + 0.001 ) self . _ag...
def hoveredItem ( self ) : """Returns the currently hovered item . : return < QtGui . QTreeWidgetItem > | | None"""
out = None if ( self . _hoveredItem is not None ) : out = self . _hoveredItem ( ) if out is None : self . _hoveredItem = None return out
def build_policy ( self , name , statements , roles , is_managed_policy = False ) : """Generate policy for IAM cloudformation template : param name : Name of the policy : param statements : The " rules " the policy should have : param roles : The roles associated with this policy : param is _ managed _ poli...
if is_managed_policy : policy = ManagedPolicy ( self . name_strip ( name , True ) , PolicyDocument = { "Version" : self . VERSION_IAM , "Statement" : statements , } , Roles = roles , Path = self . __role_path , ) else : policy = PolicyType ( self . name_strip ( name , True ) , PolicyName = self . name_strip ( n...
def del_data ( name = None ) : """This function will delete tplot variables that are already stored in memory . Parameters : name : str Name of the tplot variable to be deleted . If no name is provided , then all tplot variables will be deleted . Returns : None Examples : > > > # Delete Variable 1 ...
if name is None : tplot_names = list ( data_quants . keys ( ) ) for i in tplot_names : del data_quants [ i ] return if not isinstance ( name , list ) : name = [ name ] entries = [ ] for i in name : if ( '?' in i ) or ( '*' in i ) : for j in data_quants . keys ( ) : var_ve...
def parse ( self , output ) : """Find stems for a given text ."""
output = self . _get_lines_with_stems ( output ) words = self . _make_unique ( output ) return self . _parse_for_simple_stems ( words )
def save_json ( data , path , fatal = True , logger = None , sort_keys = True , indent = 2 , ** kwargs ) : """Args : data ( object | None ) : Data to serialize and save path ( str | None ) : Path to file where to save fatal ( bool | None ) : Abort execution on failure if True logger ( callable | None ) : Lo...
if data is None or not path : return abort ( "No file %s" , short ( path ) , fatal = fatal ) try : path = resolved_path ( path ) ensure_folder ( path , fatal = fatal , logger = None ) if is_dryrun ( ) : LOG . info ( "Would save %s" , short ( path ) ) return 1 if hasattr ( data , "to_...
def coerce_repository ( value , context = None ) : """Convert a string ( taken to be a repository name or location ) to a : class : ` Repository ` object . : param value : The name or location of a repository ( a string ) or a : class : ` Repository ` object . : param context : An execution context created by...
# Coerce the context argument . context = context or LocalContext ( ) # Repository objects pass through untouched . if isinstance ( value , Repository ) : return value # We expect a string with a name or URL . if not isinstance ( value , string_types ) : msg = "Expected string or Repository object as argument, ...
def _prerun ( self ) : """To execute before running message"""
self . check_required_params ( ) self . _set_status ( "RUNNING" ) logger . debug ( "{}.PreRun: {}[{}]: running..." . format ( self . __class__ . __name__ , self . __class__ . path , self . uuid ) , extra = dict ( kmsg = Message ( self . uuid , entrypoint = self . __class__ . path , params = self . params ) . dump ( ) )...
def _send_chunk ( self , chunk , chunk_num ) : """Send a single chunk to the remote service . : param chunk : bytes data we are uploading : param chunk _ num : int number associated with this chunk"""
url_info = self . upload_operations . create_file_chunk_url ( self . upload_id , chunk_num , chunk ) self . upload_operations . send_file_external ( url_info , chunk )
def to_file ( self , f ) : """Saves the history as a json file . In order to use this feature , the history must only contain JSON encodable Python data structures . Numpy and PyTorch types should not be in the history . Parameters f : file - like object or str"""
with open_file_like ( f , 'w' ) as fp : json . dump ( self . to_list ( ) , fp )
def _ParseContainerLogJSON ( self , parser_mediator , file_object ) : """Extract events from a Docker container log files . The format is one JSON formatted log message per line . The path of each container log file ( which logs the container stdout and stderr ) is : DOCKER _ DIR / containers / < container ...
container_id = self . _GetIdentifierFromPath ( parser_mediator ) text_file_object = text_file . TextFile ( file_object ) for log_line in text_file_object : json_log_line = json . loads ( log_line ) time = json_log_line . get ( 'time' , None ) if not time : continue event_data = DockerJSONContain...
def add_member ( self , urls ) : """Add a member into the cluster . : returns : new member : rtype : : class : ` . Member `"""
member_add_request = etcdrpc . MemberAddRequest ( peerURLs = urls ) member_add_response = self . clusterstub . MemberAdd ( member_add_request , self . timeout , credentials = self . call_credentials , metadata = self . metadata ) member = member_add_response . member return etcd3 . members . Member ( member . ID , memb...
def is_multi_timeseries_orthogonal ( nc , variable ) : '''Returns true if the variable is a orthogonal multidimensional array representation of time series . For more information on what this means see CF 1.6 § H . 2.1 http : / / cfconventions . org / cf - conventions / v1.6.0 / cf - conventions . html # _ or...
# x ( i ) , y ( i ) , z ( i ) , t ( o ) # X ( i , o ) dims = nc . variables [ variable ] . dimensions cmatrix = coordinate_dimension_matrix ( nc ) for req in ( 'x' , 'y' , 't' ) : if req not in cmatrix : return False if len ( cmatrix [ 'x' ] ) != 1 or cmatrix [ 'x' ] != cmatrix [ 'y' ] : return False if...
def resource ( ref : str , delimiter : str = None ) -> str : """Given a ( URI ) reference , return up to its delimiter ( exclusively ) , or all of it if there is none . : param ref : reference : param delimiter : delimiter character ( default None maps to ' # ' , or ' ; ' introduces identifiers )"""
return ref . split ( delimiter if delimiter else '#' ) [ 0 ]
def tupletree ( table , start = 'start' , stop = 'stop' , value = None ) : """Construct an interval tree for the given table , where each node in the tree is a row of the table ."""
import intervaltree tree = intervaltree . IntervalTree ( ) it = iter ( table ) hdr = next ( it ) flds = list ( map ( text_type , hdr ) ) assert start in flds , 'start field not recognised' assert stop in flds , 'stop field not recognised' getstart = itemgetter ( flds . index ( start ) ) getstop = itemgetter ( flds . in...
def generate_cmd_string ( self , cmd , * args , ** kwargs ) : """for any generate _ cmd _ string doesn ' t written as public method of terraform examples : 1 . call import command , ref to https : / / www . terraform . io / docs / commands / import . html - - > generate _ cmd _ string call : terraform imp...
cmds = cmd . split ( ) cmds = [ self . terraform_bin_path ] + cmds for option , value in kwargs . items ( ) : if '_' in option : option = option . replace ( '_' , '-' ) if type ( value ) is list : for sub_v in value : cmds += [ '-{k}={v}' . format ( k = option , v = sub_v ) ] ...
def from_dict ( self , dirent ) : """Create a new FilePermissions object from the given dictionary . This works with the FileListing parser class , which has already done the hard work of pulling many of these fields out . We create an object with all the dictionary keys available as properties , and also spl...
# Check that we have at least as much data as the _ _ init _ _ requires for k in [ 'perms' , 'owner' , 'group' , 'name' , 'dir' ] : if k not in dirent : raise ValueError ( "Need required key '{k}'" . format ( k = k ) ) # Copy all values across for k in dirent : setattr ( self , k , dirent [ k ] ) # Crea...
def unused ( self ) : """Return unused user - created elements . : rtype : list ( Element )"""
self . _params . update ( href = self . _resource . get ( 'search_unused' ) ) return self