signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def write ( self , message ) :
"""Writes given message to logger handlers .
: param message : Message .
: type message : unicode
: return : Method success .
: rtype : bool""" | for handler in self . __logger . __dict__ [ "handlers" ] :
handler . stream . write ( message )
return True |
def get_character ( self , position , offset = 0 ) :
"""Return character at * position * with the given offset .""" | position = self . get_position ( position ) + offset
cursor = self . textCursor ( )
cursor . movePosition ( QTextCursor . End )
if position < cursor . position ( ) :
cursor . setPosition ( position )
cursor . movePosition ( QTextCursor . Right , QTextCursor . KeepAnchor )
return to_text_string ( cursor . se... |
def split_run ( self ) :
""". . _ split _ run :
Splits the assembly code into
* commands
* directives
* jump marks""" | sp_run = [ ]
for line in self . open_stream . read ( ) . split ( "\n" ) :
self . line_count += 1
if ( self . iscomment ( line ) ) :
continue
if ( line . isspace ( ) ) :
continue
line = self . stripcomments ( line )
words = line . split ( )
if ( len ( words ) == 0 ) :
cont... |
def execute ( self , command , is_displayed = True , profile = None ) :
"""Execute a command on the remote server
: param command : Command to execute remotely
: param is _ displayed : True if information should be display ; false to return output
( default : true )
: param profile : Profile to source ( uni... | # Modify the command for remote execution
command = " " . join ( "'{0}'" . format ( argument ) for argument in command )
# Execute the command and initialize for reading ( close stdin / writes )
if not profile is None and not profile is "None" :
command = "source " + profile + ";" + command
stdin , stdout , stderr ... |
def _file_nums_str ( self , n_all , n_type , n_ign ) :
"""Construct a string showing the number of different file types .
Returns
f _ str : str""" | # ' other ' is the difference between all and named
n_oth = n_all - np . sum ( n_type )
f_str = "{} Files" . format ( n_all ) + " ("
if len ( n_type ) :
f_str += ", " . join ( "{} {}" . format ( name , num ) for name , num in zip ( self . _COUNT_FILE_TYPES , n_type ) )
f_str += ", "
f_str += "other {}; {} ignor... |
def install ( self , connection , partition , table_name = None , columns = None , materialize = False , logger = None ) :
"""Creates FDW or materialize view for given partition .
Args :
connection : connection to postgresql
partition ( orm . Partition ) :
materialize ( boolean ) : if True , create read - o... | partition . localize ( )
self . _add_partition ( connection , partition )
fdw_table = partition . vid
view_table = '{}_v' . format ( fdw_table )
if materialize :
with connection . cursor ( ) as cursor :
view_exists = self . _relation_exists ( connection , view_table )
if view_exists :
lo... |
def is_tiff_format ( self ) :
"""Checks whether file format is a TIFF image format
Example : ` ` MimeType . TIFF . is _ tiff _ format ( ) ` ` or ` ` MimeType . is _ tiff _ format ( MimeType . TIFF ) ` `
: param self : File format
: type self : MimeType
: return : ` ` True ` ` if file is in image format , ` ... | return self in frozenset ( [ MimeType . TIFF , MimeType . TIFF_d8 , MimeType . TIFF_d16 , MimeType . TIFF_d32f ] ) |
async def start_serving ( self , address = None , sockets = None , ** kw ) :
"""create the server endpoint .""" | if self . _server :
raise RuntimeError ( 'Already serving' )
server = DGServer ( self . _loop )
loop = self . _loop
if sockets :
for sock in sockets :
transport , _ = await loop . create_datagram_endpoint ( self . create_protocol , sock = sock )
server . transports . append ( transport )
elif is... |
def graph_type ( self , graph ) :
"""What type of graph is this ?""" | graph = self . pack ( graph )
return self . sql ( 'graph_type' , graph ) . fetchone ( ) [ 0 ] |
def tags ( self ) :
"""Returns a ` set ` of unique tags contained in ` raw _ content ` .""" | if not self . raw_content :
return set ( )
return { word . strip ( "#" ) . lower ( ) for word in self . raw_content . split ( ) if word . startswith ( "#" ) and len ( word ) > 1 } |
def debug ( version = False ) :
"""Shows the parsed manage file - V shows version""" | if version :
print ( __version__ )
return
print ( json . dumps ( MANAGE_DICT , indent = 2 ) ) |
def add_info ( self , data ) :
"""add info to a build""" | for key in data : # verboten
if key in ( 'status' , 'state' , 'name' , 'id' , 'application' , 'services' , 'release' ) :
raise ValueError ( "Sorry, cannot set build info with key of {}" . format ( key ) )
self . obj [ key ] = data [ key ]
self . changes . append ( "Adding build info" )
return self |
def walk_packages ( path = None , prefix = '' , onerror = None ) :
"""Yields ( module _ loader , name , ispkg ) for all modules recursively
on path , or , if path is None , all accessible modules .
' path ' should be either None or a list of paths to look for
modules in .
' prefix ' is a string to output on... | def seen ( p , m = { } ) :
if p in m :
return True
m [ p ] = True
for importer , name , ispkg in iter_modules ( path , prefix ) :
yield importer , name , ispkg
if ispkg :
try :
__import__ ( name )
except ImportError :
if onerror is not None :
... |
def standard_cl_params ( items ) :
"""Shared command line parameters for GATK programs .
Handles no removal of duplicate reads for amplicon or
non mark duplicate experiments . If we have pre - aligned inputs we
ignore the value or mark duplicates ( since they may already be
marked in the input BAM ) .""" | out = [ ]
def _skip_duplicates ( data ) :
return ( dd . get_coverage_interval ( data ) == "amplicon" or ( dd . get_aligner ( data ) and not dd . get_mark_duplicates ( data ) ) )
if any ( _skip_duplicates ( d ) for d in items ) :
broad_runner = broad . runner_from_config ( items [ 0 ] [ "config" ] )
gatk_typ... |
def close ( self ) :
"Stop the output stream , but further download will still perform" | if self . stream :
self . stream . close ( self . scheduler )
self . stream = None |
def Parse ( conditions ) :
"""Parses the file finder condition types into the condition objects .
Args :
conditions : An iterator over ` FileFinderCondition ` objects .
Yields :
` ContentCondition ` objects that correspond to the file - finder conditions .""" | kind = rdf_file_finder . FileFinderCondition . Type
classes = { kind . CONTENTS_LITERAL_MATCH : LiteralMatchCondition , kind . CONTENTS_REGEX_MATCH : RegexMatchCondition , }
for condition in conditions :
try :
yield classes [ condition . condition_type ] ( condition )
except KeyError :
pass |
def acquire_lock ( self , force = False ) :
"""Takes out a lock ( creates a < dbname > . lock file ) for the database .
: param force : Whether to force taking " ownership " of the lock file .
: type force : bool
: raises : : class : ` keepassdb . exc . DatabaseAlreadyLocked ` - If the database is already loc... | if self . readonly :
raise exc . ReadOnlyDatabase ( )
if not self . _locked :
self . log . debug ( "Acquiring lock file: {0}" . format ( self . lockfile ) )
if os . path . exists ( self . lockfile ) and not force :
raise exc . DatabaseAlreadyLocked ( 'Lock file already exists: {0}' . format ( self .... |
def path ( self , which = None ) :
"""Extend ` ` nailgun . entity _ mixins . Entity . path ` ` .
The format of the returned path depends on the value of ` ` which ` ` :
logs
/ containers / < id > / logs
power
/ containers / < id > / power
` ` super ` ` is called otherwise .""" | if which in ( 'logs' , 'power' ) :
return '{0}/{1}' . format ( super ( AbstractDockerContainer , self ) . path ( which = 'self' ) , which )
return super ( AbstractDockerContainer , self ) . path ( which ) |
def _yield_spatial_table ( patch , div , spp_col , count_col , x_col , y_col ) :
"""Calculates an empirical spatial table
Yields
DataFrame
Spatial table for each division . See Notes .
Notes
The spatial table is the precursor to the SAR , EAR , and grid - based
commonality metrics . Each row in the tabl... | # Catch error if you don ' t use ; after divs in comm _ grid in MacroecoDesktop
try :
div_split_list = div . replace ( ';' , '' ) . split ( ',' )
except AttributeError :
div_split_list = str ( div ) . strip ( "()" ) . split ( ',' )
div_split = ( x_col + ':' + div_split_list [ 0 ] + ';' + y_col + ':' + div_split... |
def create_snapshot ( self , name = None , description = None , force = False ) :
"""Creates a snapshot of this volume , with an optional name and
description .
Normally snapshots will not happen if the volume is attached . To
override this default behavior , pass force = True .""" | name = name or ""
description = description or ""
# Note that passing in non - None values is required for the _ create _ body
# method to distinguish between this and the request to create and
# instance .
return self . manager . create_snapshot ( volume = self , name = name , description = description , force = force... |
def apply_adaptation ( self , target_illuminant , adaptation = 'bradford' ) :
"""This applies an adaptation matrix to change the XYZ color ' s illuminant .
You ' ll most likely only need this during RGB conversions .""" | logger . debug ( " \- Original illuminant: %s" , self . illuminant )
logger . debug ( " \- Target illuminant: %s" , target_illuminant )
# If the XYZ values were taken with a different reference white than the
# native reference white of the target RGB space , a transformation matrix
# must be applied .
if self . illu... |
def to_dataframe ( self ) :
"""Returns the entire dataset as a single pandas DataFrame .
Returns
df : DataFrame with shape ( n _ instances , n _ columns )
A pandas DataFrame containing the complete original data table
including all targets ( specified by the meta data ) and all
features ( including those ... | if pd is None :
raise DatasetsError ( "pandas is required to load DataFrame, it can be installed with pip" )
path = find_dataset_path ( self . name , ext = ".csv.gz" , data_home = self . data_home )
return pd . read_csv ( path , compression = "gzip" ) |
def replicate_value ( value , n = 2 , copy = True ) :
"""Replicates ` n ` times the input value .
: param n :
Number of replications .
: type n : int
: param value :
Value to be replicated .
: type value : T
: param copy :
If True the list contains deep - copies of the value .
: type copy : bool
... | return bypass ( * [ value ] * n , copy = copy ) |
def recursive_input ( input_label , type_class ) :
'''Recursive user input prompter with type checker
Args
type _ class : type
name of python type ( e . g . float , no parentheses )
Returns
output : str
value entered by user converted to type ` type _ class `
Note
Use ` ctrl - c ` to exit input cycl... | import sys
type_str = str ( type_class ) . split ( "'" ) [ 1 ]
msg = 'Enter {} (type `{}`): ' . format ( input_label , type_str )
# Catch ` Ctrl - c ` keyboard interupts
try :
output = input ( msg )
print ( '' )
# Type class input , else cycle input function again
try :
output = type_class ( out... |
def get_file_contents ( filename ) :
"""Read file contents from file ` filename `""" | data = None
try :
with open ( filename ) as pf :
data = pf . read ( )
except IOError : # File not found , return None
pass
return data |
def _load_char ( self , char ) :
"""Build and store a glyph corresponding to an individual character
Parameters
char : str
A single character to be represented .""" | assert isinstance ( char , string_types ) and len ( char ) == 1
assert char not in self . _glyphs
# load new glyph data from font
_load_glyph ( self . _font , char , self . _glyphs )
# put new glyph into the texture
glyph = self . _glyphs [ char ]
bitmap = glyph [ 'bitmap' ]
# convert to padded array
data = np . zeros ... |
def member_present ( ip , port , balancer_id , profile , ** libcloud_kwargs ) :
'''Ensure a load balancer member is present
: param ip : IP address for the new member
: type ip : ` ` str ` `
: param port : Port for the new member
: type port : ` ` int ` `
: param balancer _ id : id of a load balancer you ... | existing_members = __salt__ [ 'libcloud_loadbalancer.list_balancer_members' ] ( balancer_id , profile )
for member in existing_members :
if member [ 'ip' ] == ip and member [ 'port' ] == port :
return state_result ( True , "Member already present" , balancer_id )
member = __salt__ [ 'libcloud_loadbalancer.b... |
def write_mzxml ( filename , df , info = None , precision = 'f' ) :
"""Precision is either f or d .""" | for r in df . values :
df . columns
pass |
def find ( cls , key = None , ** kwargs ) :
"""Find an asset by key
E . g .
shopify . Asset . find ( ' layout / theme . liquid ' , theme _ id = 99)""" | if not key :
return super ( Asset , cls ) . find ( ** kwargs )
params = { "asset[key]" : key }
params . update ( kwargs )
theme_id = params . get ( "theme_id" )
path_prefix = "%s/themes/%s" % ( cls . site , theme_id ) if theme_id else cls . site
resource = cls . find_one ( "%s/assets.%s" % ( path_prefix , cls . for... |
def plot_ell ( fignum , pars , col , lower , plot ) :
"""function to calcualte / plot points on an ellipse about Pdec , Pdip with angle beta , gamma
Parameters
_ _ _ _ _
fignum : matplotlib figure number
pars : list of [ Pdec , Pinc , beta , Bdec , Binc , gamma , Gdec , Ginc ]
where P is direction , Bdec ... | plt . figure ( num = fignum )
rad = old_div ( np . pi , 180. )
Pdec , Pinc , beta , Bdec , Binc , gamma , Gdec , Ginc = pars [ 0 ] , pars [ 1 ] , pars [ 2 ] , pars [ 3 ] , pars [ 4 ] , pars [ 5 ] , pars [ 6 ] , pars [ 7 ]
if beta > 90. or gamma > 90 :
beta = 180. - beta
gamma = 180. - gamma
Pdec = Pdec - 18... |
def construct ( self , request , service = None , http_args = None , ** kwargs ) :
"""Construct a dictionary to be added to the HTTP request headers
: param request : The request
: param service : A
: py : class : ` oidcservice . service . Service ` instance
: param http _ args : HTTP arguments
: return :... | if http_args is None :
http_args = { }
if "headers" not in http_args :
http_args [ "headers" ] = { }
# get the username ( client _ id ) and the password ( client _ secret )
try :
passwd = kwargs [ "password" ]
except KeyError :
try :
passwd = request [ "client_secret" ]
except KeyError :
... |
def lazy_groups_of ( iterator : Iterator [ A ] , group_size : int ) -> Iterator [ List [ A ] ] :
"""Takes an iterator and batches the individual instances into lists of the
specified size . The last list may be smaller if there are instances left over .""" | return iter ( lambda : list ( islice ( iterator , 0 , group_size ) ) , [ ] ) |
def _make_request ( self , uri , method , body , headers = { } ) :
"""Wraps the response and content returned by : mod : ` httplib2 ` into a
: class : ` ~ webunit2 . response . HttpResponse ` object .
` ` uri ` ` :
Absolute URI to the resource .
` ` method ` ` :
Any supported HTTP methods defined in : rfc... | response , content = self . _httpobj . request ( uri , method = method , body = body , headers = headers )
return HttpResponse ( response , content ) |
def paginate_response ( self , queryset , serializers_kwargs = { } ) :
"""Optionally return paginated response .
If pagination parameters are provided in the request , then paginated response
is returned , otherwise response is not paginated .""" | page = self . paginate_queryset ( queryset )
if page is not None :
serializer = self . get_serializer ( page , many = True , ** serializers_kwargs )
return self . get_paginated_response ( serializer . data )
serializer = self . get_serializer ( queryset , many = True , ** serializers_kwargs )
return Response ( ... |
def analyze ( self , scratch , ** kwargs ) :
"""Categorize instances of attempted say and sound synchronization .""" | errors = Counter ( )
for script in self . iter_scripts ( scratch ) :
prev_name , prev_depth , prev_block = '' , 0 , script . blocks [ 0 ]
gen = self . iter_blocks ( script . blocks )
for name , depth , block in gen :
if prev_depth == depth :
if prev_name in self . SAY_THINK :
... |
def __reversed_filter ( filterable , filter_ , logic_operation = 'and' ) :
"""reverse filtering DataFrame using filter _ key - value conditions applying logic _ operation
find rows where existing filterable columns ( and its values ) fitting the filter _ criterion""" | condition = [ ]
try :
subscribers_for_any = filterable . query ( 'type == "__ANY__"' )
except pd . core . computation . ops . UndefinedVariableError :
subscribers_for_any = pd . DataFrame ( )
if not filter_ :
return filterable
else :
for existing_col in filterable :
for meta_tag , meta_value in ... |
def schedule_next_job ( self ) :
"""Get the next job in the queue to be scheduled , and send a message
to the workers to start the job .
Returns : None""" | next_job = self . storage_backend . get_next_scheduled_job ( )
# TODO : don ' t loop over if workers are already all running
if not next_job :
logging . debug ( "No job to schedule right now." )
return
try :
self . messaging_backend . send ( self . worker_mailbox , Message ( type = MessageType . START_JOB ,... |
def hacking_todo_format ( physical_line , tokens ) :
"""Check for ' TODO ( ) ' .
OpenStack HACKING guide recommendation for TODO :
Include your name with TODOs as in " # TODO ( termie ) "
Okay : # TODO ( sdague )
H101 : # TODO fail
H101 : # TODO
H101 : # TODO ( jogo ) fail
Okay : TODO = 5""" | # TODO ( jogo ) : make the following doctests pass :
# H101 : # TODO ( jogo fail
# H101 : # TODO ( jogo
# TODO ( jogo ) : make this check docstrings as well ( don ' t have to be at top
# of function )
for token_type , text , start_index , _ , _ in tokens :
if token_type == tokenize . COMMENT :
pos = text . ... |
def is_quoted ( position , text ) :
"""Determine if the position in the text falls within a quote .""" | def matching ( quotemark1 , quotemark2 ) :
straight = '\"\''
curly = '“”'
if quotemark1 in straight and quotemark2 in straight :
return True
if quotemark1 in curly and quotemark2 in curly :
return True
else :
return False
def find_ranges ( text ) :
s = 0
q = pc = ''
... |
def update ( user = None , conf_file = None , bin_env = None , name = None ) :
'''Reload config and add / remove / update as necessary
user
user to run supervisorctl as
conf _ file
path to supervisord config file
bin _ env
path to supervisorctl bin or path to virtualenv with supervisor
installed
nam... | if isinstance ( name , string_types ) :
if name . endswith ( ':' ) :
name = name [ : - 1 ]
elif name . endswith ( ':*' ) :
name = name [ : - 2 ]
ret = __salt__ [ 'cmd.run_all' ] ( _ctl_cmd ( 'update' , name , conf_file , bin_env ) , runas = user , python_shell = False , )
return _get_return ( re... |
def from_array ( array ) :
"""Deserialize a new InlineKeyboardMarkup from a given dictionary .
: return : new InlineKeyboardMarkup instance .
: rtype : InlineKeyboardMarkup""" | if array is None or not array :
return None
# end if
assert_type_or_raise ( array , dict , parameter_name = "array" )
from pytgbot . api_types . sendable . reply_markup import InlineKeyboardButton
data = { }
data [ 'inline_keyboard' ] = InlineKeyboardButton . from_array_list ( array . get ( 'inline_keyboard' ) , li... |
def translate_path ( self , path ) :
"""Translate a / - separated PATH to the local filename syntax .
Components that mean special things to the local file system
( e . g . drive or directory names ) are ignored . ( XXX They should
probably be diagnosed . )""" | # abandon query parameters
path = path . split ( '?' , 1 ) [ 0 ]
path = path . split ( '#' , 1 ) [ 0 ]
path = posixpath . normpath ( urllib_parse . unquote ( path ) )
words = path . split ( '/' )
words = filter ( None , words )
path = os . getcwd ( )
for word in words :
drive , word = os . path . splitdrive ( word ... |
def formfield_for_dbfield ( self , db_field , ** kwargs ) :
"""Make slug mandatory .""" | if db_field . name == "slug" :
kwargs [ "required" ] = True
kwargs [ "help_text" ] = None
return super ( LinkAdmin , self ) . formfield_for_dbfield ( db_field , ** kwargs ) |
def save_results ( self , path = '.' ) :
"""Save results on disk .""" | with open ( path , 'wb' ) as f :
pickle . dump ( self . results , f ) |
def add ( self , key ) :
"""Adds a key to this bloom filter .
If the key already exists in this filter it will return True .
Otherwise False .
> > > b = ScalableBloomFilter ( initial _ capacity = 100 , error _ rate = 0.001 , mode = ScalableBloomFilter . SMALL _ SET _ GROWTH )
> > > b . add ( " hello " )
F... | if key in self :
return True
if not self . filters :
filter = BloomFilter ( capacity = self . initial_capacity , error_rate = self . error_rate * ( 1.0 - self . ratio ) )
self . filters . append ( filter )
else :
filter = self . filters [ - 1 ]
if filter . count >= filter . capacity :
filter... |
def w ( self ) :
"""int : The width of the texture in pixels .""" | w = ffi . new ( 'int *' )
check_int_err ( lib . SDL_QueryTexture ( self . _ptr , ffi . NULL , ffi . NULL , w , ffi . NULL ) )
return w [ 0 ] |
def android_setup_view ( request ) :
"""Set up a GCM session .
This does * not * require a valid login session . Instead , a token from the client
session is sent to the Android backend , which queries a POST request to this view .
The " android _ gcm _ rand " is randomly set when the Android app is detected ... | logger . debug ( request . POST )
if request . method == "POST" :
if "user_token" in request . POST and "gcm_token" in request . POST :
user_token = request . POST . get ( "user_token" )
gcm_token = request . POST . get ( "gcm_token" )
logger . debug ( user_token )
logger . debug ( g... |
def get_kernelspec ( self , name ) :
"""Get a kernel specification dictionary given a kernel name""" | ksm = KernelSpecManager ( )
kernelspec = ksm . get_kernel_spec ( name ) . to_dict ( )
kernelspec [ 'name' ] = name
kernelspec . pop ( 'argv' )
return kernelspec |
def get_option_lists ( self ) :
"""A hook to override the option lists used to generate option names
and defaults .""" | return [ self . get_option_list ( ) ] + [ option_list for name , description , option_list in self . get_option_groups ( ) ] |
def splitText ( text ) :
"""Split text into sub segments of size not bigger than MAX _ SEGMENT _ SIZE .""" | segments = [ ]
remaining_text = __class__ . cleanSpaces ( text )
while len ( remaining_text ) > __class__ . MAX_SEGMENT_SIZE :
cur_text = remaining_text [ : __class__ . MAX_SEGMENT_SIZE ]
# try to split at punctuation
split_idx = __class__ . findLastCharIndexMatching ( cur_text , # https : / / en . wikipedi... |
def dcc_event ( regexp , callback = None , iotype = 'in' , venusian_category = 'irc3.dcc' ) :
"""Work like : class : ` ~ irc3 . dec . event ` but occurs during DCC CHATs""" | return event ( regexp , callback = callback , iotype = 'dcc_' + iotype , venusian_category = venusian_category ) |
def remove_role_from_user ( self , user , role ) :
"""Removes a role from a user .
: param user : The user to manipulate
: param role : The role to remove from the user""" | rv = False
user , role = self . _prepare_role_modify_args ( user , role )
if role in user . roles :
rv = True
user . roles . remove ( role )
self . put ( user )
return rv |
def run ( self ) :
"""Creates a new replica using WAL - E
Returns
ExitCode
0 = Success
1 = Error , try again
2 = Error , don ' t try again""" | if self . init_error :
logger . error ( 'init error: %r did not exist at initialization time' , self . wal_e . env_dir )
return ExitCode . FAIL
try :
should_use_s3 = self . should_use_s3_to_create_replica ( )
if should_use_s3 is None : # Need to retry
return ExitCode . RETRY_LATER
elif shoul... |
def end ( self ) :
"""Write all JSON data to files .""" | for comic in self . data :
with codecs . open ( self . jsonFn ( comic ) , 'w' , self . encoding ) as f :
json . dump ( self . data [ comic ] , f , indent = 2 , separators = ( ',' , ': ' ) , sort_keys = True ) |
def get_grouped ( self , go_ntsets , go_all , gosubdag , ** kws ) :
"""Get Grouped object .""" | kws_grpd = { k : v for k , v in kws . items ( ) if k in Grouped . kws_dict }
kws_grpd [ 'go2nt' ] = self . _init_go2ntpresent ( go_ntsets , go_all , gosubdag )
return Grouped ( gosubdag , self . godag . version , ** kws_grpd ) |
def minimizePowell ( objectiveFunction , parameter_guess , verbose = False ) :
'''Minimizes the objective function using a derivative - free Powell algorithm ,
starting from an initial parameter guess .
Parameters
objectiveFunction : function
The function to be minimized . It should take only a single argum... | # Execute the minimization , starting from the given parameter guess
t0 = time ( )
# Time the process
OUTPUT = fmin_powell ( objectiveFunction , parameter_guess , full_output = 1 , maxiter = 1000 , disp = verbose )
t1 = time ( )
# Extract values from optimization output :
xopt = OUTPUT [ 0 ]
# Parameters that minimize ... |
def get_one_dimensional_kernel ( self , dim ) :
"""Specially intended for Grid regression .""" | oneDkernel = GridRBF ( input_dim = 1 , variance = self . variance . copy ( ) , originalDimensions = dim )
return oneDkernel |
def axml ( input_ , output , file_ , resource ) :
"""Parse the AndroidManifest . xml .
Parsing is either direct or from a given APK and prints in XML format or
saves to file .
This tool can also be used to process any AXML encoded file , for example
from the layout directory .
Example :
$ androguard axm... | if file_ is not None and input_ is not None :
print ( "Can not give --input and positional argument! " "Please use only one of them!" )
sys . exit ( 1 )
if file_ is None and input_ is None :
print ( "Give one file to decode!" )
sys . exit ( 1 )
if file_ is not None :
androaxml_main ( file_ , output ... |
def pool ( builder , size , timeout = None ) :
"""Create a pool that imposes a limit on the number of stored
instances .
Args :
builder : a function to build an instance .
size : the size of the pool .
timeout ( Optional [ float ] ) : the seconds to wait before raising
a ` ` queue . Empty ` ` exception ... | lock = threading . Lock ( )
local_pool = queue . Queue ( )
current_size = 0
@ contextlib . contextmanager
def pooled ( ) :
nonlocal current_size
instance = None
# If we still have free slots , then we have room to create new
# instances .
if current_size < size :
with lock : # We need to che... |
def set_ref ( self , ref_key , ref_id ) :
"""Using a ref key and ref id set the
reference to the appropriate resource type .""" | if ref_key == 'NETWORK' :
self . network_id = ref_id
elif ref_key == 'NODE' :
self . node_id = ref_id
elif ref_key == 'LINK' :
self . link_id = ref_id
elif ref_key == 'GROUP' :
self . group_id = ref_id
elif ref_key == 'SCENARIO' :
self . scenario_id = ref_id
elif ref_key == 'PROJECT' :
self . pr... |
def marketplace ( self ) :
""": returns : Version marketplace of preview
: rtype : twilio . rest . preview . marketplace . Marketplace""" | if self . _marketplace is None :
self . _marketplace = Marketplace ( self )
return self . _marketplace |
def dict_to_schema ( schema_dict , required , allow_custom_keys = True , modifier = None ) :
"""Convert a dict of Schemas into a Schema .
Args :
required ( bool ) : Whether to make schema keys optional or required .
allow _ custom _ keys ( bool , optional ) : If True , creates a schema that
allows custom it... | if modifier :
modifier = Use ( modifier )
def _to ( value ) :
if isinstance ( value , dict ) :
d = { }
for k , v in value . iteritems ( ) :
if isinstance ( k , basestring ) :
k = Required ( k ) if required else Optional ( k )
d [ k ] = _to ( v )
if... |
def startConnection ( self , point , cls = None , output = True ) :
"""Starts creating a new connection from the given output point . If a connection class is not provided , then the defaultConnectionClass will be used .
: param point < QPointF >
cls subclass of < XNodeConnection >
output < bool >""" | # clear the last connection
self . finishConnection ( False )
# create a new connection
self . _activeConnection = self . addConnection ( cls )
if self . _activeConnection :
self . _activeConnection . setOutputPoint ( point )
self . _activeConnection . setInputPoint ( point )
self . _activeConnection . setC... |
def _get_version_for_class_from_state ( state , klass ) :
"""retrieves the version of the current klass from the state mapping from old locations to new ones .""" | # klass may have been renamed , so we have to look this up in the class rename registry .
names = [ _importable_name ( klass ) ]
# lookup old names , handled by current klass .
from . util import class_rename_registry
names . extend ( class_rename_registry . old_handled_by ( klass ) )
for n in names :
try :
... |
def vars_to_array ( self ) :
"""Convert ` self . vars ` to a numpy array
Returns
numpy . array""" | logger . warn ( 'This function is deprecated. You can inspect `self.np_vars` directly as NumPy arrays ' 'without conversion.' )
if not self . vars :
return None
vars_matrix = matrix ( self . vars , size = ( self . vars [ 0 ] . size [ 0 ] , len ( self . vars ) ) ) . trans ( )
self . vars_array = np . array ( vars_ma... |
def hash_pair ( first : Keccak256 , second : Optional [ Keccak256 ] ) -> Keccak256 :
"""Computes the keccak hash of the elements ordered topologically .
Since a merkle proof will not include all the elements , but only the path
starting from the leaves up to the root , the order of the elements is not
known b... | assert first is not None
if second is None :
return first
if first > second :
return sha3 ( second + first )
return sha3 ( first + second ) |
def delayed_bamprep_merge ( samples , run_parallel ) :
"""Perform a delayed merge on regional prepared BAM files .""" | if any ( "combine" in data [ 0 ] for data in samples ) :
return run_parallel ( "delayed_bam_merge" , samples )
else :
return samples |
def get_aux_files ( basename ) :
"""Look for and return all the aux files that are associated witht this filename .
Will look for :
background ( _ bkg . fits )
rms ( _ rms . fits )
mask ( . mim )
catalogue ( _ comp . fits )
psf map ( _ psf . fits )
will return filenames if they exist , or None where t... | base = os . path . splitext ( basename ) [ 0 ]
files = { "bkg" : base + "_bkg.fits" , "rms" : base + "_rms.fits" , "mask" : base + ".mim" , "cat" : base + "_comp.fits" , "psf" : base + "_psf.fits" }
for k in files . keys ( ) :
if not os . path . exists ( files [ k ] ) :
files [ k ] = None
return files |
def reindex ( self , fq = [ ] , ** kwargs ) :
'''Starts Reindexing Process . All parameter arguments will be passed down to the getter function .
: param string fq : FilterQuery to pass to source Solr to retrieve items . This can be used to limit the results .''' | for items in self . _getter ( fq = fq , ** kwargs ) :
self . _putter ( items )
if type ( self . _dest ) is SolrClient and self . _dest_coll :
self . log . info ( "Finished Indexing, sending a commit" )
self . _dest . commit ( self . _dest_coll , openSearcher = True ) |
def attribute_crawl ( self , key ) :
"""Grab all attribute values associated with the given feature .
Traverse the given feature ( and all of its descendants ) to find all
values associated with the given attribute key .
> > > import tag
> > > reader = tag . GFF3Reader ( tag . pkgdata ( ' otau - no - seqreg... | union = set ( )
for feature in self :
values = feature . get_attribute ( key , as_list = True )
if values is not None :
union . update ( set ( values ) )
return union |
def role_list ( ) :
'''List all available roles
CLI Example :
. . code - block : : bash
salt ' * ' rbac . role _ list''' | roles = { }
# # read user _ attr file ( user : qualifier : res1 : res2 : attr )
with salt . utils . files . fopen ( '/etc/user_attr' , 'r' ) as user_attr :
for role in user_attr :
role = salt . utils . stringutils . to_unicode ( role )
role = role . split ( ':' )
# skip comments and non comp... |
def by_occupied_housing_units ( self , lower = - 1 , upper = 2 ** 31 , zipcode_type = ZipcodeType . Standard , sort_by = SimpleZipcode . occupied_housing_units . name , ascending = False , returns = DEFAULT_LIMIT ) :
"""Search zipcode information by occupied house of units .""" | return self . query ( occupied_housing_units_lower = lower , occupied_housing_units_upper = upper , sort_by = sort_by , zipcode_type = zipcode_type , ascending = ascending , returns = returns , ) |
def _spark_streaming_statistics_metrics ( self , instance , running_apps , addl_tags , requests_config ) :
"""Get metrics for each application streaming statistics .""" | for app_id , ( app_name , tracking_url ) in iteritems ( running_apps ) :
try :
base_url = self . _get_request_url ( instance , tracking_url )
response = self . _rest_request_to_json ( base_url , SPARK_APPS_PATH , SPARK_SERVICE_CHECK , requests_config , addl_tags , app_id , 'streaming/statistics' , )... |
def _from_func ( cls , f , * args , _attr_scts = None , ** kwargs ) :
"""Creates a function chain starting with the specified SCT ( f ) , and its arguments .""" | func_chain = cls ( attr_scts = _attr_scts )
func_chain . _stack . append ( [ f , args , kwargs ] )
return func_chain |
def arg_comparitor ( name ) :
""": param arg name
: return : pair containing name , comparitor
given an argument name , munge it and return a proper comparitor
> > > arg _ comparitor ( " a " )
a , operator . eq
> > > arg _ comparitor ( " a _ _ in " )
a , operator . contains""" | if name . endswith ( "__in" ) :
return name [ : - 4 ] , contains
elif name . endswith ( "__ge" ) :
return name [ : - 4 ] , ge
elif name . endswith ( "__gt" ) :
return name [ : - 4 ] , gt
elif name . endswith ( "__le" ) :
return name [ : - 4 ] , le
elif name . endswith ( "__lt" ) :
return name [ : - ... |
def rm ( device , minor ) : # pylint : disable = C0103
'''Removes the partition with number < minor > .
CLI Example :
. . code - block : : bash
salt ' * ' partition . rm / dev / sda 5''' | _validate_device ( device )
try :
int ( minor )
except Exception :
raise CommandExecutionError ( 'Invalid minor number passed to partition.rm' )
cmd = 'parted -m -s {0} rm {1}' . format ( device , minor )
out = __salt__ [ 'cmd.run' ] ( cmd ) . splitlines ( )
return out |
def calculate_bin_widths ( edges ) :
"""Calculate the widths of wavelengths bins given their edges .
Parameters
edges : array _ like
Sequence of bin edges . Must be 1D and have at least two values .
Returns
widths : ndarray
Array of bin widths . Will be 1D and have one less value than ` ` edges ` ` .""" | edges = np . asanyarray ( edges )
if edges . ndim != 1 :
raise ValueError ( 'edges input array must be 1D.' )
if edges . size < 2 :
raise ValueError ( 'edges input must have at least two values.' )
return edges [ 1 : ] - edges [ : - 1 ] |
def strip_html ( value , allowed_tags = [ ] , allowed_attributes = [ ] , allowed_styles = [ ] ) :
"""Template tag to strip html from string values . It accepts lists of
allowed tags , attributes or stylesin comma separated string or list format .
For example :
{ % load sanitizer % }
{ % strip _ html ' < a h... | if isinstance ( value , basestring ) :
value = bleach . clean ( value , tags = allowed_tags , attributes = allowed_attributes , styles = allowed_styles , strip = True )
return value |
def compress_file ( filepath , compression = "gz" ) :
"""Compresses a file with the correct extension . Functions like standard
Unix command line gzip and bzip2 in the sense that the original
uncompressed files are not retained .
Args :
filepath ( str ) : Path to file .
compression ( str ) : A compression... | if compression not in [ "gz" , "bz2" ] :
raise ValueError ( "Supported compression formats are 'gz' and 'bz2'." )
from monty . io import zopen
if not filepath . lower ( ) . endswith ( ".%s" % compression ) :
with open ( filepath , 'rb' ) as f_in , zopen ( '%s.%s' % ( filepath , compression ) , 'wb' ) as f_out :... |
def hash_file ( fileobj ) :
""": param fileobj : a file object
: return : a hash of the file content""" | hasher = hashlib . md5 ( )
buf = fileobj . read ( 65536 )
while len ( buf ) > 0 :
hasher . update ( buf )
buf = fileobj . read ( 65536 )
return hasher . hexdigest ( ) |
def clear_end_date ( self ) :
"""Clears the end date .
raise : NoAccess - ` ` Metadata . isRequired ( ) ` ` or
` ` Metadata . isReadOnly ( ) ` ` is ` ` true ` `
* compliance : mandatory - - This method must be implemented . *""" | if ( self . get_end_date_metadata ( ) . is_read_only ( ) or self . get_end_date_metadata ( ) . is_required ( ) ) :
raise NoAccess ( )
self . my_osid_object_form . _my_map [ 'endDate' ] = DateTime ( ** self . _end_date_metadata [ 'default_date_time_values' ] [ 0 ] ) |
def main ( ) :
"""The entry point for the Hyper - V Neutron Agent .""" | neutron_config . register_agent_state_opts_helper ( CONF )
common_config . init ( sys . argv [ 1 : ] )
neutron_config . setup_logging ( )
hyperv_agent = HyperVNeutronAgent ( )
# Start everything .
LOG . info ( "Agent initialized successfully, now running... " )
hyperv_agent . daemon_loop ( ) |
def variants ( self , case_id , skip = 0 , count = 1000 , filters = None ) :
"""Fetch variants for a case .""" | filters = filters or { }
logger . debug ( "Fetching case with case_id: {0}" . format ( case_id ) )
case_obj = self . case ( case_id )
plugin , case_id = self . select_plugin ( case_obj )
self . filters = plugin . filters
gene_lists = ( self . gene_list ( list_id ) for list_id in filters . get ( 'gene_lists' , [ ] ) )
n... |
def get_plate_list ( self , market , plate_class ) :
"""获取板块集合下的子板块列表
: param market : 市场标识 , 注意这里不区分沪 , 深 , 输入沪或者深都会返回沪深市场的子板块 ( 这个是和客户端保持一致的 ) 参见Market
: param plate _ class : 板块分类 , 参见Plate
: return : ret = = RET _ OK 返回pd dataframe数据 , data . DataFrame数据 , 数据列格式如下
ret ! = RET _ OK 返回错误字符串
参数 类型 说明
c... | param_table = { 'market' : market , 'plate_class' : plate_class }
for x in param_table :
param = param_table [ x ]
if param is None or is_str ( market ) is False :
error_str = ERROR_STR_PREFIX + "the type of market param is wrong"
return RET_ERROR , error_str
if market not in MKT_MAP :
error... |
def contraction_sharp ( Di1 , Di2 ) :
r'''Returns loss coefficient for any sharp edged pipe contraction
as shown in [ 1 ] _ .
. . math : :
K = 0.0696(1 - \ beta ^ 5 ) \ lambda ^ 2 + ( \ lambda - 1 ) ^ 2
. . math : :
\ lambda = 1 + 0.622(1-0.215 \ beta ^ 2 - 0.785 \ beta ^ 5)
. . math : :
\ beta = d _ ... | beta = Di2 / Di1
lbd = 1 + 0.622 * ( 1 - 0.215 * beta ** 2 - 0.785 * beta ** 5 )
return 0.0696 * ( 1 - beta ** 5 ) * lbd ** 2 + ( lbd - 1 ) ** 2 |
def checkStatus ( self ) :
"""Check status
Args :
Returns :
True : Sucess
False : Failed""" | checkAccount ( )
data = { 'userid' : self . user_id , 'useridx' : self . useridx }
r = self . session . post ( nurls [ 'checkStatus' ] , data = data )
p = re . compile ( r'\<message\>(?P<message>.+)\</message\>' )
message = p . search ( r . text ) . group ( 'message' )
if message == 'success' :
return True
else :
... |
def load_cli ( subparsers ) :
"""Given a parser , load the CLI subcommands""" | for command_name in available_commands ( ) :
module = '{}.{}' . format ( __package__ , command_name )
loader , description = _import_loader ( module )
parser = subparsers . add_parser ( command_name , description = description )
command = loader ( parser )
if command is None :
raise RuntimeE... |
def read_pkl_and_pklz ( filename ) :
"""Try read zipped or not zipped pickle file""" | fcontent = None
try :
import gzip
f = gzip . open ( filename , 'rb' )
fcontent = f . read ( )
f . close ( )
except IOError as e : # if the problem is in not gzip file
logger . info ( "Input gzip exception: " + str ( e ) )
f = open ( filename , 'rb' )
fcontent = f . read ( )
f . close ( )... |
def index2bool ( index , length = None ) :
"""Returns a numpy boolean array with Trues in the input index
positions .
: param index : index array with the Trues positions .
: type index : ndarray ( type = int )
: param length : Length of the returned array .
: type length : int or None
: returns : array... | if index . shape [ 0 ] == 0 and length is None :
return np . arange ( 0 , dtype = bool )
if length is None :
length = index . max ( ) + 1
sol = np . zeros ( length , dtype = bool )
sol [ index ] = True
return sol |
def move ( self , folder , ** kwargs ) :
''': param folder : Folder route to which to move the object
: type folder : string
: raises : : exc : ` ~ dxpy . exceptions . DXError ` if no project is associated with the object
Moves the associated remote object to * folder * .''' | if self . _proj is None :
raise DXError ( "Move called when a project ID was not associated with this object handler" )
dxpy . api . project_move ( self . _proj , { "objects" : [ self . _dxid ] , "destination" : folder } , ** kwargs ) |
def romanized ( locale : str = '' ) -> Callable :
"""Romanize the Cyrillic text .
Transliterate the Cyrillic language from the Cyrillic
script into the Latin alphabet .
. . note : : At this moment it works only for ` ru ` , ` uk ` , ` kk ` .
: param locale : Locale code .
: return : Latinized text .""" | def romanized_deco ( func ) :
@ functools . wraps ( func )
def wrapper ( * args , ** kwargs ) :
try : # String can contain ascii symbols , digits and
# punctuation symbols .
alphabet = { s : s for s in letters + digits + punctuation }
alphabet . update ( data . ROMANIZATI... |
def call_set_attr ( node : Node , key : str , value ) :
"""Calls node setter""" | node . set_attr ( key , value ) |
def calculate_sun ( self , month , day , hour , is_solar_time = False ) :
"""Get Sun data for an hour of the year .
Args :
month : An integer between 1-12
day : An integer between 1-31
hour : A positive number between 0 . . 23
is _ solar _ time : A boolean to indicate if the input hour is solar time .
(... | datetime = DateTime ( month , day , * self . _calculate_hour_and_minute ( hour ) , leap_year = self . is_leap_year )
return self . calculate_sun_from_date_time ( datetime , is_solar_time ) |
def maximum_triangle_path ( triangle , rows , cols ) :
"""A function to calculate the maximum sum of numbers from top to bottom of the triangle .
> > > maximum _ triangle _ path ( [ [ 1 , 0 , 0 ] , [ 4 , 8 , 0 ] , [ 1 , 5 , 3 ] ] , 2 , 2)
14
> > > maximum _ triangle _ path ( [ [ 13 , 0 , 0 ] , [ 7 , 4 , 0 ] ,... | # Start from the second last row
for i in range ( rows - 1 , - 1 , - 1 ) : # Compute max of triangle [ i ] [ j ] and triangle [ i ] [ j + 1 ] , and add it to triangle [ i - 1 ] [ j ]
for j in range ( i + 1 ) : # Pick maximum sum value from the children
max_num = max ( triangle [ i + 1 ] [ j ] , triangle [ i... |
def parse_file ( self , file_or_fname ) :
"""Parse a file or a filename""" | with self . _context ( ) :
if hasattr ( file_or_fname , 'read' ) :
self . filename = getattr ( file_or_fname , 'name' , file_or_fname . __class__ . __name__ )
self . p . ParseFile ( file_or_fname )
else :
self . filename = file_or_fname
with open ( file_or_fname , 'rb' ) as f :
... |
def clone ( self ) :
"""Deepclone the entity , but reset state""" | clone_copy = copy . deepcopy ( self )
clone_copy . state_ = EntityState ( )
return clone_copy |
def stp ( br = None , state = 'disable' , iface = None ) :
'''Sets Spanning Tree Protocol state for a bridge
CLI Example :
. . code - block : : bash
salt ' * ' bridge . stp br0 enable
salt ' * ' bridge . stp br0 disable
For BSD - like operating systems , it is required to add the interface on
which to e... | kernel = __grains__ [ 'kernel' ]
if kernel == 'Linux' :
states = { 'enable' : 'on' , 'disable' : 'off' }
return _os_dispatch ( 'stp' , br , states [ state ] )
elif kernel in SUPPORTED_BSD_LIKE :
states = { 'enable' : 'stp' , 'disable' : '-stp' }
return _os_dispatch ( 'stp' , br , states [ state ] , ifac... |
def send_headers ( self ) :
"""Sends the headers to the client""" | self . events . sync_emit ( 'headers' )
self . _set_default_headers ( )
header_str = self . status_line + self . EOL + str ( self . headers )
self . stream . write ( header_str . encode ( ) )
self . events . sync_emit ( 'after_headers' ) |
async def on_raw_319 ( self , message ) :
"""WHOIS active channels .""" | target , nickname , channels = message . params [ : 3 ]
channels = { channel . lstrip ( ) for channel in channels . strip ( ) . split ( ' ' ) }
info = { 'channels' : channels }
if nickname in self . _pending [ 'whois' ] :
self . _whois_info [ nickname ] . update ( info ) |
def associated_stream ( self ) :
"""Return the corresponding output or storage stream for an important system input .
Certain system inputs are designed as important and automatically
copied to output streams without requiring any manual interaction .
This method returns the corresponding stream for an import... | if not self . important :
raise InternalError ( "You may only call autocopied_stream on when DataStream.important is True" , stream = self )
if self . stream_id >= DataStream . ImportantSystemStorageStart :
stream_type = DataStream . BufferedType
else :
stream_type = DataStream . OutputType
return DataStrea... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.