signature stringlengths 29 44.1k | implementation stringlengths 0 85.2k |
|---|---|
def register_default_processors ( cls , frontend_editing = None ) :
"""Register our default request processors for the out - of - the - box
Page experience .
Since FeinCMS 1.11 was removed from core .""" | super ( Page , cls ) . register_default_processors ( )
if frontend_editing :
cls . register_request_processor ( edit_processors . frontendediting_request_processor , key = 'frontend_editing' )
cls . register_response_processor ( edit_processors . frontendediting_response_processor , key = 'frontend_editing' ) |
def Email ( self , From , To , Cc = None , Bcc = None , Subject = None , Tag = None , HtmlBody = None , TextBody = None , Metadata = None , ReplyTo = None , Headers = None , TrackOpens = None , TrackLinks = "None" , Attachments = None , ) :
"""Constructs : py : class : ` Email ` instance .
: return : : py : class... | return Email ( manager = self , From = From , To = To , Cc = Cc , Bcc = Bcc , Subject = Subject , Tag = Tag , HtmlBody = HtmlBody , TextBody = TextBody , Metadata = Metadata , ReplyTo = ReplyTo , Headers = Headers , TrackOpens = TrackOpens , TrackLinks = TrackLinks , Attachments = Attachments , ) |
def _R2deriv ( self , R , z , phi = 0. , t = 0. ) :
"""NAME :
_ R2deriv
PURPOSE :
evaluate the second radial derivative for this potential
INPUT :
R - Galactocentric cylindrical radius
z - vertical height
phi - azimuth
t - time
OUTPUT :
the second radial derivative
HISTORY :
2015-06-15 - Wri... | return ( self . _b2 - 2. * R ** 2. + z ** 2. ) * ( R ** 2. + z ** 2. + self . _b2 ) ** - 2.5 |
def check_whiteboard_status ( self , whiteboard ) :
"""Extracts stockwell text from a bug ' s whiteboard status to
determine whether it matches specified stockwell text ;
returns a boolean .""" | stockwell_text = re . search ( r'\[stockwell (.+?)\]' , whiteboard )
if stockwell_text is not None :
text = stockwell_text . group ( 1 ) . split ( ':' ) [ 0 ]
if text == 'fixed' or text == 'disable-recommended' or text == 'infra' or text == 'disabled' :
return True
return False |
def xlim ( self , low , high ) :
"""Set xaxis limits
Parameters
low : number
high : number
Returns
Chart""" | self . chart [ 'xAxis' ] [ 0 ] [ 'min' ] = low
self . chart [ 'xAxis' ] [ 0 ] [ 'max' ] = high
return self |
def report_privilege_information ( ) :
"Report all privilege information assigned to the current process ." | privileges = get_privilege_information ( )
print ( "found {0} privileges" . format ( privileges . count ) )
tuple ( map ( print , privileges ) ) |
def get_raw ( self , name = None ) :
'''Shortcut for getting a : class : ` ~ statsd . raw . Raw ` instance
: keyword name : See : func : ` ~ statsd . client . Client . get _ client `
: type name : str''' | return self . get_client ( name = name , class_ = statsd . Raw ) |
def create ( input_block : ModelFactory , rnn_type : str , output_dim : int , rnn_layers : typing . List [ int ] , rnn_dropout : float = 0.0 , bidirectional : bool = False , linear_layers : typing . List [ int ] = None , linear_dropout : float = 0.0 ) :
"""Vel factory function""" | if linear_layers is None :
linear_layers = [ ]
def instantiate ( ** _ ) :
return MultilayerRnnSequenceClassification ( input_block = input_block . instantiate ( ) , rnn_type = rnn_type , output_dim = output_dim , rnn_layers = rnn_layers , rnn_dropout = rnn_dropout , bidirectional = bidirectional , linear_layers... |
def shortlex ( start , other , excludestart = False ) :
"""Yield all unions of start with other in shortlex order .
> > > [ ' { : 03b } ' . format ( s ) for s in shortlex ( 0 , [ 0b100 , 0b010 , 0b001 ] ) ]
[ ' 000 ' , ' 100 ' , ' 010 ' , ' 001 ' , ' 110 ' , ' 101 ' , ' 011 ' , ' 111 ' ]
> > > ' , ' . join ( ... | if not excludestart :
yield start
queue = collections . deque ( [ ( start , other ) ] )
while queue :
current , other = queue . popleft ( )
while other :
first , other = other [ 0 ] , other [ 1 : ]
result = current | first
yield result
if other :
queue . append ( ... |
def _strftime ( expr , date_format ) :
"""Return formatted strings specified by date _ format ,
which supports the same string format as the python standard library .
Details of the string format can be found in python string format doc
: param expr :
: param date _ format : date format string ( e . g . “ %... | return datetime_op ( expr , Strftime , output_type = types . string , _date_format = date_format ) |
def json_output ( cls , cs , score_dict , output_filename , ds_loc , limit , output_type = 'json' ) :
'''Generates JSON output for the ocmpliance score ( s )
@ param cs Compliance Checker Suite
@ param score _ groups List of results
@ param output _ filename The file path to output to
@ param ds _ loc List ... | results = { }
# json output keys out at the top level by
if len ( score_dict ) > 1 and output_type != 'json_new' :
raise ValueError ( "output_type must be set to 'json_new' if outputting multiple datasets to a single json file or stdout" )
if output_type == 'json' :
for ds , score_groups in six . iteritems ( sc... |
def getall ( self , key , type = None ) :
"""Return a list of values for the given key .
If ` type ` is not None , all values will be converted by calling ` type `
with the value as argument . if type ( ) raises ` ValueError ` , the value
will not appear in the result list .""" | values = [ ]
for k , v in self . _items :
if k == key :
if type is not None :
try :
values . append ( type ( v ) )
except ValueError :
pass
else :
values . append ( v )
return values |
def start ( self ) :
"""Download files using wget or other downloader .
Optional curl , aria2c and httpie""" | dwn_count = 1
self . _directory_prefix ( )
for dwn in self . url : # get file name from url and fix passing char ' + '
self . file_name = dwn . split ( "/" ) [ - 1 ] . replace ( "%2B" , "+" )
if dwn . startswith ( "file:///" ) :
source_dir = dwn [ 7 : - 7 ] . replace ( slack_ver ( ) , "" )
self ... |
def write_html ( self , html_dir = '/tmp' , include_osd = False , osd_width = 500 , osd_height = 500 ) :
"""Write HTML test page using OpenSeadragon for the tiles generated .
Assumes that the generate ( . . ) method has already been called to set up
identifier etc . Parameters :
html _ dir - output directory ... | osd_config = self . get_osd_config ( self . osd_version )
osd_base = osd_config [ 'base' ]
osd_dir = osd_config [ 'dir' ]
# relative to base
osd_js = os . path . join ( osd_dir , osd_config [ 'js' ] )
osd_images = os . path . join ( osd_dir , osd_config [ 'images' ] )
if ( os . path . isdir ( html_dir ) ) : # Exists , ... |
def get_next_types ( self , n = None ) :
"""Gets the next set of ` ` Types ` ` in this list .
The specified amount must be less than or equal to the return
from ` ` available ( ) ` ` .
arg : n ( cardinal ) : the number of ` ` Type ` ` elements requested
which must be less than or equal to ` ` available ( ) ... | if n > self . available ( ) : # ! ! ! This is not quite as specified ( see method docs ) ! ! !
raise IllegalState ( 'not enough elements available in this list' )
else :
next_list = [ ]
i = 0
while i < n :
try :
next_list . append ( next ( self ) )
except : # Need to specify ... |
def load_array ( path , group = None ) :
"""Load an Array from a . hdf , . txt or . npy file . The
default data types will be double precision floating point .
Parameters
path : string
source file path . Must end with either . npy or . txt .
group : string
Additional name for internal storage use . Ex .... | ext = _os . path . splitext ( path ) [ 1 ]
if ext == '.npy' :
data = _numpy . load ( path )
elif ext == '.txt' :
data = _numpy . loadtxt ( path )
elif ext == '.hdf' :
key = 'data' if group is None else group
return Array ( h5py . File ( path ) [ key ] )
else :
raise ValueError ( 'Path must end with ... |
def properties ( self ) :
"""Morphosemantic property mapping .
Unlike : attr : ` sortinfo ` , this does not include ` cvarsort ` .""" | d = dict ( self . sortinfo )
if CVARSORT in d :
del d [ CVARSORT ]
return d |
def processInput ( self , dataAveraging = False , windowSize = None ) :
"""# TODO : docstring
: param dataAveraging : # TODO : docstring
: param windowSize : # TODO : docstring""" | self . dependentVar = numpy . array ( self . dependentVarInput , dtype = numpy . float64 )
self . independentVar = numpy . array ( self . independentVarInput , dtype = numpy . float64 )
sortMask = self . independentVar . argsort ( )
self . dependentVar = self . dependentVar [ sortMask ]
self . independentVar = self . i... |
def input_ratio ( self , name , choices , labels , multi_line = False ) :
"""{ % for value , label in [ ( ' choice1 ' , ' 选项1 ' ) , ( ' choice2 ' , ' 选项2 ' ) ] % }
{ % if ratio = = value % }
{ % set checked = " checked " % }
{ % else % }
{ % set checked = " " % }
{ % endif % }
< input type = " radio " n... | if len ( choices ) != len ( labels ) :
raise ValueError ( "The size of 'choices' and 'labels' doesn't match!" )
choice_label = list ( zip ( choices , labels ) )
lines = list ( )
lines . append ( '{%% for value, label in %s %%}' % repr ( choice_label ) )
lines . append ( self . tab + '{%% if %s == value %%}' % name ... |
def copy ( self ) :
"""Return a new : class : ` FontOptions ` with the same values .""" | cls = type ( self )
other = object . __new__ ( cls )
cls . _init_pointer ( other , cairo . cairo_font_options_copy ( self . _pointer ) )
return other |
def _handleCtrlZ ( self ) :
"""Handler for CTRL + Z keypresses""" | if self . _typingSms :
self . serial . write ( '' . join ( self . inputBuffer ) )
self . serial . write ( self . CTRL_Z_CHARACTER )
self . _typingSms = False
self . inputBuffer = [ ]
self . cursorPos = 0
sys . stdout . write ( '\n' )
self . _refreshInputPrompt ( ) |
def _parse_properties ( self , properties ) :
"""Make list of properties into 2 things :
(1 ) dictionary of { ' aliased - field ' : 1 , . . . } for a mongodb query eg . { ' ' }
(2 ) dictionary , keyed by aliased field , for display""" | props = { }
# TODO : clean up prop _ dict ?
prop_dict = OrderedDict ( )
# We use a dict instead of list to provide for a richer syntax
for p in properties :
if p in self . aliases :
if isinstance ( properties , dict ) :
props [ self . aliases [ p ] ] = properties [ p ]
else :
... |
def transformer ( self , instance_count , instance_type , strategy = None , assemble_with = None , output_path = None , output_kms_key = None , accept = None , env = None , max_concurrent_transforms = None , max_payload = None , tags = None , role = None , model_server_workers = None , volume_kms_key = None ) :
"""... | role = role or self . role
if self . latest_training_job is not None :
model = self . create_model ( role = role , model_server_workers = model_server_workers )
container_def = model . prepare_container_def ( instance_type )
model_name = model . name or name_from_image ( container_def [ 'Image' ] )
vpc_... |
def _datetime_to_tuple ( dt_dict ) :
"""datetime . datetime components from dictionary to tuple .
Example
dt _ dict = { ' year ' : ' 2014 ' , ' month ' : ' 07 ' , ' day ' : ' 23 ' ,
' hour ' : ' 13 ' , ' minute ' : ' 12 ' , ' second ' : ' 45 ' , ' microsecond ' : ' 321 ' }
_ datetime _ to _ tuple ( dt _ dic... | year , month , day = _date_to_tuple ( dt_dict )
hour , minute , second , microsecond = _time_to_tuple ( dt_dict )
return year , month , day , hour , minute , second , microsecond |
def plot ( self , value = None , pixel = None ) :
"""Plot the ROI""" | # DEPRECATED
import ugali . utils . plotting
map_roi = np . array ( hp . UNSEEN * np . ones ( hp . nside2npix ( self . config . params [ 'coords' ] [ 'nside_pixel' ] ) ) )
if value is None : # map _ roi [ self . pixels ] = ugali . utils . projector . angsep ( self . lon , self . lat , self . centers _ lon , self . cent... |
def prune ( self , vault_client ) :
"""Will remove any mount point which is not actually defined
in this context .""" | existing = getattr ( vault_client , SecretBackend . list_fun ) ( ) [ 'data' ] . items ( )
for mount_name , _values in existing : # ignore system paths and cubbyhole
mount_path = normalize_vault_path ( mount_name )
if mount_path . startswith ( 'sys' ) or mount_path == 'cubbyhole' :
continue
exists = ... |
def _delete_dynamic_versions ( self ) :
"""Call the ` delete ` method of all dynamic versions of the current field
found in the inventory then clean the inventory .""" | if self . dynamic_version_of :
raise ImplementationError ( u'"_delete_dynamic_versions" can only be ' u'executed on the base field' )
inventory = self . _inventory
for dynamic_part in inventory . smembers ( ) :
name = self . get_name_for ( dynamic_part )
# create the field
new_field = self . _create_dyn... |
def calculate_width_content ( width , border = False , margin = None , margin_left = None , margin_right = None , padding = None , padding_left = None , padding_right = None ) :
"""Calculate actual widget content width based on given margins and paddings .""" | if margin_left is None :
margin_left = margin
if margin_right is None :
margin_right = margin
if margin_left is not None :
width -= int ( margin_left )
if margin_right is not None :
width -= int ( margin_right )
if padding_left is None :
padding_left = padding
if padding_right is None :
padding_... |
def get_default_compartment ( model ) :
"""Return what the default compartment should be set to .
If some compounds have no compartment , unique compartment
name is returned to avoid collisions .""" | default_compartment = 'c'
default_key = set ( )
for reaction in model . reactions :
equation = reaction . equation
if equation is None :
continue
for compound , _ in equation . compounds :
default_key . add ( compound . compartment )
if None in default_key and default_compartment in default_... |
def engine_from_environment ( ) -> Engine :
"""Returns an Engine instance configured using environment variables .
If the environment variables are set , but incorrect , an authentication
failure will occur when attempting to run jobs on the engine .
Required Environment Variables :
QUANTUM _ ENGINE _ PROJE... | api_key = os . environ . get ( ENV_API_KEY )
if not api_key :
raise EnvironmentError ( 'Environment variable {} is not set.' . format ( ENV_API_KEY ) )
default_project_id = os . environ . get ( ENV_DEFAULT_PROJECT_ID )
return Engine ( api_key = api_key , default_project_id = default_project_id ) |
def update_rating ( self , postid ) :
'''only the used who logged in would voting .''' | post_data = self . get_post_data ( )
rating = float ( post_data [ 'rating' ] )
postinfo = MPost . get_by_uid ( postid )
if postinfo and self . userinfo :
MRating . update ( postinfo . uid , self . userinfo . uid , rating = rating )
self . update_post ( postid )
else :
return False |
def GetEntries ( self , parser_mediator , match = None , ** unused_kwargs ) :
"""Extracts relevant user timestamp entries .
Args :
parser _ mediator ( ParserMediator ) : mediates interactions between parsers
and other components , such as storage and dfvfs .
match ( Optional [ dict [ str : object ] ] ) : ke... | if 'name' not in match or 'uid' not in match :
return
account = match [ 'name' ] [ 0 ]
uid = match [ 'uid' ] [ 0 ]
for policy in match . get ( 'passwordpolicyoptions' , [ ] ) :
try :
xml_policy = ElementTree . fromstring ( policy )
except ( ElementTree . ParseError , LookupError ) as exception :
... |
def deployments ( self ) -> Union [ "Deployments" , Dict [ None , None ] ] :
"""Returns a ` ` Deployments ` ` object containing all the deployment data and contract
factories of a ` ` Package ` ` ' s ` contract _ types ` . Automatically filters deployments
to only expose those available on the current ` ` Packa... | if not check_for_deployments ( self . manifest ) :
return { }
all_blockchain_uris = self . manifest [ "deployments" ] . keys ( )
matching_uri = validate_single_matching_uri ( all_blockchain_uris , self . w3 )
deployments = self . manifest [ "deployments" ] [ matching_uri ]
all_contract_factories = { deployment_data... |
def add_mobile_gateway ( self , gateway ) :
"""Add a mobile VPN gateway to this policy VPN .
Example of adding or removing a mobile VPN gateway : :
policy _ vpn = PolicyVPN ( ' myvpn ' )
policy _ vpn . open ( )
policy _ vpn . add _ mobile _ vpn _ gateway ( ExternalGateway ( ' extgw3 ' ) )
for mobile _ gat... | try :
gateway = gateway . vpn . internal_gateway . href
# Engine
except AttributeError :
gateway = element_resolver ( gateway )
# External Gateway
self . make_request ( PolicyCommandFailed , method = 'create' , resource = 'mobile_gateway_node' , json = { 'gateway' : gateway , 'node_usage' : 'mobile' } ) |
def to_tree ( self ) :
"""returns a TreeLib tree""" | tree = TreeLibTree ( )
for node in self :
tree . create_node ( node , node . node_id , parent = node . parent )
return tree |
def registry_storage ( cls ) :
"""Get registry storage
: return : WTaskRegistryBase""" | if cls . __registry_storage__ is None :
raise ValueError ( '__registry_storage__ must be defined' )
if isinstance ( cls . __registry_storage__ , WTaskRegistryBase ) is False :
raise TypeError ( "Property '__registry_storage__' is invalid (must derived from WTaskRegistryBase)" )
return cls . __registry_storage__ |
def add_doc ( self , doc , index_update = True , label_guesser_update = True ) :
"""Add a document to the index""" | if not self . index_writer and index_update :
self . index_writer = self . index . writer ( )
if not self . label_guesser_updater and label_guesser_update :
self . label_guesser_updater = self . label_guesser . get_updater ( )
logger . info ( "Indexing new doc: %s" % doc )
if index_update :
self . _update_d... |
def replace ( text , old , new , count = None , strip = False ) :
'''Replace an ` ` old ` ` subset of ` ` text ` ` with ` ` new ` ` .
` ` old ` ` type may be either a string or regular expression .
If ` ` strip ` ` , remove all leading / trailing whitespace .
If ` ` count ` ` , replace the specified number of... | if is_string ( old ) :
text = text . replace ( old , new , - 1 if count is None else count )
else :
text = old . sub ( new , text , 0 if count is None else count )
if strip :
text = text . strip ( None if strip == True else strip )
return text |
def _remove_document ( self , gh_user , doc_id , parent_sha , author , commit_msg = None ) :
"""Remove a document
Remove a document on the given branch and attribute the commit to author .
Returns the SHA of the commit on branch .""" | # _ LOG . debug ( " @ @ @ @ @ GitActionBase . _ remove _ document , doc _ id = { } " . format ( doc _ id ) )
doc_filepath = self . path_for_doc ( doc_id )
# _ LOG . debug ( " @ @ @ @ @ GitActionBase . _ remove _ document , doc _ filepath = { } " . format ( doc _ filepath ) )
branch = self . create_or_checkout_branch ( ... |
def _sanity_check_all_marked_locations_are_registered ( ir_blocks , query_metadata_table ) :
"""Assert that all locations in MarkLocation blocks have registered and valid metadata .""" | # Grab all the registered locations , then make sure that :
# - Any location that appears in a MarkLocation block is also registered .
# - There are no registered locations that do not appear in a MarkLocation block .
registered_locations = { location for location , _ in query_metadata_table . registered_locations }
ir... |
def _find_mime_parameters ( tokenlist , value ) :
"""Do our best to find the parameters in an invalid MIME header""" | while value and value [ 0 ] != ';' :
if value [ 0 ] in PHRASE_ENDS :
tokenlist . append ( ValueTerminal ( value [ 0 ] , 'misplaced-special' ) )
value = value [ 1 : ]
else :
token , value = get_phrase ( value )
tokenlist . append ( token )
if not value :
return
tokenlist . app... |
def ddebug ( msg , err = None ) : # pragma : no cover
"""err can be an instance of sys . exc _ info ( ) - - which is the latest traceback
info""" | import os
if err :
err = '' . join ( traceback . format_exception ( * err ) )
else :
err = ''
sys . __stdout__ . write ( "({}) {} {}" . format ( os . getpid ( ) , msg , err ) + '\n' )
sys . __stdout__ . flush ( ) |
def get_high_water_mark ( self , mark_type , obstory_name = None ) :
"""Retrieves the high water mark for a given obstory , defaulting to the current installation ID
: param string mark _ type :
The type of high water mark to set
: param string obstory _ name :
The obstory ID to check for , or the default i... | if obstory_name is None :
obstory_name = self . obstory_name
obstory = self . get_obstory_from_name ( obstory_name )
key_id = self . get_hwm_key_id ( mark_type )
self . con . execute ( 'SELECT time FROM archive_highWaterMarks WHERE markType=%s AND observatoryId=%s' , ( key_id , obstory [ 'uid' ] ) )
results = self ... |
def xslt_transformation ( xml , template ) :
"""Transform ` xml ` using XSLT ` template ` .
Args :
xml ( str ) : Filename or XML string . Don ' t use ` ` \\ n ` ` in case of
filename .
template ( str ) : Filename or XML string . Don ' t use ` ` \\ n ` ` in case of
filename .
Returns :
str : Transforme... | transformer = ET . XSLT ( _read_template ( template ) )
newdom = transformer ( _read_marcxml ( xml ) )
return ET . tostring ( newdom , pretty_print = True , encoding = "utf-8" ) |
def iter_links ( self ) : # type : ( ) - > Iterable [ Link ]
"""Yields all links in the page""" | document = html5lib . parse ( self . content , transport_encoding = _get_encoding_from_headers ( self . headers ) , namespaceHTMLElements = False , )
base_url = _determine_base_url ( document , self . url )
for anchor in document . findall ( ".//a" ) :
if anchor . get ( "href" ) :
href = anchor . get ( "hre... |
def table_to_intermediary ( table ) :
"""Transform an SQLAlchemy Table object to it ' s intermediary representation .""" | return Table ( name = table . fullname , columns = [ column_to_intermediary ( col ) for col in table . c . _data . values ( ) ] ) |
def sqrt ( self , val , flag ) :
"""calculate the square root modulus p""" | if val . iszero ( ) :
return val
sw = self . p % 8
if sw == 3 or sw == 7 :
res = val ** ( ( self . p + 1 ) / 4 )
elif sw == 5 :
x = val ** ( ( self . p + 1 ) / 4 )
if x == 1 :
res = val ** ( ( self . p + 3 ) / 8 )
else :
res = ( 4 * val ) ** ( ( self . p - 5 ) / 8 ) * 2 * val
else :
... |
def extendedMeasurementOrder ( ) :
"""EXTENDED MEASUREMENT ORDER Section 9.1.51""" | a = L2PseudoLength ( l2pLength = 0x12 )
b = TpPd ( pd = 0x6 )
c = MessageType ( mesType = 0x37 )
# 00110111
d = ExtendedMeasurementFrequencyList ( )
packet = a / b / c / d
return packet |
def _get_view_results ( self , view ) :
"""Get the results based on the view""" | if view == TREE_VIEW :
result = self . tree
else :
result = TextResult ( tree_results = self . tree )
result . cleanup ( )
# clean up text - style result dictionary
return result |
def data ( self ) :
"""Returns the entire configuration as a dict .
Note that this will force all plugins to be loaded .""" | d = { }
for key in self . _data :
if key == "plugins" :
d [ key ] = self . plugins . data ( )
else :
try :
d [ key ] = getattr ( self , key )
except AttributeError :
pass
# unknown key , just leave it unchanged
return d |
def write_loudest_events ( page , bins , onsource = False ) :
"""Write injection chisq plots to markup . page object page""" | th = [ '' ] + [ 'Mchirp %s - %s' % tuple ( bin ) for bin in bins ]
td = [ ]
plots = [ 'BestNR' , 'SNR' ]
if onsource :
trial = 'ONSOURCE'
else :
trial = 'OFFTRIAL_1'
for pTag in plots :
row = pTag . lower ( )
d = [ pTag ]
for bin in bins :
b = '%s_%s' % tuple ( bin )
plot = markup . ... |
def create_customer ( self , full_name , email ) :
"""Creating customer user
: param full _ name : str
: param email : str
: return : New customer""" | log . warning ( 'Creating customer...' )
data = { 'fullName' : full_name , 'email' : email }
return self . post ( 'rest/servicedeskapi/customer' , headers = self . experimental_headers , data = data ) |
def _asarray_tuplesafe ( values ) :
"""Convert values into a numpy array of at most 1 - dimension , while preserving
tuples .
Adapted from pandas . core . common . _ asarray _ tuplesafe""" | if isinstance ( values , tuple ) :
result = utils . to_0d_object_array ( values )
else :
result = np . asarray ( values )
if result . ndim == 2 :
result = np . empty ( len ( values ) , dtype = object )
result [ : ] = values
return result |
def _parse_join ( self , tokens ) :
"""Parses a join .
Join : : = ' join ' ' ( ' SuperRange [ ' , ' SuperRange ] ' ) '""" | children = [ ]
tokens . pop ( 0 )
# Pop ' join '
tokens . pop ( 0 )
# Pop ' ( '
children . append ( self . _parse_nested_interval ( tokens ) )
while tokens [ 0 ] == ',' :
tokens . pop ( 0 )
children . append ( self . _parse_nested_interval ( tokens ) )
tokens . pop ( 0 )
# Pop ' ) '
chromosome , strand = next (... |
def parse_component_requirement ( self , node ) :
"""Parses < ComponentRequirement >
@ param node : Node containing the < ComponentRequirement > element
@ type node : xml . etree . Element""" | if 'name' in node . lattrib :
name = node . lattrib [ 'name' ]
else :
self . raise_error ( '<ComponentRequirement> must specify a name' )
self . current_component_type . add_component_requirement ( ComponentRequirement ( name ) ) |
def export_to_dict ( self , recursive = True , include_parent_ref = False , include_defaults = False ) :
"""Export obj to dictionary""" | cls = self . __class__
parent_excludes = { }
if recursive and not include_parent_ref :
parent_ref = cls . __mapper__ . relationships . get ( cls . export_parent )
if parent_ref :
parent_excludes = { c . name for c in parent_ref . local_columns }
dict_rep = { c . name : getattr ( self , c . name ) for c ... |
def parse_coaches ( self ) :
"""Parse the home and away coaches
: returns : ` ` self ` ` on success , ` ` None ` ` otherwise""" | lx_doc = self . html_doc ( )
tr = lx_doc . xpath ( '//tr[@id="HeadCoaches"]' ) [ 0 ]
for i , td in enumerate ( tr ) :
txt = td . xpath ( './/text()' )
txt = ex_junk ( txt , [ '\n' , '\r' ] )
team = 'away' if i == 0 else 'home'
self . coaches [ team ] = txt [ 0 ]
return self if self . coaches else None |
def cdx_load ( sources , query , process = True ) :
"""merge text CDX lines from sources , return an iterator for
filtered and access - checked sequence of CDX objects .
: param sources : iterable for text CDX sources .
: param process : bool , perform processing sorting / filtering / grouping ops""" | cdx_iter = create_merged_cdx_gen ( sources , query )
# page count is a special case , no further processing
if query . page_count :
return cdx_iter
cdx_iter = make_obj_iter ( cdx_iter , query )
if process and not query . secondary_index_only :
cdx_iter = process_cdx ( cdx_iter , query )
custom_ops = query . cus... |
def _set_keychain ( self , v , load = False ) :
"""Setter method for keychain , mapped from YANG variable / keychain ( list )
If this variable is read - only ( config : false ) in the
source YANG file , then _ set _ keychain is considered as a private
method . Backends looking to populate this variable should... | if hasattr ( v , "_utype" ) :
v = v . _utype ( v )
try :
t = YANGDynClass ( v , base = YANGListType ( "name_of_keychain" , keychain . keychain , yang_name = "keychain" , rest_name = "keychain" , parent = self , is_container = 'list' , user_ordered = False , path_helper = self . _path_helper , yang_keys = 'name-... |
def widont ( value , count = 1 ) :
"""Add an HTML non - breaking space between the final two words of the string to
avoid " widowed " words .
Examples :
> > > print ( widont ( ' Test me out ' ) )
Test me & nbsp ; out
> > > print ( " ' " , widont ( ' It works with trailing spaces too ' ) , " ' " )
' It w... | def replace ( matchobj ) :
return force_text ( ' %s' % matchobj . group ( 1 ) )
for i in range ( count ) :
value = re_widont . sub ( replace , force_text ( value ) )
return value |
def count ( self ) :
"""Registered task count
: return : int""" | result = 0
for tasks in self . __registry . values ( ) :
result += len ( tasks )
return result |
def upload_string ( to_upload , media_type = None , keep_open = False , wait_on_close = False , ** kwargs ) :
""": param to _ upload : String to upload into a file
: type to _ upload : string
: param media _ type : Internet Media Type
: type media _ type : string
: param keep _ open : If False , closes the ... | # Use ' a ' mode because we will be responsible for closing the file
# ourselves later ( if requested ) .
handler = new_dxfile ( media_type = media_type , mode = 'a' , ** kwargs )
# For subsequent API calls , don ' t supply the dataobject metadata
# parameters that are only needed at creation time .
_ , remaining_kwarg... |
def FromBinary ( cls , record_data , record_count = 1 ) :
"""Create an UpdateRecord subclass from binary record data .
This should be called with a binary record blob ( NOT including the
record type header ) and it will decode it into a SetConstantRecord .
Args :
record _ data ( bytearray ) : The raw record... | _cmd , address , _resp_length , payload = cls . _parse_rpc_info ( record_data )
try :
value , encoded_stream = struct . unpack ( "<LH" , payload )
stream = DataStream . FromEncoded ( encoded_stream )
except ValueError :
raise ArgumentError ( "Could not parse set_constant payload" , payload = payload )
retur... |
def overlap ( self , x , j = None ) :
"""Checks how many ellipsoid ( s ) ` x ` falls within , skipping the ` j ` - th
ellipsoid .""" | q = len ( self . within ( x , j = j ) )
return q |
def contour_to_geojson ( contour , geojson_filepath = None , min_angle_deg = None , ndigits = 5 , unit = '' , stroke_width = 1 , geojson_properties = None , strdump = False , serialize = True ) :
"""Transform matplotlib . contour to geojson .""" | collections = contour . collections
contour_index = 0
line_features = [ ]
for collection in collections :
color = collection . get_edgecolor ( )
for path in collection . get_paths ( ) :
v = path . vertices
if len ( v ) < 3 :
continue
coordinates = keep_high_angle ( v , min_an... |
def generate_corpus ( self , text ) :
"""Given a text string , returns a list of lists ; that is , a list of
" sentences , " each of which is a list of words . Before splitting into
words , the sentences are filtered through ` self . test _ sentence _ input `""" | if isinstance ( text , str ) :
sentences = self . sentence_split ( text )
else :
sentences = [ ]
for line in text :
sentences += self . sentence_split ( line )
passing = filter ( self . test_sentence_input , sentences )
runs = map ( self . word_split , passing )
return runs |
def register ( linter ) :
"""Required method to auto register this checker .""" | linter . register_checker ( NewDbFieldWithDefaultChecker ( linter ) )
if not compat . LOAD_CONFIGURATION_SUPPORTED :
load_configuration ( linter ) |
def dbStore ( self , typ , py_value ) :
"""Prepares to store this column for the a particular backend database .
: param backend : < orb . Database >
: param py _ value : < variant >
: return : < variant >""" | if isinstance ( py_value , datetime . datetime ) : # ensure we have some timezone information before converting to UTC time
if py_value . tzinfo is None : # match the server information
tz = pytz . timezone ( orb . system . settings ( ) . server_timezone )
py_value = tz . localize ( py_value )
r... |
def set ( self , instance , value , ** kwargs ) :
"""writes the value to the same named field on the proxy object""" | # Retrieve the proxy object
proxy_object = self . get_proxy ( instance )
# Return None if we could not find a proxied object , e . g . through
# the proxy expression ' context . getSample ( ) ' on an AR
if not proxy_object :
logger . debug ( "Expression '{}' did not return a valid Proxy Object on {}" . format ( sel... |
def _generate_notebook_header ( notebook_object , notebook_type , notebook_title = "Notebook Title" , tags = "tags" , difficulty_stars = 1 , notebook_description = "Notebook Description" ) :
"""Internal function that is used for generation of the generic notebooks header .
Parameters
notebook _ object : noteboo... | # = = = = = Creation of Header = = = = =
header_temp = HEADER_ALL_CATEGORIES . replace ( "header_image_color_i" , "header_image_color_" + str ( NOTEBOOK_KEYS [ notebook_type ] ) )
header_temp = header_temp . replace ( "header_image_i" , "header_image_" + str ( NOTEBOOK_KEYS [ notebook_type ] ) )
header_temp = header_te... |
def process_tessellate ( elem , update_delta , delta , ** kwargs ) :
"""Tessellates surfaces .
. . note : : Helper function required for ` ` multiprocessing ` `
: param elem : surface
: type elem : abstract . Surface
: param update _ delta : flag to control evaluation delta updates
: type update _ delta :... | if update_delta :
elem . delta = delta
elem . evaluate ( )
elem . tessellate ( ** kwargs )
return elem |
def flatten_excel ( path = '.' , ext = 'xlsx' , sheetname = 0 , skiprows = None , header = 0 , date_parser = parse_date , verbosity = 0 , output_ext = None ) :
"""Load all Excel files in the given path , write . flat . csv files , return ` DataFrame ` dict
Arguments :
path ( str ) : file or folder to retrieve C... | date_parser = date_parser or ( lambda x : x )
dotted_ext , dotted_output_ext = None , None
if ext != None and output_ext != None :
dotted_ext = ( '' if ext . startswith ( '.' ) else '.' ) + ext
dotted_output_ext = ( '' if output_ext . startswith ( '.' ) else '.' ) + output_ext
table = { }
for file_properties in... |
def attributes ( self ) -> Sequence [ bytes ] :
"""The mailbox attributes that should be returned with the mailbox
in a ` ` LIST ` ` response , e . g . ` ` \\ Noselect ` ` .
See Also :
` RFC 3348 < https : / / tools . ietf . org / html / rfc3348 > ` _""" | ret : List [ bytes ] = [ ]
if not self . exists :
ret . append ( b'Noselect' )
if self . has_children :
ret . append ( b'HasChildren' )
else :
ret . append ( b'HasNoChildren' )
if self . marked is True :
ret . append ( b'Marked' )
elif self . marked is False :
ret . append ( b'Unmarked' )
return ret |
def GetFrequencyStartTimes ( self ) :
"""Return a list of start time for each headway - based run .
Returns :
a sorted list of seconds since midnight , the start time of each run . If
this trip doesn ' t have headways returns an empty list .""" | start_times = [ ]
# for each headway period of the trip
for freq_tuple in self . GetFrequencyTuples ( ) :
( start_secs , end_secs , headway_secs ) = freq_tuple [ 0 : 3 ]
# reset run secs to the start of the timeframe
run_secs = start_secs
while run_secs < end_secs :
start_times . append ( run_se... |
def atan2 ( y , x , context = None ) :
"""Return ` ` atan ( y / x ) ` ` with the appropriate choice of function branch .
If ` ` x > 0 ` ` , then ` ` atan2 ( y , x ) ` ` is mathematically equivalent to ` ` atan ( y
/ x ) ` ` . If ` ` x < 0 ` ` and ` ` y > 0 ` ` , ` ` atan ( y , x ) ` ` is equivalent to ` ` π +
... | return _apply_function_in_current_context ( BigFloat , mpfr . mpfr_atan2 , ( BigFloat . _implicit_convert ( y ) , BigFloat . _implicit_convert ( x ) , ) , context , ) |
def _replace_tables ( self , soup , v_separator = ' | ' , h_separator = '-' ) :
"""Replaces < table > elements with its ASCII equivalent .""" | tables = self . _parse_tables ( soup )
v_sep_len = len ( v_separator )
v_left_sep = v_separator . lstrip ( )
for t in tables :
html = ''
trs = t [ 'trs' ]
h_length = 1 + ( v_sep_len * len ( t [ 'col_width' ] ) ) + t [ 'width' ]
head_foot = ( h_separator * h_length ) + "\n"
html += head_foot
for ... |
def get_new_tag ( self , api_tag ) :
"""Instantiate a new Tag from api data .
: param api _ tag : the api data for the Tag
: return : the new Tag""" | return Tag ( site_id = self . site_id , wp_id = api_tag [ "ID" ] , ** self . api_object_data ( "tag" , api_tag ) ) |
def has_layer ( fcollection ) :
"""Returns true for a multi - layer dict of FeatureCollections .""" | for val in six . viewvalues ( fcollection ) :
if has_features ( val ) :
return True
return False |
def safeMkdir ( p , permissions = permissions755 ) :
'''Wrapper around os . mkdir which does not raise an error if the directory exists .''' | try :
os . mkdir ( p )
except OSError :
pass
os . chmod ( p , permissions ) |
def execute_commands ( self , mapping , * args , ** kwargs ) :
"""Concurrently executes a sequence of commands on a Redis cluster that
are associated with a routing key , returning a new mapping where
values are a list of results that correspond to the command in the same
position . For example : :
> > > cl... | def is_script_command ( command ) :
return isinstance ( command [ 0 ] , Script )
def check_script_load_result ( script , result ) :
if script . sha != result :
raise AssertionError ( 'Hash mismatch loading {!r}: expected {!r}, got {!r}' . format ( script , script . sha , result , ) )
# Run through all t... |
def _notify ( self , topic , ** kwargs ) :
"""Invokes callbacks for an event topic .
@ param topic : String event name
@ type topic : str
@ param kwargs : Values associated with the event
@ type kwargs : dict""" | for cb in self . _connects . get ( topic , [ ] ) :
try :
cb ( ** kwargs )
except Exception :
if self . _debug :
traceback . print_exc ( ) |
def _add_id_or_name ( flat_path , element_pb , empty_allowed ) :
"""Add the ID or name from an element to a list .
: type flat _ path : list
: param flat _ path : List of accumulated path parts .
: type element _ pb : : class : ` . _ app _ engine _ key _ pb2 . Path . Element `
: param element _ pb : The ele... | id_ = element_pb . id
name = element_pb . name
# NOTE : Below 0 and the empty string are the " null " values for their
# respective types , indicating that the value is unset .
if id_ == 0 :
if name == u"" :
if not empty_allowed :
raise ValueError ( _EMPTY_ELEMENT )
else :
flat_path ... |
def match_input_fmt ( self , fmt_list ) :
"""Given a list of Fortran format specifiers , e . g . , [ ' I5 ' , ' 2X ' , ' F4.1 ' ] ,
this function constructs a list of tuples for matching an input
string against those format specifiers .""" | rexp_list = [ ]
for fmt in fmt_list :
rexp_list . extend ( self . match_input_fmt_1 ( fmt ) )
return rexp_list |
def plot_and_save ( self , data , w = 800 , h = 420 , filename = 'chart' , overwrite = True ) :
"""Save the rendered html to a file and returns an IFrame to display the plot in the notebook .""" | self . save ( data , filename , overwrite )
return IFrame ( filename + '.html' , w , h ) |
def once ( ctx , name ) :
"""Run kibitzr checks once and exit""" | from kibitzr . app import Application
app = Application ( )
sys . exit ( app . run ( once = True , log_level = ctx . obj [ 'log_level' ] , names = name ) ) |
def message_details ( self , message_id , statistics = False ) :
"""Gets the details of this message .""" | response = self . _get ( "/transactional/messages/%s?statistics=%s" % ( message_id , statistics ) )
return json_to_py ( response ) |
def canonicalize_gates ( gates : LogicalGates ) -> Dict [ frozenset , LogicalGates ] :
"""Canonicalizes a set of gates by the qubits they act on .
Takes a set of gates specified by ordered sequences of logical
indices , and groups those that act on the same qubits regardless of
order .""" | canonicalized_gates = defaultdict ( dict )
# type : DefaultDict [ frozenset , LogicalGates ]
for indices , gate in gates . items ( ) :
indices = tuple ( indices )
canonicalized_gates [ frozenset ( indices ) ] [ indices ] = gate
return { canonical_indices : dict ( list ( gates . items ( ) ) ) for canonical_indic... |
def ReadHuntFlows ( self , hunt_id , offset , count , filter_condition = db . HuntFlowsCondition . UNSET ) :
"""Reads hunt flows matching given conditins .""" | if filter_condition == db . HuntFlowsCondition . UNSET :
filter_fn = lambda _ : True
elif filter_condition == db . HuntFlowsCondition . FAILED_FLOWS_ONLY :
filter_fn = lambda f : f . flow_state == f . FlowState . ERROR
elif filter_condition == db . HuntFlowsCondition . SUCCEEDED_FLOWS_ONLY :
filter_fn = lam... |
def handle_vcf_calls ( vcf_file , data , orig_items ) :
"""Prioritize VCF calls based on external annotations supplied through GEMINI .""" | if not _do_prioritize ( orig_items ) :
return vcf_file
else :
ann_vcf = population . run_vcfanno ( vcf_file , data )
if ann_vcf :
priority_file = _prep_priority_filter_vcfanno ( ann_vcf , data )
return _apply_priority_filter ( ann_vcf , priority_file , data )
# No data available for filt... |
def _add_series_or_dataframe_operations ( cls ) :
"""Add the series or dataframe only operations to the cls ; evaluate
the doc strings again .""" | from pandas . core import window as rwindow
@ Appender ( rwindow . rolling . __doc__ )
def rolling ( self , window , min_periods = None , center = False , win_type = None , on = None , axis = 0 , closed = None ) :
axis = self . _get_axis_number ( axis )
return rwindow . rolling ( self , window = window , min_pe... |
def plot_gen_diff ( networkA , networkB , leave_out_carriers = [ 'geothermal' , 'oil' , 'other_non_renewable' , 'reservoir' , 'waste' ] ) :
"""Plot difference in generation between two networks grouped by carrier type
Parameters
networkA : PyPSA network container with switches
networkB : PyPSA network contain... | def gen_by_c ( network ) :
gen = pd . concat ( [ network . generators_t . p . mul ( network . snapshot_weightings , axis = 0 ) [ network . generators [ network . generators . control != 'Slack' ] . index ] , network . generators_t . p . mul ( network . snapshot_weightings , axis = 0 ) [ network . generators [ netwo... |
def exists ( self , root ) :
"""Check to see if the < xs : import / > already exists
in the specified schema root by matching I { namesapce } .
@ param root : A schema root .
@ type root : L { Element }""" | for node in root . children :
if node . name != 'import' :
continue
ns = node . get ( 'namespace' )
if self . ns == ns :
return 1
return 0 |
def sweObjectLon ( obj , jd ) :
"""Returns the longitude of an object .""" | sweObj = SWE_OBJECTS [ obj ]
sweList = swisseph . calc_ut ( jd , sweObj )
return sweList [ 0 ] |
def revoke ( self ) :
"""LeaseRevoke revokes a lease .
All keys attached to the lease will expire and be deleted .
This method makes a synchronous HTTP request by default . To make an
asynchronous HTTP request , please define a ` callback ` function
to be invoked when receiving the response .
: return :""... | self . client . post ( self . client . get_url ( "/kv/lease/revoke" ) , json = { "ID" : self . id } )
return True |
def search ( self , term ) :
"""Searches the PyPi repository for the given ` term ` and returns a
dictionary of results .
New in 2.1.5 : returns a dictionary instead of list of tuples""" | packages = { }
results = self . _execute_pip ( [ 'search' , term ] , log = False )
# Don ' t want to log searches
for result in results . split ( linesep ) :
try :
name , description = result . split ( six . u ( ' - ' ) , 1 )
except ValueError : # ' - ' not in result so unable to split into tuple ;
... |
def renew ( domain_name , years , promotion_code = None ) :
'''Try to renew the specified expiring domain name for a specified number of years
domain _ name
The domain name to be renewed
years
Number of years to renew
Returns the following information :
- Whether or not the domain was renewed successful... | opts = salt . utils . namecheap . get_opts ( 'namecheap.domains.renew' )
opts [ 'DomainName' ] = domain_name
opts [ 'Years' ] = years
if promotion_code is not None :
opts [ 'PromotionCode' ] = promotion_code
response_xml = salt . utils . namecheap . post_request ( opts )
if response_xml is None :
return { }
dom... |
def get_attrs ( self ) :
"""retrieve our attributes""" | self . non_index_axes = getattr ( self . attrs , 'non_index_axes' , None ) or [ ]
self . data_columns = getattr ( self . attrs , 'data_columns' , None ) or [ ]
self . info = getattr ( self . attrs , 'info' , None ) or dict ( )
self . nan_rep = getattr ( self . attrs , 'nan_rep' , None )
self . encoding = _ensure_encodi... |
def list_locks ( root = None ) :
'''List current package locks .
root
operate on a different root directory .
Return a dict containing the locked package with attributes : :
{ ' < package > ' : { ' case _ sensitive ' : ' < case _ sensitive > ' ,
' match _ type ' : ' < match _ type > '
' type ' : ' < typ... | locks = { }
_locks = os . path . join ( root , os . path . relpath ( LOCKS , os . path . sep ) ) if root else LOCKS
try :
with salt . utils . files . fopen ( _locks ) as fhr :
items = salt . utils . stringutils . to_unicode ( fhr . read ( ) ) . split ( '\n\n' )
for meta in [ item . split ( '\n' ) fo... |
def write_to_sdpa ( sdp , filename ) :
"""Write the SDP relaxation to SDPA format .
: param sdp : The SDP relaxation to write .
: type sdp : : class : ` ncpol2sdpa . sdp ` .
: param filename : The name of the file . It must have the suffix " . dat - s "
: type filename : str .""" | # Coefficient matrices
row_offsets = [ 0 ]
cumulative_sum = 0
for block_size in sdp . block_struct :
cumulative_sum += block_size ** 2
row_offsets . append ( cumulative_sum )
multiplier = 1
if sdp . F . dtype == np . complex128 :
multiplier = 2
lines = [ [ ] for _ in range ( multiplier * sdp . n_vars + 1 ) ... |
def workflow_stop ( obj , names ) :
"""Stop one or more running workflows .
NAMES : The names , ids or job ids of the workflows that should be stopped .
Leave empty to stop all running workflows .""" | if len ( names ) == 0 :
msg = 'Would you like to stop all workflows?'
else :
msg = '\n{}\n\n{}' . format ( '\n' . join ( names ) , 'Would you like to stop these jobs?' )
if click . confirm ( msg , default = True , abort = True ) :
stop_workflow ( obj [ 'config' ] , names = names if len ( names ) > 0 else No... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.