signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def targets ( tgt , tgt_type = 'glob' , ** kwargs ) :
'''Return the targets from the flat yaml file , checks opts for location but
defaults to / etc / salt / roster''' | template = get_roster_file ( __opts__ )
rend = salt . loader . render ( __opts__ , { } )
raw = compile_template ( template , rend , __opts__ [ 'renderer' ] , __opts__ [ 'renderer_blacklist' ] , __opts__ [ 'renderer_whitelist' ] , mask_value = 'passw*' , ** kwargs )
conditioned_raw = { }
for minion in raw :
conditio... |
def _base64_encode ( self , string_to_encode ) :
"""Base64 encodes a string , with either Python 2 or 3.
: param string _ to _ encode : the string to encode""" | try : # python 2
return base64 . b64encode ( string_to_encode )
except TypeError : # python 3
encoding = sys . getdefaultencoding ( )
base64_bytes = base64 . b64encode ( bytes ( string_to_encode , encoding ) )
return base64_bytes . decode ( encoding ) |
def enumerate ( self , ** kwargs ) :
'''Iterate through all possible sequences ( lists ) . By default , will
stop after 50 items have been yielded . This value can be
change by supplying a different value via the max _ enumerate kwarg .''' | for item in self . set . enumerate ( ** kwargs ) :
yield flattened ( item ) |
def enable_mac ( self , app = None ) :
"""Enable event loop integration with MacOSX .
We call function pyplot . pause , which updates and displays active
figure during pause . It ' s not MacOSX - specific , but it enables to
avoid inputhooks in native MacOSX backend .
Also we shouldn ' t import pyplot , unt... | def inputhook_mac ( app = None ) :
if self . pyplot_imported :
pyplot = sys . modules [ 'matplotlib.pyplot' ]
try :
pyplot . pause ( 0.01 )
except :
pass
else :
if 'matplotlib.pyplot' in sys . modules :
self . pyplot_imported = True
self . set_... |
def _disconnect_locked ( self ) :
"""Closes the current connection . Assume self . _ lock is held .""" | self . _connected = False
self . _connect_cond . notify_all ( )
self . _telnet = None
_LOGGER . warning ( "Disconnected" ) |
def gas_liquid_viscosity ( x , mul , mug , rhol = None , rhog = None , Method = None , AvailableMethods = False ) :
r'''This function handles the calculation of two - phase liquid - gas viscosity .
Six calculation methods are available ; three of them require only ` x ` ,
` mul ` , and ` mug ` ; the other three... | def list_methods ( ) :
methods = [ 'McAdams' , 'Cicchitti' , 'Lin Kwok' ]
if rhol is not None and rhog is not None :
methods = list ( liquid_gas_viscosity_correlations . keys ( ) )
return methods
if AvailableMethods :
return list_methods ( )
if not Method :
Method = 'McAdams'
if Method in li... |
def set ( ctx , key , value ) :
"""Set configuration parameters""" | if key == "default_account" and value [ 0 ] == "@" :
value = value [ 1 : ]
ctx . blockchain . config [ key ] = value |
def ctime ( self , fpath = None ) :
"""Returns :
str : strftime - formatted ctime ( creation time ) of fpath""" | return dtformat ( datetime . datetime . utcfromtimestamp ( os . path . getctime ( fpath or self . fpath ) ) ) |
def get_dict_of_all_args ( self ) :
"""Generates a dictionary from a handler paths query string and returns it
: returns : Dictionary of all key / values in arguments list
: rtype : dict""" | dictionary = { }
for arg in [ arg for arg in self . request . arguments if arg not in self . settings . get ( "reserved_query_string_params" , [ ] ) ] :
val = self . get_argument ( arg , default = None )
if val :
dictionary [ arg ] = val
return dictionary |
def clear_created_date ( self ) :
"""Removes the created date .
raise : NoAccess - ` ` Metadata . isRequired ( ) ` ` is ` ` true ` ` or
` ` Metadata . isReadOnly ( ) ` ` is ` ` true ` `
* compliance : mandatory - - This method must be implemented . *""" | # Implemented from template for osid . assessment . AssessmentOfferedForm . clear _ start _ time _ template
if ( self . get_created_date_metadata ( ) . is_read_only ( ) or self . get_created_date_metadata ( ) . is_required ( ) ) :
raise errors . NoAccess ( )
self . _my_map [ 'createdDate' ] = self . _created_date_d... |
def set ( self , data , path = KISSmetrics . SET_PATH , resp = False ) :
"""Set a properties provided in ` data ` for identity .
: param data : key - value pairs to associate with identity
: type data : dict
: param path : endpoint path ; defaults to ` ` KISSmetrics . SET _ PATH ` `
: param resp : indicate ... | self . check_id_key ( )
timestamp = None
response = self . client . set ( person = self . identity , properties = data , timestamp = timestamp , path = path )
if resp :
return response |
def tee ( iterable , n = 2 ) :
"""Return n independent iterators from a single iterable .
Once tee ( ) has made a split , the original iterable should not be used
anywhere else ; otherwise , the iterable could get advanced without the tee
objects being informed .
This itertool may require significant auxili... | tees = tuple ( AsyncTeeIterable ( iterable ) for _ in range ( n ) )
for tee in tees :
tee . _siblings = tees
return tees |
def extract_keywords ( func ) :
"""Parses the keywords from the given function .
: param func | < function >""" | if hasattr ( func , 'im_func' ) :
func = func . im_func
try :
return func . func_code . co_varnames [ - len ( func . func_defaults ) : ]
except ( TypeError , ValueError , IndexError ) :
return tuple ( ) |
def sample_train_batch ( self ) :
"""Sample a training batch ( data and label ) .""" | batch = [ ]
labels = [ ]
num_groups = self . batch_size // self . batch_k
# For CUB200 , we use the first 100 classes for training .
sampled_classes = np . random . choice ( 100 , num_groups , replace = False )
for i in range ( num_groups ) :
img_fnames = np . random . choice ( self . train_image_files [ sampled_cl... |
def on_success ( self , retval , task_id , args , kwargs ) :
"""Store results in the backend even if we ' re always eager . This ensures
the ` delay _ or _ run ` calls always at least have results .""" | if self . request . is_eager : # Store the result because celery wouldn ' t otherwise
self . update_state ( task_id , SUCCESS , retval ) |
def present ( name , user , enc = 'ssh-rsa' , comment = '' , source = '' , options = None , config = '.ssh/authorized_keys' , fingerprint_hash_type = None , ** kwargs ) :
'''Verifies that the specified SSH key is present for the specified user
name
The SSH key to manage
user
The user who owns the SSH author... | ret = { 'name' : name , 'changes' : { } , 'result' : True , 'comment' : '' }
if source == '' : # check if this is of form { options } { enc } { key } { comment }
sshre = re . compile ( r'^(.*?)\s?((?:ssh\-|ecds)[\w-]+\s.+)$' )
fullkey = sshre . search ( name )
# if it is { key } [ comment ]
if not fullk... |
def from_name ( cls , name , all_fallback = True ) :
"""Gets a vocation filter from a vocation ' s name .
Parameters
name : : class : ` str `
The name of the vocation .
all _ fallback : : class : ` bool `
Whether to return : py : attr : ` ALL ` if no match is found . Otherwise , ` ` None ` ` will be retur... | name = name . upper ( )
for vocation in cls : # type : VocationFilter
if vocation . name in name or vocation . name [ : - 1 ] in name and vocation != cls . ALL :
return vocation
if all_fallback or name . upper ( ) == "ALL" :
return cls . ALL
return None |
def do_set ( self , line ) :
"""set [ parameter [ value ] ] set ( without parameters ) : Display the value of all
session variables .
set < session variable > : Display the value of a single session variable . set
< session variable > < value > : Set the value of a session variable .""" | session_parameter , value = self . _split_args ( line , 0 , 2 )
if value is None :
self . _command_processor . get_session ( ) . print_variable ( session_parameter )
else :
self . _command_processor . get_session ( ) . set_with_conversion ( session_parameter , value )
self . _print_info_if_verbose ( 'Set se... |
def random_like ( ary = None , shape = None , dtype = None ) :
"""Returns a random array of the same shape and type as the
supplied array argument , or the supplied shape and dtype""" | if ary is not None :
shape , dtype = ary . shape , ary . dtype
elif shape is None or dtype is None :
raise ValueError ( ( 'random_like(ary, shape, dtype) must be supplied ' 'with either an array argument, or the shape and dtype ' 'of the desired random array.' ) )
if np . issubdtype ( dtype , np . complexfloati... |
def fail_to ( future ) :
"""A decorator for function callbacks to catch uncaught non - async
exceptions and forward them to the given future .
The primary use for this is to catch exceptions in async callbacks and
propagate them to futures . For example , consider ,
. . code - block : : python
answer = Fu... | assert is_future ( future ) , 'you forgot to pass a future'
def decorator ( f ) :
@ wraps ( f )
def new_f ( * args , ** kwargs ) :
try :
return f ( * args , ** kwargs )
except Exception :
future . set_exc_info ( sys . exc_info ( ) )
return new_f
return decorator |
def nearby_faces ( mesh , points ) :
"""For each point find nearby faces relatively quickly .
The closest point on the mesh to the queried point is guaranteed to be
on one of the faces listed .
Does this by finding the nearest vertex on the mesh to each point , and
then returns all the faces that intersect ... | points = np . asanyarray ( points , dtype = np . float64 )
if not util . is_shape ( points , ( - 1 , 3 ) ) :
raise ValueError ( 'points must be (n,3)!' )
# an r - tree containing the axis aligned bounding box for every triangle
rtree = mesh . triangles_tree
# a kd - tree containing every vertex of the mesh
kdtree =... |
def set_problem_feedback ( feedback , problem_id , append = False ) :
"""Set problem specific feedback""" | rdict = load_feedback ( )
if not 'problems' in rdict :
rdict [ 'problems' ] = { }
cur_val = rdict [ 'problems' ] . get ( problem_id , '' )
rdict [ 'problems' ] [ problem_id ] = ( cur_val + feedback if append else feedback ) if type ( cur_val ) == str else [ cur_val [ 0 ] , ( cur_val [ 1 ] + feedback if append else ... |
def adjustPitchmarkers ( self ) :
'''Adjusts the location and orientation of pitch markers .''' | pitchdiff = self . dist10deg * ( self . pitch / 10.0 )
rollRotate = mpl . transforms . Affine2D ( ) . rotate_deg_around ( 0.0 , - pitchdiff , self . roll ) + self . axes . transData
j = 0
for i in [ - 9 , - 8 , - 7 , - 6 , - 5 , - 4 , - 3 , - 2 , - 1 , 0 , 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 ] :
width = self . calcPi... |
def _get_entity_prop ( self , entity , prop ) :
"""returns Wikidata entity property value""" | variant = self . params . get ( 'variant' )
lang = self . params . get ( 'lang' )
if entity . get ( prop ) :
ent = entity [ prop ]
try :
return ent [ variant or lang ] . get ( 'value' )
except AttributeError :
return ent . get ( 'value' ) |
def isdir ( self , path ) :
"""Return ` True ` if directory at ` path ` exist , False otherwise .""" | try :
self . remote_context . check_output ( [ "test" , "-d" , path ] )
except subprocess . CalledProcessError as e :
if e . returncode == 1 :
return False
else :
raise
return True |
def get_default_config ( self ) :
"""Returns the default collector settings""" | config = super ( EntropyStatCollector , self ) . get_default_config ( )
config . update ( { 'path' : 'entropy' } )
return config |
def compare ( dicts ) :
"""Compare by iteration""" | common_members = { }
common_keys = reduce ( lambda x , y : x & y , map ( dict . keys , dicts ) )
for k in common_keys :
common_members [ k ] = list ( reduce ( lambda x , y : x & y , [ set ( d [ k ] ) for d in dicts ] ) )
return common_members |
def antonym ( phrase , format = "json" ) :
"""queries the bighugelabs API for the antonym . The results include
- " syn " ( synonym )
- " ant " ( antonym )
- " rel " ( related terms )
- " sim " ( similar terms )
- " usr " ( user suggestions )
But currently parsing only the antonym as I have already done... | base_url = Vocabulary . __get_api_link ( "bighugelabs" )
url = base_url . format ( word = phrase )
json_obj = Vocabulary . __return_json ( url )
if not json_obj :
return False
result = [ ]
visited = { }
idx = 0
for key in json_obj . keys ( ) :
antonyms = json_obj [ key ] . get ( 'ant' , False )
if not anton... |
def scheduled ( self ) -> ScheduledTxsAggregate :
"""Scheduled Transactions""" | if not self . __scheduled_tx_aggregate :
self . __scheduled_tx_aggregate = ScheduledTxsAggregate ( self . book )
return self . __scheduled_tx_aggregate |
def _run_internal ( self , context , pipeline_key , root_pipeline_key , caller_output ) :
"""Used by the Pipeline evaluator to execute this Pipeline .""" | self . _set_values_internal ( context , pipeline_key , root_pipeline_key , caller_output , _PipelineRecord . RUN )
logging . debug ( 'Running %s(*%s, **%s)#%s' , self . _class_path , _short_repr ( self . args ) , _short_repr ( self . kwargs ) , self . _pipeline_key . name ( ) )
return self . run ( * self . args , ** se... |
def add_warning ( self , s , tag = None ) :
"""Add a warning string .""" | item = ( tag , s )
if item not in self . warnings and tag not in self . aggregate . config [ "ignorewarnings" ] :
self . warnings . append ( item ) |
def rna_transcript_expression_dict_from_args ( args ) :
"""Returns a dictionary mapping Ensembl transcript IDs to FPKM expression
values or None if neither Cufflinks tracking file nor StringTie GTF file
were specified .""" | if args . rna_transcript_fpkm_tracking_file :
return load_cufflinks_fpkm_dict ( args . rna_transcript_fpkm_tracking_file )
elif args . rna_transcript_fpkm_gtf_file :
return load_transcript_fpkm_dict_from_gtf ( args . rna_transcript_fpkm_gtf_file )
else :
return None |
def _hide_loading_page ( self ) :
"""Hide animation shown while the kernel is loading .""" | self . infowidget . hide ( )
self . shellwidget . show ( )
self . info_page = self . blank_page
self . set_info_page ( )
self . shellwidget . sig_prompt_ready . disconnect ( self . _hide_loading_page ) |
def get_since_until ( time_range : Optional [ str ] = None , since : Optional [ str ] = None , until : Optional [ str ] = None , time_shift : Optional [ str ] = None , relative_end : Optional [ str ] = None ) -> Tuple [ datetime , datetime ] :
"""Return ` since ` and ` until ` date time tuple from string representa... | separator = ' : '
relative_end = parse_human_datetime ( relative_end if relative_end else 'today' )
common_time_frames = { 'Last day' : ( relative_end - relativedelta ( days = 1 ) , relative_end ) , # noqa : T400
'Last week' : ( relative_end - relativedelta ( weeks = 1 ) , relative_end ) , # noqa : T400
'Last month' : ... |
def main ( ) :
"""This demo shows the main features of the pythondialog Dialog class .""" | try :
demo ( )
except dialog . error , exc_instance :
sys . stderr . write ( "Error:\n\n%s\n" % exc_instance . complete_message ( ) )
sys . exit ( 1 )
sys . exit ( 0 ) |
def count ( args ) :
"""count occurences in a list of lists
> > > count ( [ [ ' a ' , ' b ' ] , [ ' a ' ] ] )
defaultdict ( int , { ' a ' : 2 , ' b ' : 1 } )""" | counts = defaultdict ( int )
for arg in args :
for item in arg :
counts [ item ] = counts [ item ] + 1
return counts |
def get_snapshot_brok ( self , snap_output , exit_status ) :
"""Create snapshot ( check _ result type ) brok
: param snap _ output : value of output
: type snap _ output : str
: param exit _ status : status of exit
: type exit _ status : integer
: return : Brok object
: rtype : alignak . Brok""" | data = { 'uuid' : self . uuid , 'snapshot_output' : snap_output , 'snapshot_time' : int ( time . time ( ) ) , 'snapshot_exit_status' : exit_status , }
self . fill_data_brok_from ( data , 'check_result' )
return Brok ( { 'type' : self . my_type + '_snapshot' , 'data' : data } ) |
def needsEncoding ( self , s ) :
"""Get whether string I { s } contains special characters .
@ param s : A string to check .
@ type s : str
@ return : True if needs encoding .
@ rtype : boolean""" | if isinstance ( s , str ) :
for c in self . special :
if c in s :
return True
return False |
def Deserialize ( self , reader ) :
"""Deserialize full object .
Args :
reader ( neo . IO . BinaryReader ) :""" | self . HashStart = reader . ReadSerializableArray ( 'neocore.UInt256.UInt256' )
self . HashStop = reader . ReadUInt256 ( ) |
def remove ( self , path ) :
"""Remove the file at the given path . This only works on files ; for
removing folders ( directories ) , use L { rmdir } .
@ param path : path ( absolute or relative ) of the file to remove
@ type path : str
@ raise IOError : if the path refers to a folder ( directory )""" | path = self . _adjust_cwd ( path )
self . _log ( DEBUG , 'remove(%r)' % path )
self . _request ( CMD_REMOVE , path ) |
def _value_ref ( self , column , value , * , dumped = False , inner = False ) :
"""inner = True uses column . typedef . inner _ type instead of column . typedef""" | ref = ":v{}" . format ( self . next_index )
# Need to dump this value
if not dumped :
typedef = column . typedef
for segment in path_of ( column ) :
typedef = typedef [ segment ]
if inner :
typedef = typedef . inner_typedef
value = self . engine . _dump ( typedef , value )
self . attr_va... |
def expand_dict ( flat_dict , sep = '_' ) :
"""Expand a flattened dictionary .
: param dict flat _ dict : a nested dictionary that has been flattened so the keys are composite
: param str sep : the separator between concatenated keys
: rtype : dict""" | res = { }
rdict = defaultdict ( list )
for flat_key , value in flat_dict . items ( ) :
key = flat_key . split ( sep , 1 )
if 1 == len ( key ) :
res [ key [ 0 ] ] = value
else :
rdict [ key [ 0 ] ] . append ( ( key [ 1 : ] , value ) )
for k , v in rdict . items ( ) :
res [ k ] = expand_di... |
def mean ( data , units = False , time = False ) :
"""Function to compute mean of data
Parameters
data : numpy . ndarray
1st axis unit , 2nd axis time
units : bool
Average over units
time : bool
Average over time
Returns
if units = False and time = False :
error
if units = True :
1 dim numpy... | assert ( units is not False or time is not False )
if units is True and time is False :
return np . mean ( data , axis = 0 )
elif units is False and time is True :
return np . mean ( data , axis = 1 )
elif units is True and time is True :
return np . mean ( data ) |
def extract_pdf ( file_name ) :
"""Extract text from a pdf file
: param file _ name path to pdf to read
: return text from pdf""" | rsrcmgr = pdfminer . pdfinterp . PDFResourceManager ( )
sio = StringIO ( )
laparams = LAParams ( )
device = TextConverter ( rsrcmgr , sio , codec = 'utf-8' , laparams = laparams )
interpreter = pdfminer . pdfinterp . PDFPageInterpreter ( rsrcmgr , device )
# Extract text from pdf file
with open ( file_name , 'rb' ) as ... |
def _get_kernel_from_bayesian_model ( self , model ) :
"""Computes the Gibbs transition models from a Bayesian Network .
' Probabilistic Graphical Model Principles and Techniques ' , Koller and
Friedman , Section 12.3.3 pp 512-513.
Parameters :
model : BayesianModel
The model from which probabilities will... | self . variables = np . array ( model . nodes ( ) )
self . cardinalities = { var : model . get_cpds ( var ) . variable_card for var in self . variables }
for var in self . variables :
other_vars = [ v for v in self . variables if var != v ]
other_cards = [ self . cardinalities [ v ] for v in other_vars ]
cp... |
def dump ( self , dump_file_name = None ) : # pragma : no cover , never called
# pylint : disable = unused - argument
"""Dump Item object properties
: return : dictionary with properties
: rtype : dict""" | dump = { }
for prop in self . properties :
if not hasattr ( self , prop ) :
continue
attr = getattr ( self , prop )
if isinstance ( attr , list ) and attr and isinstance ( attr [ 0 ] , Item ) :
dump [ prop ] = [ i . dump ( ) for i in attr ]
elif isinstance ( attr , Item ) :
dump ... |
def _is_contiguous ( positions ) :
"""Given a non - empty list , does it consist of contiguous integers ?""" | previous = positions [ 0 ]
for current in positions [ 1 : ] :
if current != previous + 1 :
return False
previous = current
return True |
def trim_decimals ( s , precision = - 3 ) :
"""Convert from scientific notation using precision""" | encoded = s . encode ( 'ascii' , 'ignore' )
str_val = ""
if six . PY3 :
str_val = str ( encoded , encoding = 'ascii' , errors = 'ignore' ) [ : precision ]
else : # If precision is 0 , this must be handled seperately
if precision == 0 :
str_val = str ( encoded )
else :
str_val = str ( encoded... |
def init ( * args , ** kwargs ) :
"""Initializes the SDK and optionally integrations .
This takes the same arguments as the client constructor .""" | global _initial_client
client = Client ( * args , ** kwargs )
Hub . current . bind_client ( client )
rv = _InitGuard ( client )
if client is not None :
_initial_client = weakref . ref ( client )
return rv |
def get_all_last_24h_kline ( self , _async = False ) :
"""获取所有24小时的概况
: param _ async :
: return :""" | params = { }
url = u . MARKET_URL + '/market/tickers'
return http_get_request ( url , params , _async = _async ) |
def sliding ( self , size , step = 1 ) :
"""Groups elements in fixed size blocks by passing a sliding window over them .
The last window has at least one element but may have less than size elements
: param size : size of sliding window
: param step : step size between windows
: return : sequence of sliding... | return self . _transform ( transformations . sliding_t ( _wrap , size , step ) ) |
def _ConvertCollectionsCounterToDict ( cls , collections_counter ) :
"""Converts a collections . Counter object into a JSON dictionary .
The resulting dictionary of the JSON serialized objects consists of :
' _ _ type _ _ ' : ' collections . Counter '
Here ' _ _ type _ _ ' indicates the object base type . In ... | if not isinstance ( collections_counter , collections . Counter ) :
raise TypeError
json_dict = { '__type__' : 'collections.Counter' }
for attribute_name , attribute_value in iter ( collections_counter . items ( ) ) :
if attribute_value is None :
continue
if isinstance ( attribute_value , py2to3 . B... |
def _validate_method_decoration ( meta , class_ ) :
"""Validate the usage of ` ` @ override ` ` and ` ` @ final ` ` modifiers
on methods of the given ` ` class _ ` ` .""" | # TODO ( xion ) : employ some code inspection tricks to serve ClassErrors
# as if they were thrown at the offending class ' s / method ' s definition
super_mro = class_ . __mro__ [ 1 : ]
own_methods = ( ( name , member ) for name , member in class_ . __dict__ . items ( ) if is_method ( member ) )
# check that ` ` @ ove... |
def config ( p_path = None , p_overrides = None ) :
"""Retrieve the config instance .
If a path is given , the instance is overwritten by the one that supplies an
additional filename ( for testability ) . Moreover , no other configuration
files will be read when a path is given .
Overrides will discard a se... | if not config . instance or p_path is not None or p_overrides is not None :
try :
config . instance = _Config ( p_path , p_overrides )
except configparser . ParsingError as perr :
raise ConfigError ( str ( perr ) ) from perr
return config . instance |
def log_to_logger ( fn ) :
"""Wrap a Bottle request so that a log line is emitted after it ' s handled .""" | @ wraps ( fn )
def _log_to_logger ( * args , ** kwargs ) :
actual_response = fn ( * args , ** kwargs )
# modify this to log exactly what you need :
logger . info ( '%s %s %s %s' % ( bottle . request . remote_addr , bottle . request . method , bottle . request . url , bottle . response . status ) )
retur... |
def lipd_read ( path ) :
"""Loads a LiPD file from local path . Unzip , read , and process data
Steps : create tmp , unzip lipd , read files into memory , manipulate data , move to original dir , delete tmp .
: param str path : Source path
: return none :""" | _j = { }
dir_original = os . getcwd ( )
# Import metadata into object
try :
print ( "reading: {}" . format ( print_filename ( path ) ) )
# bigger than 2mb file ? This could take a while
if os . stat ( path ) . st_size > 1000000 :
_size = os . stat ( path ) . st_size
print ( "{} :That's a big... |
def validate_items ( self ) :
"""Validates the items in the backing array , including
performing type validation .
Sets the _ typed property and clears the dirty flag as a side effect
Returns :
The typed array""" | logger . debug ( fmt ( "Validating {}" , self ) )
from python_jsonschema_objects import classbuilder
if self . __itemtype__ is None :
return
type_checks = self . __itemtype__
if not isinstance ( type_checks , ( tuple , list ) ) : # we were given items = { ' type ' : ' blah ' } ; thus ensure the type for all data .
... |
def register_column ( self , column , expr , deltas = None , checkpoints = None , odo_kwargs = None ) :
"""Explicitly map a single bound column to a collection of blaze
expressions . The expressions need to have ` ` timestamp ` ` and ` ` as _ of ` `
columns .
Parameters
column : BoundColumn
The pipeline d... | self . _table_expressions [ column ] = ExprData ( expr , deltas , checkpoints , odo_kwargs , ) |
def can_float ( item , max_weight ) :
"""A function that determines if an object ' item ' can float .
The object ' item ' canfloat if the list is a palindrome and
the total of its elements is smaller or equal to the ' max _ weight ' .
Args :
item ( List [ int ] ) : List of integer weights
max _ weight ( i... | if sum ( item ) > max_weight :
return False
return item == item [ : : - 1 ] |
def get_share_info ( self , grantee_type = None , grantee_id = None , grantee_name = None , owner = None , owner_type = 'name' ) :
""": returns : list of dict representing shares informations""" | params = { }
if grantee_type :
if 'grantee' not in params . keys ( ) :
params [ 'grantee' ] = { }
params [ 'grantee' ] . update ( { 'type' : grantee_type } )
if grantee_id :
if 'grantee' not in params . keys ( ) :
params [ 'grantee' ] = { }
params [ 'grantee' ] . update ( { 'id' : grante... |
def sendCommandAPDU ( self , command ) :
"""Send an APDU command to the connected smartcard .
@ param command : list of APDU bytes , e . g . [ 0xA0 , 0xA4 , 0x00 , 0x00 , 0x02]
@ return : a tuple ( response , sw1 , sw2 ) where
response is the APDU response
sw1 , sw2 are the two status words""" | response , sw1 , sw2 = self . cs . connection . transmit ( command )
if len ( response ) > 2 :
response . append ( sw1 )
response . append ( sw2 )
return response , sw1 , sw2 |
def simulated_binary_crossover ( random , mom , dad , args ) :
"""Return the offspring of simulated binary crossover on the candidates .
This function performs simulated binary crossover ( SBX ) , following the
implementation in NSGA - II
` ( Deb et al . , ICANNGA 1999 ) < http : / / vision . ucsd . edu / ~ s... | crossover_rate = args . setdefault ( 'crossover_rate' , 1.0 )
if random . random ( ) < crossover_rate :
di = args . setdefault ( 'sbx_distribution_index' , 10 )
bounder = args [ '_ec' ] . bounder
bro = copy . copy ( dad )
sis = copy . copy ( mom )
for i , ( m , d , lb , ub ) in enumerate ( zip ( mom... |
def _create_buffers ( self , view_size , buffer_size ) :
"""Create the buffers , taking in account pixel alpha or colorkey
: param view _ size : pixel size of the view
: param buffer _ size : pixel size of the buffer""" | requires_zoom_buffer = not view_size == buffer_size
self . _zoom_buffer = None
if self . _clear_color is None :
if requires_zoom_buffer :
self . _zoom_buffer = Surface ( view_size )
self . _buffer = Surface ( buffer_size )
elif self . _clear_color == self . _rgba_clear_color :
if requires_zoom_buffe... |
def run ( self ) :
'''Run the LaTeX compilation .''' | # store files
self . old_dir = [ ]
if self . opt . clean :
self . old_dir = os . listdir ( '.' )
cite_counter , toc_file , gloss_files = self . _read_latex_files ( )
self . latex_run ( )
self . read_glossaries ( )
gloss_changed = self . makeindex_runs ( gloss_files )
if gloss_changed or self . _is_toc_changed ( toc... |
def release ( self , device_info ) :
"""This function is called by the segmentation state machine when it
has finished with the device information .""" | if _debug :
DeviceInfoCache . _debug ( "release %r" , device_info )
# this information record might be used by more than one SSM
if device_info . _ref_count == 0 :
raise RuntimeError ( "reference count" )
# decrement the reference count
device_info . _ref_count -= 1 |
def update_table ( self , tablename , throughput = None , global_indexes = None , index_updates = None ) :
"""Update the throughput of a table and / or global indexes
Parameters
tablename : str
Name of the table to update
throughput : : class : ` ~ dynamo3 . fields . Throughput ` , optional
The new throug... | kwargs = { 'TableName' : tablename }
all_attrs = set ( )
if throughput is not None :
kwargs [ 'ProvisionedThroughput' ] = throughput . schema ( )
if index_updates is not None :
updates = [ ]
for update in index_updates :
all_attrs . update ( update . get_attrs ( ) )
updates . append ( update... |
def require_version ( namespace , version ) :
"""Set a version for the namespace to be loaded .
This needs to be called before importing the namespace or any
namespace that depends on it .""" | global _versions
repo = GIRepository ( )
namespaces = repo . get_loaded_namespaces ( )
if namespace in namespaces :
loaded_version = repo . get_version ( namespace )
if loaded_version != version :
raise ValueError ( 'Namespace %s is already loaded with version %s' % ( namespace , loaded_version ) )
if n... |
async def on_raw_433 ( self , message ) :
"""Nickname in use .""" | if not self . registered :
self . _registration_attempts += 1
# Attempt to set new nickname .
if self . _attempt_nicknames :
await self . set_nickname ( self . _attempt_nicknames . pop ( 0 ) )
else :
await self . set_nickname ( self . _nicknames [ 0 ] + '_' * ( self . _registration_attem... |
def make_data ( ) :
"""1 . . T : set of periods
K : set of resources
P : set of items
f [ t , p ] : set - up costs
g [ t , p ] : set - up times
c [ t , p ] : variable costs
d [ t , p ] : demand values
h [ t , p ] : holding costs
a [ t , k , p ] : amount of resource k for producing product p in perio... | T = 5
K = [ 1 ]
P = [ 1 , 2 , 3 , 4 , 5 ]
_ , f , g , c , d , h , UB = multidict ( { ( 1 , 1 ) : [ 10 , 1 , 2 , 0 , 0.5 , 24 ] , ( 1 , 2 ) : [ 10 , 1 , 2 , 0 , 0.5 , 24 ] , ( 1 , 3 ) : [ 10 , 1 , 2 , 0 , 0.5 , 24 ] , ( 1 , 4 ) : [ 10 , 1 , 2 , 0 , 0.5 , 24 ] , ( 1 , 5 ) : [ 10 , 1 , 2 , 0 , 0.5 , 24 ] , ( 2 , 1 ) : [ 1... |
def trim ( self ) :
"""Discard the ancestry of this state .""" | new_hist = self . copy ( { } )
new_hist . parent = None
self . state . register_plugin ( 'history' , new_hist ) |
def retrieve_prop ( name ) :
"""retrieve a property handler""" | handler_get , handler_set = None , None
if name in props_get :
handler_get = props_get [ name ]
if name in props_set :
handler_set = props_set [ name ]
return ( name , handler_get , handler_set ) |
def get_transitions_forward_steps ( self , indexes , forward_steps , discount_factor ) :
"""Get dictionary of transition data""" | return self . deque . get_transitions_forward_steps ( indexes , forward_steps , discount_factor ) |
def create ( self , title , description = None , document_ids = None ) :
"""Creates a new project .
Returns its unique identifer in documentcloud
Example usage :
> > documentcloud . projects . create ( " The Ruben Salazar Files " )""" | params = { 'title' : title , }
if description :
params [ 'description' ] = description
params = urllib . parse . urlencode ( params , doseq = True )
if document_ids : # These need to be specially formatted in the style documentcloud
# expects arrays . The example they provide is :
# ? document _ ids [ ] = 28 - boum... |
def split_sequence ( seq , n ) :
"""Generates tokens of length n from a sequence .
The last token may be of smaller length .""" | tokens = [ ]
while seq :
tokens . append ( seq [ : n ] )
seq = seq [ n : ]
return tokens |
def get_build_report ( self , project , build_id , type = None ) :
"""GetBuildReport .
[ Preview API ] Gets a build report .
: param str project : Project ID or project name
: param int build _ id : The ID of the build .
: param str type :
: rtype : : class : ` < BuildReportMetadata > < azure . devops . v... | route_values = { }
if project is not None :
route_values [ 'project' ] = self . _serialize . url ( 'project' , project , 'str' )
if build_id is not None :
route_values [ 'buildId' ] = self . _serialize . url ( 'build_id' , build_id , 'int' )
query_parameters = { }
if type is not None :
query_parameters [ 't... |
def head ( self , n ) :
"""Return a DataAccessObject containing the first n rows
: param n : number of rows
: return : DataAccessObject""" | return DataAccessObject ( { k : self . dict [ k ] [ : n ] for k in self . dict } ) |
def get_n_config_to_keep ( self , n_suggestions , bracket_iteration ) :
"""Return the number of configs to keep and resume .""" | n_configs = n_suggestions * ( self . eta ** - bracket_iteration )
return int ( n_configs / self . eta ) |
def sepBy1 ( p , sep ) :
'''` sepBy1 ( p , sep ) ` parses one or more occurrences of ` p ` , separated by
` sep ` . Returns a list of values returned by ` p ` .''' | return separated ( p , sep , 1 , maxt = float ( 'inf' ) , end = False ) |
def frombed ( args ) :
"""% prog frombed bedfile
Generate AGP file based on bed file . The bed file must have at least 6
columns . With the 4 - th column indicating the new object .""" | p = OptionParser ( frombed . __doc__ )
p . add_option ( "--gapsize" , default = 100 , type = "int" , help = "Insert gaps of size [default: %default]" )
opts , args = p . parse_args ( args )
if len ( args ) != 1 :
sys . exit ( not p . print_help ( ) )
bedfile , = args
gapsize = opts . gapsize
agpfile = bedfile . rep... |
def get_zernike_indexes ( limit = 10 ) :
"""Return a list of all Zernike indexes up to the given limit
limit - return all Zernike indexes with N less than this limit
returns an array of 2 - tuples . Each tuple is organized as ( N , M ) .
The Zernikes are stored as complex numbers with the real part
being ( ... | def zernike_indexes_iter ( n_max ) :
for n in range ( 0 , n_max ) :
for m in range ( n % 2 , n + 1 , 2 ) :
yield n
yield m
z_ind = np . fromiter ( zernike_indexes_iter ( limit ) , np . intc )
z_ind = z_ind . reshape ( ( len ( z_ind ) // 2 , 2 ) )
return z_ind |
def add_empty_magic_table ( self , dtype , col_names = None , groups = None ) :
"""Add a blank MagicDataFrame to the contribution .
You can provide either a list of column names ,
or a list of column group names .
If provided , col _ names takes precedence .""" | if dtype not in self . table_names :
print ( "-W- {} is not a valid MagIC table name" . format ( dtype ) )
print ( "-I- Valid table names are: {}" . format ( ", " . join ( self . table_names ) ) )
return
data_container = MagicDataFrame ( dtype = dtype , columns = col_names , groups = groups )
self . tables ... |
def connect ( self ) :
"""Returns an open connection ( socket ) to the Splunk instance .
This method is used for writing bulk events to an index or similar tasks
where the overhead of opening a connection multiple times would be
prohibitive .
: returns : A socket .
* * Example * * : :
import splunklib .... | sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM )
if self . scheme == "https" :
sock = ssl . wrap_socket ( sock )
sock . connect ( ( socket . gethostbyname ( self . host ) , self . port ) )
return sock |
def send_photo ( self , * args , ** kwargs ) :
"""See : func : ` send _ photo `""" | return send_photo ( * args , ** self . _merge_overrides ( ** kwargs ) ) . run ( ) |
def _initialize_generator ( self , gen , obj = None ) :
"""Add ' last time ' and ' last value ' attributes to the generator .""" | # CEBALERT : use a dictionary to hold these things .
if hasattr ( obj , "_Dynamic_time_fn" ) :
gen . _Dynamic_time_fn = obj . _Dynamic_time_fn
gen . _Dynamic_last = None
# CEB : I ' d use None for this , except can ' t compare a fixedpoint
# number with None ( e . g . 1 > None but FixedPoint ( 1 ) > None can ' t be... |
def availability_rtf ( ) -> bool :
"""Is an RTF processor available ?""" | unrtf = tools [ 'unrtf' ]
if unrtf :
return True
elif pyth :
log . warning ( "RTF conversion: unrtf missing; " "using pyth (less efficient)" )
return True
else :
return False |
def get_incomings_per_page ( self , per_page = 1000 , page = 1 , params = None ) :
"""Get incomings per page
: param per _ page : How many objects per page . Default : 1000
: param page : Which page . Default : 1
: param params : Search parameters . Default : { }
: return : list""" | return self . _get_resource_per_page ( resource = INCOMINGS , per_page = per_page , page = page , params = params ) |
def get_categories ( self , languages = None ) :
"""GetCategories .
[ Preview API ]
: param str languages :
: rtype : [ str ]""" | query_parameters = { }
if languages is not None :
query_parameters [ 'languages' ] = self . _serialize . query ( 'languages' , languages , 'str' )
response = self . _send ( http_method = 'GET' , location_id = 'e0a5a71e-3ac3-43a0-ae7d-0bb5c3046a2a' , version = '5.1-preview.1' , query_parameters = query_parameters )
... |
def run_board ( args ) :
"""Run main entry for AutoMLBoard .
Args :
args : args parsed from command line""" | init_config ( args )
# backend service , should import after django settings initialized
from backend . collector import CollectorService
service = CollectorService ( args . logdir , args . reload_interval , standalone = False , log_level = args . log_level )
service . run ( )
# frontend service
logger . info ( "Try to... |
def timestamp_from_dt ( dt , epoch = datetime ( 1970 , 1 , 1 ) ) :
"""Convert a datetime to a timestamp .
https : / / stackoverflow . com / a / 8778548/141395""" | delta = dt - epoch
# return delta . total _ seconds ( )
return delta . seconds + delta . days * 86400 |
def Reset ( self ) :
"""Resets the internal state of the analyzer .""" | hasher_names = hashers_manager . HashersManager . GetHasherNamesFromString ( self . _hasher_names_string )
self . _hashers = hashers_manager . HashersManager . GetHashers ( hasher_names ) |
def start_r_creation_task_with_single_url ( self , body , ** kwargs ) :
"""Start Repository Creation task with url autodetect ( internal vs . external ) .
This method makes a synchronous HTTP request by default . To make an
asynchronous HTTP request , please define a ` callback ` function
to be invoked when r... | kwargs [ '_return_http_data_only' ] = True
if kwargs . get ( 'callback' ) :
return self . start_r_creation_task_with_single_url_with_http_info ( body , ** kwargs )
else :
( data ) = self . start_r_creation_task_with_single_url_with_http_info ( body , ** kwargs )
return data |
def get_focus_widget ( self ) :
"""Returns the Widget with focus .
: return : Widget with focus .
: rtype : QWidget""" | current_widget = QApplication . focusWidget ( )
if current_widget is None :
return False
if current_widget . objectName ( ) == "Script_Editor_Output_plainTextEdit" or isinstance ( current_widget , Editor ) :
return current_widget |
def cmdline_split ( s : str , platform : Union [ int , str ] = 'this' ) -> List [ str ] :
"""As per
https : / / stackoverflow . com / questions / 33560364 / python - windows - parsing - command - lines - with - shlex .
Multi - platform variant of ` ` shlex . split ( ) ` ` for command - line splitting .
For us... | # noqa
if platform == 'this' :
platform = ( sys . platform != 'win32' )
# RNC : includes 64 - bit Windows
if platform == 1 : # POSIX
re_cmd_lex = r'''"((?:\\["\\]|[^"])*)"|'([^']*)'|(\\.)|(&&?|\|\|?|\d?\>|[<])|([^\s'"\\&|<>]+)|(\s+)|(.)'''
# noqa
elif platform == 0 : # Windows / CMD
re_cmd_lex = r''... |
async def stream_as_text ( stream ) :
"""Given a stream of bytes or text , if any of the items in the stream
are bytes convert them to text .
This function can be removed once we return text streams
instead of byte streams .""" | async for data in stream :
if not isinstance ( data , six . text_type ) :
data = data . decode ( 'utf-8' , 'replace' )
yield data |
def validate_metadata ( train_config ) :
"""Perform some checks that the trainig config is correct .
Args :
train _ config : train config as produced by merge _ metadata ( )
Raises :
ValueError : if columns look wrong .""" | # Make sure we have a default for every column
if len ( train_config [ 'csv_header' ] ) != len ( train_config [ 'csv_defaults' ] ) :
raise ValueError ( 'Unequal number of columns in input features file and ' 'schema file.' )
# Check there are no missing columns . sorted _ colums has two copies of the
# target colum... |
def _IsMariaDB ( cursor ) :
"""Checks if we are running against MariaDB .""" | for variable in [ "version" , "version_comment" ] :
cursor . execute ( "SHOW VARIABLES LIKE %s;" , ( variable , ) )
version = cursor . fetchone ( )
if version and "MariaDB" in version [ 1 ] :
return True
return False |
def save ( self , basename ) :
"""Save a set of V1 images for flashing . Parameter is a base filename .""" | # IROM data goes in its own plain binary file
irom_segment = self . get_irom_segment ( )
if irom_segment is not None :
with open ( "%s0x%05x.bin" % ( basename , irom_segment . addr - ESP8266ROM . IROM_MAP_START ) , "wb" ) as f :
f . write ( irom_segment . data )
# everything but IROM goes at 0x00000 in an i... |
def locate_primers ( sequences , forward_primer , reverse_primer , reverse_complement , max_hamming_distance ) :
"""Find forward and reverse primers in a set of sequences , return two tuples :
( forward _ start , forward _ end ) , ( reverse _ start , reverse _ end )""" | forward_loc = None
reverse_loc = None
seq_length = None
# Reverse complement the reverse primer , if appropriate
if reverse_complement :
reverse_primer = reverse_primer . reverse_complement ( )
forward_aligner = PrimerAligner ( forward_primer )
reverse_aligner = PrimerAligner ( reverse_primer )
for i , sequence in ... |
def qt4_menu_nib_dir ( ) :
"""Return path to Qt resource dir qt _ menu . nib .""" | menu_dir = ''
# Detect MacPorts prefix ( usually / opt / local ) .
# Suppose that PyInstaller is using python from macports .
macports_prefix = sys . executable . split ( '/Library' ) [ 0 ]
# list of directories where to look for qt _ menu . nib
dirs = [ # Qt4 from MacPorts not compiled as framework .
os . path . join ... |
def make_single_array ( ds , batch_size = 8 * 1024 ) :
"""Create a single numpy array from a dataset .
The dataset must have only one dimension , that is ,
the length of its ` output _ shapes ` and ` output _ types `
is 1 , and its output shape must be ` [ ] ` , that is ,
every tensor in the dataset must be... | if isinstance ( ds . output_types , tuple ) or isinstance ( ds . output_shapes , tuple ) :
raise ValueError ( 'Dataset must have a single type and shape' )
nshapes = len ( ds . output_shapes )
if nshapes > 0 :
raise ValueError ( 'Dataset must be comprised of scalars (TensorShape=[])' )
batches = [ ]
with tf . S... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.