signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def run ( app : web . Application ) :
"""Runs the application in an async context .
This function will block indefinitely until the application is shut down .
Args :
app ( web . Application ) :
The Aiohttp Application as created by ` create _ app ( ) `""" | host = app [ 'config' ] [ 'host' ]
port = app [ 'config' ] [ 'port' ]
# starts app . run _ app ( ) will automatically start the async context .
web . run_app ( app , host = host , port = port ) |
def mavlink_packet ( self , m ) :
'''handle an incoming mavlink packet''' | if not self . mpstate . map : # don ' t draw if no map
return
if m . get_type ( ) != 'GIMBAL_REPORT' :
return
needed = [ 'ATTITUDE' , 'GLOBAL_POSITION_INT' ]
for n in needed :
if not n in self . master . messages :
return
# clear the camera icon
self . mpstate . map . add_object ( mp_slipmap . SlipC... |
def gamma_centered ( cls , kpts = ( 1 , 1 , 1 ) , use_symmetries = True , use_time_reversal = True ) :
"""Convenient static constructor for an automatic Gamma centered Kpoint grid .
Args :
kpts : Subdivisions N _ 1 , N _ 2 and N _ 3 along reciprocal lattice vectors .
use _ symmetries : False if spatial symmet... | return cls ( kpts = [ kpts ] , kpt_shifts = ( 0.0 , 0.0 , 0.0 ) , use_symmetries = use_symmetries , use_time_reversal = use_time_reversal , comment = "gamma-centered mode" ) |
def create_with_validation ( cls , * args , ** kwargs ) :
"""Factory method that creates and validates the model object before it is saved .""" | ret_val = cls ( * args , ** kwargs )
ret_val . full_clean ( )
ret_val . save ( )
return ret_val |
def form_valid ( self , post_form , attachment_formset , ** kwargs ) :
"""Processes valid forms .
Called if all forms are valid . Creates a Post instance along with associated attachments if
required and then redirects to a success page .""" | save_attachment_formset = attachment_formset is not None and not self . preview
if self . preview :
return self . render_to_response ( self . get_context_data ( preview = True , post_form = post_form , attachment_formset = attachment_formset , ** kwargs ) , )
# This is not a preview ; the object is going to be save... |
def _get_analysis_type ( analysis_types : List [ str ] ) -> str :
"""Determine the overall analysis type .""" | types_set = set ( analysis_types )
return types_set . pop ( ) if len ( types_set ) == 1 else 'wgs' |
def re_run_last_cell ( self ) :
"""Run the previous cell again .""" | text , line = ( self . get_current_editor ( ) . get_last_cell_as_executable_code ( ) )
self . _run_cell_text ( text , line ) |
async def post ( self , path , data = { } , send_raw = False , ** params ) :
'''sends post request
Parameters
path : str
same as get _ url
query : kargs dict
additional info to pass to get _ url
See Also
get _ url :
Returns
requests . models . Response
the response that was given''' | url = self . get_url ( path , ** params )
jstr = json . dumps ( data )
for i in range ( self . tries + 1 ) :
try :
if send_raw :
resp = await self . session . post ( url , data = data , timeout = self . timeout )
else :
resp = await self . session . post ( url , data = jstr ,... |
def zoomlevel ( self ) :
"""Retrieves zoomlevel from the output response
Returns :
zoomlevel ( namedtuple ) : A namedtuple of zoomlevel from the output
response""" | resources = self . get_resource ( )
zoomlevel = namedtuple ( 'zoomlevel' , 'zoomLevel' )
try :
return [ zoomlevel ( resource [ 'zoomLevel' ] ) for resource in resources ]
except TypeError :
try :
if isinstance ( resources [ 'ElevationData' ] , dict ) :
return zoomlevel ( resources [ 'Elevati... |
def get_response ( self ) :
"""Generate the response block of this request .
Careful : it only sets the fields which can be set from the request""" | res = IODWriteMultipleRes ( )
for field in [ "seqNum" , "ARUUID" , "API" , "slotNumber" , "subslotNumber" , "index" ] :
res . setfieldval ( field , self . getfieldval ( field ) )
# append all block response
res_blocks = [ ]
for block in self . getfieldval ( "blocks" ) :
res_blocks . append ( block . get_respons... |
def format_filename ( series_name , season_number , episode_numbers , episode_names , extension ) :
"""Generates a filename based on metadata using configured format .
: param str series _ name : name of TV series
: param int season _ number : the numeric season of series
: param list ( int ) episode _ number... | epdata = { 'seriesname' : tc . titlecase ( _replace_series_name ( series_name , cfg . CONF . output_series_replacements ) or '' ) , 'seasonnumber' : season_number , 'episode' : _format_episode_numbers ( episode_numbers ) , 'episodename' : tc . titlecase ( _format_episode_name ( episode_names ) ) , 'ext' : extension , }... |
def make_carrier_tone ( freq , db , dur , samplerate , caldb = 100 , calv = 0.1 ) :
"""Produce a pure tone signal
: param freq : Frequency of the tone to be produced ( Hz )
: type freq : int
: param db : Intensity of the tone in dB SPL
: type db : int
: param dur : duration ( seconds )
: type dur : floa... | if samplerate <= 0 :
raise ValueError ( "Samplerate must be greater than 0" )
if caldb <= 0 :
raise ValueError ( "Calibration dB SPL must be greater than 0" )
npts = int ( dur * samplerate )
amp = ( 10 ** ( ( db - caldb ) / 20 ) * calv )
if USE_RMS :
amp *= 1.414213562373
if VERBOSE :
print ( "current d... |
def add_var_arg ( self , arg_index ) :
"""Add a command to the submit file to allow variable ( macro ) arguments
to be passed to the executable .""" | try :
self . __var_args [ arg_index ]
except IndexError :
if arg_index != self . __arg_index :
raise CondorDAGJobError , "mismatch between job and node var_arg index"
self . __var_args . append ( '$(macroargument%s)' % str ( arg_index ) )
self . add_arg ( self . __var_args [ self . __arg_index ]... |
def merge_deltas ( stmts_in ) :
"""Gather and merge original Influence delta information from evidence .
This function is only applicable to Influence Statements that have
subj and obj deltas . All other statement types are passed through unchanged .
Polarities and adjectives for subjects and objects respecti... | stmts_out = [ ]
for stmt in stmts_in : # This operation is only applicable to Influences
if not isinstance ( stmt , Influence ) :
stmts_out . append ( stmt )
continue
# At this point this is guaranteed to be an Influence
deltas = { }
for role in ( 'subj' , 'obj' ) :
for info in (... |
def replaceData ( self , offset : int , count : int , string : str ) -> None :
"""Replace data from offset to count by string .""" | self . _replace_data ( offset , count , string ) |
def gridOn ( self ) : # noqa : N802
"""Control whether the gridline is drawn for this tick .""" | return ( self . _gridOn and ( self . _has_default_loc ( ) or transforms . interval_contains ( self . get_view_interval ( ) , self . get_loc ( ) ) ) ) |
def as_bulk_queries ( queries , bulk_size ) :
"""Group a iterable of ( stmt , args ) by stmt into ( stmt , bulk _ args ) .
bulk _ args will be a list of the args grouped by stmt .
len ( bulk _ args ) will be < = bulk _ size""" | stmt_dict = defaultdict ( list )
for stmt , args in queries :
bulk_args = stmt_dict [ stmt ]
bulk_args . append ( args )
if len ( bulk_args ) == bulk_size :
yield stmt , bulk_args
del stmt_dict [ stmt ]
for stmt , bulk_args in stmt_dict . items ( ) :
yield stmt , bulk_args |
def set_fitness ( self , v ) :
"""Set the fitness to a new node .
Returns false in case fitness is not finite""" | base = self . _base
self . fitness ( v )
if not np . isfinite ( v . fitness ) :
self . del_error ( v )
return False
if base . _tr_fraction < 1 :
self . fitness_vs ( v )
if not np . isfinite ( v . fitness_vs ) :
self . del_error ( v )
return False
self . del_error ( v )
return True |
def head ( self , * args , ** kwargs ) :
"""Executes an HTTP HEAD .
: Parameters :
- ` args ` : Non - keyword arguments
- ` kwargs ` : Keyword arguments""" | return self . session . head ( * args , ** self . get_kwargs ( ** kwargs ) ) |
def collect_from_bundle ( self , bundle : Bundle ) -> Dict [ str , Any ] :
"""Collect objects where : meth : ` type _ check ` returns ` ` True ` ` from bundles .
Bundle subclasses can override objects discovered in superclass bundles .""" | members = { }
hierarchy = ( [ bundle ] if not self . discover_from_bundle_superclasses else bundle . _iter_class_hierarchy ( ) )
for bundle in hierarchy :
module = self . import_bundle_module ( bundle )
if not module :
continue
members . update ( self . _collect_from_package ( module ) )
return memb... |
def _find_attrNodeNS ( E , namespaceURI , localName ) :
'''Must grab the attribute Node to distinquish between
an unspecified attribute ( None ) and one set to empty string ( " " ) .
namespaceURI
localName''' | attr = E . getAttributeNodeNS ( namespaceURI , localName )
if attr is None :
return None
try :
return attr . value
except :
pass
return E . getAttributeNS ( namespaceURI , localName ) |
def _find_attrNS ( E , namespaceURI , localName ) :
'''namespaceURI
localName''' | try :
v = E . getAttributeNS ( namespaceURI , localName )
if v :
return v
except :
pass
return None |
def t_NUMBER ( self , t ) :
r'( \ d + ( \ . \ d * ) ? | \ . \ d + ) ( [ eE ] [ + - ] ? \ d + ) ? ( kb | gb | mb | tb | pb | Kb | Gb | Mb | Tb | Pb ) ?' | if re . match ( r'^(\d+(\.\d*)?|\.\d+)([eE][+-]?\d+)?(kb|gb|mb|tb|pb|Kb|Gb|Mb|Tb|Pb)?$' , t . value ) :
multiplyer = 1
try :
suffix = ( t . value [ - 2 : ] ) . lower ( )
if suffix in [ 'kb' ] :
multiplyer = 1024
elif suffix in [ 'mb' ] :
multiplyer = 1024 * 1024
... |
def cklpf ( filename ) :
"""Load a CK pointing file for use by the CK readers . Return that
file ' s handle , to be used by other CK routines to refer to the
file .
http : / / naif . jpl . nasa . gov / pub / naif / toolkit _ docs / C / cspice / cklpf _ c . html
: param filename : Name of the CK file to be l... | filename = stypes . stringToCharP ( filename )
handle = ctypes . c_int ( )
libspice . cklpf_c ( filename , ctypes . byref ( handle ) )
return handle . value |
def generate_sample_sls_module ( env_root , module_dir = None ) :
"""Generate skeleton Serverless sample module .""" | if module_dir is None :
module_dir = os . path . join ( env_root , 'sampleapp.sls' )
generate_sample_module ( module_dir )
for i in [ 'config-dev-us-east-1.json' , 'handler.py' , 'package.json' , 'serverless.yml' ] :
shutil . copyfile ( os . path . join ( ROOT , 'templates' , 'serverless' , i ) , os . path . jo... |
def start_log_monitor ( self ) :
"""Start the log monitor .""" | stdout_file , stderr_file = self . new_log_files ( "log_monitor" )
process_info = ray . services . start_log_monitor ( self . redis_address , self . _logs_dir , stdout_file = stdout_file , stderr_file = stderr_file , redis_password = self . _ray_params . redis_password )
assert ray_constants . PROCESS_TYPE_LOG_MONITOR ... |
def get_relationships ( self ) :
"""Gets the relationship list resulting from a search .
return : ( osid . relationship . RelationshipList ) - the relationship
list
raise : IllegalState - list already retrieved
* compliance : mandatory - - This method must be implemented . *""" | if self . retrieved :
raise errors . IllegalState ( 'List has already been retrieved.' )
self . retrieved = True
return objects . RelationshipList ( self . _results , runtime = self . _runtime ) |
def tabulate_body ( obj , level_keys , v_level_indexes , h_level_indexes , v_level_sort_keys = None , h_level_sort_keys = None , ) :
"""Args :
v _ level _ indexes : A sequence of level indexes .
h _ level _ indexes : A sequence of level indexes .""" | v_key_sorted = make_sorter ( v_level_sort_keys , v_level_indexes )
h_key_sorted = make_sorter ( h_level_sort_keys , h_level_indexes )
h_level_keys = [ level_keys [ level ] for level in h_level_indexes ]
v_level_keys = [ level_keys [ level ] for level in v_level_indexes ]
h_key_tuples = h_key_sorted ( product ( * h_leve... |
def predict_expectation ( self , X , ancillary_X = None ) :
"""Predict the expectation of lifetimes , : math : ` E [ T | x ] ` .
Parameters
X : numpy array or DataFrame
a ( n , d ) covariate numpy array or DataFrame . If a DataFrame , columns
can be in any order . If a numpy array , columns must be in the
... | lambda_ , rho_ = self . _prep_inputs_for_prediction_and_return_scores ( X , ancillary_X )
return pd . DataFrame ( ( lambda_ * gamma ( 1 + 1 / rho_ ) ) , index = _get_index ( X ) ) |
def write_data ( self , data , dstart = None , swap_axes = True ) :
"""Write ` ` data ` ` to ` file ` .
Parameters
data : ` array - like `
Data that should be written to ` file ` .
dstart : non - negative int , optional
Offset in bytes of the start position of the written data .
If provided , reshaping ... | if dstart is None :
shape = self . data_shape
dstart = int ( self . header_size )
elif dstart < 0 :
raise ValueError ( '`dstart` must be non-negative, got {}' '' . format ( dstart ) )
else :
shape = - 1
dstart = int ( dstart )
if dstart < self . header_size :
raise ValueError ( 'invalid `dstart`... |
def write_warc ( self , resources = None , dumpfile = None ) :
"""Write a WARC dump file .
WARC support is not part of ResourceSync v1.0 ( Z39.99 2014 ) but is left
in this library for experimentation .""" | # Load library late as we want to be able to run rest of code
# without this installed
try :
from warc import WARCFile , WARCHeader , WARCRecord
except :
raise DumpError ( "Failed to load WARC library" )
wf = WARCFile ( dumpfile , mode = "w" , compress = self . compress )
# Add all files in the resources
for re... |
def get_arc ( self , x_start , y , y_curve , x_end ) :
"""Render individual arc .
x _ start ( int ) : X - coordinate of arrow start point .
y ( int ) : Y - coordinate of arrow start and end point .
y _ curve ( int ) : Y - corrdinate of Cubic Bézier y _ curve point .
x _ end ( int ) : X - coordinate of arro... | template = "M{x},{y} C{x},{c} {e},{c} {e},{y}"
if self . compact :
template = "M{x},{y} {x},{c} {e},{c} {e},{y}"
return template . format ( x = x_start , y = y , c = y_curve , e = x_end ) |
def handle_format_group ( self , field , text ) :
"""Handle format group .""" | # Handle auto incrementing group indexes
if field == '' :
if self . auto :
field = str ( self . auto_index )
text [ 0 ] = ( _util . FMT_FIELD , field )
self . auto_index += 1
elif not self . manual and not self . auto :
self . auto = True
field = str ( self . auto_index )... |
def _verify_dict ( self , conf ) :
"""Check that the configuration contains all necessary keys .
: type conf : dict
: rtype : None
: raise SATOSAConfigurationError : if the configuration is incorrect
: param conf : config to verify
: return : None""" | if not conf :
raise SATOSAConfigurationError ( "Missing configuration or unknown format" )
for key in SATOSAConfig . mandatory_dict_keys :
if key not in conf :
raise SATOSAConfigurationError ( "Missing key '%s' in config" % key )
for key in SATOSAConfig . sensitive_dict_keys :
if key not in conf and... |
def load_results ( result_files , options , run_set_id = None , columns = None , columns_relevant_for_diff = set ( ) ) :
"""Version of load _ result for multiple input files that will be loaded concurrently .""" | return parallel . map ( load_result , result_files , itertools . repeat ( options ) , itertools . repeat ( run_set_id ) , itertools . repeat ( columns ) , itertools . repeat ( columns_relevant_for_diff ) ) |
def _get_client ( self ) :
"""Swift client
Returns :
swiftclient . client . Connection : client""" | kwargs = self . _storage_parameters
# Handles unsecure mode
if self . _unsecure :
kwargs = kwargs . copy ( )
kwargs [ 'ssl_compression' ] = False
return _swift . client . Connection ( ** kwargs ) |
def MultimodeCombine ( pupils ) :
"""Return the instantaneous coherent fluxes and photometric fluxes for a
multiway multimode combiner ( no spatial filtering )""" | fluxes = [ np . vdot ( pupils [ i ] , pupils [ i ] ) . real for i in range ( len ( pupils ) ) ]
coherentFluxes = [ np . vdot ( pupils [ i ] , pupils [ j ] ) for i in range ( 1 , len ( pupils ) ) for j in range ( i ) ]
return fluxes , coherentFluxes |
def pip ( self , points , sorted_col = 0 , radius = 0 ) :
"""Point - in - Polygon for the z = 0 projection . This function enhances
the performance of ` ` Polygon . contains ( ) ` ` by verifying only the
points which are inside the bounding box of the polygon . To do
it fast , it needs the points array to be ... | xy = points [ : , : 2 ]
n_points = xy . shape [ 0 ]
index = np . arange ( n_points , dtype = int )
b = self . domain
b [ 0 ] = b [ 0 ] - radius
b [ 1 ] = b [ 1 ] + radius
# Slicing the sorted column
k = np . searchsorted ( xy [ : , sorted_col ] , ( b [ 0 , sorted_col ] , b [ 1 , sorted_col ] + 1e-10 ) )
xy = xy [ k [ 0... |
def execute ( self , container , start = None , end = None , registers = None ) :
"""Execute instructions .""" | if registers :
self . __cpu . registers = dict ( registers )
ip = start if start else container [ 0 ] . address
while ip and ip != end :
try :
instr = container . fetch ( ip )
except ReilContainerInvalidAddressError :
logger . info ( "Invalid address: {:#010x}:{:#02x}" . format ( ip >> 8 , i... |
def _partition_and_stitch ( self , args , func_name ) :
"""args is a list of tensors , to be passed to self . likelihoods . < func _ name >
args [ - 1 ] is the ' Y ' argument , which contains the indexes to self . likelihoods .
This function splits up the args using dynamic _ partition , calls the
relevant fu... | # get the index from Y
Y = args [ - 1 ]
ind = Y [ : , - 1 ]
ind = tf . cast ( ind , tf . int32 )
Y = Y [ : , : - 1 ]
args [ - 1 ] = Y
# split up the arguments into chunks corresponding to the relevant likelihoods
args = zip ( * [ tf . dynamic_partition ( X , ind , self . num_likelihoods ) for X in args ] )
# apply the ... |
def start_task ( self , task_tag , skip_unresolved = False ) :
"""Check dependency for the given task _ tag and start task . For dependency checking see
: meth : ` . WTaskDependencyRegistryStorage . dependency _ check ` . If task is already started then it must be
stopped before it will be started again .
: p... | if self . started_tasks ( task_registry_id = task_tag ) is not None :
return
task_cls = self . tasks_by_tag ( task_tag )
if task_cls is None :
raise RuntimeError ( "Task '%s' wasn't found" % task_tag )
self . dependency_check ( task_cls , skip_unresolved = skip_unresolved )
def start_dependency ( start_task_cls... |
def group_records_by_category ( self ) :
"""Return the records grouped by the category of their source .
The return value is a dict , a key in this dict is a category
and the value is a list of all the records with this category .""" | Source . validate_categories ( categories )
key_function = lambda record : record . source . category
return self . group_records ( key_function ) |
def get_cpu_info_json ( ) :
'''Returns the CPU info by using the best sources of information for your OS .
Returns the result in a json string''' | import json
output = None
# If running under pyinstaller , run normally
if getattr ( sys , 'frozen' , False ) :
info = _get_cpu_info_internal ( )
output = json . dumps ( info )
output = "{0}" . format ( output )
# if not running under pyinstaller , run in another process .
# This is done because multiproces... |
def fastq_iter ( handle , header = None ) :
"""Iterate over FASTQ file and return FASTQ entries
Args :
handle ( file ) : FASTQ file handle , can be any iterator so long as it
it returns subsequent " lines " of a FASTQ entry
header ( str ) : Header line of next FASTQ entry , if ' handle ' has been
partiall... | # Speed tricks : reduces function calls
append = list . append
join = str . join
strip = str . strip
next_line = next
if header is None :
header = next ( handle )
# Read first FASTQ entry header
# Check if input is text or bytestream
if ( isinstance ( header , bytes ) ) :
def next_line ( i ) :
return ne... |
def start_receive ( self , fd , data = None ) :
"""Cause : meth : ` poll ` to yield ` data ` when ` fd ` is readable .""" | self . _rfds [ fd ] = ( data or fd , self . _generation )
self . _update ( fd ) |
def refresh_actions ( self ) :
"""Create options menu .""" | self . options_menu . clear ( )
# Decide what additional actions to show
if self . undocked_window is None :
additional_actions = [ MENU_SEPARATOR , self . undock_action , self . close_plugin_action ]
else :
additional_actions = [ MENU_SEPARATOR , self . dock_action ]
# Create actions list
self . plugin_actions... |
def remapScipy ( im , coords ) :
"""Remap an image using SciPy . See : func : ` remap ` for parameters .""" | height , width = im . shape [ 0 ] , im . shape [ 1 ]
# switch to y , x order
coords = coords [ : , : , : : - 1 ]
# make it ( h , w , 3 , 3)
coords_channels = np . empty ( ( height , width , 3 , 3 ) )
coords_channel = np . zeros ( ( height , width , 3 ) )
coords_channel [ : , : , : 2 ] = coords
coords_channels [ : , : ,... |
def _get_img_attrs ( self , style , kwargs ) :
"""Get the attributes of an an < img > tag for this image , hidpi - aware""" | # Get the 1x and 2x renditions
img_1x , img_2x , size = self . _get_renditions ( kwargs )
return { 'src' : img_1x , 'width' : size [ 0 ] , 'height' : size [ 1 ] , 'srcset' : "{} 1x, {} 2x" . format ( img_1x , img_2x ) if img_1x != img_2x else None , 'style' : ';' . join ( style ) if style else None , 'class' : kwargs .... |
def adjust_for_triggers ( self ) :
"""Remove trigger - related plugins when needed
If there are no triggers defined , it ' s assumed the
feature is disabled and all trigger - related plugins
are removed .
If there are triggers defined , and this is a custom
base image , some trigger - related plugins do n... | triggers = self . template [ 'spec' ] . get ( 'triggers' , [ ] )
remove_plugins = [ ( "prebuild_plugins" , "check_and_set_rebuild" ) , ( "prebuild_plugins" , "stop_autorebuild_if_disabled" ) , ]
should_remove = False
if triggers and ( self . is_custom_base_image ( ) or self . is_from_scratch_image ( ) ) :
if self .... |
def do_ls ( self , nothing = '' ) :
"""list files in current remote directory""" | for d in self . dirs :
self . stdout . write ( "\033[0;34m" + ( '%s\n' % d ) + "\033[0m" )
for f in self . files :
self . stdout . write ( '%s\n' % f ) |
def _describe_atom ( topology , index ) :
"""Returns a string describing the given atom
: param topology :
: param index :
: return :""" | at = topology . atom ( index )
if topology . n_chains > 1 :
return "%s %i %s %i %i" % ( at . residue . name , at . residue . resSeq , at . name , at . index , at . residue . chain . index )
else :
return "%s %i %s %i" % ( at . residue . name , at . residue . resSeq , at . name , at . index ) |
def _example_broker_queue ( quote_ctx ) :
"""获取经纪队列 , 输出 买盘卖盘的经纪ID , 经纪名称 , 经纪档位""" | stock_code_list = [ "HK.00700" ]
for stk_code in stock_code_list :
ret_status , ret_data = quote_ctx . subscribe ( stk_code , ft . SubType . BROKER )
if ret_status != ft . RET_OK :
print ( ret_data )
exit ( )
for stk_code in stock_code_list :
ret_status , bid_data , ask_data = quote_ctx . ge... |
def reset ( self , context ) :
"""Return a reference , forcing close and discard of the underlying
connection . Used for ' meta : reset _ connection ' or when some other error
is detected .""" | LOG . debug ( '%r.reset(%r)' , self , context )
self . _lock . acquire ( )
try :
self . _shutdown_unlocked ( context )
finally :
self . _lock . release ( ) |
def is_interesting ( entry ) :
"""Is this entry interesting ?
` ` entry ` ` is an XML node representing one entry of the svn status
XML output . It looks like this : :
< entry path = " unchanged . txt " >
< wc - status item = " normal " revision = " 1 " props = " none " >
< commit revision = " 1 " >
< a... | if entry . get ( 'path' ) == '.' :
return False
status = entry . find ( 'wc-status' )
if status is None :
warning ( 'svn status --xml parse error: <entry path="%s"> without' ' <wc-status>' % entry . get ( 'path' ) )
return False
# For SVN externals we get two entries : one mentioning the
# existence of the ... |
def port_profile_vlan_profile_switchport_access_mac_group_vlan_classification_access_vlan_access_mac_group ( self , ** kwargs ) :
"""Auto Generated Code""" | config = ET . Element ( "config" )
port_profile = ET . SubElement ( config , "port-profile" , xmlns = "urn:brocade.com:mgmt:brocade-port-profile" )
name_key = ET . SubElement ( port_profile , "name" )
name_key . text = kwargs . pop ( 'name' )
vlan_profile = ET . SubElement ( port_profile , "vlan-profile" )
switchport =... |
def register_app_activity ( ) :
"""Create watchers for models defined in settings . py .
Once created , they will be passed over
Activity . objects . follow _ model ( ) , which lives in managers . py""" | from django . conf import settings
from django . contrib . contenttypes . models import ContentType
from . models import Activity
# TO - DO : Add check for existence of setting
if not hasattr ( settings , 'ACTIVITY_MONITOR_MODELS' ) :
return
for item in settings . ACTIVITY_MONITOR_MODELS :
try :
app_lab... |
def change_column_length ( table : Table , column : Column , length : int , engine : Engine ) -> None :
"""Change the column length in the supplied table""" | if column . type . length < length :
print ( "Changing length of {} from {} to {}" . format ( column , column . type . length , length ) )
column . type . length = length
column_name = column . name
column_type = column . type . compile ( engine . dialect )
engine . execute ( 'ALTER TABLE {table} AL... |
def ibis_schema_apply_to ( schema , df ) :
"""Applies the Ibis schema to a pandas DataFrame
Parameters
schema : ibis . schema . Schema
df : pandas . DataFrame
Returns
df : pandas . DataFrame
Notes
Mutates ` df `""" | for column , dtype in schema . items ( ) :
pandas_dtype = dtype . to_pandas ( )
col = df [ column ]
col_dtype = col . dtype
try :
not_equal = pandas_dtype != col_dtype
except TypeError : # ugh , we can ' t compare dtypes coming from pandas , assume not equal
not_equal = True
if n... |
def calc_wada_waes_v1 ( self ) :
"""Calculate the actual water release from the snow cover .
Required control parameters :
| NHRU |
| Lnk |
| PWMax |
Required flux sequences :
| NBes |
Calculated flux sequence :
| WaDa |
Updated state sequence :
| WAeS |
Basic equations :
: math : ` \\ frac ... | con = self . parameters . control . fastaccess
flu = self . sequences . fluxes . fastaccess
sta = self . sequences . states . fastaccess
for k in range ( con . nhru ) :
if con . lnk [ k ] in ( WASSER , FLUSS , SEE ) :
sta . waes [ k ] = 0.
flu . wada [ k ] = flu . nbes [ k ]
else :
sta .... |
def write_event ( self , event ) :
"""Appends event to the file .""" | # Check if event is of type event _ pb2 . Event proto .
if not isinstance ( event , event_pb2 . Event ) :
raise TypeError ( "expected an event_pb2.Event proto, " " but got %s" % type ( event ) )
return self . _write_serialized_event ( event . SerializeToString ( ) ) |
def process_paper_helper ( model_name , pmid , start_time_local ) :
"""Wraps processing a paper by either a local or remote service
and caches any uncaught exceptions""" | try :
if not aws_available :
rp , txt_format = process_paper ( model_name , pmid )
else :
rp , txt_format = process_paper_aws ( pmid , start_time_local )
except :
logger . exception ( 'uncaught exception while processing %s' , pmid )
return None , None
return rp , txt_format |
async def is_change_done ( self , zone , change_id ) :
"""Check if a DNS change has completed .
Args :
zone ( str ) : DNS zone of the change .
change _ id ( str ) : Identifier of the change .
Returns :
Boolean""" | zone_id = self . get_managed_zone ( zone )
url = f'{self._base_url}/managedZones/{zone_id}/changes/{change_id}'
resp = await self . get_json ( url )
return resp [ 'status' ] == self . DNS_CHANGES_DONE |
def url_encode_stream ( obj , stream = None , charset = 'utf-8' , encode_keys = False , sort = False , key = None , separator = '&' ) :
"""Like : meth : ` url _ encode ` but writes the results to a stream
object . If the stream is ` None ` a generator over all encoded
pairs is returned .
. . versionadded : : ... | gen = _url_encode_impl ( obj , charset , encode_keys , sort , key )
if stream is None :
return gen
for idx , chunk in enumerate ( gen ) :
if idx :
stream . write ( separator )
stream . write ( chunk ) |
def duty_cycle ( self ) :
"""16 bit value that dictates how much of one cycle is high ( 1 ) versus low ( 0 ) . 0xffff will
always be high , 0 will always be low and 0x7fff will be half high and then half low .""" | pwm = self . _pca . pwm_regs [ self . _index ]
if pwm [ 0 ] == 0x1000 :
return 0xffff
return pwm [ 1 ] << 4 |
def ceil ( self ) :
"""Round ` x ` and ` y ` up to integers .""" | return Point ( int ( math . ceil ( self . x ) ) , int ( math . ceil ( self . y ) ) ) |
def ssh_known_host_key ( host , application_name , user = None ) :
"""Return the first entry in known _ hosts for host .
: param host : hostname to lookup in file .
: type host : str
: param application _ name : Name of application eg nova - compute - something
: type application _ name : str
: param user... | cmd = [ 'ssh-keygen' , '-f' , known_hosts ( application_name , user ) , '-H' , '-F' , host ]
try : # The first line of output is like ' # Host xx found : line 1 type RSA ' ,
# which should be excluded .
output = subprocess . check_output ( cmd )
except subprocess . CalledProcessError as e : # RC of 1 seems to be le... |
def source_attr ( attr_name ) :
"""Creates a getter that will drop the current value
and retrieve the source ' s attribute with specified name .
@ param attr _ name : the name of an attribute belonging to the source .
@ type attr _ name : str""" | def source_attr ( _value , context , ** _params ) :
value = getattr ( context [ "model" ] . source , attr_name )
return _attr ( value )
return source_attr |
def neighbors ( self ) :
"""A dictionary with neighbors
The dictionary will have the following form :
` ` { vertexX : ( vertexY1 , vertexY2 , . . . ) , . . . } ` `
This means that vertexX and vertexY1 are connected etc . This also
implies that the following elements are part of the dictionary :
` ` { vert... | neighbors = dict ( ( vertex , [ ] ) for vertex in range ( self . num_vertices ) )
for a , b in self . edges :
neighbors [ a ] . append ( b )
neighbors [ b ] . append ( a )
# turn lists into frozensets
neighbors = dict ( ( key , frozenset ( val ) ) for key , val in neighbors . items ( ) )
return neighbors |
def range ( self , dimension , data_range = True , dimension_range = True ) :
"""Return the lower and upper bounds of values along dimension .
Args :
dimension : The dimension to compute the range on .
data _ range ( bool ) : Compute range from data values
dimension _ range ( bool ) : Include Dimension rang... | dimension = self . get_dimension ( dimension )
if dimension is None or ( not data_range and not dimension_range ) :
return ( None , None )
elif all ( util . isfinite ( v ) for v in dimension . range ) and dimension_range :
return dimension . range
elif data_range :
if dimension in self . kdims + self . vdim... |
def handle_line ( self , frame , arg ) :
"""This function is called when we stop or break at this line .""" | log . info ( 'Stopping at line %s' % pretty_frame ( frame ) )
self . interaction ( frame ) |
def user_view_task ( self , ) :
"""View the task that is selected
: returns : None
: rtype : None
: raises : None""" | if not self . cur_user :
return
i = self . user_task_treev . currentIndex ( )
item = i . internalPointer ( )
if item :
task = item . internal_data ( )
if isinstance ( task , djadapter . models . Task ) :
self . view_task ( task ) |
def enable_file_approve ( self , enable = True ) :
"""Enables or disables menu item ( for entering / leaving save mode )""" | approve_item = self . shortcut2menuitem [ _ ( "&Approve file" ) ]
approve_item . Enable ( enable ) |
def update_groups_for_user ( self , user : User , state : State = None ) :
"""Update the Group memberships for the given users state
: param user : User to update for
: param state : State to update user for
: return :""" | if state is None :
state = user . profile . state
for config in self . filter ( states = state ) : # grant user new groups for their state
config . update_group_membership_for_user ( user )
for config in self . exclude ( states = state ) : # ensure user does not have groups from previous state
config . remo... |
def pin_chat_message ( self , * args , ** kwargs ) :
"""See : func : ` pin _ chat _ message `""" | return pin_chat_message ( * args , ** self . _merge_overrides ( ** kwargs ) ) . run ( ) |
def _setup_firefox ( self , capabilities ) :
"""Setup Firefox webdriver
: param capabilities : capabilities object
: returns : a new local Firefox driver""" | if capabilities . get ( "marionette" ) :
gecko_driver = self . config . get ( 'Driver' , 'gecko_driver_path' )
self . logger . debug ( "Gecko driver path given in properties: %s" , gecko_driver )
else :
gecko_driver = None
# Get Firefox binary
firefox_binary = self . config . get_optional ( 'Firefox' , 'bin... |
def render ( file ) :
"""Generate the result HTML .""" | fp = file . open ( )
content = fp . read ( )
fp . close ( )
notebook = nbformat . reads ( content . decode ( 'utf-8' ) , as_version = 4 )
html_exporter = HTMLExporter ( )
html_exporter . template_file = 'basic'
( body , resources ) = html_exporter . from_notebook_node ( notebook )
return body , resources |
def xyz2angle ( x , y , z ) :
"""Convert cartesian to azimuth and zenith .""" | azi = xu . rad2deg ( xu . arctan2 ( x , y ) )
zen = 90 - xu . rad2deg ( xu . arctan2 ( z , xu . sqrt ( x ** 2 + y ** 2 ) ) )
return azi , zen |
async def can_cast ( self , unit : Unit , ability_id : AbilityId , target : Optional [ Union [ Unit , Point2 , Point3 ] ] = None , only_check_energy_and_cooldown : bool = False , cached_abilities_of_unit : List [ AbilityId ] = None ) -> bool :
"""Tests if a unit has an ability available and enough energy to cast it... | assert isinstance ( unit , Unit )
assert isinstance ( ability_id , AbilityId )
assert isinstance ( target , ( type ( None ) , Unit , Point2 , Point3 ) )
# check if unit has enough energy to cast or if ability is on cooldown
if cached_abilities_of_unit :
abilities = cached_abilities_of_unit
else :
abilities = ( ... |
def parse ( self ) -> typing . Union [ list , dict , None ] :
"""Parse the BYML and get the root node with all children .""" | root_node_offset = self . _read_u32 ( 12 )
if root_node_offset == 0 :
return None
node_type = self . _data [ root_node_offset ]
if not _is_container_type ( node_type ) :
raise ValueError ( "Invalid root node: expected array or dict, got type 0x%x" % node_type )
return self . _parse_node ( node_type , 12 ) |
def sorted_bfs_edges ( G , source = None ) :
"""Produce edges in a breadth - first - search starting at source .
Neighbors appear in the order a linguist would expect in a syntax tree .
The result will only contain edges that express a dominance or spanning
relation , i . e . edges expressing pointing or prec... | if source is None :
source = G . root
xpos = horizontal_positions ( G , source )
visited = set ( [ source ] )
source_children = get_child_nodes ( G , source )
queue = deque ( [ ( source , iter ( sorted ( source_children , key = lambda x : xpos [ x ] ) ) ) ] )
while queue :
parent , children = queue [ 0 ]
tr... |
def dinfFlowDirection ( self , flow_dir_grid , slope_grid , pit_filled_elevation_grid = None ) :
"""Calculates flow direction with Dinf method""" | log ( "PROCESS: DinfFlowDirection" )
if pit_filled_elevation_grid :
self . pit_filled_elevation_grid = pit_filled_elevation_grid
# Construct the taudem command line .
cmd = [ os . path . join ( self . taudem_exe_path , 'dinfflowdir' ) , '-fel' , self . pit_filled_elevation_grid , '-ang' , flow_dir_grid , '-slp' , s... |
def show ( self , filter = None ) :
"""Print the list of commands currently in the queue . If filter is
given , print only commands that match the filter .""" | for command in self . _commands :
if command [ 0 ] is None : # or command [ 1 ] in self . _ invalid _ objects :
continue
# Skip nill commands
if filter and command [ 0 ] != filter :
continue
t = [ ]
for e in command :
if isinstance ( e , np . ndarray ) :
t . a... |
def _set_aaa_config ( self , v , load = False ) :
"""Setter method for aaa _ config , mapped from YANG variable / aaa _ config ( container )
If this variable is read - only ( config : false ) in the
source YANG file , then _ set _ aaa _ config is considered as a private
method . Backends looking to populate t... | if hasattr ( v , "_utype" ) :
v = v . _utype ( v )
try :
t = YANGDynClass ( v , base = aaa_config . aaa_config , is_container = 'container' , presence = False , yang_name = "aaa-config" , rest_name = "" , parent = self , path_helper = self . _path_helper , extmethods = self . _extmethods , register_paths = True... |
def fn_minimum_argcount ( callable ) :
"""Returns the minimum number of arguments that must be provided for the call to succeed .""" | fn = get_fn ( callable )
available_argcount = fn_available_argcount ( callable )
try :
return available_argcount - len ( fn . __defaults__ )
except TypeError :
return available_argcount |
def owner_search_fields ( self ) :
"""Returns all the fields that are CharFields except for password from the
User model . For the built - in User model , that means username ,
first _ name , last _ name , and email .""" | try :
from django . contrib . auth import get_user_model
except ImportError : # Django < 1.5
from django . contrib . auth . models import User
else :
User = get_user_model ( )
return [ field . name for field in User . _meta . fields if isinstance ( field , models . CharField ) and field . name != 'password'... |
def replace_exceptions ( old_to_new_exceptions : Dict [ Type [ BaseException ] , Type [ BaseException ] ] ) -> Callable [ ... , Any ] :
"""Replaces old exceptions with new exceptions to be raised in their place .""" | old_exceptions = tuple ( old_to_new_exceptions . keys ( ) )
def decorator ( to_wrap : Callable [ ... , Any ] ) -> Callable [ ... , Any ] :
@ functools . wraps ( to_wrap )
# String type b / c pypy3 throws SegmentationFault with Iterable as arg on nested fn
# Ignore so we don ' t have to import ` Iterable `
... |
def save_file_list ( key , * files_refs ) :
"""Convert the given parameters to a special JSON object .
Each parameter is a file - refs specification of the form :
< file - path > : < reference1 > , < reference2 > , . . . ,
where the colon ' : ' and the list of references are optional .
JSON object is of the... | file_list = [ ]
for file_refs in files_refs :
if ':' in file_refs :
try :
file_name , refs = file_refs . split ( ':' )
except ValueError as e :
return error ( "Only one colon ':' allowed in file-refs specification." )
else :
file_name , refs = file_refs , None
... |
def postinit ( self , target = None , value = None ) :
"""Do some setup after initialisation .
: param target : What is being assigned to .
: type target : NodeNG or None
: param value : The value being assigned to the variable .
: type : NodeNG or None""" | self . target = target
self . value = value |
def setup_job ( manager , job_id , tool_id , tool_version , use_metadata = False ) :
"""Setup new job from these inputs and return dict summarizing state
( used to configure command line ) .""" | job_id = manager . setup_job ( job_id , tool_id , tool_version )
if use_metadata :
manager . enable_metadata_directory ( job_id )
return build_job_config ( job_id = job_id , job_directory = manager . job_directory ( job_id ) , system_properties = manager . system_properties ( ) , tool_id = tool_id , tool_version = ... |
def p_expr_XOR_expr ( p ) :
"""expr : expr XOR expr""" | p [ 0 ] = make_binary ( p . lineno ( 2 ) , 'XOR' , p [ 1 ] , p [ 3 ] , lambda x , y : ( x and not y ) or ( not x and y ) ) |
def _parse ( self , msg ) :
"""Parses a Scratch message and returns a tuple with the first element
as the message type , and the second element as the message payload . The
payload for a ' broadcast ' message is a string , and the payload for a
' sensor - update ' message is a dict whose keys are variables , ... | if not self . _is_msg ( msg ) :
return None
msg_type = msg [ self . prefix_len : ] . split ( ' ' ) [ 0 ]
if msg_type == 'broadcast' :
return ( 'broadcast' , self . _parse_broadcast ( msg ) )
else :
return ( 'sensor-update' , self . _parse_sensorupdate ( msg ) ) |
def bishop88 ( diode_voltage , photocurrent , saturation_current , resistance_series , resistance_shunt , nNsVth , d2mutau = 0 , NsVbi = np . Inf , gradients = False ) :
"""Explicit calculation of points on the IV curve described by the single
diode equation [ 1 ] _ .
. . warning : :
* Do not use ` ` d2mutau ... | # calculate recombination loss current where d2mutau > 0
is_recomb = d2mutau > 0
# True where there is thin - film recombination loss
v_recomb = np . where ( is_recomb , NsVbi - diode_voltage , np . inf )
i_recomb = np . where ( is_recomb , photocurrent * d2mutau / v_recomb , 0 )
# calculate temporary values to simplif... |
def send_KeyEvent ( self , key , down ) :
"""For most ordinary keys , the " keysym " is the same as the
corresponding ASCII value . Other common keys are shown in the
KEY _ constants .""" | self . sendMessage ( struct . pack ( '!BBxxI' , 4 , down , key ) ) |
def is_in_scope ( cls , want_scope : str , have_scopes : List [ Scope ] ) -> bool :
"""Return True if wanted scope is in list of scopes or derived scopes .
: param want _ scope : scope wanted for permission to do something ( str because could be invalid scope )
: param have _ scopes : list of valid scopes that ... | if not want_scope :
return True
if want_scope in have_scopes or want_scope . split ( ':' ) [ 0 ] in have_scopes :
return True
elif want_scope . startswith ( 'read' ) :
return cls . is_in_scope ( want_scope . replace ( 'read' , 'write' ) , have_scopes )
elif want_scope . startswith ( 'write' ) :
return c... |
def get_host ( self , name , default = NoHostError ) :
'''Get a single host by name .''' | if name in self . hosts :
return self . hosts [ name ]
if default is NoHostError :
raise NoHostError ( 'No such host: {0}' . format ( name ) )
return default |
def redact_image ( self , parent , inspect_config = None , image_redaction_configs = None , include_findings = None , byte_item = None , retry = google . api_core . gapic_v1 . method . DEFAULT , timeout = google . api_core . gapic_v1 . method . DEFAULT , metadata = None , ) :
"""Redacts potentially sensitive info f... | # Wrap the transport method to add retry and timeout logic .
if "redact_image" not in self . _inner_api_calls :
self . _inner_api_calls [ "redact_image" ] = google . api_core . gapic_v1 . method . wrap_method ( self . transport . redact_image , default_retry = self . _method_configs [ "RedactImage" ] . retry , defa... |
def close ( self ) :
'''Closes connection with the q service .''' | if self . _connection :
self . _connection_file . close ( )
self . _connection_file = None
self . _connection . close ( )
self . _connection = None |
def pvRvz ( self , vR , vz , R , z , gl = True , ngl = _DEFAULTNGL2 , vTmax = 1.5 ) :
"""NAME :
pvR
PURPOSE :
calculate the marginalized ( vR , vz ) probability at this location ( NOT normalized by the density )
INPUT :
vR - radial velocity ( can be Quantity )
vz - vertical velocity ( can be Quantity ) ... | if gl :
if ngl % 2 == 1 :
raise ValueError ( "ngl must be even" )
# Use Gauss - Legendre integration for all
if ngl == _DEFAULTNGL :
glx , glw = self . _glxdef , self . _glwdef
glx12 , glw12 = self . _glxdef12 , self . _glwdef12
elif ngl == _DEFAULTNGL2 :
glx , glw = self... |
def apply_func_to_select_indices_along_full_axis ( self , axis , func , indices , keep_remaining = False ) :
"""Applies a function to a select subset of full columns / rows .
Note : This should be used when you need to apply a function that relies
on some global information for the entire column / row , but onl... | if self . partitions . size == 0 :
return self . __constructor__ ( np . array ( [ [ ] ] ) )
if isinstance ( indices , dict ) :
dict_indices = indices
indices = list ( indices . keys ( ) )
else :
dict_indices = None
if not isinstance ( indices , list ) :
indices = [ indices ]
partitions_dict = self .... |
def from_las ( cls , fname , remap = None , funcs = None , data = True , req = None , alias = None , encoding = None , printfname = False ) :
"""Constructor . Essentially just wraps ` ` from _ lasio ( ) ` ` , but is more
convenient for most purposes .
Args :
fname ( str ) : The path of the LAS file , or a URL... | if printfname :
print ( fname )
if re . match ( r'https?://.+\..+/.+?' , fname ) is not None :
try :
data = urllib . request . urlopen ( fname ) . read ( ) . decode ( )
except urllib . HTTPError as e :
raise WellError ( 'Could not retrieve url: ' , e )
fname = ( StringIO ( data ) )
las =... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.