signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def profit_construct ( self ) : """利润构成 Returns : dict - - 利润构成表"""
return { 'total_buyandsell' : round ( self . profit_money - self . total_commission - self . total_tax , 2 ) , 'total_tax' : self . total_tax , 'total_commission' : self . total_commission , 'total_profit' : self . profit_money }
def register_factory ( self , specification , factory , scope = None ) : """Shortcut for creating and registering a : py : class : ` wiring . providers . FactoryProvider ` ."""
self . register_provider ( specification , FactoryProvider ( factory , scope = scope ) )
def remove ( self , item ) : """Transactional implementation of : func : ` List . remove ( item ) < hazelcast . proxy . list . List . remove > ` : param item : ( object ) , the specified item to be removed . : return : ( bool ) , ` ` true ` ` if the item is removed successfully , ` ` false ` ` otherwise ."""
check_not_none ( item , "item can't be none" ) return self . _encode_invoke ( transactional_list_remove_codec , item = self . _to_data ( item ) )
def view_aterator ( connection , callback , view , view_keys = dict ( ) , args = tuple ( ) , kwargs = dict ( ) , per_page = 15 , consume_errors = True ) : '''Asynchronous iterator for the view . Downloads a view in pages and calls the callback for each row . This helps avoid transfering data in huge datachunks ...
skip = 0 while True : keys = dict ( view_keys ) keys . update ( dict ( skip = skip , limit = per_page ) ) records = yield connection . query_view ( view , ** keys ) log . debug ( 'view_aterator' , "Fetched %d records of the view: %s" , len ( records ) , view . name ) skip += len ( records ) for ...
def authenticate ( self , user , password ) : """Authenticate user ."""
assert user [ 'password_hash' ] == '_' . join ( ( password , 'hash' ) ) self . logger . debug ( 'User %s has been successfully authenticated' , user [ 'uid' ] )
def requests ( self , code = None , ** kwargs ) : """Retrieve open requests . You can also enter a specific service code argument . > > > Three ( ' api . city . gov ' ) . requests ( ) { ' all ' : { ' requests ' : ' data ' } } > > > Three ( ' api . city . gov ' ) . requests ( ' 123 ' ) { ' 123 ' : { ' requ...
if code : kwargs [ 'service_code' ] = code data = self . get ( 'requests' , ** kwargs ) return data
def cumulative_value ( self , slip , mmax , mag_value , bbar , dbar , beta ) : '''Returns the rate of events with M > mag _ value : param float slip : Slip rate in mm / yr : param float mmax : Maximum magnitude : param float mag _ value : Magnitude value : param float bbar : \b ar { b } parameter ( ...
delta_m = ( mmax - mag_value ) a_1 = self . _get_a1_value ( bbar , dbar , slip / 10. , beta , mmax ) return a_1 * np . exp ( bbar * delta_m ) * ( delta_m > 0.0 )
def _is_finished_dumping_checkpoint ( directory ) : """Recent versions of RTA ( 1.10 or better ) , write the complete file . This is the most straightforward source but as of 1.10 still does not work correctly as the file will be created at the end of Read 1 even if there are multiple reads ."""
check_file = os . path . join ( directory , "Basecalling_Netcopy_complete.txt" ) check_v1 , check_v2 = ( 1 , 10 ) if os . path . exists ( check_file ) : with open ( check_file ) as in_handle : line = in_handle . readline ( ) . strip ( ) if line : version = line . split ( ) [ - 1 ] v1 , v...
def tco_return_handle ( tokens ) : """Process tail - call - optimizable return statements ."""
internal_assert ( len ( tokens ) == 2 , "invalid tail-call-optimizable return statement tokens" , tokens ) if tokens [ 1 ] . startswith ( "()" ) : return "return _coconut_tail_call(" + tokens [ 0 ] + ")" + tokens [ 1 ] [ 2 : ] # tokens [ 1 ] contains \ n else : return "return _coconut_tail_call(" + tokens [...
def getEmpTraitCorrCoef ( self ) : """Returns the empirical trait correlation matrix"""
cov = self . getEmpTraitCovar ( ) stds = SP . sqrt ( cov . diagonal ( ) ) [ : , SP . newaxis ] RV = cov / stds / stds . T return RV
def sec_to_public_pair ( sec , generator = None , strict = True ) : """Convert a public key in sec binary format to a public pair ."""
byte_count = ( generator . p ( ) . bit_length ( ) + 7 ) >> 3 if generator else ( len ( sec ) - 1 ) x = from_bytes_32 ( sec [ 1 : 1 + byte_count ] ) sec0 = sec [ : 1 ] if len ( sec ) == 1 + byte_count * 2 : isok = sec0 == b'\4' if not strict : isok = isok or ( sec0 in [ b'\6' , b'\7' ] ) if isok : ...
def filter_images_urls ( image_urls , image_filter , common_image_filter = None ) : '''图片链接过滤器 , 根据传入的过滤器规则 , 对图片链接列表进行过滤并返回结果列表 : param list ( str ) image _ urls : 图片链接字串列表 : param list ( str ) image _ filter : 过滤器字串列表 : param list ( str ) common _ image _ filter : 可选 , 通用的基础过滤器 , 会在定制过滤器前对传入图片应用 : retur...
common_image_filter = common_image_filter or [ ] # 对图片过滤器进行完整性验证 image_filter = json . loads ( image_filter , encoding = 'utf-8' ) if not isinstance ( image_filter , ( str , list ) ) : raise TypeError ( 'image_filter not str or list' ) if isinstance ( image_filter , str ) : image_filter = [ image_filter ] if no...
def build_acl_port ( self , port , enabled = True ) : "Build the acl for L4 Ports ."
if port is not None : if ':' in port : range = port . replace ( ':' , ' ' ) acl = "range %(range)s " % { 'range' : range } else : acl = "eq %(port)s " % { 'port' : port } if not enabled : acl += "inactive" return acl
def get ( self , request , slug ) : """Basic functionality for GET request to view ."""
matching_datasets = self . generate_matching_datasets ( slug ) if matching_datasets is None : raise Http404 ( "Datasets meeting these criteria do not exist." ) base_context = { 'datasets' : matching_datasets , 'num_datasets' : matching_datasets . count ( ) , 'page_title' : self . generate_page_title ( slug ) , } ad...
def _setup_exercise ( game_interface : GameInterface , ex : Exercise , seed : int ) -> Optional [ Result ] : """Set the game state . Only returns a result if there was an error in ex . setup ( )"""
rng = random . Random ( ) rng . seed ( seed ) try : game_state = ex . setup ( rng ) except Exception as e : return Result ( ex , seed , FailDueToExerciseException ( e , traceback . format_exc ( ) ) ) game_interface . set_game_state ( game_state )
def to_cmd_args ( mapping ) : # type : ( dict ) - > list """Transform a dictionary in a list of cmd arguments . Example : > > > args = mapping . to _ cmd _ args ( { ' model _ dir ' : ' / opt / ml / model ' , ' batch _ size ' : 25 } ) > > > print ( args ) [ ' - - model _ dir ' , ' / opt / ml / model ' , ' - ...
sorted_keys = sorted ( mapping . keys ( ) ) def arg_name ( obj ) : string = _decode ( obj ) if string : return u'--%s' % string if len ( string ) > 1 else u'-%s' % string else : return u'' arg_names = [ arg_name ( argument ) for argument in sorted_keys ] def arg_value ( value ) : if hasa...
def json ( self ) : """Get the result of simplejson . loads if possible ."""
if 'json' not in self . environ . get ( 'CONTENT_TYPE' , '' ) : raise BadRequest ( 'Not a JSON request' ) try : return loads ( self . data ) except Exception : raise BadRequest ( 'Unable to read JSON request' )
def agents ( ) : """Lists the currently active agents"""
print 'The following LiveSync agents are active:' agent_list = LiveSyncAgent . find ( ) . order_by ( LiveSyncAgent . backend_name , db . func . lower ( LiveSyncAgent . name ) ) . all ( ) table_data = [ [ 'ID' , 'Name' , 'Backend' , 'Initial Export' , 'Queue' ] ] for agent in agent_list : initial = ( cformat ( '%{gr...
def update ( self , id , * args , ** kwargs ) : """Update a source Updates source information If the specified source does not exist , the request will return an error < figure class = " notice " > If you want to update a source , you * * must * * make sure source ' s name is unique < / figure > : calls...
if not args and not kwargs : raise Exception ( 'attributes for DealSource are missing' ) attributes = args [ 0 ] if args else kwargs attributes = dict ( ( k , v ) for k , v in attributes . iteritems ( ) if k in self . OPTS_KEYS_TO_PERSIST ) _ , _ , deal_source = self . http_client . put ( "/deal_sources/{id}" . for...
def fcd2dri ( inpFCD , outSTRM , ignored ) : """Reformats the contents of the given fcd - output file into a . dri file , readable by PHEM . The fcd - output " fcd " must be a valid file name of an fcd - output . The following may be a matter of changes : - the engine torque is not given"""
# print > > outSTRM , " v1 \ n < t > , < v > , < grad > , < n > \ n [ s ] , [ km / h ] , [ % ] , [ 1 / min ] \ n " print ( "v1\n<t>,<v>,<grad>\n[s],[km/h],[%]" , file = outSTRM ) for q in inpFCD : if q . vehicle : for v in q . vehicle : percSlope = math . sin ( float ( v . slope ) ) * 100. ...
def setReferenceVoltage ( self , caldb , calv ) : """Sets the reference point to determine what outgoing voltage will produce what intensity , used to calculate the proper output amplitude of components : param caldb : calibration intensity in dbSPL : type caldb : float : param calv : calibration voltage th...
self . caldb = caldb self . calv = calv
def add_watcher ( self , fd , callback ) : """Starts watching a non - blocking fd for data ."""
if not isinstance ( fd , int ) : fd = fd . fileno ( ) self . callbacks [ fd ] = callback self . epoll . register ( fd , EPOLLIN )
def python ( source ) : r"""> > > python ( ' def add ( a , b ) : return a + b ' ) . add ( 40 , 2) 42"""
obj = type ( '' , ( object , ) , { } ) ( ) _exec ( source , obj . __dict__ , obj . __dict__ ) return obj
def match_set ( self , tokens , item ) : """Matches a set ."""
match , = tokens self . add_check ( "_coconut.isinstance(" + item + ", _coconut.abc.Set)" ) self . add_check ( "_coconut.len(" + item + ") == " + str ( len ( match ) ) ) for const in match : self . add_check ( const + " in " + item )
def print_hits ( results ) : "Simple utility function to print results of a search query ."
print_search_stats ( results ) for hit in results [ 'hits' ] [ 'hits' ] : # get created date for a repo and fallback to authored _ date for a commit created_at = parse_date ( hit [ '_source' ] . get ( 'created_at' , hit [ '_source' ] [ 'authored_date' ] ) ) print ( '/%s/%s/%s (%s): %s' % ( hit [ '_index' ] , hi...
def profiling_request_formatter ( view , context , model , name ) : """Wrap HTTP method value in a bs3 label ."""
document = model [ name ] return Markup ( '' . join ( [ '<p class="profiling-request">' , '<a href="{}">' . format ( document . get_admin_url ( _external = True ) ) , http_method_formatter ( view , context , document , 'method' ) , '&nbsp;' , document . path , '</a>' , '</p>' , ] ) )
def configure ( ) : """Load logging configuration from our own defaults ."""
log_levels = { 5 : logging . NOTSET , 4 : logging . DEBUG , 3 : logging . INFO , 2 : logging . WARNING , 1 : logging . ERROR , 0 : logging . CRITICAL } logging . captureWarnings ( True ) root_logger = logging . getLogger ( ) if settings . CFG [ "debug" ] : details_format = logging . Formatter ( '%(name)s (%(filenam...
def clean_readme ( fname ) : """Cleanup README . rst for proper PyPI formatting ."""
with codecs . open ( fname , 'r' , 'utf-8' ) as f : return '' . join ( re . sub ( r':\w+:`([^`]+?)( <[^<>]+>)?`' , r'``\1``' , line ) for line in f if not ( line . startswith ( '.. currentmodule' ) or line . startswith ( '.. toctree' ) ) )
def get_task_output_description ( task_output ) : '''Returns a task ' s output as a string'''
output_description = "n/a" if isinstance ( task_output , RemoteTarget ) : output_description = "[SSH] {0}:{1}" . format ( task_output . _fs . remote_context . host , task_output . path ) elif isinstance ( task_output , S3Target ) : output_description = "[S3] {0}" . format ( task_output . path ) elif isinstance ...
def indx ( self , norm ) : '''Return the property index bytes for the given * normalized * value .'''
name = self . __class__ . __name__ raise s_exc . NoSuchImpl ( name = '%s.indx' % name )
def fresh_transaction ( self , name = None ) : """On entrance to this context manager , hold an exclusive lock and create a fresh transaction for redshift , then commit and begin a new one before releasing the lock on exit . See drop _ relation in RedshiftAdapter for more information . : param Optional [ st...
with drop_lock : connection = self . get_thread_connection ( ) if connection . transaction_open : self . commit ( ) self . begin ( ) yield self . commit ( ) self . begin ( )
def get_bb_intersections ( recording ) : """Get all intersections of the bounding boxes of strokes . Parameters recording : list of lists of integers Returns A symmetrical matrix which indicates if two bounding boxes intersect ."""
intersections = numpy . zeros ( ( len ( recording ) , len ( recording ) ) , dtype = bool ) for i in range ( len ( recording ) - 1 ) : a = geometry . get_bounding_box ( recording [ i ] ) . grow ( 0.2 ) for j in range ( i + 1 , len ( recording ) ) : b = geometry . get_bounding_box ( recording [ j ] ) . gr...
def get_compositions_by_search ( self , composition_query , composition_search ) : """Gets the search results matching the given search query using the given search . arg : composition _ query ( osid . repository . CompositionQuery ) : the composition query arg : composition _ search ( osid . repository . Com...
# Implemented from template for # osid . resource . ResourceSearchSession . get _ resources _ by _ search _ template # Copied from osid . resource . ResourceQuerySession . get _ resources _ by _ query _ template and_list = list ( ) or_list = list ( ) for term in composition_query . _query_terms : and_list . append ...
def get_network ( self ) : """Identify the connected network . This call returns a dictionary with keys chain _ id , core _ symbol and prefix"""
props = self . get_chain_properties ( ) chain_id = props [ "chain_id" ] for k , v in known_chains . items ( ) : if v [ "chain_id" ] == chain_id : return v raise Exception ( "Connecting to unknown network!" )
def fill_missing ( self ) : """We do not want TLSServerKeyExchange . build ( ) to overload and recompute things every time it is called . This method can be called specifically to have things filled in a smart fashion . XXX We should account for the point _ format ( before ' point ' filling ) ."""
s = self . tls_session if self . curve_type is None : self . curve_type = _tls_ec_curve_types [ "named_curve" ] if self . named_curve is None : curve = ec . SECP256R1 ( ) s . server_kx_privkey = ec . generate_private_key ( curve , default_backend ( ) ) self . named_curve = next ( ( cid for cid , name in...
def p_if_statement_delay ( self , p ) : 'if _ statement : delays IF LPAREN cond RPAREN true _ statement ELSE else _ statement'
p [ 0 ] = IfStatement ( p [ 4 ] , p [ 6 ] , p [ 8 ] , lineno = p . lineno ( 2 ) ) p . set_lineno ( 0 , p . lineno ( 2 ) )
def create_account_user ( self , account_id , body , ** kwargs ) : # noqa : E501 """Create a new user . # noqa : E501 An endpoint for creating or inviting a new user to the account . In case of invitation email address is used only , other attributes are set in the 2nd step . * * Example usage : * * ` curl - X PO...
kwargs [ '_return_http_data_only' ] = True if kwargs . get ( 'asynchronous' ) : return self . create_account_user_with_http_info ( account_id , body , ** kwargs ) # noqa : E501 else : ( data ) = self . create_account_user_with_http_info ( account_id , body , ** kwargs ) # noqa : E501 return data
def filterVerticalLines ( arr , min_line_length = 4 ) : """Remove vertical lines in boolean array if linelength > = min _ line _ length"""
gy = arr . shape [ 0 ] gx = arr . shape [ 1 ] mn = min_line_length - 1 for i in range ( gy ) : for j in range ( gx ) : if arr [ i , j ] : for d in range ( min_line_length ) : if not arr [ i + d , j ] : break if d == mn : d = 0 ...
def findfile ( self , old , new ) : """return name of file to be patched or None"""
if exists ( old ) : return old elif exists ( new ) : return new else : # [ w ] Google Code generates broken patches with its online editor debug ( "broken patch from Google Code, stripping prefixes.." ) if old . startswith ( b'a/' ) and new . startswith ( b'b/' ) : old , new = old [ 2 : ] , new ...
def change_access_key ( self ) : """Change access key of your account ."""
method = 'POST' endpoint = '/rest/v1/users/{}/accesskey/change' . format ( self . client . sauce_username ) return self . client . request ( method , endpoint )
def DeregisterPathSpec ( cls , path_spec_type ) : """Deregisters a path specification . Args : path _ spec _ type ( type ) : path specification type . Raises : KeyError : if path specification is not registered ."""
type_indicator = path_spec_type . TYPE_INDICATOR if type_indicator not in cls . _path_spec_types : raise KeyError ( 'Path specification type: {0:s} not set.' . format ( type_indicator ) ) del cls . _path_spec_types [ type_indicator ] if type_indicator in cls . _system_level_type_indicators : del cls . _system_l...
def main ( args ) : """Main function which runs master ."""
if args . blacklisted_submissions : logging . warning ( 'BLACKLISTED SUBMISSIONS: %s' , args . blacklisted_submissions ) if args . limited_dataset : logging . info ( 'Using limited dataset: 3 batches * 10 images' ) max_dataset_num_images = 30 batch_size = 10 else : logging . info ( 'Using full datas...
def summarize ( logger ) : """Creates a short summary on the actions that were logged by the given Logger . : type logger : Logger : param logger : The logger that recorded what happened in the queue . : rtype : string : return : A string summarizing the status of every performed task ."""
summary = [ ] for log in logger . get_logs ( ) : thestatus = log . has_error ( ) and log . get_error ( False ) or 'ok' name = log . get_name ( ) summary . append ( name + ': ' + thestatus ) return '\n' . join ( summary )
def random_name ( num_surnames = 2 ) : """Returns a random person name Arguments : num _ surnames - - number of surnames"""
a = [ ] # Prefix if random . random ( ) < _PROB_PREF : a . append ( _prefixes [ random . randint ( 0 , len ( _prefixes ) - 1 ) ] ) # Forename a . append ( _forenames [ random . randint ( 0 , len ( _forenames ) - 1 ) ] ) # Surnames for i in range ( num_surnames ) : a . append ( _surnames [ random . randint ( 0 ,...
def get_requirement_files ( args = None ) : """Get the " best " requirements file we can find"""
if args and args . input_filename : return [ args . input_filename ] paths = [ ] for regex in settings . REQUIREMENTS_SOURCE_GLOBS : paths . extend ( glob . glob ( regex ) ) return paths
def make_m_psd ( self , original_nu , feed_dictionary ) : """Run binary search to find a value for nu that makes M PSD Args : original _ nu : starting value of nu to do binary search on feed _ dictionary : dictionary of updated lambda variables to feed into M Returns : new _ nu : new value of nu"""
feed_dict = feed_dictionary . copy ( ) _ , min_eig_val_m = self . get_lanczos_eig ( compute_m = True , feed_dict = feed_dict ) lower_nu = original_nu upper_nu = original_nu num_iter = 0 # Find an upper bound on nu while min_eig_val_m - TOL < 0 and num_iter < ( MAX_BINARY_SEARCH_ITER / 2 ) : num_iter += 1 upper_...
def scan_dir ( dirname , tags = None , md5_hash = False ) : '''scans a directory tree and returns a dictionary with files and key DICOM tags return value is a dictionary absolute filenames as keys and with dictionaries of tags / values as values the param ` ` tags ` ` is the list of DICOM tags ( given as tupl...
if tags == None : tags = [ ( 0x0008 , 0x0021 ) , ( 0x0008 , 0x0031 ) , ( 0x0008 , 0x103E ) , ( 0x0008 , 0x0080 ) , ( 0x0010 , 0x0020 ) , ( 0x0028 , 0x0010 ) , ( 0x0028 , 0x0011 ) , ] return_dict = { } for root , dirs , files in os . walk ( dirname ) : for filename in files : fullname = os . path . join ...
def RunOnce ( self , names = None , token = None ) : """Tries to lock and run cron jobs . Args : names : List of cron jobs to run . If unset , run them all . token : security token . Raises : OneOrMoreCronJobsFailedError : if one or more individual cron jobs fail . Note : a failure of a single cron job ...
del token leased_jobs = data_store . REL_DB . LeaseCronJobs ( cronjob_ids = names , lease_time = rdfvalue . Duration ( "10m" ) ) logging . info ( "Leased %d cron jobs for processing." , len ( leased_jobs ) ) if not leased_jobs : return errors = { } processed_count = 0 for job in sorted ( leased_jobs , key = lambda ...
def _read_single ( parser , filepath ) : """Reads a single config file into the parser , silently failing if the file does not exist . Args : parser ( ConfigParser ) : parser to read the file into . filepath ( str ) : full path to the config file ."""
from os import path global packages if path . isfile ( filepath ) : parser . readfp ( open ( filepath ) )
def filter ( self , ** kwargs ) : """Filter the base queryset ."""
assert not self . _primary_keys self . queryset = self . queryset . filter ( ** kwargs ) return self
def randomreads ( reference , length , reads , out_fastq , paired = False , returncmd = False , ** kwargs ) : """Wrapper for bbmap . Assumes that bbmap executable is in your $ PATH . : param reference : Reference fasta . Won ' t be written to disk by default . If you want it to be , add nodisk = ' t ' as an arg ....
options = kwargs_to_string ( kwargs ) # If the paired option is selected , set the name of the reverse reads to be the same as the forward reads # but replace _ R1 with _ R2 if paired : out_fastq2 = out_fastq . replace ( '_R1' , '_R2' ) # Create the call to randomreads - use paired = t cmd = 'randomreads.sh...
def _setable_get_ ( name , self ) : "Used to raise an exception for attributes unable to be evaluated yet ."
raise AttributeError ( "'{typename}' object has no attribute '{name}'" . format ( typename = type ( self ) . __name__ , name = name ) )
def derivative ( self , t , n = 1 ) : """returns the nth derivative of the segment at t . Note : Bezier curves can have points where their derivative vanishes . If you are interested in the tangent direction , use the unit _ tangent ( ) method instead ."""
p = self . bpoints ( ) if n == 1 : return 3 * ( p [ 1 ] - p [ 0 ] ) * ( 1 - t ) ** 2 + 6 * ( p [ 2 ] - p [ 1 ] ) * ( 1 - t ) * t + 3 * ( p [ 3 ] - p [ 2 ] ) * t ** 2 elif n == 2 : return 6 * ( ( 1 - t ) * ( p [ 2 ] - 2 * p [ 1 ] + p [ 0 ] ) + t * ( p [ 3 ] - 2 * p [ 2 ] + p [ 1 ] ) ) elif n == 3 : return 6 ...
def authors ( self ) : """List of : class : ` ~ zenodio . harvest . Author ` \ s ( : class : ` zenodio . harvest . Author ` ) . Authors correspond to ` creators ` in the Datacite schema ."""
creators = _pluralize ( self . _r [ 'creators' ] , 'creator' ) authors = [ Author . from_xmldict ( c ) for c in creators ] return authors
def exists ( self , symbol ) : """Checks to if a symbol exists , by name . Parameters symbol : str or Symbol Returns bool"""
if isinstance ( symbol , str ) : sym = symbol elif isinstance ( symbol , Symbol ) : sym = symbol . name syms = self . ses . query ( Symbol ) . filter ( Symbol . name == sym ) . all ( ) if len ( syms ) == 0 : return False else : return True
def wait ( self , timeout = None ) : # type : ( Optional [ int ] ) - > None """Wait on the long running operation for a specified length of time . You can check if this call as ended with timeout with the " done ( ) " method . : param int timeout : Period of time to wait for the long running operation to co...
if self . _thread is None : return self . _thread . join ( timeout = timeout ) try : # Let ' s handle possible None in forgiveness here raise self . _exception # type : ignore except TypeError : # Was None pass
def update_annotation_version ( xml_file ) : """Update the fields that have changed over different versions . Parameters xml _ file : path to file xml file with the sleep scoring Notes new in version 4 : use ' marker _ name ' instead of simply ' name ' etc new in version 5 : use ' bookmark ' instead of ...
with open ( xml_file , 'r' ) as f : s = f . read ( ) m = search ( '<annotations version="([0-9]*)">' , s ) current = int ( m . groups ( ) [ 0 ] ) if current < 4 : s = sub ( '<marker><name>(.*?)</name><time>(.*?)</time></marker>' , '<marker><marker_name>\g<1></marker_name><marker_start>\g<2></marker_start><marke...
def remove_all ( self ) : """Remove all actions ."""
names = sorted ( self . _actions_dict . keys ( ) ) for name in names : self . remove ( name )
def symbol_search ( self , search_terms ) : """Search for symbols matching a set of keywords"""
self . log . debug ( 'symbol_search: in' ) if not search_terms : self . editor . message ( 'symbol_search_symbol_required' ) return req = { "typehint" : "PublicSymbolSearchReq" , "keywords" : search_terms , "maxResults" : 25 } self . send_request ( req )
def cli ( env , identifier ) : """List server credentials ."""
manager = SoftLayer . HardwareManager ( env . client ) hardware_id = helpers . resolve_id ( manager . resolve_ids , identifier , 'hardware' ) instance = manager . get_hardware ( hardware_id ) table = formatting . Table ( [ 'username' , 'password' ] ) for item in instance [ 'softwareComponents' ] : if 'passwords' no...
def yyparse ( self , cfgfile , splitstring = 0 ) : """Args : cfgfile ( str ) : The path for the file containing the CFG rules splitstring ( bool ) : A boolean for enabling or disabling the splitting of symbols using a space Returns : PDA : The generated PDA"""
re_grammar = self . _read_file ( cfgfile ) mma = self . _mpda ( re_grammar , splitstring ) return mma
def create_calendar_resource ( self , name , password = None , attrs = { } ) : """: param : attrs a dict of attributes , must specify the displayName and zimbraCalResType"""
args = { 'name' : name , 'a' : [ { 'n' : k , '_content' : v } for k , v in attrs . items ( ) ] } if password : args [ 'password' ] = password resp = self . request_single ( 'CreateCalendarResource' , args ) return zobjects . CalendarResource . from_dict ( resp )
def get_next_index ( self , matrix , manipulation , indices_left ) : """Returns an index that should have the most negative effect on the matrix sum"""
f = manipulation [ 0 ] indices = list ( indices_left . intersection ( manipulation [ 2 ] ) ) sums = np . sum ( matrix [ indices ] , axis = 1 ) if f < 1 : next_index = indices [ sums . argmax ( axis = 0 ) ] else : next_index = indices [ sums . argmin ( axis = 0 ) ] return next_index
def cortex_to_image_interpolation ( obj , mask = None , affine = None , method = 'linear' , shape = None ) : '''cortex _ to _ image _ interpolation ( obj ) yields a tuple ( indices , interp ) where indices is a tuple of voxel indices and interp is an interpolation matrix that converts a vector of cortical surfa...
# get the min / max values of the coordinates ( for deducing sizes , if necessary ) if mask is None : if shape is None and affine is None : # we have no way to deduce anything shape = ( 256 , 256 , 256 ) affine = ( [ [ - 1 , 0 , 0 ] , [ 0 , 0 , - 1 ] , [ 0 , 1 , 0 ] ] , [ 128 , 128 , 128 ] ) eli...
def stream_filesystem_node ( path , recursive = False , patterns = '**' , chunk_size = default_chunk_size ) : """Gets a buffered generator for streaming either files or directories . Returns a buffered generator which encodes the file or directory at the given path as : mimetype : ` multipart / form - data ` wi...
is_dir = isinstance ( path , six . string_types ) and os . path . isdir ( path ) if recursive or is_dir : return stream_directory ( path , recursive , patterns , chunk_size ) else : return stream_files ( path , chunk_size )
def convert ( amount , source , target = 'CZK' , date = None , percent = 0 , valid_days_max = None ) : """without target parameter returns equivalent of amount + source in CZK with target parameter returns equivalent of amount + source in given currency you can calculate with regard to ( given ) date you can ...
if source . upper ( ) == 'CZK' : czk = amount else : czk = amount * rate ( source , date , valid_days_max = valid_days_max ) result = convert_to ( target , czk , date , valid_days_max = valid_days_max ) return modified ( result , percent )
def to_png ( self , transparent = True , thumbnail_size = None , resampling = None , in_range = 'dtype' , out_range = 'dtype' ) : """Convert to png format ( discarding geo ) . Optionally also resizes . Note : for color images returns interlaced . : param transparent : if True - sets alpha channel for nodata p...
return self . to_bytes ( transparent = transparent , thumbnail_size = thumbnail_size , resampling = resampling , in_range = in_range , out_range = out_range )
def lookup ( self , inc_raw = False , retry_count = 3 , response = None , get_referral = False , extra_blacklist = None , ignore_referral_errors = False , asn_data = None , field_list = None , is_offline = False ) : """The function for retrieving and parsing whois information for an IP address via port 43 / tcp (...
# Create the return dictionary . results = { 'query' : self . _net . address_str , 'nets' : [ ] , 'raw' : None , 'referral' : None , 'raw_referral' : None } # The referral server and port . Only used if get _ referral is True . referral_server = None referral_port = 0 # Only fetch the response if we haven ' t already ....
def send ( self , request , stream = False , timeout = None , verify = True , cert = None , proxies = None ) : """Sends PreparedRequest object . Returns Response object . : param request : The : class : ` PreparedRequest < PreparedRequest > ` being sent . : param stream : ( optional ) Whether to stream the requ...
conn = self . get_connection ( request . url , proxies ) self . cert_verify ( conn , request . url , verify , cert ) url = self . request_url ( request , proxies ) self . add_headers ( request ) chunked = not ( request . body is None or 'Content-Length' in request . headers ) if isinstance ( timeout , tuple ) : try...
def delete_attachment ( self , attachment , headers = None ) : """Removes an attachment from a remote document and refreshes the locally cached document object . : param str attachment : Attachment file name used to identify the attachment . : param dict headers : Optional , additional headers to be sent ...
# need latest rev self . fetch ( ) attachment_url = '/' . join ( ( self . document_url , attachment ) ) if headers is None : headers = { 'If-Match' : self [ '_rev' ] } else : headers [ 'If-Match' ] = self [ '_rev' ] resp = self . r_session . delete ( attachment_url , headers = headers ) resp . raise_for_status ...
def ids_from_seq_two_step ( seq , n , max_iterations , app , core_threshold , extra_threshold , lower_threshold , second_db = None ) : """Returns ids that match a seq , using a 2 - tiered strategy . Optionally uses a second database for the second search ."""
# first time through : reset ' h ' and ' e ' to core # - h is the e - value threshold for including seqs in the score matrix model app . Parameters [ '-h' ] . on ( core_threshold ) # - e is the e - value threshold for the final blast app . Parameters [ '-e' ] . on ( core_threshold ) checkpoints = [ ] ids = [ ] last_num...
def assert_stmt ( self ) : '''Returns a string displaying the whole statement that failed , with a ' > ' indicator on the line starting the expression .'''
# This will be used by linecache to read the source of this # module . See the docstring for _ find _ assert _ stmt below which # explains how . # We don ' t have a test for this because automating the # creation of an egg , installation into an environment , # running of tests , and verification that marbles found the...
def convolve ( sequence , rule , ** kwds ) : """Wrapper around scipy . ndimage . convolve1d that allows complex input ."""
dtype = np . result_type ( float , np . ravel ( sequence ) [ 0 ] ) seq = np . asarray ( sequence , dtype = dtype ) if np . iscomplexobj ( seq ) : return ( convolve1d ( seq . real , rule , ** kwds ) + 1j * convolve1d ( seq . imag , rule , ** kwds ) ) return convolve1d ( seq , rule , ** kwds )
def process_question ( self ) : """Parse specific fields in ` self . raw _ data ` that needs to have image strings processed : repalced by references to ` CONTENTSTORAGE ` + added as files . Returns : list of all files needed to render this question ."""
image_files = [ ] question_data = json . loads ( self . raw_data ) # process urls for widgets self . _recursive_url_find ( question_data , image_files ) # Process question if 'question' in question_data and 'images' in question_data [ 'question' ] : question_data [ 'question' ] [ 'images' ] , qfiles = self . proces...
def delete_question_answer ( self , number : str ) -> bool : """刪除特定題目的作業"""
try : # 操作所需資訊 params = { 'title' : number } # 刪除作業 response = self . __session . get ( self . __url + '/delHw' , params = params , timeout = 0.5 , verify = False ) soup = BeautifulSoup ( response . text , 'html.parser' ) # 回傳結果 return soup . find ( 'body' ) . get_text ( ) . replace ( '\n' , '' ...
def _pred_sets_are_in_conflict ( pred_set_a , pred_set_b ) : """Find conflict in sets , return conflict if found , else None ."""
# pred _ sets conflict if we cannot find one shared predicate that is " negated " in one # and " non - negated " in the other for pred_a , bool_a in pred_set_a : for pred_b , bool_b in pred_set_b : if pred_a is pred_b and bool_a != bool_b : return False return True
def get_global_achievement_percentages_for_app ( self , gameID , format = None ) : """Request statistics showing global achievements that have been unlocked . gameID : The id of the game . format : Return format . None defaults to json . ( json , xml , vdf )"""
parameters = { 'gameid' : gameID } if format is not None : parameters [ 'format' ] = format url = self . create_request_url ( self . interface , 'GetGlobalAchievementPercentagesForApp' , 2 , parameters ) data = self . retrieve_request ( url ) return self . return_data ( data , format = format )
def get_field_template ( self , bound_field , template_name = None ) : """Uses a special field template for widget with multiple inputs . It only applies if no other template than the default one has been defined ."""
template_name = super ( ) . get_field_template ( bound_field , template_name ) if ( template_name == self . field_template and isinstance ( bound_field . field . widget , ( forms . RadioSelect , forms . CheckboxSelectMultiple ) ) ) : return 'tapeforms/fields/foundation_fieldset.html' return template_name
def flags ( self , index ) : """Returns the item flags for the given index as ored value , e . x . : Qt . ItemIsUserCheckable | Qt . ItemIsEditable Args : index ( QtCore . QModelIndex ) : Index to define column and row Returns : for column ' column ' : Qt . ItemIsSelectable | Qt . ItemIsEnabled for column...
if not index . isValid ( ) : return Qt . NoItemFlags col = index . column ( ) flags = Qt . ItemIsEnabled | Qt . ItemIsSelectable if col > 0 and self . editable ( ) : flags = Qt . ItemIsSelectable | Qt . ItemIsEnabled | Qt . ItemIsEditable return flags
def listPrimaryDatasets ( self , primary_ds_name = "" , primary_ds_type = "" ) : """Returns all primary dataset if primary _ ds _ name or primary _ ds _ type are not passed ."""
conn = self . dbi . connection ( ) try : result = self . primdslist . execute ( conn , primary_ds_name , primary_ds_type ) if conn : conn . close ( ) return result finally : if conn : conn . close ( )
def saved_groups ( self ) : """Return True if saved group files exits , else False ."""
if self . _saved_groups is None : self . _saved_groups = False fqfn_saved = os . path . join ( self . tcex . args . tc_temp_path , 'groups-saved' ) if ( self . enable_saved_file and os . path . isfile ( fqfn_saved ) and os . access ( fqfn_saved , os . R_OK ) ) : self . _saved_groups = True s...
def get_column_info ( connection , table_name ) : """Return an in order list of ( name , type ) tuples describing the columns in the given table ."""
cursor = connection . cursor ( ) cursor . execute ( "SELECT sql FROM sqlite_master WHERE type == 'table' AND name == ?" , ( table_name , ) ) statement , = cursor . fetchone ( ) coldefs = re . match ( _sql_create_table_pattern , statement ) . groupdict ( ) [ "coldefs" ] return [ ( coldef . groupdict ( ) [ "name" ] , col...
def model_schema ( model : Type [ 'main.BaseModel' ] , by_alias : bool = True , ref_prefix : Optional [ str ] = None ) -> Dict [ str , Any ] : """Generate a JSON Schema for one model . With all the sub - models defined in the ` ` definitions ` ` top - level JSON key . : param model : a Pydantic model ( a class ...
ref_prefix = ref_prefix or default_prefix flat_models = get_flat_models_from_model ( model ) model_name_map = get_model_name_map ( flat_models ) m_schema , m_definitions = model_process_schema ( model , by_alias = by_alias , model_name_map = model_name_map , ref_prefix = ref_prefix ) if m_definitions : m_schema . u...
def read_band ( self , key , info ) : """Read the data ."""
shape = int ( np . ceil ( self . mda [ 'data_field_length' ] / 8. ) ) if self . mda [ 'number_of_bits_per_pixel' ] == 16 : dtype = '>u2' shape //= 2 elif self . mda [ 'number_of_bits_per_pixel' ] in [ 8 , 10 ] : dtype = np . uint8 shape = ( shape , ) data = np . memmap ( self . filename , mode = 'r' , offse...
def _queue_manangement_worker ( executor_reference , processes , pending_work_items , work_ids_queue , call_queue , result_queue , shutdown_process_event ) : """Manages the communication between this process and the worker processes . This function is run in a local thread . Args : executor _ reference : A we...
while True : _add_call_item_to_queue ( pending_work_items , work_ids_queue , call_queue ) try : result_item = result_queue . get ( block = True , timeout = 0.1 ) except queue . Empty : executor = executor_reference ( ) # No more work items can be added if : # - The interprete...
def get_roster_file ( options ) : '''Find respective roster file . : param options : : return :'''
template = None # The _ _ disable _ custom _ roster is always True if Salt SSH Client comes # from Salt API . In that case no way to define own ' roster _ file ' , instead # this file needs to be chosen from already validated rosters # ( see / etc / salt / master config ) . if options . get ( '__disable_custom_roster' ...
def upgradePrivateApplication3to4 ( old ) : """Upgrade L { PrivateApplication } from schema version 3 to schema version 4. Copy all existing attributes to the new version and use the L { PrivateApplication } to power up the item it is installed on for L { ITemplateNameResolver } ."""
new = old . upgradeVersion ( PrivateApplication . typeName , 3 , 4 , preferredTheme = old . preferredTheme , privateKey = old . privateKey , website = old . website , customizedPublicPage = old . customizedPublicPage , authenticationApplication = old . authenticationApplication , preferenceAggregator = old . preference...
def projects ( self , task , params = { } , ** options ) : """Returns a compact representation of all of the projects the task is in . Parameters task : { Id } The task to get projects on . [ params ] : { Object } Parameters for the request"""
path = "/tasks/%s/projects" % ( task ) return self . client . get_collection ( path , params , ** options )
def ConsumeCommentOrTrailingComment ( self ) : """Consumes a comment , returns a 2 - tuple ( trailing bool , comment str ) ."""
# Tokenizer initializes _ previous _ line and _ previous _ column to 0 . As the # tokenizer starts , it looks like there is a previous token on the line . just_started = self . _line == 0 and self . _column == 0 before_parsing = self . _previous_line comment = self . ConsumeComment ( ) # A trailing comment is a comment...
def get_libraries ( ) : '''return a list of libraries to link against .'''
# Note that this list does not include libcsamtools . so as there are # numerous name conflicts with libchtslib . so . dirname = os . path . abspath ( os . path . join ( os . path . dirname ( __file__ ) ) ) pysam_libs = [ 'libctabixproxies' , 'libcfaidx' , 'libcsamfile' , 'libcvcf' , 'libcbcf' , 'libctabix' ] if pysam ...
def get_interface_detail_output_interface_ifHCOutMulticastPkts ( self , ** kwargs ) : """Auto Generated Code"""
config = ET . Element ( "config" ) get_interface_detail = ET . Element ( "get_interface_detail" ) config = get_interface_detail output = ET . SubElement ( get_interface_detail , "output" ) interface = ET . SubElement ( output , "interface" ) interface_type_key = ET . SubElement ( interface , "interface-type" ) interfac...
def _move_mount ( robot , mount , point ) : """The carriage moves the mount in the Z axis , and the gantry moves in X and Y Mount movements do not have the same protections calculated in to an existing ` move ` command like Pipette does , so the safest thing is to home the Z axis , then move in X and Y , then...
carriage = robot . _actuators [ mount ] [ 'carriage' ] # Home both carriages , to prevent collisions and to ensure that the other # mount doesn ' t block the one being moved ( mount moves are primarily for # changing pipettes , so we don ' t want the other pipette blocking access ) robot . poses = carriage . home ( rob...
def fix_config ( self , options ) : """Fixes the options , if necessary . I . e . , it adds all required elements to the dictionary . : param options : the options to fix : type options : dict : return : the ( potentially ) fixed options : rtype : dict"""
options = super ( LinePlot , self ) . fix_config ( options ) opt = "attributes" if opt not in options : options [ opt ] = None if opt not in self . help : self . help [ opt ] = "The list of 0-based attribute indices to print; None for all (int)." opt = "percent" if opt not in options : options [ opt ] = 100...
def set_fixed_mask ( self , image ) : """Set Fixed ANTsImage Mask for metric"""
if not isinstance ( image , iio . ANTsImage ) : raise ValueError ( 'image must be ANTsImage type' ) if image . dimension != self . dimension : raise ValueError ( 'image dim (%i) does not match metric dim (%i)' % ( image . dimension , self . dimension ) ) self . _metric . setFixedImage ( image . pointer , True )...
def reverse ( self ) : """In place reverses the list . Very expensive on large data sets . The reversed list will be persisted to the redis : prop : _ client as well ."""
tmp_list = RedisList ( randint ( 0 , 100000000 ) , prefix = self . key_prefix , client = self . _client , serializer = self . serializer , serialized = self . serialized ) cursor = '0' count = 1000 start = ( - 1 * count ) stop = - 1 _loads = self . _loads while cursor : cursor = self . _client . lrange ( self . key...
def dump_uint_b_into ( n , width , buffer , offset = 0 ) : """Serializes fixed size integer to the buffer : param n : : param width : : return :"""
for idx in range ( width ) : buffer [ idx + offset ] = n & 0xff n >>= 8 return buffer
def assertStructIsInline ( self , obj ) : """Structs are always stored inline , so need to be created right where they are used . You ' ll get this error if you created it elsewhere ."""
N . enforce_number ( obj , N . UOffsetTFlags ) if obj != self . Offset ( ) : msg = ( "flatbuffers: Tried to write a Struct at an Offset that " "is different from the current Offset of the Builder." ) raise StructIsNotInlineError ( msg )
def swapon ( name , priority = None ) : '''Activate a swap disk . . versionchanged : : 2016.3.2 CLI Example : . . code - block : : bash salt ' * ' mount . swapon / root / swapfile'''
ret = { } on_ = swaps ( ) if name in on_ : ret [ 'stats' ] = on_ [ name ] ret [ 'new' ] = False return ret if __grains__ [ 'kernel' ] == 'SunOS' : if __grains__ [ 'virtual' ] != 'zone' : __salt__ [ 'cmd.run' ] ( 'swap -a {0}' . format ( name ) , python_shell = False ) else : return F...
def _decode_preferred_encoding ( s ) : """Decode the supplied byte string using the preferred encoding for the locale ( ` locale . getpreferredencoding ` ) or , if the default encoding is invalid , fall back first on utf - 8 , then on latin - 1 if the message cannot be decoded with utf - 8."""
enc = locale . getpreferredencoding ( ) try : try : return s . decode ( enc ) except LookupError : enc = _DEFAULT_ENCODING return s . decode ( enc ) except UnicodeDecodeError : return s . decode ( 'latin-1' )
def copy_file ( src , dest ) : """copy single file"""
try : shutil . copy2 ( src , dest ) except Exception as ex : print ( 'ERROR copying file' + str ( ex ) )