code stringlengths 51 2.34k | sequence stringlengths 186 3.94k | docstring stringlengths 11 171 |
|---|---|---|
def to_json(df, values):
records = []
if df.empty:
return {"data": []}
sum_ = float(np.sum([df[c].iloc[0] for c in values]))
for c in values:
records.append({
"label": values[c],
"value": "%.2f"%np.around(df[c].iloc[0] / sum_, decimals=2)
})
return {
"data" : records
} | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier list if_statement attribute identifier identifier block return_statement dictionary pair string string_start string_content string_end list expression_statement assignment identifier call identifier argument_list call attribute identifier identifier argument_list list_comprehension subscript attribute subscript identifier identifier identifier integer for_in_clause identifier identifier for_statement identifier identifier block expression_statement call attribute identifier identifier argument_list dictionary pair string string_start string_content string_end subscript identifier identifier pair string string_start string_content string_end binary_operator string string_start string_content string_end call attribute identifier identifier argument_list binary_operator subscript attribute subscript identifier identifier identifier integer identifier keyword_argument identifier integer return_statement dictionary pair string string_start string_content string_end identifier | Format output for the json response. |
def cal_model_performance(obsl, siml):
nse = MathClass.nashcoef(obsl, siml)
r2 = MathClass.rsquare(obsl, siml)
rmse = MathClass.rmse(obsl, siml)
pbias = MathClass.pbias(obsl, siml)
rsr = MathClass.rsr(obsl, siml)
print('NSE: %.2f, R-square: %.2f, PBIAS: %.2f%%, RMSE: %.2f, RSR: %.2f' %
(nse, r2, pbias, rmse, rsr)) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier expression_statement call identifier argument_list binary_operator string string_start string_content string_end tuple identifier identifier identifier identifier identifier | Calculate model performance indexes. |
def dlp_job_path(cls, project, dlp_job):
return google.api_core.path_template.expand(
"projects/{project}/dlpJobs/{dlp_job}", project=project, dlp_job=dlp_job
) | module function_definition identifier parameters identifier identifier identifier block return_statement call attribute attribute attribute identifier identifier identifier identifier argument_list string string_start string_content string_end keyword_argument identifier identifier keyword_argument identifier identifier | Return a fully-qualified dlp_job string. |
def download_threads(self, url):
output_file = os.path.join(self.output_path, '{}.tfa'.format(os.path.split(url)[-1]))
size = 0
try:
stats = os.stat(output_file)
size = stats.st_size
except FileNotFoundError:
pass
if not os.path.isfile(output_file) or size <= 100:
session = OAuth1Session(self.consumer_key,
self.consumer_secret,
access_token=self.session_token,
access_token_secret=self.session_secret)
r = session.get(url + '/alleles_fasta')
if r.status_code == 200 or r.status_code == 201:
if re.search('json', r.headers['content-type'], flags=0):
decoded = r.json()
else:
decoded = r.text
with open(output_file, 'w') as allele:
allele.write(decoded) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier call attribute string string_start string_content string_end identifier argument_list subscript call attribute attribute identifier identifier identifier argument_list identifier unary_operator integer expression_statement assignment identifier integer try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier attribute identifier identifier except_clause identifier block pass_statement if_statement boolean_operator not_operator call attribute attribute identifier identifier identifier argument_list identifier comparison_operator identifier integer block expression_statement assignment identifier call identifier argument_list attribute identifier identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list binary_operator identifier string string_start string_content string_end if_statement boolean_operator comparison_operator attribute identifier identifier integer comparison_operator attribute identifier identifier integer block if_statement call attribute identifier identifier argument_list string string_start string_content string_end subscript attribute identifier identifier string string_start string_content string_end keyword_argument identifier integer block expression_statement assignment identifier call attribute identifier identifier argument_list else_clause block expression_statement assignment identifier attribute identifier identifier with_statement with_clause with_item as_pattern call identifier argument_list identifier string string_start string_content string_end as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list identifier | Download the allele files |
def run(self):
log.debug("Starting Kafka producer I/O thread.")
while self._running:
try:
self.run_once()
except Exception:
log.exception("Uncaught error in kafka producer I/O thread")
log.debug("Beginning shutdown of Kafka producer I/O thread, sending"
" remaining records.")
while (not self._force_close
and (self._accumulator.has_unsent()
or self._client.in_flight_request_count() > 0)):
try:
self.run_once()
except Exception:
log.exception("Uncaught error in kafka producer I/O thread")
if self._force_close:
self._accumulator.abort_incomplete_batches()
try:
self._client.close()
except Exception:
log.exception("Failed to close network client")
log.debug("Shutdown of Kafka producer I/O thread has completed.") | module function_definition identifier parameters identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end while_statement attribute identifier identifier block try_statement block expression_statement call attribute identifier identifier argument_list except_clause identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list concatenated_string string string_start string_content string_end string string_start string_content string_end while_statement parenthesized_expression boolean_operator not_operator attribute identifier identifier parenthesized_expression boolean_operator call attribute attribute identifier identifier identifier argument_list comparison_operator call attribute attribute identifier identifier identifier argument_list integer block try_statement block expression_statement call attribute identifier identifier argument_list except_clause identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end if_statement attribute identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list try_statement block expression_statement call attribute attribute identifier identifier identifier argument_list except_clause identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end | The main run loop for the sender thread. |
def history(verbose, range):
alembic_command.history(
config=get_config(),
rev_range=range,
verbose=verbose
) | module function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list keyword_argument identifier call identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier | List revision changesets chronologically |
def from_string(cls, s):
for num, text in cls._STATUS2STR.items():
if text == s:
return cls(num)
else:
raise ValueError("Wrong string %s" % s) | module function_definition identifier parameters identifier identifier block for_statement pattern_list identifier identifier call attribute attribute identifier identifier identifier argument_list block if_statement comparison_operator identifier identifier block return_statement call identifier argument_list identifier else_clause block raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier | Return a `Status` instance from its string representation. |
def create_router(self, name, tenant_id, subnet_lst):
try:
body = {'router': {'name': name, 'tenant_id': tenant_id,
'admin_state_up': True}}
router = self.neutronclient.create_router(body=body)
rout_dict = router.get('router')
rout_id = rout_dict.get('id')
except Exception as exc:
LOG.error("Failed to create router with name %(name)s"
" Exc %(exc)s", {'name': name, 'exc': str(exc)})
return None
ret = self.add_intf_router(rout_id, tenant_id, subnet_lst)
if not ret:
try:
ret = self.neutronclient.delete_router(rout_id)
except Exception as exc:
LOG.error("Failed to delete router %(name)s, Exc %(exc)s",
{'name': name, 'exc': str(exc)})
return None
return rout_id | module function_definition identifier parameters identifier identifier identifier identifier block try_statement block expression_statement assignment identifier dictionary pair string string_start string_content string_end dictionary pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end true expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list keyword_argument identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list concatenated_string string string_start string_content string_end string string_start string_content string_end dictionary pair string string_start string_content string_end identifier pair string string_start string_content string_end call identifier argument_list identifier return_statement none expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier identifier if_statement not_operator identifier block try_statement block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end dictionary pair string string_start string_content string_end identifier pair string string_start string_content string_end call identifier argument_list identifier return_statement none return_statement identifier | Create a openstack router and add the interfaces. |
def _CreateSudoersGroup(self):
if not self._GetGroup(self.google_sudoers_group):
try:
command = self.groupadd_cmd.format(group=self.google_sudoers_group)
subprocess.check_call(command.split(' '))
except subprocess.CalledProcessError as e:
self.logger.warning('Could not create the sudoers group. %s.', str(e))
if not os.path.exists(self.google_sudoers_file):
try:
with open(self.google_sudoers_file, 'w') as group:
message = '%{0} ALL=(ALL:ALL) NOPASSWD:ALL'.format(
self.google_sudoers_group)
group.write(message)
except IOError as e:
self.logger.error(
'Could not write sudoers file. %s. %s',
self.google_sudoers_file, str(e))
return
file_utils.SetPermissions(
self.google_sudoers_file, mode=0o440, uid=0, gid=0) | module function_definition identifier parameters identifier block if_statement not_operator call attribute identifier identifier argument_list attribute identifier identifier block try_statement block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list keyword_argument identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end except_clause as_pattern attribute identifier identifier as_pattern_target identifier block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier if_statement not_operator call attribute attribute identifier identifier identifier argument_list attribute identifier identifier block try_statement block with_statement with_clause with_item as_pattern call identifier argument_list attribute identifier identifier string string_start string_content string_end as_pattern_target identifier block expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end attribute identifier identifier call identifier argument_list identifier return_statement expression_statement call attribute identifier identifier argument_list attribute identifier identifier keyword_argument identifier integer keyword_argument identifier integer keyword_argument identifier integer | Create a Linux group for Google added sudo user accounts. |
def _get_sql(filename):
with open(os.path.join(SQL_DIR, filename), 'r') as f:
return f.read() | module function_definition identifier parameters identifier block with_statement with_clause with_item as_pattern call identifier argument_list call attribute attribute identifier identifier identifier argument_list identifier identifier string string_start string_content string_end as_pattern_target identifier block return_statement call attribute identifier identifier argument_list | Returns the contents of the sql file from the given ``filename``. |
def endSubscription(self, subscriber):
self._reqId2Contract.pop(subscriber.reqId, None)
self.reqId2Subscriber.pop(subscriber.reqId, None) | module function_definition identifier parameters identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier none expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier none | Unregister a live subscription. |
def sphinx_extension(app, exception):
"Wrapped up as a Sphinx Extension"
if not app.builder.name in ("html", "dirhtml"):
return
if not app.config.sphinx_to_github:
if app.config.sphinx_to_github_verbose:
print("Sphinx-to-github: Disabled, doing nothing.")
return
if exception:
if app.config.sphinx_to_github_verbose:
print("Sphinx-to-github: Exception raised in main build, doing nothing.")
return
dir_helper = DirHelper(
os.path.isdir,
os.listdir,
os.walk,
shutil.rmtree
)
file_helper = FileSystemHelper(
open,
os.path.join,
shutil.move,
os.path.exists
)
operations_factory = OperationsFactory()
handler_factory = HandlerFactory()
layout_factory = LayoutFactory(
operations_factory,
handler_factory,
file_helper,
dir_helper,
app.config.sphinx_to_github_verbose,
sys.stdout,
force=True
)
layout = layout_factory.create_layout(app.outdir)
layout.process() | module function_definition identifier parameters identifier identifier block expression_statement string string_start string_content string_end if_statement not_operator comparison_operator attribute attribute identifier identifier identifier tuple string string_start string_content string_end string string_start string_content string_end block return_statement if_statement not_operator attribute attribute identifier identifier identifier block if_statement attribute attribute identifier identifier identifier block expression_statement call identifier argument_list string string_start string_content string_end return_statement if_statement identifier block if_statement attribute attribute identifier identifier identifier block expression_statement call identifier argument_list string string_start string_content string_end return_statement expression_statement assignment identifier call identifier argument_list attribute attribute identifier identifier identifier attribute identifier identifier attribute identifier identifier attribute identifier identifier expression_statement assignment identifier call identifier argument_list identifier attribute attribute identifier identifier identifier attribute identifier identifier attribute attribute identifier identifier identifier expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier call identifier argument_list identifier identifier identifier identifier attribute attribute identifier identifier identifier attribute identifier identifier keyword_argument identifier true expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list | Wrapped up as a Sphinx Extension |
def getPreprocessorDefinitions(self, engineRoot, delimiter=' '):
return delimiter.join(self.resolveRoot(self.definitions, engineRoot)) | module function_definition identifier parameters identifier identifier default_parameter identifier string string_start string_content string_end block return_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list attribute identifier identifier identifier | Returns the list of preprocessor definitions for this library, joined using the specified delimiter |
def check_who_read(self, messages):
for m in messages:
readers = []
for p in m.thread.participation_set.all():
if p.date_last_check is None:
pass
elif p.date_last_check > m.sent_at:
readers.append(p.participant.id)
setattr(m, "readers", readers)
return messages | module function_definition identifier parameters identifier identifier block for_statement identifier identifier block expression_statement assignment identifier list for_statement identifier call attribute attribute attribute identifier identifier identifier identifier argument_list block if_statement comparison_operator attribute identifier identifier none block pass_statement elif_clause comparison_operator attribute identifier identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list attribute attribute identifier identifier identifier expression_statement call identifier argument_list identifier string string_start string_content string_end identifier return_statement identifier | Check who read each message. |
def WaitForSnapshotCompleted(snapshot):
print 'Waiting for snapshot %s to be completed...' % (snapshot)
while True:
snapshot.update()
sys.stdout.write('.')
sys.stdout.flush()
if snapshot.status == 'completed':
break
time.sleep(5)
return | module function_definition identifier parameters identifier block print_statement binary_operator string string_start string_content string_end parenthesized_expression identifier while_statement true block expression_statement call attribute identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block break_statement expression_statement call attribute identifier identifier argument_list integer return_statement | Blocks until snapshot is complete. |
def validate(self, data, schema, **kwargs):
if not isinstance(schema, dict):
schema = {'$ref': schema}
return validate(
data,
schema,
resolver=self.ref_resolver_cls.from_schema(schema),
types=self.app.config.get('RECORDS_VALIDATION_TYPES', {}),
**kwargs
) | module function_definition identifier parameters identifier identifier identifier dictionary_splat_pattern identifier block if_statement not_operator call identifier argument_list identifier identifier block expression_statement assignment identifier dictionary pair string string_start string_content string_end identifier return_statement call identifier argument_list identifier identifier keyword_argument identifier call attribute attribute identifier identifier identifier argument_list identifier keyword_argument identifier call attribute attribute attribute identifier identifier identifier identifier argument_list string string_start string_content string_end dictionary dictionary_splat identifier | Validate data using schema with ``JSONResolver``. |
def _checkDragDropEvent(self, ev):
mimedata = ev.mimeData()
if mimedata.hasUrls():
urls = [str(url.toLocalFile()) for url in mimedata.urls() if url.toLocalFile()]
else:
urls = []
if urls:
ev.acceptProposedAction()
return urls
else:
ev.ignore()
return None | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list if_statement call attribute identifier identifier argument_list block expression_statement assignment identifier list_comprehension call identifier argument_list call attribute identifier identifier argument_list for_in_clause identifier call attribute identifier identifier argument_list if_clause call attribute identifier identifier argument_list else_clause block expression_statement assignment identifier list if_statement identifier block expression_statement call attribute identifier identifier argument_list return_statement identifier else_clause block expression_statement call attribute identifier identifier argument_list return_statement none | Checks if event contains a file URL, accepts if it does, ignores if it doesn't |
def setup_multiifo_combine_statmap(workflow, final_bg_file_list, out_dir, tags):
if tags is None:
tags = []
make_analysis_dir(out_dir)
logging.info('Setting up multiifo combine statmap')
cstat_exe = PyCBCMultiifoCombineStatmap(workflow.cp,
'combine_statmap',
ifos=workflow.ifos,
tags=tags,
out_dir=out_dir)
ifolist = ' '.join(workflow.ifos)
cluster_window = float(workflow.cp.get_opt_tags('combine_statmap',
'cluster-window',
tags))
combine_statmap_node = cstat_exe.create_node(final_bg_file_list,
ifolist,
cluster_window,
tags)
workflow.add_node(combine_statmap_node)
return combine_statmap_node.output_file | module function_definition identifier parameters identifier identifier identifier identifier block if_statement comparison_operator identifier none block expression_statement assignment identifier list expression_statement call identifier argument_list identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call identifier argument_list attribute identifier identifier string string_start string_content string_end keyword_argument identifier attribute identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier expression_statement assignment identifier call identifier argument_list call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier identifier identifier expression_statement call attribute identifier identifier argument_list identifier return_statement attribute identifier identifier | Combine the multiifo statmap files into one background file |
def render(self, context, instance, placeholder):
if instance and instance.template:
self.render_template = instance.template
return super(PluginTemplateMixin,self).render(context,instance,placeholder) | module function_definition identifier parameters identifier identifier identifier identifier block if_statement boolean_operator identifier attribute identifier identifier block expression_statement assignment attribute identifier identifier attribute identifier identifier return_statement call attribute call identifier argument_list identifier identifier identifier argument_list identifier identifier identifier | Permits setting of the template in the plugin instance configuration |
def clean_workspace(self):
if os.path.isdir(self._temp_workspace):
shutil.rmtree(self._temp_workspace) | module function_definition identifier parameters identifier block if_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier | Clean up the temporary workspace if one exists |
def coverage_lineplot (self):
data = list()
data_labels = list()
if len(self.rna_seqc_norm_high_cov) > 0:
data.append(self.rna_seqc_norm_high_cov)
data_labels.append({'name': 'High Expressed'})
if len(self.rna_seqc_norm_medium_cov) > 0:
data.append(self.rna_seqc_norm_medium_cov)
data_labels.append({'name': 'Medium Expressed'})
if len(self.rna_seqc_norm_low_cov) > 0:
data.append(self.rna_seqc_norm_low_cov)
data_labels.append({'name': 'Low Expressed'})
pconfig = {
'id': 'rna_seqc_mean_coverage_plot',
'title': 'RNA-SeQC: Gene Body Coverage',
'ylab': '% Coverage',
'xlab': "Gene Body Percentile (5' -> 3')",
'xmin': 0,
'xmax': 100,
'tt_label': "<strong>{point.x}% from 5'</strong>: {point.y:.2f}",
'data_labels': data_labels
}
if len(data) > 0:
self.add_section (
name = 'Gene Body Coverage',
anchor = 'rseqc-rna_seqc_mean_coverage',
helptext = 'The metrics are calculated across the transcripts with tiered expression levels.',
plot = linegraph.plot(data, pconfig)
) | module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier call identifier argument_list if_statement comparison_operator call identifier argument_list attribute identifier identifier integer block expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list dictionary pair string string_start string_content string_end string string_start string_content string_end if_statement comparison_operator call identifier argument_list attribute identifier identifier integer block expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list dictionary pair string string_start string_content string_end string string_start string_content string_end if_statement comparison_operator call identifier argument_list attribute identifier identifier integer block expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list dictionary pair string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end integer pair string string_start string_content string_end integer pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end identifier if_statement comparison_operator call identifier argument_list identifier integer block expression_statement call attribute identifier identifier argument_list keyword_argument identifier string string_start string_content string_end keyword_argument identifier string string_start string_content string_end keyword_argument identifier string string_start string_content string_end keyword_argument identifier call attribute identifier identifier argument_list identifier identifier | Make HTML for coverage line plots |
def nearest(self, idx):
hi = self.after(idx)
lo = self.before(idx)
if hi is None:
return lo
if lo is None:
return hi
if abs(hi - idx) < abs(lo - idx):
return hi
return lo | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement comparison_operator identifier none block return_statement identifier if_statement comparison_operator identifier none block return_statement identifier if_statement comparison_operator call identifier argument_list binary_operator identifier identifier call identifier argument_list binary_operator identifier identifier block return_statement identifier return_statement identifier | Return datetime of record whose datetime is nearest idx. |
def Construct(self):
self.gdml_parser.Read(self.filename)
self.world = self.gdml_parser.GetWorldVolume()
self.log.info("Materials:")
self.log.info(G4.G4Material.GetMaterialTable())
return self.world | module function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list return_statement attribute identifier identifier | Construct a cuboid from a GDML file without sensitive detector |
def ignored_regions(source):
return [(match.start(), match.end()) for match in _str.finditer(source)] | module function_definition identifier parameters identifier block return_statement list_comprehension tuple call attribute identifier identifier argument_list call attribute identifier identifier argument_list for_in_clause identifier call attribute identifier identifier argument_list identifier | Return ignored regions like strings and comments in `source` |
def timestamp(self):
if self.conf.time_source == CTIME:
return os.path.getctime(self.path)
return email.utils.mktime_tz(email.utils.parsedate_tz(
self.message.get('Date'))) | module function_definition identifier parameters identifier block if_statement comparison_operator attribute attribute identifier identifier identifier identifier block return_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier return_statement call attribute attribute identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end | Compute the normalized canonical timestamp of the mail. |
def initialize_dag(self,
targets: Optional[List[str]] = [],
nested: bool = False) -> SoS_DAG:
self.reset_dict()
dag = SoS_DAG(name=self.md5)
targets = sos_targets(targets)
self.add_forward_workflow(dag, self.workflow.sections)
if self.resolve_dangling_targets(dag, targets) == 0:
if targets:
raise UnknownTarget(f'No step to generate target {targets}.')
dag.build()
if targets:
dag = dag.subgraph_from(targets)
cycle = dag.circular_dependencies()
if cycle:
raise RuntimeError(
f'Circular dependency detected {cycle}. It is likely a later step produces input of a previous step.'
)
dag.save(env.config['output_dag'])
return dag | module function_definition identifier parameters identifier typed_default_parameter identifier type generic_type identifier type_parameter type generic_type identifier type_parameter type identifier list typed_default_parameter identifier type identifier false type identifier block expression_statement call attribute identifier identifier argument_list expression_statement assignment identifier call identifier argument_list keyword_argument identifier attribute identifier identifier expression_statement assignment identifier call identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier attribute attribute identifier identifier identifier if_statement comparison_operator call attribute identifier identifier argument_list identifier identifier integer block if_statement identifier block raise_statement call identifier argument_list string string_start string_content interpolation identifier string_content string_end expression_statement call attribute identifier identifier argument_list if_statement identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list if_statement identifier block raise_statement call identifier argument_list string string_start string_content interpolation identifier string_content string_end expression_statement call attribute identifier identifier argument_list subscript attribute identifier identifier string string_start string_content string_end return_statement identifier | Create a DAG by analyzing sections statically. |
def make_gym_env(env_id, num_env=2, seed=123, wrapper_kwargs=None, start_index=0):
if wrapper_kwargs is None:
wrapper_kwargs = {}
def make_env(rank):
def _thunk():
env = gym.make(env_id)
env.seed(seed + rank)
return env
return _thunk
set_global_seeds(seed)
return SubprocVecEnv([make_env(i + start_index) for i in range(num_env)]) | module function_definition identifier parameters identifier default_parameter identifier integer default_parameter identifier integer default_parameter identifier none default_parameter identifier integer block if_statement comparison_operator identifier none block expression_statement assignment identifier dictionary function_definition identifier parameters identifier block function_definition identifier parameters block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list binary_operator identifier identifier return_statement identifier return_statement identifier expression_statement call identifier argument_list identifier return_statement call identifier argument_list list_comprehension call identifier argument_list binary_operator identifier identifier for_in_clause identifier call identifier argument_list identifier | Create a wrapped, SubprocVecEnv for Gym Environments. |
def cast_column(self, keys, func):
import utool as ut
for key in ut.ensure_iterable(keys):
self[key] = [func(v) for v in self[key]] | module function_definition identifier parameters identifier identifier identifier block import_statement aliased_import dotted_name identifier identifier for_statement identifier call attribute identifier identifier argument_list identifier block expression_statement assignment subscript identifier identifier list_comprehension call identifier argument_list identifier for_in_clause identifier subscript identifier identifier | like map column but applies values inplace |
def deleted_records(endpoint):
@utils.for_each_value
def _deleted_records(self, key, value):
deleted_recid = maybe_int(value.get('a'))
if deleted_recid:
return get_record_ref(deleted_recid, endpoint)
return _deleted_records | module function_definition identifier parameters identifier block decorated_definition decorator attribute identifier identifier function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end if_statement identifier block return_statement call identifier argument_list identifier identifier return_statement identifier | Populate the ``deleted_records`` key. |
def delay_or_fail(self, *args, **kwargs):
return self.async_or_fail(args=args, kwargs=kwargs) | module function_definition identifier parameters identifier list_splat_pattern identifier dictionary_splat_pattern identifier block return_statement call attribute identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier | Wrap async_or_fail with a convenience signiture like delay |
def _classify_load_constant(self, regs_init, regs_fini, mem_fini, written_regs, read_regs):
matches = []
for dst_reg, dst_val in regs_fini.items():
if dst_reg not in written_regs:
continue
if dst_val == regs_init[dst_reg]:
continue
dst_val_ir = ReilImmediateOperand(dst_val, self._arch_regs_size[dst_reg])
dst_reg_ir = ReilRegisterOperand(dst_reg, self._arch_regs_size[dst_reg])
matches.append({
"src": [dst_val_ir],
"dst": [dst_reg_ir]
})
return matches | module function_definition identifier parameters identifier identifier identifier identifier identifier identifier block expression_statement assignment identifier list for_statement pattern_list identifier identifier call attribute identifier identifier argument_list block if_statement comparison_operator identifier identifier block continue_statement if_statement comparison_operator identifier subscript identifier identifier block continue_statement expression_statement assignment identifier call identifier argument_list identifier subscript attribute identifier identifier identifier expression_statement assignment identifier call identifier argument_list identifier subscript attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list dictionary pair string string_start string_content string_end list identifier pair string string_start string_content string_end list identifier return_statement identifier | Classify load-constant gadgets. |
def del_module(self, module):
rev = util.get_latest_revision(module)
del self.modules[(module.arg, rev)] | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier delete_statement subscript attribute identifier identifier tuple attribute identifier identifier identifier | Remove a module from the context |
def fix_e731(self, result):
(line_index, _, target) = get_index_offset_contents(result,
self.source)
match = LAMBDA_REGEX.search(target)
if match:
end = match.end()
self.source[line_index] = '{}def {}({}): return {}'.format(
target[:match.start(0)], match.group(1), match.group(2),
target[end:].lstrip()) | module function_definition identifier parameters identifier identifier block expression_statement assignment tuple_pattern identifier identifier identifier call identifier argument_list identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment subscript attribute identifier identifier identifier call attribute string string_start string_content string_end identifier argument_list subscript identifier slice call attribute identifier identifier argument_list integer call attribute identifier identifier argument_list integer call attribute identifier identifier argument_list integer call attribute subscript identifier slice identifier identifier argument_list | Fix do not assign a lambda expression check. |
def pypi(
click_ctx,
requirements,
index=None,
python_version=3,
exclude_packages=None,
output=None,
subgraph_check_api=None,
no_transitive=True,
no_pretty=False,
):
requirements = [requirement.strip() for requirement in requirements.split("\\n") if requirement]
if not requirements:
_LOG.error("No requirements specified, exiting")
sys.exit(1)
if not subgraph_check_api:
_LOG.info(
"No subgraph check API provided, no queries will be done for dependency subgraphs that should be avoided"
)
result = resolve_python(
requirements,
index_urls=index.split(",") if index else ("https://pypi.org/simple",),
python_version=int(python_version),
transitive=not no_transitive,
exclude_packages=set(map(str.strip, (exclude_packages or "").split(","))),
subgraph_check_api=subgraph_check_api,
)
print_command_result(
click_ctx,
result,
analyzer=analyzer_name,
analyzer_version=analyzer_version,
output=output or "-",
pretty=not no_pretty,
) | module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier integer default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier true default_parameter identifier false block expression_statement assignment identifier list_comprehension call attribute identifier identifier argument_list for_in_clause identifier call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end if_clause identifier if_statement not_operator identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list integer if_statement not_operator identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier keyword_argument identifier conditional_expression call attribute identifier identifier argument_list string string_start string_content string_end identifier tuple string string_start string_content string_end keyword_argument identifier call identifier argument_list identifier keyword_argument identifier not_operator identifier keyword_argument identifier call identifier argument_list call identifier argument_list attribute identifier identifier call attribute parenthesized_expression boolean_operator identifier string string_start string_end identifier argument_list string string_start string_content string_end keyword_argument identifier identifier expression_statement call identifier argument_list identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier boolean_operator identifier string string_start string_content string_end keyword_argument identifier not_operator identifier | Manipulate with dependency requirements using PyPI. |
def asDictionary(self):
feat_dict = {}
if self._geom is not None:
if 'feature' in self._dict:
feat_dict['geometry'] = self._dict['feature']['geometry']
elif 'geometry' in self._dict:
feat_dict['geometry'] = self._dict['geometry']
if 'feature' in self._dict:
feat_dict['attributes'] = self._dict['feature']['attributes']
else:
feat_dict['attributes'] = self._dict['attributes']
return self._dict | module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary if_statement comparison_operator attribute identifier identifier none block if_statement comparison_operator string string_start string_content string_end attribute identifier identifier block expression_statement assignment subscript identifier string string_start string_content string_end subscript subscript attribute identifier identifier string string_start string_content string_end string string_start string_content string_end elif_clause comparison_operator string string_start string_content string_end attribute identifier identifier block expression_statement assignment subscript identifier string string_start string_content string_end subscript attribute identifier identifier string string_start string_content string_end if_statement comparison_operator string string_start string_content string_end attribute identifier identifier block expression_statement assignment subscript identifier string string_start string_content string_end subscript subscript attribute identifier identifier string string_start string_content string_end string string_start string_content string_end else_clause block expression_statement assignment subscript identifier string string_start string_content string_end subscript attribute identifier identifier string string_start string_content string_end return_statement attribute identifier identifier | returns the feature as a dictionary |
def greedy_trails(subg, odds, verbose):
if verbose:
print('\tCreating edge map')
edges = defaultdict(list)
for x,y in subg.edges():
edges[x].append(y)
edges[y].append(x)
if verbose:
print('\tSelecting trails')
trails = []
for x in subg.nodes():
if verbose > 2:
print('\t\tNode {0}'.format(x))
while len(edges[x]) > 0:
y = edges[x][0]
trail = [(x,y)]
edges[x].remove(y)
edges[y].remove(x)
while len(edges[y]) > 0:
x = y
y = edges[y][0]
trail.append((x,y))
edges[x].remove(y)
edges[y].remove(x)
trails.append(trail)
return trails | module function_definition identifier parameters identifier identifier identifier block if_statement identifier block expression_statement call identifier argument_list string string_start string_content escape_sequence string_end expression_statement assignment identifier call identifier argument_list identifier for_statement pattern_list identifier identifier call attribute identifier identifier argument_list block expression_statement call attribute subscript identifier identifier identifier argument_list identifier expression_statement call attribute subscript identifier identifier identifier argument_list identifier if_statement identifier block expression_statement call identifier argument_list string string_start string_content escape_sequence string_end expression_statement assignment identifier list for_statement identifier call attribute identifier identifier argument_list block if_statement comparison_operator identifier integer block expression_statement call identifier argument_list call attribute string string_start string_content escape_sequence escape_sequence string_end identifier argument_list identifier while_statement comparison_operator call identifier argument_list subscript identifier identifier integer block expression_statement assignment identifier subscript subscript identifier identifier integer expression_statement assignment identifier list tuple identifier identifier expression_statement call attribute subscript identifier identifier identifier argument_list identifier expression_statement call attribute subscript identifier identifier identifier argument_list identifier while_statement comparison_operator call identifier argument_list subscript identifier identifier integer block expression_statement assignment identifier identifier expression_statement assignment identifier subscript subscript identifier identifier integer expression_statement call attribute identifier identifier argument_list tuple identifier identifier expression_statement call attribute subscript identifier identifier identifier argument_list identifier expression_statement call attribute subscript identifier identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Greedily select trails by making the longest you can until the end |
def _clone(self):
instance = super(Bungiesearch, self)._clone()
instance._raw_results_only = self._raw_results_only
return instance | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute call identifier argument_list identifier identifier identifier argument_list expression_statement assignment attribute identifier identifier attribute identifier identifier return_statement identifier | Must clone additional fields to those cloned by elasticsearch-dsl-py. |
def mutate(self, p_mutate):
new_dna = []
for bit in self.dna:
if random.random() < p_mutate:
bit = '1' if bit == '0' else '0'
new_dna.append(bit)
self.dna = ''.join(new_dna) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier list for_statement identifier attribute identifier identifier block if_statement comparison_operator call attribute identifier identifier argument_list identifier block expression_statement assignment identifier conditional_expression string string_start string_content string_end comparison_operator identifier string string_start string_content string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment attribute identifier identifier call attribute string string_start string_end identifier argument_list identifier | Check each element for mutation, swapping "0" for "1" and vice-versa. |
def _get_config(self, unit, filename):
file_contents = unit.file_contents(filename)
config = configparser.ConfigParser(allow_no_value=True)
config.readfp(io.StringIO(file_contents))
return config | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list keyword_argument identifier true expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier return_statement identifier | Get a ConfigParser object for parsing a unit's config file. |
def _version_newer_than(self, vers):
v = self.version(self.executable())
vers_num = v[:v.index('-')]
if not vers_num[0].isdigit():
return False
v1 = list(map(int, vers_num.split('.')))
v2 = list(map(int, vers.split('.')))
assert len(v1) == 3
assert len(v2) == 3
if v1[0] > v2[0]:
return True
elif v1[0] == v2[0]:
if v1[1] == v2[1]:
return v1[2] >= v2[2]
elif v1[1] > v2[1]:
return True
return False | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list call attribute identifier identifier argument_list expression_statement assignment identifier subscript identifier slice call attribute identifier identifier argument_list string string_start string_content string_end if_statement not_operator call attribute subscript identifier integer identifier argument_list block return_statement false expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier call attribute identifier identifier argument_list string string_start string_content string_end assert_statement comparison_operator call identifier argument_list identifier integer assert_statement comparison_operator call identifier argument_list identifier integer if_statement comparison_operator subscript identifier integer subscript identifier integer block return_statement true elif_clause comparison_operator subscript identifier integer subscript identifier integer block if_statement comparison_operator subscript identifier integer subscript identifier integer block return_statement comparison_operator subscript identifier integer subscript identifier integer elif_clause comparison_operator subscript identifier integer subscript identifier integer block return_statement true return_statement false | Determine whether the version is greater than some given version |
def to_gpu(*args):
if len(args) > 1:
return (cp.asarray(x) for x in args)
else:
return cp.asarray(args[0]) | module function_definition identifier parameters list_splat_pattern identifier block if_statement comparison_operator call identifier argument_list identifier integer block return_statement generator_expression call attribute identifier identifier argument_list identifier for_in_clause identifier identifier else_clause block return_statement call attribute identifier identifier argument_list subscript identifier integer | Upload numpy arrays to GPU and return them |
def del_pickled_ontology(filename):
pickledfile = ONTOSPY_LOCAL_CACHE + "/" + filename + ".pickle"
if os.path.isfile(pickledfile) and not GLOBAL_DISABLE_CACHE:
os.remove(pickledfile)
return True
else:
return None | module function_definition identifier parameters identifier block expression_statement assignment identifier binary_operator binary_operator binary_operator identifier string string_start string_content string_end identifier string string_start string_content string_end if_statement boolean_operator call attribute attribute identifier identifier identifier argument_list identifier not_operator identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement true else_clause block return_statement none | try to remove a cached ontology |
def xgroup_setid(self, stream, group_name, latest_id='$'):
fut = self.execute(b'XGROUP', b'SETID', stream, group_name, latest_id)
return wait_ok(fut) | module function_definition identifier parameters identifier identifier identifier default_parameter identifier string string_start string_content string_end block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end identifier identifier identifier return_statement call identifier argument_list identifier | Set the latest ID for a consumer group |
def save_png_with_metadata(fig, filename, fig_kwds, kwds):
from PIL import Image, PngImagePlugin
fig.savefig(filename, **fig_kwds)
im = Image.open(filename)
meta = PngImagePlugin.PngInfo()
for key in kwds:
meta.add_text(str(key), str(kwds[key]))
im.save(filename, "png", pnginfo=meta) | module function_definition identifier parameters identifier identifier identifier identifier block import_from_statement dotted_name identifier dotted_name identifier dotted_name identifier expression_statement call attribute identifier identifier argument_list identifier dictionary_splat identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list for_statement identifier identifier block expression_statement call attribute identifier identifier argument_list call identifier argument_list identifier call identifier argument_list subscript identifier identifier expression_statement call attribute identifier identifier argument_list identifier string string_start string_content string_end keyword_argument identifier identifier | Save a matplotlib figure to a png with metadata |
def stream_length(self):
if self._stream_length is None:
try:
current_position = self.source_stream.tell()
self.source_stream.seek(0, 2)
self._stream_length = self.source_stream.tell()
self.source_stream.seek(current_position, 0)
except Exception as error:
raise NotSupportedError(error)
return self._stream_length | module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier none block try_statement block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list integer integer expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list identifier integer except_clause as_pattern identifier as_pattern_target identifier block raise_statement call identifier argument_list identifier return_statement attribute identifier identifier | Returns the length of the source stream, determining it if not already known. |
def histogram_info(self) -> dict:
return {
'support_atoms': self.support_atoms,
'atom_delta': self.atom_delta,
'vmin': self.vmin,
'vmax': self.vmax,
'num_atoms': self.atoms
} | module function_definition identifier parameters identifier type identifier block return_statement dictionary pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier | Return extra information about histogram |
def create_entity_class(self):
entity = Entity()
entity.PartitionKey = 'pk{}'.format(str(uuid.uuid4()).replace('-', ''))
entity.RowKey = 'rk{}'.format(str(uuid.uuid4()).replace('-', ''))
entity.age = 39
entity.large = 933311100
entity.sex = 'male'
entity.married = True
entity.ratio = 3.1
entity.birthday = datetime(1970, 10, 4)
entity.binary = EntityProperty(EdmType.BINARY, b'xyz')
entity.other = EntityProperty(EdmType.INT32, 20)
entity.clsid = EntityProperty(EdmType.GUID, 'c9da6455-213d-42c9-9a79-3e9149a57833')
return entity | module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list expression_statement assignment attribute identifier identifier call attribute string string_start string_content string_end identifier argument_list call attribute call identifier argument_list call attribute identifier identifier argument_list identifier argument_list string string_start string_content string_end string string_start string_end expression_statement assignment attribute identifier identifier call attribute string string_start string_content string_end identifier argument_list call attribute call identifier argument_list call attribute identifier identifier argument_list identifier argument_list string string_start string_content string_end string string_start string_end expression_statement assignment attribute identifier identifier integer expression_statement assignment attribute identifier identifier integer expression_statement assignment attribute identifier identifier string string_start string_content string_end expression_statement assignment attribute identifier identifier true expression_statement assignment attribute identifier identifier float expression_statement assignment attribute identifier identifier call identifier argument_list integer integer integer expression_statement assignment attribute identifier identifier call identifier argument_list attribute identifier identifier string string_start string_content string_end expression_statement assignment attribute identifier identifier call identifier argument_list attribute identifier identifier integer expression_statement assignment attribute identifier identifier call identifier argument_list attribute identifier identifier string string_start string_content string_end return_statement identifier | Creates a class-based entity with fixed values, using all of the supported data types. |
def objref(obj):
ref = _objrefs.get(obj)
if ref is None:
clsname = obj.__class__.__name__.split('.')[-1]
seqno = _lastids.setdefault(clsname, 1)
ref = '{}-{}'.format(clsname, seqno)
_objrefs[obj] = ref
_lastids[clsname] += 1
return ref | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement comparison_operator identifier none block expression_statement assignment identifier subscript call attribute attribute attribute identifier identifier identifier identifier argument_list string string_start string_content string_end unary_operator integer expression_statement assignment identifier call attribute identifier identifier argument_list identifier integer expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier identifier expression_statement assignment subscript identifier identifier identifier expression_statement augmented_assignment subscript identifier identifier integer return_statement identifier | Return a string that uniquely and compactly identifies an object. |
def hostname_text(self):
if self._hostname_text is None:
self.chain.connection.log("Collecting hostname information")
self._hostname_text = self.driver.get_hostname_text()
if self._hostname_text:
self.chain.connection.log("Hostname info collected")
else:
self.chain.connection.log("Hostname info not collected")
return self._hostname_text | module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier none block expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list if_statement attribute identifier identifier block expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list string string_start string_content string_end else_clause block expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list string string_start string_content string_end return_statement attribute identifier identifier | Return hostname text and collect if not collected. |
def _extract_sender(
message: Message, resent_dates: List[Union[str, Header]] = None
) -> str:
if resent_dates:
sender_header = "Resent-Sender"
from_header = "Resent-From"
else:
sender_header = "Sender"
from_header = "From"
if sender_header in message:
sender = message[sender_header]
else:
sender = message[from_header]
return str(sender) if sender else "" | module function_definition identifier parameters typed_parameter identifier type identifier typed_default_parameter identifier type generic_type identifier type_parameter type generic_type identifier type_parameter type identifier type identifier none type identifier block if_statement identifier block expression_statement assignment identifier string string_start string_content string_end expression_statement assignment identifier string string_start string_content string_end else_clause block expression_statement assignment identifier string string_start string_content string_end expression_statement assignment identifier string string_start string_content string_end if_statement comparison_operator identifier identifier block expression_statement assignment identifier subscript identifier identifier else_clause block expression_statement assignment identifier subscript identifier identifier return_statement conditional_expression call identifier argument_list identifier identifier string string_start string_end | Extract the sender from the message object given. |
def auth_request(self, url, headers, body):
return self.req.post(url, headers, body=body) | module function_definition identifier parameters identifier identifier identifier identifier block return_statement call attribute attribute identifier identifier identifier argument_list identifier identifier keyword_argument identifier identifier | Perform auth request for token. |
def print_yaml(o):
print(yaml.dump(o, default_flow_style=False, indent=4, encoding='utf-8')) | module function_definition identifier parameters identifier block expression_statement call identifier argument_list call attribute identifier identifier argument_list identifier keyword_argument identifier false keyword_argument identifier integer keyword_argument identifier string string_start string_content string_end | Pretty print an object as YAML. |
def loss(loss_value):
total_loss = tf.Variable(0.0, False)
loss_count = tf.Variable(0, False)
total_loss_update = tf.assign_add(total_loss, loss_value)
loss_count_update = tf.assign_add(loss_count, 1)
loss_op = total_loss / tf.cast(loss_count, tf.float32)
return [total_loss_update, loss_count_update], loss_op | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list float false expression_statement assignment identifier call attribute identifier identifier argument_list integer false expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier integer expression_statement assignment identifier binary_operator identifier call attribute identifier identifier argument_list identifier attribute identifier identifier return_statement expression_list list identifier identifier identifier | Calculates aggregated mean loss. |
def _detect(env):
QTDIR = None
if not QTDIR:
QTDIR = env.get('QTDIR',None)
if not QTDIR:
QTDIR = os.environ.get('QTDIR',None)
if not QTDIR:
moc = env.WhereIs('moc')
if moc:
QTDIR = os.path.dirname(os.path.dirname(moc))
SCons.Warnings.warn(
QtdirNotFound,
"Could not detect qt, using moc executable as a hint (QTDIR=%s)" % QTDIR)
else:
QTDIR = None
SCons.Warnings.warn(
QtdirNotFound,
"Could not detect qt, using empty QTDIR")
return QTDIR | module function_definition identifier parameters identifier block expression_statement assignment identifier none if_statement not_operator identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end none if_statement not_operator identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end none if_statement not_operator identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier binary_operator string string_start string_content string_end identifier else_clause block expression_statement assignment identifier none expression_statement call attribute attribute identifier identifier identifier argument_list identifier string string_start string_content string_end return_statement identifier | Not really safe, but fast method to detect the QT library |
def n_hot(ids, c):
res = np.zeros((c,), dtype=np.float32)
res[ids] = 1
return res | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list tuple identifier keyword_argument identifier attribute identifier identifier expression_statement assignment subscript identifier identifier integer return_statement identifier | one hot encoding by index. Returns array of length c, where all entries are 0, except for the indecies in ids |
def draw_separators(self):
total = 1
self._timeline.create_line((0, 1, self.pixel_width, 1))
for index, (category, label) in enumerate(self._category_labels.items()):
height = label.winfo_reqheight()
self._rows[category] = (total, total + height)
total += height
self._timeline.create_line((0, total, self.pixel_width, total))
pixel_height = total
self._timeline.config(height=pixel_height) | module function_definition identifier parameters identifier block expression_statement assignment identifier integer expression_statement call attribute attribute identifier identifier identifier argument_list tuple integer integer attribute identifier identifier integer for_statement pattern_list identifier tuple_pattern identifier identifier call identifier argument_list call attribute attribute identifier identifier identifier argument_list block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment subscript attribute identifier identifier identifier tuple identifier binary_operator identifier identifier expression_statement augmented_assignment identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list tuple integer identifier attribute identifier identifier identifier expression_statement assignment identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list keyword_argument identifier identifier | Draw the lines separating the categories on the Canvas |
def deploy_webconf():
deployed = []
log_dir = '/'.join([deployment_root(),'log'])
if webserver_list():
if env.verbosity:
print env.host,"DEPLOYING webconf:"
if not exists(log_dir):
run('ln -s /var/log log')
if 'apache2' in get_packages():
deployed += _deploy_webconf('/etc/apache2/sites-available','django-apache-template.txt')
deployed += _deploy_webconf('/etc/nginx/sites-available','nginx-template.txt')
elif 'gunicorn' in get_packages():
deployed += _deploy_webconf('/etc/nginx/sites-available','nginx-gunicorn-template.txt')
if not exists('/var/www/nginx-default'):
sudo('mkdir /var/www/nginx-default')
upload_template('woven/maintenance.html','/var/www/nginx-default/maintenance.html',use_sudo=True)
sudo('chmod ugo+r /var/www/nginx-default/maintenance.html')
else:
print env.host,
return deployed | module function_definition identifier parameters block expression_statement assignment identifier list expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list list call identifier argument_list string string_start string_content string_end if_statement call identifier argument_list block if_statement attribute identifier identifier block print_statement attribute identifier identifier string string_start string_content string_end if_statement not_operator call identifier argument_list identifier block expression_statement call identifier argument_list string string_start string_content string_end if_statement comparison_operator string string_start string_content string_end call identifier argument_list block expression_statement augmented_assignment identifier call identifier argument_list string string_start string_content string_end string string_start string_content string_end expression_statement augmented_assignment identifier call identifier argument_list string string_start string_content string_end string string_start string_content string_end elif_clause comparison_operator string string_start string_content string_end call identifier argument_list block expression_statement augmented_assignment identifier call identifier argument_list string string_start string_content string_end string string_start string_content string_end if_statement not_operator call identifier argument_list string string_start string_content string_end block expression_statement call identifier argument_list string string_start string_content string_end expression_statement call identifier argument_list string string_start string_content string_end string string_start string_content string_end keyword_argument identifier true expression_statement call identifier argument_list string string_start string_content string_end else_clause block print_statement attribute identifier identifier return_statement identifier | Deploy nginx and other wsgi server site configurations to the host |
def on_retry(self, exc, task_id, args, kwargs, einfo):
super(LoggedTask, self).on_retry(exc, task_id, args, kwargs, einfo)
log.warning('[{}] retried due to {}'.format(task_id, getattr(einfo, 'traceback', None))) | module function_definition identifier parameters identifier identifier identifier identifier identifier identifier block expression_statement call attribute call identifier argument_list identifier identifier identifier argument_list identifier identifier identifier identifier identifier expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier call identifier argument_list identifier string string_start string_content string_end none | Capture the exception that caused the task to be retried, if any. |
def create_update_symlink(self, link_destination, remote_path):
try:
self.sftp.remove(remote_path)
except IOError:
pass
finally:
try:
self.sftp.symlink(link_destination, remote_path)
except OSError as e:
self.logger.error("error while symlinking {} to {}: {}".format(
remote_path, link_destination, e)) | module function_definition identifier parameters identifier identifier identifier block try_statement block expression_statement call attribute attribute identifier identifier identifier argument_list identifier except_clause identifier block pass_statement finally_clause block try_statement block expression_statement call attribute attribute identifier identifier identifier argument_list identifier identifier except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute attribute identifier identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier identifier identifier | Create a new link pointing to link_destination in remote_path position. |
def contribute_to_class(self, cls, name, virtual_only=False):
super(RegexField, self).contribute_to_class(cls, name, virtual_only)
setattr(cls, name, CastOnAssignDescriptor(self)) | module function_definition identifier parameters identifier identifier identifier default_parameter identifier false block expression_statement call attribute call identifier argument_list identifier identifier identifier argument_list identifier identifier identifier expression_statement call identifier argument_list identifier identifier call identifier argument_list identifier | Cast to the correct value every |
def active_plan_summary(self):
return self.active().values("plan").order_by().annotate(count=models.Count("plan")) | module function_definition identifier parameters identifier block return_statement call attribute call attribute call attribute call attribute identifier identifier argument_list identifier argument_list string string_start string_content string_end identifier argument_list identifier argument_list keyword_argument identifier call attribute identifier identifier argument_list string string_start string_content string_end | Return active Subscriptions with plan counts annotated. |
def feature_analysis(fname="feature_analysis.png"):
_, axes = plt.subplots(ncols=2, figsize=(18,6))
data = load_occupancy(split=False)
oz = RadViz(ax=axes[0], classes=["unoccupied", "occupied"])
oz.fit(data.X, data.y)
oz.finalize()
data = load_concrete(split=False)
oz = Rank2D(ax=axes[1])
oz.fit_transform(data.X, data.y)
oz.finalize()
path = os.path.join(FIGURES, fname)
plt.tight_layout()
plt.savefig(path) | module function_definition identifier parameters default_parameter identifier string string_start string_content string_end block expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list keyword_argument identifier integer keyword_argument identifier tuple integer integer expression_statement assignment identifier call identifier argument_list keyword_argument identifier false expression_statement assignment identifier call identifier argument_list keyword_argument identifier subscript identifier integer keyword_argument identifier list string string_start string_content string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list expression_statement assignment identifier call identifier argument_list keyword_argument identifier false expression_statement assignment identifier call identifier argument_list keyword_argument identifier subscript identifier integer expression_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier identifier expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list identifier | Create figures for feature analysis |
def list_tables(refresh=False, cache_file=None):
if not cache_file:
cache_file = os.path.join(str(Path.home()), ".bcdata")
if refresh or check_cache(cache_file):
wfs = WebFeatureService(url=bcdata.OWS_URL, version="2.0.0")
bcdata_objects = [i.strip("pub:") for i in list(wfs.contents)]
with open(cache_file, "w") as outfile:
json.dump(sorted(bcdata_objects), outfile)
else:
with open(cache_file, "r") as infile:
bcdata_objects = json.load(infile)
return bcdata_objects | module function_definition identifier parameters default_parameter identifier false default_parameter identifier none block if_statement not_operator identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list call identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end if_statement boolean_operator identifier call identifier argument_list identifier block expression_statement assignment identifier call identifier argument_list keyword_argument identifier attribute identifier identifier keyword_argument identifier string string_start string_content string_end expression_statement assignment identifier list_comprehension call attribute identifier identifier argument_list string string_start string_content string_end for_in_clause identifier call identifier argument_list attribute identifier identifier with_statement with_clause with_item as_pattern call identifier argument_list identifier string string_start string_content string_end as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list call identifier argument_list identifier identifier else_clause block with_statement with_clause with_item as_pattern call identifier argument_list identifier string string_start string_content string_end as_pattern_target identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier return_statement identifier | Return a list of all datasets available via WFS |
def resources_assigned(self) -> List[Resource]:
resources_str = DB.get_hash_value(self.key, 'resources_assigned')
resources_assigned = []
for resource in ast.literal_eval(resources_str):
resources_assigned.append(Resource(resource))
return resources_assigned | module function_definition identifier parameters identifier type generic_type identifier type_parameter type identifier block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier string string_start string_content string_end expression_statement assignment identifier list for_statement identifier call attribute identifier identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list call identifier argument_list identifier return_statement identifier | Return list of resources assigned to the PB. |
def _create_websession(self):
from socket import AF_INET
from aiohttp import ClientTimeout, TCPConnector
_LOGGER.debug('Creating web session')
conn = TCPConnector(
family=AF_INET,
limit_per_host=5,
enable_cleanup_closed=True,
)
session_timeout = ClientTimeout(connect=10)
self._websession = ClientSession(connector=conn,
timeout=session_timeout)
self._supplied_websession = False | module function_definition identifier parameters identifier block import_from_statement dotted_name identifier dotted_name identifier import_from_statement dotted_name identifier dotted_name identifier dotted_name identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call identifier argument_list keyword_argument identifier identifier keyword_argument identifier integer keyword_argument identifier true expression_statement assignment identifier call identifier argument_list keyword_argument identifier integer expression_statement assignment attribute identifier identifier call identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier expression_statement assignment attribute identifier identifier false | Create a web session. |
def Logger(name, **kargs):
path_dirs = PathDirs(**kargs)
logging.captureWarnings(True)
logger = logging.getLogger(name)
logger.setLevel(logging.INFO)
handler = logging.handlers.WatchedFileHandler(os.path.join(
path_dirs.meta_dir, 'vent.log'))
handler.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(name)s:%(lineno)-4d - '
'%(levelname)s - %(message)s')
handler.setFormatter(formatter)
if not len(logger.handlers):
logger.addHandler(handler)
return logger | module function_definition identifier parameters identifier dictionary_splat_pattern identifier block expression_statement assignment identifier call identifier argument_list dictionary_splat identifier expression_statement call attribute identifier identifier argument_list true expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list attribute identifier identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list concatenated_string string string_start string_content string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier if_statement not_operator call identifier argument_list attribute identifier identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Create and return logger |
def import_it(cls):
if not cls in cls._FEATURES:
try:
cls._FEATURES[cls] = cls._import_it()
except ImportError:
raise cls.Error(cls._import_error_message(), cls.Error.UNSATISFIED_IMPORT_REQ)
return cls._FEATURES[cls] | module function_definition identifier parameters identifier block if_statement not_operator comparison_operator identifier attribute identifier identifier block try_statement block expression_statement assignment subscript attribute identifier identifier identifier call attribute identifier identifier argument_list except_clause identifier block raise_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list attribute attribute identifier identifier identifier return_statement subscript attribute identifier identifier identifier | Performs the import only once. |
def copy_file(filename):
print("Updating file %s" % filename)
out_dir = os.path.abspath(DIRECTORY)
tags = filename[:-4].split("-")
tags[-2] = tags[-2].replace("m", "")
new_name = "-".join(tags) + ".whl"
wheel_flag = "-".join(tags[2:])
with InWheelCtx(os.path.join(DIRECTORY, filename)) as ctx:
info_fname = os.path.join(_dist_info_dir(ctx.path), 'WHEEL')
infos = pkginfo.read_pkg_info(info_fname)
print("Changing Tag %s to %s" % (infos["Tag"], wheel_flag))
del infos['Tag']
infos.add_header('Tag', wheel_flag)
pkginfo.write_pkg_info(info_fname, infos)
ctx.out_wheel = os.path.join(out_dir, new_name)
print("Saving new wheel into %s" % ctx.out_wheel) | module function_definition identifier parameters identifier block expression_statement call identifier argument_list binary_operator string string_start string_content string_end identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier call attribute subscript identifier slice unary_operator integer identifier argument_list string string_start string_content string_end expression_statement assignment subscript identifier unary_operator integer call attribute subscript identifier unary_operator integer identifier argument_list string string_start string_content string_end string string_start string_end expression_statement assignment identifier binary_operator call attribute string string_start string_content string_end identifier argument_list identifier string string_start string_content string_end expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list subscript identifier slice integer with_statement with_clause with_item as_pattern call identifier argument_list call attribute attribute identifier identifier identifier argument_list identifier identifier as_pattern_target identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list call identifier argument_list attribute identifier identifier string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement call identifier argument_list binary_operator string string_start string_content string_end tuple subscript identifier string string_start string_content string_end identifier delete_statement subscript identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier expression_statement call attribute identifier identifier argument_list identifier identifier expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list identifier identifier expression_statement call identifier argument_list binary_operator string string_start string_content string_end attribute identifier identifier | Copy the file and put the correct tag |
def format_call(self, api_version, api_call):
api_call = api_call.lstrip('/')
api_call = api_call.rstrip('?')
logger.debug('api_call post strip =\n%s' % api_call)
if (api_version == 2 and api_call[-1] != '/'):
logger.debug('Adding "/" to api_call.')
api_call += '/'
if api_call in self.api_methods_with_trailing_slash[api_version]:
logger.debug('Adding "/" to api_call.')
api_call += '/'
return api_call | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content escape_sequence string_end identifier if_statement parenthesized_expression boolean_operator comparison_operator identifier integer comparison_operator subscript identifier unary_operator integer string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement augmented_assignment identifier string string_start string_content string_end if_statement comparison_operator identifier subscript attribute identifier identifier identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement augmented_assignment identifier string string_start string_content string_end return_statement identifier | Return properly formatted QualysGuard API call according to api_version etiquette. |
def _get_dL2L(self, imt_per):
if imt_per < 0.18:
dL2L = -0.06
elif 0.18 <= imt_per < 0.35:
dL2L = self._interp_function(0.12, -0.06, 0.35, 0.18, imt_per)
elif 0.35 <= imt_per <= 10:
dL2L = self._interp_function(0.65, 0.12, 10, 0.35, imt_per)
else:
dL2L = 0
return dL2L | module function_definition identifier parameters identifier identifier block if_statement comparison_operator identifier float block expression_statement assignment identifier unary_operator float elif_clause comparison_operator float identifier float block expression_statement assignment identifier call attribute identifier identifier argument_list float unary_operator float float float identifier elif_clause comparison_operator float identifier integer block expression_statement assignment identifier call attribute identifier identifier argument_list float float integer float identifier else_clause block expression_statement assignment identifier integer return_statement identifier | Table 3 and equation 19 of 2013 report. |
def _channel_exists_and_not_settled(
self,
participant1: Address,
participant2: Address,
block_identifier: BlockSpecification,
channel_identifier: ChannelID = None,
) -> bool:
try:
channel_state = self._get_channel_state(
participant1=participant1,
participant2=participant2,
block_identifier=block_identifier,
channel_identifier=channel_identifier,
)
except RaidenRecoverableError:
return False
exists_and_not_settled = (
channel_state > ChannelState.NONEXISTENT and
channel_state < ChannelState.SETTLED
)
return exists_and_not_settled | module function_definition identifier parameters identifier typed_parameter identifier type identifier typed_parameter identifier type identifier typed_parameter identifier type identifier typed_default_parameter identifier type identifier none type identifier block try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier except_clause identifier block return_statement false expression_statement assignment identifier parenthesized_expression boolean_operator comparison_operator identifier attribute identifier identifier comparison_operator identifier attribute identifier identifier return_statement identifier | Returns if the channel exists and is in a non-settled state |
def mail_json(self):
if self.mail.get("date"):
self._mail["date"] = self.date.isoformat()
return json.dumps(self.mail, ensure_ascii=False, indent=2) | module function_definition identifier parameters identifier block if_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end block expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end call attribute attribute identifier identifier identifier argument_list return_statement call attribute identifier identifier argument_list attribute identifier identifier keyword_argument identifier false keyword_argument identifier integer | Return the JSON of mail parsed |
def GetParserFromFilename(self, path):
handler_name = path.split("://")[0]
for parser_cls in itervalues(GRRConfigParser.classes):
if parser_cls.name == handler_name:
return parser_cls
extension = os.path.splitext(path)[1]
if extension in [".yaml", ".yml"]:
return YamlParser
return ConfigFileParser | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier subscript call attribute identifier identifier argument_list string string_start string_content string_end integer for_statement identifier call identifier argument_list attribute identifier identifier block if_statement comparison_operator attribute identifier identifier identifier block return_statement identifier expression_statement assignment identifier subscript call attribute attribute identifier identifier identifier argument_list identifier integer if_statement comparison_operator identifier list string string_start string_content string_end string string_start string_content string_end block return_statement identifier return_statement identifier | Returns the appropriate parser class from the filename. |
def issuperset(self, other):
self._binary_sanity_check(other)
return set.issuperset(self, other) | module function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list identifier identifier | Report whether this RangeSet contains another set. |
def kvlclient(self):
if self._kvlclient is None:
self._kvlclient = kvlayer.client()
return self._kvlclient | module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier none block expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list return_statement attribute identifier identifier | Return a thread local ``kvlayer`` client. |
def create_untl_xml_subelement(parent, element, prefix=''):
subelement = SubElement(parent, prefix + element.tag)
if element.content is not None:
subelement.text = element.content
if element.qualifier is not None:
subelement.attrib["qualifier"] = element.qualifier
if element.children > 0:
for child in element.children:
SubElement(subelement, prefix + child.tag).text = child.content
else:
subelement.text = element.content
return subelement | module function_definition identifier parameters identifier identifier default_parameter identifier string string_start string_end block expression_statement assignment identifier call identifier argument_list identifier binary_operator identifier attribute identifier identifier if_statement comparison_operator attribute identifier identifier none block expression_statement assignment attribute identifier identifier attribute identifier identifier if_statement comparison_operator attribute identifier identifier none block expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end attribute identifier identifier if_statement comparison_operator attribute identifier identifier integer block for_statement identifier attribute identifier identifier block expression_statement assignment attribute call identifier argument_list identifier binary_operator identifier attribute identifier identifier identifier attribute identifier identifier else_clause block expression_statement assignment attribute identifier identifier attribute identifier identifier return_statement identifier | Create a UNTL XML subelement. |
def save_db(self):
with self.db_mutex:
if not isinstance(self.db, dict) and not isinstance(self.db, list):
return False
try:
with open(self.json_db_path, "w") as fp:
json.dump(self.db, fp, indent=4)
except Exception as e:
_logger.debug("*** Write JSON DB to file error.")
raise e
else:
self.sync()
return True | module function_definition identifier parameters identifier block with_statement with_clause with_item attribute identifier identifier block if_statement boolean_operator not_operator call identifier argument_list attribute identifier identifier identifier not_operator call identifier argument_list attribute identifier identifier identifier block return_statement false try_statement block with_statement with_clause with_item as_pattern call identifier argument_list attribute identifier identifier string string_start string_content string_end as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier identifier keyword_argument identifier integer except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end raise_statement identifier else_clause block expression_statement call attribute identifier identifier argument_list return_statement true | " Save json db to file system. |
def s2time(secs, show_secs=True, show_fracs=True):
try:
secs = float(secs)
except:
return "--:--:--.--"
wholesecs = int(secs)
centisecs = int((secs - wholesecs) * 100)
hh = int(wholesecs / 3600)
hd = int(hh % 24)
mm = int((wholesecs / 60) - (hh*60))
ss = int(wholesecs - (hh*3600) - (mm*60))
r = "{:02d}:{:02d}".format(hd, mm)
if show_secs:
r += ":{:02d}".format(ss)
if show_fracs:
r += ".{:02d}".format(centisecs)
return r | module function_definition identifier parameters identifier default_parameter identifier true default_parameter identifier true block try_statement block expression_statement assignment identifier call identifier argument_list identifier except_clause block return_statement string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call identifier argument_list binary_operator parenthesized_expression binary_operator identifier identifier integer expression_statement assignment identifier call identifier argument_list binary_operator identifier integer expression_statement assignment identifier call identifier argument_list binary_operator identifier integer expression_statement assignment identifier call identifier argument_list binary_operator parenthesized_expression binary_operator identifier integer parenthesized_expression binary_operator identifier integer expression_statement assignment identifier call identifier argument_list binary_operator binary_operator identifier parenthesized_expression binary_operator identifier integer parenthesized_expression binary_operator identifier integer expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier identifier if_statement identifier block expression_statement augmented_assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier if_statement identifier block expression_statement augmented_assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier return_statement identifier | Converts seconds to time |
def _get_hydrated_path(field):
if isinstance(field, str) and hasattr(field, 'file_name'):
return field
if isinstance(field, dict) and 'file' in field:
hydrated_path = field['file']
if not hasattr(hydrated_path, 'file_name'):
raise TypeError("Filter argument must be a valid file-type field.")
return hydrated_path | module function_definition identifier parameters identifier block if_statement boolean_operator call identifier argument_list identifier identifier call identifier argument_list identifier string string_start string_content string_end block return_statement identifier if_statement boolean_operator call identifier argument_list identifier identifier comparison_operator string string_start string_content string_end identifier block expression_statement assignment identifier subscript identifier string string_start string_content string_end if_statement not_operator call identifier argument_list identifier string string_start string_content string_end block raise_statement call identifier argument_list string string_start string_content string_end return_statement identifier | Return HydratedPath object for file-type field. |
def selector(C, style):
clas = C.classname(style.name)
if style.type == 'paragraph':
outlineLvl = int((style.properties.get('outlineLvl') or {}).get('val') or 8) + 1
if outlineLvl < 9:
tag = 'h%d' % outlineLvl
else:
tag = 'p'
elif style.type == 'character':
tag = 'span'
elif style.type == 'table':
tag = 'table'
elif style.type == 'numbering':
tag = 'ol'
return "%s.%s" % (tag, clas) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier binary_operator call identifier argument_list boolean_operator call attribute parenthesized_expression boolean_operator call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end dictionary identifier argument_list string string_start string_content string_end integer integer if_statement comparison_operator identifier integer block expression_statement assignment identifier binary_operator string string_start string_content string_end identifier else_clause block expression_statement assignment identifier string string_start string_content string_end elif_clause comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier string string_start string_content string_end elif_clause comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier string string_start string_content string_end elif_clause comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier string string_start string_content string_end return_statement binary_operator string string_start string_content string_end tuple identifier identifier | return the selector for the given stylemap style |
def sam_readline(sock, partial = None):
response = b''
exception = None
while True:
try:
c = sock.recv(1)
if not c:
raise EOFError('SAM connection died. Partial response %r %r' % (partial, response))
elif c == b'\n':
break
else:
response += c
except (BlockingIOError, pysocket.timeout) as e:
if partial is None:
raise e
else:
exception = e
break
if partial is None:
return response.decode('ascii')
else:
return (partial + response.decode('ascii'), exception) | module function_definition identifier parameters identifier default_parameter identifier none block expression_statement assignment identifier string string_start string_end expression_statement assignment identifier none while_statement true block try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list integer if_statement not_operator identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end tuple identifier identifier elif_clause comparison_operator identifier string string_start string_content escape_sequence string_end block break_statement else_clause block expression_statement augmented_assignment identifier identifier except_clause as_pattern tuple identifier attribute identifier identifier as_pattern_target identifier block if_statement comparison_operator identifier none block raise_statement identifier else_clause block expression_statement assignment identifier identifier break_statement if_statement comparison_operator identifier none block return_statement call attribute identifier identifier argument_list string string_start string_content string_end else_clause block return_statement tuple binary_operator identifier call attribute identifier identifier argument_list string string_start string_content string_end identifier | read a line from a sam control socket |
def split(src, chunksize=MINWEIGHT):
for i, block in enumerate(block_splitter(src.iter_ruptures(), chunksize,
key=operator.attrgetter('mag'))):
rup = block[0]
source_id = '%s:%d' % (src.source_id, i)
amfd = mfd.ArbitraryMFD([rup.mag], [rup.mag_occ_rate])
rcs = RuptureCollectionSource(
source_id, src.name, src.tectonic_region_type, amfd, block)
yield rcs | module function_definition identifier parameters identifier default_parameter identifier identifier block for_statement pattern_list identifier identifier call identifier argument_list call identifier argument_list call attribute identifier identifier argument_list identifier keyword_argument identifier call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier subscript identifier integer expression_statement assignment identifier binary_operator string string_start string_content string_end tuple attribute identifier identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list list attribute identifier identifier list attribute identifier identifier expression_statement assignment identifier call identifier argument_list identifier attribute identifier identifier attribute identifier identifier identifier identifier expression_statement yield identifier | Split a complex fault source in chunks |
def find_all_runs(self, session=None):
with self._session(session) as session:
return session.query(TaskRecord).all() | module function_definition identifier parameters identifier default_parameter identifier none block with_statement with_clause with_item as_pattern call attribute identifier identifier argument_list identifier as_pattern_target identifier block return_statement call attribute call attribute identifier identifier argument_list identifier identifier argument_list | Return all tasks that have been updated. |
def sanitize_win_path(winpath):
intab = '<>:|?*'
if isinstance(winpath, six.text_type):
winpath = winpath.translate(dict((ord(c), '_') for c in intab))
elif isinstance(winpath, six.string_types):
outtab = '_' * len(intab)
trantab = ''.maketrans(intab, outtab) if six.PY3 else string.maketrans(intab, outtab)
winpath = winpath.translate(trantab)
return winpath | module function_definition identifier parameters identifier block expression_statement assignment identifier string string_start string_content string_end if_statement call identifier argument_list identifier attribute identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list call identifier generator_expression tuple call identifier argument_list identifier string string_start string_content string_end for_in_clause identifier identifier elif_clause call identifier argument_list identifier attribute identifier identifier block expression_statement assignment identifier binary_operator string string_start string_content string_end call identifier argument_list identifier expression_statement assignment identifier conditional_expression call attribute string string_start string_end identifier argument_list identifier identifier attribute identifier identifier call attribute identifier identifier argument_list identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier return_statement identifier | Remove illegal path characters for windows |
def _set_conn(self):
if self._tls:
ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_NEVER)
try:
conn = ldap.initialize(self._url)
conn.set_option(ldap.OPT_NETWORK_TIMEOUT, self._timeout)
conn.simple_bind_s(self._binddn, self._bindpw)
except Exception as e:
if hasattr(e, 'message') and 'desc' in e.message:
msg = e.message['desc']
else:
msg = e.args[0]['desc']
log.critical(msg)
raise
log.debug('%s connection established' % ('LDAPS' if self._tls else 'LDAP'))
self._conn = conn | module function_definition identifier parameters identifier block if_statement attribute identifier identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier except_clause as_pattern identifier as_pattern_target identifier block if_statement boolean_operator call identifier argument_list identifier string string_start string_content string_end comparison_operator string string_start string_content string_end attribute identifier identifier block expression_statement assignment identifier subscript attribute identifier identifier string string_start string_content string_end else_clause block expression_statement assignment identifier subscript subscript attribute identifier identifier integer string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier raise_statement expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end parenthesized_expression conditional_expression string string_start string_content string_end attribute identifier identifier string string_start string_content string_end expression_statement assignment attribute identifier identifier identifier | Establish connection to the server |
def _compress_obj(obj, level):
return zlib.compress(pickle.dumps(obj, protocol=2), level) | module function_definition identifier parameters identifier identifier block return_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier keyword_argument identifier integer identifier | Compress object to bytes. |
def divideHosts(self, hosts, qty):
maximumWorkers = sum(host[1] for host in hosts)
if qty > maximumWorkers:
index = 0
while qty > maximumWorkers:
hosts[index] = (hosts[index][0], hosts[index][1] + 1)
index = (index + 1) % len(hosts)
maximumWorkers += 1
elif qty < maximumWorkers:
while qty < maximumWorkers:
maximumWorkers -= hosts[-1][1]
if qty > maximumWorkers:
hosts[-1] = (hosts[-1][0], qty - maximumWorkers)
maximumWorkers += hosts[-1][1]
else:
del hosts[-1]
if self.externalHostname in utils.loopbackReferences and \
len(hosts) > 1 and \
not self.tunnel:
raise Exception("\n"
"Could not find route from external worker to the "
"broker: Unresolvable hostname or IP address.\n "
"Please specify your externally routable hostname "
"or IP using the --external-hostname parameter or "
"use the --tunnel flag.")
return hosts | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call identifier generator_expression subscript identifier integer for_in_clause identifier identifier if_statement comparison_operator identifier identifier block expression_statement assignment identifier integer while_statement comparison_operator identifier identifier block expression_statement assignment subscript identifier identifier tuple subscript subscript identifier identifier integer binary_operator subscript subscript identifier identifier integer integer expression_statement assignment identifier binary_operator parenthesized_expression binary_operator identifier integer call identifier argument_list identifier expression_statement augmented_assignment identifier integer elif_clause comparison_operator identifier identifier block while_statement comparison_operator identifier identifier block expression_statement augmented_assignment identifier subscript subscript identifier unary_operator integer integer if_statement comparison_operator identifier identifier block expression_statement assignment subscript identifier unary_operator integer tuple subscript subscript identifier unary_operator integer integer binary_operator identifier identifier expression_statement augmented_assignment identifier subscript subscript identifier unary_operator integer integer else_clause block delete_statement subscript identifier unary_operator integer if_statement boolean_operator boolean_operator comparison_operator attribute identifier identifier attribute identifier identifier line_continuation comparison_operator call identifier argument_list identifier integer line_continuation not_operator attribute identifier identifier block raise_statement call identifier argument_list concatenated_string string string_start string_content escape_sequence string_end string string_start string_content string_end string string_start string_content escape_sequence string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end return_statement identifier | Divide processes among hosts. |
def coroutine(func):
def __start(*args, **kwargs):
__cr = func(*args, **kwargs)
next(__cr)
return __cr
return __start | module function_definition identifier parameters identifier block function_definition identifier parameters list_splat_pattern identifier dictionary_splat_pattern identifier block expression_statement assignment identifier call identifier argument_list list_splat identifier dictionary_splat identifier expression_statement call identifier argument_list identifier return_statement identifier return_statement identifier | Basic decorator to implement the coroutine pattern. |
def house_exists(self, complex: str, house: str) -> bool:
try:
self.check_house(complex, house)
except exceptions.RumetrHouseNotFound:
return False
return True | module function_definition identifier parameters identifier typed_parameter identifier type identifier typed_parameter identifier type identifier type identifier block try_statement block expression_statement call attribute identifier identifier argument_list identifier identifier except_clause attribute identifier identifier block return_statement false return_statement true | Shortcut to check if house exists in our database. |
def user_is_submission_owner(self, submission):
if not self._user_manager.session_logged_in():
raise Exception("A user must be logged in to verify if he owns a jobid")
return self._user_manager.session_username() in submission["username"] | module function_definition identifier parameters identifier identifier block if_statement not_operator call attribute attribute identifier identifier identifier argument_list block raise_statement call identifier argument_list string string_start string_content string_end return_statement comparison_operator call attribute attribute identifier identifier identifier argument_list subscript identifier string string_start string_content string_end | Returns true if the current user is the owner of this jobid, false else |
def ConsultarLiquidacionesPorContrato(self, nro_contrato=None,
cuit_comprador=None,
cuit_vendedor=None,
cuit_corredor=None,
cod_grano=None,
**kwargs):
"Obtener los COE de liquidaciones relacionadas a un contrato"
ret = self.client.liquidacionPorContratoConsultar(
auth={
'token': self.Token, 'sign': self.Sign,
'cuit': self.Cuit, },
nroContrato=nro_contrato,
cuitComprador=cuit_comprador,
cuitVendedor=cuit_vendedor,
cuitCorredor=cuit_corredor,
codGrano=cod_grano,
)
ret = ret['liqPorContratoCons']
self.__analizar_errores(ret)
if 'coeRelacionados' in ret:
self.DatosLiquidacion = sorted(ret['coeRelacionados'])
self.LeerDatosLiquidacion()
return True | module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier none dictionary_splat_pattern identifier block expression_statement string string_start string_content string_end expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list keyword_argument identifier dictionary pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier expression_statement assignment identifier subscript identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier if_statement comparison_operator string string_start string_content string_end identifier block expression_statement assignment attribute identifier identifier call identifier argument_list subscript identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list return_statement true | Obtener los COE de liquidaciones relacionadas a un contrato |
def delete(ctx, resource, id):
session, api_url, project_id = build_client_from_context(ctx)
url = '/'.join([api_url, resource, id])
r = session.delete(url)
if r.status_code != 200:
raise failed_request_exception('failed to delete resource', r)
click.echo(r.text) | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment pattern_list identifier identifier identifier call identifier argument_list identifier expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list list identifier identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement comparison_operator attribute identifier identifier integer block raise_statement call identifier argument_list string string_start string_content string_end identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier | Delete given device model or instance. |
def draw(self, surf):
if self.shown:
for w in self.widgets:
surf.blit(w.image, self.convert_rect(w.rect))
for c in self.containers:
c.draw(surf) | module function_definition identifier parameters identifier identifier block if_statement attribute identifier identifier block for_statement identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier call attribute identifier identifier argument_list attribute identifier identifier for_statement identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list identifier | Draw all widgets and sub-containers to @surf. |
def _parse_title(line_iter, cur_line, conf):
title = []
conf['title'].append(title)
title.append(('title_name', cur_line.split('title', 1)[1].strip()))
while (True):
line = next(line_iter)
if line.startswith("title "):
return line
cmd, opt = _parse_cmd(line)
title.append((cmd, opt)) | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier list expression_statement call attribute subscript identifier string string_start string_content string_end identifier argument_list identifier expression_statement call attribute identifier identifier argument_list tuple string string_start string_content string_end call attribute subscript call attribute identifier identifier argument_list string string_start string_content string_end integer integer identifier argument_list while_statement parenthesized_expression true block expression_statement assignment identifier call identifier argument_list identifier if_statement call attribute identifier identifier argument_list string string_start string_content string_end block return_statement identifier expression_statement assignment pattern_list identifier identifier call identifier argument_list identifier expression_statement call attribute identifier identifier argument_list tuple identifier identifier | Parse "title" in grub v1 config |
def runlist_remove(name, **kwargs):
ctx = Context(**kwargs)
ctx.execute_action('runlist:remove', **{
'storage': ctx.repo.create_secure_service('storage'),
'name': name,
}) | module function_definition identifier parameters identifier dictionary_splat_pattern identifier block expression_statement assignment identifier call identifier argument_list dictionary_splat identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end dictionary_splat dictionary pair string string_start string_content string_end call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end pair string string_start string_content string_end identifier | Remove runlist from the storage. |
def categories(self):
if not getattr(self, '_categories', False):
self._categories = [re.sub(r'^Category:', '', x) for x in
[link['title']
for link in self.__continued_query({
'prop': 'categories',
'cllimit': 'max'
})
]]
return self._categories | module function_definition identifier parameters identifier block if_statement not_operator call identifier argument_list identifier string string_start string_content string_end false block expression_statement assignment attribute identifier identifier list_comprehension call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_end identifier for_in_clause identifier list_comprehension subscript identifier string string_start string_content string_end for_in_clause identifier call attribute identifier identifier argument_list dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end string string_start string_content string_end return_statement attribute identifier identifier | List of categories of a page. |
def causally_significant_nodes(cm):
inputs = cm.sum(0)
outputs = cm.sum(1)
nodes_with_inputs_and_outputs = np.logical_and(inputs > 0, outputs > 0)
return tuple(np.where(nodes_with_inputs_and_outputs)[0]) | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list integer expression_statement assignment identifier call attribute identifier identifier argument_list integer expression_statement assignment identifier call attribute identifier identifier argument_list comparison_operator identifier integer comparison_operator identifier integer return_statement call identifier argument_list subscript call attribute identifier identifier argument_list identifier integer | Return indices of nodes that have both inputs and outputs. |
def register_db(cls, dbname):
def decorator(subclass):
cls._dbs[dbname] = subclass
subclass.name = dbname
return subclass
return decorator | module function_definition identifier parameters identifier identifier block function_definition identifier parameters identifier block expression_statement assignment subscript attribute identifier identifier identifier identifier expression_statement assignment attribute identifier identifier identifier return_statement identifier return_statement identifier | Register method to keep list of dbs. |
def project(self, lng_lat):
(lng, lat) = lng_lat
x = lng * DEG_TO_RAD
lat = max(min(MAX_LATITUDE, lat), -MAX_LATITUDE)
y = lat * DEG_TO_RAD
y = log(tan((pi / 4) + (y / 2)))
return (x*EARTH_RADIUS, y*EARTH_RADIUS) | module function_definition identifier parameters identifier identifier block expression_statement assignment tuple_pattern identifier identifier identifier expression_statement assignment identifier binary_operator identifier identifier expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier identifier unary_operator identifier expression_statement assignment identifier binary_operator identifier identifier expression_statement assignment identifier call identifier argument_list call identifier argument_list binary_operator parenthesized_expression binary_operator identifier integer parenthesized_expression binary_operator identifier integer return_statement tuple binary_operator identifier identifier binary_operator identifier identifier | Returns the coordinates in meters from WGS84 |
def ExtendAnomalies(self, other):
for o in other:
if o is not None:
self.anomaly.Extend(list(o.anomaly)) | module function_definition identifier parameters identifier identifier block for_statement identifier identifier block if_statement comparison_operator identifier none block expression_statement call attribute attribute identifier identifier identifier argument_list call identifier argument_list attribute identifier identifier | Merge anomalies from another CheckResult. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.