code
stringlengths
51
2.34k
sequence
stringlengths
186
3.94k
docstring
stringlengths
11
171
def _spot_check_that_elements_produced_by_this_generator_have_attribute(self, name): g_tmp = self.values_gen.spawn() sample_element = next(g_tmp)[0] try: getattr(sample_element, name) except AttributeError: raise AttributeError(f"Items produced by {self} do not have the attribute '{name}'")
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list expression_statement assignment identifier subscript call identifier argument_list identifier integer try_statement block expression_statement call identifier argument_list identifier identifier except_clause identifier block raise_statement call identifier argument_list string string_start string_content interpolation identifier string_content interpolation identifier string_content string_end
Helper function to spot-check that the items produces by this generator have the attribute `name`.
def flush(self): for name in self.item_names: item = self[name] item.flush() self.file.flush()
module function_definition identifier parameters identifier block for_statement identifier attribute identifier identifier block expression_statement assignment identifier subscript identifier identifier expression_statement call attribute identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list
Ensure contents are written to file.
def result(self, value): if self._process_result: self._result = self._process_result(value) self._raw_result = value
module function_definition identifier parameters identifier identifier block if_statement attribute identifier identifier block expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list identifier expression_statement assignment attribute identifier identifier identifier
The result of the command.
def register(self, entity): response = self.api.post_entity(entity.serialize) print(response) print() if response['status']['code'] == 200: entity.id = response['id'] if response['status']['code'] == 409: entity.id = next(i.id for i in self.api.agent_entities if i.name == entity.name) self.update(entity) return entity
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement call identifier argument_list identifier expression_statement call identifier argument_list if_statement comparison_operator subscript subscript identifier string string_start string_content string_end string string_start string_content string_end integer block expression_statement assignment attribute identifier identifier subscript identifier string string_start string_content string_end if_statement comparison_operator subscript subscript identifier string string_start string_content string_end string string_start string_content string_end integer block expression_statement assignment attribute identifier identifier call identifier generator_expression attribute identifier identifier for_in_clause identifier attribute attribute identifier identifier identifier if_clause comparison_operator attribute identifier identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier return_statement identifier
Registers a new entity and returns the entity object with an ID
def as_dict(self): result = {} for key in self._valid_properties: val = getattr(self, key) if isinstance(val, datetime): val = val.isoformat() elif val and not Model._is_builtin(val): val = val.as_dict() elif isinstance(val, list): for i in range(len(val)): if Model._is_builtin(val[i]): continue val[i] = val[i].as_dict() elif isinstance(val, bool): result[key] = val if val: result[key] = val return result
module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary for_statement identifier attribute identifier identifier block expression_statement assignment identifier call identifier argument_list identifier identifier if_statement call identifier argument_list identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list elif_clause boolean_operator identifier not_operator call attribute identifier identifier argument_list identifier block expression_statement assignment identifier call attribute identifier identifier argument_list elif_clause call identifier argument_list identifier identifier block for_statement identifier call identifier argument_list call identifier argument_list identifier block if_statement call attribute identifier identifier argument_list subscript identifier identifier block continue_statement expression_statement assignment subscript identifier identifier call attribute subscript identifier identifier identifier argument_list elif_clause call identifier argument_list identifier identifier block expression_statement assignment subscript identifier identifier identifier if_statement identifier block expression_statement assignment subscript identifier identifier identifier return_statement identifier
Returns a dict representation of the resource
def render(self, model, color, num_turtles): self.program.bind() glBindVertexArray(self.vao) self.model_buffer.load(model.data, model.byte_size) self.color_buffer.load(color.data, color.byte_size) glDrawArraysInstanced( GL_TRIANGLES, 0, len(self.geometry.edges) // 7, num_turtles ) glBindVertexArray(0) self.program.unbind()
module function_definition identifier parameters identifier identifier identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list expression_statement call identifier argument_list attribute identifier identifier 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 binary_operator call identifier argument_list attribute attribute identifier identifier identifier integer identifier expression_statement call identifier argument_list integer expression_statement call attribute attribute identifier identifier identifier argument_list
Renders all turtles of a given shape
async def _execute(self, appt): user = self.core.auth.user(appt.useriden) if user is None: logger.warning('Unknown user %s in stored appointment', appt.useriden) await self._markfailed(appt) return await self.core.boss.execute(self._runJob(user, appt), f'Agenda {appt.iden}', user)
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list attribute identifier identifier if_statement comparison_operator identifier none block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end attribute identifier identifier expression_statement await call attribute identifier identifier argument_list identifier return_statement expression_statement await call attribute attribute attribute identifier identifier identifier identifier argument_list call attribute identifier identifier argument_list identifier identifier string string_start string_content interpolation attribute identifier identifier string_end identifier
Fire off the task to make the storm query
def tags_context(self, worker_ctx, exc_info): tags = { 'call_id': worker_ctx.call_id, 'parent_call_id': worker_ctx.immediate_parent_call_id, 'service_name': worker_ctx.container.service_name, 'method_name': worker_ctx.entrypoint.method_name } for key in worker_ctx.context_data: for matcher in self.tag_type_context_keys: if re.search(matcher, key): tags[key] = worker_ctx.context_data[key] break self.client.tags_context(tags)
module function_definition identifier parameters identifier identifier 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 attribute identifier identifier pair string string_start string_content string_end attribute attribute identifier identifier identifier pair string string_start string_content string_end attribute attribute identifier identifier identifier for_statement identifier attribute identifier identifier block for_statement identifier attribute identifier identifier block if_statement call attribute identifier identifier argument_list identifier identifier block expression_statement assignment subscript identifier identifier subscript attribute identifier identifier identifier break_statement expression_statement call attribute attribute identifier identifier identifier argument_list identifier
Merge any tags to include in the sentry payload.
def delete(self, uid): if self.check_post_role()['DELETE']: pass else: return False histinfo = MWikiHist.get_by_uid(uid) if histinfo: pass else: return False postinfo = MWiki.get_by_uid(histinfo.wiki_id) MWikiHist.delete(uid) self.redirect('/wiki_man/view/{0}'.format(postinfo.uid))
module function_definition identifier parameters identifier identifier block if_statement subscript call attribute identifier identifier argument_list string string_start string_content string_end block pass_statement else_clause block return_statement false expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement identifier block pass_statement else_clause block return_statement false expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier
Delete the history of certain ID.
def ReadCronJobs(self, cronjob_ids=None): if cronjob_ids is None: res = [job.Copy() for job in itervalues(self.cronjobs)] else: res = [] for job_id in cronjob_ids: try: res.append(self.cronjobs[job_id].Copy()) except KeyError: raise db.UnknownCronJobError("Cron job with id %s not found." % job_id) for job in res: lease = self.cronjob_leases.get(job.cron_job_id) if lease: job.leased_until, job.leased_by = lease return res
module function_definition identifier parameters identifier default_parameter identifier none block if_statement comparison_operator identifier none block expression_statement assignment identifier list_comprehension call attribute identifier identifier argument_list for_in_clause identifier call identifier argument_list attribute identifier identifier else_clause block expression_statement assignment identifier list for_statement identifier identifier block try_statement block expression_statement call attribute identifier identifier argument_list call attribute subscript attribute identifier identifier identifier identifier argument_list except_clause identifier block raise_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end identifier for_statement identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier if_statement identifier block expression_statement assignment pattern_list attribute identifier identifier attribute identifier identifier identifier return_statement identifier
Reads a cronjob from the database.
def draw(self): cell_background_renderer = GridCellBackgroundCairoRenderer( self.context, self.code_array, self.key, self.rect, self.view_frozen) cell_content_renderer = GridCellContentCairoRenderer( self.context, self.code_array, self.key, self.rect, self.spell_check) cell_border_renderer = GridCellBorderCairoRenderer( self.context, self.code_array, self.key, self.rect) cell_background_renderer.draw() cell_content_renderer.draw() cell_border_renderer.draw()
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list attribute identifier identifier attribute identifier identifier attribute identifier identifier attribute identifier identifier attribute identifier identifier expression_statement assignment identifier call identifier argument_list attribute identifier identifier attribute identifier identifier attribute identifier identifier attribute identifier identifier attribute identifier identifier expression_statement assignment identifier call identifier argument_list attribute identifier identifier attribute identifier identifier attribute identifier identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list
Draws cell to context
def register_master(): tango_db = Database() device = "sip_sdp/elt/master" device_info = DbDevInfo() device_info._class = "SDPMasterDevice" device_info.server = "sdp_master_ds/1" device_info.name = device devices = tango_db.get_device_name(device_info.server, device_info._class) if device not in devices: LOG.info('Registering device "%s" with device server "%s"', device_info.name, device_info.server) tango_db.add_device(device_info)
module function_definition identifier parameters block expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier string string_start string_content string_end expression_statement assignment identifier call identifier argument_list expression_statement assignment attribute identifier identifier string string_start string_content string_end expression_statement assignment attribute identifier identifier string string_start string_content string_end expression_statement assignment attribute identifier identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier if_statement comparison_operator identifier identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end attribute identifier identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list identifier
Register the SDP Master device.
def _set_spyder_breakpoints(self, breakpoints): if not self._pdb_obj: return serialized_breakpoints = breakpoints[0] breakpoints = pickle.loads(serialized_breakpoints) self._pdb_obj.set_spyder_breakpoints(breakpoints)
module function_definition identifier parameters identifier identifier block if_statement not_operator attribute identifier identifier block return_statement expression_statement assignment identifier subscript identifier integer expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier
Set all Spyder breakpoints in an active pdb session
def read_profiles(profiles_dir=None): if profiles_dir is None: profiles_dir = PROFILES_DIR raw_profiles = read_profile(profiles_dir) if raw_profiles is None: profiles = {} else: profiles = {k: v for (k, v) in raw_profiles.items() if k != 'config'} return profiles
module function_definition identifier parameters default_parameter identifier none block if_statement comparison_operator identifier none block expression_statement assignment identifier identifier expression_statement assignment identifier call identifier argument_list identifier if_statement comparison_operator identifier none block expression_statement assignment identifier dictionary else_clause block expression_statement assignment identifier dictionary_comprehension pair identifier identifier for_in_clause tuple_pattern identifier identifier call attribute identifier identifier argument_list if_clause comparison_operator identifier string string_start string_content string_end return_statement identifier
This is only used for some error handling
def commit(self, callback=None): if self.executed: raise InvalidTransaction('Invalid operation. ' 'Transaction already executed.') session = self.session self.session = None self.on_result = self._commit(session, callback) return self.on_result
module function_definition identifier parameters identifier default_parameter identifier none block if_statement attribute identifier identifier block raise_statement call identifier argument_list concatenated_string string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier attribute identifier identifier expression_statement assignment attribute identifier identifier none expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list identifier identifier return_statement attribute identifier identifier
Close the transaction and commit session to the backend.
def __flushLevel(self, level): objectsCount = len(self.objectsStack) while objectsCount > level: lastIndex = objectsCount - 1 if lastIndex == 0: if self.objectsStack[0].__class__.__name__ == "Class": self.classes.append(self.objectsStack[0]) else: self.functions.append(self.objectsStack[0]) self.objectsStack = [] break if self.objectsStack[lastIndex].__class__.__name__ == "Class": self.objectsStack[lastIndex - 1].classes. \ append(self.objectsStack[lastIndex]) else: self.objectsStack[lastIndex - 1].functions. \ append(self.objectsStack[lastIndex]) del self.objectsStack[lastIndex] objectsCount -= 1
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list attribute identifier identifier while_statement comparison_operator identifier identifier block expression_statement assignment identifier binary_operator identifier integer if_statement comparison_operator identifier integer block if_statement comparison_operator attribute attribute subscript attribute identifier identifier integer identifier identifier string string_start string_content string_end block expression_statement call attribute attribute identifier identifier identifier argument_list subscript attribute identifier identifier integer else_clause block expression_statement call attribute attribute identifier identifier identifier argument_list subscript attribute identifier identifier integer expression_statement assignment attribute identifier identifier list break_statement if_statement comparison_operator attribute attribute subscript attribute identifier identifier identifier identifier identifier string string_start string_content string_end block expression_statement call attribute attribute subscript attribute identifier identifier binary_operator identifier integer identifier line_continuation identifier argument_list subscript attribute identifier identifier identifier else_clause block expression_statement call attribute attribute subscript attribute identifier identifier binary_operator identifier integer identifier line_continuation identifier argument_list subscript attribute identifier identifier identifier delete_statement subscript attribute identifier identifier identifier expression_statement augmented_assignment identifier integer
Merge the found objects to the required level
def clear_dir(self): self.stdout.write("Deleting contents of '{}'.".format(self.destination_path)) for filename in os.listdir(self.destination_path): if os.path.isfile(filename) or os.path.islink(filename): os.remove(filename) elif os.path.isdir(filename): shutil.rmtree(filename)
module function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list attribute identifier identifier for_statement identifier call attribute identifier identifier argument_list attribute identifier identifier block if_statement boolean_operator call attribute attribute identifier identifier identifier argument_list identifier call attribute attribute identifier identifier identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list identifier elif_clause call attribute attribute identifier identifier identifier argument_list identifier block expression_statement call attribute identifier identifier argument_list identifier
Delete contents of the directory on the given path.
def _domain_event_metadata_change_cb(conn, domain, mtype, nsuri, opaque): _salt_send_domain_event(opaque, conn, domain, opaque['event'], { 'type': _get_libvirt_enum_string('VIR_DOMAIN_METADATA_', mtype), 'nsuri': nsuri })
module function_definition identifier parameters identifier identifier identifier identifier identifier block expression_statement call identifier argument_list identifier identifier identifier subscript identifier string string_start string_content string_end dictionary pair string string_start string_content string_end call identifier argument_list string string_start string_content string_end identifier pair string string_start string_content string_end identifier
Domain metadata change events handler
def _handle_actionpush(self, length): init_pos = self._src.tell() while self._src.tell() < init_pos + length: obj = _make_object("ActionPush") obj.Type = unpack_ui8(self._src) push_types = { 0: ("String", self._get_struct_string), 1: ("Float", lambda: unpack_float(self._src)), 2: ("Null", lambda: None), 4: ("RegisterNumber", lambda: unpack_ui8(self._src)), 5: ("Boolean", lambda: unpack_ui8(self._src)), 6: ("Double", lambda: unpack_double(self._src)), 7: ("Integer", lambda: unpack_ui32(self._src)), 8: ("Constant8", lambda: unpack_ui8(self._src)), 9: ("Constant16", lambda: unpack_ui16(self._src)), } name, func = push_types[obj.Type] setattr(obj, name, func()) yield obj
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list while_statement comparison_operator call attribute attribute identifier identifier identifier argument_list binary_operator identifier identifier block expression_statement assignment identifier call identifier argument_list string string_start string_content string_end expression_statement assignment attribute identifier identifier call identifier argument_list attribute identifier identifier expression_statement assignment identifier dictionary pair integer tuple string string_start string_content string_end attribute identifier identifier pair integer tuple string string_start string_content string_end lambda call identifier argument_list attribute identifier identifier pair integer tuple string string_start string_content string_end lambda none pair integer tuple string string_start string_content string_end lambda call identifier argument_list attribute identifier identifier pair integer tuple string string_start string_content string_end lambda call identifier argument_list attribute identifier identifier pair integer tuple string string_start string_content string_end lambda call identifier argument_list attribute identifier identifier pair integer tuple string string_start string_content string_end lambda call identifier argument_list attribute identifier identifier pair integer tuple string string_start string_content string_end lambda call identifier argument_list attribute identifier identifier pair integer tuple string string_start string_content string_end lambda call identifier argument_list attribute identifier identifier expression_statement assignment pattern_list identifier identifier subscript identifier attribute identifier identifier expression_statement call identifier argument_list identifier identifier call identifier argument_list expression_statement yield identifier
Handle the ActionPush action.
def reject(self, reason): if self._state != 'pending': raise RuntimeError('Promise is no longer pending.') self.reason = reason self._state = 'rejected' errbacks = self._errbacks self._errbacks = None for errback in errbacks: errback(reason)
module function_definition identifier parameters identifier identifier block if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment attribute identifier identifier identifier expression_statement assignment attribute identifier identifier string string_start string_content string_end expression_statement assignment identifier attribute identifier identifier expression_statement assignment attribute identifier identifier none for_statement identifier identifier block expression_statement call identifier argument_list identifier
Rejects the promise with the given reason.
def find_loci(self): session = OAuth1Session(self.consumer_key, self.consumer_secret, access_token=self.session_token, access_token_secret=self.session_secret) r = session.get(self.loci) if r.status_code == 200 or r.status_code == 201: if re.search('json', r.headers['content-type'], flags=0): decoded = r.json() else: decoded = r.text for locus in decoded['loci']: self.loci_url.append(locus)
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list attribute identifier identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier if_statement boolean_operator comparison_operator attribute identifier identifier integer comparison_operator attribute identifier identifier integer block if_statement call attribute identifier identifier argument_list string string_start string_content string_end subscript attribute identifier identifier string string_start string_content string_end keyword_argument identifier integer block expression_statement assignment identifier call attribute identifier identifier argument_list else_clause block expression_statement assignment identifier attribute identifier identifier for_statement identifier subscript identifier string string_start string_content string_end block expression_statement call attribute attribute identifier identifier identifier argument_list identifier
Finds the URLs for all allele files
def to_feature_reports(self, debug=False): rest = self.to_string() seq = 0 out = [] while rest: this, rest = rest[:7], rest[7:] if seq > 0 and rest: if this != b'\x00\x00\x00\x00\x00\x00\x00': this += yubico_util.chr_byte(yubikey_defs.SLOT_WRITE_FLAG + seq) out.append(self._debug_string(debug, this)) else: this += yubico_util.chr_byte(yubikey_defs.SLOT_WRITE_FLAG + seq) out.append(self._debug_string(debug, this)) seq += 1 return out
module function_definition identifier parameters identifier default_parameter identifier false block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier integer expression_statement assignment identifier list while_statement identifier block expression_statement assignment pattern_list identifier identifier expression_list subscript identifier slice integer subscript identifier slice integer if_statement boolean_operator comparison_operator identifier integer identifier block if_statement comparison_operator identifier string string_start string_content escape_sequence escape_sequence escape_sequence escape_sequence escape_sequence escape_sequence escape_sequence string_end block expression_statement augmented_assignment identifier call attribute identifier identifier argument_list binary_operator attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier identifier else_clause block expression_statement augmented_assignment identifier call attribute identifier identifier argument_list binary_operator attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier identifier expression_statement augmented_assignment identifier integer return_statement identifier
Return the frame as an array of 8-byte parts, ready to be sent to a YubiKey.
def status(self): status_request = etcdrpc.StatusRequest() status_response = self.maintenancestub.Status( status_request, self.timeout, credentials=self.call_credentials, metadata=self.metadata ) for m in self.members: if m.id == status_response.leader: leader = m break else: leader = None return Status(status_response.version, status_response.dbSize, leader, status_response.raftIndex, status_response.raftTerm)
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier for_statement identifier attribute identifier identifier block if_statement comparison_operator attribute identifier identifier attribute identifier identifier block expression_statement assignment identifier identifier break_statement else_clause block expression_statement assignment identifier none return_statement call identifier argument_list attribute identifier identifier attribute identifier identifier identifier attribute identifier identifier attribute identifier identifier
Get the status of the responding member.
def check_link(self, link): r = requests.get(CHECK_LINK_ENDPOINT + link) if r.status_code != 200: raise GfycatClientError('Unable to check the link', r.status_code) return r.json()
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list binary_operator identifier identifier if_statement comparison_operator attribute identifier identifier integer block raise_statement call identifier argument_list string string_start string_content string_end attribute identifier identifier return_statement call attribute identifier identifier argument_list
Check if a link has been already converted.
def make_video_cache(self, days=None): if days is None: days = self._min_days_vdo_cache self._cached_videos = self.videos(days)
module function_definition identifier parameters identifier default_parameter identifier none block if_statement comparison_operator identifier none block expression_statement assignment identifier attribute identifier identifier expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list identifier
Save videos on _cache_videos to avoid dups.
def delete_lbaas_member(self, lbaas_member, lbaas_pool): return self.delete(self.lbaas_member_path % (lbaas_pool, lbaas_member))
module function_definition identifier parameters identifier identifier identifier block return_statement call attribute identifier identifier argument_list binary_operator attribute identifier identifier tuple identifier identifier
Deletes the specified lbaas_member.
def namedb_get_num_names( cur, current_block, include_expired=False ): unexpired_query = "" unexpired_args = () if not include_expired: unexpired_query, unexpired_args = namedb_select_where_unexpired_names( current_block ) unexpired_query = 'WHERE {}'.format(unexpired_query) query = "SELECT COUNT(name_records.name) FROM name_records JOIN namespaces ON name_records.namespace_id = namespaces.namespace_id " + unexpired_query + ";" args = unexpired_args num_rows = namedb_select_count_rows( cur, query, args, count_column='COUNT(name_records.name)' ) return num_rows
module function_definition identifier parameters identifier identifier default_parameter identifier false block expression_statement assignment identifier string string_start string_end expression_statement assignment identifier tuple if_statement not_operator identifier block expression_statement assignment pattern_list identifier identifier call identifier argument_list identifier expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier expression_statement assignment identifier binary_operator binary_operator string string_start string_content string_end identifier string string_start string_content string_end expression_statement assignment identifier identifier expression_statement assignment identifier call identifier argument_list identifier identifier identifier keyword_argument identifier string string_start string_content string_end return_statement identifier
Get the number of names that exist at the current block
def create_client_for_file(self, filename, is_cython=False): self.create_new_client(filename=filename, is_cython=is_cython) self.master_clients -= 1 client = self.get_current_client() client.allow_rename = False tab_text = self.disambiguate_fname(filename) self.rename_client_tab(client, tab_text)
module function_definition identifier parameters identifier identifier default_parameter identifier false block expression_statement call attribute identifier identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier expression_statement augmented_assignment attribute identifier identifier integer expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment attribute identifier identifier false expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier identifier
Create a client to execute code related to a file.
def create_toolbar_tokens_func(get_is_refreshing, show_fish_help): token = Token.Toolbar def get_toolbar_tokens(cli): result = [] result.append((token, ' ')) if cli.buffers[DEFAULT_BUFFER].always_multiline: result.append((token.On, '[F3] Multiline: ON ')) else: result.append((token.Off, '[F3] Multiline: OFF ')) if cli.buffers[DEFAULT_BUFFER].always_multiline: result.append((token, ' (Semi-colon [;] will end the line)')) if cli.editing_mode == EditingMode.VI: result.append(( token.On, 'Vi-mode ({})'.format(_get_vi_mode(cli)) )) if show_fish_help(): result.append((token, ' Right-arrow to complete suggestion')) if get_is_refreshing(): result.append((token, ' Refreshing completions...')) return result return get_toolbar_tokens
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier attribute identifier identifier function_definition identifier parameters identifier block expression_statement assignment identifier list expression_statement call attribute identifier identifier argument_list tuple identifier string string_start string_content string_end if_statement attribute subscript attribute identifier identifier identifier identifier block expression_statement call attribute identifier identifier argument_list tuple attribute identifier identifier string string_start string_content string_end else_clause block expression_statement call attribute identifier identifier argument_list tuple attribute identifier identifier string string_start string_content string_end if_statement attribute subscript attribute identifier identifier identifier identifier block expression_statement call attribute identifier identifier argument_list tuple identifier string string_start string_content string_end if_statement comparison_operator attribute identifier identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list tuple attribute identifier identifier call attribute string string_start string_content string_end identifier argument_list call identifier argument_list identifier if_statement call identifier argument_list block expression_statement call attribute identifier identifier argument_list tuple identifier string string_start string_content string_end if_statement call identifier argument_list block expression_statement call attribute identifier identifier argument_list tuple identifier string string_start string_content string_end return_statement identifier return_statement identifier
Return a function that generates the toolbar tokens.
def _remove_bcbiovm_path(): cur_path = os.path.dirname(os.path.realpath(sys.executable)) paths = os.environ["PATH"].split(":") if cur_path in paths: paths.remove(cur_path) os.environ["PATH"] = ":".join(paths)
module function_definition identifier parameters block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement assignment identifier call attribute subscript attribute identifier identifier string string_start string_content string_end identifier argument_list string string_start string_content string_end if_statement comparison_operator identifier identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end call attribute string string_start string_content string_end identifier argument_list identifier
Avoid referencing minimal bcbio_nextgen in bcbio_vm installation.
def getobject_use_prevfield(idf, idfobject, fieldname): if not fieldname.endswith("Name"): return None fdnames = idfobject.fieldnames ifieldname = fdnames.index(fieldname) prevfdname = fdnames[ifieldname - 1] if not prevfdname.endswith("Object_Type"): return None objkey = idfobject[prevfdname].upper() objname = idfobject[fieldname] try: foundobj = idf.getobject(objkey, objname) except KeyError as e: return None return foundobj
module function_definition identifier parameters identifier identifier identifier block if_statement not_operator call attribute identifier identifier argument_list string string_start string_content string_end block return_statement none expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier subscript identifier binary_operator identifier integer if_statement not_operator call attribute identifier identifier argument_list string string_start string_content string_end block return_statement none expression_statement assignment identifier call attribute subscript identifier identifier identifier argument_list expression_statement assignment identifier subscript identifier identifier try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier except_clause as_pattern identifier as_pattern_target identifier block return_statement none return_statement identifier
field=object_name, prev_field=object_type. Return the object
def _request_titles_xml() -> ET.ElementTree: response = api.titles_request() return api.unpack_xml(response.text)
module function_definition identifier parameters type attribute identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list return_statement call attribute identifier identifier argument_list attribute identifier identifier
Request AniDB titles file.
def Negation(expr: Expression) -> Expression: expr = Expression(_negate(expr.body)) return ast.fix_missing_locations(expr)
module function_definition identifier parameters typed_parameter identifier type identifier type identifier block expression_statement assignment identifier call identifier argument_list call identifier argument_list attribute identifier identifier return_statement call attribute identifier identifier argument_list identifier
Return expression which is the negation of `expr`.
def __get_tokens(self, row): row_tokenizer = RowTokenizer(row, self.config) line = row_tokenizer.next() while line: yield line line = row_tokenizer.next()
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list while_statement identifier block expression_statement yield identifier expression_statement assignment identifier call attribute identifier identifier argument_list
Row should be a single string
def add_current_vrf(self): vrf_id = request.json['vrf_id'] if vrf_id is not None: if vrf_id == 'null': vrf = VRF() else: vrf_id = int(vrf_id) vrf = VRF.get(vrf_id) session['current_vrfs'][vrf_id] = { 'id': vrf.id, 'rt': vrf.rt, 'name': vrf.name, 'description': vrf.description } session.save() return json.dumps(session.get('current_vrfs', {}))
module function_definition identifier parameters identifier block expression_statement assignment identifier subscript attribute identifier identifier string string_start string_content string_end if_statement comparison_operator identifier none block if_statement comparison_operator identifier string string_start string_content string_end block expression_statement assignment identifier call identifier argument_list else_clause block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment subscript subscript identifier string string_start string_content string_end identifier dictionary pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier expression_statement call attribute identifier identifier argument_list return_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end dictionary
Add VRF to filter list session variable
def OnTimerToggle(self, event): if self.grid.timer_running: self.grid.timer_running = False self.grid.timer.Stop() del self.grid.timer else: self.grid.timer_running = True self.grid.timer = wx.Timer(self.grid) self.grid.timer.Start(config["timer_interval"])
module function_definition identifier parameters identifier identifier block if_statement attribute attribute identifier identifier identifier block expression_statement assignment attribute attribute identifier identifier identifier false expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list delete_statement attribute attribute identifier identifier identifier else_clause block expression_statement assignment attribute attribute identifier identifier identifier true expression_statement assignment attribute attribute identifier identifier identifier call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list subscript identifier string string_start string_content string_end
Toggles the timer for updating frozen cells
def keys(self): keys = Struct.keys(self) for key in ( '_cloud_provider', '_naming_policy', '_setup_provider', 'known_hosts_file', 'repository', ): if key in keys: keys.remove(key) return keys
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier for_statement 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 string string_start string_content string_end block if_statement comparison_operator identifier identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement identifier
Only expose some of the attributes when using as a dictionary
def expr_to_json(expr): if isinstance(expr, symbolics.Mul): return {"type": "Mul", "args": [expr_to_json(arg) for arg in expr.args]} elif isinstance(expr, symbolics.Add): return {"type": "Add", "args": [expr_to_json(arg) for arg in expr.args]} elif isinstance(expr, symbolics.Symbol): return {"type": "Symbol", "name": expr.name} elif isinstance(expr, symbolics.Pow): return {"type": "Pow", "args": [expr_to_json(arg) for arg in expr.args]} elif isinstance(expr, (float, int)): return {"type": "Number", "value": expr} elif isinstance(expr, symbolics.Real): return {"type": "Number", "value": float(expr)} elif isinstance(expr, symbolics.Integer): return {"type": "Number", "value": int(expr)} else: raise NotImplementedError("Type not implemented: " + str(type(expr)))
module function_definition identifier parameters identifier block if_statement call identifier argument_list identifier attribute identifier identifier block return_statement dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end list_comprehension call identifier argument_list identifier for_in_clause identifier attribute identifier identifier elif_clause call identifier argument_list identifier attribute identifier identifier block return_statement dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end list_comprehension call identifier argument_list identifier for_in_clause identifier attribute identifier identifier elif_clause call identifier argument_list identifier attribute identifier identifier block return_statement dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end attribute identifier identifier elif_clause call identifier argument_list identifier attribute identifier identifier block return_statement dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end list_comprehension call identifier argument_list identifier for_in_clause identifier attribute identifier identifier elif_clause call identifier argument_list identifier tuple identifier identifier block return_statement dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end identifier elif_clause call identifier argument_list identifier attribute identifier identifier block return_statement dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end call identifier argument_list identifier elif_clause call identifier argument_list identifier attribute identifier identifier block return_statement dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end call identifier argument_list identifier else_clause 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
Converts a Sympy expression to a json-compatible tree-structure.
def do_function(self, prov, func, kwargs): matches = self.lookup_providers(prov) if len(matches) > 1: raise SaltCloudSystemExit( 'More than one results matched \'{0}\'. Please specify ' 'one of: {1}'.format( prov, ', '.join([ '{0}:{1}'.format(alias, driver) for (alias, driver) in matches ]) ) ) alias, driver = matches.pop() fun = '{0}.{1}'.format(driver, func) if fun not in self.clouds: raise SaltCloudSystemExit( 'The \'{0}\' cloud provider alias, for the \'{1}\' driver, does ' 'not define the function \'{2}\''.format(alias, driver, func) ) log.debug( 'Trying to execute \'%s\' with the following kwargs: %s', fun, kwargs ) with salt.utils.context.func_globals_inject( self.clouds[fun], __active_provider_name__=':'.join([alias, driver]) ): if kwargs: return { alias: { driver: self.clouds[fun]( call='function', kwargs=kwargs ) } } return { alias: { driver: self.clouds[fun](call='function') } }
module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement comparison_operator call identifier argument_list identifier integer block raise_statement call identifier argument_list call attribute concatenated_string string string_start string_content escape_sequence escape_sequence string_end string string_start string_content string_end identifier argument_list identifier call attribute string string_start string_content string_end identifier argument_list list_comprehension call attribute string string_start string_content string_end identifier argument_list identifier identifier for_in_clause tuple_pattern identifier identifier identifier expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier identifier if_statement comparison_operator identifier attribute identifier identifier block raise_statement call identifier argument_list call attribute concatenated_string string string_start string_content escape_sequence escape_sequence escape_sequence escape_sequence string_end string string_start string_content escape_sequence escape_sequence string_end identifier argument_list identifier identifier identifier expression_statement call attribute identifier identifier argument_list string string_start string_content escape_sequence escape_sequence string_end identifier identifier with_statement with_clause with_item call attribute attribute attribute identifier identifier identifier identifier argument_list subscript attribute identifier identifier identifier keyword_argument identifier call attribute string string_start string_content string_end identifier argument_list list identifier identifier block if_statement identifier block return_statement dictionary pair identifier dictionary pair identifier call subscript attribute identifier identifier identifier argument_list keyword_argument identifier string string_start string_content string_end keyword_argument identifier identifier return_statement dictionary pair identifier dictionary pair identifier call subscript attribute identifier identifier identifier argument_list keyword_argument identifier string string_start string_content string_end
Perform a function against a cloud provider
def pan_cb(self, setting, value): pan_x, pan_y = value[:2] self.logger.debug("pan set to %.2f,%.2f" % (pan_x, pan_y)) self.redraw(whence=0)
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment pattern_list identifier identifier subscript identifier slice integer expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content string_end tuple identifier identifier expression_statement call attribute identifier identifier argument_list keyword_argument identifier integer
Handle callback related to changes in pan.
def GetPythonLibraryDirectoryPath(): path = sysconfig.get_python_lib(True) _, _, path = path.rpartition(sysconfig.PREFIX) if path.startswith(os.sep): path = path[1:] return path
module function_definition identifier parameters block expression_statement assignment identifier call attribute identifier identifier argument_list true expression_statement assignment pattern_list identifier identifier identifier call attribute identifier identifier argument_list attribute identifier identifier if_statement call attribute identifier identifier argument_list attribute identifier identifier block expression_statement assignment identifier subscript identifier slice integer return_statement identifier
Retrieves the Python library directory path.
def to_bool(text): downcased_text = six.text_type(text).strip().lower() if downcased_text == 'false': return False elif downcased_text == 'true': return True return text
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute call attribute call attribute identifier identifier argument_list identifier identifier argument_list identifier argument_list if_statement comparison_operator identifier string string_start string_content string_end block return_statement false elif_clause comparison_operator identifier string string_start string_content string_end block return_statement true return_statement identifier
Convert the string name of a boolean to that boolean value.
def _ndefs(f): if isinstance(f, Function): return f.ndefs spec = inspect.getfullargspec(f) if spec.defaults is None: return 0 return len(spec.defaults)
module function_definition identifier parameters identifier block if_statement call identifier argument_list identifier identifier block return_statement attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement comparison_operator attribute identifier identifier none block return_statement integer return_statement call identifier argument_list attribute identifier identifier
number of any default values for positional or keyword parameters
async def _send_packet(self, pkt): if self.state != 'connected': return await self.queue.put(pkt) self.logger.info( 'Sending packet %s data %s', packet.packet_names[pkt.packet_type], pkt.data if not isinstance(pkt.data, bytes) else '<binary>')
module function_definition identifier parameters identifier identifier block if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block return_statement expression_statement await call attribute attribute identifier identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end subscript attribute identifier identifier attribute identifier identifier conditional_expression attribute identifier identifier not_operator call identifier argument_list attribute identifier identifier identifier string string_start string_content string_end
Queue a packet to be sent to the server.
def getbyteslice(self, start, end): c = self._rawarray[start:end] return c
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier subscript attribute identifier identifier slice identifier identifier return_statement identifier
Direct access to byte data.
def upload_vcl(self, service_id, version_number, name, content, main=None, comment=None): body = self._formdata({ "name": name, "content": content, "comment": comment, "main": main, }, FastlyVCL.FIELDS) content = self._fetch("/service/%s/version/%d/vcl" % (service_id, version_number), method="POST", body=body) return FastlyVCL(self, content)
module function_definition identifier parameters identifier identifier identifier identifier identifier default_parameter identifier none default_parameter identifier none block expression_statement assignment identifier call attribute 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 attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list binary_operator string string_start string_content string_end tuple identifier identifier keyword_argument identifier string string_start string_content string_end keyword_argument identifier identifier return_statement call identifier argument_list identifier identifier
Upload a VCL for a particular service and version.
def data_url_scheme(self): encoded = base64.b64encode(self.contents().encode()) return "data:image/svg+xml;base64," + encoded.decode()
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list call attribute call attribute identifier identifier argument_list identifier argument_list return_statement binary_operator string string_start string_content string_end call attribute identifier identifier argument_list
Get svg in Data URL Scheme format.
def links(self, base_link, current_page) -> dict: max_pages = self.max_pages - 1 if \ self.max_pages > 0 else self.max_pages base_link = '/%s' % (base_link.strip("/")) self_page = current_page prev = current_page - 1 if current_page is not 0 else None prev_link = '%s/page/%s/%s' % (base_link, prev, self.limit) if \ prev is not None else None next = current_page + 1 if current_page < max_pages else None next_link = '%s/page/%s/%s' % (base_link, next, self.limit) if \ next is not None else None first = 0 last = max_pages return { 'self': '%s/page/%s/%s' % (base_link, self_page, self.limit), 'prev': prev_link, 'next': next_link, 'first': '%s/page/%s/%s' % (base_link, first, self.limit), 'last': '%s/page/%s/%s' % (base_link, last, self.limit), }
module function_definition identifier parameters identifier identifier identifier type identifier block expression_statement assignment identifier conditional_expression binary_operator attribute identifier identifier integer line_continuation comparison_operator attribute identifier identifier integer attribute identifier identifier expression_statement assignment identifier binary_operator string string_start string_content string_end parenthesized_expression call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier identifier expression_statement assignment identifier conditional_expression binary_operator identifier integer comparison_operator identifier integer none expression_statement assignment identifier conditional_expression binary_operator string string_start string_content string_end tuple identifier identifier attribute identifier identifier line_continuation comparison_operator identifier none none expression_statement assignment identifier conditional_expression binary_operator identifier integer comparison_operator identifier identifier none expression_statement assignment identifier conditional_expression binary_operator string string_start string_content string_end tuple identifier identifier attribute identifier identifier line_continuation comparison_operator identifier none none expression_statement assignment identifier integer expression_statement assignment identifier identifier return_statement dictionary pair string string_start string_content string_end binary_operator string string_start string_content string_end tuple identifier identifier attribute identifier 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 binary_operator string string_start string_content string_end tuple identifier identifier attribute identifier identifier pair string string_start string_content string_end binary_operator string string_start string_content string_end tuple identifier identifier attribute identifier identifier
Return JSON paginate links
def _parse_return_code_powershell(string): regex = re.search(r'ReturnValue\s*: (\d*)', string) if not regex: return (False, 'Could not parse PowerShell return code.') else: return int(regex.group(1))
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end identifier if_statement not_operator identifier block return_statement tuple false string string_start string_content string_end else_clause block return_statement call identifier argument_list call attribute identifier identifier argument_list integer
return from the input string the return code of the powershell command
def wrap_text(paragraph, line_count, min_char_per_line=0): one_string = strip_all_white_space(paragraph) if min_char_per_line: lines = wrap(one_string, width=min_char_per_line) try: return lines[:line_count] except IndexError: return lines else: return wrap(one_string, len(one_string)/line_count)
module function_definition identifier parameters identifier identifier default_parameter identifier integer block expression_statement assignment identifier call identifier argument_list identifier if_statement identifier block expression_statement assignment identifier call identifier argument_list identifier keyword_argument identifier identifier try_statement block return_statement subscript identifier slice identifier except_clause identifier block return_statement identifier else_clause block return_statement call identifier argument_list identifier binary_operator call identifier argument_list identifier identifier
Wraps the given text to the specified number of lines.
def render_node(_node_id, value=None, noderequest={}, **kw): "Recursively render a node's value" if value == None: kw.update( noderequest ) results = _query(_node_id, **kw) current_app.logger.debug("results: %s", results) if results: values = [] for (result, cols) in results: if set(cols) == set(['node_id', 'name', 'value']): for subresult in result: current_app.logger.debug("sub: %s", subresult) name = subresult['name'] if noderequest.get('_no_template'): name = "{0} ({1})".format(name, subresult['node_id']) values.append( {name: render_node( subresult['node_id'], noderequest=noderequest, **subresult )} ) else: values.append( result ) value = values value = _short_circuit(value) if not noderequest.get('_no_template'): value = _template(_node_id, value) return value
module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier dictionary dictionary_splat_pattern identifier block expression_statement string string_start string_content string_end if_statement comparison_operator identifier none block expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment identifier call identifier argument_list identifier dictionary_splat identifier expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end identifier if_statement identifier block expression_statement assignment identifier list for_statement tuple_pattern identifier identifier identifier block if_statement comparison_operator call identifier argument_list 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 block for_statement identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier subscript identifier string string_start string_content string_end if_statement call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier subscript identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list dictionary pair identifier call identifier argument_list subscript identifier string string_start string_content string_end keyword_argument identifier identifier dictionary_splat identifier else_clause block expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment identifier identifier expression_statement assignment identifier call identifier argument_list identifier if_statement not_operator call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier call identifier argument_list identifier identifier return_statement identifier
Recursively render a node's value
def session_state_view(request, template_name, **kwargs): 'Example view that exhibits the use of sessions to store state' session = request.session demo_count = session.get('django_plotly_dash', {}) ind_use = demo_count.get('ind_use', 0) ind_use += 1 demo_count['ind_use'] = ind_use context = {'ind_use' : ind_use} session['django_plotly_dash'] = demo_count return render(request, template_name=template_name, context=context)
module function_definition identifier parameters identifier identifier dictionary_splat_pattern identifier block expression_statement string string_start string_content string_end expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end dictionary expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end integer expression_statement augmented_assignment identifier integer expression_statement assignment subscript identifier string string_start string_content string_end identifier expression_statement assignment identifier dictionary pair string string_start string_content string_end identifier expression_statement assignment subscript identifier string string_start string_content string_end identifier return_statement call identifier argument_list identifier keyword_argument identifier identifier keyword_argument identifier identifier
Example view that exhibits the use of sessions to store state
def function(self,p): generators = self._advance_pattern_generators(p) assert hasattr(p.operator,'reduce'),repr(p.operator)+" does not support 'reduce'." patterns = [pg(xdensity=p.xdensity,ydensity=p.ydensity, bounds=p.bounds,mask=p.mask, x=p.x+p.size*(pg.x*np.cos(p.orientation)- pg.y*np.sin(p.orientation)), y=p.y+p.size*(pg.x*np.sin(p.orientation)+ pg.y*np.cos(p.orientation)), orientation=pg.orientation+p.orientation, size=pg.size*p.size) for pg in generators] image_array = p.operator.reduce(patterns) return image_array
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier assert_statement call identifier argument_list attribute identifier identifier string string_start string_content string_end binary_operator call identifier argument_list attribute identifier identifier string string_start string_content string_end expression_statement assignment identifier list_comprehension call identifier argument_list keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier binary_operator attribute identifier identifier binary_operator attribute identifier identifier parenthesized_expression binary_operator binary_operator attribute identifier identifier call attribute identifier identifier argument_list attribute identifier identifier binary_operator attribute identifier identifier call attribute identifier identifier argument_list attribute identifier identifier keyword_argument identifier binary_operator attribute identifier identifier binary_operator attribute identifier identifier parenthesized_expression binary_operator binary_operator attribute identifier identifier call attribute identifier identifier argument_list attribute identifier identifier binary_operator attribute identifier identifier call attribute identifier identifier argument_list attribute identifier identifier keyword_argument identifier binary_operator attribute identifier identifier attribute identifier identifier keyword_argument identifier binary_operator attribute identifier identifier attribute identifier identifier for_in_clause identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier return_statement identifier
Constructs combined pattern out of the individual ones.
def from_name(cls, name): return Author(name=name, sha512=cls.hash_name(name))
module function_definition identifier parameters identifier identifier block return_statement call identifier argument_list keyword_argument identifier identifier keyword_argument identifier call attribute identifier identifier argument_list identifier
Create an author by name, automatically populating the hash.
def generate_wakeword_pieces(self, volume): while True: target = 1 if random() > 0.5 else 0 it = self.pos_files_it if target else self.neg_files_it sample_file = next(it) yield self.layer_with(self.normalize_volume_to(load_audio(sample_file), volume), target) yield self.layer_with(np.zeros(int(pr.sample_rate * (0.5 + 2.0 * random()))), 0)
module function_definition identifier parameters identifier identifier block while_statement true block expression_statement assignment identifier conditional_expression integer comparison_operator call identifier argument_list float integer expression_statement assignment identifier conditional_expression attribute identifier identifier identifier attribute identifier identifier expression_statement assignment identifier call identifier argument_list identifier expression_statement yield call attribute identifier identifier argument_list call attribute identifier identifier argument_list call identifier argument_list identifier identifier identifier expression_statement yield call attribute identifier identifier argument_list call attribute identifier identifier argument_list call identifier argument_list binary_operator attribute identifier identifier parenthesized_expression binary_operator float binary_operator float call identifier argument_list integer
Generates chunks of audio that represent the wakeword stream
def _yarn_scheduler_metrics(self, rm_address, instance, addl_tags, queue_blacklist): metrics_json = self._rest_request_to_json(rm_address, instance, YARN_SCHEDULER_PATH, addl_tags) try: metrics_json = metrics_json['scheduler']['schedulerInfo'] if metrics_json['type'] == 'capacityScheduler': self._yarn_capacity_scheduler_metrics(metrics_json, addl_tags, queue_blacklist) except KeyError: pass
module function_definition identifier parameters identifier identifier identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier identifier identifier try_statement block expression_statement assignment identifier subscript subscript identifier string string_start string_content string_end string string_start string_content string_end if_statement comparison_operator subscript identifier string string_start string_content string_end string string_start string_content string_end block expression_statement call attribute identifier identifier argument_list identifier identifier identifier except_clause identifier block pass_statement
Get metrics from YARN scheduler
def query_ids(self, ids): results = self._get_repo_filter(Layer.objects).filter(uuid__in=ids).all() if len(results) == 0: results = self._get_repo_filter(Service.objects).filter(uuid__in=ids).all() return results
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute call attribute call attribute identifier identifier argument_list attribute identifier identifier identifier argument_list keyword_argument identifier identifier identifier argument_list if_statement comparison_operator call identifier argument_list identifier integer block expression_statement assignment identifier call attribute call attribute call attribute identifier identifier argument_list attribute identifier identifier identifier argument_list keyword_argument identifier identifier identifier argument_list return_statement identifier
Query by list of identifiers
def send(self, auth_header=None, callback=None, **data): message = self.encode(data) return self.send_encoded(message, auth_header=auth_header, callback=callback)
module function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none dictionary_splat_pattern identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list identifier keyword_argument identifier identifier keyword_argument identifier identifier
Serializes the message and passes the payload onto ``send_encoded``.
def _get_serv(ret): _options = _get_options(ret) host = _options.get('host') port = _options.get('port') log.debug('memcache server: %s:%s', host, port) if not host or not port: log.error('Host or port not defined in salt config') return memcacheoptions = (host, port) return memcache.Client(['{0}:{1}'.format(*memcacheoptions)], debug=0)
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier identifier if_statement boolean_operator not_operator identifier not_operator identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end return_statement expression_statement assignment identifier tuple identifier identifier return_statement call attribute identifier identifier argument_list list call attribute string string_start string_content string_end identifier argument_list list_splat identifier keyword_argument identifier integer
Return a memcache server object
def mdata(): grains = {} mdata_list = salt.utils.path.which('mdata-list') mdata_get = salt.utils.path.which('mdata-get') grains = salt.utils.dictupdate.update(grains, _user_mdata(mdata_list, mdata_get), merge_lists=True) grains = salt.utils.dictupdate.update(grains, _sdc_mdata(mdata_list, mdata_get), merge_lists=True) grains = _legacy_grains(grains) return grains
module function_definition identifier parameters block expression_statement assignment identifier dictionary expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list identifier call identifier argument_list identifier identifier keyword_argument identifier true expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list identifier call identifier argument_list identifier identifier keyword_argument identifier true expression_statement assignment identifier call identifier argument_list identifier return_statement identifier
Provide grains from the SmartOS metadata
def parse_PRIK(chunk, encryption_key): decrypted = decode_aes256('cbc', encryption_key[:16], decode_hex(chunk.payload), encryption_key) hex_key = re.match(br'^LastPassPrivateKey<(?P<hex_key>.*)>LastPassPrivateKey$', decrypted).group('hex_key') rsa_key = RSA.importKey(decode_hex(hex_key)) rsa_key.dmp1 = rsa_key.d % (rsa_key.p - 1) rsa_key.dmq1 = rsa_key.d % (rsa_key.q - 1) rsa_key.iqmp = number.inverse(rsa_key.q, rsa_key.p) return rsa_key
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list string string_start string_content string_end subscript identifier slice integer call identifier argument_list attribute identifier identifier identifier expression_statement assignment identifier call attribute call attribute identifier identifier argument_list string string_start string_content string_end identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list call identifier argument_list identifier expression_statement assignment attribute identifier identifier binary_operator attribute identifier identifier parenthesized_expression binary_operator attribute identifier identifier integer expression_statement assignment attribute identifier identifier binary_operator attribute identifier identifier parenthesized_expression binary_operator attribute identifier identifier integer expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier return_statement identifier
Parse PRIK chunk which contains private RSA key
def _is_undefok(arg, undefok_names): if not arg.startswith('-'): return False if arg.startswith('--'): arg_without_dash = arg[2:] else: arg_without_dash = arg[1:] if '=' in arg_without_dash: name, _ = arg_without_dash.split('=', 1) else: name = arg_without_dash if name in undefok_names: return True return False
module function_definition identifier parameters identifier identifier block if_statement not_operator call attribute identifier identifier argument_list string string_start string_content string_end block return_statement false if_statement call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier subscript identifier slice integer else_clause block expression_statement assignment identifier subscript identifier slice integer if_statement comparison_operator string string_start string_content string_end identifier block expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list string string_start string_content string_end integer else_clause block expression_statement assignment identifier identifier if_statement comparison_operator identifier identifier block return_statement true return_statement false
Returns whether we can ignore arg based on a set of undefok flag names.
def _check_success(self): cube_height = self.sim.data.body_xpos[self.cube_body_id][2] table_height = self.table_full_size[2] return cube_height > table_height + 0.10
module function_definition identifier parameters identifier block expression_statement assignment identifier subscript subscript attribute attribute attribute identifier identifier identifier identifier attribute identifier identifier integer expression_statement assignment identifier subscript attribute identifier identifier integer return_statement comparison_operator identifier binary_operator identifier float
Returns True if task is successfully completed
def text(self): text = [] rows = self.rowCount() cols = self.columnCount() if rows == 2 and cols == 2: item = self.item(0, 0) if item is None: return '' for r in range(rows - 1): for c in range(cols - 1): item = self.item(r, c) if item is not None: value = item.text() else: value = '0' if not value.strip(): value = '0' text.append(' ') text.append(value) text.append(ROW_SEPARATOR) return ''.join(text[:-1])
module function_definition identifier parameters identifier block expression_statement assignment identifier list expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list if_statement boolean_operator comparison_operator identifier integer comparison_operator identifier integer block expression_statement assignment identifier call attribute identifier identifier argument_list integer integer if_statement comparison_operator identifier none block return_statement string string_start string_end for_statement identifier call identifier argument_list binary_operator identifier integer block for_statement identifier call identifier argument_list binary_operator identifier integer block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier if_statement comparison_operator identifier none block expression_statement assignment identifier call attribute identifier identifier argument_list else_clause block expression_statement assignment identifier string string_start string_content string_end if_statement not_operator call attribute identifier identifier argument_list block expression_statement assignment identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier return_statement call attribute string string_start string_end identifier argument_list subscript identifier slice unary_operator integer
Return the entered array in a parseable form.
def OnWidget(self, event): self.choice_dialects.SetValue(len(self.choices['dialects']) - 1) event.Skip()
module function_definition identifier parameters identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator call identifier argument_list subscript attribute identifier identifier string string_start string_content string_end integer expression_statement call attribute identifier identifier argument_list
Update the dialect widget to 'user
def calculate_normals(vertices): verts = np.array(vertices, dtype=float) normals = np.zeros_like(verts) for start, end in pairwise(np.arange(0, verts.shape[0] + 1, 3)): vecs = np.vstack((verts[start + 1] - verts[start], verts[start + 2] - verts[start])) vecs /= np.linalg.norm(vecs, axis=1, keepdims=True) normal = np.cross(*vecs) normals[start:end, :] = normal / np.linalg.norm(normal) return normals
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier keyword_argument identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier for_statement pattern_list identifier identifier call identifier argument_list call attribute identifier identifier argument_list integer binary_operator subscript attribute identifier identifier integer integer integer block expression_statement assignment identifier call attribute identifier identifier argument_list tuple binary_operator subscript identifier binary_operator identifier integer subscript identifier identifier binary_operator subscript identifier binary_operator identifier integer subscript identifier identifier expression_statement augmented_assignment identifier call attribute attribute identifier identifier identifier argument_list identifier keyword_argument identifier integer keyword_argument identifier true expression_statement assignment identifier call attribute identifier identifier argument_list list_splat identifier expression_statement assignment subscript identifier slice identifier identifier slice binary_operator identifier call attribute attribute identifier identifier identifier argument_list identifier return_statement identifier
Return Nx3 normal array from Nx3 vertex array.
def min_pos(self): if self.__len__() == 0: return ArgumentError('empty set has no minimum positive value.') if self.contains(0): return None positive = [interval for interval in self.intervals if interval.left > 0] if len(positive) == 0: return None return numpy.min(list(map(lambda i: i.left, positive)))
module function_definition identifier parameters identifier block if_statement comparison_operator call attribute identifier identifier argument_list integer block return_statement call identifier argument_list string string_start string_content string_end if_statement call attribute identifier identifier argument_list integer block return_statement none expression_statement assignment identifier list_comprehension identifier for_in_clause identifier attribute identifier identifier if_clause comparison_operator attribute identifier identifier integer if_statement comparison_operator call identifier argument_list identifier integer block return_statement none return_statement call attribute identifier identifier argument_list call identifier argument_list call identifier argument_list lambda lambda_parameters identifier attribute identifier identifier identifier
Returns minimal positive value or None.
def check_duplicate_filenames(files): used_names = set() dup_names = list() for this_file in files: this_fname = os.path.basename(this_file) if this_fname in used_names: dup_names.append(this_file) else: used_names.add(this_fname) if len(dup_names) > 0: logger.warning( 'Duplicate file name(s) found. Having duplicate file names will ' 'break some links. List of files: {}'.format(sorted(dup_names),))
module function_definition identifier parameters identifier block 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 attribute identifier identifier identifier argument_list identifier if_statement comparison_operator identifier identifier block expression_statement call attribute identifier identifier argument_list identifier else_clause block expression_statement 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 call attribute concatenated_string string string_start string_content string_end string string_start string_content string_end identifier argument_list call identifier argument_list identifier
Check for duplicate filenames across gallery directories.
def run_notebook(self, nb, f): if PYTHON_MAJOR_VERSION == 3: kernel_name = 'python3' elif PYTHON_MAJOR_VERSION == 2: kernel_name = 'python2' else: raise Exception('Only Python 2 and 3 are supported') ep = ExecutePreprocessor(timeout=600, kernel_name=kernel_name) try: ep.preprocess(nb, {'metadata': {'path': '.'}}) except CellExecutionError: msg = 'Error executing the notebook "%s".\n\n' % f.name msg += 'See notebook "%s" for the traceback.' % f.name print(msg) raise finally: nbformat.write(nb, f)
module function_definition identifier parameters identifier identifier identifier block if_statement comparison_operator identifier integer block expression_statement assignment identifier string string_start string_content string_end elif_clause comparison_operator identifier integer block expression_statement assignment identifier string string_start string_content string_end else_clause block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment identifier call identifier argument_list keyword_argument identifier integer keyword_argument identifier identifier try_statement block expression_statement call attribute identifier identifier argument_list identifier dictionary pair string string_start string_content string_end dictionary pair string string_start string_content string_end string string_start string_content string_end except_clause identifier block expression_statement assignment identifier binary_operator string string_start string_content escape_sequence escape_sequence string_end attribute identifier identifier expression_statement augmented_assignment identifier binary_operator string string_start string_content string_end attribute identifier identifier expression_statement call identifier argument_list identifier raise_statement finally_clause block expression_statement call attribute identifier identifier argument_list identifier identifier
Runs a loaded notebook file.
def do_install(ctx, verbose, fake): click.echo('The following git aliases will be installed:\n') aliases = cli.list_commands(ctx) output_aliases(aliases) if click.confirm('\n{}Install aliases above?'.format('FAKE ' if fake else ''), default=fake): for alias in aliases: cmd = '!legit ' + alias system_command = 'git config --global --replace-all alias.{0} "{1}"'.format(alias, cmd) verbose_echo(system_command, verbose, fake) if not fake: os.system(system_command) if not fake: click.echo("\nAliases installed.") else: click.echo("\nAliases will not be installed.")
module function_definition identifier parameters identifier identifier identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement call identifier argument_list identifier if_statement call attribute identifier identifier argument_list call attribute string string_start string_content escape_sequence string_end identifier argument_list conditional_expression string string_start string_content string_end identifier string string_start string_end keyword_argument identifier identifier block for_statement identifier identifier block expression_statement assignment identifier binary_operator 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 call identifier argument_list identifier identifier identifier if_statement not_operator identifier block expression_statement call attribute identifier identifier argument_list identifier if_statement not_operator identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end else_clause block expression_statement call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end
Installs legit git aliases.
def update(self): self.idx_chan.clear() for chan_name in self.parent.traces.chan: self.idx_chan.addItem(chan_name) if self.selected_chan is not None: self.idx_chan.setCurrentIndex(self.selected_chan) self.selected_chan = None
module function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list for_statement identifier attribute attribute attribute identifier identifier identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list identifier if_statement comparison_operator attribute identifier identifier none block expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement assignment attribute identifier identifier none
Add channel names to the combobox.
def trigger(self, identifier, force=True): self.debug(identifier) url = "{base}/{identifier}".format( base=self.local_base_url, identifier=identifier ) param = {} if force: param['force'] = force encode = urllib.urlencode(param) if encode: url += "?" url += encode return self.core.update(url, {})
module function_definition identifier parameters identifier identifier default_parameter identifier true block expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list keyword_argument identifier attribute identifier identifier keyword_argument identifier identifier expression_statement assignment identifier dictionary if_statement identifier block expression_statement assignment subscript identifier string string_start string_content string_end identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement identifier block expression_statement augmented_assignment identifier string string_start string_content string_end expression_statement augmented_assignment identifier identifier return_statement call attribute attribute identifier identifier identifier argument_list identifier dictionary
Trigger an upgrade task.
def renamed_class(cls): class DeprecationWrapper(cls): def __init__(self, config=None, env=None, logger_creator=None): old_name = cls.__name__.replace("Trainer", "Agent") new_name = cls.__name__ logger.warn("DeprecationWarning: {} has been renamed to {}. ". format(old_name, new_name) + "This will raise an error in the future.") cls.__init__(self, config, env, logger_creator) DeprecationWrapper.__name__ = cls.__name__ return DeprecationWrapper
module function_definition identifier parameters identifier block class_definition identifier argument_list identifier block function_definition identifier parameters identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list binary_operator call attribute string string_start string_content string_end identifier argument_list identifier identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier identifier identifier identifier expression_statement assignment attribute identifier identifier attribute identifier identifier return_statement identifier
Helper class for renaming Agent => Trainer with a warning.
def to_dict(self): return { 'current': self.current, 'first': self.first, 'last': self.last, 'next': self.more, 'prev': self.prev, }
module function_definition identifier parameters identifier block return_statement dictionary pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier pair string string_start string_content string_end attribute identifier identifier
Convert the Paginator into a dict
def suspend_queues(self, active_queues, sleep_time=10.0): for queue in active_queues: self.disable_queue(queue) while self.get_active_tasks(): time.sleep(sleep_time)
module function_definition identifier parameters identifier identifier default_parameter identifier float block for_statement identifier identifier block expression_statement call attribute identifier identifier argument_list identifier while_statement call attribute identifier identifier argument_list block expression_statement call attribute identifier identifier argument_list identifier
Suspend Celery queues and wait for running tasks to complete.
def abstract(cls): if not issubclass(cls, HasProps): raise TypeError("%s is not a subclass of HasProps" % cls.__name__) if cls.__doc__ is not None: cls.__doc__ += _ABSTRACT_ADMONITION return cls
module function_definition identifier parameters identifier block if_statement not_operator call identifier argument_list identifier identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end attribute identifier identifier if_statement comparison_operator attribute identifier identifier none block expression_statement augmented_assignment attribute identifier identifier identifier return_statement identifier
A decorator to mark abstract base classes derived from |HasProps|.
def _generate_alphabet_dict(iterable, reserved_tokens=None): if reserved_tokens is None: reserved_tokens = RESERVED_TOKENS alphabet = {c for token in iterable for c in token} alphabet |= {c for token in reserved_tokens for c in token} alphabet |= _ESCAPE_CHARS return alphabet
module function_definition identifier parameters identifier default_parameter identifier none block if_statement comparison_operator identifier none block expression_statement assignment identifier identifier expression_statement assignment identifier set_comprehension identifier for_in_clause identifier identifier for_in_clause identifier identifier expression_statement augmented_assignment identifier set_comprehension identifier for_in_clause identifier identifier for_in_clause identifier identifier expression_statement augmented_assignment identifier identifier return_statement identifier
Create set of characters that appear in any element in the iterable.
def update_params(self, token, match): for k, v in self.params.items(): if isinstance(v, MatchGroup): self.params[k] = v.get_group_value(token, match)
module function_definition identifier parameters identifier identifier identifier block for_statement pattern_list identifier identifier call attribute attribute identifier identifier identifier argument_list block if_statement call identifier argument_list identifier identifier block expression_statement assignment subscript attribute identifier identifier identifier call attribute identifier identifier argument_list identifier identifier
Update dict of params from results of regex match
def _is_number_matching_desc(national_number, number_desc): if number_desc is None: return False actual_length = len(national_number) possible_lengths = number_desc.possible_length if len(possible_lengths) > 0 and actual_length not in possible_lengths: return False return _match_national_number(national_number, number_desc, False)
module function_definition identifier parameters identifier identifier block if_statement comparison_operator identifier none block return_statement false expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier attribute identifier identifier if_statement boolean_operator comparison_operator call identifier argument_list identifier integer comparison_operator identifier identifier block return_statement false return_statement call identifier argument_list identifier identifier false
Determine if the number matches the given PhoneNumberDesc
def _close_stdio(): for fd in (sys.stdin, sys.stdout, sys.stderr): file_no = fd.fileno() fd.flush() fd.close() os.close(file_no)
module function_definition identifier parameters block for_statement identifier tuple attribute identifier identifier attribute identifier identifier attribute identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list identifier
Close stdio streams to avoid output in the tty that launched pantsd.
def isPIDValid(self, pid): class ExitCodeProcess(ctypes.Structure): _fields_ = [('hProcess', ctypes.c_void_p), ('lpExitCode', ctypes.POINTER(ctypes.c_ulong))] SYNCHRONIZE = 0x100000 PROCESS_QUERY_LIMITED_INFORMATION = 0x1000 process = self._kernel32.OpenProcess(SYNCHRONIZE|PROCESS_QUERY_LIMITED_INFORMATION, 0, pid) if not process: return False ec = ExitCodeProcess() out = self._kernel32.GetExitCodeProcess(process, ctypes.byref(ec)) if not out: err = self._kernel32.GetLastError() if self._kernel32.GetLastError() == 5: logging.warning("Access is denied to get pid info.") self._kernel32.CloseHandle(process) return False elif bool(ec.lpExitCode): self._kernel32.CloseHandle(process) return False self._kernel32.CloseHandle(process) return True
module function_definition identifier parameters identifier identifier block class_definition identifier argument_list attribute identifier identifier block expression_statement assignment identifier list tuple string string_start string_content string_end attribute identifier identifier tuple string string_start string_content string_end call attribute identifier identifier argument_list attribute identifier identifier expression_statement assignment identifier integer expression_statement assignment identifier integer expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list binary_operator identifier identifier integer identifier if_statement not_operator identifier block return_statement false expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier call attribute identifier identifier argument_list identifier if_statement not_operator identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list if_statement comparison_operator call attribute attribute identifier identifier identifier argument_list integer block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list identifier return_statement false elif_clause call identifier argument_list attribute identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list identifier return_statement false expression_statement call attribute attribute identifier identifier identifier argument_list identifier return_statement true
Checks if a PID is associated with a running process
def process(self): self.modules.sort(key=lambda x: x.priority) for module in self.modules: transforms = module.transform(self.data) transforms.sort(key=lambda x: x.linenum, reverse=True) for transform in transforms: linenum = transform.linenum if isinstance(transform.data, basestring): transform.data = [transform.data] if transform.oper == "prepend": self.data[linenum:linenum] = transform.data elif transform.oper == "append": self.data[linenum+1:linenum+1] = transform.data elif transform.oper == "swap": self.data[linenum:linenum+1] = transform.data elif transform.oper == "drop": self.data[linenum:linenum+1] = [] elif transform.oper == "noop": pass
module function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list keyword_argument identifier lambda lambda_parameters identifier attribute identifier identifier for_statement identifier attribute identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list keyword_argument identifier lambda lambda_parameters identifier attribute identifier identifier keyword_argument identifier true for_statement identifier identifier block expression_statement assignment identifier attribute identifier identifier if_statement call identifier argument_list attribute identifier identifier identifier block expression_statement assignment attribute identifier identifier list attribute identifier identifier if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment subscript attribute identifier identifier slice identifier identifier attribute identifier identifier elif_clause comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment subscript attribute identifier identifier slice binary_operator identifier integer binary_operator identifier integer attribute identifier identifier elif_clause comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment subscript attribute identifier identifier slice identifier binary_operator identifier integer attribute identifier identifier elif_clause comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment subscript attribute identifier identifier slice identifier binary_operator identifier integer list elif_clause comparison_operator attribute identifier identifier string string_start string_content string_end block pass_statement
This method handles the actual processing of Modules and Transforms
def add_layer_item(self, layer): if not layer.is_draft_version: raise ValueError("Layer isn't a draft version") self.items.append(layer.latest_version)
module function_definition identifier parameters identifier identifier block if_statement not_operator attribute identifier identifier block raise_statement call identifier argument_list string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list attribute identifier identifier
Adds a Layer to the publish group.
def via_nupnp(): bridges_from_portal = parse_portal_json() logger.info('Portal returned %d Hue bridges(s).', len(bridges_from_portal)) found_bridges = {} for bridge in bridges_from_portal: serial, bridge_info = parse_description_xml(bridge[1]) if serial: found_bridges[serial] = bridge_info logger.debug('%s', found_bridges) if found_bridges: return found_bridges else: raise DiscoveryError('Portal returned nothing')
module function_definition identifier parameters block expression_statement assignment identifier call identifier argument_list expression_statement call attribute identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier expression_statement assignment identifier dictionary for_statement identifier identifier block expression_statement assignment pattern_list identifier identifier call identifier argument_list subscript identifier integer if_statement identifier block expression_statement assignment subscript identifier identifier identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier if_statement identifier block return_statement identifier else_clause block raise_statement call identifier argument_list string string_start string_content string_end
Use method 2 as described by the Philips guide
def retrieve_and_parse_profile(fid: str) -> Optional[ActivitypubProfile]: profile = retrieve_and_parse_document(fid) if not profile: return try: profile.validate() except ValueError as ex: logger.warning("retrieve_and_parse_profile - found profile %s but it didn't validate: %s", profile, ex) return return profile
module function_definition identifier parameters typed_parameter identifier type identifier type generic_type identifier type_parameter type identifier block expression_statement assignment identifier call identifier argument_list identifier if_statement not_operator identifier block return_statement try_statement block expression_statement call attribute identifier identifier argument_list except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier identifier return_statement return_statement identifier
Retrieve the remote fid and return a Profile object.
def diff_files(left, right, diff_options=None, formatter=None): return _diff(etree.parse, left, right, diff_options=diff_options, formatter=formatter)
module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier none block return_statement call identifier argument_list attribute identifier identifier identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier
Takes two filenames or streams, and diffs the XML in those files
def _create_gitlab_runner_prometheus_instance(self, instance, init_config): allowed_metrics = init_config.get('allowed_metrics') if allowed_metrics is None: raise CheckException("At least one metric must be whitelisted in `allowed_metrics`.") gitlab_runner_instance = deepcopy(instance) gitlab_runner_instance['prometheus_url'] = instance.get('prometheus_endpoint', None) gitlab_runner_instance.update( { 'namespace': 'gitlab_runner', 'metrics': allowed_metrics, 'send_monotonic_counter': instance.get('send_monotonic_counter', False), 'health_service_check': instance.get('health_service_check', False), } ) return gitlab_runner_instance
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement comparison_operator identifier none block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment subscript identifier string string_start string_content string_end call attribute identifier identifier argument_list string string_start string_content string_end none 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 identifier pair string string_start string_content string_end call attribute identifier identifier argument_list string string_start string_content string_end false pair string string_start string_content string_end call attribute identifier identifier argument_list string string_start string_content string_end false return_statement identifier
Set up the gitlab_runner instance so it can be used in OpenMetricsBaseCheck
def _call_command(self, name, *args, **kwargs): meth = super(RedisField, self)._call_command if self.indexable and name in self.available_modifiers: with FieldLock(self): try: result = meth(name, *args, **kwargs) except: self._rollback_indexes() raise else: return result finally: self._reset_indexes_caches() else: return meth(name, *args, **kwargs)
module function_definition identifier parameters identifier identifier list_splat_pattern identifier dictionary_splat_pattern identifier block expression_statement assignment identifier attribute call identifier argument_list identifier identifier identifier if_statement boolean_operator attribute identifier identifier comparison_operator identifier attribute identifier identifier block with_statement with_clause with_item call identifier argument_list identifier block try_statement block expression_statement assignment identifier call identifier argument_list identifier list_splat identifier dictionary_splat identifier except_clause block expression_statement call attribute identifier identifier argument_list raise_statement else_clause block return_statement identifier finally_clause block expression_statement call attribute identifier identifier argument_list else_clause block return_statement call identifier argument_list identifier list_splat identifier dictionary_splat identifier
Add lock management and call parent.
def flush_queue(self): records = [] while not self.queue.empty() and len(records) < self.batch_size: records.append(self.queue.get()) if records: self.send_records(records) self.last_flush = time.time()
module function_definition identifier parameters identifier block expression_statement assignment identifier list while_statement boolean_operator not_operator call attribute attribute identifier identifier identifier argument_list comparison_operator call identifier argument_list identifier attribute identifier identifier block expression_statement call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list if_statement identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list
Grab all the current records in the queue and send them.
def replace_graph(cls, response, serialized): if cls.is_graph(response): return serialized if hasattr(response, '__getitem__'): if len(response) > 0 and \ cls.is_graph(response[0]): return (serialized,) + response[1:] return response
module function_definition identifier parameters identifier identifier identifier block if_statement call attribute identifier identifier argument_list identifier block return_statement identifier if_statement call identifier argument_list identifier string string_start string_content string_end block if_statement boolean_operator comparison_operator call identifier argument_list identifier integer line_continuation call attribute identifier identifier argument_list subscript identifier integer block return_statement binary_operator tuple identifier subscript identifier slice integer return_statement identifier
Replace the rdflib Graph in a Flask response
def stop(self): with self.lock: self._message_received(ConnectionClosed(self._file, self))
module function_definition identifier parameters identifier block with_statement with_clause with_item attribute identifier identifier block expression_statement call attribute identifier identifier argument_list call identifier argument_list attribute identifier identifier identifier
Stop the communication with the shield.
def generate(self): t = (self.context.identifier, RDF.type, META.Provenance) if t not in self.context.graph: self.context.graph.add(t) for name, value in self.data.items(): pat = (self.context.identifier, META[name], None) if pat in self.context.graph: self.context.graph.remove(pat) self.context.graph.add((pat[0], META[name], Literal(value)))
module function_definition identifier parameters identifier block expression_statement assignment identifier tuple attribute attribute identifier identifier identifier attribute identifier identifier attribute identifier identifier if_statement comparison_operator identifier attribute attribute identifier identifier identifier block expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list identifier for_statement pattern_list identifier identifier call attribute attribute identifier identifier identifier argument_list block expression_statement assignment identifier tuple attribute attribute identifier identifier identifier subscript identifier identifier none if_statement comparison_operator identifier attribute attribute identifier identifier identifier block expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list identifier expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list tuple subscript identifier integer subscript identifier identifier call identifier argument_list identifier
Add provenance info to the context graph.
def import_related_module(package, pkg_path, related_name, ignore_exceptions=False): try: imp.find_module(related_name, pkg_path) except ImportError: return try: return getattr( __import__('%s' % (package), globals(), locals(), [related_name]), related_name ) except Exception as e: if ignore_exceptions: current_app.logger.exception( 'Can not import "{}" package'.format(package) ) else: raise e
module function_definition identifier parameters identifier identifier identifier default_parameter identifier false block try_statement block expression_statement call attribute identifier identifier argument_list identifier identifier except_clause identifier block return_statement try_statement block return_statement call identifier argument_list call identifier argument_list binary_operator string string_start string_content string_end parenthesized_expression identifier call identifier argument_list call identifier argument_list list identifier identifier except_clause as_pattern identifier as_pattern_target identifier block if_statement identifier block expression_statement call attribute attribute identifier identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier else_clause block raise_statement identifier
Import module from given path.
def rounding(price, currency): currency = validate_currency(currency) price = validate_price(price) if decimals(currency) == 0: return round(int(price), decimals(currency)) return round(price, decimals(currency))
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call identifier argument_list identifier if_statement comparison_operator call identifier argument_list identifier integer block return_statement call identifier argument_list call identifier argument_list identifier call identifier argument_list identifier return_statement call identifier argument_list identifier call identifier argument_list identifier
rounding currency value based on its max decimal digits
def _container_attrib_builder(name, container, mapper): context = {'@container': '@{0}'.format(name)} def _attrib(type, **kwargs): kwargs.setdefault('metadata', {}) kwargs['metadata'][KEY_CLS] = type kwargs['default'] = Factory(container) def _converter(value): if isinstance(value, container): return mapper(type, value) elif value is None: return value raise ValueError(value) kwargs.setdefault('converter', _converter) context_ib = context.copy() context_ib.update(kwargs.pop('context', {})) return attrib(context=context_ib, **kwargs) return _attrib
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier dictionary pair string string_start string_content string_end call attribute string string_start string_content string_end identifier argument_list identifier function_definition identifier parameters identifier dictionary_splat_pattern identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end dictionary expression_statement assignment subscript subscript identifier string string_start string_content string_end identifier identifier expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list identifier function_definition identifier parameters identifier block if_statement call identifier argument_list identifier identifier block return_statement call identifier argument_list identifier identifier elif_clause comparison_operator identifier none block return_statement identifier raise_statement call identifier argument_list identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end dictionary return_statement call identifier argument_list keyword_argument identifier identifier dictionary_splat identifier return_statement identifier
Builder for container attributes.
def model_resources(self): response = jsonify({ 'apiVersion': '0.1', 'swaggerVersion': '1.1', 'basePath': '%s%s' % (self.base_uri(), self.api.url_prefix), 'apis': self.get_model_resources() }) response.headers.add('Cache-Control', 'max-age=0') return response
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list dictionary pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end string string_start string_content string_end pair string string_start string_content string_end binary_operator string string_start string_content string_end tuple call attribute identifier identifier argument_list attribute attribute identifier identifier identifier pair string string_start string_content string_end call attribute identifier identifier argument_list expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end return_statement identifier
Listing of all supported resources.
def model_ext_functions(vk, model): model['ext_functions'] = {'instance': {}, 'device': {}} alias = {v: k for k, v in model['alias'].items()} for extension in get_extensions_filtered(vk): for req in extension['require']: if not req.get('command'): continue ext_type = extension['@type'] for x in req['command']: name = x['@name'] if name in alias.keys(): model['ext_functions'][ext_type][name] = alias[name] else: model['ext_functions'][ext_type][name] = name
module function_definition identifier parameters identifier identifier block expression_statement assignment subscript identifier string string_start string_content string_end dictionary pair string string_start string_content string_end dictionary pair string string_start string_content string_end dictionary expression_statement assignment identifier dictionary_comprehension pair identifier identifier for_in_clause pattern_list identifier identifier call attribute subscript identifier string string_start string_content string_end identifier argument_list for_statement identifier call identifier argument_list identifier block for_statement identifier subscript identifier string string_start string_content string_end block if_statement not_operator call attribute identifier identifier argument_list string string_start string_content string_end block continue_statement expression_statement assignment identifier subscript identifier string string_start string_content string_end for_statement identifier subscript identifier string string_start string_content string_end block expression_statement assignment identifier subscript identifier string string_start string_content string_end if_statement comparison_operator identifier call attribute identifier identifier argument_list block expression_statement assignment subscript subscript subscript identifier string string_start string_content string_end identifier identifier subscript identifier identifier else_clause block expression_statement assignment subscript subscript subscript identifier string string_start string_content string_end identifier identifier identifier
Fill the model with extensions functions
def time_delay_from_earth_center(self, right_ascension, declination, t_gps): return self.time_delay_from_location(np.array([0, 0, 0]), right_ascension, declination, t_gps)
module function_definition identifier parameters identifier identifier identifier identifier block return_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list list integer integer integer identifier identifier identifier
Return the time delay from the earth center
def dragLeaveEvent(self, event): super(AbstractDragView, self).dragLeaveEvent(event) self.dragline = None self.viewport().update() event.accept()
module function_definition identifier parameters identifier identifier block expression_statement call attribute call identifier argument_list identifier identifier identifier argument_list identifier expression_statement assignment attribute identifier identifier none expression_statement call attribute call attribute identifier identifier argument_list identifier argument_list expression_statement call attribute identifier identifier argument_list
Clears drop cursor line
def _graphql_query_waittime(self, query_hash: str, current_time: float, untracked_queries: bool = False) -> int: sliding_window = 660 if query_hash not in self._graphql_query_timestamps: self._graphql_query_timestamps[query_hash] = [] self._graphql_query_timestamps[query_hash] = list(filter(lambda t: t > current_time - 60 * 60, self._graphql_query_timestamps[query_hash])) reqs_in_sliding_window = list(filter(lambda t: t > current_time - sliding_window, self._graphql_query_timestamps[query_hash])) count_per_sliding_window = self._graphql_request_count_per_sliding_window(query_hash) if len(reqs_in_sliding_window) < count_per_sliding_window and not untracked_queries: return max(0, self._graphql_earliest_next_request_time - current_time) next_request_time = min(reqs_in_sliding_window) + sliding_window + 6 if untracked_queries: self._graphql_earliest_next_request_time = next_request_time return round(max(next_request_time, self._graphql_earliest_next_request_time) - current_time)
module function_definition identifier parameters identifier typed_parameter identifier type identifier typed_parameter identifier type identifier typed_default_parameter identifier type identifier false type identifier block expression_statement assignment identifier integer if_statement comparison_operator identifier attribute identifier identifier block expression_statement assignment subscript attribute identifier identifier identifier list expression_statement assignment subscript attribute identifier identifier identifier call identifier argument_list call identifier argument_list lambda lambda_parameters identifier comparison_operator identifier binary_operator identifier binary_operator integer integer subscript attribute identifier identifier identifier expression_statement assignment identifier call identifier argument_list call identifier argument_list lambda lambda_parameters identifier comparison_operator identifier binary_operator identifier identifier subscript attribute identifier identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement boolean_operator comparison_operator call identifier argument_list identifier identifier not_operator identifier block return_statement call identifier argument_list integer binary_operator attribute identifier identifier identifier expression_statement assignment identifier binary_operator binary_operator call identifier argument_list identifier identifier integer if_statement identifier block expression_statement assignment attribute identifier identifier identifier return_statement call identifier argument_list binary_operator call identifier argument_list identifier attribute identifier identifier identifier
Calculate time needed to wait before GraphQL query can be executed.