signature
stringlengths
29
44.1k
implementation
stringlengths
0
85.2k
def p_arg1 ( p ) : """arg1 : STRING | NUMBER | IDENT | GLOBAL"""
# a hack to support " clear global " p [ 0 ] = node . string ( value = str ( p [ 1 ] ) , lineno = p . lineno ( 1 ) , lexpos = p . lexpos ( 1 ) )
def cross_val_score ( estimator , X , y = None , scoring = None , cv = None , n_jobs = 1 , verbose = 0 , fit_params = None , pre_dispatch = '2*n_jobs' ) : """Evaluate a score by cross - validation Parameters estimator : estimator object implementing ' fit ' The object to use to fit the data . X : array - li...
X , y = indexable ( X , y ) cv = _check_cv ( cv , X , y , classifier = is_classifier ( estimator ) ) scorer = check_scoring ( estimator , scoring = scoring ) # We clone the estimator to make sure that all the folds are # independent , and that it is pickle - able . parallel = Parallel ( n_jobs = n_jobs , verbose = verb...
def remove ( self , item ) : """See : meth : ` list . remove ( ) ` method Calls observer ` ` self . observer ( UpdateType . DELETED , item , index ) ` ` where * * index * * is * item position *"""
index = self . index ( item ) self . real_list . remove ( item ) self . observer ( UpdateType . DELETED , item , index )
def _get_authorization_headers ( self , context ) : """Gets the authorization headers for a request . Returns : Sequence [ Tuple [ str , str ] ] : A list of request headers ( key , value ) to add to the request ."""
headers = { } self . _credentials . before_request ( self . _request , context . method_name , context . service_url , headers ) return list ( six . iteritems ( headers ) )
def ix_ ( selection , shape ) : """Convert an orthogonal selection to a numpy advanced ( fancy ) selection , like numpy . ix _ but with support for slices and single ints ."""
# normalisation selection = replace_ellipsis ( selection , shape ) # replace slice and int as these are not supported by numpy . ix _ selection = [ slice_to_range ( dim_sel , dim_len ) if isinstance ( dim_sel , slice ) else [ dim_sel ] if is_integer ( dim_sel ) else dim_sel for dim_sel , dim_len in zip ( selection , sh...
def _mirror_idx_cov ( self , f_values , idx1 ) : # will most likely be removed """obsolete and subject to removal ( TODO ) , return indices for negative ( " active " ) update of the covariance matrix assuming that ` ` f _ values [ idx1 [ i ] ] ` ` and ` ` f _ values [ - 1 - i ] ` ` are the corresponding mirro...
idx2 = np . arange ( len ( f_values ) - 1 , len ( f_values ) - 1 - len ( idx1 ) , - 1 ) f = [ ] for i in rglen ( ( idx1 ) ) : f . append ( min ( ( f_values [ idx1 [ i ] ] , f_values [ idx2 [ i ] ] ) ) ) # idx . append ( idx1 [ i ] if f _ values [ idx1 [ i ] ] > f _ values [ idx2 [ i ] ] else idx2 [ i ] ) return...
def PlaceCall ( self , * Targets ) : """Places a call to a single user or creates a conference call . : Parameters : Targets : str One or more call targets . If multiple targets are specified , a conference call is created . The call target can be a Skypename , phone number , or speed dial code . : return...
calls = self . ActiveCalls reply = self . _DoCommand ( 'CALL %s' % ', ' . join ( Targets ) ) # Skype for Windows returns the call status which gives us the call Id ; if reply . startswith ( 'CALL ' ) : return Call ( self , chop ( reply , 2 ) [ 1 ] ) # On linux we get ' OK ' as reply so we search for the new call on...
def _set_collector_vrf ( self , v , load = False ) : """Setter method for collector _ vrf , mapped from YANG variable / sflow / collector _ vrf ( common - def : vrf - name ) If this variable is read - only ( config : false ) in the source YANG file , then _ set _ collector _ vrf is considered as a private met...
if hasattr ( v , "_utype" ) : v = v . _utype ( v ) try : t = YANGDynClass ( v , base = RestrictedClassType ( base_type = unicode , restriction_dict = { 'pattern' : u'((([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.)*([a-zA-Z0-9_]([a-zA-Z0-9\\-_]){0,61})?[a-zA-Z0-9]\\.?)|\\.' , 'length' : [ u'1..32' ] } ) ...
def operator_same_class ( method ) : """Intended to wrap operator methods , this decorator ensures the ` other ` parameter is of the same type as the ` self ` parameter . : param method : The method being decorated . : return : The wrapper to replace the method with ."""
def wrapper ( self , other ) : if not isinstance ( other , self . __class__ ) : raise TypeError ( 'unsupported operand types: \'{0}\' and \'{1}\'' . format ( self . __class__ . __name__ , other . __class__ . __name__ ) ) return method ( self , other ) return wrapper
def write_report ( self , template ) : """Write the compiled jinja template to the results file : param template str : the compiled jinja template"""
with open ( self . fn , 'w' ) as f : f . write ( template )
def _renew_by ( name , window = None ) : '''Date before a certificate should be renewed : param name : Common Name of the certificate ( DNS name of certificate ) : param window : days before expiry date to renew : return datetime object of first renewal date'''
expiry = _expires ( name ) if window is not None : expiry = expiry - datetime . timedelta ( days = window ) return expiry
def get_networks ( project_id , include_data = 'N' , ** kwargs ) : """Get all networks in a project Returns an array of network objects ."""
log . info ( "Getting networks for project %s" , project_id ) user_id = kwargs . get ( 'user_id' ) project = _get_project ( project_id ) project . check_read_permission ( user_id ) rs = db . DBSession . query ( Network . id , Network . status ) . filter ( Network . project_id == project_id ) . all ( ) networks = [ ] fo...
def is_empty ( self ) : """Return whether this rule is considered " empty " - - i . e . , has no contents that should end up in the final CSS ."""
if self . properties : # Rules containing CSS properties are never empty return False if not self . descendants : for header in self . ancestry . headers : if header . is_atrule and header . directive != '@media' : # At - rules should always be preserved , UNLESS they are @ media # blocks , whic...
def progress_updater ( size , total ) : """Progress reporter for checksum verification ."""
current_task . update_state ( state = state ( 'PROGRESS' ) , meta = dict ( size = size , total = total ) )
def word_spans ( self ) : """The list of spans representing ` ` words ` ` layer elements ."""
if not self . is_tagged ( WORDS ) : self . tokenize_words ( ) return self . spans ( WORDS )
def check_input ( self , token ) : """Performs checks on the input token . Raises an exception if unsupported . : param token : the token to check : type token : Token"""
if isinstance ( token . payload , Evaluation ) : return None if isinstance ( token . payload , ClusterEvaluation ) : return None raise Exception ( self . full_name + ": Input token is not a supported Evaluation object - " + classes . get_classname ( token . payload ) )
def update_user_display_name ( user , ** kwargs ) : """Update a user ' s display name"""
# check _ perm ( kwargs . get ( ' user _ id ' ) , ' edit _ user ' ) try : user_i = db . DBSession . query ( User ) . filter ( User . id == user . id ) . one ( ) user_i . display_name = user . display_name return user_i except NoResultFound : raise ResourceNotFoundError ( "User (id=%s) not found" % ( use...
def decode ( pieces , sequence_length , model_file = None , model_proto = None , reverse = False , name = None ) : """Decode pieces into postprocessed text . Args : pieces : A 2D int32 or string tensor [ batch _ size x max _ length ] of encoded sequences . sequence _ length : A 1D int32 tensor [ batch _ siz...
return _gen_sentencepiece_processor_op . sentencepiece_decode ( pieces , sequence_length , model_file = model_file , model_proto = model_proto , reverse = reverse , name = name )
def clean ( ) : "take out the trash"
src_dir = easy . options . setdefault ( "docs" , { } ) . get ( 'src_dir' , None ) if src_dir is None : src_dir = 'src' if easy . path ( 'src' ) . exists ( ) else '.' with easy . pushd ( src_dir ) : for pkg in set ( easy . options . setup . packages ) | set ( ( "tests" , ) ) : for filename in glob . glob...
def _assign_uid ( self , sid ) : """Purpose : Assign a uid to the current object based on the sid passed . Pass the current uid to children of current object"""
self . _uid = ru . generate_id ( 'pipeline.%(item_counter)04d' , ru . ID_CUSTOM , namespace = sid ) for stage in self . _stages : stage . _assign_uid ( sid ) self . _pass_uid ( )
def _RunMethod ( dev , args , extra ) : """Runs a method registered via MakeSubparser ."""
logging . info ( '%s(%s)' , args . method . __name__ , ', ' . join ( args . positional ) ) result = args . method ( dev , * args . positional , ** extra ) if result is not None : if isinstance ( result , io . StringIO ) : sys . stdout . write ( result . getvalue ( ) ) elif isinstance ( result , ( list ,...
def create_review ( self , review , pub_name , ext_name ) : """CreateReview . [ Preview API ] Creates a new review for an extension : param : class : ` < Review > < azure . devops . v5_0 . gallery . models . Review > ` review : Review to be created for the extension : param str pub _ name : Name of the publis...
route_values = { } if pub_name is not None : route_values [ 'pubName' ] = self . _serialize . url ( 'pub_name' , pub_name , 'str' ) if ext_name is not None : route_values [ 'extName' ] = self . _serialize . url ( 'ext_name' , ext_name , 'str' ) content = self . _serialize . body ( review , 'Review' ) response =...
def p_InClassDefList ( p ) : '''InClassDefList : InClassDef | InClassDefList InClassDef'''
if len ( p ) < 3 : p [ 0 ] = InClassDefList ( None , p [ 1 ] ) else : p [ 0 ] = InClassDefList ( p [ 1 ] , p [ 2 ] )
def agent_check_warn ( consul_url = None , token = None , checkid = None , ** kwargs ) : '''This endpoint is used with a check that is of the TTL type . When this is called , the status of the check is set to warning and the TTL clock is reset . : param consul _ url : The Consul server URL . : param checkid...
ret = { } query_params = { } if not consul_url : consul_url = _get_config ( ) if not consul_url : log . error ( 'No Consul URL found.' ) ret [ 'message' ] = 'No Consul URL found.' ret [ 'res' ] = False return ret if not checkid : raise SaltInvocationError ( 'Required argument...
def soa_rec ( rdata ) : '''Validate and parse DNS record data for SOA record ( s ) : param rdata : DNS record data : return : dict w / fields'''
rschema = OrderedDict ( ( ( 'mname' , str ) , ( 'rname' , str ) , ( 'serial' , int ) , ( 'refresh' , int ) , ( 'retry' , int ) , ( 'expire' , int ) , ( 'minimum' , int ) , ) ) return _data2rec ( rschema , rdata )
def update ( self ) : """Request an updated set of data from casper . jxml ."""
response = self . jss . session . post ( self . url , data = self . auth ) response_xml = ElementTree . fromstring ( response . text . encode ( "utf_8" ) ) # Remove previous data , if any , and then add in response ' s XML . self . clear ( ) for child in response_xml . getchildren ( ) : self . append ( child )
def add_firmware_image ( self , name , datafile , ** kwargs ) : """Add a new firmware reference . : param str name : Firmware file short name ( Required ) : param str datafile : The file object or * path * to the firmware image file ( Required ) : param str description : Firmware file description : return :...
kwargs . update ( { 'name' : name } ) firmware_image = FirmwareImage . _create_request_map ( kwargs ) firmware_image . update ( { 'datafile' : datafile } ) api = self . _get_api ( update_service . DefaultApi ) return FirmwareImage ( api . firmware_image_create ( ** firmware_image ) )
def list_cubes ( self ) : """List all available JSON files ."""
for file_name in os . listdir ( self . directory ) : if '.' in file_name : name , ext = file_name . rsplit ( '.' , 1 ) if ext . lower ( ) == 'json' : yield name
def get_objective_lookup_session ( self ) : """Gets the OsidSession associated with the objective lookup service . return : ( osid . learning . ObjectiveLookupSession ) - an ObjectiveLookupSession raise : OperationFailed - unable to complete request raise : Unimplemented - supports _ objective _ lookup ( ...
if not self . supports_objective_lookup ( ) : raise Unimplemented ( ) try : from . import sessions except ImportError : raise # OperationFailed ( ) try : session = sessions . ObjectiveLookupSession ( runtime = self . _runtime ) except AttributeError : raise # OperationFailed ( ) return sessi...
def set_operator_password ( operator , password , auth , url ) : """Function to set the password of an existing operator : param operator : str Name of the operator account : param password : str New password : param auth : requests auth object # usually auth . creds from auth pyhpeimc . auth . class : para...
if operator is None : operator = input ( '''\n What is the username you wish to change the password?''' ) oper_id = '' authtype = None plat_oper_list = get_plat_operator ( auth , url ) for i in plat_oper_list : if i [ 'name' ] == operator : oper_id = i [ 'id' ] authtype = i [ 'authType' ] if ope...
def wr_txt_section_hdrgos ( self , fout_txt , sortby = None , prt_section = True ) : """Write high GO IDs that are actually used to group current set of GO IDs ."""
sec2d_go = self . grprobj . get_sections_2d ( ) # lists of GO IDs sec2d_nt = self . get_sections_2dnt ( sec2d_go ) # lists of GO Grouper namedtuples if sortby is None : sortby = self . fncsortnt with open ( fout_txt , 'w' ) as prt : self . prt_ver ( prt ) prt . write ( "# GROUP NAME: {NAME}\n" . format ( NA...
def get_smt_userid ( ) : """Get the userid of smt server"""
cmd = [ "sudo" , "/sbin/vmcp" , "query userid" ] try : userid = subprocess . check_output ( cmd , close_fds = True , stderr = subprocess . STDOUT ) userid = bytes . decode ( userid ) userid = userid . split ( ) [ 0 ] return userid except Exception as err : msg = ( "Could not find the userid of the s...
def bar_chart ( data , bar_char = '=' , width = 80 ) : """Return an horizontal bar chart > > > print bar _ chart ( { . . . ' one ' : ' 1 ' , . . . ' two ' : ' 2 ' , . . . ' three ' : ' 3 ' , . . . ' four ' : ' 4 ' , . . . ' five ' : ' 5 ' , five = = = = = four = = = = one = three = = = two = =...
if type ( data ) is dict : output = [ ] max_len = len ( max ( data , key = len ) ) float_values = map ( float , data . values ( ) ) max_value = max ( float_values ) min_value = min ( float_values ) all_integer = all ( f . is_integer ( ) for f in float_values ) for key in sorted ( data ) : ...
def _publish ( tgt , fun , arg = None , tgt_type = 'glob' , returner = '' , timeout = 5 , form = 'clean' , wait = False , via_master = None ) : '''Publish a command from the minion out to other minions , publications need to be enabled on the Salt master and the minion needs to have permission to publish the co...
if 'master_uri' not in __opts__ : log . error ( 'Cannot run publish commands without a connection to a salt master. No command sent.' ) return { } if fun . startswith ( 'publish.' ) : log . info ( 'Cannot publish publish calls. Returning {}' ) return { } arg = _parse_args ( arg ) if via_master : if ...
def _aln_filename ( self , prefix ) : """Return name of file containing the alignment prefix - - str , prefix of alignment file ."""
if self . Parameters [ '-outfile' ] . isOn ( ) : aln_filename = self . _absolute ( self . Parameters [ '-outfile' ] . Value ) else : aln_filename = prefix + self . _suffix ( ) return aln_filename
def enable_digital_reporting ( self , pin ) : """Enables digital reporting . By turning reporting on for all 8 bits in the " port " . This is part of Firmata ' s protocol specification . : param pin : Pin and all pins for this port : returns : No return value"""
task = asyncio . ensure_future ( self . core . enable_digital_reporting ( pin ) ) self . loop . run_until_complete ( task )
def _opt_soft ( eigvectors , rot_matrix , n_clusters ) : """Optimizes the PCCA + rotation matrix such that the memberships are exclusively nonnegative . Parameters eigenvectors : ndarray A matrix with the sorted eigenvectors in the columns . The stationary eigenvector should be first , then the one to the s...
# only consider first n _ clusters eigenvectors eigvectors = eigvectors [ : , : n_clusters ] # crop first row and first column from rot _ matrix # rot _ crop _ matrix = rot _ matrix [ 1 : , 1 : ] rot_crop_matrix = rot_matrix [ 1 : ] [ : , 1 : ] ( x , y ) = rot_crop_matrix . shape # reshape rot _ crop _ matrix into line...
def get_data_path ( data , module , check_exists = True ) : """return a directory path to data within a module Parameters data : str or list [ str ] file name or list of sub - directories and file name ( e . g . [ ' lammps ' , ' data . txt ' ] )"""
basepath = os . path . dirname ( os . path . abspath ( inspect . getfile ( module ) ) ) if isinstance ( data , basestring ) : data = [ data ] dirpath = os . path . join ( basepath , * data ) if check_exists : assert os . path . exists ( dirpath ) , '{0} does not exist' . format ( dirpath ) return pathlib . Path...
def affects ( self , reglist ) : """Returns if this instruction affects any of the registers in reglist ."""
if isinstance ( reglist , str ) : reglist = [ reglist ] reglist = single_registers ( reglist ) return len ( [ x for x in self . destroys if x in reglist ] ) > 0
def add_full_state_methods ( class_with_globalize_methods ) : """class decorator to create " _ full _ state " methods / properties on the class ( so they are valid for all instances created from this class ) . Parameters class _ with _ globalize _ methods"""
assert hasattr ( class_with_globalize_methods , 'active_set' ) assert hasattr ( class_with_globalize_methods , 'nstates_full' ) for name , method in class_with_globalize_methods . __dict__ . copy ( ) . items ( ) : if isinstance ( method , property ) and hasattr ( method . fget , '_map_to_full_state_def_arg' ) : ...
def logger_delete ( self , project , logger_name ) : """API call : delete all entries in a logger via a DELETE request See https : / / cloud . google . com / logging / docs / reference / v2 / rest / v2 / projects . logs / delete : type project : str : param project : ID of project containing the log entries...
path = "/projects/%s/logs/%s" % ( project , logger_name ) self . api_request ( method = "DELETE" , path = path )
def download ( cls , url = None , force_download = False ) : """Downloads uniprot _ sprot . xml . gz and reldate . txt ( release date information ) from URL or file path . . note : : only URL / path of xml . gz is needed and valid value for parameter url . URL / path for reldate . txt have to be the same fold...
if url : version_url = os . path . join ( os . path . dirname ( url ) , defaults . VERSION_FILE_NAME ) else : url = os . path . join ( defaults . XML_DIR_NAME , defaults . SWISSPROT_FILE_NAME ) version_url = os . path . join ( defaults . XML_DIR_NAME , defaults . VERSION_FILE_NAME ) xml_file_path = cls . ge...
def get_by_params ( self , process_name , timeperiod , start_id , end_id ) : """method finds unit _ of _ work record and returns it to the caller"""
query = { unit_of_work . PROCESS_NAME : process_name , unit_of_work . TIMEPERIOD : timeperiod , unit_of_work . START_ID : start_id , unit_of_work . END_ID : end_id } collection = self . ds . connection ( COLLECTION_UNIT_OF_WORK ) document = collection . find_one ( query ) if document is None : raise LookupError ( '...
def addprojecthook ( self , project_id , url , push = False , issues = False , merge_requests = False , tag_push = False ) : """add a hook to a project : param project _ id : project id : param url : url of the hook : return : True if success"""
data = { 'id' : project_id , 'url' : url , 'push_events' : int ( bool ( push ) ) , 'issues_events' : int ( bool ( issues ) ) , 'merge_requests_events' : int ( bool ( merge_requests ) ) , 'tag_push_events' : int ( bool ( tag_push ) ) , } request = requests . post ( '{0}/{1}/hooks' . format ( self . projects_url , projec...
def set_datapoint ( self , ind , datapoint ) : """Sets the value of the datapoint at the given index ."""
if ind >= self . num_datapoints : raise ValueError ( 'Index %d out of bounds! Tensor has %d datapoints' % ( ind , self . num_datapoints ) ) self . data [ ind , ... ] = np . array ( datapoint ) . astype ( self . dtype )
def shutdown ( name , ** kwargs ) : '''Shuts down the device . . . code - block : : yaml shut the device : junos : - shutdown - in _ min : 10 Parameters : Optional * kwargs : * reboot : Whether to reboot instead of shutdown . ( default = False ) * at : Specify time for reboot . ( To be used ...
ret = { 'name' : name , 'changes' : { } , 'result' : True , 'comment' : '' } ret [ 'changes' ] = __salt__ [ 'junos.shutdown' ] ( ** kwargs ) return ret
def load_from_json ( file_path ) : """Load the stored data from json , and return as a dict ."""
if os . path . exists ( file_path ) : raw_data = open ( file_path , 'rb' ) . read ( ) return json . loads ( base64 . decodestring ( raw_data ) . decode ( 'utf-8' ) )
async def on_raw_731 ( self , message ) : """Someone we are monitoring got offline ."""
for nick in message . params [ 1 ] . split ( ',' ) : self . _destroy_user ( nick , monitor_override = True ) await self . on_user_offline ( nickname )
def virt_conf ( self , conf , template_repo = None , template_store = None , do_bootstrap = True , do_build = True ) : """Initializes all the virt infrastructure of the prefix , creating the domains disks , doing any network leases and creating all the virt related files and dirs inside this prefix . Args : ...
os . environ [ 'LAGO_PREFIX_PATH' ] = self . paths . prefix_path ( ) with utils . RollbackContext ( ) as rollback : rollback . prependDefer ( shutil . rmtree , self . paths . prefix_path ( ) , ignore_errors = True ) self . _metadata = { 'lago_version' : pkg_resources . get_distribution ( "lago" ) . version , } ...
def get_order_info ( self , order_id , _async = False ) : """查询某个订单 : param order _ id : : return :"""
params = { } path = f'/v1/order/orders/{order_id}' return api_key_get ( params , path , _async = _async )
def config ( config , fork_name = "" , origin_name = "" ) : """Setting various configuration options"""
state = read ( config . configfile ) any_set = False if fork_name : update ( config . configfile , { "FORK_NAME" : fork_name } ) success_out ( "fork-name set to: {}" . format ( fork_name ) ) any_set = True if origin_name : update ( config . configfile , { "ORIGIN_NAME" : origin_name } ) success_out ...
def existing_choice_control ( self ) : """It controls errors . It generates an error message if zero or more than one channels are selected ."""
self . current . task_data [ 'existing' ] = False self . current . task_data [ 'msg' ] = _ ( u"You should choose just one channel to do operation." ) keys , names = self . return_selected_form_items ( self . input [ 'form' ] [ 'ChannelList' ] ) if len ( keys ) == 1 : self . current . task_data [ 'existing' ] = True...
def from_dict ( cls , coll , d ) : """Construct from dict : param coll : Collection for the mark : param d : Input : type d : dict : return : new instance : rtype : Mark"""
return Mark ( collection = coll , operation = Operation [ d [ cls . FLD_OP ] ] , pos = d [ cls . FLD_MARK ] , field = d [ cls . FLD_FLD ] )
def exportdb ( outdir ) : """Export all anchore images to JSON files"""
ecode = 0 try : imgdir = os . path . join ( outdir , "images" ) feeddir = os . path . join ( outdir , "feeds" ) storedir = os . path . join ( outdir , "storedfiles" ) for d in [ outdir , imgdir , feeddir , storedir ] : if not os . path . exists ( d ) : os . makedirs ( d ) anchore...
def LighterColor ( self , level ) : '''Create a new instance based on this one but lighter . Parameters : : level : The amount by which the color should be lightened to produce the new one [ 0 . . . 1 ] . Returns : A grapefruit . Color instance . > > > Color . NewFromHsl ( 30 , 1 , 0.5 ) . LighterColo...
h , s , l = self . __hsl return Color ( ( h , s , min ( l + level , 1 ) ) , 'hsl' , self . __a , self . __wref )
def resolution ( self , index ) : """Resolution with a given index . Parameters index : int Resolution index . Global if this is the ` ` aionationstates . wa ` ` object , local if this is ` ` aionationstates . ga ` ` or ` ` aionationstates . sc ` ` . Returns : class : ` ApiQuery ` of : class : ` Resol...
@ api_query ( 'resolution' , id = str ( index ) ) async def result ( _ , root ) : elem = root . find ( 'RESOLUTION' ) if not elem : raise NotFound ( f'No resolution found with index {index}' ) return Resolution ( elem ) return result ( self )
def getLockStatsDB ( self ) : """Returns the number of active lock discriminated by database . @ return : : Dictionary of stats ."""
info_dict = { 'all' : { } , 'wait' : { } } cur = self . _conn . cursor ( ) cur . execute ( "SELECT d.datname, l.granted, COUNT(*) FROM pg_database d " "JOIN pg_locks l ON d.oid=l.database " "GROUP BY d.datname, l.granted;" ) rows = cur . fetchall ( ) for ( db , granted , cnt ) in rows : info_dict [ 'all' ] [ db ] =...
def nl_recv ( sk , nla , buf , creds = None ) : """Receive data from Netlink socket . https : / / github . com / thom311 / libnl / blob / libnl3_2_25 / lib / nl . c # L625 Receives data from a connected netlink socket using recvmsg ( ) and returns the number of bytes read . The read data is stored in a newly ...
flags = 0 page_size = resource . getpagesize ( ) * 4 if sk . s_flags & NL_MSG_PEEK : flags |= socket . MSG_PEEK | socket . MSG_TRUNC iov_len = sk . s_bufsize or page_size if creds and sk . s_flags & NL_SOCK_PASSCRED : raise NotImplementedError # TODO https : / / github . com / Robpol86 / libnl / issues / 2 whil...
def wysiwyg_setup ( protocol = "http" , editor_override = None ) : """Create the < style > and < script > tags needed to initialize the rich text editor . Create a local django _ wysiwyg / includes . html template if you don ' t want to use Yahoo ' s CDN"""
ctx = { "protocol" : protocol , } ctx . update ( get_settings ( editor_override = editor_override ) ) return render_to_string ( "django_wysiwyg/%s/includes.html" % ctx [ 'DJANGO_WYSIWYG_FLAVOR' ] , ctx )
def copy ( cell ) : """Copy the contents of a SpiceCell of any data type to another cell of the same type . http : / / naif . jpl . nasa . gov / pub / naif / toolkit _ docs / C / cspice / copy _ c . html : param cell : Cell to be copied . : type cell : spiceypy . utils . support _ types . SpiceCell : retu...
assert isinstance ( cell , stypes . SpiceCell ) # Next line was redundant with [ raise NotImpImplementedError ] below # assert cell . dtype = = 0 or cell . dtype = = 1 or cell . dtype = = 2 if cell . dtype is 0 : newcopy = stypes . SPICECHAR_CELL ( cell . size , cell . length ) elif cell . dtype is 1 : newcopy ...
def makeDataFiles ( prefix , dir ) : """Create distutils data _ files structure from dir distutil will copy all file rooted under dir into prefix , excluding dir itself , just like ' ditto src dst ' works , and unlike ' cp - r src dst , which copy src into dst ' . Typical usage : # install the contents of...
# Strip ' dir / ' from of path before joining with prefix dir = dir . rstrip ( '/' ) strip = len ( dir ) + 1 found = [ ] os . path . walk ( dir , visit , ( prefix , strip , found ) ) # print found [ 0] return found [ 0 ]
def update_vertices ( self , vertices ) : """Update the triangle vertices ."""
vertices = np . array ( vertices , dtype = np . float32 ) self . _vbo_v . set_data ( vertices )
def discard ( self , key ) : """Remove an element . Do not raise an exception if absent . The MutableSet mixin uses this to implement the . remove ( ) method , which * does * raise an error when asked to remove a non - existent item ."""
if key in self : i = self . map [ key ] del self . items [ i ] del self . map [ key ] for k , v in self . map . items ( ) : if v >= i : self . map [ k ] = v - 1
async def initialize ( self , timeout = 2.0 ) : """Launch any background tasks associated with this subsystem . This method will synchronously await self . initialized ( ) which makes sure that the background tasks start up correctly ."""
if self . initialized . is_set ( ) : raise InternalError ( "initialize called when already initialized" ) self . _emulator . add_task ( 8 , self . _reset_vector ( ) ) await asyncio . wait_for ( self . initialized . wait ( ) , timeout = timeout )
def reset_query_marks ( self ) : """set or reset hyb and neighbors marks to atoms ."""
for i , atom in self . atoms ( ) : neighbors = 0 hybridization = 1 p_neighbors = 0 p_hybridization = 1 # hyb 1 - sp3 ; 2 - sp2 ; 3 - sp1 ; 4 - aromatic for j , bond in self . _adj [ i ] . items ( ) : isnth = self . _node [ j ] . element != 'H' order = bond . order if orde...
def set_faultset_name ( self , name , fsObj ) : """Set name for Faultset : param name : Name of Faultset : param fsObj : ScaleIO FS object : return : POST request response : rtype : Requests POST response object"""
# Set name of FaultSet self . conn . connection . _check_login ( ) faultSetNameDict = { 'Name' : name } # This one is the most logical name comparing to other methods . response = self . conn . connection . _do_post ( "{}/{}{}/{}" . format ( self . conn . connection . _api_url , "types/FaultSet::" , fsObj . id , 'insta...
def _get_name ( self ) : """Find name of scoring function ."""
if self . name is not None : return self . name if self . scoring_ is None : return 'score' if isinstance ( self . scoring_ , str ) : return self . scoring_ if isinstance ( self . scoring_ , partial ) : return self . scoring_ . func . __name__ if isinstance ( self . scoring_ , _BaseScorer ) : return...
def get_effective_agent_id_with_proxy ( proxy ) : """Given a Proxy , returns the Id of the effective Agent"""
if is_authenticated_with_proxy ( proxy ) : if proxy . has_effective_agent ( ) : return proxy . get_effective_agent_id ( ) else : return proxy . get_authentication ( ) . get_agent_id ( ) else : return Id ( identifier = 'MC3GUE$T@MIT.EDU' , namespace = 'authentication.Agent' , authority = 'MIT...
def _mark_grid_bounds ( self , plane , region_bbox ) : """Assume all lines define a complete grid over the region _ bbox . Detect which lines are missing so that we can recover merged cells ."""
# Grid boundaries vbars = np . zeros ( [ self . num_rows , self . num_cols + 1 ] , dtype = np . bool ) hbars = np . zeros ( [ self . num_rows + 1 , self . num_cols ] , dtype = np . bool ) def closest_idx ( arr , elem ) : left = bisect . bisect_left ( arr , elem ) - 1 right = bisect . bisect_right ( arr , elem )...
def set_weather ( self , weather_type ) : """Queue up a set weather command . It will be applied when ` tick ` or ` step ` is called next . By the next tick , the lighting , skysphere , fog , and relevant particle systems will be updated and / or spawned to the given weather . If there is no skysphere or direct...
if not SetWeatherCommand . has_type ( weather_type . lower ( ) ) : raise HolodeckException ( "Invalid weather type " + weather_type ) self . _should_write_to_command_buffer = True command_to_send = SetWeatherCommand ( weather_type . lower ( ) ) self . _commands . add_command ( command_to_send )
def mode_clipboard_watch ( options ) : """Clipboard Watch Mode : watches for a new string on the clipboard , and tries to fetch that URL"""
articles = set ( ) failures = set ( ) print ( 'Hello, this is news-scraper. Copy a URL to start!' ) print ( 'To quit, press CTRL+C in this window.\n' ) url = pyperclip . paste ( ) while True : try : tmp_value = pyperclip . paste ( ) if tmp_value != url : url = tmp_value print...
def ip_rtm_config_route_static_route_nh_static_route_dest ( self , ** kwargs ) : """Auto Generated Code"""
config = ET . Element ( "config" ) ip = ET . SubElement ( config , "ip" , xmlns = "urn:brocade.com:mgmt:brocade-common-def" ) rtm_config = ET . SubElement ( ip , "rtm-config" , xmlns = "urn:brocade.com:mgmt:brocade-rtm" ) route = ET . SubElement ( rtm_config , "route" ) static_route_nh = ET . SubElement ( route , "stat...
def get_resources_by_query ( self , resource_query ) : """Gets a list of ` ` Resources ` ` matching the given resource query . arg : resource _ query ( osid . resource . ResourceQuery ) : the resource query return : ( osid . resource . ResourceList ) - the returned ` ` ResourceList ` ` raise : NullArgumen...
# Implemented from template for # osid . resource . ResourceQuerySession . get _ resources _ by _ query and_list = list ( ) or_list = list ( ) for term in resource_query . _query_terms : if '$in' in resource_query . _query_terms [ term ] and '$nin' in resource_query . _query_terms [ term ] : and_list . appe...
def get_toplosses_idxs ( cls , learn , n_imgs , ** kwargs ) : "Sorts ` ds _ type ` dataset by top losses and returns dataset and sorted indices ."
dl = learn . data . fix_dl if not n_imgs : n_imgs = len ( dl . dataset ) _ , _ , top_losses = learn . get_preds ( ds_type = DatasetType . Fix , with_loss = True ) idxs = torch . topk ( top_losses , n_imgs ) [ 1 ] return cls . padded_ds ( dl . dataset , ** kwargs ) , idxs
def length ( self , chain = - 1 ) : """Return the length of the trace . : Parameters : chain : int or None The chain index . If None , returns the combined length of all chains ."""
if chain is not None : return len ( self . _vlarrays [ chain ] ) else : return sum ( map ( len , self . _vlarrays ) )
def fit_model ( df , filters , model_expression ) : """Use statsmodels OLS to construct a model relation . Parameters df : pandas . DataFrame Data to use for fit . Should contain all the columns referenced in the ` model _ expression ` . filters : list of str Any filters to apply before doing the model ...
df = util . apply_filter_query ( df , filters ) model = smf . ols ( formula = model_expression , data = df ) if len ( model . exog ) != len ( df ) : raise ModelEvaluationError ( 'Estimated data does not have the same length as input. ' 'This suggests there are null values in one or more of ' 'the input columns.' )...
def get_view ( self , table ) : """Returns the SQL query for a view , or None if it doesn ' t exist or is not a view . : param table : The table containing the view . : type table : BQTable"""
request = self . client . tables ( ) . get ( projectId = table . project_id , datasetId = table . dataset_id , tableId = table . table_id ) try : response = request . execute ( ) except http . HttpError as ex : if ex . resp . status == 404 : return None raise return response [ 'view' ] [ 'query' ] i...
def _ScheduleGenericHunt ( hunt_obj ) : """Adds foreman rules for a generic hunt ."""
# TODO : Migrate foreman conditions to use relation expiration # durations instead of absolute timestamps . foreman_condition = foreman_rules . ForemanCondition ( creation_time = rdfvalue . RDFDatetime . Now ( ) , expiration_time = hunt_obj . init_start_time + hunt_obj . duration , description = "Hunt %s %s" % ( hunt_o...
def unparse_qsl ( qsl , sort = False , reverse = False ) : """Reverse conversion for parse _ qsl"""
result = [ ] items = qsl if sort : items = sorted ( items , key = lambda x : x [ 0 ] , reverse = reverse ) for keys , values in items : query_name = quote ( keys ) result . append ( query_name + "=" + quote ( values ) ) return "&" . join ( result )
def process_json_file ( file_name ) : """Return an EidosProcessor by processing the given Eidos JSON - LD file . This function is useful if the output from Eidos is saved as a file and needs to be processed . Parameters file _ name : str The name of the JSON - LD file to be processed . Returns ep : Ei...
try : with open ( file_name , 'rb' ) as fh : json_str = fh . read ( ) . decode ( 'utf-8' ) return process_json_str ( json_str ) except IOError : logger . exception ( 'Could not read file %s.' % file_name )
def _get_9q_square_qvm ( name : str , noisy : bool , connection : ForestConnection = None , qvm_type : str = 'qvm' ) -> QuantumComputer : """A nine - qubit 3x3 square lattice . This uses a " generic " lattice not tied to any specific device . 9 qubits is large enough to do vaguely interesting algorithms and sma...
topology = nx . convert_node_labels_to_integers ( nx . grid_2d_graph ( 3 , 3 ) ) return _get_qvm_with_topology ( name = name , connection = connection , topology = topology , noisy = noisy , requires_executable = True , qvm_type = qvm_type )
def prettyMatcherList ( things ) : """Try to construct a nicely - formatted string for a list of matcher objects . Those may be compiled regular expressions or strings . . ."""
norm = [ ] for x in makeSequence ( things ) : if hasattr ( x , 'pattern' ) : norm . append ( x . pattern ) else : norm . append ( x ) return "('%s')" % "', '" . join ( norm )
def bind ( self , prefix , namespace , * args , ** kwargs ) : """Extends the function to add an attribute to the class for each added namespace to allow for use of dot notation . All prefixes are converted to lowercase Args : prefix : string of namespace name namespace : rdflib . namespace instance kwar...
# RdfNamespace ( prefix , namespace , * * kwargs ) setattr ( self , prefix , RdfNamespace ( prefix , namespace , ** kwargs ) ) if kwargs . pop ( 'calc' , True ) : self . __make_dicts__
def _load_private_key_file ( fname ) : """Loads an onion - service private - key from the given file . This can be either a ' key blog ' as returned from a previous ADD _ ONION call , or a v3 or v2 file as created by Tor when using the HiddenServiceDir directive . In any case , a key - blob suitable for ADD...
with open ( fname , "rb" ) as f : data = f . read ( ) if b"\x00\x00\x00" in data : # v3 private key file blob = data [ data . find ( b"\x00\x00\x00" ) + 3 : ] return u"ED25519-V3:{}" . format ( b2a_base64 ( blob . strip ( ) ) . decode ( 'ascii' ) . strip ( ) ) if b"-----BEGIN RSA PRIVATE KEY-----" in data :...
def set_coordinate_selection ( self , selection , value , fields = None ) : """Modify a selection of individual items , by providing the indices ( coordinates ) for each item to be modified . Parameters selection : tuple An integer ( coordinate ) array for each dimension of the array . value : scalar or a...
# guard conditions if self . _read_only : err_read_only ( ) # refresh metadata if not self . _cache_metadata : self . _load_metadata_nosync ( ) # setup indexer indexer = CoordinateIndexer ( selection , self ) # handle value - need to flatten if not is_scalar ( value , self . _dtype ) : value = np . asanyarr...
def maximize ( self , element : Expression [ z3 . ExprRef ] ) -> None : """In solving this solver will try to maximize the passed expression . : param element :"""
self . raw . maximize ( element . raw )
def main ( argString = None ) : """The main function of the module . : param argString : the options . : type argString : list These are the steps : 1 . Prints the options . 2 . Compute frequency using Plink . 3 . Runs bafRegress ."""
# Getting and checking the options args = parseArgs ( argString ) checkArgs ( args ) logger . info ( "Options used:" ) for key , value in vars ( args ) . iteritems ( ) : logger . info ( " --{} {}" . format ( key . replace ( "_" , "-" ) , value ) ) # Checks the sample raw data logger . info ( "Checking the raw data...
def uint8 ( self , val ) : """append a frame containing a uint8"""
try : self . msg += [ pack ( "B" , val ) ] except struct . error : raise ValueError ( "Expected uint32" ) return self
def _read_current_marker ( self ) : """Reads the current marker and returns its genotypes ."""
return self . _geno_values [ np . frombuffer ( self . _bed . read ( self . _nb_bytes ) , dtype = np . uint8 ) ] . flatten ( order = "C" ) [ : self . _nb_samples ]
def validate_raw_manifest_format ( raw_manifest : str ) -> None : """Raise a ValidationError if a manifest . . . - is not tightly packed ( i . e . no linebreaks or extra whitespace ) - does not have alphabetically sorted keys - has duplicate keys - is not UTF - 8 encoded - has a trailing newline"""
try : manifest_dict = json . loads ( raw_manifest , encoding = "UTF-8" ) except json . JSONDecodeError as err : raise json . JSONDecodeError ( "Failed to load package data. File is not a valid JSON document." , err . doc , err . pos , ) compact_manifest = json . dumps ( manifest_dict , sort_keys = True , separa...
def filter_picks ( catalog , stations = None , channels = None , networks = None , locations = None , top_n_picks = None , evaluation_mode = 'all' ) : """Filter events in the catalog based on a number of parameters . : param catalog : Catalog to filter . : type catalog : obspy . core . event . Catalog : param...
# Don ' t work in place on the catalog filtered_catalog = catalog . copy ( ) if stations : for event in filtered_catalog : if len ( event . picks ) == 0 : continue event . picks = [ pick for pick in event . picks if pick . waveform_id . station_code in stations ] if channels : for ev...
def get_suffix ( name ) : """Check if file name have valid suffix for formatting . if have suffix return it else return False ."""
a = name . count ( "." ) if a : ext = name . split ( "." ) [ - 1 ] if ext in LANGS . keys ( ) : return ext return False else : return False
def remove ( self , func ) : """Remove any provisioned log sink if auto created"""
if not self . data [ 'name' ] . startswith ( self . prefix ) : return parent = self . get_parent ( self . get_log ( ) ) _ , sink_path , _ = self . get_sink ( ) client = self . session . client ( 'logging' , 'v2' , '%s.sinks' % ( parent . split ( '/' , 1 ) [ 0 ] ) ) try : client . execute_command ( 'delete' , { ...
def _parse_kexgss_init ( self , m ) : """Parse the SSH2 _ MSG _ KEXGSS _ INIT message ( server mode ) . : param ` . Message ` m : The content of the SSH2 _ MSG _ KEXGSS _ INIT message"""
# server mode client_token = m . get_string ( ) self . e = m . get_mpint ( ) if ( self . e < 1 ) or ( self . e > self . P - 1 ) : raise SSHException ( 'Client kex "e" is out of range' ) K = pow ( self . e , self . x , self . P ) self . transport . host_key = NullHostKey ( ) key = self . transport . host_key . __str...
def load_resources ( bucket , prefix , region , account_config , accounts , assume , start , end , resources , store , db , verbose , debug ) : """load resources into resource database ."""
logging . basicConfig ( level = ( verbose and logging . DEBUG or logging . INFO ) ) logging . getLogger ( 'botocore' ) . setLevel ( logging . WARNING ) logging . getLogger ( 's3transfer' ) . setLevel ( logging . WARNING ) start = date_parse ( start ) end = date_parse ( end ) if not resources : resources = [ 'Networ...
def discard ( self , val ) : """Remove the first occurrence of * val * . If * val * is not a member , does nothing ."""
_maxes = self . _maxes if not _maxes : return key = self . _key ( val ) pos = bisect_left ( _maxes , key ) if pos == len ( _maxes ) : return _keys = self . _keys _lists = self . _lists idx = bisect_left ( _keys [ pos ] , key ) len_keys = len ( _keys ) len_sublist = len ( _keys [ pos ] ) while True : if _key...
def ParseSearchRow ( self , parser_mediator , query , row , ** unused_kwargs ) : """Parses a search row from the database . Args : parser _ mediator ( ParserMediator ) : mediates interactions between parsers and other components , such as storage and dfvfs . query ( str ) : query that created the row . ro...
query_hash = hash ( query ) event_data = TwitterAndroidSearchEventData ( ) event_data . query = query event_data . name = self . _GetRowValue ( query_hash , row , 'name' ) event_data . search_query = self . _GetRowValue ( query_hash , row , 'query' ) timestamp = self . _GetRowValue ( query_hash , row , 'time' ) if time...
def init_drivers ( enable_debug_driver = False ) : """Initialize all the drivers ."""
for driver in DRIVERS : try : if driver != DebugDriver or enable_debug_driver : CLASSES . append ( driver ) except Exception : # pylint : disable = W0703 continue
def plot_chempot_range_map ( self , elements , referenced = True ) : """Plot the chemical potential range _ map . Currently works only for 3 - component PDs . Args : elements : Sequence of elements to be considered as independent variables . E . g . , if you want to show the stability ranges of all Li - C...
self . get_chempot_range_map_plot ( elements , referenced = referenced ) . show ( )
def neural_networks ( self ) : """List of the neural networks in the ensemble . Returns list of ` Class1NeuralNetwork `"""
result = [ ] for models in self . allele_to_allele_specific_models . values ( ) : result . extend ( models ) result . extend ( self . class1_pan_allele_models ) return result