signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def logger ( name = 'BHMM' , pattern = '%(asctime)s %(levelname)s %(name)s: %(message)s' , date_format = '%H:%M:%S' , handler = logging . StreamHandler ( sys . stdout ) ) :
"""Retrieves the logger instance associated to the given name .
: param name : The name of the logger instance .
: type name : str
: para... | _logger = logging . getLogger ( name )
_logger . setLevel ( config . log_level ( ) )
if not _logger . handlers :
formatter = logging . Formatter ( pattern , date_format )
handler . setFormatter ( formatter )
handler . setLevel ( config . log_level ( ) )
_logger . addHandler ( handler )
_logger . pro... |
def strip_bewit ( url ) :
"""Strips the bewit parameter out of a url .
Returns ( encoded _ bewit , stripped _ url )
Raises InvalidBewit if no bewit found .
: param url :
The url containing a bewit parameter
: type url : str""" | m = re . search ( '[?&]bewit=([^&]+)' , url )
if not m :
raise InvalidBewit ( 'no bewit data found' )
bewit = m . group ( 1 )
stripped_url = url [ : m . start ( ) ] + url [ m . end ( ) : ]
return bewit , stripped_url |
def cib ( args ) :
"""% prog cib bamfile samplekey
Convert BAM to CIB ( a binary storage of int8 per base ) .""" | p = OptionParser ( cib . __doc__ )
p . add_option ( "--prefix" , help = "Report seqids with this prefix only" )
p . set_cpus ( )
opts , args = p . parse_args ( args )
if len ( args ) != 2 :
sys . exit ( not p . print_help ( ) )
bamfile , samplekey = args
mkdir ( samplekey )
bam = pysam . AlignmentFile ( bamfile , "... |
def func_call ( self , t ) :
"""For function calls e . g . TEXT ( tostring ( [ area ] , " % . 2f " ) )""" | func , params = t
func_name = func . value
func . value = "({}({}))" . format ( func_name , params )
return func |
def create ( self , name , kind , ** kwargs ) :
"""Creates an input of a specific kind in this collection , with any
arguments you specify .
: param ` name ` : The input name .
: type name : ` ` string ` `
: param ` kind ` : The kind of input :
- " ad " : Active Directory
- " monitor " : Files and direc... | kindpath = self . kindpath ( kind )
self . post ( kindpath , name = name , ** kwargs )
# If we created an input with restrictToHost set , then
# its path will be < restrictToHost > : < name > , not just < name > ,
# and we have to adjust accordingly .
# Url encodes the name of the entity .
name = UrlEncoded ( name , en... |
def _purge_jobs ( timestamp ) :
'''Purge records from the returner tables .
: param job _ age _ in _ seconds : Purge jobs older than this
: return :''' | with _get_serv ( ) as cursor :
try :
sql = 'delete from jids where jid in (select distinct jid from salt_returns where alter_time < %s)'
cursor . execute ( sql , ( timestamp , ) )
cursor . execute ( 'COMMIT' )
except psycopg2 . DatabaseError as err :
error = err . args
sy... |
def login ( self , username , password = '' , login_key = None , auth_code = None , two_factor_code = None , login_id = None ) :
"""Login as a specific user
: param username : username
: type username : : class : ` str `
: param password : password
: type password : : class : ` str `
: param login _ key :... | self . _LOG . debug ( "Attempting login" )
if not self . _pre_login ( ) :
return EResult . TryAnotherCM
self . username = username
message = MsgProto ( EMsg . ClientLogon )
message . header . steamid = SteamID ( type = 'Individual' , universe = 'Public' )
message . body . protocol_version = 65579
message . body . c... |
def p_object_const_list ( self , p ) :
'''object _ const _ list : object _ const _ list COMMA IDENT
| IDENT''' | if len ( p ) == 4 :
p [ 1 ] . append ( p [ 3 ] )
p [ 0 ] = p [ 1 ]
elif len ( p ) == 2 :
p [ 0 ] = [ p [ 1 ] ] |
def stage_job ( self , credentials , job_details , input_files , vm_instance_name ) :
"""Request that a job be staged on a worker ( ie . download some files )
: param credentials : jobapi . Credentials : user ' s credentials used to download input _ files
: param job _ details : object : details about job ( id ... | self . _send ( JobCommands . STAGE_JOB , StageJobPayload ( credentials , job_details , input_files , vm_instance_name ) ) |
def device_count ( self ) :
"""Find amount of CUE devices
: returns : amount of CUE devices
: rtype : int""" | device_count = get_device_count ( self . corsair_sdk )
if device_count == - 1 :
self . _raise_corsair_error ( )
return device_count |
def setup_privnet ( self , host = None ) :
"""Load settings from the privnet JSON config file
Args :
host ( string , optional ) : if supplied , uses this IP or domain as neo nodes . The host must
use these standard ports : P2P 20333 , RPC 30333.""" | self . setup ( FILENAME_SETTINGS_PRIVNET )
if isinstance ( host , str ) :
if ":" in host :
raise Exception ( "No protocol prefix or port allowed in host, use just the IP or domain." )
print ( "Using custom privatenet host:" , host )
self . SEED_LIST = [ "%s:20333" % host ]
self . RPC_LIST = [ "h... |
def multi_raw ( query , params , models , model_to_fields ) :
"""Scoop multiple model instances out of the DB at once , given a query that
returns all fields of each .
Return an iterable of sequences of model instances parallel to the
` ` models ` ` sequence of classes . For example : :
[ ( < User such - an... | cursor = connections [ router . db_for_read ( models [ 0 ] ) ] . cursor ( )
cursor . execute ( query , params )
rows = cursor . fetchall ( )
for row in rows :
row_iter = iter ( row )
yield [ model_class ( ** dict ( ( a , next ( row_iter ) ) for a in model_to_fields [ model_class ] ) ) for model_class in models ... |
def scrub ( data ) :
"""Verify and clean data . Raise error if input fails .""" | # blanks , Nones , and empty strings can stay as is
if not data :
return data
if isinstance ( data , ( int , float ) ) :
return data
if isinstance ( data , list ) :
return [ scrub ( entry ) for entry in data ]
if isinstance ( data , dict ) :
return { scrub ( key ) : scrub ( value ) for key , value in da... |
def get_environ ( keys ) :
"""Get environment variables from : data : ` os . environ ` .
: type keys : [ str ]
: rtype : dict
Some additional features .
* If ' HOST ' is not in : data : ` os . environ ` , this function
automatically fetch it using : meth : ` platform . node ` .
* If ' TTY ' is not in : ... | items = ( ( k , os . environ . get ( k ) ) for k in keys )
subenv = dict ( ( k , v ) for ( k , v ) in items if v is not None )
needset = lambda k : k in keys and not subenv . get ( k )
def setifnonempty ( key , value ) :
if value :
subenv [ key ] = value
if needset ( 'HOST' ) :
import platform
suben... |
def noop ( * layers ) :
"""Transform a sequences of layers into a null operation .""" | def begin_update ( X , drop = 0.0 ) :
return X , lambda D , * a , ** k : D
return begin_update |
def set_Y ( self , Y ) :
"""Set the output data of the model
: param Y : output observations
: type Y : np . ndarray or ObsArray""" | assert isinstance ( Y , ( np . ndarray , ObsAr ) )
state = self . update_model ( )
self . update_model ( False )
if self . normalizer is not None :
self . normalizer . scale_by ( Y )
self . Y_normalized = ObsAr ( self . normalizer . normalize ( Y ) )
self . Y = Y
else :
self . Y = ObsAr ( Y ) if isinsta... |
def set_value ( self , visual_property , value ) :
"""Set a single Visual Property Value
: param visual _ property : Visual Property ID
: param value : New value for the VP
: return : None""" | if visual_property is None or value is None :
raise ValueError ( 'Both VP and value are required.' )
new_value = [ { 'visualProperty' : visual_property , "value" : value } ]
requests . put ( self . url , data = json . dumps ( new_value ) , headers = HEADERS ) |
def dump_stacks ( self ) :
'''Dumps the stack of all threads . This function
is meant for debugging . Useful when a deadlock happens .
borrowed from : http : / / blog . ziade . org / 2012/05/25 / zmq - and - gevent - debugging - nightmares /''' | dump = [ ]
# threads
threads = dict ( [ ( th . ident , th . name ) for th in threading . enumerate ( ) ] )
for thread , frame in sys . _current_frames ( ) . items ( ) :
if thread not in threads :
continue
dump . append ( 'Thread 0x%x (%s)\n' % ( thread , threads [ thread ] ) )
dump . append ( '' . j... |
def fit_from_cfg ( cls , df , cfgname , debug = False , outcfgname = None ) :
"""Parameters
df : DataFrame
The dataframe which contains the columns to use for the estimation .
cfgname : string
The name of the yaml config file which describes the hedonic model .
debug : boolean , optional ( default False )... | logger . debug ( 'start: fit from configuration {}' . format ( cfgname ) )
hm = cls . from_yaml ( str_or_buffer = cfgname )
ret = hm . fit ( df , debug = debug )
print ( ret . summary ( ) )
outcfgname = outcfgname or cfgname
hm . to_yaml ( str_or_buffer = outcfgname )
logger . debug ( 'finish: fit into configuration {}... |
def stop ( self , devices ) :
"""Power - Off one or more running devices .""" | for device in devices :
self . logger . info ( 'Stopping: %s' , device . id )
try :
device . power_off ( )
except packet . baseapi . Error :
raise PacketManagerException ( 'Unable to stop instance "{}"' . format ( device . id ) ) |
def parse_sync_points ( names , tests ) :
"""Slice list of test names on sync points .
If test is test file find full path to file .
Returns :
A list of test file sets and sync point strings .
Examples :
[ ' test _ hard _ reboot ' ]
[ set ( ' test1 ' , ' test2 ' ) ]
[ set ( ' test1 ' , ' test2 ' ) , '... | test_files = [ ]
section = set ( )
for name in names :
if name in SYNC_POINTS :
if section :
test_files . append ( section )
test_files . append ( name )
section = set ( )
else :
section . add ( find_test_file ( name , tests ) )
if section :
test_files . append ( ... |
def arc ( self , x , y , radius , start_angle , end_angle ) :
"""draw arc going counter - clockwise from start _ angle to end _ angle""" | self . _add_instruction ( "arc" , x , y , radius , start_angle , end_angle ) |
def get_all ( self ) -> List [ Commodity ] :
"""Loads all non - currency commodities , assuming they are stocks .""" | query = ( self . query . order_by ( Commodity . namespace , Commodity . mnemonic ) )
return query . all ( ) |
def interpret ( self ) :
"""Generic entrypoint of ` Interpreter ` class .""" | self . load_builtins ( )
self . load_functions ( self . tree )
self . visit ( self . tree ) |
def post ( self , request ) :
"""Respond to POSTed username / password with token .""" | serializer = AuthTokenSerializer ( data = request . data )
if serializer . is_valid ( ) :
token , _ = ExpiringToken . objects . get_or_create ( user = serializer . validated_data [ 'user' ] )
if token . expired ( ) : # If the token is expired , generate a new one .
token . delete ( )
token = Exp... |
def git_tag_to_semver ( git_tag : str ) -> SemVer :
""": git _ tag : A string representation of a Git tag .
Searches a Git tag ' s string representation for a SemVer , and returns that
as a SemVer object .""" | pattern = re . compile ( r'[0-9]+\.[0-9]+\.[0-9]+$' )
match = pattern . search ( git_tag )
if match :
version = match . group ( 0 )
else :
raise InvalidTagFormatException ( 'Tag passed contains no SemVer.' )
return SemVer . from_str ( version ) |
def get_file_size ( fileobj ) :
"""Returns the size of a file - like object .""" | currpos = fileobj . tell ( )
fileobj . seek ( 0 , 2 )
total_size = fileobj . tell ( )
fileobj . seek ( currpos )
return total_size |
def toggle_rules ( self , * args ) :
"""Display or hide the view for constructing rules out of cards .""" | if self . app . manager . current != 'rules' and not isinstance ( self . app . selected_proxy , CharStatProxy ) :
self . app . rules . entity = self . app . selected_proxy
self . app . rules . rulebook = self . app . selected_proxy . rulebook
if isinstance ( self . app . selected_proxy , CharStatProxy ) :
s... |
def get_abi_alignment ( self , target_data , context = None ) :
"""Get the minimum ABI alignment of this type according to data layout
* target _ data * .""" | llty = self . _get_ll_pointer_type ( target_data , context )
return target_data . get_pointee_abi_alignment ( llty ) |
def _connect ( self , timeout = None ) :
'''Connect to a running IPCServer''' | if isinstance ( self . socket_path , int ) :
sock_type = socket . AF_INET
sock_addr = ( '127.0.0.1' , self . socket_path )
else :
sock_type = socket . AF_UNIX
sock_addr = self . socket_path
self . stream = None
if timeout is not None :
timeout_at = time . time ( ) + timeout
while True :
if self ... |
def generate_rest_view ( config , model_cls , attrs = None , es_based = True , attr_view = False , singular = False ) :
"""Generate REST view for a model class .
: param model _ cls : Generated DB model class .
: param attr : List of strings that represent names of view methods , new
generated view should sup... | valid_attrs = ( list ( collection_methods . values ( ) ) + list ( item_methods . values ( ) ) )
missing_attrs = set ( valid_attrs ) - set ( attrs )
if singular :
bases = [ ItemSingularView ]
elif attr_view :
bases = [ ItemAttributeView ]
elif es_based :
bases = [ ESCollectionView ]
else :
bases = [ Coll... |
def get_config_from_env ( cls ) :
""". . deprecated : : 2.5.3
Gets configuration out of environment .
Returns list of dicts - list of namenode representations""" | core_path = os . path . join ( os . environ [ 'HADOOP_HOME' ] , 'conf' , 'core-site.xml' )
core_configs = cls . read_core_config ( core_path )
hdfs_path = os . path . join ( os . environ [ 'HADOOP_HOME' ] , 'conf' , 'hdfs-site.xml' )
hdfs_configs = cls . read_hdfs_config ( hdfs_path )
if ( not core_configs ) and ( not ... |
def apply ( self , context , clear , split , ** kwargs ) :
"""Extract candidates from the given Context .
: param context : A document to process .
: param clear : Whether or not to clear the existing database entries .
: param split : Which split to use .""" | logger . debug ( f"Document: {context}" )
# Iterate over each candidate class
for i , candidate_class in enumerate ( self . candidate_classes ) :
logger . debug ( f" Relation: {candidate_class.__name__}" )
# Generates and persists candidates
candidate_args = { "split" : split }
candidate_args [ "docume... |
def validate_q_time ( self , value ) :
"""Would be for example : [ 2013-03-01 TO 2013-04-01T00:00:00 ] and / or [ * TO * ]
Returns a valid sorl value . [ 2013-03-01T00:00:00Z TO 2013-04-01T00:00:00Z ] and / or [ * TO * ]""" | if value :
try :
range = utils . parse_datetime_range_to_solr ( value )
return range
except Exception as e :
raise serializers . ValidationError ( e . message )
return value |
def schema_keys ( schema ) :
"""Get the string values of keys in a dict - based schema .
Non - string keys are ignored .
Returns :
Set of string keys of a schema which is in the form ( eg ) :
schema = Schema ( { Required ( " foo " ) : int ,
Optional ( " bah " ) : basestring } )""" | def _get_leaf ( value ) :
if isinstance ( value , Schema ) :
return _get_leaf ( value . _schema )
return value
keys = set ( )
dict_ = schema . _schema
assert isinstance ( dict_ , dict )
for key in dict_ . iterkeys ( ) :
key_ = _get_leaf ( key )
if isinstance ( key_ , basestring ) :
keys ... |
def append_varint32 ( self , value ) :
"""Appends a signed 32 - bit integer to the internal buffer ,
encoded as a varint . ( Note that a negative varint32 will
always require 10 bytes of space . )""" | if not wire_format . INT32_MIN <= value <= wire_format . INT32_MAX :
raise errors . EncodeError ( 'Value out of range: %d' % value )
self . append_varint64 ( value ) |
def send_order ( self , acc_id , amount , symbol , _type , price = 0 , site = 'Pro' , _async = False ) :
"""创建并执行订单
: param amount :
: param source : 如果使用借贷资产交易 , 请在下单接口 , 请求参数source中填写 ' margin - api '
: param symbol :
: param _ type : 可选值 { buy - market : 市价买 , sell - market : 市价卖 , buy - limit : 限价买 , se... | assert site in [ 'Pro' , 'HADAX' ]
assert _type in u . ORDER_TYPE
params = { 'account-id' : acc_id , 'amount' : amount , 'symbol' : symbol , 'type' : _type , 'source' : 'api' }
if price :
params [ 'price' ] = price
path = f'/v1{"/" if site == "Pro" else "/hadax/"}order/orders/place'
return api_key_post ( params , p... |
def tick ( self , d ) :
"""ticks come in on every block""" | if self . test_blocks :
if not ( self . counter [ "blocks" ] or 0 ) % self . test_blocks :
self . test ( )
self . counter [ "blocks" ] += 1 |
def get_instance ( self , payload ) :
"""Build an instance of ApplicationInstance
: param dict payload : Payload response from the API
: returns : twilio . rest . api . v2010 . account . application . ApplicationInstance
: rtype : twilio . rest . api . v2010 . account . application . ApplicationInstance""" | return ApplicationInstance ( self . _version , payload , account_sid = self . _solution [ 'account_sid' ] , ) |
def generate ( env ) :
"""Add Builders and construction variables for lib to an Environment .""" | SCons . Tool . createStaticLibBuilder ( env )
# Set - up ms tools paths
msvc_setup_env_once ( env )
env [ 'AR' ] = 'lib'
env [ 'ARFLAGS' ] = SCons . Util . CLVar ( '/nologo' )
env [ 'ARCOM' ] = "${TEMPFILE('$AR $ARFLAGS /OUT:$TARGET $SOURCES','$ARCOMSTR')}"
env [ 'LIBPREFIX' ] = ''
env [ 'LIBSUFFIX' ] = '.lib' |
def deletescript ( self , name ) :
"""Delete a script from the server
See MANAGESIEVE specifications , section 2.10
: param name : script ' s name
: rtype : boolean""" | code , data = self . __send_command ( "DELETESCRIPT" , [ name . encode ( "utf-8" ) ] )
if code == "OK" :
return True
return False |
def month_interval ( year , month , return_str = False ) :
"""Usage Example : :
> > > timewrapper . day _ interval ( 2014 , 12)
( datetime ( 2014 , 12 , 1 , 0 , 0 , 0 ) , datetime ( 2014 , 12 , 31 , 23 , 59 , 59 ) )""" | if month == 12 :
start , end = datetime ( year , month , 1 ) , datetime ( year + 1 , 1 , 1 ) - timedelta ( seconds = 1 )
else :
start , end = datetime ( year , month , 1 ) , datetime ( year , month + 1 , 1 ) - timedelta ( seconds = 1 )
if not return_str :
return start , end
else :
return str ( start ) ,... |
def _call ( self , f , out ) :
"""Implement ` ` self ( vf , out ) ` ` .""" | for vfi , oi , ran_wi , dom_wi in zip ( self . vecfield , out , self . __ran_weights , self . weights ) :
vfi . multiply ( f , out = oi )
if not np . isclose ( ran_wi , dom_wi ) :
oi *= dom_wi / ran_wi |
def execute ( self , cmd , block_size = DEFAULT_EXECUTE_READ_BLOCK_SIZE ) :
"""Execute a remote command . This functionality does not support more
than one command to be executed on the same channel , so we create a
dedicated channel at the session level than allowing direct access at
the channel level .""" | with SshChannel ( self ) as sc :
self . __log . debug ( "Executing command: %s" % ( cmd ) )
sc . open_session ( )
sc . request_exec ( cmd )
buffer_ = bytearray ( )
while 1 :
bytes = sc . read ( block_size )
yield bytes
if len ( bytes ) < block_size :
break |
def from_json ( cls , data ) :
"""Create Wea from json file
" location " : { } , / / ladybug location schema
" direct _ normal _ irradiance " : [ ] , / / List of hourly direct normal
irradiance data points
" diffuse _ horizontal _ irradiance " : [ ] , / / List of hourly diffuse
horizontal irradiance data ... | required_keys = ( 'location' , 'direct_normal_irradiance' , 'diffuse_horizontal_irradiance' )
optional_keys = ( 'timestep' , 'is_leap_year' )
for key in required_keys :
assert key in data , 'Required key "{}" is missing!' . format ( key )
for key in optional_keys :
if key not in data :
data [ key ] = No... |
def restore ( self , fade = False ) :
"""Restore the state of a device to that which was previously saved .
For coordinator devices restore everything . For slave devices
only restore volume etc . , not transport info ( transport info
comes from the slave ' s coordinator ) .
Args :
fade ( bool ) : Whether... | try :
if self . is_coordinator :
self . _restore_coordinator ( )
finally :
self . _restore_volume ( fade )
# Now everything is set , see if we need to be playing , stopped
# or paused ( only for coordinators )
if self . is_coordinator :
if self . transport_state == 'PLAYING' :
self . device ... |
def RGBA ( self , val ) :
"""Set the color using an Nx4 array of RGBA uint8 values""" | # need to convert to normalized float
val = np . atleast_1d ( val ) . astype ( np . float32 ) / 255
self . rgba = val |
def reset_job ( self , description ) :
"""remove the job from the state .
if means that next time we run , this job will start over from scratch .""" | class_list = self . config . crontabber . jobs . class_list
class_list = self . _reorder_class_list ( class_list )
for class_name , job_class in class_list :
if ( job_class . app_name == description or description == job_class . __module__ + '.' + job_class . __name__ ) :
if job_class . app_name in self . j... |
def generate ( self , state ) :
"""Return a random variable if any , otherwise create a new default variable .""" | if self . count >= random . randint ( DharmaConst . VARIABLE_MIN , DharmaConst . VARIABLE_MAX ) :
return "%s%d" % ( self . var , random . randint ( 1 , self . count ) )
var = random . choice ( self )
prefix = self . eval ( var [ 0 ] , state )
suffix = self . eval ( var [ 1 ] , state )
self . count += 1
element_name... |
def _GetAttributeContainerByIndex ( self , container_type , index ) :
"""Retrieves a specific attribute container .
Args :
container _ type ( str ) : attribute container type .
index ( int ) : attribute container index .
Returns :
AttributeContainer : attribute container or None if not available .
Raise... | sequence_number = index + 1
query = 'SELECT _data FROM {0:s} WHERE rowid = {1:d}' . format ( container_type , sequence_number )
try :
self . _cursor . execute ( query )
except sqlite3 . OperationalError as exception :
raise IOError ( 'Unable to query storage file with error: {0!s}' . format ( exception ) )
row ... |
def retrieve ( self , request , project , pk = None ) :
"""Returns a job _ log _ url object given its ID""" | log = JobLog . objects . get ( id = pk )
return Response ( self . _log_as_dict ( log ) ) |
def rate_of_change ( data , period ) :
"""Rate of Change .
Formula :
( Close - Close n periods ago ) / ( Close n periods ago ) * 100""" | catch_errors . check_for_period_error ( data , period )
rocs = [ ( ( data [ idx ] - data [ idx - ( period - 1 ) ] ) / data [ idx - ( period - 1 ) ] ) * 100 for idx in range ( period - 1 , len ( data ) ) ]
rocs = fill_for_noncomputable_vals ( data , rocs )
return rocs |
def _extractAssociation ( self , assoc_response , assoc_session ) :
"""Attempt to extract an association from the response , given
the association response message and the established
association session .
@ param assoc _ response : The association response message from
the server
@ type assoc _ response ... | # Extract the common fields from the response , raising an
# exception if they are not found
assoc_type = assoc_response . getArg ( OPENID_NS , 'assoc_type' , no_default )
assoc_handle = assoc_response . getArg ( OPENID_NS , 'assoc_handle' , no_default )
# expires _ in is a base - 10 string . The Python parsing will
# ... |
def image_id ( self ) :
"""this container is created from image with id . . .""" | try : # docker > = 1.9
image_id = self . data [ "ImageID" ]
except KeyError : # docker < = 1.8
image_id = self . metadata_get ( [ "Image" ] )
return image_id |
def bitop_not ( self , dest , key ) :
"""Perform bitwise NOT operations between strings .""" | return self . execute ( b'BITOP' , b'NOT' , dest , key ) |
def _game_image_from_screen ( self , game_type ) :
"""Return the image of the given game type from the screen .
Return None if no game is found .""" | # screen
screen_img = self . _screen_shot ( )
# game image
game_rect = self . _game_finders [ game_type ] . locate_in ( screen_img )
if game_rect is None :
return
t , l , b , r = game_rect
game_img = screen_img [ t : b , l : r ]
return game_img |
def gdsii_hash ( filename , engine = None ) :
"""Calculate the a hash value for a GDSII file .
The hash is generated based only on the contents of the cells in the
GDSII library , ignoring any timestamp records present in the file
structure .
Parameters
filename : string
Full path to the GDSII file .
... | with open ( filename , 'rb' ) as fin :
data = fin . read ( )
contents = [ ]
start = pos = 0
while pos < len ( data ) :
size , rec = struct . unpack ( '>HH' , data [ pos : pos + 4 ] )
if rec == 0x0502 :
start = pos + 28
elif rec == 0x0700 :
contents . append ( data [ start : pos ] )
p... |
def parse_named_type ( lexer : Lexer ) -> NamedTypeNode :
"""NamedType : Name""" | start = lexer . token
return NamedTypeNode ( name = parse_name ( lexer ) , loc = loc ( lexer , start ) ) |
def OnRowSize ( self , event ) :
"""Row size event handler""" | row = event . GetRowOrCol ( )
tab = self . grid . current_table
rowsize = self . grid . GetRowSize ( row ) / self . grid . grid_renderer . zoom
# Detect for resizing group of rows
rows = self . grid . GetSelectedRows ( )
if len ( rows ) == 0 :
rows = [ row , ]
# Detect for selection of rows spanning all columns
sel... |
def get_block_overview ( block_representation , coin_symbol = 'btc' , txn_limit = None , txn_offset = None , api_key = None ) :
"""Takes a block _ representation , coin _ symbol and txn _ limit and gets an overview
of that block , including up to X transaction ids .
Note that block _ representation may be the b... | assert is_valid_coin_symbol ( coin_symbol )
assert is_valid_block_representation ( block_representation = block_representation , coin_symbol = coin_symbol )
url = make_url ( coin_symbol , ** dict ( blocks = block_representation ) )
params = { }
if api_key :
params [ 'token' ] = api_key
if txn_limit :
params [ '... |
def objectMD5 ( obj ) :
'''Get md5 of an object''' | if hasattr ( obj , 'target_name' ) :
return obj . target_name ( )
try :
return textMD5 ( pickle . dumps ( obj ) )
except :
return '' |
def nvmlDeviceGetCurrPcieLinkWidth ( handle ) :
r"""* Retrieves the current PCIe link width
* For Fermi & tm ; or newer fully supported devices .
* @ param device The identifier of the target device
* @ param currLinkWidth Reference in which to return the current PCIe link generation
* @ return
* - \ ref ... | fn = _nvmlGetFunctionPointer ( "nvmlDeviceGetCurrPcieLinkWidth" )
width = c_uint ( )
ret = fn ( handle , byref ( width ) )
_nvmlCheckReturn ( ret )
return bytes_to_str ( width . value ) |
def replace_category_by_id ( cls , category_id , category , ** kwargs ) :
"""Replace Category
Replace all attributes of Category
This method makes a synchronous HTTP request by default . To make an
asynchronous HTTP request , please pass async = True
> > > thread = api . replace _ category _ by _ id ( categ... | kwargs [ '_return_http_data_only' ] = True
if kwargs . get ( 'async' ) :
return cls . _replace_category_by_id_with_http_info ( category_id , category , ** kwargs )
else :
( data ) = cls . _replace_category_by_id_with_http_info ( category_id , category , ** kwargs )
return data |
def create_mutation_file ( self , list_of_tuples ) :
"""Create the FoldX file ' individual _ list . txt ' to run BuildModel upon .
Args :
list _ of _ tuples ( list ) : A list of tuples indicating mutation groups to carry out BuildModel upon . Example : :
( ( ' N ' , ' A ' , 308 , ' S ' ) , ( ' S ' , ' A ' , 3... | self . mutation_infile = op . join ( self . foldx_dir , 'individual_list.txt' )
idx = 1
with open ( self . mutation_infile , 'w' ) as f :
for mutant_group in list_of_tuples : # Write the mutation string to the file
mutstring = '' . join ( list ( map ( lambda x : '{}{}{}{};' . format ( x [ 0 ] , x [ 1 ] , x ... |
def unstage_signature ( vcs , signature ) :
"""Remove ` signature ` from the list of staged signatures
Args :
vcs ( easyci . vcs . base . Vcs )
signature ( basestring )
Raises :
NotStagedError""" | evidence_path = _get_staged_history_path ( vcs )
staged = get_staged_signatures ( vcs )
if signature not in staged :
raise NotStagedError
staged . remove ( signature )
string = '\n' . join ( staged )
with open ( evidence_path , 'w' ) as f :
f . write ( string ) |
def avl_insert_dir ( root , new_node , direction = 1 ) :
"""Inserts a single node all the way to the left ( direction = 1 ) or right ( direction = 1)
CommandLine :
python - m utool . experimental . euler _ tour _ tree _ avl avl _ insert _ dir - - show
python - m utool . experimental . euler _ tour _ tree _ av... | if root is None :
return new_node
assert new_node . parent is None , str ( ( new_node , new_node . parent ) )
assert new_node . left is None
assert new_node . right is None
assert root . parent is None
node_stack = [ ]
# node stack
# dir _ stack = array ( ' I ' ) # direction stack
done = False
top = 0
# Move all th... |
def load_product_class ( self , mode ) :
"""Load recipe object , according to observing mode""" | product_entry = self . products [ mode ]
return self . _get_base_class ( product_entry ) |
def normal ( nmr_distributions , nmr_samples , mean = 0 , std = 1 , ctype = 'float' , seed = None ) :
"""Draw random samples from the Gaussian distribution .
Args :
nmr _ distributions ( int ) : the number of unique continuous _ distributions to create
nmr _ samples ( int ) : The number of samples to draw
m... | if is_scalar ( mean ) :
mean = np . ones ( ( nmr_distributions , 1 ) ) * mean
if is_scalar ( std ) :
std = np . ones ( ( nmr_distributions , 1 ) ) * std
kernel_data = { 'mean' : Array ( mean , as_scalar = True ) , 'std' : Array ( std , as_scalar = True ) }
kernel = SimpleCLFunction . from_string ( '''
v... |
def info ( self , text = None ) :
"""Shows and persists info symbol and text and exits .
Parameters
text : None , optional
Text to be shown alongside info symbol .
Returns
self""" | return self . stop_and_persist ( symbol = LogSymbols . INFO . value , text = text ) |
def AtMaximumDepth ( self , search_depth ) :
"""Determines if the find specification is at maximum depth .
Args :
search _ depth ( int ) : number of key path segments to compare .
Returns :
bool : True if at maximum depth , False if not .""" | if self . _key_path_segments is not None :
if search_depth >= self . _number_of_key_path_segments :
return True
return False |
def path_param ( name , ns ) :
"""Build a path parameter definition .""" | if ns . identifier_type == "uuid" :
param_type = "string"
param_format = "uuid"
else :
param_type = "string"
param_format = None
kwargs = { "name" : name , "in" : "path" , "required" : True , "type" : param_type , }
if param_format :
kwargs [ "format" ] = param_format
return swagger . PathParameterS... |
def use ( wcspkg , raise_err = True ) :
"""Choose WCS package .""" | global coord_types , wcs_configured , WCS
if wcspkg not in common . custom_wcs : # Try to dynamically load WCS
modname = 'wcs_%s' % ( wcspkg )
path = os . path . join ( wcs_home , '%s.py' % ( modname ) )
try :
my_import ( modname , path )
except ImportError :
return False
if wcspkg in co... |
def processing_blocks ( self ) :
"""Return the a JSON dict encoding the PBs known to SDP .""" | pb_list = ProcessingBlockList ( )
# TODO ( BMo ) realtime , offline etc .
return json . dumps ( dict ( active = pb_list . active , completed = pb_list . completed , aborted = pb_list . aborted ) ) |
def find_sum_of_first_even_and_odd ( array ) :
"""Function to calculate the sum of first even and first odd number in a list .
> > > find _ sum _ of _ first _ even _ and _ odd ( [ 1 , 3 , 5 , 7 , 4 , 1 , 6 , 8 ] )
> > > find _ sum _ of _ first _ even _ and _ odd ( [ 1 , 2 , 3 , 4 , 5 , 6 , 7 , 8 , 9 , 10 ] )
... | first_even = next ( ( num for num in array if num % 2 == 0 ) , - 1 )
first_odd = next ( ( num for num in array if num % 2 != 0 ) , - 1 )
return first_even + first_odd |
def safe_walk ( top , topdown = True , onerror = None , followlinks = True , _seen = None ) :
'''A clone of the python os . walk function with some checks for recursive
symlinks . Unlike os . walk this follows symlinks by default .''' | if _seen is None :
_seen = set ( )
# We may not have read permission for top , in which case we can ' t
# get a list of the files the directory contains . os . path . walk
# always suppressed the exception then , rather than blow up for a
# minor reason when ( say ) a thousand readable directories are still
# left ... |
def add_ylabel ( self , text = None ) :
"""Add a label to the y - axis .""" | y = self . fit . meta [ 'dependent' ]
if not text :
text = '$' + y [ 'tex_symbol' ] + r'$ $(\si{' + y [ 'siunitx' ] + r'})$'
self . plt . set_ylabel ( text ) |
def getGroupContentItems ( self , groupName ) :
"""Gets all the items owned by a group ( s ) .
Args :
groupName ( list ) : The name of the group ( s ) from which to get items .
Returns :
list : A list of items belonging to the group ( s ) .
Notes :
If you want to get items from a single group , ` ` grou... | admin = None
userCommunity = None
groupIds = None
groupId = None
groupContent = None
result = None
item = None
items = [ ]
try :
admin = arcrest . manageorg . Administration ( securityHandler = self . _securityHandler )
userCommunity = admin . community
groupIds = userCommunity . getGroupIDs ( groupNames = ... |
def gaussian2d ( xy , sx , sy , mx = 0 , my = 0 , rho = 0 , amp = 1 , offs = 0 ) :
'''see http : / / en . wikipedia . org / wiki / Multivariate _ normal _ distribution
# probability density function of a vector [ x , y ]
sx , sy - > sigma ( standard deviation )
mx , my : mue ( mean position )
rho : correlat... | x , y = xy
return offs + amp * ( 1 / ( 2 * np . pi * sx * sy * ( 1 - ( rho ** 2 ) ) ** 0.5 ) * np . exp ( ( - 1 / ( 2 * ( 1 - rho ** 2 ) ) ) * ( ( ( x - mx ) ** 2 / sx ** 2 ) + ( ( y - my ) ** 2 / sy ** 2 ) - ( ( 2 * rho * ( x - mx ) * ( y - my ) ) / ( sx * sy ) ) ) ) ) |
def org_set_member_access ( object_id , input_params = { } , always_retry = True , ** kwargs ) :
"""Invokes the / org - xxxx / setMemberAccess API method .
For more info , see : https : / / wiki . dnanexus . com / API - Specification - v1.0.0 / Organizations # API - method % 3A - % 2Forg - xxxx % 2FsetMemberAcces... | return DXHTTPRequest ( '/%s/setMemberAccess' % object_id , input_params , always_retry = always_retry , ** kwargs ) |
def del_host_downtime ( self , downtime_id ) :
"""Delete a host downtime
Format of the line that triggers function call : :
DEL _ HOST _ DOWNTIME ; < downtime _ id >
: param downtime _ id : downtime id to delete
: type downtime _ id : int
: return : None""" | broks = [ ]
for item in self . daemon . hosts :
if downtime_id in item . downtimes :
broks . extend ( item . downtimes [ downtime_id ] . cancel ( self . daemon . timeperiods , self . daemon . hosts , self . daemon . services ) )
break
else :
self . send_an_element ( make_monitoring_log ( 'warnin... |
def add_link ( self , referenced , dependent ) :
"""Add a link between two relations to the database . Both the old and
new entries must already exist in the database .
The dependent model refers _ to _ the referenced model . So , given
arguments of ( jake _ test , bar , jake _ test , foo ) :
both values ar... | referenced = _make_key ( referenced )
if ( referenced . database , referenced . schema ) not in self : # if we have not cached the referenced schema at all , we must be
# referring to a table outside our control . There ' s no need to make
# a link - we will never drop the referenced relation during a run .
logger ... |
def get_tensor_info ( self ) :
"""See base class for details .""" | # Add the additional length dimension to every shape
def add_length_dim ( tensor_info ) :
return feature_lib . TensorInfo ( shape = ( self . _length , ) + tensor_info . shape , dtype = tensor_info . dtype , )
tensor_info = super ( SequenceDict , self ) . get_tensor_info ( )
return utils . map_nested ( add_length_di... |
def deep_merge_dicts ( base , incoming ) :
"""Performs an * in - place * deep - merge of key - values from : attr : ` incoming `
into : attr : ` base ` . No attempt is made to preserve the original state of
the objects passed in as arguments .
: param dict base : The target container for the merged values . T... | for ki , vi in incoming . iteritems ( ) :
if ( ki in base and isinstance ( vi , collections . MutableMapping ) and isinstance ( base [ ki ] , collections . MutableMapping ) ) :
deep_merge_dicts ( base [ ki ] , vi )
else :
base [ ki ] = vi |
def getPersonPluginWidget ( self , name ) :
"""Return the L { PersonPluginView } for the named person .
@ type name : C { unicode }
@ param name : A value which corresponds to the I { name } attribute of an
extant L { Person } .
@ rtype : L { PersonPluginView }""" | fragment = PersonPluginView ( self . organizer . getOrganizerPlugins ( ) , self . organizer . personByName ( name ) )
fragment . setFragmentParent ( self )
return fragment |
def in_32 ( library , session , space , offset , extended = False ) :
"""Reads in an 32 - bit value from the specified memory space and offset .
Corresponds to viIn32 * function of the VISA library .
: param library : the visa library wrapped by ctypes .
: param session : Unique logical identifier to a sessio... | value_32 = ViUInt32 ( )
if extended :
ret = library . viIn32Ex ( session , space , offset , byref ( value_32 ) )
else :
ret = library . viIn32 ( session , space , offset , byref ( value_32 ) )
return value_32 . value , ret |
def _is_indirect_jump ( _ , sim_successors ) :
"""Determine if this SimIRSB has an indirect jump as its exit""" | if sim_successors . artifacts [ 'irsb_direct_next' ] : # It ' s a direct jump
return False
default_jumpkind = sim_successors . artifacts [ 'irsb_default_jumpkind' ]
if default_jumpkind not in ( 'Ijk_Call' , 'Ijk_Boring' , 'Ijk_InvalICache' ) : # It ' s something else , like a ret of a syscall . . . we don ' t care ... |
def interpret ( self ) :
"""Interprets the console on the loaded code .
RETURNS :
bool ; True if the code passes , False otherwise .""" | if not self . _interpret_lines ( self . _setup ) :
return False
success = self . _interpret_lines ( self . _code , compare_all = True )
success &= self . _interpret_lines ( self . _teardown )
return success |
def register ( cls , use_admin = True ) :
"""Register with the API a : class : ` sandman . model . Model ` class and
associated endpoint .
: param cls : User - defined class derived from : class : ` sandman . model . Model ` to
be registered with the endpoint returned by : func : ` endpoint ( ) `
: type cls... | with app . app_context ( ) :
if getattr ( current_app , 'class_references' , None ) is None :
current_app . class_references = { }
if isinstance ( cls , ( list , tuple ) ) :
for entry in cls :
register_internal_data ( entry )
entry . use_admin = use_admin
else :
... |
def unhold ( self ) :
'''Turn off any active document hold and apply any collected events .
Returns :
None''' | # no - op if we are already no holding
if self . _hold is None :
return
self . _hold = None
events = list ( self . _held_events )
self . _held_events = [ ]
for event in events :
self . _trigger_on_change ( event ) |
def release ( ctx , deploy = False , test = False , version = '' ) :
"""Tag release , run Travis - CI , and deploy to PyPI""" | if test :
run ( "python setup.py check" )
run ( "python setup.py register sdist upload --dry-run" )
if deploy :
run ( "python setup.py check" )
if version :
run ( "git checkout master" )
run ( "git tag -a v{ver} -m 'v{ver}'" . format ( ver = version ) )
run ( "git push" )
... |
def avail_sizes ( call = None ) :
'''Return a list of sizes from Azure''' | if call == 'action' :
raise SaltCloudSystemExit ( 'The avail_sizes function must be called with ' '-f or --function, or with the --list-sizes option' )
conn = get_conn ( )
data = conn . list_role_sizes ( )
ret = { }
for item in data . role_sizes :
ret [ item . name ] = object_to_dict ( item )
return ret |
def on_transmit ( self , broker ) :
"""Transmit buffered messages .""" | _vv and IOLOG . debug ( '%r.on_transmit()' , self )
if self . _output_buf :
buf = self . _output_buf . popleft ( )
written = self . transmit_side . write ( buf )
if not written :
_v and LOG . debug ( '%r.on_transmit(): disconnection detected' , self )
self . on_disconnect ( broker )
... |
def parse_email ( self , email_info ) :
"""Allows passing emails as " Example Name < example @ example . com > "
: param email _ info : Allows passing emails as
" Example Name < example @ example . com > "
: type email _ info : string""" | name , email = rfc822 . parseaddr ( email_info )
# more than likely a string was passed here instead of an email address
if "@" not in email :
name = email
email = None
if not name :
name = None
if not email :
email = None
self . name = name
self . email = email
return name , email |
def to_protobuf ( self ) :
"""Convert object to a protobuf message""" | self . _validate ( )
kwargs = { k : _convert ( getattr ( self , k ) , 'to_protobuf' ) for k in self . _get_params ( ) }
return self . _protobuf_cls ( ** kwargs ) |
def GetEntries ( self , parser_mediator , match = None , ** unused_kwargs ) :
"""Extracts relevant Apple Account entries .
Args :
parser _ mediator ( ParserMediator ) : mediates interactions between parsers
and other components , such as storage and dfvfs .
match ( Optional [ dict [ str : object ] ] ) : key... | accounts = match . get ( 'Accounts' , { } )
for name_account , account in iter ( accounts . items ( ) ) :
first_name = account . get ( 'FirstName' , '<FirstName>' )
last_name = account . get ( 'LastName' , '<LastName>' )
general_description = '{0:s} ({1:s} {2:s})' . format ( name_account , first_name , last... |
def get_pip_options ( args = [ ] , sources = None , pip_command = None ) :
"""Build a pip command from a list of sources
: param args : positional arguments passed through to the pip parser
: param sources : A list of pipfile - formatted sources , defaults to None
: param sources : list [ dict ] , optional
... | if not pip_command :
pip_command = get_pip_command ( )
if not sources :
sources = [ { "url" : "https://pypi.org/simple" , "name" : "pypi" , "verify_ssl" : True } ]
_ensure_dir ( CACHE_DIR )
pip_args = args
pip_args = prepare_pip_source_args ( sources , pip_args )
pip_options , _ = pip_command . parser . parse_a... |
def get_user_profile_photos ( self , user_id , offset = None , limit = None ) :
"""Use this method to get a list of profile pictures for a user . Returns a UserProfilePhotos object .
https : / / core . telegram . org / bots / api # getuserprofilephotos
Parameters :
: param user _ id : Unique identifier of the... | assert_type_or_raise ( user_id , int , parameter_name = "user_id" )
assert_type_or_raise ( offset , None , int , parameter_name = "offset" )
assert_type_or_raise ( limit , None , int , parameter_name = "limit" )
result = self . do ( "getUserProfilePhotos" , user_id = user_id , offset = offset , limit = limit )
if self ... |
def walk_skip_hidden ( top , onerror = None , followlinks = False ) :
"""A wrapper for ` os . walk ` that skips hidden files and directories .
This function does not have the parameter ` topdown ` from
` os . walk ` : the directories must always be recursed top - down when
using this function .
See also
o... | for root , dirs , files in os . walk ( top , topdown = True , onerror = onerror , followlinks = followlinks ) : # These lists must be updated in - place so os . walk will skip
# hidden directories
dirs [ : ] = [ d for d in dirs if not is_path_hidden ( d ) ]
files [ : ] = [ f for f in files if not is_path_hidden... |
def reversed ( self ) :
'''Returns a copy of this arc , with the direction flipped .
> > > Arc ( ( 0 , 0 ) , 1 , 0 , 360 , True ) . reversed ( )
Arc ( [ 0.000 , 0.000 ] , 1.000 , 360.000 , 0.000 , False , degrees = 360.000)
> > > Arc ( ( 0 , 0 ) , 1 , 175 , - 175 , True ) . reversed ( )
Arc ( [ 0.000 , 0.00... | return Arc ( self . center , self . radius , self . to_angle , self . from_angle , not self . direction ) |
def _set_member_vlan ( self , v , load = False ) :
"""Setter method for member _ vlan , mapped from YANG variable / topology _ group / member _ vlan ( container )
If this variable is read - only ( config : false ) in the
source YANG file , then _ set _ member _ vlan is considered as a private
method . Backend... | if hasattr ( v , "_utype" ) :
v = v . _utype ( v )
try :
t = YANGDynClass ( v , base = member_vlan . member_vlan , is_container = 'container' , presence = False , yang_name = "member-vlan" , rest_name = "member-vlan" , parent = self , path_helper = self . _path_helper , extmethods = self . _extmethods , registe... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.