code stringlengths 51 2.34k | sequence stringlengths 186 3.94k | docstring stringlengths 11 171 |
|---|---|---|
def _check_configs(self):
configs = set(self._find_configs())
known_configs = set(self.configs.keys())
new_configs = configs - known_configs
for cfg in (known_configs - configs):
self.log.debug("Compass configuration has been removed: " + cfg)
del self.configs[cfg]
for cfg in new_configs:
self.log.debug("Found new compass configuration: " + cfg)
self.configs[cfg] = CompassConfig(cfg) | module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list call attribute identifier identifier argument_list expression_statement assignment identifier call identifier argument_list call attribute attribute identifier identifier identifier argument_list expression_statement assignment identifier binary_operator identifier identifier for_statement identifier parenthesized_expression binary_operator identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content string_end identifier delete_statement subscript attribute identifier identifier identifier for_statement identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content string_end identifier expression_statement assignment subscript attribute identifier identifier identifier call identifier argument_list identifier | Reloads the configuration files. |
def verify_secret(self, form_instance, secret):
warn_untested()
if not check_secret(form_instance, secret):
self.set_flag("Invalid secret. (%s)") % secret
self.save() | module function_definition identifier parameters identifier identifier identifier block expression_statement call identifier argument_list if_statement not_operator call identifier argument_list identifier identifier block expression_statement binary_operator call attribute identifier identifier argument_list string string_start string_content string_end identifier expression_statement call attribute identifier identifier argument_list | Verifies an IPN payment over SSL using EWP. |
def profile(curr_step, start_step, end_step, profile_name='profile.json',
early_exit=True):
if curr_step == start_step:
mx.nd.waitall()
mx.profiler.set_config(profile_memory=False, profile_symbolic=True,
profile_imperative=True, filename=profile_name,
aggregate_stats=True)
mx.profiler.set_state('run')
elif curr_step == end_step:
mx.nd.waitall()
mx.profiler.set_state('stop')
logging.info(mx.profiler.dumps())
mx.profiler.dump()
if early_exit:
exit() | module function_definition identifier parameters identifier identifier identifier default_parameter identifier string string_start string_content string_end default_parameter identifier true block if_statement comparison_operator identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list keyword_argument identifier false keyword_argument identifier true keyword_argument identifier true keyword_argument identifier identifier keyword_argument identifier true expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end elif_clause comparison_operator identifier identifier block expression_statement 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 identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list if_statement identifier block expression_statement call identifier argument_list | profile the program between [start_step, end_step). |
def update(self, stats):
all_stats = stats.getAllExportsAsDict(plugin_list=self.plugins_to_export())
if self.first_line:
csv_header = ['timestamp']
csv_data = [time.strftime('%Y-%m-%d %H:%M:%S')]
for plugin in self.plugins_to_export():
if isinstance(all_stats[plugin], list):
for stat in all_stats[plugin]:
if self.first_line:
csv_header += ('{}_{}_{}'.format(
plugin, self.get_item_key(stat), item) for item in stat)
csv_data += itervalues(stat)
elif isinstance(all_stats[plugin], dict):
if self.first_line:
fieldnames = iterkeys(all_stats[plugin])
csv_header += ('{}_{}'.format(plugin, fieldname)
for fieldname in fieldnames)
csv_data += itervalues(all_stats[plugin])
if self.first_line:
self.writer.writerow(csv_header)
self.first_line = False
self.writer.writerow(csv_data)
self.csv_file.flush() | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list keyword_argument identifier call attribute identifier identifier argument_list if_statement attribute identifier identifier block expression_statement assignment identifier list string string_start string_content string_end expression_statement assignment identifier list call attribute identifier identifier argument_list string string_start string_content string_end for_statement identifier call attribute identifier identifier argument_list block if_statement call identifier argument_list subscript identifier identifier identifier block for_statement identifier subscript identifier identifier block if_statement attribute identifier identifier block expression_statement augmented_assignment identifier generator_expression call attribute string string_start string_content string_end identifier argument_list identifier call attribute identifier identifier argument_list identifier identifier for_in_clause identifier identifier expression_statement augmented_assignment identifier call identifier argument_list identifier elif_clause call identifier argument_list subscript identifier identifier identifier block if_statement attribute identifier identifier block expression_statement assignment identifier call identifier argument_list subscript identifier identifier expression_statement augmented_assignment identifier generator_expression call attribute string string_start string_content string_end identifier argument_list identifier identifier for_in_clause identifier identifier expression_statement augmented_assignment identifier call identifier argument_list subscript identifier identifier if_statement attribute identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment attribute identifier identifier false expression_statement call attribute attribute identifier identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list | Update stats in the CSV output file. |
def check_python_matlab_architecture(bits, lib_dir):
if not os.path.isdir(lib_dir):
raise RuntimeError("It seem that you are using {bits} version of Python, but there's no matching MATLAB installation in {lib_dir}.".format(bits=bits, lib_dir=lib_dir)) | module function_definition identifier parameters identifier identifier block if_statement not_operator call attribute attribute identifier identifier identifier argument_list identifier block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier | Make sure we can find corresponding installation of Python and MATLAB. |
def update(self, other, **kwargs):
if other is None: return
if not isinstance(other, dict):
other = other.to_dict()
self.__dict__.update(other, **kwargs) | module function_definition identifier parameters identifier identifier dictionary_splat_pattern identifier block if_statement comparison_operator identifier none block return_statement if_statement not_operator call identifier argument_list identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list identifier dictionary_splat identifier | A dict-like update for Struct attributes. |
def read_py(self, fin_txt, get_goids_only, exclude_ungrouped, prt=sys.stdout):
goids_fin = self._read_py(fin_txt, get_goids_only, exclude_ungrouped)
sections = self._read_finish(goids_fin, prt)
if prt is not None:
self._prt_read_msg(prt, fin_txt, exclude_ungrouped)
return sections | module function_definition identifier parameters identifier identifier identifier identifier default_parameter identifier attribute identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier if_statement comparison_operator identifier none block expression_statement call attribute identifier identifier argument_list identifier identifier identifier return_statement identifier | Read GO IDs or sections data from a Python file. |
def _pip_search(stdout, stderr):
result = {}
lines = to_text_string(stdout).split('\n')
while '' in lines:
lines.remove('')
for line in lines:
if ' - ' in line:
parts = line.split(' - ')
name = parts[0].strip()
description = parts[1].strip()
result[name] = description
return result | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier dictionary expression_statement assignment identifier call attribute call identifier argument_list identifier identifier argument_list string string_start string_content escape_sequence string_end while_statement comparison_operator string string_start string_end identifier block expression_statement call attribute identifier identifier argument_list string string_start string_end for_statement identifier identifier block if_statement comparison_operator string string_start string_content string_end 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 subscript identifier integer identifier argument_list expression_statement assignment identifier call attribute subscript identifier integer identifier argument_list expression_statement assignment subscript identifier identifier identifier return_statement identifier | Callback for pip search. |
def listen_init(self):
self.dispatcher = ObjectDispatch(self)
self.factory = MsgPackProtocolFactory(self.dispatcher)
self.server = UnixServer(self.loop, self.factory, self.path)
self.server.start() | module function_definition identifier parameters identifier block expression_statement assignment attribute identifier identifier call identifier argument_list identifier expression_statement assignment attribute identifier identifier call identifier argument_list attribute identifier identifier expression_statement assignment attribute identifier identifier call identifier argument_list attribute identifier identifier attribute identifier identifier attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list | Setup the service to listen for clients. |
def openstack_undercloud_install(self):
instack_undercloud_ver, _ = self.run('repoquery --whatprovides /usr/share/instack-undercloud/puppet-stack-config/puppet-stack-config.pp')
if instack_undercloud_ver.rstrip('\n') == 'instack-undercloud-0:2.2.0-1.el7ost.noarch':
LOG.warn('Workaround for BZ1298189')
self.run("sed -i \"s/.*Keystone_domain\['heat_domain'\].*/Service\['keystone'\] -> Class\['::keystone::roles::admin'\] -> Class\['::heat::keystone::domain'\]/\" /usr/share/instack-undercloud/puppet-stack-config/puppet-stack-config.pp")
self.run('OS_PASSWORD=bob openstack undercloud install', user='stack')
if self.run('rpm -qa openstack-ironic-api')[0].rstrip('\n') == 'openstack-ironic-api-4.2.2-3.el7ost.noarch':
LOG.warn('Workaround for BZ1297796')
self.run('systemctl start openstack-ironic-api.service')
self.add_environment_file(user='stack', filename='stackrc')
self.run('heat stack-list', user='stack') | module function_definition identifier parameters identifier block expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement comparison_operator call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end 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 call attribute identifier identifier argument_list string string_start string_content escape_sequence escape_sequence string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end keyword_argument identifier string string_start string_content string_end if_statement comparison_operator call attribute subscript call attribute identifier identifier argument_list string string_start string_content string_end integer identifier argument_list string string_start string_content escape_sequence string_end 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 call attribute identifier identifier argument_list string string_start string_content string_end 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 expression_statement call attribute identifier identifier argument_list string string_start string_content string_end keyword_argument identifier string string_start string_content string_end | Deploy an undercloud on the host. |
def distancemodulus(d):
if type(d)==Quantity:
x = d.to('pc').value
else:
x = d
if np.size(x)>1:
d = np.atleast_1d(x)
return 5*np.log10(x/10) | module function_definition identifier parameters identifier block if_statement comparison_operator call identifier argument_list identifier identifier block expression_statement assignment identifier attribute call attribute identifier identifier argument_list string string_start string_content string_end identifier else_clause block expression_statement assignment identifier identifier if_statement comparison_operator call attribute identifier identifier argument_list identifier integer block expression_statement assignment identifier call attribute identifier identifier argument_list identifier return_statement binary_operator integer call attribute identifier identifier argument_list binary_operator identifier integer | Returns distance modulus given d in parsec. |
def xml_row(row, lang):
for elem in row:
name = elem.get('name')
child = elem[0]
ftype = re.sub(r'\{[^}]+\}', '', child.tag)
if ftype == 'literal':
ftype = '{}, {}'.format(ftype, child.attrib.get(XML_LANG, 'none'))
yield (name, (child.text, ftype)) | module function_definition identifier parameters identifier identifier block for_statement identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier subscript identifier integer expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_end attribute identifier identifier if_statement comparison_operator identifier string string_start string_content string_end block expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier call attribute attribute identifier identifier identifier argument_list identifier string string_start string_content string_end expression_statement yield tuple identifier tuple attribute identifier identifier identifier | Generator for an XML row |
def visit_for(self, node):
fors = "for %s in %s:\n%s" % (
node.target.accept(self),
node.iter.accept(self),
self._stmt_list(node.body),
)
if node.orelse:
fors = "%s\nelse:\n%s" % (fors, self._stmt_list(node.orelse))
return fors | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier binary_operator string string_start string_content escape_sequence string_end tuple call attribute attribute identifier identifier identifier argument_list identifier call attribute attribute identifier identifier identifier argument_list identifier call attribute identifier identifier argument_list attribute identifier identifier if_statement attribute identifier identifier block expression_statement assignment identifier binary_operator string string_start string_content escape_sequence escape_sequence string_end tuple identifier call attribute identifier identifier argument_list attribute identifier identifier return_statement identifier | return an astroid.For node as string |
def _locate_file(f, base_dir):
if base_dir == None:
return f
file_name = os.path.join(base_dir, f)
real = os.path.realpath(file_name)
return real | module function_definition identifier parameters identifier identifier block if_statement comparison_operator identifier none block return_statement identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier return_statement identifier | Utility method for finding full path to a filename as string |
def create_ssl_context():
ssl_context = ssl.create_default_context(ssl.Purpose.SERVER_AUTH)
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
return ssl_context | module function_definition identifier parameters block expression_statement assignment identifier call attribute identifier identifier argument_list attribute attribute identifier identifier identifier expression_statement assignment attribute identifier identifier false expression_statement assignment attribute identifier identifier attribute identifier identifier return_statement identifier | Create and return SSL Context. |
def _FetchRemapping(type_name, mapping_type, python_name=None, json_name=None,
mappings=None):
if python_name and json_name:
raise exceptions.InvalidDataError(
'Cannot specify both python_name and json_name '
'for %s remapping' % mapping_type)
if not (python_name or json_name):
raise exceptions.InvalidDataError(
'Must specify either python_name or json_name for %s remapping' % (
mapping_type,))
field_remappings = mappings.get(type_name, {})
if field_remappings:
if python_name:
return field_remappings.get(python_name)
elif json_name:
if json_name in list(field_remappings.values()):
return [k for k in field_remappings
if field_remappings[k] == json_name][0]
return None | module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none block if_statement boolean_operator identifier identifier block raise_statement call attribute identifier identifier argument_list binary_operator concatenated_string string string_start string_content string_end string string_start string_content string_end identifier if_statement not_operator parenthesized_expression boolean_operator identifier identifier block raise_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end tuple identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier dictionary if_statement identifier block if_statement identifier block return_statement call attribute identifier identifier argument_list identifier elif_clause identifier block if_statement comparison_operator identifier call identifier argument_list call attribute identifier identifier argument_list block return_statement subscript list_comprehension identifier for_in_clause identifier identifier if_clause comparison_operator subscript identifier identifier identifier integer return_statement none | Common code for fetching a key or value from a remapping dict. |
def run_normalization(self):
for index, media_file in enumerate(
tqdm(
self.media_files,
desc="File",
disable=not self.progress,
position=0
)):
logger.info("Normalizing file {} ({} of {})".format(media_file, index + 1, self.file_count))
media_file.run_normalization()
logger.info("Normalized file written to {}".format(media_file.output_file)) | module function_definition identifier parameters identifier block for_statement pattern_list identifier identifier call identifier argument_list call identifier argument_list attribute identifier identifier keyword_argument identifier string string_start string_content string_end keyword_argument identifier not_operator attribute identifier identifier keyword_argument identifier integer block expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier binary_operator identifier integer attribute identifier identifier expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier | Run the normalization procedures |
def run(wf, *, display, n_threads=1):
worker = dynamic_exclusion_worker(display, n_threads)
return noodles.Scheduler(error_handler=display.error_handler)\
.run(worker, get_workflow(wf)) | module function_definition identifier parameters identifier keyword_separator identifier default_parameter identifier integer block expression_statement assignment identifier call identifier argument_list identifier identifier return_statement call attribute call attribute identifier identifier argument_list keyword_argument identifier attribute identifier identifier line_continuation identifier argument_list identifier call identifier argument_list identifier | Run the workflow using the dynamic-exclusion worker. |
def show_some(items:Collection, n_max:int=5, sep:str=','):
"Return the representation of the first `n_max` elements in `items`."
if items is None or len(items) == 0: return ''
res = sep.join([f'{o}' for o in items[:n_max]])
if len(items) > n_max: res += '...'
return res | module function_definition identifier parameters typed_parameter identifier type identifier typed_default_parameter identifier type identifier integer typed_default_parameter identifier type identifier string string_start string_content string_end block expression_statement string string_start string_content string_end if_statement boolean_operator comparison_operator identifier none comparison_operator call identifier argument_list identifier integer block return_statement string string_start string_end expression_statement assignment identifier call attribute identifier identifier argument_list list_comprehension string string_start interpolation identifier string_end for_in_clause identifier subscript identifier slice identifier if_statement comparison_operator call identifier argument_list identifier identifier block expression_statement augmented_assignment identifier string string_start string_content string_end return_statement identifier | Return the representation of the first `n_max` elements in `items`. |
def clear(self, startBlock, endBlock):
for block in qutepart.iterateBlocksFrom(startBlock):
self._setBlockMarked(block, False)
if block == endBlock:
break | module function_definition identifier parameters identifier identifier identifier block for_statement identifier call attribute identifier identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list identifier false if_statement comparison_operator identifier identifier block break_statement | Clear bookmarks on block range including start and end |
def _parse_columns(self):
column_map = {}
for key, value in self.model.keyMap.items():
record_key = key[1:]
if record_key:
if self.item_key.findall(record_key):
pass
else:
if value['value_datatype'] == 'map':
continue
datatype = value['value_datatype']
if value['value_datatype'] == 'number':
datatype = 'float'
if 'integer_data' in value.keys():
if value['integer_data']:
datatype = 'integer'
replace_key = ''
if 'field_metadata' in value.keys():
if 'replace_key' in value['field_metadata'].keys():
if isinstance(value['field_metadata']['replace_key'], str):
replace_key = value['field_metadata']['replace_key']
max_length = None
if 'max_length' in value.keys():
max_length = value['max_length']
column_map[record_key] = (record_key, datatype, replace_key, max_length)
return column_map | module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary for_statement pattern_list identifier identifier call attribute attribute attribute identifier identifier identifier identifier argument_list block expression_statement assignment identifier subscript identifier slice integer if_statement identifier block if_statement call attribute attribute identifier identifier identifier argument_list identifier block pass_statement else_clause block if_statement comparison_operator subscript identifier string string_start string_content string_end string string_start string_content string_end block continue_statement expression_statement assignment identifier subscript identifier string string_start string_content string_end if_statement comparison_operator subscript identifier string string_start string_content string_end string string_start string_content string_end block expression_statement assignment identifier string string_start string_content string_end if_statement comparison_operator string string_start string_content string_end call attribute identifier identifier argument_list block if_statement subscript identifier string string_start string_content string_end block expression_statement assignment identifier string string_start string_content string_end expression_statement assignment identifier string string_start string_end if_statement comparison_operator string string_start string_content string_end call attribute identifier identifier argument_list block if_statement comparison_operator string string_start string_content string_end call attribute subscript identifier string string_start string_content string_end identifier argument_list block if_statement call identifier argument_list subscript subscript identifier string string_start string_content string_end string string_start string_content string_end identifier block expression_statement assignment identifier subscript subscript identifier string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier none if_statement comparison_operator string string_start string_content string_end call attribute identifier identifier argument_list block expression_statement assignment identifier subscript identifier string string_start string_content string_end expression_statement assignment subscript identifier identifier tuple identifier identifier identifier identifier return_statement identifier | a helper method for parsing the column properties from the record schema |
def url_for(**options):
url_parts = get_url_parts(**options)
image_hash = hashlib.md5(b(options['image_url'])).hexdigest()
url_parts.append(image_hash)
return "/".join(url_parts) | module function_definition identifier parameters dictionary_splat_pattern identifier block expression_statement assignment identifier call identifier argument_list dictionary_splat identifier expression_statement assignment identifier call attribute call attribute identifier identifier argument_list call identifier argument_list subscript identifier string string_start string_content string_end identifier argument_list expression_statement call attribute identifier identifier argument_list identifier return_statement call attribute string string_start string_content string_end identifier argument_list identifier | Returns the url for the specified options |
def single(wosclient, wos_query, xml_query=None, count=5, offset=1):
result = wosclient.search(wos_query, count, offset)
xml = _re.sub(' xmlns="[^"]+"', '', result.records, count=1).encode('utf-8')
if xml_query:
xml = _ET.fromstring(xml)
return [el.text for el in xml.findall(xml_query)]
else:
return _minidom.parseString(xml).toprettyxml() | module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier integer default_parameter identifier integer block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier identifier expression_statement assignment identifier call attribute call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_end attribute identifier identifier keyword_argument identifier integer identifier argument_list string string_start string_content string_end if_statement identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier return_statement list_comprehension attribute identifier identifier for_in_clause identifier call attribute identifier identifier argument_list identifier else_clause block return_statement call attribute call attribute identifier identifier argument_list identifier identifier argument_list | Perform a single Web of Science query and then XML query the results. |
def model(self):
if self.z == 0:
m = self._model
else:
if self._internal_wave_unit.physical_type == 'length':
rs = self._redshift_model.inverse
else:
rs = self._redshift_model
if self.z_type == 'wavelength_only':
m = rs | self._model
else:
m = rs | self._model | self._redshift_flux_model
return m | module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier integer block expression_statement assignment identifier attribute identifier identifier else_clause block if_statement comparison_operator attribute attribute identifier identifier identifier string string_start string_content string_end block expression_statement assignment identifier attribute attribute identifier identifier identifier else_clause block expression_statement assignment identifier attribute identifier identifier if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier binary_operator identifier attribute identifier identifier else_clause block expression_statement assignment identifier binary_operator binary_operator identifier attribute identifier identifier attribute identifier identifier return_statement identifier | Model of the spectrum with given redshift. |
def format_summary(self):
chunks = [chunk.format_chunk_summary()
for chunk in self._progress_chunks]
return "/".join(chunks) | module function_definition identifier parameters identifier block expression_statement assignment identifier list_comprehension call attribute identifier identifier argument_list for_in_clause identifier attribute identifier identifier return_statement call attribute string string_start string_content string_end identifier argument_list identifier | Generate a summary string for the progress bar. |
def cookie_signature(seed, *parts):
sha1 = hmac.new(seed, digestmod=hashlib.sha1)
for part in parts:
if part:
sha1.update(part)
return sha1.hexdigest() | module function_definition identifier parameters identifier list_splat_pattern identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier keyword_argument identifier attribute identifier identifier for_statement identifier identifier block if_statement identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list | Generates a cookie signature. |
def remove_old_dumps(connection, container: str, days=None):
if not days:
return
if days < 20:
LOG.error('A minimum of 20 backups is stored')
return
options = return_file_objects(connection, container)
for dt, o_info in options:
now = datetime.datetime.now()
delta = now - dt
if delta.days > days:
LOG.info('Deleting %s', o_info['name'])
objectstore.delete_object(connection, container, o_info) | module function_definition identifier parameters identifier typed_parameter identifier type identifier default_parameter identifier none block if_statement not_operator identifier block return_statement if_statement comparison_operator identifier integer block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end return_statement expression_statement assignment identifier call identifier argument_list identifier identifier for_statement pattern_list identifier identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list expression_statement assignment identifier binary_operator identifier identifier if_statement comparison_operator attribute identifier identifier identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end subscript identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier identifier identifier | Remove dumps older than x days |
def diff(self):
if not self.present:
if self.existing:
return DEL
return NOOP
is_diff = NOOP
if self.present and self.existing:
a_obj = self.config.copy()
if self.config and diff_dict(a_obj, self.existing, True):
is_diff = CHANGED
if self.description != self.existing.get('description'):
is_diff = CONFLICT
elif self.present and not self.existing:
is_diff = ADD
return is_diff | module function_definition identifier parameters identifier block if_statement not_operator attribute identifier identifier block if_statement attribute identifier identifier block return_statement identifier return_statement identifier expression_statement assignment identifier identifier if_statement boolean_operator attribute identifier identifier attribute identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list if_statement boolean_operator attribute identifier identifier call identifier argument_list identifier attribute identifier identifier true block expression_statement assignment identifier identifier if_statement comparison_operator attribute identifier identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier identifier elif_clause boolean_operator attribute identifier identifier not_operator attribute identifier identifier block expression_statement assignment identifier identifier return_statement identifier | Determines if changes are needed for the Vault backend |
def normalize_path():
whole_path = [
os.path.abspath(path) for path in sys.path if os.path.exists(path)
]
whole_set = collections.OrderedDict((("", 1), (os.getcwd(), 1)))
for path in whole_path:
if path not in whole_set:
whole_set[path] = 1
sys.path = list(whole_set)
for module_ in sys.modules.values():
try:
module_.__path__ = [
os.path.abspath(path)
for path in module_.__path__
if _package_exists(path)
]
except AttributeError:
pass
except ImportError:
pass | module function_definition identifier parameters block expression_statement assignment identifier list_comprehension call attribute attribute identifier identifier identifier argument_list identifier for_in_clause identifier attribute identifier identifier if_clause call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list tuple tuple string string_start string_end integer tuple call attribute identifier identifier argument_list integer for_statement identifier identifier block if_statement comparison_operator identifier identifier block expression_statement assignment subscript identifier identifier integer expression_statement assignment attribute identifier identifier call identifier argument_list identifier for_statement identifier call attribute attribute identifier identifier identifier argument_list block try_statement block expression_statement assignment attribute identifier identifier list_comprehension call attribute attribute identifier identifier identifier argument_list identifier for_in_clause identifier attribute identifier identifier if_clause call identifier argument_list identifier except_clause identifier block pass_statement except_clause identifier block pass_statement | Normalizes sys.path to avoid the use of relative folders |
def safe_record(ctx, item):
if isinstance(item, basestring):
return ctx.env.ref(item)
return item | module function_definition identifier parameters identifier identifier block if_statement call identifier argument_list identifier identifier block return_statement call attribute attribute identifier identifier identifier argument_list identifier return_statement identifier | Make sure we get a record instance even if we pass an xmlid. |
def _build_text_filter(self):
text_filter = TextFilter(logger=self.logger)
self.log(u"Created TextFilter object")
for key, cls, param_name in [
(
gc.PPN_TASK_IS_TEXT_FILE_IGNORE_REGEX,
TextFilterIgnoreRegex,
"regex"
),
(
gc.PPN_TASK_IS_TEXT_FILE_TRANSLITERATE_MAP,
TextFilterTransliterate,
"map_file_path"
)
]:
cls_name = cls.__name__
param_value = gf.safe_get(self.parameters, key, None)
if param_value is not None:
self.log([u"Creating %s object...", cls_name])
params = {
param_name: param_value,
"logger": self.logger
}
try:
inner_filter = cls(**params)
text_filter.add_filter(inner_filter)
self.log([u"Creating %s object... done", cls_name])
except ValueError as exc:
self.log_exc(u"Creating %s object failed" % (cls_name), exc, False, None)
return text_filter | module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list keyword_argument identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end for_statement pattern_list identifier identifier identifier list tuple attribute identifier identifier identifier string string_start string_content string_end tuple attribute identifier identifier identifier string string_start string_content string_end block expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier identifier none if_statement comparison_operator identifier none block expression_statement call attribute identifier identifier argument_list list string string_start string_content string_end identifier expression_statement assignment identifier dictionary pair identifier identifier pair string string_start string_content string_end attribute identifier identifier try_statement block expression_statement assignment identifier call identifier argument_list dictionary_splat identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list list string string_start string_content string_end identifier except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end parenthesized_expression identifier identifier false none return_statement identifier | Build a suitable TextFilter object. |
def embeddedFileCount(self):
if self.isClosed or self.isEncrypted:
raise ValueError("operation illegal for closed / encrypted doc")
return _fitz.Document_embeddedFileCount(self) | module function_definition identifier parameters identifier block if_statement boolean_operator attribute identifier identifier attribute identifier identifier block raise_statement call identifier argument_list string string_start string_content string_end return_statement call attribute identifier identifier argument_list identifier | Return number of embedded files. |
def int_subtype(i, bits, signed) :
"returns integer i after checking that it fits in the given number of bits."
if not isinstance(i, int) :
raise TypeError("value is not int: %s" % repr(i))
if signed :
lo = - 1 << bits - 1
hi = (1 << bits - 1) - 1
else :
lo = 0
hi = (1 << bits) - 1
if i < lo or i > hi :
raise ValueError \
(
"%d not in range of %s %d-bit value" % (i, ("unsigned", "signed")[signed], bits)
)
return \
i | module function_definition identifier parameters identifier identifier identifier block expression_statement string string_start string_content string_end if_statement not_operator call identifier argument_list identifier identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end call identifier argument_list identifier if_statement identifier block expression_statement assignment identifier binary_operator unary_operator integer binary_operator identifier integer expression_statement assignment identifier binary_operator parenthesized_expression binary_operator integer binary_operator identifier integer integer else_clause block expression_statement assignment identifier integer expression_statement assignment identifier binary_operator parenthesized_expression binary_operator integer identifier integer if_statement boolean_operator comparison_operator identifier identifier comparison_operator identifier identifier block raise_statement call identifier line_continuation argument_list binary_operator string string_start string_content string_end tuple identifier subscript tuple string string_start string_content string_end string string_start string_content string_end identifier identifier return_statement line_continuation identifier | returns integer i after checking that it fits in the given number of bits. |
def DumpCurrentSchema(cursor):
cursor.execute("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES "
"WHERE table_schema = (SELECT DATABASE())")
defs = []
for table, in sorted(cursor.fetchall()):
cursor.execute("SHOW CREATE TABLE `{}`".format(table))
rows = cursor.fetchall()
defs.append(rows[0][1])
return "\n\n".join(defs) | module function_definition identifier parameters 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 expression_statement assignment identifier list for_statement pattern_list identifier call identifier argument_list call attribute identifier identifier argument_list block expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list subscript subscript identifier integer integer return_statement call attribute string string_start string_content escape_sequence escape_sequence string_end identifier argument_list identifier | Dumps current database schema. |
def _secret_yaml(loader, node):
fname = os.path.join(os.path.dirname(loader.name), "secrets.yaml")
try:
with open(fname, encoding="utf-8") as secret_file:
secrets = YAML(typ="safe").load(secret_file)
except FileNotFoundError:
raise ValueError("Secrets file {} not found".format(fname)) from None
try:
return secrets[node.value]
except KeyError:
raise ValueError("Secret {} not found".format(node.value)) from None | module function_definition identifier parameters identifier identifier block 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 try_statement block with_statement with_clause with_item as_pattern call identifier argument_list identifier keyword_argument identifier string string_start string_content string_end as_pattern_target identifier block expression_statement assignment identifier call attribute call identifier argument_list keyword_argument identifier string string_start string_content string_end identifier argument_list identifier except_clause identifier block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier none try_statement block return_statement subscript identifier attribute identifier identifier except_clause identifier block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier none | Load secrets and embed it into the configuration YAML. |
def experiment(self):
if self._experiment is None:
self._experiment = list(self.config.experiments.keys())[-1]
return self._experiment | module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier none block expression_statement assignment attribute identifier identifier subscript call identifier argument_list call attribute attribute attribute identifier identifier identifier identifier argument_list unary_operator integer return_statement attribute identifier identifier | The identifier or the experiment that is currently processed |
def main(argv):
del argv
engine = make_gtp_instance(FLAGS.load_file,
cgos_mode=FLAGS.cgos_mode,
kgs_mode=FLAGS.kgs_mode,
minigui_mode=FLAGS.minigui_mode)
dbg("GTP engine ready\n")
for msg in sys.stdin:
if not engine.handle_msg(msg.strip()):
break | module function_definition identifier parameters identifier block delete_statement identifier expression_statement assignment identifier call identifier argument_list attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier expression_statement call identifier argument_list string string_start string_content escape_sequence string_end for_statement identifier attribute identifier identifier block if_statement not_operator call attribute identifier identifier argument_list call attribute identifier identifier argument_list block break_statement | Run Minigo in GTP mode. |
def no_content_response(response):
"Cautious assessment of the response body for no content."
if not hasattr(response, '_container'):
return True
if response._container is None:
return True
if isinstance(response._container, (list, tuple)):
if len(response._container) == 1 and not response._container[0]:
return True
return False | module function_definition identifier parameters identifier block expression_statement string string_start string_content string_end if_statement not_operator call identifier argument_list identifier string string_start string_content string_end block return_statement true if_statement comparison_operator attribute identifier identifier none block return_statement true if_statement call identifier argument_list attribute identifier identifier tuple identifier identifier block if_statement boolean_operator comparison_operator call identifier argument_list attribute identifier identifier integer not_operator subscript attribute identifier identifier integer block return_statement true return_statement false | Cautious assessment of the response body for no content. |
def setOrga(request, hproPk=None):
if settings.PIAPI_STANDALONE:
request.session['plugit-standalone-organame'] = request.GET.get('name')
request.session['plugit-standalone-orgapk'] = request.GET.get('pk')
else:
(_, _, hproject) = getPlugItObject(hproPk)
from organizations.models import Organization
orga = get_object_or_404(Organization, pk=request.GET.get('orga'))
if request.user.is_superuser or orga.isMember(request.user) or orga.isOwner(request.user):
request.session['plugit-orgapk-' + str(hproject.pk)] = orga.pk
return HttpResponse('') | module function_definition identifier parameters identifier default_parameter identifier none block if_statement attribute identifier identifier block expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end else_clause block expression_statement assignment tuple_pattern identifier identifier identifier call identifier argument_list identifier import_from_statement dotted_name identifier identifier dotted_name identifier expression_statement assignment identifier call identifier argument_list identifier keyword_argument identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end if_statement boolean_operator boolean_operator attribute attribute identifier identifier identifier call attribute identifier identifier argument_list attribute identifier identifier call attribute identifier identifier argument_list attribute identifier identifier block expression_statement assignment subscript attribute identifier identifier binary_operator string string_start string_content string_end call identifier argument_list attribute identifier identifier attribute identifier identifier return_statement call identifier argument_list string string_start string_end | Change the current orga |
def _html(self, text):
html = URL_REGEX.sub(self._parse_urls, text)
html = USERNAME_REGEX.sub(self._parse_users, html)
html = LIST_REGEX.sub(self._parse_lists, html)
return HASHTAG_REGEX.sub(self._parse_tags, html) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier identifier return_statement call attribute identifier identifier argument_list attribute identifier identifier identifier | Parse a Tweet and generate HTML. |
def function_parser(function, parser):
parser.set_defaults(func=function)
help_text = inspect.getdoc(function)
main_text, params_help = parser_help_text(help_text)
args, varargs, keywords, defaults = inspect.getargspec(function)
if args is None:
args = []
if defaults is None:
defaults = []
if len(args) and args[0] == 'self':
args.pop(0)
num_required_args = len(args) - len(defaults)
for idx, arg in enumerate(args):
if idx < num_required_args:
arg_name, arg_params = calculate_default_type(arg, False, None, params_help)
else:
default_value = defaults[idx - num_required_args]
arg_name, arg_params = calculate_default_type(arg, True, default_value, params_help)
parser.add_argument(arg_name, **arg_params) | module function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list keyword_argument identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment pattern_list identifier identifier call identifier argument_list identifier expression_statement assignment pattern_list identifier identifier identifier identifier call attribute identifier identifier argument_list identifier if_statement comparison_operator identifier none block expression_statement assignment identifier list if_statement comparison_operator identifier none block expression_statement assignment identifier list if_statement boolean_operator call identifier argument_list identifier comparison_operator subscript identifier integer string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list integer expression_statement assignment identifier binary_operator call identifier argument_list identifier call identifier argument_list identifier for_statement pattern_list identifier identifier call identifier argument_list identifier block if_statement comparison_operator identifier identifier block expression_statement assignment pattern_list identifier identifier call identifier argument_list identifier false none identifier else_clause block expression_statement assignment identifier subscript identifier binary_operator identifier identifier expression_statement assignment pattern_list identifier identifier call identifier argument_list identifier true identifier identifier expression_statement call attribute identifier identifier argument_list identifier dictionary_splat identifier | This function parses a function and adds its arguments to the supplied parser |
def _repair_column(self):
check_for_title = True
for column_index in range(self.start[1], self.end[1]):
table_column = TableTranspose(self.table)[column_index]
column_start = table_column[self.start[0]]
if check_for_title and is_empty_cell(column_start):
self._stringify_column(column_index)
elif (isinstance(column_start, basestring) and
re.search(allregex.year_regex, column_start)):
self._check_stringify_year_column(column_index)
else:
check_for_title = False | module function_definition identifier parameters identifier block expression_statement assignment identifier true for_statement identifier call identifier argument_list subscript attribute identifier identifier integer subscript attribute identifier identifier integer block expression_statement assignment identifier subscript call identifier argument_list attribute identifier identifier identifier expression_statement assignment identifier subscript identifier subscript attribute identifier identifier integer if_statement boolean_operator identifier call identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list identifier elif_clause parenthesized_expression boolean_operator call identifier argument_list identifier identifier call attribute identifier identifier argument_list attribute identifier identifier identifier block expression_statement call attribute identifier identifier argument_list identifier else_clause block expression_statement assignment identifier false | Same as _repair_row but for columns. |
def export_serving(model_path):
pred_config = PredictConfig(
session_init=get_model_loader(model_path),
model=InferenceOnlyModel(),
input_names=['input_img_bytes'],
output_names=['prediction_img_bytes'])
ModelExporter(pred_config).export_serving('/tmp/exported') | module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list keyword_argument identifier call identifier argument_list identifier keyword_argument identifier call identifier argument_list keyword_argument identifier list string string_start string_content string_end keyword_argument identifier list string string_start string_content string_end expression_statement call attribute call identifier argument_list identifier identifier argument_list string string_start string_content string_end | Export trained model to use it in TensorFlow Serving or cloudML. |
def _collect_state_names(self, variable):
"Return a list of states that the variable takes in the data"
states = sorted(list(self.data.ix[:, variable].dropna().unique()))
return states | module function_definition identifier parameters identifier identifier block expression_statement string string_start string_content string_end expression_statement assignment identifier call identifier argument_list call identifier argument_list call attribute call attribute subscript attribute attribute identifier identifier identifier slice identifier identifier argument_list identifier argument_list return_statement identifier | Return a list of states that the variable takes in the data |
def ensure_unicode(text):
u
if isinstance(text, str):
try:
return text.decode(pyreadline_codepage, u"replace")
except (LookupError, TypeError):
return text.decode(u"ascii", u"replace")
return text | module function_definition identifier parameters identifier block expression_statement identifier if_statement call identifier argument_list identifier identifier block try_statement block return_statement call attribute identifier identifier argument_list identifier string string_start string_content string_end except_clause tuple identifier identifier block return_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end return_statement identifier | u"""helper to ensure that text passed to WriteConsoleW is unicode |
def load_stats(self, cache=None, wait=None):
if cache is None:
cache = not self.debug
if wait is None:
wait = self.debug
if not cache or self._stats is None:
self._stats = self._load_stats()
start = time.time()
while wait and self._stats.get('status') == 'compiling':
if self.timeout and (time.time() - start > self.timeout):
raise RuntimeError("Webpack {0!r} timed out while compiling"
.format(self.stats_file.path))
time.sleep(0.1)
self._stats = self._load_stats()
return self._stats | module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none block if_statement comparison_operator identifier none block expression_statement assignment identifier not_operator attribute identifier identifier if_statement comparison_operator identifier none block expression_statement assignment identifier attribute identifier identifier if_statement boolean_operator not_operator identifier comparison_operator attribute identifier identifier none block expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list while_statement boolean_operator identifier comparison_operator call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end block if_statement boolean_operator attribute identifier identifier parenthesized_expression comparison_operator binary_operator call attribute identifier identifier argument_list identifier attribute identifier identifier block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list attribute attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list float expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list return_statement attribute identifier identifier | Load and cache the webpack-stats file |
def blocks(self, lines):
state = markdown.blockparser.State()
blocks = []
state.set('start')
currblock = 0
for line in lines:
line += '\n'
if state.isstate('start'):
if line[:3] == '```':
state.set('```')
else:
state.set('\n')
blocks.append('')
currblock = len(blocks) - 1
else:
marker = line[:3]
if state.isstate(marker):
state.reset()
blocks[currblock] += line
return blocks | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list expression_statement assignment identifier list expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier integer for_statement identifier identifier block expression_statement augmented_assignment identifier string string_start string_content escape_sequence string_end if_statement call attribute identifier identifier argument_list string string_start string_content string_end block if_statement comparison_operator subscript identifier slice integer string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end else_clause block expression_statement call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end expression_statement call attribute identifier identifier argument_list string string_start string_end expression_statement assignment identifier binary_operator call identifier argument_list identifier integer else_clause block expression_statement assignment identifier subscript identifier slice integer if_statement call attribute identifier identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list expression_statement augmented_assignment subscript identifier identifier identifier return_statement identifier | Groups lines into markdown blocks |
def _create_attach_records(self, ids, attributes):
records = []
timed = self._has_pivot_column(self.created_at()) or self._has_pivot_column(
self.updated_at()
)
for key, value in enumerate(ids):
records.append(self._attacher(key, value, attributes, timed))
return records | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier list expression_statement assignment identifier boolean_operator call attribute identifier identifier argument_list call attribute identifier identifier argument_list call attribute identifier identifier argument_list call attribute identifier identifier argument_list for_statement pattern_list identifier identifier call identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier identifier identifier identifier return_statement identifier | Create a list of records to insert into the pivot table. |
def prioritize(self, item, force=False):
with self.condition:
if item in self.working or item in self.force:
return
self.queue.remove(item)
if force:
self.force.append(item)
else:
self.queue.appendleft(item)
self.condition.notify_all() | module function_definition identifier parameters identifier identifier default_parameter identifier false block with_statement with_clause with_item attribute identifier identifier block if_statement boolean_operator comparison_operator identifier attribute identifier identifier comparison_operator identifier attribute identifier identifier block return_statement expression_statement call attribute attribute identifier identifier identifier argument_list identifier if_statement identifier block expression_statement call attribute attribute identifier identifier identifier argument_list identifier else_clause block expression_statement call attribute attribute identifier identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list | Moves the item to the very left of the queue. |
async def command(dev, service, method, parameters):
params = None
if parameters is not None:
params = ast.literal_eval(parameters)
click.echo("Calling %s.%s with params %s" % (service, method, params))
res = await dev.raw_command(service, method, params)
click.echo(res) | module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier none if_statement comparison_operator identifier none block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end tuple identifier identifier identifier expression_statement assignment identifier await call attribute identifier identifier argument_list identifier identifier identifier expression_statement call attribute identifier identifier argument_list identifier | Run a raw command. |
def meminfo():
f = open("/proc/meminfo")
hwinfo = {}
for line in f.readlines():
meml = line.split()
if (meml[0] == "MemTotal:"):
mem = int(meml[1])
hwinfo["Mem_MiB"] = mem/1024
elif (meml[0] == "SwapTotal:"):
swap = int(meml[1])
hwinfo["Swap_MiB"] = swap/1024
f.close()
return hwinfo | module function_definition identifier parameters block expression_statement assignment identifier call identifier argument_list string string_start string_content string_end expression_statement assignment identifier dictionary for_statement identifier call attribute identifier identifier argument_list block expression_statement assignment identifier call attribute identifier identifier argument_list if_statement parenthesized_expression comparison_operator subscript identifier integer string string_start string_content string_end block expression_statement assignment identifier call identifier argument_list subscript identifier integer expression_statement assignment subscript identifier string string_start string_content string_end binary_operator identifier integer elif_clause parenthesized_expression comparison_operator subscript identifier integer string string_start string_content string_end block expression_statement assignment identifier call identifier argument_list subscript identifier integer expression_statement assignment subscript identifier string string_start string_content string_end binary_operator identifier integer expression_statement call attribute identifier identifier argument_list return_statement identifier | Get the amount of memory and swap, Mebibytes |
def record_event(self, event):
with open(self._path, 'a') as file_:
file_.write(str(event) + '\n') | module function_definition identifier parameters identifier identifier 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 binary_operator call identifier argument_list identifier string string_start string_content escape_sequence string_end | Records the ``KindleEvent`` `event` in the store |
def _parallel_predict(estimators, estimators_features, X, n_classes, combination, estimators_weight):
n_samples = X.shape[0]
pred = np.zeros((n_samples, n_classes))
n_estimators = len(estimators)
for estimator, features, weight in zip(estimators, estimators_features, estimators_weight):
predictions = estimator.predict(X[:, features])
for i in range(n_samples):
if combination == 'weighted_voting':
pred[i, int(predictions[i])] += 1 * weight
else:
pred[i, int(predictions[i])] += 1
return pred | module function_definition identifier parameters identifier identifier identifier identifier identifier identifier block expression_statement assignment identifier subscript attribute identifier identifier integer expression_statement assignment identifier call attribute identifier identifier argument_list tuple identifier identifier expression_statement assignment identifier call identifier argument_list identifier for_statement pattern_list identifier identifier identifier call identifier argument_list identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list subscript identifier slice identifier for_statement identifier call identifier argument_list identifier block if_statement comparison_operator identifier string string_start string_content string_end block expression_statement augmented_assignment subscript identifier identifier call identifier argument_list subscript identifier identifier binary_operator integer identifier else_clause block expression_statement augmented_assignment subscript identifier identifier call identifier argument_list subscript identifier identifier integer return_statement identifier | Private function used to compute predictions within a job. |
def kill(self, jid):
greenlet = self.greenlets.get(jid)
if greenlet is not None:
logger.warn('Lost ownership of %s' % jid)
greenlet.kill() | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier if_statement comparison_operator identifier none block expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end identifier expression_statement call attribute identifier identifier argument_list | Stop the greenlet processing the provided jid |
def process_environment_settings(default_dictionary: dict, settings: typing.Optional[dict]=None,
presets: typing.Optional[dict]=None):
settings = settings if settings is not None else {}
presets = presets if presets is not None else {}
env_keys = sorted(set(default_dictionary.keys()) | set(presets.keys()))
result_dict = {}
for key in env_keys:
if key in default_dictionary:
new_dict = default_dictionary[key].copy()
else:
new_dict = {}
new_dict.update(settings)
if key in presets:
new_dict.update(presets[key])
result_dict[key] = new_dict
return result_dict | module function_definition identifier parameters typed_parameter identifier type identifier typed_default_parameter identifier type subscript attribute identifier identifier identifier none typed_default_parameter identifier type subscript attribute identifier identifier identifier none block expression_statement assignment identifier conditional_expression identifier comparison_operator identifier none dictionary expression_statement assignment identifier conditional_expression identifier comparison_operator identifier none dictionary expression_statement assignment identifier call identifier argument_list binary_operator call identifier argument_list call attribute identifier identifier argument_list call identifier argument_list call attribute identifier identifier argument_list expression_statement assignment identifier dictionary for_statement identifier identifier block if_statement comparison_operator identifier identifier block expression_statement assignment identifier call attribute subscript identifier identifier identifier argument_list else_clause block expression_statement assignment identifier dictionary expression_statement call attribute identifier identifier argument_list identifier if_statement comparison_operator identifier identifier block expression_statement call attribute identifier identifier argument_list subscript identifier identifier expression_statement assignment subscript identifier identifier identifier return_statement identifier | Process a dictionary of env settings |
def _log_app_data(self):
if self.install_json:
app_commit_hash = self.install_json.get('commitHash')
app_features = ','.join(self.install_json.get('features', []))
app_min_ver = self.install_json.get('minServerVersion', 'N/A')
app_name = self.install_json.get('displayName')
app_runtime_level = self.install_json.get('runtimeLevel')
app_version = self.install_json.get('programVersion')
self.log.info(u'App Name: {}'.format(app_name))
if app_features:
self.log.info(u'App Features: {}'.format(app_features))
self.log.info(u'App Minimum ThreatConnect Version: {}'.format(app_min_ver))
self.log.info(u'App Runtime Level: {}'.format(app_runtime_level))
self.log.info(u'App Version: {}'.format(app_version))
if app_commit_hash is not None:
self.log.info(u'App Commit Hash: {}'.format(app_commit_hash)) | module function_definition identifier parameters identifier block if_statement attribute identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end list expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier 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 string string_start string_content string_end identifier argument_list identifier if_statement 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 expression_statement call attribute attribute identifier identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier if_statement comparison_operator identifier none block expression_statement call attribute attribute identifier identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier | Log the App data information. |
def sorted(self, wantdirs=False):
def add_dir(dirs, d):
dirs.add(d)
logger.debug('add_dir added %s', d)
if d != self.base:
parent, _ = os.path.split(d)
assert parent not in ('', '/')
add_dir(dirs, parent)
result = set(self.files)
if wantdirs:
dirs = set()
for f in result:
add_dir(dirs, os.path.dirname(f))
result |= dirs
return [os.path.join(*path_tuple) for path_tuple in
sorted(os.path.split(path) for path in result)] | module function_definition identifier parameters identifier default_parameter identifier false block function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier if_statement comparison_operator identifier attribute identifier identifier block expression_statement assignment pattern_list identifier identifier call attribute attribute identifier identifier identifier argument_list identifier assert_statement comparison_operator identifier tuple string string_start string_end string string_start string_content string_end expression_statement call identifier argument_list identifier identifier expression_statement assignment identifier call identifier argument_list attribute identifier identifier if_statement identifier block expression_statement assignment identifier call identifier argument_list for_statement identifier identifier block expression_statement call identifier argument_list identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement augmented_assignment identifier identifier return_statement list_comprehension call attribute attribute identifier identifier identifier argument_list list_splat identifier for_in_clause identifier call identifier generator_expression call attribute attribute identifier identifier identifier argument_list identifier for_in_clause identifier identifier | Return sorted files in directory order |
def update_rbac_policy(self, rbac_policy_id, body=None):
return self.put(self.rbac_policy_path % rbac_policy_id, body=body) | module function_definition identifier parameters identifier identifier default_parameter identifier none block return_statement call attribute identifier identifier argument_list binary_operator attribute identifier identifier identifier keyword_argument identifier identifier | Update a RBAC policy. |
def plantloopfieldlists(data):
objkey = 'plantloop'.upper()
numobjects = len(data.dt[objkey])
return [[
'Name',
'Plant Side Inlet Node Name',
'Plant Side Outlet Node Name',
'Plant Side Branch List Name',
'Demand Side Inlet Node Name',
'Demand Side Outlet Node Name',
'Demand Side Branch List Name']] * numobjects | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list expression_statement assignment identifier call identifier argument_list subscript attribute identifier identifier identifier return_statement binary_operator list list string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end identifier | return the plantloopfield list |
def _compute_dlt(self):
res = super()._compute_dlt()
for rec in self:
ltaf_to_apply = self.env['ddmrp.adjustment'].search(
rec._ltaf_to_apply_domain())
if ltaf_to_apply:
ltaf = 1
values = ltaf_to_apply.mapped('value')
for val in values:
ltaf *= val
prev = rec.dlt
rec.dlt *= ltaf
_logger.debug(
"LTAF=%s applied to %s. DLT: %s -> %s" %
(ltaf, rec.name, prev, rec.dlt))
return res | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute call identifier argument_list identifier argument_list for_statement identifier identifier block expression_statement assignment identifier call attribute subscript attribute identifier identifier string string_start string_content string_end identifier argument_list call attribute identifier identifier argument_list if_statement identifier block expression_statement assignment identifier integer expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end for_statement identifier identifier block expression_statement augmented_assignment identifier identifier expression_statement assignment identifier attribute identifier identifier expression_statement augmented_assignment attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end tuple identifier attribute identifier identifier identifier attribute identifier identifier return_statement identifier | Apply Lead Time Adj Factor if existing |
def load(self, fileobj):
for loader in (pickle.load, json.load, csv.reader):
fileobj.seek(0)
try:
return self.initial_update(loader(fileobj))
except Exception as e:
pass
raise ValueError('File not in a supported format') | module function_definition identifier parameters identifier identifier block for_statement identifier tuple attribute identifier identifier attribute identifier identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list integer try_statement block return_statement call attribute identifier identifier argument_list call identifier argument_list identifier except_clause as_pattern identifier as_pattern_target identifier block pass_statement raise_statement call identifier argument_list string string_start string_content string_end | Load the dict from the file object |
def _lob_start_handler(c, ctx):
assert c == _OPEN_BRACE
c, self = yield
trans = ctx.immediate_transition(self)
quotes = 0
while True:
if c in _WHITESPACE:
if quotes > 0:
_illegal_character(c, ctx)
elif c == _DOUBLE_QUOTE:
if quotes > 0:
_illegal_character(c, ctx)
ctx.set_ion_type(IonType.CLOB).set_unicode(quoted_text=True)
yield ctx.immediate_transition(_short_string_handler(c, ctx))
elif c == _SINGLE_QUOTE:
if not quotes:
ctx.set_ion_type(IonType.CLOB).set_unicode(quoted_text=True)
quotes += 1
if quotes == 3:
yield ctx.immediate_transition(_long_string_handler(c, ctx))
else:
yield ctx.immediate_transition(_blob_end_handler(c, ctx))
c, _ = yield trans | module function_definition identifier parameters identifier identifier block assert_statement comparison_operator identifier identifier expression_statement assignment pattern_list identifier identifier yield expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier integer while_statement true block if_statement comparison_operator identifier identifier block if_statement comparison_operator identifier integer block expression_statement call identifier argument_list identifier identifier elif_clause comparison_operator identifier identifier block if_statement comparison_operator identifier integer block expression_statement call identifier argument_list identifier identifier expression_statement call attribute call attribute identifier identifier argument_list attribute identifier identifier identifier argument_list keyword_argument identifier true expression_statement yield call attribute identifier identifier argument_list call identifier argument_list identifier identifier elif_clause comparison_operator identifier identifier block if_statement not_operator identifier block expression_statement call attribute call attribute identifier identifier argument_list attribute identifier identifier identifier argument_list keyword_argument identifier true expression_statement augmented_assignment identifier integer if_statement comparison_operator identifier integer block expression_statement yield call attribute identifier identifier argument_list call identifier argument_list identifier identifier else_clause block expression_statement yield call attribute identifier identifier argument_list call identifier argument_list identifier identifier expression_statement assignment pattern_list identifier identifier yield identifier | Handles tokens that begin with two open braces. |
def combination_memo(n, r):
memo = {}
def recur(n, r):
if n == r or r == 0:
return 1
if (n, r) not in memo:
memo[(n, r)] = recur(n - 1, r - 1) + recur(n - 1, r)
return memo[(n, r)]
return recur(n, r) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier dictionary function_definition identifier parameters identifier identifier block if_statement boolean_operator comparison_operator identifier identifier comparison_operator identifier integer block return_statement integer if_statement comparison_operator tuple identifier identifier identifier block expression_statement assignment subscript identifier tuple identifier identifier binary_operator call identifier argument_list binary_operator identifier integer binary_operator identifier integer call identifier argument_list binary_operator identifier integer identifier return_statement subscript identifier tuple identifier identifier return_statement call identifier argument_list identifier identifier | This function calculates nCr using memoization method. |
def _is_broken_ref(key1, value1, key2, value2):
if key1 != 'Link' or key2 != 'Str':
return False
n = 0 if _PANDOCVERSION < '1.16' else 1
if isinstance(value1[n][0]['c'], list):
return False
s = value1[n][0]['c'] + value2
return True if _REF.match(s) else False | module function_definition identifier parameters identifier identifier identifier identifier block if_statement boolean_operator comparison_operator identifier string string_start string_content string_end comparison_operator identifier string string_start string_content string_end block return_statement false expression_statement assignment identifier conditional_expression integer comparison_operator identifier string string_start string_content string_end integer if_statement call identifier argument_list subscript subscript subscript identifier identifier integer string string_start string_content string_end identifier block return_statement false expression_statement assignment identifier binary_operator subscript subscript subscript identifier identifier integer string string_start string_content string_end identifier return_statement conditional_expression true call attribute identifier identifier argument_list identifier false | True if this is a broken reference; False otherwise. |
def _to_solr(self, data):
return self._dest.index_json(self._dest_coll, json.dumps(data,sort_keys=True)) | module function_definition identifier parameters identifier identifier block return_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier call attribute identifier identifier argument_list identifier keyword_argument identifier true | Sends data to a Solr instance. |
def defvar(varname):
if 'pyraf' in sys.modules:
from pyraf import iraf
else:
iraf = None
if iraf:
_irafdef = iraf.envget(varname)
else:
_irafdef = 0
return varname in _varDict or varname in os.environ or _irafdef | module function_definition identifier parameters identifier block if_statement comparison_operator string string_start string_content string_end attribute identifier identifier block import_from_statement dotted_name identifier dotted_name identifier else_clause block expression_statement assignment identifier none if_statement identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier else_clause block expression_statement assignment identifier integer return_statement boolean_operator boolean_operator comparison_operator identifier identifier comparison_operator identifier attribute identifier identifier identifier | Returns true if CL variable is defined. |
def _get_agg_font(self, prop):
if __debug__: verbose.report('RendererAgg._get_agg_font',
'debug-annoying')
key = hash(prop)
font = RendererAgg._fontd.get(key)
if font is None:
fname = findfont(prop)
font = RendererAgg._fontd.get(fname)
if font is None:
font = FT2Font(
str(fname),
hinting_factor=rcParams['text.hinting_factor'])
RendererAgg._fontd[fname] = font
RendererAgg._fontd[key] = font
font.clear()
size = prop.get_size_in_points()
font.set_size(size, self.dpi)
return font | module function_definition identifier parameters identifier identifier block if_statement identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier if_statement comparison_operator identifier none block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier if_statement comparison_operator identifier none block expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier keyword_argument identifier subscript identifier string string_start string_content string_end expression_statement assignment subscript attribute identifier identifier identifier identifier expression_statement assignment subscript attribute identifier identifier identifier identifier expression_statement call attribute identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list identifier attribute identifier identifier return_statement identifier | Get the font for text instance t, cacheing for efficiency |
def to_json(self):
result = super(Space, self).to_json()
result.update({'name': self.name})
return result | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute call identifier argument_list identifier identifier identifier argument_list expression_statement call attribute identifier identifier argument_list dictionary pair string string_start string_content string_end attribute identifier identifier return_statement identifier | Returns the JSON representation of the space. |
def _get_metadata_as_string(self):
metalist = []
for metaname, meta in iteritems(self.metadata):
message = "Single value in metadata dictionary should be a list!"
assert isinstance(meta, list), message
for data in meta:
if data:
metalist.append("!%s_%s = %s" % (self.geotype.capitalize(),
metaname, data))
return "\n".join(metalist) | module function_definition identifier parameters identifier block expression_statement assignment identifier list for_statement pattern_list identifier identifier call identifier argument_list attribute identifier identifier block expression_statement assignment identifier string string_start string_content string_end assert_statement call identifier argument_list identifier identifier identifier for_statement identifier identifier block if_statement identifier block expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end tuple call attribute attribute identifier identifier identifier argument_list identifier identifier return_statement call attribute string string_start string_content escape_sequence string_end identifier argument_list identifier | Get the metadata as SOFT formatted string. |
def _repr_values(self):
def getattr_better(obj, field):
try:
return getattr(obj, field)
except AttributeError as e:
try:
return getattr(obj, '_' + field)
except AttributeError:
raise e
return (getattr_better(self, attr) for attr in self._repr_attributes) | module function_definition identifier parameters identifier block function_definition identifier parameters identifier identifier block try_statement block return_statement call identifier argument_list identifier identifier except_clause as_pattern identifier as_pattern_target identifier block try_statement block return_statement call identifier argument_list identifier binary_operator string string_start string_content string_end identifier except_clause identifier block raise_statement identifier return_statement generator_expression call identifier argument_list identifier identifier for_in_clause identifier attribute identifier identifier | Return values that are to be shown in repr string. |
def extract(self, file_path):
import tarfile
print('Extracting {}'.format(file_path))
if not os.path.exists(self.extracted_data_directory):
os.makedirs(self.extracted_data_directory)
def track_progress(members):
sys.stdout.write('.')
for member in members:
yield member
with tarfile.open(file_path) as tar:
tar.extractall(path=self.extracted_data_directory, members=track_progress(tar))
self.chatbot.logger.info('File extracted to {}'.format(self.extracted_data_directory))
return True | module function_definition identifier parameters identifier identifier block import_statement dotted_name identifier expression_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier if_statement not_operator call attribute attribute identifier identifier identifier argument_list attribute identifier identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end for_statement identifier identifier block expression_statement yield identifier with_statement with_clause with_item as_pattern call attribute identifier identifier argument_list identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list keyword_argument identifier attribute identifier identifier keyword_argument identifier call identifier argument_list identifier expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier return_statement true | Extract a tar file at the specified file path. |
def init(self):
self.target.halt()
self.target.reset_and_halt()
result = self._call_function_and_wait(self.flash_algo['pc_init'], init=True)
if result != 0:
logging.error('init error: %i', result)
self.erase_sector(0x01000000)
time.sleep(.5)
self.target.dp.reset()
time.sleep(1.3)
self.target.dp.init()
self.target.dp.power_up_debug()
self.target.halt()
self.target.reset_and_halt()
result = self._call_function_and_wait(self.flash_algo['pc_init'], init=True)
if result != 0:
logging.error('init error: %i', result) | module function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list subscript attribute identifier identifier string string_start string_content string_end keyword_argument identifier true if_statement comparison_operator identifier integer block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier expression_statement call attribute identifier identifier argument_list integer expression_statement call attribute identifier identifier argument_list float expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list expression_statement call attribute identifier identifier argument_list float expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list subscript attribute identifier identifier string string_start string_content string_end keyword_argument identifier true if_statement comparison_operator identifier integer block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier | Download the flash algorithm in RAM |
def extern_store_utf8(self, context_handle, utf8_ptr, utf8_len):
c = self._ffi.from_handle(context_handle)
return c.to_value(self._ffi.string(utf8_ptr, utf8_len).decode('utf-8')) | module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list call attribute call attribute attribute identifier identifier identifier argument_list identifier identifier identifier argument_list string string_start string_content string_end | Given a context and UTF8 bytes, return a new Handle to represent the content. |
def start_process(self, key):
if key in self.processes and key in self.paused:
os.killpg(os.getpgid(self.processes[key].pid), signal.SIGCONT)
self.queue[key]['status'] = 'running'
self.paused.remove(key)
return True
elif key not in self.processes:
if self.queue[key]['status'] in ['queued', 'stashed']:
self.spawn_new(key)
return True
return False | module function_definition identifier parameters identifier identifier block if_statement boolean_operator comparison_operator identifier attribute identifier identifier comparison_operator identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list attribute subscript attribute identifier identifier identifier identifier attribute identifier identifier expression_statement assignment subscript subscript attribute identifier identifier identifier string string_start string_content string_end string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list identifier return_statement true elif_clause comparison_operator identifier attribute identifier identifier block if_statement comparison_operator subscript subscript attribute identifier identifier identifier string string_start string_content string_end list string string_start string_content string_end string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list identifier return_statement true return_statement false | Start a specific processes. |
def remove_callback(obj, handle):
callbacks = obj._callbacks
if callbacks is handle:
obj._callbacks = None
elif isinstance(callbacks, dllist):
callbacks.remove(handle)
if not callbacks:
obj._callbacks = None | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier attribute identifier identifier if_statement comparison_operator identifier identifier block expression_statement assignment attribute identifier identifier none elif_clause call identifier argument_list identifier identifier block expression_statement call attribute identifier identifier argument_list identifier if_statement not_operator identifier block expression_statement assignment attribute identifier identifier none | Remove a callback from an object. |
def constraints(self, chunk):
a = [self._map1[w.index] for w in chunk.words if w.index in self._map1]
b = []; [b.append(constraint) for constraint in a if constraint not in b]
return b | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier list_comprehension subscript attribute identifier identifier attribute identifier identifier for_in_clause identifier attribute identifier identifier if_clause comparison_operator attribute identifier identifier attribute identifier identifier expression_statement assignment identifier list expression_statement list_comprehension call attribute identifier identifier argument_list identifier for_in_clause identifier identifier if_clause comparison_operator identifier identifier return_statement identifier | Returns a list of constraints that match the given Chunk. |
def inverse(self):
if self._inverse is None:
self._inverse = InverseTransform(self)
return self._inverse | module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier none block expression_statement assignment attribute identifier identifier call identifier argument_list identifier return_statement attribute identifier identifier | The inverse of this transform. |
def _set_data(self, data):
if type(data) == bytearray:
self._data = data
elif type(data) == str:
if sys.version_info < (3,):
self._data = bytearray(data)
else:
self._data = bytearray(data.encode('ISO-8859-1'))
elif type(data) == list or type(data) == tuple:
self._data = bytearray(data)
elif sys.version_info >= (3,) and type(data) == bytes:
self._data = bytearray(data)
else:
raise Exception('Data must be bytearray, string, list or tuple,'
' not {}'.format(type(data))) | module function_definition identifier parameters identifier identifier block if_statement comparison_operator call identifier argument_list identifier identifier block expression_statement assignment attribute identifier identifier identifier elif_clause comparison_operator call identifier argument_list identifier identifier block if_statement comparison_operator attribute identifier identifier tuple integer block expression_statement assignment attribute identifier identifier call identifier argument_list identifier else_clause block expression_statement assignment attribute identifier identifier call identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end elif_clause boolean_operator comparison_operator call identifier argument_list identifier identifier comparison_operator call identifier argument_list identifier identifier block expression_statement assignment attribute identifier identifier call identifier argument_list identifier elif_clause boolean_operator comparison_operator attribute identifier identifier tuple integer comparison_operator call identifier argument_list identifier identifier block expression_statement assignment attribute identifier identifier call identifier argument_list identifier else_clause block raise_statement call identifier argument_list call attribute concatenated_string string string_start string_content string_end string string_start string_content string_end identifier argument_list call identifier argument_list identifier | Set the packet data |
def ip_registrant_monitor(self, query, days_back=0, search_type="all", server=None, country=None, org=None, page=1,
include_total_count=False, **kwargs):
return self._results('ip-registrant-monitor', '/v1/ip-registrant-monitor', query=query,
days_back=days_back, search_type=search_type, server=server, country=country, org=org,
page=page, include_total_count=include_total_count, **kwargs) | module function_definition identifier parameters identifier identifier default_parameter identifier integer default_parameter identifier string string_start string_content string_end default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier integer default_parameter identifier false dictionary_splat_pattern identifier block return_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier dictionary_splat identifier | Query based on free text query terms |
def deploy(verbose, app):
config = PsiturkConfig()
config.load_config()
config.set("Experiment Configuration", "mode", "deploy")
config.set("Server Parameters", "logfile", "-")
config.set("Shell Parameters", "launch_in_sandbox_mode", "false")
deploy_sandbox_shared_setup(verbose=verbose, app=app) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end expression_statement call identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier | Deploy app using Heroku to MTurk. |
def decode_signature(sigb64):
sig_bin = base64.b64decode(sigb64)
if len(sig_bin) != 64:
raise ValueError("Invalid base64 signature")
sig_hex = sig_bin.encode('hex')
sig_r = int(sig_hex[:64], 16)
sig_s = int(sig_hex[64:], 16)
return sig_r, sig_s | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement comparison_operator call identifier argument_list identifier integer block raise_statement call 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 assignment identifier call identifier argument_list subscript identifier slice integer integer expression_statement assignment identifier call identifier argument_list subscript identifier slice integer integer return_statement expression_list identifier identifier | Decode a signature into r, s |
def currentVersion(self):
if self._currentVersion is None:
self.__init(self._url)
return self._currentVersion | module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier none block expression_statement call attribute identifier identifier argument_list attribute identifier identifier return_statement attribute identifier identifier | returns the current version of the site |
def _is_complex(pe):
val = isinstance(pe, _bp('Complex')) or \
isinstance(pe, _bpimpl('Complex'))
return val | module function_definition identifier parameters identifier block expression_statement assignment identifier boolean_operator call identifier argument_list identifier call identifier argument_list string string_start string_content string_end line_continuation call identifier argument_list identifier call identifier argument_list string string_start string_content string_end return_statement identifier | Return True if the physical entity is a complex |
def normalise_key(self, key):
key = key.replace('-', '_')
if key.startswith("noy_"):
key = key[4:]
return key | module function_definition identifier parameters identifier identifier 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 if_statement call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier subscript identifier slice integer return_statement identifier | Make sure key is a valid python attribute |
def start_batch(job, input_args):
samples = parse_sra(input_args['sra'])
job.addChildJobFn(download_and_transfer_sample, input_args, samples, cores=1, disk='30') | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list subscript identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier identifier identifier keyword_argument identifier integer keyword_argument identifier string string_start string_content string_end | This function will administer 5 jobs at a time then recursively call itself until subset is empty |
def annotatedcore(self):
logging.info('Calculating annotated core')
self.total_core()
for sample in self.metadata:
if sample.general.bestassemblyfile != 'NA':
sample[self.analysistype].coreset = set()
if sample.general.referencegenus == 'Escherichia':
self.runmetadata.samples.append(sample)
try:
report = sample[self.analysistype].report
self.blastparser(report=report,
sample=sample,
fieldnames=self.fieldnames)
except KeyError:
sample[self.analysistype].coreset = list()
self.reporter() | module function_definition identifier parameters 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 for_statement identifier attribute identifier identifier block if_statement comparison_operator attribute attribute identifier identifier identifier string string_start string_content string_end block expression_statement assignment attribute subscript identifier attribute identifier identifier identifier call identifier argument_list if_statement comparison_operator attribute attribute identifier identifier identifier string string_start string_content string_end block expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list identifier try_statement block expression_statement assignment identifier attribute subscript identifier attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier keyword_argument identifier attribute identifier identifier except_clause identifier block expression_statement assignment attribute subscript identifier attribute identifier identifier identifier call identifier argument_list expression_statement call attribute identifier identifier argument_list | Calculates the core genome of organisms using custom databases |
def period(
start, end, absolute=False
):
return Period(start, end, absolute=absolute) | module function_definition identifier parameters identifier identifier default_parameter identifier false block return_statement call identifier argument_list identifier identifier keyword_argument identifier identifier | Create a Period instance. |
def _save_cache(self):
safe_makedirs(self.cache_dir)
try:
with open(self.cache_file, 'wb') as f:
pickle.dump(self.data, f)
except Exception as e:
logger.error("Cannot write version to cache file {} ({})".format(self.cache_file, e)) | module function_definition identifier parameters identifier block expression_statement call identifier argument_list attribute identifier identifier 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 except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier identifier | Save data to the cache file. |
def GoZero(self, speed):
' Go to Zero position '
self.ReleaseSW()
spi.SPI_write_byte(self.CS, 0x82 | (self.Dir & 1))
spi.SPI_write_byte(self.CS, 0x00)
spi.SPI_write_byte(self.CS, speed)
while self.IsBusy():
pass
time.sleep(0.3)
self.ReleaseSW() | module function_definition identifier parameters identifier identifier block expression_statement string string_start string_content string_end expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list attribute identifier identifier binary_operator integer parenthesized_expression binary_operator attribute identifier identifier integer expression_statement call attribute identifier identifier argument_list attribute identifier identifier integer expression_statement call attribute identifier identifier argument_list attribute identifier identifier identifier while_statement call attribute identifier identifier argument_list block pass_statement expression_statement call attribute identifier identifier argument_list float expression_statement call attribute identifier identifier argument_list | Go to Zero position |
def _handle_single_tag_end(self):
stack = self._stack
depth = 1
for index, token in enumerate(stack[2:], 2):
if isinstance(token, tokens.TagOpenOpen):
depth += 1
elif isinstance(token, tokens.TagCloseOpen):
depth -= 1
if depth == 0:
break
elif isinstance(token, tokens.TagCloseSelfclose):
depth -= 1
if depth == 0:
raise ParserError(
"_handle_single_tag_end() got an unexpected "
"TagCloseSelfclose")
else:
raise ParserError("_handle_single_tag_end() missed a TagCloseOpen")
padding = stack[index].padding
stack[index] = tokens.TagCloseSelfclose(padding=padding, implicit=True)
return self._pop() | module function_definition identifier parameters identifier block expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier integer for_statement pattern_list identifier identifier call identifier argument_list subscript identifier slice integer integer block if_statement call identifier argument_list identifier attribute identifier identifier block expression_statement augmented_assignment identifier integer elif_clause call identifier argument_list identifier attribute identifier identifier block expression_statement augmented_assignment identifier integer if_statement comparison_operator identifier integer block break_statement elif_clause call identifier argument_list identifier attribute identifier identifier block expression_statement augmented_assignment identifier integer if_statement comparison_operator identifier integer block raise_statement call identifier argument_list concatenated_string string string_start string_content string_end string string_start string_content string_end else_clause block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment identifier attribute subscript identifier identifier identifier expression_statement assignment subscript identifier identifier call attribute identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier true return_statement call attribute identifier identifier argument_list | Handle the stream end when inside a single-supporting HTML tag. |
def match(self, *args):
self.fall = self.fall or not args
self.fall = self.fall or (self.value in args)
return self.fall | module function_definition identifier parameters identifier list_splat_pattern identifier block expression_statement assignment attribute identifier identifier boolean_operator attribute identifier identifier not_operator identifier expression_statement assignment attribute identifier identifier boolean_operator attribute identifier identifier parenthesized_expression comparison_operator attribute identifier identifier identifier return_statement attribute identifier identifier | Whether or not to enter a given case statement |
def read(self):
if self.lines and self.chunksize:
obj = concat(self)
elif self.lines:
data = to_str(self.data)
obj = self._get_object_parser(
self._combine_lines(data.split('\n'))
)
else:
obj = self._get_object_parser(self.data)
self.close()
return obj | module function_definition identifier parameters identifier block if_statement boolean_operator attribute identifier identifier attribute identifier identifier block expression_statement assignment identifier call identifier argument_list identifier elif_clause attribute identifier identifier block expression_statement assignment identifier call identifier argument_list attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list call attribute identifier identifier argument_list call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list return_statement identifier | Read the whole JSON input into a pandas object. |
def api_notifications():
event_type = request.values['Event.1.EventType']
assignment_id = request.values['Event.1.AssignmentId']
db.logger.debug('rq: Queueing %s with id: %s for worker_function',
event_type, assignment_id)
q.enqueue(worker_function, event_type, assignment_id, None)
db.logger.debug('rq: Submitted Queue Length: %d (%s)', len(q),
', '.join(q.job_ids))
return success_response(request_type="notification") | module function_definition identifier parameters block expression_statement assignment identifier subscript attribute identifier identifier string string_start string_content string_end expression_statement assignment identifier subscript attribute identifier identifier string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end identifier identifier expression_statement call attribute identifier identifier argument_list identifier identifier identifier none expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier return_statement call identifier argument_list keyword_argument identifier string string_start string_content string_end | Receive MTurk REST notifications. |
def _parse_certificate(cls, response):
links = _parse_header_links(response)
try:
cert_chain_uri = links[u'up'][u'url']
except KeyError:
cert_chain_uri = None
return (
response.content()
.addCallback(
lambda body: messages.CertificateResource(
uri=cls._maybe_location(response),
cert_chain_uri=cert_chain_uri,
body=body))
) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list identifier try_statement block expression_statement assignment identifier subscript subscript identifier string string_start string_content string_end string string_start string_content string_end except_clause identifier block expression_statement assignment identifier none return_statement parenthesized_expression call attribute call attribute identifier identifier argument_list identifier argument_list lambda lambda_parameters identifier call attribute identifier identifier argument_list keyword_argument identifier call attribute identifier identifier argument_list identifier keyword_argument identifier identifier keyword_argument identifier identifier | Parse a response containing a certificate resource. |
def process_exception(self, request, exception):
log_format = self._get_log_format(request)
if log_format is None:
return
params = self._get_parameters_from_request(request, True)
params['message'] = exception
params['http_status'] = '-'
self.OPERATION_LOG.info(log_format, params) | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement comparison_operator identifier none block return_statement expression_statement assignment identifier call attribute identifier identifier argument_list identifier true expression_statement assignment subscript identifier string string_start string_content string_end identifier expression_statement assignment subscript identifier string string_start string_content string_end string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list identifier identifier | Log error info when exception occurred. |
def start(cls):
if cls._thread is None:
cls._thread = threading.Thread(target=cls._run, name="Heartbeat")
cls._thread.daemon = True
cls._thread.start() | 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 keyword_argument identifier attribute identifier identifier keyword_argument identifier string string_start string_content string_end expression_statement assignment attribute attribute identifier identifier identifier true expression_statement call attribute attribute identifier identifier identifier argument_list | Start background thread if not already started |
def open_fd(cls, name):
try:
return os.open(name, os.O_CREAT | os.O_RDWR | os.O_EXCL)
except OSError as e:
if e.errno != errno.EEXIST:
raise
return os.open(name, os.O_RDWR | os.O_EXCL) | module function_definition identifier parameters identifier identifier block try_statement block return_statement call attribute identifier identifier argument_list identifier binary_operator binary_operator attribute identifier identifier attribute identifier identifier attribute identifier identifier except_clause as_pattern identifier as_pattern_target identifier block if_statement comparison_operator attribute identifier identifier attribute identifier identifier block raise_statement return_statement call attribute identifier identifier argument_list identifier binary_operator attribute identifier identifier attribute identifier identifier | Open a file or create it. |
def format(self, formatstring, *args):
if self.incoming_section:
self.SendMessage(['s', {'name': args}])
self.incoming_section = False | module function_definition identifier parameters identifier identifier list_splat_pattern identifier block if_statement attribute identifier identifier block expression_statement call attribute identifier identifier argument_list list string string_start string_content string_end dictionary pair string string_start string_content string_end identifier expression_statement assignment attribute identifier identifier false | Presentation Information from the Plugin |
def count_elements_exactly_by_selector(self, number, selector):
elems = find_elements_by_jquery(world.browser, selector)
number = int(number)
if len(elems) != number:
raise AssertionError("Expected {} elements, found {}".format(
number, len(elems))) | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call identifier argument_list attribute identifier identifier identifier expression_statement assignment identifier call identifier argument_list identifier if_statement comparison_operator call identifier argument_list identifier identifier block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier call identifier argument_list identifier | Assert n elements exist matching the given selector. |
def iterdirty(self):
return iter(chain(itervalues(self._new), itervalues(self._modified))) | module function_definition identifier parameters identifier block return_statement call identifier argument_list call identifier argument_list call identifier argument_list attribute identifier identifier call identifier argument_list attribute identifier identifier | Ordered iterator over dirty elements. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.