signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def listen ( self , addr = None ) : """Wait for a connection / reconnection from a DCC peer . Returns the DCCConnection object . The local IP address and port are available as self . localaddress and self . localport . After connection from a peer , the peer address and port are available as self . peerad...
self . buffer = buffer . LineBuffer ( ) self . handlers = { } self . socket = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) self . passive = True default_addr = socket . gethostbyname ( socket . gethostname ( ) ) , 0 try : self . socket . bind ( addr or default_addr ) self . localaddress , self . ...
def multi_option ( * param_decls , ** attrs ) : """modify help text and indicate option is permitted multiple times : param param _ decls : : param attrs : : return :"""
attrhelp = attrs . get ( 'help' , None ) if attrhelp is not None : newhelp = attrhelp + " (multiple occurrence permitted)" attrs [ 'help' ] = newhelp attrs [ 'multiple' ] = True return click . option ( * param_decls , ** attrs )
def next_joystick_device ( ) : """Finds the next available js device name ."""
for i in range ( 100 ) : dev = "/dev/input/js{0}" . format ( i ) if not os . path . exists ( dev ) : return dev
def formdata_encode ( fields ) : """Encode fields ( a dict ) as a multipart / form - data HTTP request payload . Returns a ( content type , request body ) pair ."""
BOUNDARY = '----form-data-boundary-ZmRkNzJkMjUtMjkyMC00' out = [ ] for ( key , value ) in fields . items ( ) : out . append ( '--' + BOUNDARY ) out . append ( 'Content-Disposition: form-data; name="%s"' % key ) out . append ( '' ) out . append ( value ) out . append ( '--' + BOUNDARY + '--' ) out . appe...
def release_lock ( dax , key , lock_mode = LockMode . wait ) : """Manually release a pg advisory lock . : dax : a DataAccess instance : key : either a big int or a 2 - tuple of integers : lock _ mode : a member of the LockMode enum"""
lock_fxn = _lock_fxn ( "unlock" , lock_mode , False ) return dax . get_scalar ( dax . callproc ( lock_fxn , key if isinstance ( key , ( list , tuple ) ) else [ key ] ) [ 0 ] )
def _create_target_dir_if_needed ( self , target , depth_limit = 20 ) : """Creates the directory for the path given , recursively creating parent directories when needed"""
if depth_limit <= 0 : raise FtpCreateDirsException ( 'Depth limit exceeded' ) if not target : return target_dir = os . path . dirname ( target ) parent_dir , dir_name = os . path . split ( target_dir ) parent_dir_ls = [ ] try : parent_dir_ls = self . ftp . nlst ( parent_dir ) except : # Possibly a microsoft...
def normalized ( beta , beta_list ) : """归一化函数 Keyword arguments : beta - - 当前文本行的beta值 , float类型 beta _ list - - 标题候选队列的beta队列 , list类型 Return : result - - 归一化结果 , 区间 【 0,1】"""
if len ( beta_list ) <= 2 : # beta _ list元素小于等于2时 , 根据jiaccard相似度公式进行判定 return 1 try : result = ( beta - min ( beta_list ) ) / ( max ( beta_list ) - min ( beta_list ) ) except ZeroDivisionError : result = 1 return result
def csr_matrix ( arg1 , shape = None , ctx = None , dtype = None ) : """Creates a ` CSRNDArray ` , an 2D array with compressed sparse row ( CSR ) format . The CSRNDArray can be instantiated in several ways : - csr _ matrix ( D ) : to construct a CSRNDArray with a dense 2D array ` ` D ` ` - * * D * * ( * arr...
# construct a csr matrix from ( M , N ) or ( data , indices , indptr ) if isinstance ( arg1 , tuple ) : arg_len = len ( arg1 ) if arg_len == 2 : # construct a sparse csr matrix from # scipy coo matrix if input format is coo if isinstance ( arg1 [ 1 ] , tuple ) and len ( arg1 [ 1 ] ) == 2 : ...
def random_tracing ( ) : """Create new Tracing ( ) tuple with random IDs ."""
new_id = _uniq_id ( ) return Tracing ( span_id = new_id , parent_id = 0 , trace_id = new_id , traceflags = 0 )
def _format_option_strings ( self , option , mvarfmt = ' <%s>' , optsep = ', ' ) : """Return a comma - separated list of option strings and metavars . : param option : tuple of ( short opt , long opt ) , e . g : ( ' - f ' , ' - - format ' ) : param mvarfmt : metavar format string - evaluated as mvarfmt % metava...
opts = [ ] if option . _short_opts : opts . append ( option . _short_opts [ 0 ] ) if option . _long_opts : opts . append ( option . _long_opts [ 0 ] ) if len ( opts ) > 1 : opts . insert ( 1 , optsep ) if option . takes_value ( ) : metavar = option . metavar or option . dest . lower ( ) opts . appen...
def put_job_into ( self , tube_name , data , pri = 65536 , delay = 0 , ttr = 120 ) : """Insert a new job into a specific queue . Wrapper around : func : ` put _ job ` . : param tube _ name : Tube name : type tube _ name : str : param data : Job body : type data : Text ( either str which will be encoded as u...
with self . using ( tube_name ) as inserter : return inserter . put_job ( data = data , pri = pri , delay = delay , ttr = ttr )
def group_by_types ( self ) : """Iterate over species grouped by type"""
for t in self . types_of_specie : for site in self : if site . specie == t : yield site
def get_parameters ( self , packet_count = None ) : """Returns the special tshark parameters to be used according to the configuration of this class ."""
params = [ ] if self . _capture_filter : params += [ '-f' , self . _capture_filter ] if self . _display_filter : params += [ get_tshark_display_filter_flag ( self . tshark_path ) , self . _display_filter ] # Raw is only enabled when JSON is also enabled . if self . include_raw : params += [ "-x" ] if packet...
def handle_new_selection ( self , models ) : """Handles the selection for generic widgets This is a helper method for generic widgets that want to modify the selection . These widgets can pass a list of newly selected ( or clicked on ) models . The method looks at the previous selection , the passed models an...
models = self . _check_model_types ( models ) if extend_selection ( ) : already_selected_elements = models & self . _selected newly_selected_elements = models - self . _selected self . _selected . difference_update ( already_selected_elements ) self . _selected . update ( newly_selected_elements ) else ...
def execute ( self , input_args = None , monitor = False ) : """Executes the workflow . : param input _ args : External input arguments to the workflow . They have to be in a form of a dictionary where each key is an EOTask used in the workflow and each value is a dictionary or a tuple of arguments . : type i...
out_degs = dict ( self . dag . get_outdegrees ( ) ) input_args = self . parse_input_args ( input_args ) _ , intermediate_results = self . _execute_tasks ( input_args = input_args , out_degs = out_degs , monitor = monitor ) return WorkflowResults ( intermediate_results )
def remove_module ( self , module ) : """Ownership of module is returned"""
with ffi . OutputString ( ) as outerr : if ffi . lib . LLVMPY_RemoveModule ( self , module , outerr ) : raise RuntimeError ( str ( outerr ) ) self . _modules . remove ( module ) module . _owned = False
def to_pixel ( self , wcs , mode = 'all' ) : """Convert the aperture to a ` CircularAnnulus ` object defined in pixel coordinates . Parameters wcs : ` ~ astropy . wcs . WCS ` The world coordinate system ( WCS ) transformation to use . mode : { ' all ' , ' wcs ' } , optional Whether to do the transformat...
pixel_params = self . _to_pixel_params ( wcs , mode = mode ) return CircularAnnulus ( ** pixel_params )
def set_empty_region ( self , region_id , type_id , generated_at , error_if_orders_present = True ) : """Prepares for the given region + item combo by instantiating a : py : class : ` MarketItemsInRegionList ` instance , which will track region ID , type ID , and generated time . This is mostly used for the J...
key = '%s_%s' % ( region_id , type_id ) if error_if_orders_present and self . _orders . has_key ( key ) : raise ItemAlreadyPresentError ( "Orders already exist for the given region and type ID. " "Pass error_if_orders_present=False to disable this failsafe, " "if desired." ) self . _orders [ key ] = MarketItemsInRe...
def curses_session ( ) : """Setup terminal and initialize curses . Most of this copied from curses . wrapper in order to convert the wrapper into a context manager ."""
try : # Curses must wait for some time after the Escape key is pressed to # check if it is the beginning of an escape sequence indicating a # special key . The default wait time is 1 second , which means that # http : / / stackoverflow . com / questions / 27372068 os . environ [ 'ESCDELAY' ] = '25' # Initialize...
def _recognize_basic_types ( s ) : """If value of given string ` s ` is an integer ( or long ) , float or boolean , convert it to a proper type and return it ."""
tps = [ int , float ] if not six . PY3 : # compat for older versions of six that don ' t have PY2 tps . append ( long ) for tp in tps : try : return tp ( s ) except ValueError : pass if s . lower ( ) == 'true' : return True if s . lower ( ) == 'false' : return False if s . lower ( ) ...
def get_object_from_classbased_instance ( instance , queryset , request , * args , ** kwargs ) : """Get object from an instance of classbased generic view Parameters instance : instance An instance of classbased generic view queryset : instance A queryset instance request : instance A instance of Http...
from django . views . generic . edit import BaseCreateView # initialize request , args , kwargs of classbased _ instance # most of methods of classbased view assumed these attributes # but these attributes is initialized in ` ` dispatch ` ` method . instance . request = request instance . args = args instance . kwargs ...
def loads ( buf , mutable = True , value_encoding = None , value_errors = None ) : """Deserialize a BSER - encoded blob . @ param buf : The buffer to deserialize . @ type buf : bytes @ param mutable : Whether to return mutable results . @ type mutable : bool @ param value _ encoding : Optional codec to us...
info = _pdu_info_helper ( buf ) expected_len = info [ 2 ] pos = info [ 3 ] if len ( buf ) != expected_len + pos : raise ValueError ( "bser data len %d != header len %d" % ( expected_len + pos , len ( buf ) ) ) bunser = Bunser ( mutable = mutable , value_encoding = value_encoding , value_errors = value_errors ) retu...
def classify_file ( f ) : """Examine the column names to determine which type of file this is . Return a tuple : retvalue [ 0 ] = " file is non - parameterized " retvalue [ 1 ] = " file contains error column " """
cols = f [ 1 ] . columns if len ( cols ) == 2 : # Then we must have a simple file return ( True , False ) elif len ( cols ) == 3 and ( 'ERROR' in cols . names ) : return ( True , True ) elif len ( cols ) > 2 and ( 'ERROR' not in cols . names ) : return ( True , False ) else : return ( False , True )
def up ( queue , host = None ) : '''Up a queue , by removing a down file - - if a queue has no down file , this function is a no - op .'''
down_path = fsq_path . down ( queue , host = host ) _queue_ok ( os . path . dirname ( down_path ) ) try : os . unlink ( down_path ) except ( OSError , IOError , ) , e : if e . errno != errno . ENOENT : raise FSQConfigError ( e . errno , wrap_io_os_err ( e ) )
def _histplot_op ( values , values2 , rotated , ax , hist_kwargs ) : """Add a histogram for the data to the axes ."""
if values2 is not None : raise NotImplementedError ( "Insert hexbin plot here" ) bins = hist_kwargs . pop ( "bins" ) if bins is None : bins = get_bins ( values ) ax . hist ( values , bins = bins , ** hist_kwargs ) if rotated : ax . set_yticks ( bins [ : - 1 ] ) else : ax . set_xticks ( bins [ : - 1 ] ) ...
def shorrocks_index ( A ) : r"""Implements Shorrocks mobility index Parameters A : array _ like ( float ) Square matrix with transition probabilities ( mobility matrix ) of dimension m Returns Shorrocks index : float The Shorrocks mobility index calculated as . . math : : s ( A ) = \ frac { m - \ ...
A = np . asarray ( A ) # Convert to array if not already m , n = A . shape if m != n : raise ValueError ( 'A must be a square matrix' ) diag_sum = np . diag ( A ) . sum ( ) return ( m - diag_sum ) / ( m - 1 )
def redef ( obj , key , value , ** kwargs ) : '''A static constructor helper function'''
return Redef ( obj , key , value = value , ** kwargs )
def on_get ( self , req , resp , ** kwargs ) : """Respond on GET requests using ` ` self . retrieve ( ) ` ` handler ."""
return super ( ) . on_get ( req , resp , handler = self . _retrieve , ** kwargs )
def load_version ( fname : str ) -> str : """Loads version from file . : param fname : Name of file to load version from . : return : Version string ."""
if not os . path . exists ( fname ) : logger . warning ( "No version file found. Defaulting to 1.0.3" ) return "1.0.3" with open ( fname ) as inp : return inp . read ( ) . strip ( )
def __new_submodule ( self , name , obj ) : """Create a new submodule documentation object for this ` obj ` , which must by a Python module object and pass along any settings in this module ."""
# Forcefully set the module name so that it is always the absolute # import path . We can ' t rely on ` obj . _ _ name _ _ ` , since it doesn ' t # necessarily correspond to the public exported name of the module . obj . __dict__ [ '__budoc_module_name' ] = '%s.%s' % ( self . refname , name ) return Module ( obj , docf...
def parse_DID ( did , name_type = None ) : """Given a DID string , parse it into { ' address ' : . . . , ' index ' : . . . , ' name _ type ' } Raise on invalid DID"""
did_pattern = '^did:stack:v0:({}{{25,35}})-([0-9]+)$' . format ( OP_BASE58CHECK_CLASS ) m = re . match ( did_pattern , did ) assert m , 'Invalid DID: {}' . format ( did ) original_address = str ( m . groups ( ) [ 0 ] ) name_index = int ( m . groups ( ) [ 1 ] ) vb = keylib . b58check . b58check_version_byte ( original_a...
def create ( cls , name , engines , policy = None , comment = None , ** kwargs ) : """Create a new validate policy task . If a policy is not specified , the engines existing policy will be validated . Override default validation settings as kwargs . : param str name : name of task : param engines : list of ...
json = { 'name' : name , 'resources' : [ eng . href for eng in engines ] , 'policy' : policy . href if policy is not None else policy , 'comment' : comment } if kwargs : json . update ( policy_validation_settings ( ** kwargs ) ) return ElementCreator ( cls , json )
def key_validation_check ( tweet_keys_list , superset_keys , minset_keys ) : """Validates the keys present in a Tweet . Args : tweet _ keys _ list ( list ) : the keys present in a tweet superset _ keys ( set ) : the set of all possible keys for a tweet minset _ keys ( set ) : the set of minimal keys expecte...
# check for keys that must be present tweet_keys = set ( tweet_keys_list ) minset_overlap = tweet_keys & minset_keys if minset_overlap != minset_keys : raise UnexpectedFormatError ( "keys ({}) missing from Tweet (Public API data is not supported)" . format ( minset_keys - tweet_keys ) ) # check for keys that could ...
def get_film ( film_id ) : '''Return a single film'''
result = _get ( film_id , settings . FILMS ) return Film ( result . content )
def _set_igp_sync ( self , v , load = False ) : """Setter method for igp _ sync , mapped from YANG variable / mpls _ state / rsvp / igp _ sync ( container ) If this variable is read - only ( config : false ) in the source YANG file , then _ set _ igp _ sync is considered as a private method . Backends looking...
if hasattr ( v , "_utype" ) : v = v . _utype ( v ) try : t = YANGDynClass ( v , base = igp_sync . igp_sync , is_container = 'container' , presence = False , yang_name = "igp-sync" , rest_name = "igp-sync" , parent = self , path_helper = self . _path_helper , extmethods = self . _extmethods , register_paths = Tr...
def is_email ( string ) : """> > > is _ email ( ' username @ example . com ' ) True > > > is _ email ( ' example . com ' ) False > > > is _ email ( ' firstname . lastname @ domain . co . uk ' ) True"""
email_regex = r'^[A-Za-z0-9\.\+_-]+@[A-Za-z0-9\._-]+\.[a-zA-Z]*$' if isinstance ( string , str ) and not re . match ( email_regex , string ) : return False else : return True
def _set_platform_specific_keyboard_shortcuts ( self ) : """QtDesigner does not support QKeySequence : : StandardKey enum based default keyboard shortcuts . This means that all default key combinations ( " Save " , " Quit " , etc ) have to be defined in code ."""
self . action_new_phrase . setShortcuts ( QKeySequence . New ) self . action_save . setShortcuts ( QKeySequence . Save ) self . action_close_window . setShortcuts ( QKeySequence . Close ) self . action_quit . setShortcuts ( QKeySequence . Quit ) self . action_undo . setShortcuts ( QKeySequence . Undo ) self . action_re...
def _call_java ( sc , java_obj , name , * args ) : """Method copied from pyspark . ml . wrapper . Uses private Spark APIs ."""
m = getattr ( java_obj , name ) java_args = [ _py2java ( sc , arg ) for arg in args ] return _java2py ( sc , m ( * java_args ) )
def reflect ( source , model , cache = None ) : '''Finds an object of class ` model ` with the same identifier as the ` source ` object'''
if source is None : return None if cache and source in cache : return cache [ source ] db = object_session ( source ) ident = identity_key ( instance = source ) [ 1 ] assert ident is not None return db . query ( model ) . get ( ident )
def scroll_mouse ( self , mouse_x : int ) : """Scrolls the mouse if ROI Selection reaches corner of view : param mouse _ x : : return :"""
scrollbar = self . horizontalScrollBar ( ) if mouse_x - self . view_rect ( ) . x ( ) > self . view_rect ( ) . width ( ) : scrollbar . setValue ( scrollbar . value ( ) + 5 ) elif mouse_x < self . view_rect ( ) . x ( ) : scrollbar . setValue ( scrollbar . value ( ) - 5 )
def flownet2_sd ( self , x ) : """Architecture in Table 3 of FlowNet 2.0. Args : x : concatenation of two inputs , of shape [ 1 , 2xC , H , W ]"""
with argscope ( [ tf . layers . conv2d ] , activation = lambda x : tf . nn . leaky_relu ( x , 0.1 ) , padding = 'valid' , strides = 2 , kernel_size = 3 , data_format = 'channels_first' ) , argscope ( [ tf . layers . conv2d_transpose ] , padding = 'same' , activation = tf . identity , data_format = 'channels_first' , st...
async def jsk_show ( self , ctx : commands . Context ) : """Shows Jishaku in the help command ."""
if not self . jsk . hidden : return await ctx . send ( "Jishaku is already visible." ) self . jsk . hidden = False await ctx . send ( "Jishaku is now visible." )
def samblaster_dedup_sort ( data , tx_out_file , tx_sr_file , tx_disc_file ) : """Deduplicate and sort with samblaster , produces split read and discordant pair files ."""
samblaster = config_utils . get_program ( "samblaster" , data [ "config" ] ) samtools = config_utils . get_program ( "samtools" , data [ "config" ] ) tmp_prefix = "%s-sorttmp" % utils . splitext_plus ( tx_out_file ) [ 0 ] tobam_cmd = ( "{samtools} sort {sort_opt} -@ {cores} -m {mem} -T {tmp_prefix}-{dext} {out_file} -"...
def retain_identities ( retention_time , es_enrichment_url , sortinghat_db , data_source , active_data_sources ) : """Select the unique identities not seen before ` retention _ time ` and delete them from SortingHat . Furthermore , it deletes also the orphan unique identities , those ones stored in SortingHat b...
before_date = get_diff_current_date ( minutes = retention_time ) before_date_str = before_date . isoformat ( ) es = Elasticsearch ( [ es_enrichment_url ] , timeout = 120 , max_retries = 20 , retry_on_timeout = True , verify_certs = False ) # delete the unique identities which have not been seen after ` before _ date ` ...
def run ( self ) : '''Run listener'''
self . running = True for msg in self . recv ( 1 ) : if msg is None : if self . running : continue else : break self . logger . debug ( "New message received: %s" , str ( msg ) ) self . add_to_queue ( msg )
def on_config_value_changed ( self , config_m , prop_name , info ) : """Callback when a config value has been changed : param ConfigModel config _ m : The config model that has been changed : param str prop _ name : Should always be ' config ' : param dict info : Information e . g . about the changed config k...
config_key = info [ 'args' ] [ 1 ] if "LOGGING" in config_key : self . update_log_button_state ( )
def first ( self ) : """Gets item with highest priority . Performance : O ( 1)"""
with self . lock : try : return self . data [ 0 ] [ 0 ] except IndexError as ex : ex . args = ( 'DEPQ is empty' , ) raise
def get_deserializer ( serializer_format ) : """Get the deserializer for a specific format"""
if serializer_format == Format . JSON : return _deserialize_json if serializer_format == Format . PICKLE : return _deserialize_pickle
def __vCmdCamTrigger ( self , args ) : '''Trigger Camera'''
# print ( self . camera _ list ) for cam in self . camera_list : cam . take_picture ( ) print ( "Trigger Cam %s" % cam )
def save ( self , commit = True ) : """Save and send"""
contact = super ( ContactFormBase , self ) . save ( ) context = { 'contact' : contact } context . update ( get_site_metas ( ) ) subject = '' . join ( render_to_string ( self . mail_subject_template , context ) . splitlines ( ) ) content = render_to_string ( self . mail_content_template , context ) send_mail ( subject ,...
def _next_raw_dimension ( self ) : """_ RawDimension for next * dimension _ dict * in sequence or None for last . Returns None if this dimension is the last in sequence for this cube ."""
dimension_dicts = self . _dimension_dicts this_idx = dimension_dicts . index ( self . _dimension_dict ) if this_idx > len ( dimension_dicts ) - 2 : return None return _RawDimension ( dimension_dicts [ this_idx + 1 ] , self . _dimension_dicts )
def asizeof ( self , * objs , ** opts ) : '''Return the combined size of the given objects ( with modified options , see method * * set * * ) .'''
if opts : self . set ( ** opts ) s , _ = self . _sizes ( objs , None ) return s
def get_letters_iterable ( word ) : """splits the word into a character - list of tamil / english characters present in the stream"""
WLEN , idx = len ( word ) , 0 while ( idx < WLEN ) : c = word [ idx ] # print ( idx , hex ( ord ( c ) ) , len ( ta _ letters ) ) if c in uyir_letter_set or c == ayudha_letter : idx = idx + 1 yield c elif c in grantha_agaram_set : if idx + 1 < WLEN and word [ idx + 1 ] in all_symb...
def dead_links ( self ) : """Generate the coordinates of all dead links leaving working chips . Any link leading to a dead chip will also be included in the list of dead links . In non - torroidal SpiNNaker sysmtes ( e . g . single SpiNN - 5 boards ) , links on the periphery of the system will be marked as de...
for ( x , y ) , chip_info in iteritems ( self ) : for link in Links : if link not in chip_info . working_links : yield ( x , y , link )
def json ( self ) : """Load response body as json . : raises : : class : ` ContentDecodingError `"""
try : return json . loads ( self . text ) except Exception as e : raise ContentDecodingError ( e )
def getprefix ( self , u ) : """Get the prefix for the specified namespace ( uri ) @ param u : A namespace uri . @ type u : str @ return : The namspace . @ rtype : ( prefix , uri ) ."""
for ns in Namespace . all : if u == ns [ 1 ] : return ns [ 0 ] for ns in self . prefixes : if u == ns [ 1 ] : return ns [ 0 ] raise Exception ( 'ns (%s) not mapped' % u )
def get_upstream_paths ( self , port ) : """Retrieve a dictionary containing the full URLs of the upstream apps : param int port : The port used by the replay and cdx servers : return : A dictionary containing the upstream paths ( replay , cdx - server , record [ if enabled ] ) : rtype : dict [ str , str ]"""
base_paths = { 'replay' : self . REPLAY_API % port , 'cdx-server' : self . CDX_API % port , } if self . recorder_path : base_paths [ 'record' ] = self . recorder_path return base_paths
def write_hw_scgink ( hw , filename = 'mathbrush-test.txt' ) : """Parameters hw : HandwrittenData object filename : string Path , where the SCG INK file gets written"""
with open ( filename , 'w' ) as f : f . write ( 'SCG_INK\n' ) f . write ( '%i\n' % len ( hw . get_pointlist ( ) ) ) for stroke in hw . get_pointlist ( ) : f . write ( '%i\n' % len ( stroke ) ) for point in stroke : f . write ( '%i %i\n' % ( point [ 'x' ] , point [ 'y' ] ) )
def process_lines ( self , input_lines , ** kwargs ) : '''Executes the pipeline of subsequent VISL _ CG3 commands . The first process in pipeline gets input _ lines as an input , and each subsequent process gets the output of the previous process as an input . The idea of how to construct the pipeline borrows...
split_result_lines = False remove_info = True for argName , argVal in kwargs . items ( ) : if argName in [ 'split_result_lines' , 'split_result' ] and argVal in [ True , False ] : split_result_lines = argVal if argName in [ 'remove_info' , 'info_remover' , 'clean_up' ] and argVal in [ True , False ] : ...
def _dir_size ( directory ) : """Returns total size ( in bytes ) of the given ' directory ' ."""
size = 0 for elem in tf_v1 . gfile . ListDirectory ( directory ) : elem_full_path = os . path . join ( directory , elem ) stat = tf_v1 . gfile . Stat ( elem_full_path ) size += _dir_size ( elem_full_path ) if stat . is_directory else stat . length return size
def _imm_new ( cls ) : '''All immutable new classes use a hack to make sure the post - init cleanup occurs .'''
imm = object . __new__ ( cls ) # Note that right now imm has a normal setattr method ; # Give any parameter that has one a default value params = cls . _pimms_immutable_data_ [ 'params' ] for ( p , dat ) in six . iteritems ( params ) : dat = dat [ 0 ] if dat : object . __setattr__ ( imm , p , dat [ 0 ] ...
def read_distributions_from_config ( cp , section = "prior" ) : """Returns a list of PyCBC distribution instances for a section in the given configuration file . Parameters cp : WorflowConfigParser An open config file to read . section : { " prior " , string } Prefix on section names from which to retri...
dists = [ ] variable_args = [ ] for subsection in cp . get_subsections ( section ) : name = cp . get_opt_tag ( section , "name" , subsection ) dist = distribs [ name ] . from_config ( cp , section , subsection ) if set ( dist . params ) . isdisjoint ( variable_args ) : dists . append ( dist ) ...
def process_request ( self , request , client_address ) : """Call finish _ request ."""
self . finish_request ( request , client_address ) self . shutdown_request ( request )
def get_taf_alt_ice_turb ( wxdata : [ str ] ) -> ( [ str ] , str , [ str ] , [ str ] ) : # type : ignore """Returns the report list and removed : Altimeter string , Icing list , Turbulance list"""
altimeter = '' icing , turbulence = [ ] , [ ] for i , item in reversed ( list ( enumerate ( wxdata ) ) ) : if len ( item ) > 6 and item . startswith ( 'QNH' ) and item [ 3 : 7 ] . isdigit ( ) : altimeter = wxdata . pop ( i ) [ 3 : 7 ] elif item . isdigit ( ) : if item [ 0 ] == '6' : ...
def domain_add ( self , domain , description = DESCRIPTION ) : """Sends a POST to / 1.0 / domains / using this post - data : { " domain " : " www . fogfu . com " , " description " : " Added by tagcube - api " } : param domain : The domain name to add as a new resource : return : The newly created resource""...
data = { "domain" : domain , "description" : description } url = self . build_full_url ( self . DOMAINS ) return self . create_resource ( url , data )
def append_on_chord ( self , on_chord , root ) : """Append on chord To create Am7 / G q = Quality ( ' m7 ' ) q . append _ on _ chord ( ' G ' , root = ' A ' ) : param str on _ chord : bass note of the chord : param str root : root note of the chord"""
root_val = note_to_val ( root ) on_chord_val = note_to_val ( on_chord ) - root_val list_ = list ( self . components ) for idx , val in enumerate ( list_ ) : if val % 12 == on_chord_val : self . components . remove ( val ) break if on_chord_val > root_val : on_chord_val -= 12 if on_chord_val not ...
def start ( self ) : """Launches a new SMTP client session on the server taken from the ` self . options ` dict . : param my _ ip : IP of this Client itself"""
username = self . options [ 'username' ] password = self . options [ 'password' ] server_host = self . options [ 'server' ] server_port = self . options [ 'port' ] honeypot_id = self . options [ 'honeypot_id' ] session = self . create_session ( server_host , server_port , honeypot_id ) logger . debug ( 'Sending {0} bai...
def delete_connection ( self , ** kwargs ) : """Remove a single connection to a provider for the specified user ."""
conn = self . find_connection ( ** kwargs ) if not conn : return False self . delete ( conn ) return True
def nii_modify ( nii , fimout = '' , outpath = '' , fcomment = '' , voxel_range = [ ] ) : '''Modify the NIfTI image given either as a file path or a dictionary , obtained by nimpa . getnii ( file _ path ) .'''
if isinstance ( nii , basestring ) and os . path . isfile ( nii ) : dctnii = imio . getnii ( nii , output = 'all' ) fnii = nii if isinstance ( nii , dict ) and 'im' in nii : dctnii = nii if 'fim' in dctnii : fnii = dctnii [ 'fim' ] # > output path if outpath == '' and fimout != '' and '/' in fim...
def tocimxml ( value ) : # pylint : disable = line - too - long """Return the CIM - XML representation of the input object , as an object of an appropriate subclass of : term : ` Element ` . The returned CIM - XML representation is consistent with : term : ` DSP0201 ` . Parameters : value ( : term : ` CIM o...
# noqa : E501 if isinstance ( value , ( tuple , list ) ) : array_xml = [ ] for v in value : if v is None : if SEND_VALUE_NULL : array_xml . append ( cim_xml . VALUE_NULL ( ) ) else : array_xml . append ( cim_xml . VALUE ( None ) ) else : ...
def _shutdown_proc ( p , timeout ) : """Wait for a proc to shut down , then terminate or kill it after ` timeout ` ."""
freq = 10 # how often to check per second for _ in range ( 1 + timeout * freq ) : ret = p . poll ( ) if ret is not None : logging . info ( "Shutdown gracefully." ) return ret time . sleep ( 1 / freq ) logging . warning ( "Killing the process." ) p . kill ( ) return p . wait ( )
def select_as_multiple ( self , keys , where = None , selector = None , columns = None , start = None , stop = None , iterator = False , chunksize = None , auto_close = False , ** kwargs ) : """Retrieve pandas objects from multiple tables Parameters keys : a list of the tables selector : the table to apply th...
# default to single select where = _ensure_term ( where , scope_level = 1 ) if isinstance ( keys , ( list , tuple ) ) and len ( keys ) == 1 : keys = keys [ 0 ] if isinstance ( keys , str ) : return self . select ( key = keys , where = where , columns = columns , start = start , stop = stop , iterator = iterator...
def analyze ( self , text ) : u"""Analyze the input text with custom CharFilters , Tokenizer and TokenFilters . : param text : unicode string to be tokenized : return : token generator . emitted element type depends on the output of the last TokenFilter . ( e . g . , ExtractAttributeFilter emits strings . )"""
for cfilter in self . char_filters : text = cfilter . filter ( text ) tokens = self . tokenizer . tokenize ( text , stream = True , wakati = False ) for tfilter in self . token_filters : tokens = tfilter . filter ( tokens ) return tokens
def addScalarBar ( self , c = None , title = "" , horizontal = False , vmin = None , vmax = None ) : """Add a 2D scalar bar to actor . . . hint : : | mesh _ bands | | mesh _ bands . py | _"""
# book it , it will be created by Plotter . show ( ) later self . scalarbar = [ c , title , horizontal , vmin , vmax ] return self
def factorization_machine_model ( factor_size , num_features , lr_mult_config , wd_mult_config , init_config ) : """builds factorization machine network with proper formulation : y = w _ 0 \ sum ( x _ i w _ i ) + 0.5 ( \ sum \ sum < v _ i , v _ j > x _ ix _ j - \ sum < v _ iv _ i > x _ i ^ 2)"""
x = mx . symbol . Variable ( "data" , stype = 'csr' ) # factor , linear and bias terms v = mx . symbol . Variable ( "v" , shape = ( num_features , factor_size ) , stype = 'row_sparse' , init = init_config [ 'v' ] , lr_mult = lr_mult_config [ 'v' ] , wd_mult = wd_mult_config [ 'v' ] ) w = mx . symbol . Variable ( 'w' , ...
def Satisfy_Constraints ( U , B , BtBinv ) : """U is the prolongator update . Project out components of U such that U * B = 0. Parameters U : bsr _ matrix m x n sparse bsr matrix Update to the prolongator B : array n x k array of the coarse grid near nullspace vectors BtBinv : array Local inv ( B _ ...
RowsPerBlock = U . blocksize [ 0 ] ColsPerBlock = U . blocksize [ 1 ] num_block_rows = int ( U . shape [ 0 ] / RowsPerBlock ) UB = np . ravel ( U * B ) # Apply constraints , noting that we need the conjugate of B # for use as Bi . H in local projection pyamg . amg_core . satisfy_constraints_helper ( RowsPerBlock , Cols...
def randomArray ( size , bound ) : """Returns an array initialized to random values between - max and max ."""
if type ( size ) == type ( 1 ) : size = ( size , ) temp = Numeric . array ( ndim ( * size ) ) * ( 2.0 * bound ) return temp - bound
def get ( self , sid ) : """Constructs a FieldValueContext : param sid : The unique string that identifies the resource : returns : twilio . rest . autopilot . v1 . assistant . field _ type . field _ value . FieldValueContext : rtype : twilio . rest . autopilot . v1 . assistant . field _ type . field _ value ...
return FieldValueContext ( self . _version , assistant_sid = self . _solution [ 'assistant_sid' ] , field_type_sid = self . _solution [ 'field_type_sid' ] , sid = sid , )
def embedManifestExeCheck ( target , source , env ) : """Function run by embedManifestExeCheckAction to check for existence of manifest and other conditions , and embed the manifest by calling embedManifestExeAction if so ."""
if env . get ( 'WINDOWS_EMBED_MANIFEST' , 0 ) : manifestSrc = target [ 0 ] . get_abspath ( ) + '.manifest' if os . path . exists ( manifestSrc ) : ret = ( embedManifestExeAction ) ( [ target [ 0 ] ] , None , env ) if ret : raise SCons . Errors . UserError ( "Unable to embed manifest ...
def get_declaration ( self ) : """Returns the string for the declaration of the type"""
if self . is_opaque : out = "{strrep} = type opaque" . format ( strrep = str ( self ) ) else : out = "{strrep} = type {struct}" . format ( strrep = str ( self ) , struct = self . structure_repr ( ) ) return out
def ask_string ( * question : Token , default : Optional [ str ] = None ) -> Optional [ str ] : """Ask the user to enter a string ."""
tokens = get_ask_tokens ( question ) if default : tokens . append ( "(%s)" % default ) info ( * tokens ) answer = read_input ( ) if not answer : return default return answer
def set_ ( self , state ) : """Set new state for machine ."""
if not self . can_be_ ( state ) : state = self . _meta [ 'translator' ] . translate ( state ) raise TransitionError ( "Cannot transit from '{actual_value}' to '{value}'." . format ( actual_value = self . actual_state . value , value = state . value ) ) self . force_set ( state )
def _save_obj_without_attr ( obj , attr_list , path , values_to_save = None ) : """Save object with attributes from attr _ list . Parameters obj : obj Object of class with _ _ dict _ _ attribute . attr _ list : list List with attributes to exclude from saving to dill object . If empty list all attribute...
if values_to_save is None : values_to_save = [ None ] * len ( attr_list ) saved_attr_dict = { } for attr , val_save in zip ( attr_list , values_to_save ) : if attr in obj . __dict__ : item = obj . __dict__ . pop ( attr ) saved_attr_dict [ attr ] = item setattr ( obj , attr , val_save ) w...
def resource_id ( ** kwargs ) : """Create a valid resource id string from the given parts . This method builds the resource id from the left until the next required id parameter to be appended is not found . It then returns the built up id . : param dict kwargs : The keyword arguments that will make up the id...
kwargs = { k : v for k , v in kwargs . items ( ) if v is not None } rid_builder = [ '/subscriptions/{subscription}' . format ( ** kwargs ) ] try : try : rid_builder . append ( 'resourceGroups/{resource_group}' . format ( ** kwargs ) ) except KeyError : pass rid_builder . append ( 'providers/...
def plot_feature_importances ( clf , title = 'Feature Importance' , feature_names = None , max_num_features = 20 , order = 'descending' , x_tick_rotation = 0 , ax = None , figsize = None , title_fontsize = "large" , text_fontsize = "medium" ) : """Generates a plot of a classifier ' s feature importances . Args : ...
if not hasattr ( clf , 'feature_importances_' ) : raise TypeError ( '"feature_importances_" attribute not in classifier. ' 'Cannot plot feature importances.' ) importances = clf . feature_importances_ if hasattr ( clf , 'estimators_' ) and isinstance ( clf . estimators_ , list ) and hasattr ( clf . estimators_ [ 0 ...
def get_gos_d0d1 ( self ) : """Return GO IDs whose depth is 0 ( BP , MF , CC ) or depth is 1."""
return set ( [ o . id for d in [ 0 , 1 ] for o in self . gosubdag . rcntobj . depth2goobjs . get ( d ) ] )
def get_qualification_requests ( self , qualification_type_id , sort_by = 'Expiration' , sort_direction = 'Ascending' , page_size = 10 , page_number = 1 ) : """TODO : Document ."""
params = { 'QualificationTypeId' : qualification_type_id , 'SortProperty' : sort_by , 'SortDirection' : sort_direction , 'PageSize' : page_size , 'PageNumber' : page_number } return self . _process_request ( 'GetQualificationRequests' , params , [ ( 'QualificationRequest' , QualificationRequest ) , ] )
def total_charges ( self ) : """Represents the ' goods ' acquired in the invoice ."""
selected_charges = Charge . objects . filter ( invoice = self ) . charges ( ) . exclude ( product_code = CARRIED_FORWARD ) return total_amount ( selected_charges )
def _get_subject_info ( self , n_local_subj , data ) : """Calculate metadata for subjects allocated to this process Parameters n _ local _ subj : int Number of subjects allocated to this process . data : list of 2D array . Each in shape [ n _ voxel , n _ tr ] Total number of MPI process . Returns max ...
max_sample_tr = np . zeros ( n_local_subj ) . astype ( int ) max_sample_voxel = np . zeros ( n_local_subj ) . astype ( int ) for idx in np . arange ( n_local_subj ) : nvoxel = data [ idx ] . shape [ 0 ] ntr = data [ idx ] . shape [ 1 ] max_sample_voxel [ idx ] = min ( self . max_voxel , int ( self . voxel_r...
def send_peers ( self , connection_id ) : """Sends a message containing our peers to the connection identified by connection _ id . Args : connection _ id ( str ) : A unique identifier which identifies an connection on the network server socket ."""
with self . _lock : # Needs to actually be the list of advertised endpoints of # our peers peer_endpoints = list ( self . _peers . values ( ) ) if self . _endpoint : peer_endpoints . append ( self . _endpoint ) peers_response = GetPeersResponse ( peer_endpoints = peer_endpoints ) try : # Send a ...
def addvPPfunc ( self , solution ) : '''Adds the marginal marginal value function to an existing solution , so that the next solver can evaluate vPP and thus use cubic interpolation . Parameters solution : ConsumerSolution The solution to this single period problem , which must include the consumption fun...
vPPfuncNow = MargMargValueFunc ( solution . cFunc , self . CRRA ) solution . vPPfunc = vPPfuncNow return solution
def cpe_disjoint ( cls , source , target ) : """Compares two WFNs and returns True if the set - theoretic relation between the names is DISJOINT . : param CPE2_3 _ WFN source : first WFN CPE Name : param CPE2_3 _ WFN target : seconds WFN CPE Name : returns : True if the set relation between source and targe...
# If any pairwise comparison returned DISJOINT then # the overall name relationship is DISJOINT for att , result in CPESet2_3 . compare_wfns ( source , target ) : isDisjoint = result == CPESet2_3 . LOGICAL_VALUE_DISJOINT if isDisjoint : return True return False
def resolve ( self , component_type , ** kwargs ) : """Resolves an instance of the component type . : param component _ type : The type of the component ( e . g . a class ) . : param kwargs : Overriding arguments to use ( by name ) instead of resolving them . : return : An instance of the component ."""
with self . _resolve_lock : context = _ComponentContext ( self ) return context . resolve ( component_type , ** kwargs )
def to_vars_dict ( self ) : """Return local state which is relevant for the cluster setup process ."""
return { 'azure_client_id' : self . client_id , 'azure_location' : self . location , 'azure_secret' : self . secret , 'azure_subscription_id' : self . subscription_id , 'azure_tenant_id' : self . tenant_id , }
def ImportBoarding ( self , drop_off_file ) : "Reads the bedverb . mdv file ."
for trip_id , seq , code in ReadCSV ( drop_off_file , [ 'FRT_FID' , 'LI_LFD_NR' , 'BEDVERB_CODE' ] ) : key = ( trip_id , int ( seq ) - 1 ) if code == 'A' : self . pickup_type [ key ] = '1' # '1 ' = no pick - up elif code == 'E' : self . drop_off_type [ key ] = '1' # '1 ' = no...
def get_web_element ( self , element ) : """Return the web element from a page element or its locator : param element : either a WebElement , PageElement or element locator as a tuple ( locator _ type , locator _ value ) : returns : WebElement object"""
from toolium . pageelements . page_element import PageElement if isinstance ( element , WebElement ) : web_element = element elif isinstance ( element , PageElement ) : web_element = element . web_element elif isinstance ( element , tuple ) : web_element = self . driver_wrapper . driver . find_element ( * e...
def calc_widths_filter ( self , next_filter ) : """Coroutine to analyze the incoming data stream for creating optimal column width choices . This may buffer some of the incoming stream if there isn ' t enough information to make good choices about column widths . Also it may resize widths if certain condition...
window_sent = not not self . data_window next_primed = False genexit = None if not self . data_window : start = time . monotonic ( ) while len ( self . data_window ) < self . min_render_prefill or ( len ( self . data_window ) < self . max_render_prefill and ( time . monotonic ( ) - start ) < self . max_render_d...
async def save ( self ) : """Save the machine in MAAS ."""
orig_owner_data = self . _orig_data [ 'owner_data' ] new_owner_data = dict ( self . _data [ 'owner_data' ] ) self . _changed_data . pop ( 'owner_data' , None ) await super ( Machine , self ) . save ( ) params_diff = calculate_dict_diff ( orig_owner_data , new_owner_data ) if len ( params_diff ) > 0 : params_diff [ ...
def get_term_by_name ( self , name ) : """Get the GO term with the given GO term name . If the given name is not associated with any GO term , the function will search for it among synonyms . Parameters name : str The name of the GO term . Returns ` GOTerm ` The GO term with the given name . Raise...
term = None try : term = self . terms [ self . name2id [ name ] ] except KeyError : try : term = self . terms [ self . syn2id [ name ] ] except KeyError : pass else : logger . info ( 'GO term name "%s" is a synonym for "%s".' , name , term . name ) if term is None : raise Val...
def insert ( collection_name , docs , check_keys , safe , last_error_args ) : """Get an * * insert * * message ."""
data = __ZERO data += bson . _make_c_string ( collection_name ) bson_data = "" . join ( [ bson . BSON . encode ( doc , check_keys ) for doc in docs ] ) if not bson_data : raise InvalidOperation ( "cannot do an empty bulk insert" ) data += bson_data if safe : ( _ , insert_message ) = __pack_message ( 2002 , data...