signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def connection_exists ( self , from_obj , to_obj ) :
"""Returns ` ` True ` ` if a connection between the given objects exists ,
else ` ` False ` ` .""" | self . _validate_ctypes ( from_obj , to_obj )
return self . connections . filter ( from_pk = from_obj . pk , to_pk = to_obj . pk ) . exists ( ) |
def _check_data ( self ) :
"""Check if the data given is valid""" | if self . axes is None :
raise PolygonFilterError ( "`axes` parm not set." )
if self . points is None :
raise PolygonFilterError ( "`points` parm not set." )
self . points = np . array ( self . points )
if self . points . shape [ 1 ] != 2 :
raise PolygonFilterError ( "data points' shape[1] must be 2." )
if ... |
def _ip_is_usable ( self , current_ip ) :
"""Check if the current Tor ' s IP is usable .
: argument current _ ip : current Tor IP
: type current _ ip : str
: returns bool""" | # Consider IP addresses only .
try :
ipaddress . ip_address ( current_ip )
except ValueError :
return False
# Never use real IP .
if current_ip == self . real_ip :
return False
# Do dot allow IP reuse .
if not self . _ip_is_safe ( current_ip ) :
return False
return True |
def get_variables ( self , * args , ** kwargs ) :
"""Provide a warning that get _ variables on Sequential always returns ( ) .""" | tf . logging . warning ( "Calling Sequential.get_variables, which will always return an empty " "tuple. get_variables() can only return variables created directly by " "a Module, or created by submodules directly created inside the " "Module. Sequential is constructed from already constructed submodules " "and so this ... |
def read ( self , path , encoding = None ) :
"""Read the template at the given path , and return it as a unicode string .""" | b = common . read ( path )
if encoding is None :
encoding = self . file_encoding
return self . unicode ( b , encoding ) |
def msg ( self , * args , ** kwargs ) :
"Only execute callback when interval is reached ." | if self . timestamp is None or self . _interval_reached ( ) :
self . callback ( * args , ** kwargs )
self . reset ( ) |
def create_role ( self , name ) :
'''Create a new : class : ` Role ` owned by this : class : ` Subject `''' | models = self . session . router
return models . role . new ( name = name , owner = self ) |
def authenticate ( self , provider = None , identifier = None ) :
"Fetch user for a given provider by id ." | provider_q = Q ( provider__name = provider )
if isinstance ( provider , Provider ) :
provider_q = Q ( provider = provider )
try :
access = AccountAccess . objects . filter ( provider_q , identifier = identifier ) . select_related ( 'user' ) [ 0 ]
except IndexError :
return None
else :
return access . us... |
def _get_address_override ( endpoint_type = PUBLIC ) :
"""Returns any address overrides that the user has defined based on the
endpoint type .
Note : this function allows for the service name to be inserted into the
address if the user specifies { service _ name } . somehost . org .
: param endpoint _ type ... | override_key = ADDRESS_MAP [ endpoint_type ] [ 'override' ]
addr_override = config ( override_key )
if not addr_override :
return None
else :
return addr_override . format ( service_name = service_name ( ) ) |
def restart_kernel ( self ) :
"""Restart kernel of current client .""" | client = self . get_current_client ( )
if client is not None :
self . switch_to_plugin ( )
client . restart_kernel ( ) |
def get_logging_file_handler ( logger = None , file = None , formatter = LOGGING_DEFAULT_FORMATTER ) :
"""Adds a logging file handler to given logger or default logger using given file .
: param logger : Logger to add the handler to .
: type logger : Logger
: param file : File to verbose into .
: type file ... | logger = LOGGER if logger is None else logger
file = tempfile . NamedTemporaryFile ( ) . name if file is None else file
logging_file_handler = logging . FileHandler ( file )
logging_file_handler . setFormatter ( formatter )
logger . addHandler ( logging_file_handler )
return logging_file_handler |
def window_open_config ( self , temperature , duration ) :
"""Configures the window open behavior . The duration is specified in
5 minute increments .""" | _LOGGER . debug ( "Window open config, temperature: %s duration: %s" , temperature , duration )
self . _verify_temperature ( temperature )
if duration . seconds < 0 and duration . seconds > 3600 :
raise ValueError
value = struct . pack ( 'BBB' , PROP_WINDOW_OPEN_CONFIG , int ( temperature * 2 ) , int ( duration . s... |
def get_midpoint_outgroup ( self ) :
"""Returns the node that divides the current tree into two
distance - balanced partitions .""" | # Gets the farthest node to the current root
root = self . get_tree_root ( )
nA , r2A_dist = root . get_farthest_leaf ( )
nB , A2B_dist = nA . get_farthest_node ( )
outgroup = nA
middist = A2B_dist / 2.0
cdist = 0
current = nA
while current is not None :
cdist += current . dist
if cdist > ( middist ) : # Deja d... |
def get_option_columns ( self , typ , element ) :
"""Return the column of the model to show for each level
Because each level might be displayed in a combobox . So you might want to provide the column
to show .
: param typ : the typ of options . E . g . Asset , Alembic , Camera etc
: type typ : str
: para... | inter = self . get_typ_interface ( typ )
return inter . get_option_columns ( element ) |
def _set_use_vrf ( self , v , load = False ) :
"""Setter method for use _ vrf , mapped from YANG variable / rbridge _ id / ssh / server / ssh _ vrf _ cont / use _ vrf ( list )
If this variable is read - only ( config : false ) in the
source YANG file , then _ set _ use _ vrf is considered as a private
method ... | if hasattr ( v , "_utype" ) :
v = v . _utype ( v )
try :
t = YANGDynClass ( v , base = YANGListType ( "use_vrf_name" , use_vrf . use_vrf , yang_name = "use-vrf" , rest_name = "use-vrf" , parent = self , is_container = 'list' , user_ordered = False , path_helper = self . _path_helper , yang_keys = 'use-vrf-name'... |
def add_pane ( self , pane , vsplit = False ) :
"""Add another pane to this Window .""" | assert isinstance ( pane , Pane )
assert isinstance ( vsplit , bool )
split_cls = VSplit if vsplit else HSplit
if self . active_pane is None :
self . root . append ( pane )
else :
parent = self . _get_parent ( self . active_pane )
same_direction = isinstance ( parent , split_cls )
index = parent . index... |
def bounding_box ( self ) :
"""Generate a bounding box based on the full complexity part .
: return : bounding box of part
: rtype : cadquery . BoundBox""" | if self . world_coords :
return self . world_obj . findSolid ( ) . BoundingBox ( )
return self . local_obj . findSolid ( ) . BoundingBox ( ) |
def make_fileitem_peinfo_detectedentrypointsignature_name ( entrypoint_name , condition = 'is' , negate = False , preserve_case = False ) :
"""Create a node for FileItem / PEInfo / DetectedEntryPointSignature / Name
: return : A IndicatorItem represented as an Element node""" | document = 'FileItem'
search = 'FileItem/PEInfo/DetectedEntryPointSignature/Name'
content_type = 'string'
content = entrypoint_name
ii_node = ioc_api . make_indicatoritem_node ( condition , document , search , content_type , content , negate = negate , preserve_case = preserve_case )
return ii_node |
def to_file ( self , filename , format = 'shtools' , header = None , errors = False , ** kwargs ) :
"""Save spherical harmonic coefficients to a file .
Usage
x . to _ file ( filename , [ format = ' shtools ' , header , errors ] )
x . to _ file ( filename , [ format = ' npy ' , * * kwargs ] )
Parameters
fi... | if format is 'shtools' :
if errors is True and self . errors is None :
raise ValueError ( 'Can not save errors when then have not been ' 'initialized.' )
if self . omega is None :
omega = 0.
else :
omega = self . omega
with open ( filename , mode = 'w' ) as file :
if head... |
def _greater_or_close ( a , value , ** kwargs ) :
r"""Compare values for greater or close to boolean masks .
Returns a boolean mask for values greater than or equal to a target within a specified
absolute or relative tolerance ( as in : func : ` numpy . isclose ` ) .
Parameters
a : array - like
Array of v... | return ( a > value ) | np . isclose ( a , value , ** kwargs ) |
def skip ( self , regex ) :
"""Like : meth : ` scan ` , but return the number of characters matched .
> > > s = Scanner ( " test string " )
> > > s . skip ( ' test ' )""" | return self . scan_full ( regex , return_string = False , advance_pointer = True ) |
def _imm_dir ( self ) :
'''An immutable object ' s dir function should list not only its attributes , but also its un - cached
lazy values .''' | dir0 = set ( dir ( self . __class__ ) )
dir0 . update ( self . __dict__ . keys ( ) )
dir0 . update ( six . iterkeys ( _imm_value_data ( self ) ) )
return sorted ( list ( dir0 ) ) |
def format_stats ( stats ) :
"""Given a dictionary following this layout :
' encoded : label ' : ' Encoded ' ,
' encoded : value ' : ' Yes ' ,
' encoded : description ' : ' Indicates if the column is encoded ' ,
' encoded : include ' : True ,
' size : label ' : ' Size ' ,
' size : value ' : 128,
' siz... | stats_collector = { }
for stat_key , stat_value in stats . items ( ) :
stat_id , stat_field = stat_key . split ( ":" )
stats_collector . setdefault ( stat_id , { "id" : stat_id } )
stats_collector [ stat_id ] [ stat_field ] = stat_value
# strip out all the stats we don ' t want
stats_collector = { stat_id :... |
def now ( self , when = None ) :
"""Set the current value to the correct tuple based on the seconds
since the epoch . If ' when ' is not provided , get the current time
from the task manager .""" | if when is None :
when = _TaskManager ( ) . get_time ( )
tup = time . localtime ( when )
self . value = ( tup [ 0 ] - 1900 , tup [ 1 ] , tup [ 2 ] , tup [ 6 ] + 1 )
return self |
def addReference ( self , reference ) :
"""Adds the specified reference to this ReferenceSet .""" | id_ = reference . getId ( )
self . _referenceIdMap [ id_ ] = reference
self . _referenceNameMap [ reference . getLocalId ( ) ] = reference
self . _referenceIds . append ( id_ ) |
async def close_authenticator_async ( self ) :
"""Close the CBS auth channel and session asynchronously .""" | _logger . info ( "Shutting down CBS session on connection: %r." , self . _connection . container_id )
try :
self . _cbs_auth . destroy ( )
_logger . info ( "Auth closed, destroying session on connection: %r." , self . _connection . container_id )
await self . _session . destroy_async ( )
finally :
_logg... |
def prep_itasser_modeling ( self , itasser_installation , itlib_folder , runtype , create_in_dir = None , execute_from_dir = None , all_genes = False , print_exec = False , ** kwargs ) :
"""Prepare to run I - TASSER homology modeling for genes without structures , or all genes .
Args :
itasser _ installation ( ... | if not create_in_dir :
if not self . data_dir :
raise ValueError ( 'Output directory must be specified' )
self . homology_models_dir = op . join ( self . data_dir , 'homology_models' )
else :
self . homology_models_dir = create_in_dir
ssbio . utils . make_dir ( self . homology_models_dir )
if not ex... |
def new_data ( self , mem , addr , data ) :
"""Callback for when new memory data has been fetched""" | if mem . id == self . id :
if addr == LocoMemory2 . ADR_ID_LIST :
self . _handle_id_list_data ( data )
elif addr == LocoMemory2 . ADR_ACTIVE_ID_LIST :
self . _handle_active_id_list_data ( data )
else :
id = int ( ( addr - LocoMemory2 . ADR_ANCHOR_BASE ) / LocoMemory2 . ANCHOR_PAGE_SI... |
async def send_invoice ( self , chat_id : base . Integer , title : base . String , description : base . String , payload : base . String , provider_token : base . String , start_parameter : base . String , currency : base . String , prices : typing . List [ types . LabeledPrice ] , provider_data : typing . Union [ typi... | prices = prepare_arg ( [ price . to_python ( ) if hasattr ( price , 'to_python' ) else price for price in prices ] )
reply_markup = prepare_arg ( reply_markup )
payload_ = generate_payload ( ** locals ( ) )
result = await self . request ( api . Methods . SEND_INVOICE , payload_ )
return types . Message ( ** result ) |
def s3_cache_timeout ( self ) :
"""The socket timeout in seconds for connections to Amazon S3 ( an integer ) .
This value is injected into Boto ' s configuration to override the
default socket timeout used for connections to Amazon S3.
- Environment variable : ` ` $ PIP _ ACCEL _ S3 _ TIMEOUT ` `
- Configur... | value = self . get ( property_name = 's3_cache_timeout' , environment_variable = 'PIP_ACCEL_S3_TIMEOUT' , configuration_option = 's3-timeout' )
try :
n = int ( value )
if n >= 0 :
return n
except :
return 60 |
def compare ( self , other , t_threshold = 1e-3 , r_threshold = 1e-3 ) :
"""Compare two transformations
The RMSD values of the rotation matrices and the translation vectors
are computed . The return value is True when the RMSD values are below
the thresholds , i . e . when the two transformations are almost
... | return compute_rmsd ( self . t , other . t ) < t_threshold and compute_rmsd ( self . r , other . r ) < r_threshold |
def status ( self ) :
"""Returns modified , added , removed , deleted files for current changeset""" | return self . repository . _repo . status ( self . _ctx . p1 ( ) . node ( ) , self . _ctx . node ( ) ) |
def longitude ( self , value ) :
"""Set longitude value in degrees .""" | self . _longitude = math . radians ( float ( value ) )
# update time _ zone
if abs ( ( value / 15.0 ) - self . time_zone ) > 1 : # if time _ zone doesn ' t match the longitude update the time _ zone
self . time_zone = value / 15.0 |
def on_for_distance ( self , speed , distance_mm , brake = True , block = True ) :
"""Drive distance _ mm""" | rotations = distance_mm / self . wheel . circumference_mm
log . debug ( "%s: on_for_rotations distance_mm %s, rotations %s, speed %s" % ( self , distance_mm , rotations , speed ) )
MoveTank . on_for_rotations ( self , speed , speed , rotations , brake , block ) |
def gen_opt_str ( ser_rec : pd . Series ) -> str :
'''generate rst option string
Parameters
ser _ rec : pd . Series
record for specifications
Returns
str
rst string''' | name = ser_rec . name
indent = r' '
str_opt = f'.. option:: {name}' + '\n\n'
for spec in ser_rec . sort_index ( ) . index :
str_opt += indent + f':{spec}:' + '\n'
spec_content = ser_rec [ spec ]
str_opt += indent + indent + f'{spec_content}' + '\n'
return str_opt |
def create ( configs ) :
"""Creates AndroidDevice controller objects .
Args :
configs : A list of dicts , each representing a configuration for an
Android device .
Returns :
A list of AndroidDevice objects .""" | if not configs :
raise Error ( ANDROID_DEVICE_EMPTY_CONFIG_MSG )
elif configs == ANDROID_DEVICE_PICK_ALL_TOKEN :
ads = get_all_instances ( )
elif not isinstance ( configs , list ) :
raise Error ( ANDROID_DEVICE_NOT_LIST_CONFIG_MSG )
elif isinstance ( configs [ 0 ] , dict ) : # Configs is a list of dicts .
... |
def loads ( s , _dict = dict , decoder = None ) :
"""Parses string as toml
Args :
s : String to be parsed
_ dict : ( optional ) Specifies the class of the returned toml dictionary
Returns :
Parsed toml file represented as a dictionary
Raises :
TypeError : When a non - string is passed
TomlDecodeErro... | implicitgroups = [ ]
if decoder is None :
decoder = TomlDecoder ( _dict )
retval = decoder . get_empty_table ( )
currentlevel = retval
if not isinstance ( s , basestring ) :
raise TypeError ( "Expecting something like a string" )
if not isinstance ( s , unicode ) :
s = s . decode ( 'utf8' )
original = s
sl ... |
def cli ( obj , ids , query , filters , attributes ) :
"""Update alert attributes .""" | client = obj [ 'client' ]
if ids :
total = len ( ids )
else :
if query :
query = [ ( 'q' , query ) ]
else :
query = build_query ( filters )
total , _ , _ = client . get_count ( query )
ids = [ a . id for a in client . get_alerts ( query ) ]
with click . progressbar ( ids , label = 'U... |
def cancel_merge_when_pipeline_succeeds ( self , ** kwargs ) :
"""Cancel merge when the pipeline succeeds .
Args :
* * kwargs : Extra options to send to the server ( e . g . sudo )
Raises :
GitlabAuthenticationError : If authentication is not correct
GitlabMROnBuildSuccessError : If the server could not h... | path = ( '%s/%s/cancel_merge_when_pipeline_succeeds' % ( self . manager . path , self . get_id ( ) ) )
server_data = self . manager . gitlab . http_put ( path , ** kwargs )
self . _update_attrs ( server_data ) |
def get_lines_from_file ( filepath , encoding = "UTF-8" ) :
"""Return an iterator over lines .""" | try :
fd = codecs . open ( filepath , 'r' , encoding )
lines = fd . readlines ( )
except UnicodeDecodeError : # Fall back to ' ISO - 8859-1'
fd = codecs . open ( filepath , 'r' , 'ISO-8859-1' )
lines = fd . readlines ( )
finally :
fd . close ( )
return lines |
def _pool ( self , pool_name , pool_function , k_height , k_width , d_height , d_width , mode , input_layer , num_channels_in ) :
"""Construct a pooling layer .""" | if input_layer is None :
input_layer = self . top_layer
else :
self . top_size = num_channels_in
name = pool_name + str ( self . counts [ pool_name ] )
self . counts [ pool_name ] += 1
if self . use_tf_layers :
pool = pool_function ( input_layer , [ k_height , k_width ] , [ d_height , d_width ] , padding = ... |
def _string2Duration ( text ) :
"""CONVERT SIMPLE < float > < type > TO A DURATION OBJECT""" | if text == "" or text == "zero" :
return ZERO
amount , interval = re . match ( r"([\d\.]*)(.*)" , text ) . groups ( )
amount = int ( amount ) if amount else 1
if MILLI_VALUES [ interval ] == None :
from mo_logs import Log
Log . error ( "{{interval|quote}} in {{text|quote}} is not a recognized duration type ... |
def onStart ( self , event ) :
"""Display the environment of a started container""" | c = event . container
print '+' * 5 , 'started:' , c
kv = lambda s : s . split ( '=' , 1 )
env = { k : v for ( k , v ) in ( kv ( s ) for s in c . attrs [ 'Config' ] [ 'Env' ] ) }
print env |
def resolve_kw ( self , kwargs ) :
"""Resolve : kwargs : like ` story _ id : 1 ` to the form of ` id : 1 ` .""" | resolved = { }
for key , value in kwargs . items ( ) :
split = key . split ( '_' , 1 )
if len ( split ) > 1 :
key = split [ 1 ]
resolved [ key ] = value
return resolved |
def pyquil_to_circuit ( program : pyquil . Program ) -> Circuit :
"""Convert a protoquil pyQuil program to a QuantumFlow Circuit""" | circ = Circuit ( )
for inst in program . instructions : # print ( type ( inst ) )
if isinstance ( inst , pyquil . Declare ) : # Ignore
continue
if isinstance ( inst , pyquil . Halt ) : # Ignore
continue
if isinstance ( inst , pyquil . Pragma ) : # TODO Barrier ?
continue
elif isi... |
def end_address ( self ) :
"""Get basic block end address .""" | if self . _instrs is [ ] :
return None
return self . _instrs [ - 1 ] . address + self . _instrs [ - 1 ] . size - 1 |
def group ( self , meta = None , meta_aggregates = None , regs = None , regs_aggregates = None , meta_group_name = "_group" ) :
"""* Wrapper of * ` ` GROUP ` `
The GROUP operator is used for grouping both regions and / or metadata of input
dataset samples according to distinct values of certain attributes ( kno... | if isinstance ( meta , list ) and all ( [ isinstance ( x , str ) for x in meta ] ) :
meta = Some ( meta )
elif meta is None :
meta = none ( )
else :
raise TypeError ( "meta must be a list of strings. " "{} was provided" . format ( type ( meta ) ) )
expBuild = self . pmg . getNewExpressionBuilder ( self . __... |
def _generate_autoscaling_metadata ( self , cls , args ) :
"""Provides special handling for the autoscaling . Metadata object""" | assert isinstance ( args , Mapping )
init_config = self . _create_instance ( cloudformation . InitConfig , args [ 'AWS::CloudFormation::Init' ] [ 'config' ] )
init = self . _create_instance ( cloudformation . Init , { 'config' : init_config } )
auth = None
if 'AWS::CloudFormation::Authentication' in args :
auth_blo... |
def toc ( self ) :
"""Returns a rich list of texts in the catalog .""" | output = [ ]
for key in sorted ( self . catalog . keys ( ) ) :
edition = self . catalog [ key ] [ 'edition' ]
length = len ( self . catalog [ key ] [ 'transliteration' ] )
output . append ( "Pnum: {key}, Edition: {edition}, length: {length} line(s)" . format ( key = key , edition = edition , length = length... |
def get_shelveset_work_items ( self , shelveset_id ) :
"""GetShelvesetWorkItems .
Get work items associated with a shelveset .
: param str shelveset _ id : Shelveset ' s unique ID
: rtype : [ AssociatedWorkItem ]""" | query_parameters = { }
if shelveset_id is not None :
query_parameters [ 'shelvesetId' ] = self . _serialize . query ( 'shelveset_id' , shelveset_id , 'str' )
response = self . _send ( http_method = 'GET' , location_id = 'a7a0c1c1-373e-425a-b031-a519474d743d' , version = '5.0' , query_parameters = query_parameters )... |
def set_working_directory ( self , dirname ) :
"""Set current working directory .
In the workingdirectory and explorer plugins .""" | if dirname :
self . main . workingdirectory . chdir ( dirname , refresh_explorer = True , refresh_console = False ) |
def stations_iter ( self , * , page_size = 250 ) :
"""Get a paged iterator of library stations .
Parameters :
page _ size ( int , Optional ) : The maximum number of results per returned page .
Max allowed is ` ` 49995 ` ` .
Default : ` ` 250 ` `
Yields :
list : Station dicts .""" | start_token = None
while True :
response = self . _call ( mc_calls . RadioStation , max_results = page_size , start_token = start_token )
yield response . body . get ( 'data' , { } ) . get ( 'items' , [ ] )
start_token = response . body . get ( 'nextPageToken' )
if start_token is None :
break |
def GetForwardedIps ( self , interface , interface_ip = None ) :
"""Retrieve the list of configured forwarded IP addresses .
Args :
interface : string , the output device to query .
interface _ ip : string , current interface ip address .
Returns :
list , the IP address strings .""" | try :
ips = netifaces . ifaddresses ( interface )
ips = ips [ netifaces . AF_INET ]
except ( ValueError , IndexError ) :
return [ ]
forwarded_ips = [ ]
for ip in ips :
if ip [ 'addr' ] != interface_ip :
full_addr = '%s/%d' % ( ip [ 'addr' ] , netaddr . IPAddress ( ip [ 'netmask' ] ) . netmask_bi... |
def _DiscoverElementTypeFromLocalname ( self , type_localname ) :
"""Searches all namespaces for a type by name .
Args :
type _ localname : The name of the type .
Returns :
A fully qualified SOAP type with the specified name .
Raises :
A zeep . exceptions . LookupError if the type cannot be found in any... | elem_type = None
last_exception = None
for ns_prefix in self . zeep_client . wsdl . types . prefix_map . values ( ) :
try :
elem_type = self . zeep_client . get_type ( '{%s}%s' % ( ns_prefix , type_localname ) )
except zeep . exceptions . LookupError as e :
last_exception = e
continue
... |
def do ( self , resource , method , params = None , data = None , json = None , headers = None ) :
"""Does the request job
Args :
resource ( str ) : resource uri ( relative path )
method ( str ) : HTTP method
params ( dict ) : uri queries
data ( dict ) : HTTP body ( form )
json ( dict ) : HTTP body ( js... | uri = "{0}/{1}" . format ( self . _api_base , resource )
if not params :
params = { }
params . update ( { 'token' : self . _token } )
req = Request ( method = method , url = uri , params = params , headers = headers , data = data , json = json )
s = Session ( )
prepped = s . prepare_request ( req )
resp = s . send ... |
def _header ( self , message : str , with_gap = True ) :
"""Logs a special ( colored ) message at the indent level .""" | if with_gap :
self . _line_break ( )
self . _log ( self . _set_color ( message , self . YELLOW ) ) |
def insecure_channel ( target , options = None , * , loop = None , executor = None , standalone_pool_for_streaming = False ) :
"""Creates an insecure Channel to a server .
Args :
target : The server address
options : An optional list of key - value pairs ( channel args in gRPC runtime )
to configure the cha... | return Channel ( _grpc . insecure_channel ( target , options ) , loop , executor , standalone_pool_for_streaming ) |
def _update_stage ( awsclient , api_id , stage_name , method_settings ) :
"""Helper to apply method _ settings to stage
: param awsclient :
: param api _ id :
: param stage _ name :
: param method _ settings :
: return :""" | # settings docs in response : https : / / botocore . readthedocs . io / en / latest / reference / services / apigateway . html # APIGateway . Client . update _ stage
client_api = awsclient . get_client ( 'apigateway' )
operations = _convert_method_settings_into_operations ( method_settings )
if operations :
print (... |
def _infer_decorator_callchain ( node ) :
"""Detect decorator call chaining and see if the end result is a
static or a classmethod .""" | if not isinstance ( node , FunctionDef ) :
return None
if not node . parent :
return None
try :
result = next ( node . infer_call_result ( node . parent ) )
except exceptions . InferenceError :
return None
if isinstance ( result , bases . Instance ) :
result = result . _proxied
if isinstance ( resul... |
def id_nameDAVID ( df , GTF = None , name_id = None ) :
"""Given a DAVIDenrich output it converts ensembl gene ids to genes names and adds this column to the output
: param df : a dataframe output from DAVIDenrich
: param GTF : a GTF dataframe from readGTF ( )
: param name _ id : instead of a gtf dataframe a ... | if name_id is None :
gene_name = retrieve_GTF_field ( 'gene_name' , GTF )
gene_id = retrieve_GTF_field ( 'gene_id' , GTF )
GTF = pd . concat ( [ gene_name , gene_id ] , axis = 1 )
else :
GTF = name_id . copy ( )
df [ 'Gene_names' ] = "genes"
terms = df [ 'termName' ] . tolist ( )
enrichN = pd . DataFram... |
def cat_acc ( y , z ) :
"""Classification accuracy for multi - categorical case""" | weights = _cat_sample_weights ( y )
_acc = K . cast ( K . equal ( K . argmax ( y , axis = - 1 ) , K . argmax ( z , axis = - 1 ) ) , K . floatx ( ) )
_acc = K . sum ( _acc * weights ) / K . sum ( weights )
return _acc |
def get_captcha_key ( self , captcha_image_url ) :
"""Read CAPTCHA key from user input""" | if self . interactive :
print ( 'Open CAPTCHA image url in your browser and enter it below: ' , captcha_image_url )
captcha_key = raw_input ( 'Enter CAPTCHA key: ' )
return captcha_key
else :
raise VkAuthError ( 'Captcha is required. Use interactive mode to enter it ' 'manually' ) |
def _handle_post ( self , transaction ) :
"""Handle POST requests
: type transaction : Transaction
: param transaction : the transaction that owns the request
: rtype : Transaction
: return : the edited transaction with the response to the request""" | path = str ( "/" + transaction . request . uri_path )
transaction . response = Response ( )
transaction . response . destination = transaction . request . source
transaction . response . token = transaction . request . token
# Create request
transaction = self . _server . resourceLayer . create_resource ( path , transa... |
def handle_typical_memberdefs ( self , signature , memberdef_nodes ) :
"""Produces docstring entries containing an " Overloaded function "
section with the documentation for each overload , if the function is
overloaded and self . with _ overloaded _ functions is set . Else , produce
normal documentation .""" | if len ( memberdef_nodes ) == 1 or not self . with_overloaded_functions :
self . handle_typical_memberdefs_no_overload ( signature , memberdef_nodes )
return
self . add_text ( [ '\n' , '%feature("docstring") ' , signature , ' "' , '\n' ] )
if self . with_function_signature :
for n in memberdef_nodes :
... |
def owns_endpoint ( self , endpoint ) :
"""Tests if an endpoint name ( not path ) belongs to this Api . Takes
in to account the Blueprint name part of the endpoint name .
: param endpoint : The name of the endpoint being checked
: return : bool""" | if self . blueprint :
if endpoint . startswith ( self . blueprint . name ) :
endpoint = endpoint . split ( self . blueprint . name + '.' , 1 ) [ - 1 ]
else :
return False
return endpoint in self . endpoints |
def reject_sv ( m , s , y ) :
"""Sample from N ( m , s ^ 2 ) times SV likelihood using rejection .
SV likelihood ( in x ) corresponds to y ~ N ( 0 , exp ( x ) ) .""" | mp = m + 0.5 * s ** 2 * ( - 1. + y ** 2 * np . exp ( - m ) )
ntries = 0
while True :
ntries += 1
x = stats . norm . rvs ( loc = mp , scale = s )
u = stats . uniform . rvs ( )
if np . log ( u ) < - 0.5 * y ** 2 * ( np . exp ( - x ) - np . exp ( - m ) * ( 1. + m - x ) ) :
break
if ntries > 100... |
def enabled ( name , ** kwargs ) :
'''Check to see if the named service is enabled to start on boot
CLI Example :
. . code - block : : bash
salt ' * ' service . enabled < service name >''' | if _service_is_upstart ( name ) :
return _upstart_is_enabled ( name )
else :
if _service_is_sysv ( name ) :
return _sysv_is_enabled ( name )
return None |
def meta_to_indexes ( meta , table_name = None , model_name = None ) :
"""Find all the indexes ( primary keys ) based on the meta data""" | indexes , pk_field = { } , None
indexes = [ ]
for meta_model_name , model_meta in meta . iteritems ( ) :
if ( table_name or model_name ) and not ( table_name == model_meta [ 'Meta' ] . get ( 'db_table' , '' ) or model_name == meta_model_name ) :
continue
field_name , field_infodict , score = find_index ... |
def add_copy_spec ( self , copyspecs , sizelimit = None , tailit = True , pred = None ) :
"""Add a file or glob but limit it to sizelimit megabytes . If fname is
a single file the file will be tailed to meet sizelimit . If the first
file in a glob is too large it will be tailed to meet the sizelimit .""" | if not self . test_predicate ( pred = pred ) :
self . _log_info ( "skipped copy spec '%s' due to predicate (%s)" % ( copyspecs , self . get_predicate ( pred = pred ) ) )
return
if sizelimit is None :
sizelimit = self . get_option ( "log_size" )
if self . get_option ( 'all_logs' ) :
sizelimit = None
if s... |
def unregisterSdc ( self , sdcObj ) :
"""Unregister SDC from MDM / SIO Cluster
: param sdcObj : ScaleIO SDC object
: return : POST request response
: rtype : Requests POST response object""" | # TODO :
# Add code that unmap volume if mapped
self . conn . connection . _check_login ( )
response = self . conn . connection . _do_post ( "{}/{}{}/{}" . format ( self . conn . connection . _api_url , "instances/Sdc::" , sdcObj . id , 'action/removeSdc' ) )
return response |
def render ( json_data , saltenv = 'base' , sls = '' , ** kws ) :
'''Accepts JSON as a string or as a file object and runs it through the JSON
parser .
: rtype : A Python data structure''' | if not isinstance ( json_data , six . string_types ) :
json_data = json_data . read ( )
if json_data . startswith ( '#!' ) :
json_data = json_data [ ( json_data . find ( '\n' ) + 1 ) : ]
if not json_data . strip ( ) :
return { }
return json . loads ( json_data ) |
def lchop ( string , prefix ) :
"""Removes a prefix from string
: param string : String , possibly prefixed with prefix
: param prefix : Prefix to remove from string
: returns : string without the prefix""" | if string . startswith ( prefix ) :
return string [ len ( prefix ) : ]
return string |
def write_def_finish ( self , node , buffered , filtered , cached , callstack = True ) :
"""write the end section of a rendering function , either outermost or
inline .
this takes into account if the rendering function was filtered ,
buffered , etc . and closes the corresponding try : block if any , and
wri... | if not buffered and not cached and not filtered :
self . printer . writeline ( "return ''" )
if callstack :
self . printer . writelines ( "finally:" , "context.caller_stack._pop_frame()" , None )
if buffered or filtered or cached :
if buffered or cached : # in a caching scenario , don ' t try to get... |
def AddDirectory ( self , path ) :
"""Adds a directory to the fake file system .
Note that this function will create parent directories if needed .
Args :
path ( str ) : path of the directory within the fake file system .
Raises :
ValueError : if the path is already set .""" | if self . file_system . FileEntryExistsByPath ( path ) :
raise ValueError ( 'Path: {0:s} already set.' . format ( path ) )
self . _AddParentDirectories ( path )
self . file_system . AddFileEntry ( path , file_entry_type = definitions . FILE_ENTRY_TYPE_DIRECTORY ) |
def instantiate_from_config ( cfg ) :
"""Instantiate data types from config""" | for h in cfg :
if h . get ( "type" ) in data_types :
raise KeyError ( "Data type '%s' already exists" % h )
data_types [ h . get ( "type" ) ] = DataType ( h ) |
def get_max_capvol ( self , remove = True , insert = True , volume = None ) :
"""Give max capacity in mAh / cc for inserting and removing a charged cation into base structure .
Args :
remove : ( bool ) whether to allow cation removal
insert : ( bool ) whether to allow cation insertion
volume : ( float ) vol... | vol = volume if volume else self . struc_oxid . volume
return self . _get_max_cap_ah ( remove , insert ) * 1000 * 1E24 / ( vol * const . N_A ) |
def asd ( M1 , M2 ) :
"""Compute a Fourier transform based distance
between two matrices .
Inspired from Galiez et al . , 2015
( https : / / www . ncbi . nlm . nih . gov / pmc / articles / PMC4535829 / )""" | from scipy . fftpack import fft2
spectra1 = np . abs ( fft2 ( M1 ) )
spectra2 = np . abs ( fft2 ( M2 ) )
return np . linalg . norm ( spectra2 - spectra1 ) |
def merge ( self , hosts ) :
"""Merge extended host information into services
: param hosts : hosts list , to look for a specific one
: type hosts : alignak . objects . host . Hosts
: return : None""" | for extinfo in self :
host_name = extinfo . get_name ( )
host = hosts . find_by_name ( host_name )
if host is not None : # Fusion
self . merge_extinfo ( host , extinfo ) |
def generate_parameters ( self , parameter_id ) :
"""Returns a dict of trial ( hyper - ) parameters , as a serializable object .
Parameters
parameter _ id : int
Returns
config : dict""" | if not self . population :
raise RuntimeError ( 'The population is empty' )
pos = - 1
for i in range ( len ( self . population ) ) :
if self . population [ i ] . result is None :
pos = i
break
if pos != - 1 :
indiv = copy . deepcopy ( self . population [ pos ] )
self . population . pop (... |
def forward_complex ( self , log_sigma ) :
"""Compute a model response , i . e . complex impedances
Parameters
log _ sigma : 1xN or 2xN numpy . ndarray
Model parameters log sigma , N the number of cells . If first
dimension is of length one , assume phase values to be zero
Returns
measurements : Nx2 num... | m = 1.0 / np . exp ( log_sigma )
tdm = self . _get_tdm ( m )
measurements = tdm . measurements ( )
# import IPython
# IPython . embed ( )
# convert R to log sigma
measurements [ : , 0 ] = np . log ( 1.0 / measurements [ : , 0 ] )
return measurements |
def put_policy ( Bucket , Policy , region = None , key = None , keyid = None , profile = None ) :
'''Given a valid config , update the policy for a bucket .
Returns { updated : true } if policy was updated and returns
{ updated : False } if policy was not updated .
CLI Example :
. . code - block : : bash
... | try :
conn = _get_conn ( region = region , key = key , keyid = keyid , profile = profile )
if Policy is None :
Policy = '{}'
elif not isinstance ( Policy , six . string_types ) :
Policy = salt . utils . json . dumps ( Policy )
conn . put_bucket_policy ( Bucket = Bucket , Policy = Policy ... |
def todjango ( table , model , update = True , create = True , use_bulk_create = True , * args , ** kwargs ) :
'''Given a table with appropriate headings create Django models .''' | assert issubclass ( model , Model ) , 'Must be supplied a valid Django model class'
table_iterator = iter ( table )
table_headers = table_iterator . next ( )
model_pk_field_name = model . _meta . pk . name
model_field_names = _get_model_field_names ( model )
model_name = model . __name__
existing_models = _get_django_o... |
def checkArgs ( args ) :
"""Checks the arguments and options .
: param args : an object containing the options of the program .
: type args : argparse . Namespace
: returns : ` ` True ` ` if everything was OK .
If there is a problem with an option , an exception is raised using the
: py : class : ` Progra... | # Check in input file
if not os . path . isfile ( args . file ) :
msg = "%s: no such file" % args . file
raise ProgramError ( msg )
# Check the population file
if args . population_file is None :
msg = "population-file: no population file"
raise ProgramError ( msg )
elif not os . path . isfile ( args . ... |
def _get_acquisition ( self , model , space ) :
"""Imports the acquisition""" | from copy import deepcopy
acqOpt_config = deepcopy ( self . config [ 'acquisition' ] [ 'optimizer' ] )
acqOpt_name = acqOpt_config [ 'name' ]
del acqOpt_config [ 'name' ]
from . . optimization import AcquisitionOptimizer
acqOpt = AcquisitionOptimizer ( space , acqOpt_name , ** acqOpt_config )
from . . acquisitions impo... |
def get_object ( self , queryset = None ) :
"""Return the object the view is displaying .
Same as rest _ framework . generics . GenericAPIView , but :
- Failed assertions instead of deprecations""" | # Determine the base queryset to use .
assert queryset is None , "Passing a queryset is disabled"
queryset = self . filter_queryset ( self . get_queryset ( ) )
# Perform the lookup filtering .
lookup_url_kwarg = self . lookup_url_kwarg or self . lookup_field
lookup = self . kwargs . get ( lookup_url_kwarg , None )
asse... |
def read_config ( ) :
"""Reads and preprocesses the pydoc - markdown configuration file .""" | with open ( PYDOCMD_CONFIG ) as fp :
config = yaml . load ( fp )
return default_config ( config ) |
def spec_var ( model , ph ) :
"""Compute variance of ` ` p ` ` from Fourier coefficients ` ` ph ` ` .
Parameters
model : pyqg . Model instance
The model object from which ` ph ` originates
ph : complex array
The field on which to compute the variance
Returns
var _ dens : float
The variance of ` ph `... | var_dens = 2. * np . abs ( ph ) ** 2 / model . M ** 2
# only half of coefs [ 0 ] and [ nx / 2 + 1 ] due to symmetry in real fft2
var_dens [ ... , 0 ] /= 2
var_dens [ ... , - 1 ] /= 2
return var_dens . sum ( axis = ( - 1 , - 2 ) ) |
def group_modes ( modes ) :
"""Groups consecutive transportation modes with same label , into one
Args :
modes ( : obj : ` list ` of : obj : ` dict ` )
Returns :
: obj : ` list ` of : obj : ` dict `""" | if len ( modes ) > 0 :
previous = modes [ 0 ]
grouped = [ ]
for changep in modes [ 1 : ] :
if changep [ 'label' ] != previous [ 'label' ] :
previous [ 'to' ] = changep [ 'from' ]
grouped . append ( previous )
previous = changep
previous [ 'to' ] = modes [ - 1 ... |
def get_component_types_from_topic ( topic_id , db_conn = None ) :
"""Returns the component types of a topic .""" | db_conn = db_conn or flask . g . db_conn
query = sql . select ( [ models . TOPICS ] ) . where ( models . TOPICS . c . id == topic_id )
topic = db_conn . execute ( query ) . fetchone ( )
topic = dict ( topic )
return topic [ 'component_types' ] |
def get ( cls , reactor , source = 'graphite' , ** options ) :
"""Get Alert Class by source .""" | acls = cls . alerts [ source ]
return acls ( reactor , ** options ) |
def next_moment_operating_on ( self , qubits : Iterable [ ops . Qid ] , start_moment_index : int = 0 , max_distance : int = None ) -> Optional [ int ] :
"""Finds the index of the next moment that touches the given qubits .
Args :
qubits : We ' re looking for operations affecting any of these qubits .
start _ ... | max_circuit_distance = len ( self . _moments ) - start_moment_index
if max_distance is None :
max_distance = max_circuit_distance
elif max_distance < 0 :
raise ValueError ( 'Negative max_distance: {}' . format ( max_distance ) )
else :
max_distance = min ( max_distance , max_circuit_distance )
return self .... |
def _reshape_conv_array ( self , array , section_height , image_width ) :
'''Reshape a rank 4 array to be rank 2 , where each column of block _ width is
a filter , and each row of block height is an input channel . For example :
[ [ [ [ 11 , 21 , 31 , 41 ] ,
[ 51 , 61 , 71 , 81 ] ,
[ 91 , 101 , 111 , 121 ] ... | # E . g . [ 100 , 24 , 24 , 10 ] : this shouldn ' t be reshaped like normal .
if array . shape [ 1 ] == array . shape [ 2 ] and array . shape [ 0 ] != array . shape [ 1 ] :
array = np . rollaxis ( np . rollaxis ( array , 2 ) , 2 )
block_height , block_width , in_channels = array . shape [ : 3 ]
rows = [ ]
max_eleme... |
def get_external_instances ( self , phase = None ) :
"""Get a list of external instances ( in a specific phase )
If phase is None , return all external instances whtever the phase
: param phase : phase to filter ( never used )
: type phase :
: return : external instances list
: rtype : list""" | if phase is None :
return [ instance for instance in self . instances if instance . is_external ]
return [ instance for instance in self . instances if instance . is_external and phase in instance . phases and instance not in self . to_restart ] |
def calc_qref_v1 ( self ) :
"""Determine the reference discharge within the given space - time interval .
Required state sequences :
| QZ |
| QA |
Calculated flux sequence :
| QRef |
Basic equation :
: math : ` QRef = \\ frac { QZ _ { new } + QZ _ { old } + QA _ { old } } { 3 } `
Example :
> > > f... | new = self . sequences . states . fastaccess_new
old = self . sequences . states . fastaccess_old
flu = self . sequences . fluxes . fastaccess
flu . qref = ( new . qz + old . qz + old . qa ) / 3. |
def unpack ( self , gpsd_socket_response ) :
"""Sets new socket data as DataStream attributes in those initialised dictionaries
Arguments :
gpsd _ socket _ response ( json object ) :
Provides :
self attribute dictionaries , e . g . , self . TPV [ ' lat ' ] , self . SKY [ ' gdop ' ]
Raises :
AttributeErr... | try :
fresh_data = json . loads ( gpsd_socket_response )
# The reserved word ' class ' is popped from JSON object class
package_name = fresh_data . pop ( 'class' , 'ERROR' )
# gpsd data package errors are also ' ERROR ' .
package = getattr ( self , package_name , package_name )
# packages are na... |
def load_all ( stream , Loader = None ) :
"""Parse all YAML documents in a stream
and produce corresponding Python objects .""" | if Loader is None :
load_warning ( 'load_all' )
Loader = FullLoader
loader = Loader ( stream )
try :
while loader . check_data ( ) :
yield loader . get_data ( )
finally :
loader . dispose ( ) |
def convert_tuple_to_float ( input_tuple ) :
"""Converts a tuple to a float where first element of tuple is before the decimal
and the second element is after the decimal .
Parameters :
input _ tuple : A tuple of two integers
Returns :
A float number which is a combination of both elements of tuple
Exam... | combined_number = float ( '.' . join ( map ( str , input_tuple ) ) )
return combined_number |
def mount ( name , device , mkmnt = False , fstype = '' , opts = 'defaults' , user = None , util = 'mount' ) :
'''Mount a device
CLI Example :
. . code - block : : bash
salt ' * ' mount . mount / mnt / foo / dev / sdz1 True''' | if util != 'mount' : # This functionality used to live in img . mount _ image
if util == 'guestfs' :
return __salt__ [ 'guestfs.mount' ] ( name , root = device )
elif util == 'qemu_nbd' :
mnt = __salt__ [ 'qemu_nbd.init' ] ( name , device )
if not mnt :
return False
f... |
def autopage ( self ) :
"""Iterate through results from all pages .
: return : all results
: rtype : generator""" | while self . items :
yield from self . items
self . items = self . fetch_next ( ) |
def get_connection_string ( params , hide_password = True ) :
"""Get a database connection string
Args :
params ( dict ) : database configuration , as defined in : mod : ` ozelot . config `
hide _ password ( bool ) : if True , the password is hidden in the returned string
( use this for logging purposes ) .... | connection_string = params [ 'driver' ] + '://'
user = params . get ( 'user' , None )
password = params . get ( 'password' , None )
host = params . get ( 'host' , None )
port = params . get ( 'port' , None )
database = params . get ( 'database' , None )
if database is None :
raise ValueError ( "Field 'database' of ... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.