code
stringlengths
51
2.34k
sequence
stringlengths
186
3.94k
docstring
stringlengths
11
171
def __execute_scale(self, surface, size_to_scale_from): x = size_to_scale_from[0] * self.__scale[0] y = size_to_scale_from[1] * self.__scale[1] scaled_value = (int(x), int(y)) self.image = pygame.transform.scale(self.image, scaled_value) self.__resize_surface_extents()
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier binary_operator subscript identifier integer subscript attribute identifier identifier integer expression_statement assignment identifier binary_operator subscript identifier integer subscript attribute identifier identifier integer expression_statement assignment identifier tuple call identifier argument_list identifier call identifier argument_list identifier expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list
Execute the scaling operation
def getWorksheetServices(self): services = [] for analysis in self.getAnalyses(): service = analysis.getAnalysisService() if service and service not in services: services.append(service) return services
module function_definition identifier parameters identifier block expression_statement assignment identifier list for_statement identifier call attribute identifier identifier argument_list block expression_statement assignment identifier call attribute identifier identifier argument_list if_statement boolean_operator identifier comparison_operator identifier identifier block expression_statement call attribute identifier identifier argument_list identifier return_statement identifier
get list of analysis services present on this worksheet
def to_dicts(recarray): for rec in recarray: yield dict(zip(recarray.dtype.names, rec.tolist()))
module function_definition identifier parameters identifier block for_statement identifier identifier block expression_statement yield call identifier argument_list call identifier argument_list attribute attribute identifier identifier identifier call attribute identifier identifier argument_list
convert record array to a dictionaries
def generic_find_fk_constraint_name(table, columns, referenced, insp): for fk in insp.get_foreign_keys(table): if fk['referred_table'] == referenced and set(fk['referred_columns']) == columns: return fk['name']
module function_definition identifier parameters identifier identifier identifier identifier block for_statement identifier call attribute identifier identifier argument_list identifier block if_statement boolean_operator comparison_operator subscript identifier string string_start string_content string_end identifier comparison_operator call identifier argument_list subscript identifier string string_start string_content string_end identifier block return_statement subscript identifier string string_start string_content string_end
Utility to find a foreign-key constraint name in alembic migrations
def _load_attributes(new_class): for field_name, field_obj in new_class.meta_.declared_fields.items(): new_class.meta_.attributes[field_obj.get_attribute_name()] = field_obj
module function_definition identifier parameters identifier block for_statement pattern_list identifier identifier call attribute attribute attribute identifier identifier identifier identifier argument_list block expression_statement assignment subscript attribute attribute identifier identifier identifier call attribute identifier identifier argument_list identifier
Load list of attributes from declared fields
def _get_go2nthdridx(self, gos_all): go2nthdridx = {} obj = GrouperInit.NtMaker(self) for goid in gos_all: go2nthdridx[goid] = obj.get_nt(goid) return go2nthdridx
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier dictionary expression_statement assignment identifier call attribute identifier identifier argument_list identifier for_statement identifier identifier block expression_statement assignment subscript identifier identifier call attribute identifier identifier argument_list identifier return_statement identifier
Get GO IDs header index for each user GO ID and corresponding parent GO IDs.
def group_values(self, group_name): group_index = self.groups.index(group_name) values = [] for key in self.data_keys: if key[group_index] not in values: values.append(key[group_index]) return values
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier list for_statement identifier attribute identifier identifier block if_statement comparison_operator subscript identifier identifier identifier block expression_statement call attribute identifier identifier argument_list subscript identifier identifier return_statement identifier
Return all distinct group values for given group.
def disk(x, y, height, gaussian_width): disk_radius = height/2.0 distance_from_origin = np.sqrt(x**2+y**2) distance_outside_disk = distance_from_origin - disk_radius sigmasq = gaussian_width*gaussian_width if sigmasq==0.0: falloff = x*0.0 else: with float_error_ignore(): falloff = np.exp(np.divide(-distance_outside_disk*distance_outside_disk, 2*sigmasq)) return np.where(distance_outside_disk<=0,1.0,falloff)
module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier binary_operator identifier float expression_statement assignment identifier call attribute identifier identifier argument_list binary_operator binary_operator identifier integer binary_operator identifier integer expression_statement assignment identifier binary_operator identifier identifier expression_statement assignment identifier binary_operator identifier identifier if_statement comparison_operator identifier float block expression_statement assignment identifier binary_operator identifier float else_clause block with_statement with_clause with_item call identifier argument_list block expression_statement assignment identifier call attribute identifier identifier argument_list call attribute identifier identifier argument_list binary_operator unary_operator identifier identifier binary_operator integer identifier return_statement call attribute identifier identifier argument_list comparison_operator identifier integer float identifier
Circular disk with Gaussian fall-off after the solid central region.
def mean_abs(self): if len(self.values) > 0: return sorted(map(abs, self.values))[len(self.values) / 2] else: return None
module function_definition identifier parameters identifier block if_statement comparison_operator call identifier argument_list attribute identifier identifier integer block return_statement subscript call identifier argument_list call identifier argument_list identifier attribute identifier identifier binary_operator call identifier argument_list attribute identifier identifier integer else_clause block return_statement none
return the median of absolute values
def timestamp(self): "Return POSIX timestamp as float" if self._tzinfo is None: return _time.mktime((self.year, self.month, self.day, self.hour, self.minute, self.second, -1, -1, -1)) + self.microsecond / 1e6 else: return (self - _EPOCH).total_seconds()
module function_definition identifier parameters identifier block expression_statement string string_start string_content string_end if_statement comparison_operator attribute identifier identifier none block return_statement binary_operator call attribute identifier identifier argument_list tuple attribute identifier identifier attribute identifier identifier attribute identifier identifier attribute identifier identifier attribute identifier identifier attribute identifier identifier unary_operator integer unary_operator integer unary_operator integer binary_operator attribute identifier identifier float else_clause block return_statement call attribute parenthesized_expression binary_operator identifier identifier identifier argument_list
Return POSIX timestamp as float
def bench(func): sys.stdout.write("%44s " % format_func(func)) sys.stdout.flush() for i in xrange(3, 10): rounds = 1 << i t = timer() for _ in xrange(rounds): func() if timer() - t >= 0.2: break def _run(): gc.collect() gc.disable() try: t = timer() for _ in xrange(rounds): func() return (timer() - t) / rounds * 1000 finally: gc.enable() delta = median(_run() for x in xrange(TEST_RUNS)) sys.stdout.write("%.4f\n" % delta) sys.stdout.flush() return delta
module function_definition identifier parameters identifier block expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content string_end call identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list for_statement identifier call identifier argument_list integer integer block expression_statement assignment identifier binary_operator integer identifier expression_statement assignment identifier call identifier argument_list for_statement identifier call identifier argument_list identifier block expression_statement call identifier argument_list if_statement comparison_operator binary_operator call identifier argument_list identifier float block break_statement function_definition identifier parameters block expression_statement call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list try_statement block expression_statement assignment identifier call identifier argument_list for_statement identifier call identifier argument_list identifier block expression_statement call identifier argument_list return_statement binary_operator binary_operator parenthesized_expression binary_operator call identifier argument_list identifier identifier integer finally_clause block expression_statement call attribute identifier identifier argument_list expression_statement assignment identifier call identifier generator_expression call identifier argument_list for_in_clause identifier call identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content escape_sequence string_end identifier expression_statement call attribute attribute identifier identifier identifier argument_list return_statement identifier
Times a single function.
def _ProcessMessageHandlerRequests(self, requests): logging.debug("Leased message handler request ids: %s", ",".join(str(r.request_id) for r in requests)) grouped_requests = collection.Group(requests, lambda r: r.handler_name) for handler_name, requests_for_handler in iteritems(grouped_requests): handler_cls = handler_registry.handler_name_map.get(handler_name) if not handler_cls: logging.error("Unknown message handler: %s", handler_name) continue stats_collector_instance.Get().IncrementCounter( "well_known_flow_requests", fields=[handler_name]) try: logging.debug("Running %d messages for handler %s", len(requests_for_handler), handler_name) handler_cls(token=self.token).ProcessMessages(requests_for_handler) except Exception as e: logging.exception("Exception while processing message handler %s: %s", handler_name, e) logging.debug("Deleting message handler request ids: %s", ",".join(str(r.request_id) for r in requests)) data_store.REL_DB.DeleteMessageHandlerRequests(requests)
module function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end call attribute string string_start string_content string_end identifier generator_expression call identifier argument_list attribute identifier identifier for_in_clause identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier lambda lambda_parameters identifier attribute identifier identifier for_statement pattern_list identifier identifier call identifier argument_list identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier if_statement not_operator identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier continue_statement expression_statement call attribute call attribute identifier identifier argument_list identifier argument_list string string_start string_content string_end keyword_argument identifier list identifier try_statement block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier identifier expression_statement call attribute call identifier argument_list keyword_argument identifier attribute identifier identifier identifier argument_list identifier except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end call attribute string string_start string_content string_end identifier generator_expression call identifier argument_list attribute identifier identifier for_in_clause identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list identifier
Processes message handler requests.
def print_change(self, symbol, typ, changes=None, document=None, **kwargs): values = ", ".join("{0}={1}".format(key, val) for key, val in sorted(kwargs.items())) print("{0} {1}({2})".format(symbol, typ, values)) if changes: for change in changes: print("\n".join("\t{0}".format(line) for line in change.split('\n'))) elif document: print("\n".join("\t{0}".format(line) for line in document.split('\n')))
module function_definition identifier parameters identifier identifier identifier default_parameter identifier none default_parameter identifier none dictionary_splat_pattern identifier block expression_statement assignment identifier call attribute string string_start string_content string_end identifier generator_expression call attribute string string_start string_content string_end identifier argument_list identifier identifier for_in_clause pattern_list identifier identifier call identifier argument_list call attribute identifier identifier argument_list expression_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier identifier identifier if_statement identifier block for_statement identifier identifier block expression_statement call identifier argument_list call attribute string string_start string_content escape_sequence string_end identifier generator_expression call attribute string string_start string_content escape_sequence string_end identifier argument_list identifier for_in_clause identifier call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end elif_clause identifier block expression_statement call identifier argument_list call attribute string string_start string_content escape_sequence string_end identifier generator_expression call attribute string string_start string_content escape_sequence string_end identifier argument_list identifier for_in_clause identifier call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end
Print out a change
def _describe_list(self) -> List[Tuple[str, float]]: number_nodes = self.number_of_nodes() return [ ('Number of Nodes', number_nodes), ('Number of Edges', self.number_of_edges()), ('Number of Citations', self.number_of_citations()), ('Number of Authors', self.number_of_authors()), ('Network Density', '{:.2E}'.format(nx.density(self))), ('Number of Components', nx.number_weakly_connected_components(self)), ('Number of Warnings', self.number_of_warnings()), ]
module function_definition identifier parameters identifier type generic_type identifier type_parameter type generic_type identifier type_parameter type identifier type identifier block expression_statement assignment identifier call attribute identifier identifier argument_list return_statement list tuple string string_start string_content string_end identifier tuple string string_start string_content string_end call attribute identifier identifier argument_list tuple string string_start string_content string_end call attribute identifier identifier argument_list tuple string string_start string_content string_end call attribute identifier identifier argument_list tuple string string_start string_content string_end call attribute string string_start string_content string_end identifier argument_list call attribute identifier identifier argument_list identifier tuple string string_start string_content string_end call attribute identifier identifier argument_list identifier tuple string string_start string_content string_end call attribute identifier identifier argument_list
Return useful information about the graph as a list of tuples.
def stop_charge(self): if self.__charger_state: data = self._controller.command(self._id, 'charge_stop', wake_if_asleep=True) if data and data['response']['result']: self.__charger_state = False self.__manual_update_time = time.time()
module function_definition identifier parameters identifier block if_statement attribute identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier string string_start string_content string_end keyword_argument identifier true if_statement boolean_operator identifier subscript subscript identifier string string_start string_content string_end string string_start string_content string_end block expression_statement assignment attribute identifier identifier false expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list
Stop charging the Tesla Vehicle.
def use_plenary_relationship_view(self): self._object_views['relationship'] = PLENARY for session in self._get_provider_sessions(): try: session.use_plenary_relationship_view() except AttributeError: pass
module function_definition identifier parameters identifier block expression_statement assignment subscript attribute identifier identifier string string_start string_content string_end identifier for_statement identifier call attribute identifier identifier argument_list block try_statement block expression_statement call attribute identifier identifier argument_list except_clause identifier block pass_statement
Pass through to provider RelationshipLookupSession.use_plenary_relationship_view
def prepare_message(self, message_data, delivery_mode, content_type, content_encoding, **kwargs): return (message_data, content_type, content_encoding)
module function_definition identifier parameters identifier identifier identifier identifier identifier dictionary_splat_pattern identifier block return_statement tuple identifier identifier identifier
Prepare message for sending.
def generate(self, state): if self.count >= random.randint(DharmaConst.VARIABLE_MIN, DharmaConst.VARIABLE_MAX): return "%s%d" % (self.var, random.randint(1, self.count)) var = random.choice(self) prefix = self.eval(var[0], state) suffix = self.eval(var[1], state) self.count += 1 element_name = "%s%d" % (self.var, self.count) self.default += "%s%s%s\n" % (prefix, element_name, suffix) return element_name
module function_definition identifier parameters identifier identifier block if_statement comparison_operator attribute identifier identifier call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier block return_statement binary_operator string string_start string_content string_end tuple attribute identifier identifier call attribute identifier identifier argument_list integer attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier call attribute identifier identifier argument_list subscript identifier integer identifier expression_statement assignment identifier call attribute identifier identifier argument_list subscript identifier integer identifier expression_statement augmented_assignment attribute identifier identifier integer expression_statement assignment identifier binary_operator string string_start string_content string_end tuple attribute identifier identifier attribute identifier identifier expression_statement augmented_assignment attribute identifier identifier binary_operator string string_start string_content escape_sequence string_end tuple identifier identifier identifier return_statement identifier
Return a random variable if any, otherwise create a new default variable.
async def play(self): if self.repeat and self.current is not None: self.queue.append(self.current) self.current = None self.position = 0 self._paused = False if not self.queue: await self.stop() else: self._is_playing = True if self.shuffle: track = self.queue.pop(randrange(len(self.queue))) else: track = self.queue.pop(0) self.current = track log.debug("Assigned current.") await self.node.play(self.channel.guild.id, track)
module function_definition identifier parameters identifier block if_statement boolean_operator attribute identifier identifier 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 expression_statement assignment attribute identifier identifier integer expression_statement assignment attribute identifier identifier false if_statement not_operator attribute identifier identifier block expression_statement await call attribute identifier identifier argument_list else_clause block expression_statement assignment attribute identifier identifier true if_statement attribute identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list call identifier argument_list call identifier argument_list attribute identifier identifier else_clause block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list integer expression_statement assignment attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement await call attribute attribute identifier identifier identifier argument_list attribute attribute attribute identifier identifier identifier identifier identifier
Starts playback from lavalink.
def parameterize(self, call, host): debug("Parameterizing {!r} for host {!r}".format(call, host)) clone = call.clone(into=ConnectionCall) clone.host = host return clone
module function_definition identifier parameters identifier identifier identifier block expression_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list keyword_argument identifier identifier expression_statement assignment attribute identifier identifier identifier return_statement identifier
Parameterize a Call with its Context set to a per-host Config.
def wait_for_compactions(self, timeout=120): pattern = re.compile("pending tasks: 0") start = time.time() while time.time() - start < timeout: output, err, rc = self.nodetool("compactionstats") if pattern.search(output): return time.sleep(1) raise TimeoutError("{} [{}] Compactions did not finish in {} seconds".format(time.strftime("%d %b %Y %H:%M:%S", time.gmtime()), self.name, timeout))
module function_definition identifier parameters identifier default_parameter identifier integer block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list while_statement comparison_operator binary_operator call attribute identifier identifier argument_list identifier identifier block expression_statement assignment pattern_list identifier identifier identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement call attribute identifier identifier argument_list identifier block return_statement expression_statement call attribute identifier identifier argument_list integer raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list call attribute identifier identifier argument_list string string_start string_content string_end call attribute identifier identifier argument_list attribute identifier identifier identifier
Wait for all compactions to finish on this node.
def delayed_retry_gen(delay_schedule=[.1, 1, 10], msg=None, timeout=None, raise_=True): import utool as ut import time if not ut.isiterable(delay_schedule): delay_schedule = [delay_schedule] tt = ut.tic() yield 0 for count in it.count(0): if timeout is not None and ut.toc(tt) > timeout: if raise_: raise Exception('Retry loop timed out') else: raise StopIteration('Retry loop timed out') index = min(count, len(delay_schedule) - 1) delay = delay_schedule[index] time.sleep(delay) yield count + 1
module function_definition identifier parameters default_parameter identifier list float integer integer default_parameter identifier none default_parameter identifier none default_parameter identifier true block import_statement aliased_import dotted_name identifier identifier import_statement dotted_name identifier if_statement not_operator call attribute identifier identifier argument_list identifier block expression_statement assignment identifier list identifier expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement yield integer for_statement identifier call attribute identifier identifier argument_list integer block if_statement boolean_operator comparison_operator identifier none comparison_operator call attribute identifier identifier argument_list identifier identifier block if_statement identifier block raise_statement call identifier argument_list 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 identifier binary_operator call identifier argument_list identifier integer expression_statement assignment identifier subscript identifier identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement yield binary_operator identifier integer
template code for a infinte retry loop
def removed_issues(self, board_id, sprint_id): r_json = self._get_json('rapid/charts/sprintreport?rapidViewId=%s&sprintId=%s' % (board_id, sprint_id), base=self.AGILE_BASE_URL) issues = [Issue(self._options, self._session, raw_issues_json) for raw_issues_json in r_json['contents']['puntedIssues']] return issues
module function_definition identifier parameters identifier identifier identifier block 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 attribute identifier identifier expression_statement assignment identifier list_comprehension call identifier argument_list attribute identifier identifier attribute identifier identifier identifier for_in_clause identifier subscript subscript identifier string string_start string_content string_end string string_start string_content string_end return_statement identifier
Return the completed issues for the sprint.
def parse_definition_docstring(obj, process_doc): doc_lines, swag = None, None full_doc = None swag_path = getattr(obj, 'swag_path', None) swag_type = getattr(obj, 'swag_type', 'yml') if swag_path is not None: full_doc = load_from_file(swag_path, swag_type) else: full_doc = inspect.getdoc(obj) if full_doc: if full_doc.startswith('file:'): if not hasattr(obj, 'root_path'): obj.root_path = get_root_path(obj) swag_path, swag_type = get_path_from_doc(full_doc) doc_filepath = os.path.join(obj.root_path, swag_path) full_doc = load_from_file(doc_filepath, swag_type) yaml_sep = full_doc.find('---') if yaml_sep != -1: doc_lines = process_doc( full_doc[:yaml_sep - 1] ) swag = yaml.load(full_doc[yaml_sep:]) else: doc_lines = process_doc(full_doc) return doc_lines, swag
module function_definition identifier parameters identifier identifier block expression_statement assignment pattern_list identifier identifier expression_list none none expression_statement assignment identifier none expression_statement assignment identifier call identifier argument_list identifier string string_start string_content string_end none expression_statement assignment identifier call identifier argument_list identifier string string_start string_content string_end string string_start string_content string_end if_statement comparison_operator identifier none block expression_statement assignment identifier call identifier argument_list identifier identifier else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement identifier block if_statement call attribute identifier identifier argument_list string string_start string_content string_end block if_statement not_operator call identifier argument_list identifier string string_start string_content string_end block expression_statement assignment attribute identifier identifier call identifier argument_list identifier expression_statement assignment pattern_list identifier identifier call identifier argument_list identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier identifier expression_statement assignment identifier call identifier argument_list identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement comparison_operator identifier unary_operator integer block expression_statement assignment identifier call identifier argument_list subscript identifier slice binary_operator identifier integer expression_statement assignment identifier call attribute identifier identifier argument_list subscript identifier slice identifier else_clause block expression_statement assignment identifier call identifier argument_list identifier return_statement expression_list identifier identifier
Gets swag data from docstring for class based definitions
def find_versions(): versions = [] if SCons.Util.can_read_reg: try: HLM = SCons.Util.HKEY_LOCAL_MACHINE product = 'SOFTWARE\\Metrowerks\\CodeWarrior\\Product Versions' product_key = SCons.Util.RegOpenKeyEx(HLM, product) i = 0 while True: name = product + '\\' + SCons.Util.RegEnumKey(product_key, i) name_key = SCons.Util.RegOpenKeyEx(HLM, name) try: version = SCons.Util.RegQueryValueEx(name_key, 'VERSION') path = SCons.Util.RegQueryValueEx(name_key, 'PATH') mwv = MWVersion(version[0], path[0], 'Win32-X86') versions.append(mwv) except SCons.Util.RegError: pass i = i + 1 except SCons.Util.RegError: pass return versions
module function_definition identifier parameters block expression_statement assignment identifier list if_statement attribute attribute identifier identifier identifier block try_statement block expression_statement assignment identifier attribute attribute identifier identifier identifier expression_statement assignment identifier string string_start string_content escape_sequence escape_sequence escape_sequence string_end expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier identifier expression_statement assignment identifier integer while_statement true block expression_statement assignment identifier binary_operator binary_operator identifier string string_start string_content escape_sequence string_end call attribute attribute identifier identifier identifier argument_list identifier identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier identifier try_statement block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier string string_start string_content string_end expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier string string_start string_content string_end expression_statement assignment identifier call identifier argument_list subscript identifier integer subscript identifier integer string string_start string_content string_end expression_statement call attribute identifier identifier argument_list identifier except_clause attribute attribute identifier identifier identifier block pass_statement expression_statement assignment identifier binary_operator identifier integer except_clause attribute attribute identifier identifier identifier block pass_statement return_statement identifier
Return a list of MWVersion objects representing installed versions
def _calc_min_width(self, table): width = len(table.name) cap = table.consumed_capacity["__table__"] width = max(width, 4 + len("%.1f/%d" % (cap["read"], table.read_throughput))) width = max(width, 4 + len("%.1f/%d" % (cap["write"], table.write_throughput))) for index_name, cap in iteritems(table.consumed_capacity): if index_name == "__table__": continue index = table.global_indexes[index_name] width = max( width, 4 + len(index_name + "%.1f/%d" % (cap["read"], index.read_throughput)), ) width = max( width, 4 + len(index_name + "%.1f/%d" % (cap["write"], index.write_throughput)), ) return width
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call identifier argument_list attribute identifier identifier expression_statement assignment identifier subscript attribute identifier identifier string string_start string_content string_end expression_statement assignment identifier call identifier argument_list identifier binary_operator integer call identifier argument_list binary_operator string string_start string_content string_end tuple subscript identifier string string_start string_content string_end attribute identifier identifier expression_statement assignment identifier call identifier argument_list identifier binary_operator integer call identifier argument_list binary_operator string string_start string_content string_end tuple subscript identifier string string_start string_content string_end attribute identifier identifier for_statement pattern_list identifier identifier call identifier argument_list attribute identifier identifier block if_statement comparison_operator identifier string string_start string_content string_end block continue_statement expression_statement assignment identifier subscript attribute identifier identifier identifier expression_statement assignment identifier call identifier argument_list identifier binary_operator integer call identifier argument_list binary_operator identifier binary_operator string string_start string_content string_end tuple subscript identifier string string_start string_content string_end attribute identifier identifier expression_statement assignment identifier call identifier argument_list identifier binary_operator integer call identifier argument_list binary_operator identifier binary_operator string string_start string_content string_end tuple subscript identifier string string_start string_content string_end attribute identifier identifier return_statement identifier
Calculate the minimum allowable width for a table
def update_visual_baseline(self): if '{PlatformVersion}' in self.baseline_name: try: platform_version = self.driver.desired_capabilities['platformVersion'] except KeyError: platform_version = None self.baseline_name = self.baseline_name.replace('{PlatformVersion}', str(platform_version)) self.visual_baseline_directory = os.path.join(DriverWrappersPool.visual_baseline_directory, self.baseline_name) if '{Version}' in self.baseline_name: try: splitted_version = self.driver.desired_capabilities['version'].split('.') version = '.'.join(splitted_version[:2]) except KeyError: version = None self.baseline_name = self.baseline_name.replace('{Version}', str(version)) self.visual_baseline_directory = os.path.join(DriverWrappersPool.visual_baseline_directory, self.baseline_name) if '{RemoteNode}' in self.baseline_name: self.baseline_name = self.baseline_name.replace('{RemoteNode}', str(self.remote_node)) self.visual_baseline_directory = os.path.join(DriverWrappersPool.visual_baseline_directory, self.baseline_name)
module function_definition identifier parameters identifier block if_statement comparison_operator string string_start string_content string_end attribute identifier identifier block try_statement block expression_statement assignment identifier subscript attribute attribute identifier identifier identifier string string_start string_content string_end except_clause identifier block expression_statement assignment identifier none expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier attribute identifier identifier if_statement comparison_operator string string_start string_content string_end attribute identifier identifier block try_statement block expression_statement assignment identifier call attribute subscript attribute attribute identifier identifier identifier string string_start string_content string_end identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list subscript identifier slice integer except_clause identifier block expression_statement assignment identifier none expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end call identifier argument_list identifier expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier attribute identifier identifier if_statement comparison_operator string string_start string_content string_end attribute identifier identifier block expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end call identifier argument_list attribute identifier identifier expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier attribute identifier identifier
Configure baseline directory after driver is created
def wipe_cfg_vals_from_git_cfg(*cfg_opts): for cfg_key_suffix in cfg_opts: cfg_key = f'cherry-picker.{cfg_key_suffix.replace("_", "-")}' cmd = "git", "config", "--local", "--unset-all", cfg_key subprocess.check_call(cmd, stderr=subprocess.STDOUT)
module function_definition identifier parameters list_splat_pattern identifier block for_statement identifier identifier block expression_statement assignment identifier string string_start string_content interpolation call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end string_end expression_statement assignment identifier expression_list string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end string string_start string_content string_end identifier expression_statement call attribute identifier identifier argument_list identifier keyword_argument identifier attribute identifier identifier
Remove a set of options from Git config.
def _create_path(self): if self.driver == 'sqlite' and 'memory' not in self.dsn and self.dsn != 'sqlite://': dir_ = os.path.dirname(self.path) if dir_ and not os.path.exists(dir_): try: os.makedirs(dir_) except Exception: pass if not os.path.exists(dir_): raise Exception("Couldn't create directory " + dir_)
module function_definition identifier parameters identifier block if_statement boolean_operator boolean_operator comparison_operator attribute identifier identifier string string_start string_content string_end comparison_operator string string_start string_content string_end attribute identifier identifier comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list attribute identifier identifier if_statement boolean_operator identifier not_operator call attribute attribute identifier identifier identifier argument_list identifier block try_statement block expression_statement call attribute identifier identifier argument_list identifier except_clause identifier block pass_statement if_statement not_operator call attribute attribute identifier identifier identifier argument_list identifier block raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier
Create the path to hold the database, if one wwas specified.
def encoded_length(self, num_bytes=16): factor = math.log(256) / math.log(self._alpha_len) return int(math.ceil(factor * num_bytes))
module function_definition identifier parameters identifier default_parameter identifier integer block expression_statement assignment identifier binary_operator call attribute identifier identifier argument_list integer call attribute identifier identifier argument_list attribute identifier identifier return_statement call identifier argument_list call attribute identifier identifier argument_list binary_operator identifier identifier
Returns the string length of the shortened UUID.
def winrm_cmd(session, command, flags, **kwargs): log.debug('Executing WinRM command: %s %s', command, flags) session.protocol.transport.build_session() r = session.run_cmd(command, flags) return r.status_code
module function_definition identifier parameters identifier identifier identifier dictionary_splat_pattern identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier identifier expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier return_statement attribute identifier identifier
Wrapper for commands to be run against Windows boxes using WinRM.
def download_containers(self, to_download, current_options): if current_options["backend"] == "local": self._display_info("Connecting to the local Docker daemon...") try: docker_connection = docker.from_env() except: self._display_error("Cannot connect to local Docker daemon. Skipping download.") return for image in to_download: try: self._display_info("Downloading image %s. This can take some time." % image) docker_connection.images.pull(image + ":latest") except Exception as e: self._display_error("An error occurred while pulling the image: %s." % str(e)) else: self._display_warning( "This installation tool does not support the backend configuration directly, if it's not local. You will have to " "pull the images by yourself. Here is the list: %s" % str(to_download))
module function_definition identifier parameters identifier identifier identifier block 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 string string_start string_content string_end try_statement block expression_statement assignment identifier call attribute identifier identifier argument_list except_clause block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end return_statement for_statement identifier identifier block try_statement block expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end identifier expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator identifier string string_start string_content string_end except_clause as_pattern identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list binary_operator string string_start string_content string_end call identifier argument_list identifier else_clause block expression_statement call attribute identifier identifier argument_list binary_operator concatenated_string string string_start string_content string_end string string_start string_content string_end call identifier argument_list identifier
Download the chosen containers on all the agents
def _parse_date_nate(dateString): m = _korean_nate_date_re.match(dateString) if not m: return hour = int(m.group(5)) ampm = m.group(4) if (ampm == _korean_pm): hour += 12 hour = str(hour) if len(hour) == 1: hour = '0' + hour w3dtfdate = '%(year)s-%(month)s-%(day)sT%(hour)s:%(minute)s:%(second)s%(zonediff)s' % \ {'year': m.group(1), 'month': m.group(2), 'day': m.group(3),\ 'hour': hour, 'minute': m.group(6), 'second': m.group(7),\ 'zonediff': '+09:00'} return _parse_date_w3dtf(w3dtfdate)
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement not_operator identifier block return_statement expression_statement assignment identifier call identifier argument_list call attribute identifier identifier argument_list integer expression_statement assignment identifier call attribute identifier identifier argument_list integer if_statement parenthesized_expression comparison_operator identifier identifier block expression_statement augmented_assignment identifier integer expression_statement assignment identifier call identifier argument_list identifier if_statement comparison_operator call identifier argument_list identifier integer block expression_statement assignment identifier binary_operator string string_start string_content string_end identifier expression_statement assignment identifier binary_operator string string_start string_content string_end line_continuation dictionary pair string string_start string_content string_end call attribute identifier identifier argument_list integer pair string string_start string_content string_end call attribute identifier identifier argument_list integer pair string string_start string_content string_end call attribute identifier identifier argument_list integer pair string string_start string_content string_end identifier pair string string_start string_content string_end call attribute identifier identifier argument_list integer pair string string_start string_content string_end call attribute identifier identifier argument_list integer pair string string_start string_content string_end string string_start string_content string_end return_statement call identifier argument_list identifier
Parse a string according to the Nate 8-bit date format
def placeholder_data_view(self, request, id): try: layout = models.Layout.objects.get(pk=id) except models.Layout.DoesNotExist: json = {'success': False, 'error': 'Layout not found'} status = 404 else: placeholders = layout.get_placeholder_data() status = 200 placeholders = [p.as_dict() for p in placeholders] for p in placeholders: try: p['help_text'] = settings.FLUENT_CONTENTS_PLACEHOLDER_CONFIG.get(p['slot']).get('help_text') except AttributeError: p['help_text'] = None json = { 'id': layout.id, 'title': layout.title, 'placeholders': placeholders, } return JsonResponse(json, status=status)
module function_definition identifier parameters identifier identifier identifier block try_statement block expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list keyword_argument identifier identifier except_clause attribute attribute identifier identifier identifier block expression_statement assignment identifier dictionary pair string string_start string_content string_end false pair string string_start string_content string_end string string_start string_content string_end expression_statement assignment identifier integer else_clause block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier integer expression_statement assignment identifier list_comprehension call attribute identifier identifier argument_list for_in_clause identifier identifier for_statement identifier identifier block try_statement block expression_statement assignment subscript identifier string string_start string_content string_end call attribute call attribute attribute identifier identifier identifier argument_list subscript identifier string string_start string_content string_end identifier argument_list string string_start string_content string_end except_clause identifier block expression_statement assignment subscript identifier string string_start string_content string_end none 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 identifier return_statement call identifier argument_list identifier keyword_argument identifier identifier
Return placeholder data for the given layout's template.
def xinfo_stream(self, stream): fut = self.execute(b'XINFO', b'STREAM', stream) return wait_make_dict(fut)
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end identifier return_statement call identifier argument_list identifier
Retrieve information about the given stream.
def cleanupFilename(self, name): context = self.context id = '' name = name.replace('\\', '/') name = name.split('/')[-1] for c in name: if c.isalnum() or c in '._': id += c if context.check_id(id) is None and getattr(context, id, None) is None: return id count = 1 while 1: if count == 1: sc = '' else: sc = str(count) newid = "copy{0:s}_of_{1:s}".format(sc, id) if context.check_id(newid) is None \ and getattr(context, newid, None) is None: return newid count += 1
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier string string_start string_end expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end string string_start string_content string_end expression_statement assignment identifier subscript call attribute identifier identifier argument_list string string_start string_content string_end unary_operator integer for_statement identifier identifier block if_statement boolean_operator call attribute identifier identifier argument_list comparison_operator identifier string string_start string_content string_end block expression_statement augmented_assignment identifier identifier if_statement boolean_operator comparison_operator call attribute identifier identifier argument_list identifier none comparison_operator call identifier argument_list identifier identifier none none block return_statement identifier expression_statement assignment identifier integer while_statement integer block if_statement comparison_operator identifier integer block expression_statement assignment identifier string string_start string_end else_clause block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier identifier if_statement boolean_operator comparison_operator call attribute identifier identifier argument_list identifier none line_continuation comparison_operator call identifier argument_list identifier identifier none none block return_statement identifier expression_statement augmented_assignment identifier integer
Generate a unique id which doesn't match the system generated ids
def to_coverage(ctx): sm = Smother.load(ctx.obj['report']) sm.coverage = coverage.coverage() sm.write_coverage()
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list subscript attribute identifier identifier string string_start string_content string_end expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list
Produce a .coverage file from a smother file
def Definition(self): result = self._FormatDescriptionComment() result += " enum %s {\n" % self.enum_name for k, v in sorted(iteritems(self.reverse_enum)): result += " %s = %s;\n" % (v, k) result += " }\n" result += self._FormatField() return result
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement augmented_assignment identifier binary_operator string string_start string_content escape_sequence string_end attribute identifier identifier for_statement pattern_list identifier identifier call identifier argument_list call identifier argument_list attribute identifier identifier block expression_statement augmented_assignment identifier binary_operator string string_start string_content escape_sequence string_end tuple identifier identifier expression_statement augmented_assignment identifier string string_start string_content escape_sequence string_end expression_statement augmented_assignment identifier call attribute identifier identifier argument_list return_statement identifier
Return a string with the definition of this field.
def mac_address(ip): mac = '' for line in os.popen('/sbin/ifconfig'): s = line.split() if len(s) > 3: if s[3] == 'HWaddr': mac = s[4] elif s[2] == ip: break return {'MAC': mac}
module function_definition identifier parameters identifier block expression_statement assignment identifier string string_start string_end for_statement identifier call attribute identifier identifier argument_list string string_start string_content string_end block expression_statement assignment identifier call attribute identifier identifier argument_list if_statement comparison_operator call identifier argument_list identifier integer block if_statement comparison_operator subscript identifier integer string string_start string_content string_end block expression_statement assignment identifier subscript identifier integer elif_clause comparison_operator subscript identifier integer identifier block break_statement return_statement dictionary pair string string_start string_content string_end identifier
Get the MAC address
def copy_to_clipboard(self, url): if url is None: self.term.flash() return try: clipboard_copy(url) except (ProgramError, OSError) as e: _logger.exception(e) self.term.show_notification( 'Failed to copy url: {0}'.format(e)) else: self.term.show_notification( ['Copied to clipboard:', url], timeout=1)
module function_definition identifier parameters identifier identifier block if_statement comparison_operator identifier none block expression_statement call attribute attribute identifier identifier identifier argument_list return_statement try_statement block expression_statement call identifier argument_list identifier except_clause as_pattern tuple identifier identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute attribute identifier identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier else_clause block expression_statement call attribute attribute identifier identifier identifier argument_list list string string_start string_content string_end identifier keyword_argument identifier integer
Attempt to copy the selected URL to the user's clipboard
def send_get_command(self, command): res = requests.get("http://{host}:{port}{command}".format( host=self._host, port=self._receiver_port, command=command), timeout=self.timeout) if res.status_code == 200: return True else: _LOGGER.error(( "Host %s returned HTTP status code %s to GET command at " "end point %s"), self._host, res.status_code, command) return False
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier identifier keyword_argument identifier attribute identifier identifier if_statement comparison_operator attribute identifier identifier integer block return_statement true else_clause block expression_statement call attribute identifier identifier argument_list parenthesized_expression concatenated_string string string_start string_content string_end string string_start string_content string_end attribute identifier identifier attribute identifier identifier identifier return_statement false
Send command via HTTP get to receiver.
def attach_issue(resource_id, table, user_id): data = schemas.issue.post(flask.request.json) issue = _get_or_create_issue(data) if table.name == 'jobs': join_table = models.JOIN_JOBS_ISSUES else: join_table = models.JOIN_COMPONENTS_ISSUES key = '%s_id' % table.name[0:-1] query = join_table.insert().values({ 'user_id': user_id, 'issue_id': issue['id'], key: resource_id }) try: flask.g.db_conn.execute(query) except sa_exc.IntegrityError: raise dci_exc.DCICreationConflict(join_table.name, '%s, issue_id' % key) result = json.dumps({'issue': dict(issue)}) return flask.Response(result, 201, content_type='application/json')
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list attribute attribute identifier identifier identifier expression_statement assignment identifier call identifier argument_list identifier if_statement comparison_operator attribute identifier identifier string string_start string_content string_end block expression_statement assignment identifier attribute identifier identifier else_clause block expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier binary_operator string string_start string_content string_end subscript attribute identifier identifier slice integer unary_operator integer expression_statement assignment identifier call attribute call attribute identifier identifier argument_list identifier argument_list dictionary pair string string_start string_content string_end identifier pair string string_start string_content string_end subscript identifier string string_start string_content string_end pair identifier identifier try_statement block expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list identifier except_clause attribute identifier identifier block raise_statement call attribute identifier identifier argument_list attribute identifier identifier binary_operator string string_start string_content string_end identifier expression_statement assignment identifier call attribute identifier identifier argument_list dictionary pair string string_start string_content string_end call identifier argument_list identifier return_statement call attribute identifier identifier argument_list identifier integer keyword_argument identifier string string_start string_content string_end
Attach an issue to a specific job.
def oauth_signup(self, provider, attrs, defaults, redirect_url=None): session["oauth_user_defaults"] = defaults session["oauth_user_attrs"] = dict(provider=provider, **attrs) if not redirect_url: redirect_url = request.args.get("next") return redirect(url_for('users.oauth_signup', next=redirect_url))
module function_definition identifier parameters identifier identifier identifier identifier default_parameter identifier none block expression_statement assignment subscript identifier string string_start string_content string_end identifier expression_statement assignment subscript identifier string string_start string_content string_end call identifier argument_list keyword_argument identifier identifier dictionary_splat identifier if_statement not_operator identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end return_statement call identifier argument_list call identifier argument_list string string_start string_content string_end keyword_argument identifier identifier
Start the signup process after having logged in via oauth
def configure(cls, global_, key, val): scope = 'global' if global_ else 'local' if scope not in cls._conffiles: cls._conffiles[scope] = {} config = cls._conffiles.get(scope, {}) cls._set(scope, key, val) conf_file = cls.home_config if global_ else cls.local_config cls.save(os.path.expanduser(conf_file), config)
module function_definition identifier parameters identifier identifier identifier identifier block expression_statement assignment identifier conditional_expression string string_start string_content string_end identifier string string_start string_content string_end if_statement comparison_operator identifier attribute identifier identifier block expression_statement assignment subscript attribute identifier identifier identifier dictionary expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier dictionary expression_statement call attribute identifier identifier argument_list identifier identifier identifier expression_statement assignment identifier conditional_expression attribute identifier identifier identifier attribute identifier identifier expression_statement call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list identifier identifier
Update and save configuration value to file.
def change_ssh_port(): host = normalize(env.host_string)[1] after = env.port before = str(env.DEFAULT_SSH_PORT) host_string=join_host_strings(env.user,host,before) with settings(host_string=host_string, user=env.user): if env.verbosity: print env.host, "CHANGING SSH PORT TO: "+str(after) sed('/etc/ssh/sshd_config','Port '+ str(before),'Port '+str(after),use_sudo=True) if env.verbosity: print env.host, "RESTARTING SSH on",after sudo('/etc/init.d/ssh restart') return True
module function_definition identifier parameters block expression_statement assignment identifier subscript call identifier argument_list attribute identifier identifier integer expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier call identifier argument_list attribute identifier identifier expression_statement assignment identifier call identifier argument_list attribute identifier identifier identifier identifier with_statement with_clause with_item call identifier argument_list keyword_argument identifier identifier keyword_argument identifier attribute identifier identifier block if_statement attribute identifier identifier block print_statement attribute identifier identifier binary_operator string string_start string_content string_end call identifier argument_list identifier expression_statement call identifier argument_list string string_start string_content string_end binary_operator string string_start string_content string_end call identifier argument_list identifier binary_operator string string_start string_content string_end call identifier argument_list identifier keyword_argument identifier true if_statement attribute identifier identifier block print_statement attribute identifier identifier string string_start string_content string_end identifier expression_statement call identifier argument_list string string_start string_content string_end return_statement true
For security woven changes the default ssh port.
def xy2geom(x, y, t_srs=None): geom_wkt = 'POINT({0} {1})'.format(x, y) geom = ogr.CreateGeometryFromWkt(geom_wkt) if t_srs is not None and not wgs_srs.IsSame(t_srs): ct = osr.CoordinateTransformation(t_srs, wgs_srs) geom.Transform(ct) geom.AssignSpatialReference(t_srs) return geom
module function_definition identifier parameters identifier identifier default_parameter identifier none block expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier if_statement boolean_operator comparison_operator identifier none not_operator call attribute identifier identifier argument_list identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier identifier expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list identifier return_statement identifier
Convert x and y point coordinates to geom
def read_array(self, infile, var_name): file_handle = self.read_cdf(infile) try: return file_handle.variables[var_name][:] except KeyError: print("Cannot find variable: {0}".format(var_name)) raise KeyError
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier try_statement block return_statement subscript subscript attribute identifier identifier identifier slice except_clause identifier block expression_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier raise_statement identifier
Directly return a numpy array for a given variable name
def release(self, path, fh): "Run after a read or write operation has finished. This is where we upload on writes" try: f = self.__newfiles[path] f.seek(0, os.SEEK_END) if f.tell() > 0: self.client.up(path, f) del self.__newfiles[path] del f self._dirty(path) except KeyError: pass return ESUCCESS
module function_definition identifier parameters identifier identifier identifier block expression_statement string string_start string_content string_end try_statement block expression_statement assignment identifier subscript attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list integer attribute identifier identifier if_statement comparison_operator call attribute identifier identifier argument_list integer block expression_statement call attribute attribute identifier identifier identifier argument_list identifier identifier delete_statement subscript attribute identifier identifier identifier delete_statement identifier expression_statement call attribute identifier identifier argument_list identifier except_clause identifier block pass_statement return_statement identifier
Run after a read or write operation has finished. This is where we upload on writes
def load(target, source_module=None): module, klass, function = _get_module(target) if not module and source_module: module = source_module if not module: raise MissingModule( "No module name supplied or source_module provided.") actual_module = sys.modules[module] if not klass: return getattr(actual_module, function) class_object = getattr(actual_module, klass) if function: return getattr(class_object, function) return class_object
module function_definition identifier parameters identifier default_parameter identifier none block expression_statement assignment pattern_list identifier identifier identifier call identifier argument_list identifier if_statement boolean_operator not_operator identifier identifier block expression_statement assignment identifier identifier if_statement not_operator identifier block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment identifier subscript attribute identifier identifier identifier if_statement not_operator identifier block return_statement call identifier argument_list identifier identifier expression_statement assignment identifier call identifier argument_list identifier identifier if_statement identifier block return_statement call identifier argument_list identifier identifier return_statement identifier
Get the actual implementation of the target.
def Header(self): _ = [option.OnGetValue() for option in self.options] return self.name
module function_definition identifier parameters identifier block expression_statement assignment identifier list_comprehension call attribute identifier identifier argument_list for_in_clause identifier attribute identifier identifier return_statement attribute identifier identifier
Fetch the header name of this Value.
def summarize(self, host): return dict( ok = self.ok.get(host, 0), failures = self.failures.get(host, 0), unreachable = self.dark.get(host,0), changed = self.changed.get(host, 0), skipped = self.skipped.get(host, 0) )
module function_definition identifier parameters identifier identifier block return_statement call identifier argument_list keyword_argument identifier call attribute attribute identifier identifier identifier argument_list identifier integer keyword_argument identifier call attribute attribute identifier identifier identifier argument_list identifier integer keyword_argument identifier call attribute attribute identifier identifier identifier argument_list identifier integer keyword_argument identifier call attribute attribute identifier identifier identifier argument_list identifier integer keyword_argument identifier call attribute attribute identifier identifier identifier argument_list identifier integer
return information about a particular host
def generic_div(a, b): logger.debug('Called generic_div({}, {})'.format(a, b)) return a / b
module function_definition identifier parameters identifier identifier block expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier identifier return_statement binary_operator identifier identifier
Simple function to divide two numbers
def rm(self, fname=None): if fname is not None: return (self / fname).rm() try: self.remove() except OSError: pass
module function_definition identifier parameters identifier default_parameter identifier none block if_statement comparison_operator identifier none block return_statement call attribute parenthesized_expression binary_operator identifier identifier identifier argument_list try_statement block expression_statement call attribute identifier identifier argument_list except_clause identifier block pass_statement
Remove a file, don't raise exception if file does not exist.
def prep_args(arg_info): filtered_args = [a for a in arg_info.args if getattr(arg_info, 'varargs', None) != a] if filtered_args and (filtered_args[0] in ('self', 'cls')): filtered_args = filtered_args[1:] pos_args = [] if filtered_args: for arg in filtered_args: if isinstance(arg, str) and arg in arg_info.locals: resolved_type = resolve_type(arg_info.locals[arg]) pos_args.append(resolved_type) else: pos_args.append(type(UnknownType())) varargs = None if arg_info.varargs: varargs_tuple = arg_info.locals[arg_info.varargs] if isinstance(varargs_tuple, tuple): varargs = [resolve_type(arg) for arg in varargs_tuple[:4]] return ResolvedTypes(pos_args=pos_args, varargs=varargs)
module function_definition identifier parameters identifier block expression_statement assignment identifier list_comprehension identifier for_in_clause identifier attribute identifier identifier if_clause comparison_operator call identifier argument_list identifier string string_start string_content string_end none identifier if_statement boolean_operator identifier parenthesized_expression comparison_operator subscript identifier integer tuple string string_start string_content string_end string string_start string_content string_end block expression_statement assignment identifier subscript identifier slice integer expression_statement assignment identifier list if_statement identifier block for_statement identifier identifier block if_statement boolean_operator call identifier argument_list identifier identifier comparison_operator identifier attribute identifier identifier block expression_statement assignment identifier call identifier argument_list subscript attribute identifier identifier identifier expression_statement call attribute identifier identifier argument_list identifier else_clause block expression_statement call attribute identifier identifier argument_list call identifier argument_list call identifier argument_list expression_statement assignment identifier none if_statement attribute identifier identifier block expression_statement assignment identifier subscript attribute identifier identifier attribute identifier identifier if_statement call identifier argument_list identifier identifier block expression_statement assignment identifier list_comprehension call identifier argument_list identifier for_in_clause identifier subscript identifier slice integer return_statement call identifier argument_list keyword_argument identifier identifier keyword_argument identifier identifier
Resolve types from ArgInfo
def check_permissions(self, request): objs = [None] if hasattr(self, 'get_perms_objects'): objs = self.get_perms_objects() else: if hasattr(self, 'get_object'): try: objs = [self.get_object()] except Http404: raise except: pass if objs == [None]: objs = self.get_queryset() if len(objs) == 0: objs = [None] if (hasattr(self, 'permission_filter_queryset') and self.permission_filter_queryset is not False and self.request.method == 'GET'): if objs != [None]: self.perms_filter_queryset(objs) else: has_perm = check_perms(self.request.user, self.get_permission_required(), objs, self.request.method) if not has_perm: msg = self.get_permission_denied_message( default="Permission denied." ) if isinstance(msg, Sequence): msg = msg[0] self.permission_denied(request, message=msg)
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier list none if_statement call identifier argument_list identifier string string_start string_content string_end block expression_statement assignment identifier call attribute identifier identifier argument_list else_clause block if_statement call identifier argument_list identifier string string_start string_content string_end block try_statement block expression_statement assignment identifier list call attribute identifier identifier argument_list except_clause identifier block raise_statement except_clause block pass_statement if_statement comparison_operator identifier list none block expression_statement assignment identifier call attribute identifier identifier argument_list if_statement comparison_operator call identifier argument_list identifier integer block expression_statement assignment identifier list none if_statement parenthesized_expression boolean_operator boolean_operator call identifier argument_list identifier string string_start string_content string_end comparison_operator attribute identifier identifier false comparison_operator attribute attribute identifier identifier identifier string string_start string_content string_end block if_statement comparison_operator identifier list none block expression_statement call attribute identifier identifier argument_list identifier else_clause block expression_statement assignment identifier call identifier argument_list attribute attribute identifier identifier identifier call attribute identifier identifier argument_list identifier attribute attribute identifier identifier identifier if_statement not_operator identifier block expression_statement assignment identifier call attribute identifier identifier argument_list keyword_argument identifier string string_start string_content string_end if_statement call identifier argument_list identifier identifier block expression_statement assignment identifier subscript identifier integer expression_statement call attribute identifier identifier argument_list identifier keyword_argument identifier identifier
Permission checking for DRF.
def qpinfo(): parser = qpinfo_parser() args = parser.parse_args() path = pathlib.Path(args.path).resolve() try: ds = load_data(path) except UnknownFileFormatError: print("Unknown file format: {}".format(path)) return print("{} ({})".format(ds.__class__.__doc__, ds.__class__.__name__)) print("- number of images: {}".format(len(ds))) for key in ds.meta_data: print("- {}: {}".format(key, ds.meta_data[key]))
module function_definition identifier parameters block expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute call attribute identifier identifier argument_list attribute identifier identifier identifier argument_list try_statement block expression_statement assignment identifier call identifier argument_list identifier except_clause identifier block expression_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier return_statement expression_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list attribute attribute identifier identifier identifier attribute attribute identifier identifier identifier expression_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list call identifier argument_list identifier for_statement identifier attribute identifier identifier block expression_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier subscript attribute identifier identifier identifier
Print information of a quantitative phase imaging dataset
def get(self, path, watch=None): _log.debug( "ZK: Getting {path}".format(path=path), ) return self.zk.get(path, watch)
module function_definition identifier parameters identifier identifier default_parameter identifier none block expression_statement call attribute identifier identifier argument_list call attribute string string_start string_content string_end identifier argument_list keyword_argument identifier identifier return_statement call attribute attribute identifier identifier identifier argument_list identifier identifier
Returns the data of the specified node.
def chi_p_from_xi1_xi2(xi1, xi2): xi1, xi2, input_is_array = ensurearray(xi1, xi2) chi_p = copy.copy(xi1) mask = xi1 < xi2 chi_p[mask] = xi2[mask] return formatreturn(chi_p, input_is_array)
module function_definition identifier parameters identifier identifier block expression_statement assignment pattern_list identifier identifier identifier call identifier argument_list identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier comparison_operator identifier identifier expression_statement assignment subscript identifier identifier subscript identifier identifier return_statement call identifier argument_list identifier identifier
Returns effective precession spin from xi1 and xi2.
def _get_recurse_directive_depth(field_name, field_directives): recurse_directive = field_directives['recurse'] optional_directive = field_directives.get('optional', None) if optional_directive: raise GraphQLCompilationError(u'Found both @optional and @recurse on ' u'the same vertex field: {}'.format(field_name)) recurse_args = get_uniquely_named_objects_by_name(recurse_directive.arguments) recurse_depth = int(recurse_args['depth'].value.value) if recurse_depth < 1: raise GraphQLCompilationError(u'Found recurse directive with disallowed depth: ' u'{}'.format(recurse_depth)) return recurse_depth
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier subscript identifier string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end none if_statement identifier block raise_statement call identifier argument_list call attribute concatenated_string string string_start string_content string_end string string_start string_content string_end identifier argument_list identifier expression_statement assignment identifier call identifier argument_list attribute identifier identifier expression_statement assignment identifier call identifier argument_list attribute attribute subscript identifier string string_start string_content string_end identifier identifier if_statement comparison_operator identifier integer block raise_statement call identifier argument_list call attribute concatenated_string string string_start string_content string_end string string_start string_content string_end identifier argument_list identifier return_statement identifier
Validate and return the depth parameter of the recurse directive.
def acquire(self,blocking=True,timeout=None,shared=False): with self._lock: if shared: self._acquire_shared(blocking,timeout) else: self._acquire_exclusive(blocking,timeout) assert not (self.is_shared and self.is_exclusive)
module function_definition identifier parameters identifier default_parameter identifier true default_parameter identifier none default_parameter identifier false block with_statement with_clause with_item attribute identifier identifier block if_statement identifier block expression_statement call attribute identifier identifier argument_list identifier identifier else_clause block expression_statement call attribute identifier identifier argument_list identifier identifier assert_statement not_operator parenthesized_expression boolean_operator attribute identifier identifier attribute identifier identifier
Acquire the lock in shared or exclusive mode.
def addPhenotypeSearchOptions(parser): parser.add_argument( "--phenotype_association_set_id", "-s", default=None, help="Only return phenotypes from this phenotype_association_set.") parser.add_argument( "--phenotype_id", "-p", default=None, help="Only return this phenotype.") parser.add_argument( "--description", "-d", default=None, help="Only return phenotypes matching this description.") parser.add_argument( "--age_of_onset", "-a", default=None, help="Only return phenotypes with this age_of_onset.") parser.add_argument( "--type", "-T", default=None, help="Only return phenotypes with this type.")
module function_definition identifier parameters identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end keyword_argument identifier none keyword_argument identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end keyword_argument identifier none keyword_argument identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end keyword_argument identifier none keyword_argument identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end keyword_argument identifier none keyword_argument identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_content string_end keyword_argument identifier none keyword_argument identifier string string_start string_content string_end
Adds options to a phenotype searches command line parser.
def format_local_dap(dap, full=False, **kwargs): lines = [] label_width = dapi.DapFormatter.calculate_offset(BASIC_LABELS) lines.append(dapi.DapFormatter.format_meta(dap.meta, labels=BASIC_LABELS, offset=label_width, **kwargs)) lines.append('') lines.append(dapi.DapFormatter.format_assistants(dap.assistants)) if full: lines.append('') lines.append(dapi.DapFormatter.format_snippets(dap.snippets)) if 'supported_platforms' in dap.meta: lines.append('') lines.append(dapi.DapFormatter.format_platforms(dap.meta['supported_platforms'])) lines.append() return lines
module function_definition identifier parameters identifier default_parameter identifier false dictionary_splat_pattern identifier block expression_statement assignment identifier list expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list attribute identifier identifier keyword_argument identifier identifier keyword_argument identifier identifier dictionary_splat identifier expression_statement call attribute identifier identifier argument_list string string_start string_end expression_statement call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list attribute identifier identifier if_statement identifier block expression_statement call attribute identifier identifier argument_list string string_start string_end expression_statement call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list attribute identifier identifier if_statement comparison_operator string string_start string_content string_end attribute identifier identifier block expression_statement call attribute identifier identifier argument_list string string_start string_end expression_statement call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list subscript attribute identifier identifier string string_start string_content string_end expression_statement call attribute identifier identifier argument_list return_statement identifier
Formaqts information about the given local DAP in a human readable form to list of lines
def check_constraints(self, instance): recalc_fields = [] for constraint in self.constraints: try: constraint(self.model, instance) except constraints.InvalidConstraint as e: recalc_fields.extend(e.fields) return recalc_fields
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier list for_statement identifier attribute identifier identifier block try_statement block expression_statement call identifier argument_list attribute identifier identifier identifier except_clause as_pattern attribute identifier identifier as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier return_statement identifier
Return fieldnames which need recalculation.
def pusher_connected(self, data): self.logger.info("Pusherclient connected") self.callback_client.bind("payment_authorized", self.payment_authorized) self.callback_client.bind("shortlink_scanned", self.shortlink_scanned)
module function_definition identifier parameters identifier identifier block expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end attribute identifier identifier expression_statement call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end attribute identifier identifier
Called when the pusherclient is connected
def rewrite(self, path, expand, newmethod = None, host = None, vhost = None, method = [b'GET', b'HEAD'], keepquery = True): "Automatically rewrite a request to another location" async def func(env): newpath = self.expand(env.path_match, expand) if keepquery and getattr(env, 'querystring', None): if b'?' in newpath: newpath += b'&' + env.querystring else: newpath += b'?' + env.querystring await env.rewrite(newpath, newmethod) self.route(path, func)
module function_definition identifier parameters identifier identifier identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier list string string_start string_content string_end string string_start string_content string_end default_parameter identifier true block expression_statement string string_start string_content string_end function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list attribute identifier identifier identifier if_statement boolean_operator identifier call identifier argument_list identifier string string_start string_content string_end none block if_statement comparison_operator string string_start string_content string_end identifier block expression_statement augmented_assignment identifier binary_operator string string_start string_content string_end attribute identifier identifier else_clause block expression_statement augmented_assignment identifier binary_operator string string_start string_content string_end attribute identifier identifier expression_statement await call attribute identifier identifier argument_list identifier identifier expression_statement call attribute identifier identifier argument_list identifier identifier
Automatically rewrite a request to another location
def str_check(*args, func=None): func = func or inspect.stack()[2][3] for var in args: if not isinstance(var, (str, collections.UserString, collections.abc.Sequence)): name = type(var).__name__ raise StringError( f'Function {func} expected str, {name} got instead.')
module function_definition identifier parameters list_splat_pattern identifier default_parameter identifier none block expression_statement assignment identifier boolean_operator identifier subscript subscript call attribute identifier identifier argument_list integer integer for_statement identifier identifier block if_statement not_operator call identifier argument_list identifier tuple identifier attribute identifier identifier attribute attribute identifier identifier identifier block expression_statement assignment identifier attribute call identifier argument_list identifier identifier raise_statement call identifier argument_list string string_start string_content interpolation identifier string_content interpolation identifier string_content string_end
Check if arguments are str type.
def infer_operands_size(operands): size = None for oprnd in operands: if oprnd.size: size = oprnd.size break if size: for oprnd in operands: if not oprnd.size: oprnd.size = size else: for oprnd in operands: if isinstance(oprnd, X86ImmediateOperand) and not oprnd.size: oprnd.size = arch_info.architecture_size
module function_definition identifier parameters identifier block expression_statement assignment identifier none for_statement identifier identifier block if_statement attribute identifier identifier block expression_statement assignment identifier attribute identifier identifier break_statement if_statement identifier block for_statement identifier identifier block if_statement not_operator attribute identifier identifier block expression_statement assignment attribute identifier identifier identifier else_clause block for_statement identifier identifier block if_statement boolean_operator call identifier argument_list identifier identifier not_operator attribute identifier identifier block expression_statement assignment attribute identifier identifier attribute identifier identifier
Infer x86 instruction operand size based on other operands.
def sendBox(self, box): if self.remoteRouteName is _unspecified: raise RouteNotConnected() if self.remoteRouteName is not None: box[_ROUTE] = self.remoteRouteName.encode('ascii') self.router._sender.sendBox(box)
module function_definition identifier parameters identifier identifier block if_statement comparison_operator attribute identifier identifier identifier block raise_statement call identifier argument_list if_statement comparison_operator attribute identifier identifier none block expression_statement assignment subscript identifier identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list identifier
Add the route and send the box.
def add_lv_load_area_group(self, lv_load_area_group): if lv_load_area_group not in self.lv_load_area_groups(): self._lv_load_area_groups.append(lv_load_area_group)
module function_definition identifier parameters identifier identifier block if_statement comparison_operator identifier call attribute identifier identifier argument_list block expression_statement call attribute attribute identifier identifier identifier argument_list identifier
Adds a LV load_area to _lv_load_areas if not already existing.
def _soap_client_call(method_name, *args): soap_client = _build_soap_client() soap_args = _convert_soap_method_args(*args) if PYSIMPLESOAP_1_16_2: return getattr(soap_client, method_name)(*soap_args) else: return getattr(soap_client, method_name)(soap_client, *soap_args)
module function_definition identifier parameters identifier list_splat_pattern identifier block expression_statement assignment identifier call identifier argument_list expression_statement assignment identifier call identifier argument_list list_splat identifier if_statement identifier block return_statement call call identifier argument_list identifier identifier argument_list list_splat identifier else_clause block return_statement call call identifier argument_list identifier identifier argument_list identifier list_splat identifier
Wrapper to call SoapClient method
def queue_files(dirpath, queue): for root, _, files in os.walk(os.path.abspath(dirpath)): if not files: continue for filename in files: queue.put(os.path.join(root, filename))
module function_definition identifier parameters identifier identifier block for_statement pattern_list identifier identifier identifier call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list identifier block if_statement not_operator identifier block continue_statement for_statement identifier identifier block expression_statement call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list identifier identifier
Add files in a directory to a queue
def lookup(sock, domain, cache = None): domain = normalize_domain(domain) reply = sam_cmd(sock, "NAMING LOOKUP NAME=%s" % domain) b64_dest = reply.get('VALUE') if b64_dest: dest = Dest(b64_dest, encoding='base64') if cache: cache[dest.base32 + '.b32.i2p'] = dest return dest else: raise NSError('Domain name %r not resolved because %r' % (domain, reply))
module function_definition identifier parameters identifier identifier default_parameter identifier none block expression_statement assignment identifier call identifier argument_list identifier expression_statement assignment identifier call identifier argument_list identifier binary_operator string string_start string_content string_end identifier expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement identifier block expression_statement assignment identifier call identifier argument_list identifier keyword_argument identifier string string_start string_content string_end if_statement identifier block expression_statement assignment subscript identifier binary_operator attribute identifier identifier string string_start string_content string_end identifier return_statement identifier else_clause block raise_statement call identifier argument_list binary_operator string string_start string_content string_end tuple identifier identifier
lookup an I2P domain name, returning a Destination instance
def start_tag(self) -> str: tag = '<' + self.tag attrs = self._get_attrs_by_string() if attrs: tag = ' '.join((tag, attrs)) return tag + '>'
module function_definition identifier parameters identifier type identifier block expression_statement assignment identifier binary_operator string string_start string_content string_end attribute identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list if_statement identifier block expression_statement assignment identifier call attribute string string_start string_content string_end identifier argument_list tuple identifier identifier return_statement binary_operator identifier string string_start string_content string_end
Return HTML start tag.
def first(values, axis, skipna=None): if (skipna or skipna is None) and values.dtype.kind not in 'iSU': _fail_on_dask_array_input_skipna(values) return nanfirst(values, axis) return take(values, 0, axis=axis)
module function_definition identifier parameters identifier identifier default_parameter identifier none block if_statement boolean_operator parenthesized_expression boolean_operator identifier comparison_operator identifier none comparison_operator attribute attribute identifier identifier identifier string string_start string_content string_end block expression_statement call identifier argument_list identifier return_statement call identifier argument_list identifier identifier return_statement call identifier argument_list identifier integer keyword_argument identifier identifier
Return the first non-NA elements in this array along the given axis
def start_scanner(path): try: observer = Observer() observer.start() stream = Stream(file_modified, path, file_events=True) observer.schedule(stream) print "Watching for changes. Press Ctrl-C to stop." while 1: pass except (KeyboardInterrupt, OSError, IOError): observer.unschedule(stream) observer.stop()
module function_definition identifier parameters identifier block try_statement block expression_statement assignment identifier call identifier argument_list expression_statement call attribute identifier identifier argument_list expression_statement assignment identifier call identifier argument_list identifier identifier keyword_argument identifier true expression_statement call attribute identifier identifier argument_list identifier print_statement string string_start string_content string_end while_statement integer block pass_statement except_clause tuple identifier identifier identifier block expression_statement call attribute identifier identifier argument_list identifier expression_statement call attribute identifier identifier argument_list
watch for file events in the supplied path
def update(self, **kwargs) -> "UpdateQuery": return UpdateQuery( db=self._db, model=self.model, update_kwargs=kwargs, q_objects=self._q_objects, annotations=self._annotations, custom_filters=self._custom_filters, )
module function_definition identifier parameters identifier dictionary_splat_pattern identifier type string string_start string_content string_end block return_statement call identifier argument_list keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier keyword_argument identifier attribute identifier identifier
Update all objects in QuerySet with given kwargs.
def create_session(self): url = self.build_url(self._endpoints.get('create_session')) response = self.con.post(url, data={'persistChanges': self.persist}) if not response: raise RuntimeError('Could not create session as requested by the user.') data = response.json() self.session_id = data.get('id') return True
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier keyword_argument identifier dictionary pair string string_start string_content string_end attribute identifier identifier if_statement not_operator identifier block raise_statement call identifier argument_list string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list expression_statement assignment attribute identifier identifier call attribute identifier identifier argument_list string string_start string_content string_end return_statement true
Request a new session id
def update_text(self, mapping): found = False for node in self._page.iter("*"): if node.text or node.tail: for old, new in mapping.items(): if node.text and old in node.text: node.text = node.text.replace(old, new) found = True if node.tail and old in node.tail: node.tail = node.tail.replace(old, new) found = True if not found: raise KeyError("Updating text failed with mapping:{}".format(mapping))
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier false for_statement identifier call attribute attribute identifier identifier identifier argument_list string string_start string_content string_end block if_statement boolean_operator attribute identifier identifier attribute identifier identifier block for_statement pattern_list identifier identifier call attribute identifier identifier argument_list block if_statement boolean_operator attribute identifier identifier comparison_operator identifier attribute identifier identifier block expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list identifier identifier expression_statement assignment identifier true if_statement boolean_operator attribute identifier identifier comparison_operator identifier attribute identifier identifier block expression_statement assignment attribute identifier identifier call attribute attribute identifier identifier identifier argument_list identifier identifier expression_statement assignment identifier true if_statement not_operator identifier block raise_statement call identifier argument_list call attribute string string_start string_content string_end identifier argument_list identifier
Iterate over nodes, replace text with mapping
def _get_master_proc_by_name(self, name, tags): master_name = GUnicornCheck._get_master_proc_name(name) master_procs = [p for p in psutil.process_iter() if p.cmdline() and p.cmdline()[0] == master_name] if len(master_procs) == 0: self.service_check( self.SVC_NAME, AgentCheck.CRITICAL, tags=['app:' + name] + tags, message="No gunicorn process with name %s found" % name, ) raise GUnicornCheckError("Found no master process with name: %s" % master_name) else: self.log.debug("There exist %s master process(es) with the name %s" % (len(master_procs), name)) return master_procs
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier list_comprehension identifier for_in_clause identifier call attribute identifier identifier argument_list if_clause boolean_operator call attribute identifier identifier argument_list comparison_operator subscript call attribute identifier identifier argument_list integer identifier if_statement comparison_operator call identifier argument_list identifier integer block expression_statement call attribute identifier identifier argument_list attribute identifier identifier attribute identifier identifier keyword_argument identifier binary_operator list binary_operator string string_start string_content string_end identifier identifier keyword_argument identifier binary_operator string string_start string_content string_end identifier raise_statement call identifier argument_list binary_operator string string_start string_content string_end identifier else_clause block expression_statement call attribute attribute identifier identifier identifier argument_list binary_operator string string_start string_content string_end tuple call identifier argument_list identifier identifier return_statement identifier
Return a psutil process for the master gunicorn process with the given name.
def p_changeinfo(self): post_data, def_dic = self.fetch_post_data() usercheck = MUser.check_user(self.userinfo.uid, post_data['rawpass']) if usercheck == 1: MUser.update_info(self.userinfo.uid, post_data['user_email'], extinfo=def_dic) output = {'changeinfo ': usercheck} else: output = {'changeinfo ': 0} return json.dump(output, self)
module function_definition identifier parameters identifier block expression_statement assignment pattern_list identifier identifier call attribute identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list attribute attribute identifier identifier identifier subscript identifier string string_start string_content string_end if_statement comparison_operator identifier integer block expression_statement call attribute identifier identifier argument_list attribute attribute identifier identifier identifier subscript identifier string string_start string_content string_end keyword_argument identifier identifier expression_statement assignment identifier dictionary pair string string_start string_content string_end identifier else_clause block expression_statement assignment identifier dictionary pair string string_start string_content string_end integer return_statement call attribute identifier identifier argument_list identifier identifier
Change Infor via Ajax.
def return_small_clade(treenode): "used to produce balanced trees, returns a tip node from the smaller clade" node = treenode while 1: if node.children: c1, c2 = node.children node = sorted([c1, c2], key=lambda x: len(x.get_leaves()))[0] else: return node
module function_definition identifier parameters identifier block expression_statement string string_start string_content string_end expression_statement assignment identifier identifier while_statement integer block if_statement attribute identifier identifier block expression_statement assignment pattern_list identifier identifier attribute identifier identifier expression_statement assignment identifier subscript call identifier argument_list list identifier identifier keyword_argument identifier lambda lambda_parameters identifier call identifier argument_list call attribute identifier identifier argument_list integer else_clause block return_statement identifier
used to produce balanced trees, returns a tip node from the smaller clade
def _set_affected_target_count_in_runtracker(self): target_count = len(self.build_graph) self.run_tracker.pantsd_stats.set_affected_targets_size(target_count) return target_count
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list attribute identifier identifier expression_statement call attribute attribute attribute identifier identifier identifier identifier argument_list identifier return_statement identifier
Sets the realized target count in the run tracker's daemon stats object.
def _call_wrapper(self, time, function, *args): function(*args) if function in self._callback.keys(): repeat = self._callback[function][1] if repeat: callback_id = self.tk.after(time, self._call_wrapper, time, function, *args) self._callback[function][0] = callback_id else: self._callback.pop(function)
module function_definition identifier parameters identifier identifier identifier list_splat_pattern identifier block expression_statement call identifier argument_list list_splat identifier if_statement comparison_operator identifier call attribute attribute identifier identifier identifier argument_list block expression_statement assignment identifier subscript subscript attribute identifier identifier identifier integer if_statement identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier attribute identifier identifier identifier identifier list_splat identifier expression_statement assignment subscript subscript attribute identifier identifier identifier integer identifier else_clause block expression_statement call attribute attribute identifier identifier identifier argument_list identifier
Fired by tk.after, gets the callback and either executes the function and cancels or repeats
def _get_run_info_dict(self, run_id): run_info_path = os.path.join(self._settings.info_dir, run_id, 'info') if os.path.exists(run_info_path): return RunInfo(run_info_path).get_as_dict() else: return None
module function_definition identifier parameters identifier identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list attribute attribute identifier identifier identifier identifier string string_start string_content string_end if_statement call attribute attribute identifier identifier identifier argument_list identifier block return_statement call attribute call identifier argument_list identifier identifier argument_list else_clause block return_statement none
Get the RunInfo for a run, as a dict.
def send_line(self, data, nowait=False): data = data.replace('\n', ' ').replace('\r', ' ') f = asyncio.Future(loop=self.loop) if self.queue is not None and nowait is False: self.queue.put_nowait((f, data)) else: self.send(data.replace('\n', ' ').replace('\r', ' ')) f.set_result(True) return f
module function_definition identifier parameters identifier identifier default_parameter identifier false block expression_statement assignment identifier call attribute call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end string string_start string_content string_end identifier argument_list string string_start string_content escape_sequence string_end string string_start string_content string_end expression_statement assignment identifier call attribute identifier identifier argument_list keyword_argument identifier attribute identifier identifier if_statement boolean_operator comparison_operator attribute identifier identifier none comparison_operator identifier false block expression_statement call attribute attribute identifier identifier identifier argument_list tuple identifier identifier else_clause block expression_statement call attribute identifier identifier argument_list call attribute call attribute identifier identifier argument_list string string_start string_content escape_sequence string_end string string_start string_content string_end identifier argument_list string string_start string_content escape_sequence string_end string string_start string_content string_end expression_statement call attribute identifier identifier argument_list true return_statement identifier
send a line to the server. replace CR by spaces
def follow_shortlinks(shortlinks): links_followed = {} for shortlink in shortlinks: url = shortlink request_result = requests.get(url) redirect_history = request_result.history all_urls = [] for redirect in redirect_history: all_urls.append(redirect.url) all_urls.append(request_result.url) links_followed[shortlink] = all_urls return links_followed
module function_definition identifier parameters identifier block expression_statement assignment identifier dictionary for_statement identifier identifier block expression_statement assignment identifier identifier expression_statement assignment identifier call attribute identifier identifier argument_list identifier expression_statement assignment identifier attribute identifier identifier expression_statement assignment identifier list for_statement identifier identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement assignment subscript identifier identifier identifier return_statement identifier
Follow redirects in list of shortlinks, return dict of resulting URLs
def parseprint(code, filename="<string>", mode="exec", **kwargs): node = parse(code, mode=mode) print(dump(node, **kwargs))
module function_definition identifier parameters identifier default_parameter identifier string string_start string_content string_end default_parameter identifier string string_start string_content string_end dictionary_splat_pattern identifier block expression_statement assignment identifier call identifier argument_list identifier keyword_argument identifier identifier expression_statement call identifier argument_list call identifier argument_list identifier dictionary_splat identifier
Parse some code from a string and pretty-print it.
def rollback(self, date): if self.onOffset(date): return date else: return date - YearEnd(month=self.month)
module function_definition identifier parameters identifier identifier block if_statement call attribute identifier identifier argument_list identifier block return_statement identifier else_clause block return_statement binary_operator identifier call identifier argument_list keyword_argument identifier attribute identifier identifier
Roll date backward to nearest end of year
def create_cluster_meta(cluster_groups): meta = ClusterMeta() meta.add_field('group') cluster_groups = cluster_groups or {} data = {c: {'group': v} for c, v in cluster_groups.items()} meta.from_dict(data) return meta
module function_definition identifier parameters identifier block expression_statement assignment identifier call identifier argument_list expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier boolean_operator identifier dictionary expression_statement assignment identifier dictionary_comprehension pair identifier dictionary pair string string_start string_content string_end identifier for_in_clause pattern_list identifier identifier call attribute identifier identifier argument_list expression_statement call attribute identifier identifier argument_list identifier return_statement identifier
Return a ClusterMeta instance with cluster group support.
def update_time_range(form_data): if 'since' in form_data or 'until' in form_data: form_data['time_range'] = '{} : {}'.format( form_data.pop('since', '') or '', form_data.pop('until', '') or '', )
module function_definition identifier parameters identifier block if_statement boolean_operator comparison_operator string string_start string_content string_end identifier comparison_operator string string_start string_content string_end identifier block expression_statement assignment subscript identifier string string_start string_content string_end call attribute string string_start string_content string_end identifier argument_list boolean_operator call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_end string string_start string_end boolean_operator call attribute identifier identifier argument_list string string_start string_content string_end string string_start string_end string string_start string_end
Move since and until to time_range.
def scope_types(self, request, *args, **kwargs): return response.Response(utils.get_scope_types_mapping().keys())
module function_definition identifier parameters identifier identifier list_splat_pattern identifier dictionary_splat_pattern identifier block return_statement call attribute identifier identifier argument_list call attribute call attribute identifier identifier argument_list identifier argument_list
Returns a list of scope types acceptable by events filter.
def ctor(name, func, *args, **kwargs): return globscope.ctor(name, func, *args, **kwargs)
module function_definition identifier parameters identifier identifier list_splat_pattern identifier dictionary_splat_pattern identifier block return_statement call attribute identifier identifier argument_list identifier identifier list_splat identifier dictionary_splat identifier
Add a ctor callback to the global scope.
def skeleton_path(parts): return os.path.join(os.path.dirname(oz.__file__), "skeleton", parts)
module function_definition identifier parameters identifier block return_statement call attribute attribute identifier identifier identifier argument_list call attribute attribute identifier identifier identifier argument_list attribute identifier identifier string string_start string_content string_end identifier
Gets the path to a skeleton asset
def generate_term(self, **kwargs): term_map = kwargs.pop('term_map') if hasattr(term_map, "termType") and\ term_map.termType == NS_MGR.rr.BlankNode.rdflib: return rdflib.BNode() if not hasattr(term_map, 'datatype'): term_map.datatype = NS_MGR.xsd.anyURI.rdflib if hasattr(term_map, "template") and term_map.template is not None: template_vars = kwargs template_vars.update(self.constants) for key, value in template_vars.items(): if hasattr(value, "__call__"): template_vars[key] = value() raw_value = term_map.template.format(**template_vars) if term_map.datatype == NS_MGR.xsd.anyURI.rdflib: return rdflib.URIRef(raw_value) return rdflib.Literal(raw_value, datatype=term_map.datatype) if term_map.reference is not None: return self.__generate_reference__(term_map, **kwargs)
module function_definition identifier parameters identifier dictionary_splat_pattern identifier block expression_statement assignment identifier call attribute identifier identifier argument_list string string_start string_content string_end if_statement boolean_operator call identifier argument_list identifier string string_start string_content string_end line_continuation comparison_operator attribute identifier identifier attribute attribute attribute identifier identifier identifier identifier block return_statement call attribute identifier identifier argument_list if_statement not_operator call identifier argument_list identifier string string_start string_content string_end block expression_statement assignment attribute identifier identifier attribute attribute attribute identifier identifier identifier identifier if_statement boolean_operator call identifier argument_list identifier string string_start string_content string_end comparison_operator attribute identifier identifier none block expression_statement assignment identifier identifier expression_statement call attribute identifier identifier argument_list attribute identifier identifier for_statement pattern_list identifier identifier call attribute identifier identifier argument_list block if_statement call identifier argument_list identifier string string_start string_content string_end block expression_statement assignment subscript identifier identifier call identifier argument_list expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list dictionary_splat identifier if_statement comparison_operator attribute identifier identifier attribute attribute attribute identifier identifier identifier identifier block return_statement call attribute identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list identifier keyword_argument identifier attribute identifier identifier if_statement comparison_operator attribute identifier identifier none block return_statement call attribute identifier identifier argument_list identifier dictionary_splat identifier
Method generates a rdflib.Term based on kwargs
def select_record(self, table, where=None, values=None, orderby=None, limit=None, columns=None): query = self.schema.query_builder.build_select(table, where, orderby, limit, columns) return table.to_table(self.execute(query, values), columns=columns)
module function_definition identifier parameters identifier identifier default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier none default_parameter identifier none block expression_statement assignment identifier call attribute attribute attribute identifier identifier identifier identifier argument_list identifier identifier identifier identifier identifier return_statement call attribute identifier identifier argument_list call attribute identifier identifier argument_list identifier identifier keyword_argument identifier identifier
Support these keywords where, values, orderby, limit and columns
def render_unicode(self, *args, **data): return runtime._render(self, self.callable_, args, data, as_unicode=True)
module function_definition identifier parameters identifier list_splat_pattern identifier dictionary_splat_pattern identifier block return_statement call attribute identifier identifier argument_list identifier attribute identifier identifier identifier identifier keyword_argument identifier true
Render the output of this template as a unicode object.
def last_modified_date(filename): mtime = os.path.getmtime(filename) dt = datetime.datetime.utcfromtimestamp(mtime) return dt.replace(tzinfo=pytz.utc)
module function_definition identifier parameters identifier block expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier return_statement call attribute identifier identifier argument_list keyword_argument identifier attribute identifier identifier
Last modified timestamp as a UTC datetime
def _finishAnimation(self): self.setCurrentIndex(self._nextIndex) self.widget(self._lastIndex).hide() self.widget(self._lastIndex).move(self._lastPoint) self._active = False if not self.signalsBlocked(): self.animationFinished.emit()
module function_definition identifier parameters identifier block expression_statement call attribute identifier identifier argument_list attribute identifier identifier expression_statement call attribute call attribute identifier identifier argument_list attribute identifier identifier identifier argument_list expression_statement call attribute call attribute identifier identifier argument_list attribute identifier identifier identifier argument_list attribute identifier identifier expression_statement assignment attribute identifier identifier false if_statement not_operator call attribute identifier identifier argument_list block expression_statement call attribute attribute identifier identifier identifier argument_list
Cleans up post-animation.
def getStartingApplication(self, pchAppKeyBuffer, unAppKeyBufferLen): fn = self.function_table.getStartingApplication result = fn(pchAppKeyBuffer, unAppKeyBufferLen) return result
module function_definition identifier parameters identifier identifier identifier block expression_statement assignment identifier attribute attribute identifier identifier identifier expression_statement assignment identifier call identifier argument_list identifier identifier return_statement identifier
Returns the app key for the application that is starting up
def _generate_metadata_file(workdir, archive_name, platform, python_versions, package_name, package_version, build_tag, package_source, wheels): logger.debug('Generating Metadata...') metadata = { 'created_by_wagon_version': _get_wagon_version(), 'archive_name': archive_name, 'supported_platform': platform, 'supported_python_versions': python_versions, 'build_server_os_properties': { 'distribution': None, 'distribution_version': None, 'distribution_release': None, }, 'package_name': package_name, 'package_version': package_version, 'package_build_tag': build_tag, 'package_source': package_source, 'wheels': wheels, } if IS_LINUX and platform != ALL_PLATFORMS_TAG: distribution, version, release = _get_os_properties() metadata.update( {'build_server_os_properties': { 'distribution': distribution.lower(), 'distribution_version': version.lower(), 'distribution_release': release.lower() }}) formatted_metadata = json.dumps(metadata, indent=4, sort_keys=True) if is_verbose(): logger.debug('Metadata is: %s', formatted_metadata) output_path = os.path.join(workdir, METADATA_FILE_NAME) with open(output_path, 'w') as f: logger.debug('Writing metadata to file: %s', output_path) f.write(formatted_metadata)
module function_definition identifier parameters identifier identifier identifier identifier identifier identifier identifier identifier identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end expression_statement assignment identifier dictionary pair string string_start string_content string_end call identifier argument_list pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end identifier pair string string_start string_content string_end dictionary pair string string_start string_content string_end none pair string string_start string_content string_end none pair string string_start string_content string_end none 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 pair string string_start string_content string_end identifier if_statement boolean_operator identifier comparison_operator identifier identifier block expression_statement assignment pattern_list identifier identifier identifier call identifier argument_list expression_statement call attribute identifier identifier argument_list dictionary pair string string_start string_content string_end dictionary pair string string_start string_content string_end call attribute identifier identifier argument_list pair string string_start string_content string_end call attribute identifier identifier argument_list pair string string_start string_content string_end call attribute identifier identifier argument_list expression_statement assignment identifier call attribute identifier identifier argument_list identifier keyword_argument identifier integer keyword_argument identifier true if_statement call identifier argument_list block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier expression_statement assignment identifier call attribute attribute identifier identifier identifier argument_list identifier identifier with_statement with_clause with_item as_pattern call identifier argument_list identifier string string_start string_content string_end as_pattern_target identifier block expression_statement call attribute identifier identifier argument_list string string_start string_content string_end identifier expression_statement call attribute identifier identifier argument_list identifier
Generate a metadata file for the package.