signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def getUncleByBlock ( self , block_identifier , uncle_index ) : """` eth _ getUncleByBlockHashAndIndex ` ` eth _ getUncleByBlockNumberAndIndex `"""
method = select_method_for_block_identifier ( block_identifier , if_predefined = 'eth_getUncleByBlockNumberAndIndex' , if_hash = 'eth_getUncleByBlockHashAndIndex' , if_number = 'eth_getUncleByBlockNumberAndIndex' , ) result = self . web3 . manager . request_blocking ( method , [ block_identifier , uncle_index ] , ) if ...
def job ( self , job_id ) : """A Job resource contains information about a particular job identified by jobid . : param str job _ id : The job id : returns : API response object with JSON data : rtype : : py : class : ` yarn _ api _ client . base . Response `"""
path = '/ws/v1/history/mapreduce/jobs/{jobid}' . format ( jobid = job_id ) return self . request ( path )
def remove ( self , iterable , data = None , index = 0 ) : """Remove an element from the trie Args iterable ( hashable ) : key used to find what is to be removed data ( object ) : data associated with the key index ( int ) : index of what is to me removed Returns : bool : True : if it was removed Fa...
if index == len ( iterable ) : if self . is_terminal : if data : self . data . remove ( data ) if len ( self . data ) == 0 : self . is_terminal = False else : self . data . clear ( ) self . is_terminal = False return True el...
async def post ( self , public_key , coinid ) : """Writes content to blockchain Accepts : Query string args : - " public _ key " - str - " coin id " - str Request body arguments : - message ( signed dict as json ) : - " cus " ( content ) - str - " description " - str - " read _ access " ( price fo...
logging . debug ( "[+] -- Post content debugging. " ) # if settings . SIGNATURE _ VERIFICATION : # super ( ) . verify ( ) # Define genesis variables if coinid in settings . bridges . keys ( ) : # Define bridge url owneraddr = self . account . validator [ coinid ] ( public_key ) # Define owner address loggin...
def updateFGDBfromSDE ( fgdb , sde , logger = None ) : global changes """fgdb : file geodatabase sde : sde geodatabase connection logger : agrc . logging . Logger ( optional ) returns : String [ ] - the list of errors Loops through the file geodatabase feature classes and looks for matches in the SDE ...
def log ( msg ) : if logger : logger . logMsg ( msg ) else : print msg def updateData ( isTable ) : try : # validate that there was not a schema change arcpy . env . workspace = fgdb layer = sdeFC + '_Layer' if not isTable : arcpy . MakeFeatureLayer_manage...
def default_ccache_dir ( ) -> str : """: return : ccache directory for the current platform"""
# Share ccache across containers if 'CCACHE_DIR' in os . environ : ccache_dir = os . path . realpath ( os . environ [ 'CCACHE_DIR' ] ) try : os . makedirs ( ccache_dir , exist_ok = True ) return ccache_dir except PermissionError : logging . info ( 'Unable to make dirs at %s, falling ...
def functions ( self , value ) : """Setter for * * self . _ _ functions * * attribute . : param value : Attribute value . : type value : tuple"""
if value is not None : assert type ( value ) is tuple , "'{0}' attribute: '{1}' type is not 'tuple'!" . format ( "functions" , value ) for element in value : assert type ( element ) is LibraryHook , "'{0}' attribute: '{1}' type is not 'LibraryHook'!" . format ( "functions" , element ) self . __functions...
def generate_common_reg_log_config ( json_value ) : """Generate common logtail config from loaded json value : param json _ value : : return :"""
input_detail = copy . deepcopy ( json_value [ 'inputDetail' ] ) output_detail = json_value [ 'outputDetail' ] logSample = json_value . get ( 'logSample' , '' ) config_name = json_value [ 'configName' ] logstore_name = output_detail [ 'logstoreName' ] endpoint = output_detail . get ( 'endpoint' , '' ) log_path = input_d...
async def _read_next ( self ) : """Read next row"""
row = await self . _result . _read_rowdata_packet_unbuffered ( ) row = self . _conv_row ( row ) return row
def add_point_feature ( self , resnum , feat_type = None , feat_id = None , qualifiers = None ) : """Add a feature to the features list describing a single residue . Args : resnum ( int ) : Protein sequence residue number feat _ type ( str , optional ) : Optional description of the feature type ( ie . ' catal...
if self . feature_file : raise ValueError ( 'Feature file associated with sequence, please remove file association to append ' 'additional features.' ) if not feat_type : feat_type = 'Manually added protein sequence single residue feature' newfeat = SeqFeature ( location = FeatureLocation ( ExactPosition ( resn...
def run ( self ) : """run the model"""
model = self . model configfile = self . configfile interval = self . interval sockets = self . sockets model . initialize ( configfile ) if model . state == 'pause' : logger . info ( "model initialized and started in pause mode, waiting for requests" ) else : logger . info ( "model started and initialized, run...
async def create_session ( self , ** kwargs ) : """Creates an : class : ` aiohttp . ClientSession ` Override this or call it with ` ` kwargs ` ` to use other : mod : ` aiohttp ` functionality not covered by : class : ` ~ . InfluxDBClient . _ _ init _ _ `"""
self . opts . update ( kwargs ) self . _session = aiohttp . ClientSession ( ** self . opts , loop = self . _loop ) if self . redis_opts : if aioredis : self . _redis = await aioredis . create_redis ( ** self . redis_opts , loop = self . _loop ) else : warnings . warn ( no_redis_warning )
def validate_files ( directory , files_to_merge ) : """Asserts that the given files exist . files _ to _ merge is a list of file names ( no directories ) . directory is the directory ( a path object from path . py ) in which the files should appear . raises an Exception if any of the files are not in dir ."""
for file_path in files_to_merge : pathname = directory . joinpath ( file_path ) if not pathname . exists ( ) : raise Exception ( "I18N: Cannot generate because file not found: {0}" . format ( pathname ) ) # clean sources clean_pofile ( pathname )
def iter_options ( self ) : """Iterates configuration sections groups options ."""
for section in self . sections : name = str ( section ) for key , value in section . _get_options ( ) : yield name , key , value
def peak_memory_usage ( ) : """Return peak memory usage in MB"""
if sys . platform . startswith ( 'win' ) : p = psutil . Process ( ) return p . memory_info ( ) . peak_wset / 1024 / 1024 mem = resource . getrusage ( resource . RUSAGE_SELF ) . ru_maxrss factor_mb = 1 / 1024 if sys . platform == 'darwin' : factor_mb = 1 / ( 1024 * 1024 ) return mem * factor_mb
def alt_parser ( patterns ) : """This parser is able to handle multiple different patterns finding stuff in text - - while removing matches that overlap ."""
from reparse . util import remove_lower_overlapping get_first = lambda items : [ i [ 0 ] for i in items ] get_second = lambda items : [ i [ 1 ] for i in items ] def parse ( line ) : output = [ ] for pattern in patterns : results = pattern . scan ( line ) if results and any ( results ) : ...
def as_requirement ( self ) : """Return a ` ` Requirement ` ` that matches this distribution exactly"""
if isinstance ( self . parsed_version , packaging . version . Version ) : spec = "%s==%s" % ( self . project_name , self . parsed_version ) else : spec = "%s===%s" % ( self . project_name , self . parsed_version ) return Requirement . parse ( spec )
def error ( self , s , pos ) : """Show text and a caret under that . For example : x = 2y + z"""
print ( "Lexical error:" ) print ( "%s" % s [ : pos + 10 ] ) # + 10 for trailing context print ( "%s^" % ( " " * ( pos - 1 ) ) ) for t in self . rv : print ( t ) raise SystemExit
def explore ( self ) : """INTERACTIVE exploration source capabilities . Will use sitemap URI taken either from explicit self . sitemap _ name or derived from the mappings supplied ."""
# Where do we start ? Build options in starts which has entries # that are a pair comprised of the uri and a list of acceptable # capabilities starts = [ ] if ( self . sitemap_name is not None ) : print ( "Starting from explicit --sitemap %s" % ( self . sitemap_name ) ) starts . append ( XResource ( self . site...
def outputs ( self ) : """List of layers containing outputs from the IF . : returns : A list of vector layers . : rtype : list"""
outputs = self . _outputs ( ) if len ( outputs ) != len ( self . _output_layer_expected ) : # This will never happen in production . # Travis will fail before . # If this happen , it ' s an error from InaSAFE core developers . raise Exception ( 'The computed count of output layers is wrong. It should be ' '{expecte...
def fmap ( self , f : Callable [ [ T ] , B ] ) -> 'List[B]' : """doufo . List . fmap : map ` List ` Args : ` self ` : ` f ` ( ` Callable [ [ T ] , B ] ` ) : any callable funtion Returns : return ( ` List [ B ] ` ) : A ` List ` of objected from ` f ` . Raises :"""
return List ( [ f ( x ) for x in self . unbox ( ) ] )
def connect ( self , ** kwargs ) : """Connect to Google Compute Engine ."""
try : self . gce = get_driver ( Provider . GCE ) ( self . user_id , self . key , project = self . project , ** kwargs ) except : raise ComputeEngineManagerException ( "Unable to connect to Google Compute Engine." )
def is_isolated ( self , p_id ) : """Returns True iff the given node has no incoming or outgoing edges ."""
return ( len ( self . incoming_neighbors ( p_id ) ) == 0 and len ( self . outgoing_neighbors ( p_id ) ) == 0 )
def p_poke2 ( p ) : """statement : POKE numbertype expr COMMA expr | POKE LP numbertype expr COMMA expr RP"""
i = 2 if isinstance ( p [ 2 ] , Symbol ) or p [ 2 ] is None else 3 if p [ i + 1 ] is None or p [ i + 3 ] is None : p [ 0 ] = None return p [ 0 ] = make_sentence ( 'POKE' , make_typecast ( TYPE . uinteger , p [ i + 1 ] , p . lineno ( i + 2 ) ) , make_typecast ( p [ i ] , p [ i + 3 ] , p . lineno ( i + 3 ) ) )
def _ref ( pname , conf = None , configurable = None , cname = None , path = None , history = 0 ) : """Resolve a parameter value . : param Configuration conf : configuration to use . : param str pname : parameter name . : param Configurable configurable : configurable . : param str cname : category name . ...
result = None if configurable is not None : kwargs = { } if conf is not None : kwargs [ 'conf' ] = conf if path is not None : kwargs [ 'paths' ] = path if conf is None : conf = configurable . getconf ( ** kwargs ) if conf is None : raise ParserError ( 'Wrong ref parameters. C...
def access ( path , mode ) : '''. . versionadded : : 2014.1.0 Test whether the Salt process has the specified access to the file . One of the following modes must be specified : . . code - block : : text f : Test the existence of the path r : Test the readability of the path w : Test the writability of ...
path = os . path . expanduser ( path ) if not os . path . isabs ( path ) : raise SaltInvocationError ( 'Path to link must be absolute.' ) modes = { 'f' : os . F_OK , 'r' : os . R_OK , 'w' : os . W_OK , 'x' : os . X_OK } if mode in modes : return os . access ( path , modes [ mode ] ) elif mode in six . itervalue...
def add_view ( self , request , form_url = '' , extra_context = None ) : """The ` ` add ` ` admin view for the : class : ` Page < pages . models . Page > ` ."""
extra_context = { 'language' : get_language_from_request ( request ) , 'page_languages' : settings . PAGE_LANGUAGES , } return super ( PageAdmin , self ) . add_view ( request , form_url , extra_context )
def _parse_weights ( weight_args , default_weight = 0.6 ) : """Parse list of weight assignments ."""
weights_dict = { } r_group_weight = default_weight for weight_arg in weight_args : for weight_assignment in weight_arg . split ( ',' ) : if '=' not in weight_assignment : raise ValueError ( 'Invalid weight assignment: {}' . format ( weight_assignment ) ) key , value = weight_assignment ....
def process_file ( self , filename ) : """Processing one file ."""
if self . config . dry_run : if not self . config . internal : self . logger . info ( "Dry run mode for script %s" , filename ) with open ( filename ) as handle : for line in handle : yield line [ 0 : - 1 ] if line [ - 1 ] == '\n' else line else : if not self . config . internal ...
def evalSamples ( self , x ) : '''Evalautes the samples of quantity of interest and its gradient ( if supplied ) at the given values of the design variables : param iterable x : values of the design variables , this is passed as the first argument to the function fqoi : return : ( values of the quantity of ...
# Make sure dimensions are correct # u _ sample _ dimensions = self . _ processDimensions ( ) self . _N_dv = len ( _makeIter ( x ) ) if self . verbose : print ( 'Evaluating surrogate' ) if self . surrogate is None : def fqoi ( u ) : return self . fqoi ( x , u ) def fgrad ( u ) : return self ...
def terminal_attribute_iterator ( self , mapped_class = None , key = None ) : """Returns an iterator over all terminal mapped attributes for the given mapped class and attribute key . See : method : ` get _ attribute _ map ` for details ."""
for attr in self . _attribute_iterator ( mapped_class , key ) : if attr . kind == RESOURCE_ATTRIBUTE_KINDS . TERMINAL : yield attr
def parse ( self , fo ) : """Convert ChIPMunk output to motifs Parameters fo : file - like File object containing ChIPMunk output . Returns motifs : list List of Motif instances ."""
# KDIC | 6.124756232026243 # A | 517.99999 42.99999 345.999994 25.999996 602.99999 155.999997 2.999996 91.99999 # C | 5.99999 4.99999 2.999996 956.99999 91.99999 17.999996 22.999996 275.999994 # G | 340.999994 943.99999 630.99999 6.99999 16.999996 48.99999 960.99999 14.999998 # T | 134.999997 7.99999 19.999996 9.999998...
def import_image ( DryRun = None , Description = None , DiskContainers = None , LicenseType = None , Hypervisor = None , Architecture = None , Platform = None , ClientData = None , ClientToken = None , RoleName = None ) : """Import single or multi - volume disk images or EBS snapshots into an Amazon Machine Image (...
pass
def fetch_path ( self , name ) : """Fetch contents from the path retrieved via lookup _ path . No caching will be done ."""
with codecs . open ( self . lookup_path ( name ) , encoding = 'utf-8' ) as fd : return fd . read ( )
def grab_xml ( host , token = None ) : """Grab XML data from Gateway , returned as a dict ."""
urllib3 . disable_warnings ( ) if token : scheme = "https" if not token : scheme = "http" token = "1234567890" url = ( scheme + '://' + host + '/gwr/gop.php?cmd=GWRBatch&data=<gwrcmds><gwrcmd><gcmd>RoomGetCarousel</gcmd><gdata><gip><version>1</version><token>' + token + '</token><fields>name,status</fields>...
def _serialize_icons ( icons ) : """Serialize [ IndividualConstraints ] into the SimpleMRS encoding ."""
toks = [ 'ICONS:' , '<' ] for ic in icons : toks . extend ( ic ) # toks + = [ str ( icon . left ) , # icon . relation , # str ( icon . right ) ] toks += [ '>' ] return ' ' . join ( toks )
def insert_concurrent_execution_histories ( self , parent , concurrent_execution_histories ) : """Adds the child execution histories of a concurrency state . : param Gtk . TreeItem parent : the parent to add the next history item to : param list [ ExecutionHistory ] concurrent _ execution _ histories : a list o...
for execution_history in concurrent_execution_histories : if len ( execution_history ) >= 1 : first_history_item = execution_history [ 0 ] # this is just a dummy item to have an extra parent for each branch # gives better overview in case that one of the child state is a simple execution sta...
def _calculate_matches_closures ( groups ) : """Find the transitive closure of each unique identity . This function uses a BFS algorithm to build set of matches . For instance , given a list of matched unique identities like A = { A , B } ; B = { B , A , C } , C = { C , } and D = { D , } the output will be ...
matches = [ ] ns = sorted ( groups . groups . keys ( ) ) while ns : n = ns . pop ( 0 ) visited = [ n ] vs = [ v for v in groups . get_group ( n ) [ 'uuid_y' ] ] while vs : v = vs . pop ( 0 ) if v in visited : continue nvs = [ nv for nv in groups . get_group ( v ) [ 'u...
def setCoords ( self , x1 , y1 , x2 , y2 ) : """Set coordinates of window to run from ( x1 , y1 ) in the lower - left corner to ( x2 , y2 ) in the upper - right corner ."""
self . trans = Transform ( self . size [ 0 ] , self . size [ 1 ] , x1 , y1 , x2 , y2 )
def phred_13_to_18_sed ( self , new_path = None , in_place = True ) : """Illumina - 1.3 format conversion to Illumina - 1.8 format via sed ( faster ) ."""
# String # sed_command = r"""4~4y/@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghi/!"#$%&'\''()*+,-.\/0123456789:;<=>?@ABCDEFGHIJ/""" # Faster with bash utilities # if in_place is True : sh . sed ( '-i' , sed_command , self . path ) return self # New file # if new_path is None : new_fastq = self . __class__ ( ne...
def p_dynamic_class_name_reference ( p ) : '''dynamic _ class _ name _ reference : base _ variable OBJECT _ OPERATOR object _ property dynamic _ class _ name _ variable _ properties | base _ variable'''
if len ( p ) == 5 : name , dims = p [ 3 ] p [ 0 ] = ast . ObjectProperty ( p [ 1 ] , name , lineno = p . lineno ( 2 ) ) for class_ , dim , lineno in dims : p [ 0 ] = class_ ( p [ 0 ] , dim , lineno = lineno ) for name , dims in p [ 4 ] : p [ 0 ] = ast . ObjectProperty ( p [ 0 ] , name , ...
def verify_credentials ( self , delegate = None ) : "Verify a user ' s credentials ."
parser = txml . Users ( delegate ) return self . __downloadPage ( '/account/verify_credentials.xml' , parser )
async def copy ( self , key_source , storage_dest , key_dest ) : """Return True if data are copied * optimized for http - > fs copy * not supported return _ status"""
from aioworkers . storage . filesystem import FileSystemStorage if not isinstance ( storage_dest , FileSystemStorage ) : return super ( ) . copy ( key_source , storage_dest , key_dest ) url = self . raw_key ( key_source ) logger = self . context . logger async with self . _semaphore : async with self . session ...
def validate ( self , value ) : """validate"""
# obj can be None or a DataFrame if value is None : return True else : try : with value . open ( ) as hdulist : self . validate_hdulist ( hdulist ) except Exception : _type , exc , tb = sys . exc_info ( ) six . reraise ( ValidationError , exc , tb )
def installProductOn ( self , userstore ) : """Creates an Installation in this user store for our collection of powerups , and then install those powerups on the user ' s store ."""
def install ( ) : i = Installation ( store = userstore ) i . types = self . types i . install ( ) userstore . transact ( install )
def annotate ( results , settings ) : '''Concatenate the annotations of all checkers'''
annotations = ( generate_annotation ( result , setting ) for result , setting in zip ( results , settings ) ) return '\n' . join ( annot for annot in annotations if annot )
def detachAcceptMsOriginating ( ) : """DETACH ACCEPT Section 9.4.6.2"""
a = TpPd ( pd = 0x3 ) b = MessageType ( mesType = 0x6 ) # 00000110 c = ForceToStandbyAndSpareHalfOctets ( ) packet = a / b / c return packet
def awaitAnyTermination ( self , timeout = None ) : """Wait until any of the queries on the associated SQLContext has terminated since the creation of the context , or since : func : ` resetTerminated ( ) ` was called . If any query was terminated with an exception , then the exception will be thrown . If ` t...
if timeout is not None : if not isinstance ( timeout , ( int , float ) ) or timeout < 0 : raise ValueError ( "timeout must be a positive integer or float. Got %s" % timeout ) return self . _jsqm . awaitAnyTermination ( int ( timeout * 1000 ) ) else : return self . _jsqm . awaitAnyTermination ( )
def split_label_fuzzy ( self , label ) : """Splits a label entered as user input . It ' s more flexible in it ' s syntax parsing than the L { split _ label _ strict } method , as it allows the exclamation mark ( B { C { ! } } ) to be omitted . The ambiguity is resolved by searching the modules in the snapshot...
module = function = None offset = 0 # Special case : None if not label : label = compat . b ( "0x0" ) else : # Remove all blanks . label = label . replace ( compat . b ( ' ' ) , compat . b ( '' ) ) label = label . replace ( compat . b ( '\t' ) , compat . b ( '' ) ) label = label . replace ( compat . b (...
def write_command ( self , command : Command ) : '''Write a command to the stream . Args : command : The command . Coroutine .'''
_logger . debug ( 'Write command.' ) data = command . to_bytes ( ) yield from self . _connection . write ( data ) self . _data_event_dispatcher . notify_write ( data )
def setNotches ( self , notches ) : """Manually sets the notches list for this ruler to the inputed notches . : param notches | [ < str > , . . ] | | None"""
self . _rulerType = XChartRuler . Type . Custom self . _notches = notches
def has_successor ( self , graph , orig , dest , branch , turn , tick , * , forward = None ) : """Return whether an edge connects the origin to the destination at the given time . Doesn ' t require the edge ' s index , which makes it slower than retrieving a particular edge ."""
if forward is None : forward = self . db . _forward return dest in self . _get_destcache ( graph , orig , branch , turn , tick , forward = forward )
def handle ( self , * args , ** options ) : """With no arguments , find the first user in the system with the is _ superuser or is _ staff flag set to true , or just the first user in the system period . With a single argument , look for the user with that value as the USERNAME _ FIELD value . When a user...
user_model = get_user_model ( ) if len ( args ) == 0 : # find the first superuser , or staff member or user filters = [ { "is_superuser" : True } , { "is_staff" : True } , { } ] user = None for f in filters : try : user = user_model . _default_manager . filter ( ** f ) . order_by ( "pk" ...
def _addDPFiles ( self , * files ) : """callback to add DPs corresponding to files ."""
# quiet flag is always true self . new_entry_dialog . addDataProducts ( self . purrer . makeDataProducts ( [ ( file , True ) for file in files ] , unbanish = True , unignore = True ) )
def move ( self , node , destination , position = None , save = False ) : """Moves the given : class : ` CTENode ` ` node ` and places it as a child node of the ` destination ` : class : ` CTENode ` ( or makes it a root node if ` destination ` is ` ` None ` ` ) . Optionally , ` position ` can be a callable wh...
# Allow custom positioning semantics to specify the position before # setting the parent . if position is not None : position ( node , destination ) node . parent = destination if save : node . save ( ) return node
def list_group_maintainers ( self , name ) : """Get the maintainers of a group . Args : name ( string ) : Name of group to query . Returns : ( list [ string ] ) : List of maintainer names ."""
return self . service . list_group_maintainers ( name , self . url_prefix , self . auth , self . session , self . session_send_opts )
def _ReadString ( self , file_object , file_offset , data_type_map , description ) : """Reads a string . Args : file _ object ( FileIO ) : file - like object . file _ offset ( int ) : offset of the data relative from the start of the file - like object . data _ type _ map ( dtfabric . DataTypeMap ) : data...
# pylint : disable = protected - access element_data_size = ( data_type_map . _element_data_type_definition . GetByteSize ( ) ) elements_terminator = ( data_type_map . _data_type_definition . elements_terminator ) byte_stream = [ ] element_data = file_object . read ( element_data_size ) byte_stream . append ( element_d...
def commit ( self ) : """Commit the current transaction . Make all statements executed since the transaction was begun permanent ."""
if hasattr ( self . local , 'tx' ) and self . local . tx : tx = self . local . tx . pop ( ) tx . commit ( ) self . _flush_tables ( )
def _redundant_stack_variable_removal ( self , function , data_graph ) : """If an argument passed from the stack ( i . e . dword ptr [ ebp + 4h ] ) is saved to a local variable on the stack at the beginning of the function , and this local variable was never modified anywhere in this function , and no pointer o...
# check if there is any stack pointer being stored into any register other than esp # basically check all consumers of stack pointers stack_ptrs = [ ] sp_offset = self . project . arch . registers [ 'esp' ] [ 0 ] bp_offset = self . project . arch . registers [ 'ebp' ] [ 0 ] for n in data_graph . nodes ( ) : if isin...
def start ( parallel , items , config , dirs = None , name = None , multiplier = 1 , max_multicore = None ) : """Start a parallel cluster or machines to be used for running remote functions . Returns a function used to process , in parallel items with a given function . Allows sharing of a single cluster acro...
if name : checkpoint_dir = utils . safe_makedir ( os . path . join ( dirs [ "work" ] , "checkpoints_parallel" ) ) checkpoint_file = os . path . join ( checkpoint_dir , "%s.done" % name ) else : checkpoint_file = None sysinfo = system . get_info ( dirs , parallel , config . get ( "resources" , { } ) ) items ...
def _scrape_document ( self ) : '''Extract links from the DOM .'''
mock_response = self . _new_mock_response ( self . _response , self . _get_temp_path ( 'phantom' , '.html' ) ) self . _item_session . request = self . _request self . _item_session . response = mock_response self . _processing_rule . scrape_document ( item_session ) if mock_response . body : mock_response . body . ...
def get_dim_index ( js_dict , dim ) : """Get index from a given dimension . Args : js _ dict ( dict ) : dictionary containing dataset data and metadata . dim ( string ) : dimension name obtained from JSON file . Returns : dim _ index ( pandas . DataFrame ) : DataFrame with index - based dimension data .""...
try : dim_index = js_dict [ 'dimension' ] [ dim ] [ 'category' ] [ 'index' ] except KeyError : dim_label = get_dim_label ( js_dict , dim ) dim_index = pd . DataFrame ( list ( zip ( [ dim_label [ 'id' ] [ 0 ] ] , [ 0 ] ) ) , index = [ 0 ] , columns = [ 'id' , 'index' ] ) else : if type ( dim_index ) is l...
def mode ( values , dropna = True ) : """Returns the mode ( s ) of an array . Parameters values : array - like Array over which to check for duplicate values . dropna : boolean , default True Don ' t consider counts of NaN / NaT . . . versionadded : : 0.24.0 Returns mode : Series"""
from pandas import Series values = _ensure_arraylike ( values ) original = values # categorical is a fast - path if is_categorical_dtype ( values ) : if isinstance ( values , Series ) : return Series ( values . values . mode ( dropna = dropna ) , name = values . name ) return values . mode ( dropna = dr...
def rebuild_auth ( self , prepared_request , response ) : """Never rebuild auth for archive . org URLs ."""
u = urlparse ( prepared_request . url ) if u . netloc . endswith ( 'archive.org' ) : return super ( ArchiveSession , self ) . rebuild_auth ( prepared_request , response )
def view_attr ( attr_name ) : """Creates a setter that will set the specified view attribute to the current value . @ param attr _ name : the name of an attribute belonging to the view . @ type attr _ name : str"""
def view_attr ( value , context , ** _params ) : setattr ( context [ "view" ] , attr_name , value ) return _attr ( ) return view_attr
def closest ( self , obj , group , defaults = True ) : """This method is designed to be called from the root of the tree . Given any LabelledData object , this method will return the most appropriate Options object , including inheritance . In addition , closest supports custom options by checking the objec...
components = ( obj . __class__ . __name__ , group_sanitizer ( obj . group ) , label_sanitizer ( obj . label ) ) target = '.' . join ( [ c for c in components if c ] ) return self . find ( components ) . options ( group , target = target , defaults = defaults )
def serial_wire_viewer ( jlink_serial , device ) : """Implements a Serial Wire Viewer ( SWV ) . A Serial Wire Viewer ( SWV ) allows us implement real - time logging of output from a connected device over Serial Wire Output ( SWO ) . Args : jlink _ serial ( str ) : the J - Link serial number device ( str )...
buf = StringIO . StringIO ( ) jlink = pylink . JLink ( log = buf . write , detailed_log = buf . write ) jlink . open ( serial_no = jlink_serial ) # Use Serial Wire Debug as the target interface . Need this in order to use # Serial Wire Output . jlink . set_tif ( pylink . enums . JLinkInterfaces . SWD ) jlink . connect ...
def remove ( cls , pid ) : """Remove a pool , closing all connections : param str pid : The pool ID"""
with cls . _lock : cls . _ensure_pool_exists ( pid ) cls . _pools [ pid ] . close ( ) del cls . _pools [ pid ]
def read_bytes ( self ) : """reading bytes ; update progress bar after 1 ms"""
global exit_flag for self . i in range ( 0 , self . length ) : self . bytes [ self . i ] = i_max [ self . i ] self . maxbytes [ self . i ] = total_chunks [ self . i ] self . progress [ self . i ] [ "maximum" ] = total_chunks [ self . i ] self . progress [ self . i ] [ "value" ] = self . bytes [ self . i...
def _symlink_in_files ( in_files , data ) : """Symlink ( shared filesystem ) or copy ( CWL ) inputs into align _ prep directory ."""
work_dir = utils . safe_makedir ( os . path . join ( data [ "dirs" ] [ "work" ] , "align_prep" ) ) out = [ ] for in_file in in_files : out_file = os . path . join ( work_dir , "%s_%s" % ( dd . get_sample_name ( data ) , os . path . basename ( in_file ) ) ) out_file = _symlink_or_copy_grabix ( in_file , out_file...
def gcv ( data , channels = None ) : """Calculate the geometric CV of the events in an FCSData object . Parameters data : FCSData or numpy array NxD flow cytometry data where N is the number of events and D is the number of parameters ( aka channels ) . channels : int or str or list of int or list of str ...
# Slice data to take statistics from if channels is None : data_stats = data else : data_stats = data [ : , channels ] # Calculate and return statistic return np . sqrt ( np . exp ( np . std ( np . log ( data_stats ) , axis = 0 ) ** 2 ) - 1 )
def get_logging_stream_handler ( logger = None , formatter = LOGGING_DEFAULT_FORMATTER ) : """Adds a logging stream handler to given logger or default logger using given file . : param logger : Logger to add the handler to . : type logger : Logger : param file : File to verbose into . : type file : unicode ...
logger = LOGGER if logger is None else logger logging_stream_handler = logging . StreamHandler ( Streamer ( ) ) logging_stream_handler . setFormatter ( formatter ) logger . addHandler ( logging_stream_handler ) return logging_stream_handler
def compute_busiest_date ( feed : "Feed" , dates : List [ str ] ) -> str : """Given a list of dates , return the first date that has the maximum number of active trips . Notes Assume the following feed attributes are not ` ` None ` ` : - Those used in : func : ` compute _ trip _ activity `"""
f = feed . compute_trip_activity ( dates ) s = [ ( f [ c ] . sum ( ) , c ) for c in f . columns if c != "trip_id" ] return max ( s ) [ 1 ]
def from_file ( campaign_file , ** kwargs ) : """Load campaign from YAML file : return : memory representation of the YAML file : rtype : dictionary"""
realpath = osp . realpath ( campaign_file ) if osp . isdir ( realpath ) : campaign_file = osp . join ( campaign_file , YAML_CAMPAIGN_FILE ) campaign = Configuration . from_file ( campaign_file ) return default_campaign ( campaign , ** kwargs )
def built ( self ) : """Called just after this node is successfully built ."""
# Clear the implicit dependency caches of any Nodes # waiting for this Node to be built . for parent in self . waiting_parents : parent . implicit = None self . clear ( ) if self . pseudo : if self . exists ( ) : raise SCons . Errors . UserError ( "Pseudo target " + str ( self ) + " must not exist" ) el...
def _at ( cls , verb ) : """A verb with a select text match"""
# Named ( listed ) columns are always included columns = cls . select ( verb ) final_columns_set = set ( cls . select ( verb ) ) groups_set = set ( _get_groups ( verb ) ) final_columns_set -= groups_set - set ( verb . names ) def pred ( col ) : if col not in verb . data : raise KeyError ( "Unknown column na...
def get_readable_tasks ( self , course ) : """Returns the list of all available tasks in a course"""
course_fs = self . _filesystem . from_subfolder ( course . get_id ( ) ) tasks = [ task [ 0 : len ( task ) - 1 ] # remove trailing / for task in course_fs . list ( folders = True , files = False , recursive = False ) if self . _task_file_exists ( course_fs . from_subfolder ( task ) ) ] return tasks
def cmdify ( self ) : """Encode into a cmd - executable string . This re - implements CreateProcess ' s quoting logic to turn a list of arguments into one single string for the shell to interpret . * All double quotes are escaped with a backslash . * Existing backslashes before a quote are doubled , so they...
return " " . join ( itertools . chain ( [ _quote_if_contains ( self . command , r'[\s^()]' ) ] , ( _quote_if_contains ( arg , r'[\s^]' ) for arg in self . args ) , ) )
def extract_value ( self , agg , idx , name = '' ) : """Extract member number * idx * from aggregate ."""
if not isinstance ( idx , ( tuple , list ) ) : idx = [ idx ] instr = instructions . ExtractValue ( self . block , agg , idx , name = name ) self . _insert ( instr ) return instr
def dehydrate ( self ) : """Return a dict representing this limit ."""
# Only concerned about very specific attributes result = dict ( limit_class = self . _limit_full_name ) for attr in self . attrs : # Using getattr allows the properties to come into play result [ attr ] = getattr ( self , attr ) return result
def get_referents ( object , level = 1 ) : """Get all referents of an object up to a certain level . The referents will not be returned in a specific order and will not contain duplicate objects . Duplicate objects will be removed . Keyword arguments : level - - level of indirection to which referents consi...
res = gc . get_referents ( object ) level -= 1 if level > 0 : for o in res : res . extend ( get_referents ( o , level ) ) res = _remove_duplicates ( res ) return res
def unicode_key ( key ) : """CONVERT PROPERTY VALUE TO QUOTED NAME OF SAME"""
if not isinstance ( key , ( text_type , binary_type ) ) : from mo_logs import Log Log . error ( "{{key|quote}} is not a valid key" , key = key ) return quote ( text_type ( key ) )
def vsep ( v1 , v2 ) : """Find the separation angle in radians between two double precision , 3 - dimensional vectors . This angle is defined as zero if either vector is zero . http : / / naif . jpl . nasa . gov / pub / naif / toolkit _ docs / C / cspice / vsep _ c . html : param v1 : First vector : type ...
v1 = stypes . toDoubleVector ( v1 ) v2 = stypes . toDoubleVector ( v2 ) return libspice . vsep_c ( v1 , v2 )
def get_caller_stack_info ( start_back : int = 1 ) -> List [ str ] : r"""Retrieves a textual representation of the call stack . Args : start _ back : number of calls back in the frame stack ( starting from the frame stack as seen by : func : ` get _ caller _ stack _ info ` ) to begin with Returns : list...
# "0 back " is debug _ callers , so " 1 back " its caller # https : / / docs . python . org / 3 / library / inspect . html callers = [ ] # type : List [ str ] frameinfolist = inspect . stack ( ) # type : List [ FrameInfo ] # noqa frameinfolist = frameinfolist [ start_back : ] for frameinfo in frameinfolist : frame ...
def run_command ( self , command , stdin = None , env = None ) : """Launch a shell command line . : param command : Command line to launch : type command : str : param stdin : Standard input of command : type stdin : file : param env : Environment variable used in command : type env : dict : return : ...
cmd = shlex . split ( command ) stdout = SpooledTemporaryFile ( max_size = settings . TMP_FILE_MAX_SIZE , dir = settings . TMP_DIR ) stderr = SpooledTemporaryFile ( max_size = settings . TMP_FILE_MAX_SIZE , dir = settings . TMP_DIR ) full_env = os . environ . copy ( ) if self . use_parent_env else { } full_env . update...
def new_instance ( cls , classname , length ) : """Creates a new array with the given classname and length ; initial values are null . : param classname : the classname in Java notation ( eg " weka . core . DenseInstance " ) : type classname : str : param length : the length of the array : type length : int...
return javabridge . static_call ( "Ljava/lang/reflect/Array;" , "newInstance" , "(Ljava/lang/Class;I)Ljava/lang/Object;" , get_jclass ( classname = classname ) , length )
def serialize ( self , submit = None ) : """Serialize each form field to a Payload container . : param Submit submit : Optional ` Submit ` to click , if form includes multiple submits : return : Payload instance"""
include_fields = prepare_fields ( self . fields , self . submit_fields , submit ) return Payload . from_fields ( include_fields )
def stop_processing ( self , warning = True ) : """Registers the end of a processing operation . : param warning : Emit warning message . : type warning : int : return : Method success . : rtype : bool"""
if not self . __is_processing : warning and LOGGER . warning ( "!> {0} | Engine is not processing, 'stop_processing' request has been ignored!" . format ( self . __class__ . __name__ ) ) return False LOGGER . debug ( "> Stopping processing operation!" ) self . __is_processing = False self . Application_Progress...
def rename_file ( source_path , target_path , allow_undo = True , no_confirm = False , rename_on_collision = True , silent = False , extra_flags = 0 , hWnd = None ) : """Perform a shell - based file rename . Renaming in this way allows the possibility of undo , auto - renaming , and showing the " flying file " ...
return _file_operation ( shellcon . FO_RENAME , source_path , target_path , allow_undo , no_confirm , rename_on_collision , silent , extra_flags , hWnd )
def write_to ( output , txt ) : """Write some text to some output"""
if ( isinstance ( txt , six . binary_type ) or six . PY3 and isinstance ( output , StringIO ) ) or isinstance ( output , TextIOWrapper ) : output . write ( txt ) else : output . write ( txt . encode ( "utf-8" , "replace" ) )
def _start_consumer ( self , consumer ) : """Start a consumer as a new Thread . : param Consumer consumer : : return :"""
thread = threading . Thread ( target = consumer . start , args = ( self . _connection , ) ) thread . daemon = True thread . start ( )
def _proxy ( self ) : """Generate an instance context for the instance , the context is capable of performing various actions . All instance actions are proxied to the context : returns : ServiceContext for this ServiceInstance : rtype : twilio . rest . preview . acc _ security . service . ServiceContext"""
if self . _context is None : self . _context = ServiceContext ( self . _version , sid = self . _solution [ 'sid' ] , ) return self . _context
def build_rules ( rule_yaml , match_plugins , action_plugins ) : """Convert parsed rule YAML in to a list of ruleset objects : param rule _ yaml : Dictionary parsed from YAML rule file : param match _ plugins : Dictionary of match plugins ( key = config _ name , value = plugin object ) : param action _ plugin...
rule_sets = [ ] for yaml_section in rule_yaml : rule_sets . append ( RuleSet ( yaml_section , match_plugins = match_plugins , action_plugins = action_plugins ) ) return rule_sets
def single ( C , namespace = None ) : """An element maker with a single namespace that uses that namespace as the default"""
if namespace is None : B = C ( ) . _ else : B = C ( default = namespace , _ = namespace ) . _ return B
def compatibility_mode ( ) : """Use this function to turn on the compatibility mode . The compatibility mode is used to improve compatibility with Pyinotify 0.7.1 ( or older ) programs . The compatibility mode provides additional variables ' is _ dir ' , ' event _ name ' , ' EventsCodes . IN _ * ' and ' Event...
setattr ( EventsCodes , 'ALL_EVENTS' , ALL_EVENTS ) for evname in globals ( ) : if evname . startswith ( 'IN_' ) : setattr ( EventsCodes , evname , globals ( ) [ evname ] ) global COMPATIBILITY_MODE COMPATIBILITY_MODE = True
def url_unquote_plus ( s , charset = 'utf-8' , errors = 'replace' ) : """URL decode a single string with the given ` charset ` and decode " + " to whitespace . Per default encoding errors are ignored . If you want a different behavior you can set ` errors ` to ` ` ' replace ' ` ` or ` ` ' strict ' ` ` . In st...
if isinstance ( s , text_type ) : s = s . replace ( u'+' , u' ' ) else : s = s . replace ( b'+' , b' ' ) return url_unquote ( s , charset , errors )
def _penalize_client ( self , client ) : """Place client in the penalty box . : param client : Client object"""
if client in self . active_clients : # hasn ' t been removed yet log . warning ( "%r marked down." , client ) self . active_clients . remove ( client ) self . penalty_box . add ( client ) else : log . info ( "%r not in active client list." )
def latcyl ( radius , lon , lat ) : """Convert from latitudinal coordinates to cylindrical coordinates . http : / / naif . jpl . nasa . gov / pub / naif / toolkit _ docs / C / cspice / latcyl _ c . html : param radius : Distance of a point from the origin . : type radius : : param lon : Angle of the point f...
radius = ctypes . c_double ( radius ) lon = ctypes . c_double ( lon ) lat = ctypes . c_double ( lat ) r = ctypes . c_double ( ) lonc = ctypes . c_double ( ) z = ctypes . c_double ( ) libspice . latcyl_c ( radius , lon , lat , ctypes . byref ( r ) , ctypes . byref ( lonc ) , ctypes . byref ( z ) ) return r . value , lon...
def get_proficiency_admin_session_for_objective_bank ( self , objective_bank_id = None ) : """Gets the OsidSession associated with the proficiency administration service for the given objective bank . arg : objectiveBankId ( osid . id . Id ) : the Id of the ObjectiveBank return : ( osid . learning . Profici...
if not objective_bank_id : raise NullArgument if not self . supports_proficiency_admin ( ) : raise Unimplemented ( ) try : from . import sessions except ImportError : raise OperationFailed ( ) try : session = sessions . ProficiencyAdminSession ( objective_bank_id , runtime = self . _runtime ) except...
def _on_session_destroyed ( session_context ) : '''Calls any on _ session _ destroyed callbacks defined on the Document'''
callbacks = session_context . _document . session_destroyed_callbacks session_context . _document . session_destroyed_callbacks = set ( ) for callback in callbacks : try : callback ( session_context ) except Exception as e : log . warning ( 'DocumentLifeCycleHandler on_session_destroyed ' 'callb...