code stringlengths 51 2.34k | sequence stringlengths 186 3.94k | docstring stringlengths 11 171 |
|---|---|---|
def compileGSUB(self):
from ufo2ft.util import compileGSUB
compiler = self.context.compiler
if compiler is not None:
if hasattr(compiler, "_gsub"):
return compiler._gsub
glyphOrder = compiler.ttFont.getGlyphOrder()
else:
glyphOrder = sorted(self.context.font.keys())
gsub = compileGSUB(self.context.feaFile, glyphOrder)
if compiler and not hasattr(compiler, "_gsub"):
compiler._gsub = gsub
return gsub | module function_definition identifier parameters identifier block import_from_statement dotted_name identifier identifier dotted_name identifier expression_statement assignment identifier attribute attribute identifier identifier identifier if_statement comparison_operator identifier none block if_statement call identifier argument_list identifier string string_start string_content string_end block return_statement attribute identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list else_clause block expression_statement assignment identifier call identifier argument_list call attribute attribute attribute identifier identifier identifier identifier argument_list expression_statement assignment identifier call identifier argument_list attribute attribute identifier identifier identifier identifier if_statement boolean_operator identifier not_operator call identifier argument_list identifier string string_start string_content string_end block expression_statement assignment attribute identifier identifier identifier return_statement identifier | Compile a temporary GSUB table from the current feature file. |
def cmd_init(self, *args):
if exists('buildozer.spec'):
print('ERROR: You already have a buildozer.spec file.')
exit(1)
copyfile(join(dirname(__file__), 'default.spec'), 'buildozer.spec')
print('File buildozer.spec created, ready to customize!') | module function_definition identifier parameters identifier list_splat_pattern identifier block if_statement call identifier argument_list string string_start string_content string_end block expression_statement call identifier argument_list string string_start string_content string_end expression_statement call identifier argument_list integer expression_statement call identifier argument_list call identifier argument_list call identifier argument_list identifier string string_start string_content string_end string string_start string_content string_end expression_statement call identifier argument_list string string_start string_content string_end | Create a initial buildozer.spec in the current directory |
def can_fetch(self, url_info: URLInfo, user_agent: str):
key = self.url_info_key(url_info)
parser = self._parsers[key]
return parser.is_allowed(user_agent, url_info.url) | module function_definition identifier parameters identifier typed_parameter identifier type identifier typed_parameter identifier type identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier subscript attribute identifier identifier identifier return_statement call attribute identifier identifier argument_list identifier attribute identifier identifier | Return whether the URL can be fetched. |
def autosave_all(self):
for index in range(self.stack.get_stack_count()):
self.autosave(index) | module function_definition identifier parameters identifier block for_statement identifier call identifier argument_list call attribute attribute identifier identifier identifier argument_list block expression_statement call attribute identifier identifier argument_list identifier | Autosave all opened files. |
def display(self):
"Renders the scene once every refresh"
self.compositor.waitGetPoses(self.poses, openvr.k_unMaxTrackedDeviceCount, None, 0)
hmd_pose0 = self.poses[openvr.k_unTrackedDeviceIndex_Hmd]
if not hmd_pose0.bPoseIsValid:
return
if True:
glClearColor(0.8, 0.4, 0.4, 0)
glClear(GL_COLOR_BUFFER_BIT)
glFlush()
glBindFramebuffer(GL_FRAMEBUFFER, self.fb)
glClearColor(0.8, 0.4, 0.4, 0)
glClear(GL_COLOR_BUFFER_BIT)
glBindFramebuffer(GL_FRAMEBUFFER, 0)
self.compositor.submit(openvr.Eye_Left, self.texture)
self.compositor.submit(openvr.Eye_Right, self.texture)
glBindFramebuffer(GL_FRAMEBUFFER, 0) | module function_definition identifier parameters identifier block expression_statement string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier attribute identifier identifier none integer expression_statement assignment identifier subscript attribute identifier identifier attribute identifier identifier if_statement not_operator attribute identifier identifier block return_statement if_statement true block expression_statement call identifier argument_list float float float integer expression_statement call identifier argument_list identifier expression_statement call identifier argument_list expression_statement call identifier argument_list identifier attribute identifier identifier expression_statement call identifier argument_list float float float integer expression_statement call identifier argument_list identifier expression_statement call identifier argument_list identifier integer expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier attribute identifier identifier expression_statement call identifier argument_list identifier integer | Renders the scene once every refresh |
def generative(func):
def wrap(inst, *args, **kw):
clone = type(inst).__new__(type(inst))
clone.__dict__ = inst.__dict__.copy()
return func(clone, *args, **kw)
return update_wrapper(wrap, func) | module function_definition identifier parameters identifier block function_definition identifier parameters identifier list_splat_pattern identifier dictionary_splat_pattern identifier block expression_statement assignment identifier call attribute call identifier argument_list identifier identifier argument_list call identifier argument_list identifier expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list return_statement call identifier argument_list identifier list_splat identifier dictionary_splat identifier return_statement call identifier argument_list identifier identifier | Marks an instance method as generative. |
def push(self):
tx = Tx(self.tx_project_slug)
template = babel.messages.catalog.Catalog()
for topic in self.desk.topics():
if topic.show_in_portal:
template.add(topic.name)
template_po = StringIO()
babel.messages.pofile.write_po(template_po, template)
tx.create_or_update_resource(
self.TOPIC_STRINGS_SLUG,
DEFAULT_SOURCE_LANGUAGE,
"Help Center Topics",
template_po.getvalue(),
i18n_type='PO',
project_slug=self.tx_project_slug,
) | module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list attribute identifier identifier expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list for_statement identifier call attribute attribute identifier identifier identifier argument_list block if_statement attribute identifier identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement assignment identifier call identifier argument_list expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list identifier identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier identifier string string_start string_content string_end call attribute identifier identifier argument_list keyword_argument identifier string string_start string_content string_end keyword_argument identifier attribute identifier identifier | Push topics to Transifex. |
def restore_row(self, row, schema):
row = list(row)
for index, field in enumerate(schema.fields):
if self.__dialect == 'postgresql':
if field.type in ['array', 'object']:
continue
row[index] = field.cast_value(row[index])
return row | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call identifier argument_list identifier for_statement pattern_list identifier identifier call identifier argument_list attribute identifier identifier block if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block if_statement comparison_operator attribute identifier identifier list string string_start string_content string_end string string_start string_content string_end block continue_statement expression_statement assignment subscript identifier identifier call attribute identifier identifier argument_list subscript identifier identifier return_statement identifier | Restore row from SQL |
def update_consumer_offsets(self, partition_offsets):
self.logger.debug("Updating consumer offsets to: %s", partition_offsets)
for partition, offset in partition_offsets.items():
self.consumer.offsets[partition] = offset
self.consumer.seek(0, 1) | module function_definition identifier parameters identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end identifier for_statement pattern_list identifier identifier call attribute identifier identifier argument_list block expression_statement assignment subscript attribute attribute identifier identifier identifier identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list integer integer | Update consumer offsets to explicit positions. |
def __store_processing_state(self):
steps = self.Application_Progress_Status_processing.Processing_progressBar.maximum()
value = self.Application_Progress_Status_processing.Processing_progressBar.value()
message = self.Application_Progress_Status_processing.Processing_label.text()
state = self.__is_processing
self.__processing_state = steps, value, message, state | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list expression_statement assignment identifier attribute identifier identifier expression_statement assignment attribute identifier identifier expression_list identifier identifier identifier identifier | Stores the processing state. |
def _gen_keys_from_multicol_key(key_multicol, n_keys):
keys = [('{}{:03}of{:03}')
.format(key_multicol, i+1, n_keys) for i in range(n_keys)]
return keys | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier list_comprehension call attribute parenthesized_expression string string_start string_content string_end identifier argument_list identifier binary_operator identifier integer identifier for_in_clause identifier call identifier argument_list identifier return_statement identifier | Generates single-column keys from multicolumn key. |
def cache_key(self, request, method=None):
if method is None:
method = request.method
return "bettercache_page:%s:%s" %(request.build_absolute_uri(), method) | module function_definition identifier parameters identifier identifier default_parameter identifier none block if_statement comparison_operator identifier none block expression_statement assignment identifier attribute identifier identifier return_statement binary_operator string string_start string_content string_end tuple call attribute identifier identifier argument_list identifier | the cache key is the absolute uri and the request method |
def _requirements_to_dict(rs):
out = []
added = set([])
for r in rs:
if r["class"] == "DockerRequirement" and "docker" not in added:
added.add("docker")
out.append({"requirement_type": "docker", "value": r["dockerImageId"]})
elif r["class"] == "ResourceRequirement":
if "coresMin" in r and "cpu" not in added:
added.add("cpu")
out.append({"requirement_type": "cpu", "value": r["coresMin"]})
if "ramMin" in r and "memory" not in added:
added.add("memory")
out.append({"requirement_type": "memory", "value": "%s MB" % r["ramMin"]})
if "tmpdirMin" in r and "disks" not in added:
added.add("disks")
out.append({"requirement_type": "disks", "value": "local-disk %s HDD" % r["tmpdirMin"]})
return out | module function_definition identifier parameters identifier block expression_statement assignment identifier list expression_statement assignment identifier call identifier argument_list list for_statement identifier identifier block if_statement boolean_operator comparison_operator subscript identifier string string_start string_content string_end string string_start string_content string_end comparison_operator string string_start string_content string_end 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 dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end subscript identifier string string_start string_content string_end elif_clause comparison_operator subscript identifier string string_start string_content string_end string string_start string_content string_end block if_statement boolean_operator comparison_operator string string_start string_content string_end identifier comparison_operator string string_start string_content string_end 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 dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end subscript identifier string string_start string_content string_end if_statement boolean_operator comparison_operator string string_start string_content string_end identifier comparison_operator string string_start string_content string_end 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 dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end binary_operator string string_start string_content string_end subscript identifier string string_start string_content string_end if_statement boolean_operator comparison_operator string string_start string_content string_end identifier comparison_operator string string_start string_content string_end 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 dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end binary_operator string string_start string_content string_end subscript identifier string string_start string_content string_end return_statement identifier | Convert supported requirements into dictionary for output. |
def ok_button_status(self):
if not self.layer.currentLayer():
self.button_box.button(
QtWidgets.QDialogButtonBox.Ok).setEnabled(False)
elif (self.hazard_class_form.count() > 0
and self.layer.currentLayer().name()
and len(self.output_form.text()) >= 0):
self.button_box.button(
QtWidgets.QDialogButtonBox.Ok).setEnabled(True)
else:
self.button_box.button(
QtWidgets.QDialogButtonBox.Ok).setEnabled(False) | module function_definition identifier parameters identifier block if_statement not_operator call attribute attribute identifier identifier identifier argument_list block expression_statement call attribute call attribute attribute identifier identifier identifier argument_list attribute attribute identifier identifier identifier identifier argument_list false elif_clause parenthesized_expression boolean_operator boolean_operator comparison_operator call attribute attribute identifier identifier identifier argument_list integer call attribute call attribute attribute identifier identifier identifier argument_list identifier argument_list comparison_operator call identifier argument_list call attribute attribute identifier identifier identifier argument_list integer block expression_statement call attribute call attribute attribute identifier identifier identifier argument_list attribute attribute identifier identifier identifier identifier argument_list true else_clause block expression_statement call attribute call attribute attribute identifier identifier identifier argument_list attribute attribute identifier identifier identifier identifier argument_list false | Function to enable or disable OK button. |
def draw_footer(canvas):
note = (
u'Bank Details: Street address, Town, County, POSTCODE',
u'Sort Code: 00-00-00 Account No: 00000000 (Quote invoice number).',
u'Please pay via bank transfer or cheque. All payments should be made in CURRENCY.',
u'Make cheques payable to Company Name Ltd.',
)
textobject = canvas.beginText(1 * cm, -27 * cm)
for line in note:
textobject.textLine(line)
canvas.drawText(textobject) | module function_definition identifier parameters identifier block expression_statement assignment identifier tuple 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 expression_statement assignment identifier call attribute identifier identifier argument_list binary_operator integer identifier binary_operator unary_operator integer identifier for_statement identifier identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier | Draws the invoice footer |
def _prep_mod_opts(self):
mod_opts = {}
for key, val in six.iteritems(self.opts):
if key == 'logger':
continue
mod_opts[key] = val
return mod_opts | module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary for_statement pattern_list identifier identifier call attribute identifier identifier argument_list attribute identifier identifier block if_statement comparison_operator identifier string string_start string_content string_end block continue_statement expression_statement assignment subscript identifier identifier identifier return_statement identifier | Returns a copy of the opts with key bits stripped out |
def describe_all(self, refresh=True):
tables = self.connection.list_tables()
descs = []
for tablename in tables:
descs.append(self.describe(tablename, refresh))
return descs | module function_definition identifier parameters identifier default_parameter identifier true block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list expression_statement assignment identifier list for_statement identifier identifier block expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier identifier return_statement identifier | Describe all tables in the connected region |
def prepare_buckets(self):
for mdl in self.registry.get_base_models():
bucket = mdl(super_context).objects.adapter.bucket
self.buckets[bucket.name] = bucket | module function_definition identifier parameters identifier block for_statement identifier call attribute attribute identifier identifier identifier argument_list block expression_statement assignment identifier attribute attribute attribute call identifier argument_list identifier identifier identifier identifier expression_statement assignment subscript attribute identifier identifier attribute identifier identifier identifier | loads buckets to bucket cache. |
def delete_relation(sender, instance, **kwargs):
def process_signal(relation_id):
try:
relation = Relation.objects.get(pk=relation_id)
except Relation.DoesNotExist:
return
if relation.entities.count() == 0:
relation.delete()
transaction.on_commit(lambda: process_signal(instance.relation_id)) | module function_definition identifier parameters identifier identifier dictionary_splat_pattern identifier block function_definition identifier parameters identifier block try_statement block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list keyword_argument identifier identifier except_clause attribute identifier identifier block return_statement if_statement comparison_operator call attribute attribute identifier identifier identifier argument_list integer block expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list lambda call identifier argument_list attribute identifier identifier | Delete the Relation object when the last Entity is removed. |
def targetwords(self, index, targetwords, alignment):
return [ targetwords[x] for x in alignment[index] ] | module function_definition identifier parameters identifier identifier identifier identifier block return_statement list_comprehension subscript identifier identifier for_in_clause identifier subscript identifier identifier | Return the aligned targetwords for a specified index in the source words |
def rested_filter(name, location, size, unsize):
ver = slack_ver()
if _meta_.slack_rel == "current":
ver = "current"
path_pkg = "pkg"
if _meta_.arch == "x86_64":
path_pkg = "pkg64"
(fname, flocation, fsize, funsize) = ([] for i in range(4))
for n, l, s, u in zip(name, location, size, unsize):
if path_pkg == l.split("/")[-2] and ver == l.split("/")[-1]:
fname.append(n)
flocation.append(l)
fsize.append(s)
funsize.append(u)
return [fname, flocation, fsize, funsize] | module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier call identifier argument_list if_statement comparison_operator attribute identifier 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_content string_end if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier string string_start string_content string_end expression_statement assignment tuple_pattern identifier identifier identifier identifier generator_expression list for_in_clause identifier call identifier argument_list integer for_statement pattern_list identifier identifier identifier identifier call identifier argument_list identifier identifier identifier identifier block if_statement boolean_operator comparison_operator identifier subscript call attribute identifier identifier argument_list string string_start string_content string_end unary_operator integer comparison_operator identifier subscript call attribute identifier identifier argument_list string string_start string_content string_end unary_operator integer block expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier return_statement list identifier identifier identifier identifier | Filter Alien"s repository data |
def attach(gandi, name, vhost, remote):
return gandi.paas.attach(name, vhost, remote) | module function_definition identifier parameters identifier identifier identifier identifier block return_statement call attribute attribute identifier identifier identifier argument_list identifier identifier identifier | Add remote for an instance's default vhost to the local git repository. |
def intersection (set1, set2):
assert is_iterable(set1)
assert is_iterable(set2)
result = []
for v in set1:
if v in set2:
result.append (v)
return result | module function_definition identifier parameters identifier identifier block assert_statement call identifier argument_list identifier assert_statement call identifier argument_list identifier expression_statement assignment identifier list for_statement identifier identifier block if_statement comparison_operator identifier identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Removes from set1 any items which don't appear in set2 and returns the result. |
def _get(self, id):
"Return keys and value for karma id"
VALUE_SQL = "SELECT karmavalue from karma_values where karmaid = ?"
KEYS_SQL = "SELECT karmakey from karma_keys where karmaid = ?"
value = self.db.execute(VALUE_SQL, [id]).fetchall()[0][0]
keys_cur = self.db.execute(KEYS_SQL, [id]).fetchall()
keys = sorted(x[0] for x in keys_cur)
return keys, value | module function_definition identifier parameters identifier identifier block expression_statement string string_start string_content string_end expression_statement assignment identifier string string_start string_content string_end expression_statement assignment identifier string string_start string_content string_end expression_statement assignment identifier subscript subscript call attribute call attribute attribute identifier identifier identifier argument_list identifier list identifier identifier argument_list integer integer expression_statement assignment identifier call attribute call attribute attribute identifier identifier identifier argument_list identifier list identifier identifier argument_list expression_statement assignment identifier call identifier generator_expression subscript identifier integer for_in_clause identifier identifier return_statement expression_list identifier identifier | Return keys and value for karma id |
def default_decode(events, mode='full'):
event, elem = next(events)
root = elem
while (event, elem.tag) not in [('start', 'igt'), ('end', 'xigt-corpus')]:
event, elem = next(events)
igts = None
if event == 'start' and elem.tag == 'igt':
igts = (
decode_igt(e)
for e in iter_elements(
'igt', events, root, break_on=[('end', 'xigt-corpus')]
)
)
xc = decode_xigtcorpus(root, igts=igts, mode=mode)
return xc | module function_definition identifier parameters identifier default_parameter identifier string string_start string_content string_end block expression_statement assignment pattern_list identifier identifier call identifier argument_list identifier expression_statement assignment identifier identifier while_statement comparison_operator tuple identifier attribute identifier identifier list tuple string string_start string_content string_end string string_start string_content string_end tuple string string_start string_content string_end string string_start string_content string_end block expression_statement assignment pattern_list identifier identifier call identifier argument_list identifier expression_statement assignment identifier none if_statement boolean_operator comparison_operator identifier string string_start string_content string_end comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier generator_expression call identifier argument_list identifier for_in_clause identifier call identifier argument_list string string_start string_content string_end identifier identifier keyword_argument identifier list tuple string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier keyword_argument identifier identifier keyword_argument identifier identifier return_statement identifier | Decode a XigtCorpus element. |
def _FindPartition(self, key):
hash_value = self.hash_generator.ComputeHash(key)
return self._LowerBoundSearch(self.partitions, hash_value) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list attribute identifier identifier identifier | Finds the partition from the byte array representation of the partition key. |
def replicasResource(self):
if self._replicasResource is None:
self._replicasResource = {}
for replica in self.replicas:
self._replicasResource["replicaName"] = replica.name
self._replicasResource["replicaID"] = replica.guid
return self._replicasResource | module function_definition identifier parameters identifier block if_statement comparison_operator attribute identifier identifier none block expression_statement assignment attribute identifier identifier dictionary for_statement identifier attribute identifier identifier block expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end attribute identifier identifier expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end attribute identifier identifier return_statement attribute identifier identifier | returns a list of replices |
def populate_tree(self, master, parent, element,from_file=False):
data = WidgetDescr(None, None)
data.from_xml_node(element)
cname = data.get_class()
uniqueid = self.get_unique_id(cname, data.get_id())
data.set_property('id', uniqueid)
if cname in builder.CLASS_MAP:
pwidget = self._insert_item(master, data,from_file=from_file)
xpath = "./child"
children = element.findall(xpath)
for child in children:
child_object = child.find('./object')
cwidget = self.populate_tree(pwidget, child, child_object,from_file=from_file)
return pwidget
else:
raise Exception('Class "{0}" not mapped'.format(cname)) | module function_definition identifier parameters identifier identifier identifier identifier default_parameter identifier false block expression_statement assignment identifier call identifier argument_list none none expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list identifier call attribute identifier identifier argument_list 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 identifier call attribute identifier identifier argument_list identifier identifier keyword_argument identifier identifier expression_statement assignment identifier string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list identifier 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 call attribute identifier identifier argument_list identifier identifier identifier keyword_argument identifier identifier return_statement identifier else_clause block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier | Reads xml nodes and populates tree item |
def from_string(self, value):
if value.startswith('[') and value.endswith(']'):
text = value[1:-1].strip()
else:
text = value.strip()
result = []
if text.startswith('('):
tokens = text.split(',')
if len(tokens) % 2 != 0:
raise ValueError('not a valid list of pairs')
pos = 0
while (pos < len(tokens)):
val1 = float(tokens[pos].strip()[1:].strip())
val2 = float(tokens[pos + 1].strip()[:-1])
result.append((val1, val2))
pos += 2
else:
for val in text.split(','):
result.append(float(val))
if len(result) < 2:
raise ValueError('invalid number of elements in list: ' + str(len(result)))
return result | module function_definition identifier parameters identifier identifier block if_statement boolean_operator call attribute identifier identifier argument_list string string_start string_content string_end call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier call attribute subscript identifier slice integer unary_operator integer identifier argument_list else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier list if_statement call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement comparison_operator binary_operator call identifier argument_list identifier integer integer block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment identifier integer while_statement parenthesized_expression comparison_operator identifier call identifier argument_list identifier block expression_statement assignment identifier call identifier argument_list call attribute subscript call attribute subscript identifier identifier identifier argument_list slice integer identifier argument_list expression_statement assignment identifier call identifier argument_list subscript call attribute subscript identifier binary_operator identifier integer identifier argument_list slice unary_operator integer expression_statement call attribute identifier identifier argument_list tuple identifier identifier expression_statement augmented_assignment identifier integer else_clause block for_statement identifier call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list call identifier argument_list identifier if_statement comparison_operator call identifier argument_list identifier integer block raise_statement call identifier argument_list binary_operator string string_start string_content string_end call identifier argument_list call identifier argument_list identifier return_statement identifier | Convert string to list. |
def _get_span_name(servicer_context):
method_name = servicer_context._rpc_event.call_details.method[1:]
if isinstance(method_name, bytes):
method_name = method_name.decode('utf-8')
method_name = method_name.replace('/', '.')
return '{}.{}'.format(RECV_PREFIX, method_name) | module function_definition identifier parameters identifier block expression_statement assignment identifier subscript attribute attribute attribute identifier identifier identifier identifier slice integer if_statement call identifier argument_list identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end return_statement call attribute string string_start string_content string_end identifier argument_list identifier identifier | Generates a span name based off of the gRPC server rpc_request_info |
def _extract_parameters_from_properties(properties):
new_properties = {}
parameters = []
for key, value in six.iteritems(properties):
if key.startswith(_PARAMETER_PREFIX):
parameters.append((key.replace(_PARAMETER_PREFIX, ""), value))
else:
new_properties[key] = value
return new_properties, sorted(parameters) | module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary expression_statement assignment identifier list for_statement pattern_list identifier identifier call attribute identifier identifier argument_list identifier block if_statement call attribute identifier identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list tuple call attribute identifier identifier argument_list identifier string string_start string_end identifier else_clause block expression_statement assignment subscript identifier identifier identifier return_statement expression_list identifier call identifier argument_list identifier | Extracts parameters from properties. |
def obj(x):
j = np.arange(1, 6)
tmp1 = np.dot(j, np.cos((j+1)*x[0] + j))
tmp2 = np.dot(j, np.cos((j+1)*x[1] + j))
return tmp1 * tmp2 | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list integer integer expression_statement assignment identifier call attribute identifier identifier argument_list identifier call attribute identifier identifier argument_list binary_operator binary_operator parenthesized_expression binary_operator identifier integer subscript identifier integer identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier call attribute identifier identifier argument_list binary_operator binary_operator parenthesized_expression binary_operator identifier integer subscript identifier integer identifier return_statement binary_operator identifier identifier | Two Dimensional Shubert Function |
def build_dictionary(self):
d = {}
for t in self.all_tags_of_type(DefinitionTag, recurse_into_sprites = False):
if t.characterId in d:
raise ValueError('illegal redefinition of character')
d[t.characterId] = t
return d | module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary for_statement identifier call attribute identifier identifier argument_list identifier keyword_argument identifier false block if_statement comparison_operator attribute identifier identifier identifier block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment subscript identifier attribute identifier identifier identifier return_statement identifier | Return a dictionary of characterIds to their defining tags. |
def _check_key(self, key):
if not len(key) == 2:
raise TypeError('invalid key: %r' % key)
elif key[1] not in TYPES:
raise TypeError('invalid datatype: %s' % key[1]) | module function_definition identifier parameters identifier identifier block if_statement not_operator comparison_operator call identifier argument_list identifier integer block raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier elif_clause comparison_operator subscript identifier integer identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end subscript identifier integer | Ensures well-formedness of a key. |
def triplify_object(binding):
triples = []
if binding.uri:
triples.append((binding.subject, RDF.type, binding.uri))
if binding.parent is not None:
parent = binding.parent.subject
if binding.parent.is_array:
parent = binding.parent.parent.subject
triples.append((parent, binding.predicate, binding.subject))
if binding.reverse is not None:
triples.append((binding.subject, binding.reverse, parent))
for prop in binding.properties:
_, prop_triples = triplify(prop)
triples.extend(prop_triples)
return binding.subject, triples | module function_definition identifier parameters identifier block expression_statement assignment identifier list if_statement attribute identifier identifier block expression_statement call attribute identifier identifier argument_list tuple attribute identifier identifier attribute identifier identifier attribute identifier identifier if_statement comparison_operator attribute identifier identifier none block expression_statement assignment identifier attribute attribute identifier identifier identifier if_statement attribute attribute identifier identifier identifier block expression_statement assignment identifier attribute attribute attribute identifier identifier identifier identifier expression_statement call attribute identifier identifier argument_list tuple identifier attribute identifier identifier attribute identifier identifier if_statement comparison_operator attribute identifier identifier none block expression_statement call attribute identifier identifier argument_list tuple attribute identifier identifier attribute identifier identifier identifier for_statement identifier attribute identifier identifier block expression_statement assignment pattern_list identifier identifier call identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier return_statement expression_list attribute identifier identifier identifier | Create bi-directional bindings for object relationships. |
def maybe_convert_platform(values):
if isinstance(values, (list, tuple)):
values = construct_1d_object_array_from_listlike(list(values))
if getattr(values, 'dtype', None) == np.object_:
if hasattr(values, '_values'):
values = values._values
values = lib.maybe_convert_objects(values)
return values | module function_definition identifier parameters identifier block if_statement call identifier argument_list identifier tuple identifier identifier block expression_statement assignment identifier call identifier argument_list call identifier argument_list identifier if_statement comparison_operator call identifier argument_list identifier string string_start string_content string_end none attribute identifier identifier block if_statement call identifier argument_list 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 identifier return_statement identifier | try to do platform conversion, allow ndarray or list here |
def rm_raw(ctx, dataset, kwargs):
"removes the raw unprocessed data"
kwargs = parse_kwargs(kwargs)
data(dataset, **ctx.obj).rm_raw(**kwargs) | module function_definition identifier parameters identifier identifier identifier block expression_statement string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier expression_statement call attribute call identifier argument_list identifier dictionary_splat attribute identifier identifier identifier argument_list dictionary_splat identifier | removes the raw unprocessed data |
def _read(self, directory, filename, session, path, name, extension, spatial, spatialReferenceID, replaceParamFile):
self.fileExtension = extension
with open(path, 'r') as f:
for line in f:
sline = line.strip().split()
if len(sline) == 1:
self.numParameters = sline[0]
else:
target = TargetParameter(targetVariable=sline[0],
varFormat=sline[1])
target.replaceParamFile = self | module function_definition identifier parameters identifier identifier identifier identifier identifier identifier identifier identifier identifier identifier block expression_statement assignment attribute identifier identifier identifier with_statement with_clause with_item as_pattern call identifier argument_list identifier string string_start string_content string_end as_pattern_target identifier block for_statement identifier identifier block expression_statement assignment identifier call attribute call attribute identifier identifier argument_list identifier argument_list if_statement comparison_operator call identifier argument_list identifier integer block expression_statement assignment attribute identifier identifier subscript identifier integer else_clause block expression_statement assignment identifier call identifier argument_list keyword_argument identifier subscript identifier integer keyword_argument identifier subscript identifier integer expression_statement assignment attribute identifier identifier identifier | Replace Param File Read from File Method |
def close(self):
if self._wrapped_connection and self._pool:
logger.debug("Returning connection %s to pool %s" % (self._wrapped_connection, self._pool))
self._pool.putconn(self._wrapped_connection)
self._wrapped_connection = None | module function_definition identifier parameters identifier block if_statement boolean_operator attribute identifier identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end tuple attribute identifier identifier attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement assignment attribute identifier identifier none | Override to return the connection to the pool rather than closing it. |
def use_plenary_asset_view(self):
self._object_views['asset'] = PLENARY
for session in self._get_provider_sessions():
try:
session.use_plenary_asset_view()
except AttributeError:
pass | module function_definition identifier parameters identifier block expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end identifier for_statement identifier call attribute identifier identifier argument_list block try_statement block expression_statement call attribute identifier identifier argument_list except_clause identifier block pass_statement | Pass through to provider AssetLookupSession.use_plenary_asset_view |
def lock_pid(self):
if os.path.exists(self.lock_filename):
return int(open(self.lock_filename).read())
else:
return None | module function_definition identifier parameters identifier block if_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier block return_statement call identifier argument_list call attribute call identifier argument_list attribute identifier identifier identifier argument_list else_clause block return_statement none | Get the pid of the lock. |
def _get_site_dummy_variables(self, vs30):
s_b = np.zeros_like(vs30)
s_c = np.zeros_like(vs30)
s_d = np.zeros_like(vs30)
s_b[np.logical_and(vs30 >= 360., vs30 < 800.)] = 1.0
s_c[np.logical_and(vs30 >= 180., vs30 < 360.)] = 1.0
s_d[vs30 < 180] = 1.0
return s_b, s_c, s_d | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment subscript identifier call attribute identifier identifier argument_list comparison_operator identifier float comparison_operator identifier float float expression_statement assignment subscript identifier call attribute identifier identifier argument_list comparison_operator identifier float comparison_operator identifier float float expression_statement assignment subscript identifier comparison_operator identifier integer float return_statement expression_list identifier identifier identifier | Returns the Eurocode 8 site class dummy variable |
def store(self, installed_stuff, metadata, interpreter, options):
new_content = {
'timestamp': int(time.mktime(time.localtime())),
'installed': installed_stuff,
'metadata': metadata,
'interpreter': interpreter,
'options': options
}
logger.debug("Storing installed=%s metadata=%s interpreter=%s options=%s",
installed_stuff, metadata, interpreter, options)
with filelock(self.lockpath):
self._write_cache([json.dumps(new_content)], append=True) | module function_definition identifier parameters identifier identifier identifier identifier identifier block expression_statement assignment identifier dictionary pair string string_start string_content string_end call identifier argument_list call attribute identifier identifier argument_list call attribute identifier identifier argument_list pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier identifier identifier identifier with_statement with_clause with_item call identifier argument_list attribute identifier identifier block expression_statement call attribute identifier identifier argument_list list call attribute identifier identifier argument_list identifier keyword_argument identifier true | Store the virtualenv metadata for the indicated installed_stuff. |
def _bin_op(name, doc="binary operator"):
def _(self, other):
jc = other._jc if isinstance(other, Column) else other
njc = getattr(self._jc, name)(jc)
return Column(njc)
_.__doc__ = doc
return _ | module function_definition identifier parameters identifier default_parameter identifier string string_start string_content string_end block function_definition identifier parameters identifier identifier block expression_statement assignment identifier conditional_expression attribute identifier identifier call identifier argument_list identifier identifier identifier expression_statement assignment identifier call call identifier argument_list attribute identifier identifier identifier argument_list identifier return_statement call identifier argument_list identifier expression_statement assignment attribute identifier identifier identifier return_statement identifier | Create a method for given binary operator |
def extract_email(text):
result = list()
for tp in re.findall(_regex_extract_email, text.lower()):
for email in tp:
if re.match(_regex_validate_email, email):
result.append(email)
return result | module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list for_statement identifier call attribute identifier identifier argument_list identifier call attribute identifier identifier argument_list block for_statement identifier identifier block if_statement call attribute identifier identifier argument_list identifier identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Extract email from text. |
def getAnalysisCategories(self):
bsc = api.get_tool("bika_setup_catalog")
cats = []
for st in bsc(portal_type="AnalysisCategory",
is_active=True,
sort_on="sortable_title"):
cats.append((st.UID, st.Title))
return DisplayList(cats) | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier list for_statement identifier call identifier argument_list keyword_argument identifier string string_start string_content string_end keyword_argument identifier true keyword_argument identifier string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list tuple attribute identifier identifier attribute identifier identifier return_statement call identifier argument_list identifier | Return all available analysis categories |
def _parse_plan(self, match):
expected_tests = int(match.group("expected"))
directive = Directive(match.group("directive"))
if directive.text and not directive.skip:
return Unknown()
return Plan(expected_tests, directive) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end if_statement boolean_operator attribute identifier identifier not_operator attribute identifier identifier block return_statement call identifier argument_list return_statement call identifier argument_list identifier identifier | Parse a matching plan line. |
def adev(self, tau0, tau):
prefactor = self.adev_from_qd(tau0=tau0, tau=tau)
c = self.c_avar()
avar = pow(prefactor, 2)*pow(tau, c)
return np.sqrt(avar) | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier binary_operator call identifier argument_list identifier integer call identifier argument_list identifier identifier return_statement call attribute identifier identifier argument_list identifier | return predicted ADEV of noise-type at given tau |
def hashes_above(path, line_number):
def hash_lists(path):
hashes = []
with open(path) as file:
for lineno, line in enumerate(file, 1):
match = HASH_COMMENT_RE.match(line)
if match:
hashes.append(match.groupdict()['hash'])
if not IGNORED_LINE_RE.match(line):
yield hashes
hashes = []
elif PIP_COUNTS_COMMENTS:
yield []
return next(islice(hash_lists(path), line_number - 1, None)) | module function_definition identifier parameters identifier identifier block function_definition identifier parameters identifier block expression_statement assignment identifier list with_statement with_clause with_item as_pattern call identifier argument_list identifier as_pattern_target identifier block for_statement pattern_list identifier identifier call identifier argument_list identifier integer block expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement identifier block expression_statement call attribute identifier identifier argument_list subscript call attribute identifier identifier argument_list string string_start string_content string_end if_statement not_operator call attribute identifier identifier argument_list identifier block expression_statement yield identifier expression_statement assignment identifier list elif_clause identifier block expression_statement yield list return_statement call identifier argument_list call identifier argument_list call identifier argument_list identifier binary_operator identifier integer none | Yield hashes from contiguous comment lines before line ``line_number``. |
def IsFleetspeakEnabledClient(grr_id, token=None):
if grr_id is None:
return False
if data_store.RelationalDBEnabled():
md = data_store.REL_DB.ReadClientMetadata(grr_id)
if not md:
return False
return md.fleetspeak_enabled
else:
with aff4.FACTORY.Create(
rdf_client.ClientURN(grr_id),
aff4.AFF4Object.classes["VFSGRRClient"],
mode="r",
token=token) as client:
return bool(client.Get(client.Schema.FLEETSPEAK_ENABLED)) | module function_definition identifier parameters identifier default_parameter identifier none block if_statement comparison_operator identifier none block return_statement false if_statement call attribute identifier identifier argument_list block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier if_statement not_operator identifier block return_statement false return_statement attribute identifier identifier else_clause block with_statement with_clause with_item as_pattern call attribute attribute identifier identifier identifier argument_list call attribute identifier identifier argument_list identifier subscript attribute attribute identifier identifier identifier string string_start string_content string_end keyword_argument identifier string string_start string_content string_end keyword_argument identifier identifier as_pattern_target identifier block return_statement call identifier argument_list call attribute identifier identifier argument_list attribute attribute identifier identifier identifier | Returns whether the provided GRR id is a Fleetspeak client. |
def processLibraryDetails(details):
for includeDir in details.includeDirs:
for pattern in CUSTOM_FLAGS_FOR_INCLUDE_DIRS:
if pattern in includeDir:
flag = '-D' + CUSTOM_FLAGS_FOR_INCLUDE_DIRS[pattern] + '=' + includeDir
details.cmakeFlags.append(flag)
for lib in details.libs:
filename = os.path.basename(lib)
(name, ext) = os.path.splitext(filename)
libName = name.replace('lib', '') if name.startswith('lib') else name
libName = libName.rstrip('_-1234567890')
if libName in CUSTOM_FLAGS_FOR_LIBS:
flag = '-D' + CUSTOM_FLAGS_FOR_LIBS[libName] + '=' + lib
details.cmakeFlags.append(flag) | module function_definition identifier parameters identifier block for_statement identifier attribute identifier identifier block for_statement identifier identifier block if_statement comparison_operator identifier identifier block expression_statement assignment identifier binary_operator binary_operator binary_operator string string_start string_content string_end subscript identifier identifier string string_start string_content string_end identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier for_statement identifier attribute identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment tuple_pattern identifier identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier conditional_expression call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_end call attribute identifier identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement comparison_operator identifier identifier block expression_statement assignment identifier binary_operator binary_operator binary_operator string string_start string_content string_end subscript identifier identifier string string_start string_content string_end identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier | Processes the supplied ThirdPartyLibraryDetails instance and sets any custom CMake flags |
def edge_val_set(self, graph, orig, dest, idx, key, branch, turn, tick, value):
if (branch, turn, tick) in self._btts:
raise TimeError
self._btts.add((branch, turn, tick))
graph, orig, dest, key, value = map(self.pack, (graph, orig, dest, key, value))
self._edgevals2set.append(
(graph, orig, dest, idx, key, branch, turn, tick, value)
) | module function_definition identifier parameters identifier identifier identifier identifier identifier identifier identifier identifier identifier identifier block if_statement comparison_operator tuple identifier identifier identifier attribute identifier identifier block raise_statement identifier expression_statement call attribute attribute identifier identifier identifier argument_list tuple identifier identifier identifier expression_statement assignment pattern_list identifier identifier identifier identifier identifier call identifier argument_list attribute identifier identifier tuple identifier identifier identifier identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list tuple identifier identifier identifier identifier identifier identifier identifier identifier identifier | Set this key of this edge to this value. |
def _enum_attached_rows(self, indices):
records = self._records
i = 0
for i, line in self._enum_lines():
if i in indices:
row = records[i]
if row is None:
row = decode_row(line)
yield (i, row)
for j in range(i, len(records)):
if j in indices:
if records[j] is not None:
yield (j, records[j]) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier integer for_statement pattern_list identifier identifier call attribute identifier identifier argument_list block if_statement comparison_operator identifier identifier block expression_statement assignment identifier subscript identifier identifier if_statement comparison_operator identifier none block expression_statement assignment identifier call identifier argument_list identifier expression_statement yield tuple identifier identifier for_statement identifier call identifier argument_list identifier call identifier argument_list identifier block if_statement comparison_operator identifier identifier block if_statement comparison_operator subscript identifier identifier none block expression_statement yield tuple identifier subscript identifier identifier | Enumerate on-disk and in-memory records. |
def __findRange(self, excelLib, start, end):
inc = 1
low = 0
high = 0
dates = excelLib.readCol(0, 1)
for index, date in enumerate(dates):
if int(start) <= int(date):
low = index + inc
break
if low:
for index, date in reversed(list(enumerate(dates))):
if int(date) <= int(end):
high = index + inc
break
return low, high | module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier integer expression_statement assignment identifier integer expression_statement assignment identifier integer expression_statement assignment identifier call attribute identifier identifier argument_list integer integer for_statement pattern_list identifier identifier call identifier argument_list identifier block if_statement comparison_operator call identifier argument_list identifier call identifier argument_list identifier block expression_statement assignment identifier binary_operator identifier identifier break_statement if_statement identifier block for_statement pattern_list identifier identifier call identifier argument_list call identifier argument_list call identifier argument_list identifier block if_statement comparison_operator call identifier argument_list identifier call identifier argument_list identifier block expression_statement assignment identifier binary_operator identifier identifier break_statement return_statement expression_list identifier identifier | return low and high as excel range |
def _read_header(self):
self._header = self.cdmrf.fetch_header()
self.load_from_stream(self._header) | module function_definition identifier parameters identifier block expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list expression_statement call attribute identifier identifier argument_list attribute identifier identifier | Get the needed header information to initialize dataset. |
def entity_from_snapshot(snapshot):
assert isinstance(snapshot, AbstractSnapshop), type(snapshot)
if snapshot.state is not None:
entity_class = resolve_topic(snapshot.topic)
return reconstruct_object(entity_class, snapshot.state) | module function_definition identifier parameters identifier block assert_statement call identifier argument_list identifier identifier call identifier argument_list identifier if_statement comparison_operator attribute identifier identifier none block expression_statement assignment identifier call identifier argument_list attribute identifier identifier return_statement call identifier argument_list identifier attribute identifier identifier | Reconstructs domain entity from given snapshot. |
def press(button=LEFT):
location = get_position()
button_code, button_down, _, _ = _button_mapping[button]
e = Quartz.CGEventCreateMouseEvent(
None,
button_down,
location,
button_code)
if _last_click["time"] is not None and datetime.datetime.now() - _last_click["time"] < datetime.timedelta(seconds=0.3) and _last_click["button"] == button and _last_click["position"] == location:
_last_click["click_count"] = min(3, _last_click["click_count"]+1)
else:
_last_click["click_count"] = 1
Quartz.CGEventSetIntegerValueField(
e,
Quartz.kCGMouseEventClickState,
_last_click["click_count"])
Quartz.CGEventPost(Quartz.kCGHIDEventTap, e)
_button_state[button] = True
_last_click["time"] = datetime.datetime.now()
_last_click["button"] = button
_last_click["position"] = location | module function_definition identifier parameters default_parameter identifier identifier block expression_statement assignment identifier call identifier argument_list expression_statement assignment pattern_list identifier identifier identifier identifier subscript identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list none identifier identifier identifier if_statement boolean_operator boolean_operator boolean_operator comparison_operator subscript identifier string string_start string_content string_end none comparison_operator binary_operator call attribute attribute identifier identifier identifier argument_list subscript identifier string string_start string_content string_end call attribute identifier identifier argument_list keyword_argument identifier float comparison_operator subscript identifier string string_start string_content string_end identifier comparison_operator subscript identifier string string_start string_content string_end identifier block expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list integer binary_operator subscript identifier string string_start string_content string_end integer else_clause block expression_statement assignment subscript identifier string string_start string_content string_end integer expression_statement call attribute identifier identifier argument_list identifier attribute identifier identifier subscript identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list attribute identifier identifier identifier expression_statement assignment subscript identifier identifier true expression_statement assignment subscript identifier string string_start string_content string_end call attribute attribute identifier identifier identifier argument_list 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 identifier | Sends a down event for the specified button, using the provided constants |
def _context_source_file_url(path_or_url):
if path_or_url.startswith('http'):
return path_or_url
if path_or_url.startswith('/'):
return "file://" + path_or_url
return "file://" + os.path.join(os.path.realpath(os.getcwd()), path_or_url) | module function_definition identifier parameters identifier block if_statement call attribute identifier identifier argument_list string string_start string_content string_end block return_statement identifier if_statement call attribute identifier identifier argument_list string string_start string_content string_end block return_statement binary_operator string string_start string_content string_end identifier return_statement binary_operator string string_start string_content string_end call attribute attribute identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list call attribute identifier identifier argument_list identifier | Returns a URL for a remote or local context CSV file |
def _should_allocate_port(pid):
if pid <= 0:
log.info('Not allocating a port to invalid pid')
return False
if pid == 1:
log.info('Not allocating a port to init.')
return False
try:
os.kill(pid, 0)
except ProcessLookupError:
log.info('Not allocating a port to a non-existent process')
return False
return True | module function_definition identifier parameters identifier block if_statement comparison_operator identifier integer block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end return_statement false if_statement comparison_operator identifier integer block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end return_statement false try_statement block expression_statement call attribute identifier identifier argument_list identifier integer except_clause identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end return_statement false return_statement true | Determine if we should allocate a port for use by the given process id. |
def _add_metadata_as_attrs_da(data, units, description, dtype_out_vert):
if dtype_out_vert == 'vert_int':
if units != '':
units = '(vertical integral of {0}): {0} kg m^-2)'.format(units)
else:
units = '(vertical integral of quantity with unspecified units)'
data.attrs['units'] = units
data.attrs['description'] = description
return data | module function_definition identifier parameters identifier identifier identifier identifier block if_statement comparison_operator identifier string string_start string_content string_end block if_statement comparison_operator identifier string string_start string_end block expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier else_clause block expression_statement assignment identifier string string_start string_content string_end expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end identifier expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end identifier return_statement identifier | Add metadata attributes to DataArray |
def __normalize_list(self, msg):
if isinstance(msg, list):
msg = "".join(msg)
return list(map(lambda x: x.strip(), msg.split(","))) | module function_definition identifier parameters identifier identifier block if_statement call identifier argument_list identifier identifier block expression_statement assignment identifier call attribute string string_start string_end identifier argument_list identifier return_statement call identifier argument_list call identifier argument_list lambda lambda_parameters identifier call attribute identifier identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end | Split message to list by commas and trim whitespace. |
def update_datasources_cache():
from superset.models.core import Database
for database in db.session.query(Database).all():
if database.allow_multi_schema_metadata_fetch:
print('Fetching {} datasources ...'.format(database.name))
try:
database.all_table_names_in_database(
force=True, cache=True, cache_timeout=24 * 60 * 60)
database.all_view_names_in_database(
force=True, cache=True, cache_timeout=24 * 60 * 60)
except Exception as e:
print('{}'.format(str(e))) | module function_definition identifier parameters block import_from_statement dotted_name identifier identifier identifier dotted_name identifier for_statement identifier call attribute call attribute attribute identifier identifier identifier argument_list identifier identifier argument_list block if_statement attribute identifier identifier block expression_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier try_statement block expression_statement call attribute identifier identifier argument_list keyword_argument identifier true keyword_argument identifier true keyword_argument identifier binary_operator binary_operator integer integer integer expression_statement call attribute identifier identifier argument_list keyword_argument identifier true keyword_argument identifier true keyword_argument identifier binary_operator binary_operator integer integer integer except_clause as_pattern identifier as_pattern_target identifier block expression_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list call identifier argument_list identifier | Refresh sqllab datasources cache |
async def eval(self, text, opts=None):
async for pode in self.cell.iterStormPodes(text, opts=opts, user=self.user):
yield pode | module function_definition identifier parameters identifier identifier default_parameter identifier none block for_statement identifier call attribute attribute identifier identifier identifier argument_list identifier keyword_argument identifier identifier keyword_argument identifier attribute identifier identifier block expression_statement yield identifier | Evalute a storm query and yield packed nodes. |
def use_federated_repository_view(self):
self._repository_view = FEDERATED
for session in self._get_provider_sessions():
try:
session.use_federated_repository_view()
except AttributeError:
pass | module function_definition identifier parameters identifier block expression_statement assignment attribute identifier identifier identifier for_statement identifier call attribute identifier identifier argument_list block try_statement block expression_statement call attribute identifier identifier argument_list except_clause identifier block pass_statement | Pass through to provider AssetLookupSession.use_federated_repository_view |
def addPos(self, dp_x=None, dy=None, dz=None):
p = np.array(self.GetPosition())
if dz is None:
self.SetPosition(p + dp_x)
else:
self.SetPosition(p + [dp_x, dy, dz])
if self.trail:
self.updateTrail()
return self | module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none block expression_statement assignment identifier call attribute identifier identifier argument_list call attribute identifier identifier argument_list if_statement comparison_operator identifier none block expression_statement call attribute identifier identifier argument_list binary_operator identifier identifier else_clause block expression_statement call attribute identifier identifier argument_list binary_operator identifier list identifier identifier identifier if_statement attribute identifier identifier block expression_statement call attribute identifier identifier argument_list return_statement identifier | Add vector to current actor position. |
def statsId(obj):
if hasattr(obj, ID_KEY):
return getattr(obj, ID_KEY)
newId = next(NEXT_ID)
setattr(obj, ID_KEY, newId)
return newId | module function_definition identifier parameters identifier block if_statement call identifier argument_list identifier identifier block return_statement call identifier argument_list identifier identifier expression_statement assignment identifier call identifier argument_list identifier expression_statement call identifier argument_list identifier identifier identifier return_statement identifier | Gets a unique ID for each object. |
def forum_topic_get_by_tag_for_user(self, tag=None, author=None):
if not tag:
return None
if author:
r = self._request('ebuio/forum/search/bytag/' + tag + '?u=' + author)
else:
r = self._request('ebuio/forum/search/bytag/' + tag)
if not r:
return None
retour = []
for data in r.json().get('data', []):
retour.append(data)
return retour | module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none block if_statement not_operator identifier block return_statement none if_statement identifier block expression_statement assignment identifier call attribute identifier identifier argument_list binary_operator binary_operator binary_operator string string_start string_content string_end identifier string string_start string_content string_end identifier else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list binary_operator string string_start string_content string_end identifier if_statement not_operator identifier block return_statement none expression_statement assignment identifier list for_statement identifier call attribute call attribute identifier identifier argument_list identifier argument_list string string_start string_content string_end list block expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Get all forum topics with a specific tag |
def convert_reaction_entry(self, reaction):
d = OrderedDict()
d['id'] = reaction.id
def is_equation_valid(equation):
return (equation is not None and (
not isinstance(equation, Reaction) or
len(equation.compounds) > 0))
order = {
key: i for i, key in enumerate(
['name', 'genes', 'equation', 'subsystem', 'ec'])}
prop_keys = (set(reaction.properties) -
{'lower_flux', 'upper_flux', 'reversible'})
for prop in sorted(prop_keys, key=lambda x: (order.get(x, 1000), x)):
if reaction.properties[prop] is None:
continue
d[prop] = reaction.properties[prop]
if prop == 'equation' and not is_equation_valid(d[prop]):
del d[prop]
return d | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list expression_statement assignment subscript identifier string string_start string_content string_end attribute identifier identifier function_definition identifier parameters identifier block return_statement parenthesized_expression boolean_operator comparison_operator identifier none parenthesized_expression boolean_operator not_operator call identifier argument_list identifier identifier comparison_operator call identifier argument_list attribute identifier identifier integer expression_statement assignment identifier dictionary_comprehension pair identifier identifier for_in_clause pattern_list identifier identifier call identifier argument_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 expression_statement assignment identifier parenthesized_expression binary_operator call identifier argument_list attribute identifier identifier set string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end for_statement identifier call identifier argument_list identifier keyword_argument identifier lambda lambda_parameters identifier tuple call attribute identifier identifier argument_list identifier integer identifier block if_statement comparison_operator subscript attribute identifier identifier identifier none block continue_statement expression_statement assignment subscript identifier identifier subscript attribute identifier identifier identifier if_statement boolean_operator comparison_operator identifier string string_start string_content string_end not_operator call identifier argument_list subscript identifier identifier block delete_statement subscript identifier identifier return_statement identifier | Convert reaction entry to YAML dict. |
def check_apm_out(self):
now = time.time()
if now - self.last_apm_send_time < 0.02:
return
self.last_apm_send_time = now
if self.hil_state_msg is not None:
self.master.mav.send(self.hil_state_msg) | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list if_statement comparison_operator binary_operator identifier attribute identifier identifier float block return_statement expression_statement assignment attribute identifier identifier identifier if_statement comparison_operator attribute identifier identifier none block expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list attribute identifier identifier | check if we should send new data to the APM |
def plos_doi_to_xmlurl(doi_string):
doi_url = 'http://dx.doi.org/{0}'.format(doi_string)
log.debug('DOI URL: {0}'.format(doi_url))
try:
resolved_page = urllib.request.urlopen(doi_url)
except urllib.error.URLError as err:
print('Unable to resolve DOI URL, or could not connect')
raise err
else:
resolved_address = resolved_page.geturl()
log.debug('DOI resolved to {0}'.format(resolved_address))
parsed = urllib.parse.urlparse(resolved_address)
xml_url = '{0}://{1}'.format(parsed.scheme, parsed.netloc)
xml_url += '/article/fetchObjectAttachment.action?uri='
xml_path = parsed.path.replace(':', '%3A').replace('/', '%2F')
xml_path = xml_path.split('article%2F')[1]
xml_url += '{0}{1}'.format(xml_path, '&representation=XML')
log.debug('Shaped PLoS request for XML {0}'.format(xml_url))
return xml_url | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier try_statement block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier except_clause as_pattern attribute attribute identifier identifier identifier as_pattern_target identifier block expression_statement call identifier argument_list string string_start string_content string_end raise_statement identifier else_clause block expression_statement assignment identifier 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 identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier attribute identifier identifier expression_statement augmented_assignment identifier string string_start string_content string_end expression_statement assignment identifier call attribute call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end identifier argument_list string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier subscript call attribute identifier identifier argument_list string string_start string_content string_end integer expression_statement augmented_assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier return_statement identifier | Attempts to resolve a PLoS DOI into a URL path to the XML file. |
def in_query(expression):
def _in(index, expression=expression):
ev = expression() if callable(expression) else expression
try:
iter(ev)
except TypeError:
raise AttributeError('$in argument must be an iterable!')
hashed_ev = [index.get_hash_for(v) for v in ev]
store_keys = set()
for value in hashed_ev:
store_keys |= set(index.get_keys_for(value))
return list(store_keys)
return _in | module function_definition identifier parameters identifier block function_definition identifier parameters identifier default_parameter identifier identifier block expression_statement assignment identifier conditional_expression call identifier argument_list call identifier argument_list identifier identifier try_statement block expression_statement call identifier argument_list identifier except_clause identifier block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment identifier list_comprehension call attribute identifier identifier argument_list identifier for_in_clause identifier identifier expression_statement assignment identifier call identifier argument_list for_statement identifier identifier block expression_statement augmented_assignment identifier call identifier argument_list call attribute identifier identifier argument_list identifier return_statement call identifier argument_list identifier return_statement identifier | Match any of the values that exist in an array specified in query. |
def add_vertex_buffer(self, material, vertex_format, byte_offset, byte_length):
self._vertex_buffers.append({
"material": material,
"vertex_format": vertex_format,
"byte_offset": byte_offset,
"byte_length": byte_length,
}) | module function_definition identifier parameters identifier identifier identifier identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list dictionary pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier | Add a vertex buffer |
def stress(syllabified_simplex_word):
syllables = syllabified_simplex_word.split('.')
stressed = '\'' + syllables[0]
try:
n = 0
medial = syllables[1:-1]
for i, syll in enumerate(medial):
if (i + n) % 2 == 0:
stressed += '.' + syll
else:
try:
if is_light(syll) and is_heavy(medial[i + 1]):
stressed += '.' + syll
n += 1
continue
except IndexError:
pass
stressed += '.`' + syll
except IndexError:
pass
if len(syllables) > 1:
stressed += '.' + syllables[-1]
return stressed | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier binary_operator string string_start string_content escape_sequence string_end subscript identifier integer try_statement block expression_statement assignment identifier integer expression_statement assignment identifier subscript identifier slice integer unary_operator integer for_statement pattern_list identifier identifier call identifier argument_list identifier block if_statement comparison_operator binary_operator parenthesized_expression binary_operator identifier identifier integer integer block expression_statement augmented_assignment identifier binary_operator string string_start string_content string_end identifier else_clause block try_statement block if_statement boolean_operator call identifier argument_list identifier call identifier argument_list subscript identifier binary_operator identifier integer block expression_statement augmented_assignment identifier binary_operator string string_start string_content string_end identifier expression_statement augmented_assignment identifier integer continue_statement except_clause identifier block pass_statement expression_statement augmented_assignment identifier binary_operator string string_start string_content string_end identifier except_clause identifier block pass_statement if_statement comparison_operator call identifier argument_list identifier integer block expression_statement augmented_assignment identifier binary_operator string string_start string_content string_end subscript identifier unary_operator integer return_statement identifier | Assign primary and secondary stress to 'syllabified_simplex_word'. |
def manager(self, **kwargs):
return PreferencesManager(registry=self, model=self.preference_model, **kwargs) | module function_definition identifier parameters identifier dictionary_splat_pattern identifier block return_statement call identifier argument_list keyword_argument identifier identifier keyword_argument identifier attribute identifier identifier dictionary_splat identifier | Return a preference manager that can be used to retrieve preference values |
def make_export(self, exports):
sql = 'drop table if exists export'
logging.debug(sql)
self.cursor.execute(sql)
sql = 'create table if not exists export ' \
'(func text unique, module text)'
logging.debug(sql)
self.cursor.execute(sql)
for module in exports:
logging.debug(_('insering exports from %s'), module)
sql = 'insert into export values (?, ?)'
for func in exports[module]:
if func:
try:
self.cursor.execute(sql, (func, module))
except sqlite3.IntegrityError:
pass
self.con.commit() | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier concatenated_string string string_start string_content string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier for_statement identifier identifier block expression_statement call attribute identifier identifier argument_list call identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier string string_start string_content string_end for_statement identifier subscript identifier identifier block if_statement identifier block try_statement block expression_statement call attribute attribute identifier identifier identifier argument_list identifier tuple identifier identifier except_clause attribute identifier identifier block pass_statement expression_statement call attribute attribute identifier identifier identifier argument_list | Populate library exported function data. |
def AddAttributePath(self, **_):
attribute_path = self.current_expression.attribute
if not attribute_path:
attribute_path = []
attribute_path.append(self.string)
self.current_expression.SetAttribute(attribute_path) | module function_definition identifier parameters identifier dictionary_splat_pattern identifier block expression_statement assignment identifier attribute attribute identifier identifier identifier if_statement not_operator identifier block expression_statement assignment identifier list expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier | Adds a path component to the current attribute. |
def branch_inlet_outlet(data, commdct, branchname):
objkey = 'Branch'.upper()
theobjects = data.dt[objkey]
theobject = [obj for obj in theobjects if obj[1] == branchname]
theobject = theobject[0]
inletindex = 6
outletindex = len(theobject) - 2
return [theobject[inletindex], theobject[outletindex]] | module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list expression_statement assignment identifier subscript attribute identifier identifier identifier expression_statement assignment identifier list_comprehension identifier for_in_clause identifier identifier if_clause comparison_operator subscript identifier integer identifier expression_statement assignment identifier subscript identifier integer expression_statement assignment identifier integer expression_statement assignment identifier binary_operator call identifier argument_list identifier integer return_statement list subscript identifier identifier subscript identifier identifier | return the inlet and outlet of a branch |
def remove_empty_dir(path):
try:
if not os.path.isdir(path):
return
files = os.listdir(path)
if len(files) == 0:
os.rmdir(path)
elif len(files) > 0:
for f in files:
abspath = os.path.join(path, f)
if os.path.isdir(abspath):
remove_empty_dir(abspath)
except OSError as e:
if e.errno == errno.ENOTEMPTY:
pass | module function_definition identifier parameters identifier block try_statement block if_statement not_operator call attribute attribute identifier identifier identifier argument_list identifier block return_statement expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement comparison_operator call identifier argument_list identifier integer block expression_statement call attribute identifier identifier argument_list identifier elif_clause comparison_operator call identifier argument_list identifier integer block for_statement identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier identifier if_statement call attribute attribute identifier identifier identifier argument_list identifier block expression_statement call identifier argument_list identifier except_clause as_pattern identifier as_pattern_target identifier block if_statement comparison_operator attribute identifier identifier attribute identifier identifier block pass_statement | Function to remove empty folders |
def lookup_ids(handles):
ids = set()
for handle_list in [handles[100 * i:100 * i + 100] for i in range(len(handles))]:
if len(handle_list) > 0:
while True:
r = twapi.request('users/lookup', {'screen_name': ','.join(handle_list)})
if r.status_code in [88, 130, 420, 429]:
sys.stderr.write('Sleeping off rate limit for %s: %s\n' % (str(handle_list), r.text))
time.sleep(300)
elif r.status_code == 200:
for item in r.get_iterator():
ids.add(item['id_str'])
break
else:
sys.stderr.write('Error: %s\nSkipping %s...\n' % (str(handle_list), r.text))
break
return ids | module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list for_statement identifier list_comprehension subscript identifier slice binary_operator integer identifier binary_operator binary_operator integer identifier integer for_in_clause identifier call identifier argument_list call identifier argument_list identifier block if_statement comparison_operator call identifier argument_list identifier integer block while_statement true block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end dictionary pair string string_start string_content string_end call attribute string string_start string_content string_end identifier argument_list identifier if_statement comparison_operator attribute identifier identifier list integer integer integer integer block expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content escape_sequence string_end tuple call identifier argument_list identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list integer elif_clause comparison_operator attribute identifier identifier integer block for_statement identifier call attribute identifier identifier argument_list block expression_statement call attribute identifier identifier argument_list subscript identifier string string_start string_content string_end break_statement else_clause block expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content escape_sequence escape_sequence string_end tuple call identifier argument_list identifier attribute identifier identifier break_statement return_statement identifier | Fetch the twitter ids of each screen_name. |
def connection(self):
try:
con = self.thread.connection
except AttributeError:
con = self.steady_connection()
self.thread.connection = con
return con | module function_definition identifier parameters identifier block try_statement block expression_statement assignment identifier attribute attribute identifier identifier identifier except_clause identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment attribute attribute identifier identifier identifier identifier return_statement identifier | Get a steady, persistent PyGreSQL connection. |
def _authenticate():
global url, port, ticket, csrf, verify_ssl
url = config.get_cloud_config_value(
'url', get_configured_provider(), __opts__, search_global=False
)
port = config.get_cloud_config_value(
'port', get_configured_provider(), __opts__,
default=8006, search_global=False
)
username = config.get_cloud_config_value(
'user', get_configured_provider(), __opts__, search_global=False
),
passwd = config.get_cloud_config_value(
'password', get_configured_provider(), __opts__, search_global=False
)
verify_ssl = config.get_cloud_config_value(
'verify_ssl', get_configured_provider(), __opts__,
default=True, search_global=False
)
connect_data = {'username': username, 'password': passwd}
full_url = 'https://{0}:{1}/api2/json/access/ticket'.format(url, port)
returned_data = requests.post(
full_url, verify=verify_ssl, data=connect_data).json()
ticket = {'PVEAuthCookie': returned_data['data']['ticket']}
csrf = six.text_type(returned_data['data']['CSRFPreventionToken']) | module function_definition identifier parameters block global_statement identifier identifier identifier identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier keyword_argument identifier false expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier keyword_argument identifier integer keyword_argument identifier false expression_statement assignment identifier expression_list call attribute identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier keyword_argument identifier false expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier keyword_argument identifier false expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier keyword_argument identifier true keyword_argument identifier false expression_statement assignment identifier dictionary pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier identifier expression_statement assignment identifier call attribute call attribute identifier identifier argument_list identifier keyword_argument identifier identifier keyword_argument identifier identifier identifier argument_list expression_statement assignment identifier dictionary pair string string_start string_content string_end subscript subscript identifier string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list subscript subscript identifier string string_start string_content string_end string string_start string_content string_end | Retrieve CSRF and API tickets for the Proxmox API |
def update_datatype(self, datatype, w=None, dw=None, pw=None,
return_body=None, timeout=None, include_context=None):
raise NotImplementedError | module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier none block raise_statement identifier | Updates a Riak Datatype by sending local operations to the server. |
def create_toggle_view_action(self):
title = self.get_plugin_title()
if self.CONF_SECTION == 'editor':
title = _('Editor')
if self.shortcut is not None:
action = create_action(self, title,
toggled=lambda checked: self.toggle_view(checked),
shortcut=QKeySequence(self.shortcut),
context=Qt.WidgetShortcut)
else:
action = create_action(self, title, toggled=lambda checked:
self.toggle_view(checked))
self.toggle_view_action = action | module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier call identifier argument_list string string_start string_content string_end if_statement comparison_operator attribute identifier identifier none block expression_statement assignment identifier call identifier argument_list identifier identifier keyword_argument identifier lambda lambda_parameters identifier call attribute identifier identifier argument_list identifier keyword_argument identifier call identifier argument_list attribute identifier identifier keyword_argument identifier attribute identifier identifier else_clause block expression_statement assignment identifier call identifier argument_list identifier identifier keyword_argument identifier lambda lambda_parameters identifier call attribute identifier identifier argument_list identifier expression_statement assignment attribute identifier identifier identifier | Associate a toggle view action with each plugin |
def _get_spades_circular_nodes(self, fastg):
seq_reader = pyfastaq.sequences.file_reader(fastg)
names = set([x.id.rstrip(';') for x in seq_reader if ':' in x.id])
found_fwd = set()
found_rev = set()
for name in names:
l = name.split(':')
if len(l) != 2:
continue
if l[0] == l[1]:
if l[0][-1] == "'":
found_rev.add(l[0][:-1])
else:
found_fwd.add(l[0])
return found_fwd.intersection(found_rev) | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier call identifier argument_list list_comprehension call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end for_in_clause identifier identifier if_clause comparison_operator string string_start string_content string_end attribute identifier identifier expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier call identifier argument_list for_statement identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement comparison_operator call identifier argument_list identifier integer block continue_statement if_statement comparison_operator subscript identifier integer subscript identifier integer block if_statement comparison_operator subscript subscript identifier integer unary_operator integer string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list subscript subscript identifier integer slice unary_operator integer else_clause block expression_statement call attribute identifier identifier argument_list subscript identifier integer return_statement call attribute identifier identifier argument_list identifier | Returns set of names of nodes in SPAdes fastg file that are circular. Names will match those in spades fasta file |
def cat_acc(y, z):
weights = _cat_sample_weights(y)
_acc = K.cast(K.equal(K.argmax(y, axis=-1),
K.argmax(z, axis=-1)),
K.floatx())
_acc = K.sum(_acc * weights) / K.sum(weights)
return _acc | module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier keyword_argument identifier unary_operator integer call attribute identifier identifier argument_list identifier keyword_argument identifier unary_operator integer call attribute identifier identifier argument_list expression_statement assignment identifier binary_operator call attribute identifier identifier argument_list binary_operator identifier identifier call attribute identifier identifier argument_list identifier return_statement identifier | Classification accuracy for multi-categorical case |
def markdown_2_rst(lines):
out = []
code = False
for line in lines:
if line.strip() == "```":
code = not code
space = " " * (len(line.rstrip()) - 3)
if code:
out.append("\n\n%s.. code-block:: none\n\n" % space)
else:
out.append("\n")
else:
if code and line.strip():
line = " " + line
else:
line = line.replace("\\", "\\\\")
out.append(line)
return out | module function_definition identifier parameters identifier block expression_statement assignment identifier list expression_statement assignment identifier false for_statement identifier identifier block if_statement comparison_operator call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier not_operator identifier expression_statement assignment identifier binary_operator string string_start string_content string_end parenthesized_expression binary_operator call identifier argument_list call attribute identifier identifier argument_list integer if_statement identifier block expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content escape_sequence escape_sequence escape_sequence escape_sequence string_end identifier else_clause block expression_statement call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end else_clause block if_statement boolean_operator identifier call attribute identifier identifier argument_list block expression_statement assignment identifier binary_operator string string_start string_content string_end identifier else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end string string_start string_content escape_sequence escape_sequence string_end expression_statement call attribute identifier identifier argument_list identifier return_statement identifier | Convert markdown to restructured text |
def _construct_X_M(self, omega, **kwargs):
X = self._construct_X(omega, weighted=True, **kwargs)
M = np.dot(X.T, X)
if getattr(self, 'regularization', None) is not None:
diag = M.ravel(order='K')[::M.shape[0] + 1]
if self.regularize_by_trace:
diag += diag.sum() * np.asarray(self.regularization)
else:
diag += np.asarray(self.regularization)
return X, M | module function_definition identifier parameters identifier identifier dictionary_splat_pattern identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier keyword_argument identifier true dictionary_splat identifier expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier identifier if_statement comparison_operator call identifier argument_list identifier string string_start string_content string_end none none block expression_statement assignment identifier subscript call attribute identifier identifier argument_list keyword_argument identifier string string_start string_content string_end slice binary_operator subscript attribute identifier identifier integer integer if_statement attribute identifier identifier block expression_statement augmented_assignment identifier binary_operator call attribute identifier identifier argument_list call attribute identifier identifier argument_list attribute identifier identifier else_clause block expression_statement augmented_assignment identifier call attribute identifier identifier argument_list attribute identifier identifier return_statement expression_list identifier identifier | Construct the weighted normal matrix of the problem |
def bounds_overlap(bound1, bound2):
(x1,y1,w1,h1) = bound1
(x2,y2,w2,h2) = bound2
if x1+w1 < x2:
return False
if x2+w2 < x1:
return False
if y1+h1 < y2:
return False
if y2+h2 < y1:
return False
return True | module function_definition identifier parameters identifier identifier block expression_statement assignment tuple_pattern identifier identifier identifier identifier identifier expression_statement assignment tuple_pattern identifier identifier identifier identifier identifier if_statement comparison_operator binary_operator identifier identifier identifier block return_statement false if_statement comparison_operator binary_operator identifier identifier identifier block return_statement false if_statement comparison_operator binary_operator identifier identifier identifier block return_statement false if_statement comparison_operator binary_operator identifier identifier identifier block return_statement false return_statement true | return true if two bounding boxes overlap |
def _dense_var_to_tensor(self, dtype=None, name=None, as_ref=False):
if _enclosing_tpu_context() is None:
if hasattr(self._primary_var, '_dense_var_to_tensor'):
return self._primary_var._dense_var_to_tensor(dtype, name, as_ref)
else:
return ops.convert_to_tensor(self._primary_var)
if dtype is not None and dtype != self.dtype:
return NotImplemented
if as_ref:
return self.handle
else:
return self.read_value() | module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none default_parameter identifier false block if_statement comparison_operator call identifier argument_list none block if_statement call identifier argument_list attribute identifier identifier string string_start string_content string_end block return_statement call attribute attribute identifier identifier identifier argument_list identifier identifier identifier else_clause block return_statement call attribute identifier identifier argument_list attribute identifier identifier if_statement boolean_operator comparison_operator identifier none comparison_operator identifier attribute identifier identifier block return_statement identifier if_statement identifier block return_statement attribute identifier identifier else_clause block return_statement call attribute identifier identifier argument_list | Converts a variable to a tensor. |
def flip(f):
ensure_callable(f)
result = lambda *args, **kwargs: f(*reversed(args), **kwargs)
functools.update_wrapper(result, f, ('__name__', '__module__'))
return result | module function_definition identifier parameters identifier block expression_statement call identifier argument_list identifier expression_statement assignment identifier lambda lambda_parameters list_splat_pattern identifier dictionary_splat_pattern identifier call identifier argument_list list_splat call identifier argument_list identifier dictionary_splat identifier expression_statement call attribute identifier identifier argument_list identifier identifier tuple string string_start string_content string_end string string_start string_content string_end return_statement identifier | Flip the order of positonal arguments of given function. |
def from_git_rev_read(path):
if ":" not in path:
raise ValueError("Path identifier must start with a revision hash.")
cmd = "git", "show", "-t", path
try:
return subprocess.check_output(cmd).rstrip().decode("utf-8")
except subprocess.CalledProcessError:
raise ValueError | module function_definition identifier parameters identifier block if_statement comparison_operator string string_start string_content string_end identifier block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment identifier expression_list string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end identifier try_statement block return_statement call attribute call attribute call attribute identifier identifier argument_list identifier identifier argument_list identifier argument_list string string_start string_content string_end except_clause attribute identifier identifier block raise_statement identifier | Retrieve given file path contents of certain Git revision. |
def _make_function(instr, queue, stack, body, context):
assert stack, "Empty stack before MAKE_FUNCTION."
prev = stack[-1]
expect(prev, instrs.LOAD_CONST, "before MAKE_FUNCTION")
stack.append(instr)
if is_lambda_name(prev.arg):
return
return context.update(
make_function_context=MakeFunctionContext(
closure=isinstance(instr, instrs.MAKE_CLOSURE),
)
) | module function_definition identifier parameters identifier identifier identifier identifier identifier block assert_statement identifier string string_start string_content string_end expression_statement assignment identifier subscript identifier unary_operator integer expression_statement call identifier argument_list identifier attribute identifier identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier if_statement call identifier argument_list attribute identifier identifier block return_statement return_statement call attribute identifier identifier argument_list keyword_argument identifier call identifier argument_list keyword_argument identifier call identifier argument_list identifier attribute identifier identifier | Set a make_function_context, then push onto the stack. |
def to_dict(self):
d = {'sequence': self.sequence,
'targetComponent': self.target_component.to_dict()}
props = []
for name in self.properties:
p = {'name': name}
if self.properties[name]:
p['value'] = str(self.properties[name])
props.append(p)
if props:
d[RTS_EXT_NS_YAML + 'properties'] = props
return d | module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end call attribute attribute identifier identifier identifier argument_list expression_statement assignment identifier list for_statement identifier attribute identifier identifier block expression_statement assignment identifier dictionary pair string string_start string_content string_end identifier if_statement subscript attribute identifier identifier identifier block expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list subscript attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list identifier if_statement identifier block expression_statement assignment subscript identifier binary_operator identifier string string_start string_content string_end identifier return_statement identifier | Save this condition into a dictionary. |
def update_record(self, zeroconf, now, record):
if record is not None and not record.is_expired(now):
if record.type == _TYPE_A:
if record.name == self.name:
if not record.address in self.address:
self.address.append(record.address)
elif record.type == _TYPE_SRV:
if record.name == self.name:
self.server = record.server
self.port = record.port
self.weight = record.weight
self.priority = record.priority
self.address = []
self.update_record(zeroconf, now,
zeroconf.cache.get_by_details(self.server,
_TYPE_A, _CLASS_IN))
elif record.type == _TYPE_TXT:
if record.name == self.name:
self.set_text(record.text) | module function_definition identifier parameters identifier identifier identifier identifier block if_statement boolean_operator comparison_operator identifier none not_operator call attribute identifier identifier argument_list identifier block if_statement comparison_operator attribute identifier identifier identifier block if_statement comparison_operator attribute identifier identifier attribute identifier identifier block if_statement not_operator comparison_operator attribute identifier identifier attribute identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier elif_clause comparison_operator attribute identifier identifier identifier block if_statement comparison_operator attribute identifier identifier attribute identifier identifier block expression_statement assignment attribute identifier identifier attribute identifier identifier expression_statement assignment attribute identifier identifier attribute identifier identifier expression_statement assignment attribute identifier identifier attribute identifier identifier expression_statement assignment attribute identifier identifier attribute identifier identifier expression_statement assignment attribute identifier identifier list expression_statement call attribute identifier identifier argument_list identifier identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier identifier identifier elif_clause comparison_operator attribute identifier identifier identifier block if_statement comparison_operator attribute identifier identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier | Updates service information from a DNS record |
def package_version(self):
vbase = self.base_version
if self.ncommits:
vbase += '.dev{0}+{1}'.format(self.ncommits, self.sha)
return vbase | module function_definition identifier parameters identifier block expression_statement assignment identifier attribute identifier identifier if_statement attribute identifier identifier block expression_statement augmented_assignment identifier call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier attribute identifier identifier return_statement identifier | Returns the well formed PEP-440 version |
def convert(self, value, view):
if isinstance(value, BASESTRING):
if self.pattern and not self.regex.match(value):
self.fail(
u"must match the pattern {0}".format(self.pattern),
view
)
return value
else:
self.fail(u'must be a string', view, True) | module function_definition identifier parameters identifier identifier identifier block if_statement call identifier argument_list identifier identifier block if_statement boolean_operator attribute identifier identifier not_operator call attribute attribute identifier identifier identifier argument_list 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 return_statement identifier else_clause block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier true | Check that the value is a string and matches the pattern. |
def authenticate(self):
if self.__token:
try:
resp = self._refresh_token()
except exceptions.TVDBRequestException as err:
if getattr(err.response, 'status_code', 0) == 401:
resp = self._login()
else:
raise
else:
resp = self._login()
self.__token = resp.get('token')
self._token_timer = timeutil.utcnow() | module function_definition identifier parameters identifier block if_statement attribute identifier identifier block try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list except_clause as_pattern attribute identifier identifier as_pattern_target identifier block if_statement comparison_operator call identifier argument_list attribute identifier identifier string string_start string_content string_end integer integer block expression_statement assignment identifier call attribute identifier identifier argument_list else_clause block raise_statement else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list | Aquire authorization token for using thetvdb apis. |
def init_sources(path):
for f in dir_list(path):
if(os.path.splitext(f)[1][1:] == config.source_ext):
print "Source file discovered: %s" % (f)
script = Script(f)
if (script.filename not in config.sources.keys()):
config.sources[script.path] = script
parse.parse_dependencies(script,script) | module function_definition identifier parameters identifier block for_statement identifier call identifier argument_list identifier block if_statement parenthesized_expression comparison_operator subscript subscript call attribute attribute identifier identifier identifier argument_list identifier integer slice integer attribute identifier identifier block print_statement binary_operator string string_start string_content string_end parenthesized_expression identifier expression_statement assignment identifier call identifier argument_list identifier if_statement parenthesized_expression comparison_operator attribute identifier identifier call attribute attribute identifier identifier identifier argument_list block expression_statement assignment subscript attribute identifier identifier attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list identifier identifier | initializes array of groups and their associated js files |
def to_datetime(value):
if value is None:
return None
if isinstance(value, six.integer_types):
return parser.parse(value)
return parser.isoparse(value) | module function_definition identifier parameters identifier block if_statement comparison_operator identifier none block return_statement none if_statement call identifier argument_list identifier attribute identifier identifier block return_statement call attribute identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list identifier | Converts a string to a datetime. |
def register_segment_dcnm(self, cfg, seg_id_min, seg_id_max):
orch_id = cfg.dcnm.orchestrator_id
try:
segid_range = self.dcnm_client.get_segmentid_range(orch_id)
if segid_range is None:
self.dcnm_client.set_segmentid_range(orch_id, seg_id_min,
seg_id_max)
else:
conf_min, _, conf_max = segid_range[
"segmentIdRanges"].partition("-")
if int(conf_min) != seg_id_min or int(conf_max) != seg_id_max:
self.dcnm_client.update_segmentid_range(orch_id,
seg_id_min,
seg_id_max)
except dexc.DfaClientRequestFailed as exc:
LOG.error("Segment ID range could not be created/updated"
" on DCNM: %s", exc)
raise SystemExit(exc) | module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier attribute attribute identifier identifier identifier try_statement 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 attribute identifier identifier identifier argument_list identifier identifier identifier else_clause block expression_statement assignment pattern_list identifier identifier identifier call attribute subscript identifier string string_start string_content string_end identifier argument_list string string_start string_content string_end if_statement boolean_operator comparison_operator call identifier argument_list identifier identifier comparison_operator call identifier argument_list identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list identifier identifier identifier except_clause as_pattern attribute identifier identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list concatenated_string string string_start string_content string_end string string_start string_content string_end identifier raise_statement call identifier argument_list identifier | Register segmentation id pool with DCNM. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.