code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def _sanitise(self): for k in self.__dict__: if isinstance(self.__dict__[k], np.float32): self.__dict__[k] = np.float64(self.__dict__[k])
Convert attributes of type npumpy.float32 to numpy.float64 so that they will print properly.
def format(tokens, formatter, outfile=None): try: if not outfile: realoutfile = getattr(formatter, 'encoding', None) and BytesIO() or StringIO() formatter.format(tokens, realoutfile) return realoutfile.getvalue() else: formatter.format(tokens, outfile)...
Format a tokenlist ``tokens`` with the formatter ``formatter``. If ``outfile`` is given and a valid file object (an object with a ``write`` method), the result will be written to it, otherwise it is returned as a string.
def watch_project(self, path): try: return self.client.query('watch-project', os.path.realpath(path)) finally: self._attempt_set_timeout(self._timeout)
Issues the watch-project command to watchman to begin watching the buildroot. :param string path: the path to the watchman project root/pants build root.
def _set_fields(self, json_dict): for key, value in json_dict.items(): if not key.startswith("_"): setattr(self, key, value)
Set this object's attributes specified in json_dict
def header_expand(headers): collector = [] if isinstance(headers, dict): headers = headers.items() elif isinstance(headers, basestring): return headers for i, (value, params) in enumerate(headers): _params = [] for (p_k, p_v) in params.items(): _params.append(...
Returns an HTTP Header value string from a dictionary. Example expansion:: {'text/x-dvi': {'q': '.8', 'mxb': '100000', 'mxt': '5.0'}, 'text/x-c': {}} # Accept: text/x-dvi; q=.8; mxb=100000; mxt=5.0, text/x-c (('text/x-dvi', {'q': '.8', 'mxb': '100000', 'mxt': '5.0'}), ('text/x-c', {})) ...
def is_time_variable(varname, var): satisfied = varname.lower() == 'time' satisfied |= getattr(var, 'standard_name', '') == 'time' satisfied |= getattr(var, 'axis', '') == 'T' satisfied |= units_convertible('seconds since 1900-01-01', getattr(var, 'units', '')) return satisfied
Identifies if a variable is represents time
def lookup(self, profile, setting): for path in profiles(): cfg = SafeConfigParser() cfg.read(path) if profile not in cfg.sections(): continue if not cfg.has_option(profile, setting): continue return cfg.get(profile, set...
Check koji.conf.d files for this profile's setting. :param setting: ``str`` like "server" (for kojihub) or "weburl" :returns: ``str``, value for this setting
def patch(self, spin, header, *args): spawn(spin, 'DCC %s' % args[0], header, *args[1:])
It spawns DCC TYPE as event.
def _GetGdbThreadMapping(self, position): if len(gdb.selected_inferior().threads()) == 1: return {position[1]: 1} thread_line_regexp = r'\s*\**\s*([0-9]+)\s+[a-zA-Z]+\s+([x0-9a-fA-F]+)\s.*' output = gdb.execute('info threads', to_string=True) matches = [re.match(thread_line_regexp, line) for line ...
Gets a mapping from python tid to gdb thread num. There's no way to get the thread ident from a gdb thread. We only get the "ID of the thread, as assigned by GDB", which is completely useless for everything except talking to gdb. So in order to translate between these two, we have to execute 'info th...
def open(self, options): if self.opened: return self.opened = True log.debug('%s, including location="%s"', self.id, self.location) result = self.download(options) log.debug('included:\n%s', result) return result
Open and include the refrenced schema. @param options: An options dictionary. @type options: L{options.Options} @return: The referenced schema. @rtype: L{Schema}
def parse_negation_operation(operation: str) -> Tuple[bool, str]: _operation = operation.strip() if not _operation: raise QueryParserException('Operation is not valid: {}'.format(operation)) negation = False if _operation[0] == '~': negation = True _operation = _operation[1:] ...
Parse the negation modifier in an operation.
def make_job(job_name, **kwargs): def wraps(func): kwargs['process'] = func job = type(job_name, (Job,), kwargs) globals()[job_name] = job return job return wraps
Decorator to create a Job from a function. Give a job name and add extra fields to the job. @make_job("ExecuteDecJob", command=mongoengine.StringField(required=True), output=mongoengine.StringField(default=None)) def execute(job: Job): job.log_info('E...
def _property_set(self, msg): prop = self._sent_property.get('prop') if prop and hasattr(self, prop): setattr(self, prop, self._sent_property.get('val')) self._sent_property = {}
Set command received and acknowledged.
def label_clusters(image, min_cluster_size=50, min_thresh=1e-6, max_thresh=1, fully_connected=False): dim = image.dimension clust = threshold_image(image, min_thresh, max_thresh) temp = int(fully_connected) args = [dim, clust, clust, min_cluster_size, temp] processed_args = _int_antsProcessArguments...
This will give a unique ID to each connected component 1 through N of size > min_cluster_size ANTsR function: `labelClusters` Arguments --------- image : ANTsImage input image e.g. a statistical map min_cluster_size : integer throw away clusters smaller than this value...
def split_by_fname_file(self, fname:PathOrStr, path:PathOrStr=None)->'ItemLists': "Split the data by using the names in `fname` for the validation set. `path` will override `self.path`." path = Path(ifnone(path, self.path)) valid_names = loadtxt_str(path/fname) return self.split_by_files...
Split the data by using the names in `fname` for the validation set. `path` will override `self.path`.
def update_status(self, status): assert (status in (HightonConstants.WON, HightonConstants.PENDING, HightonConstants.LOST)) from highton.models import Status status_obj = Status(name=status) return self._put_request( data=status_obj.element_to_string(status_obj.encode()), ...
Updates the status of the deal :param status: status have to be ('won', 'pending', 'lost') :return: successfull response or raise Exception :rtype:
def process_resource(self, req, resp, resource, uri_kwargs=None): if 'user' in req.context: return identifier = self.identify(req, resp, resource, uri_kwargs) user = self.try_storage(identifier, req, resp, resource, uri_kwargs) if user is not None: req.context['us...
Process resource after routing to it. This is basic falcon middleware handler. Args: req (falcon.Request): request object resp (falcon.Response): response object resource (object): resource object matched by falcon router uri_kwargs (dict): additional ke...
def doit(self, classes=None, recursive=True, **kwargs): return super().doit(classes, recursive, **kwargs)
Write out commutator Write out the commutator according to its definition $[\Op{A}, \Op{B}] = \Op{A}\Op{B} - \Op{A}\Op{B}$. See :meth:`.Expression.doit`.
def _my_pdf_formatter(data, format, ordered_alphabets) : eps = _my_eps_formatter(data, format, ordered_alphabets).decode() gs = weblogolib.GhostscriptAPI() return gs.convert('pdf', eps, format.logo_width, format.logo_height)
Generate a logo in PDF format. Modified from weblogo version 3.4 source code.
def pop(self, name, default=SENTINEL): if default is SENTINEL: return self.__data__.pop(name) return self.__data__.pop(name, default)
Retrieve and remove a value from the backing store, optionally with a default.
def spawn_isolated_child(econtext): mitogen.parent.upgrade_router(econtext) if FORK_SUPPORTED: context = econtext.router.fork() else: context = econtext.router.local() LOG.debug('create_fork_child() -> %r', context) return context
For helper functions executed in the fork parent context, arrange for the context's router to be upgraded as necessary and for a new child to be prepared. The actual fork occurs from the 'virginal fork parent', which does not have any Ansible modules loaded prior to fork, to avoid conflicts resulting f...
def tic(self): if self.step % self.interval == 0: for exe in self.exes: for array in exe.arg_arrays: array.wait_to_read() for array in exe.aux_arrays: array.wait_to_read() self.queue = [] self.activated =...
Start collecting stats for current batch. Call before calling forward.
def _stripe_object_field_to_foreign_key( cls, field, manipulated_data, current_ids=None, pending_relations=None ): field_data = None field_name = field.name raw_field_data = manipulated_data.get(field_name) refetch = False skip = False if issubclass(field.related_model, StripeModel): id_ = cls._id_fro...
This converts a stripe API field to the dj stripe object it references, so that foreign keys can be connected up automatically. :param field: :type field: models.ForeignKey :param manipulated_data: :type manipulated_data: dict :param current_ids: stripe ids of objects that are currently being processed :...
def pandas_dtype(dtype): if isinstance(dtype, np.ndarray): return dtype.dtype elif isinstance(dtype, (np.dtype, PandasExtensionDtype, ExtensionDtype)): return dtype result = registry.find(dtype) if result is not None: return result try: npdtype = np.dtype(dtype) e...
Convert input into a pandas only dtype object or a numpy dtype object. Parameters ---------- dtype : object to be converted Returns ------- np.dtype or a pandas dtype Raises ------ TypeError if not a dtype
def echo_via_pager(*args, **kwargs): try: restore = 'LESS' not in os.environ os.environ.setdefault('LESS', '-iXFR') click.echo_via_pager(*args, **kwargs) finally: if restore: os.environ.pop('LESS', None)
Display pager only if it does not fit in one terminal screen. NOTE: The feature is available only on ``less``-based pager.
def _find_feed_language(self): self.feed_language = ( read_first_available_value( os.path.join(self.src_dir, 'feed_info.txt'), 'feed_lang') or read_first_available_value( os.path.join(self.src_dir, 'agency.txt'), 'agency_lang')) if not self.feed_la...
Find feed language based specified feed_info.txt or agency.txt.
def _merge_csv_section(sections, pc, csvs): logger_csvs.info("enter merge_csv_section") try: for _name, _section in sections.items(): if "measurementTable" in _section: sections[_name]["measurementTable"] = _merge_csv_table(_section["measurementTable"], pc, csvs) ...
Add csv data to all paleo data tables :param dict sections: Metadata :return dict sections: Metadata
def stop_loop(self): hub.kill(self._querier_thread) self._querier_thread = None self._datapath = None self.logger.info("stopped a querier.")
stop QUERY thread.
def make(cls, **kwargs): cls_attrs = {f.name: f for f in attr.fields(cls)} unknown = {k: v for k, v in kwargs.items() if k not in cls_attrs} if len(unknown) > 0: _LOGGER.warning( "Got unknowns for %s: %s - please create an issue!", cls.__name__, unknown ) missing = [k for k i...
Create a container. Reports extra keys as well as missing ones. Thanks to habnabit for the idea!
def overlaps(self, other): if self > other: smaller, larger = other, self else: smaller, larger = self, other if larger.empty(): return False if smaller._upper_value == larger._lower_value: return smaller._upper == smaller.CLOSED and larger...
If self and other have any overlapping values returns True, otherwise returns False
def resolveSharedConnections(root: LNode): for ch in root.children: resolveSharedConnections(ch) for ch in root.children: for p in ch.iterPorts(): portTryReduce(root, p)
Walk all ports on all nodes and group subinterface connections to only parent interface connection if it is possible
def _set_body(self, body): assert isinstance(body, CodeStatement) if isinstance(body, CodeBlock): self.body = body else: self.body._add(body)
Set the main body for this control flow structure.
def show(dataset_uri, overlay_name): dataset = dtoolcore.DataSet.from_uri(dataset_uri) try: overlay = dataset.get_overlay(overlay_name) except: click.secho( "No such overlay: {}".format(overlay_name), fg="red", err=True ) sys.exit(11) f...
Show the content of a specific overlay.
def query(self, transport, protocol, *data): if not self._query: raise AttributeError('Command is not queryable') if self.protocol: protocol = self.protocol if self._query.data_type: data = _dump(self._query.data_type, data) else: data = ()...
Generates and sends a query message unit. :param transport: An object implementing the `.Transport` interface. It is used by the protocol to send the message and receive the response. :param protocol: An object implementing the `.Protocol` interface. :param data: The pro...
def _find_stages(self): stages = [] end = last_user_found = None for part in reversed(self.dfp.structure): if end is None: end = part if part['instruction'] == 'USER' and not last_user_found: last_user_found = part['content'] if...
Find limits of each Dockerfile stage
def giant_text_sqltype(dialect: Dialect) -> str: if dialect.name == SqlaDialectName.SQLSERVER: return 'NVARCHAR(MAX)' elif dialect.name == SqlaDialectName.MYSQL: return 'LONGTEXT' else: raise ValueError("Unknown dialect: {}".format(dialect.name))
Returns the SQL column type used to make very large text columns for a given dialect. Args: dialect: a SQLAlchemy :class:`Dialect` Returns: the SQL data type of "giant text", typically 'LONGTEXT' for MySQL and 'NVARCHAR(MAX)' for SQL Server.
def write_rst(self, prefix: str = "", suffix: str = "", heading_underline_char: str = "=", method: AutodocMethod = None, overwrite: bool = False, mock: bool = False) -> None: content = self.rst_content( ...
Writes the RST file to our destination RST filename, making any necessary directories. Args: prefix: as for :func:`rst_content` suffix: as for :func:`rst_content` heading_underline_char: as for :func:`rst_content` method: as for :func:`rst_content` ...
def callback_result(self): if self._state in [PENDING, RUNNING]: self.x if self._user_callbacks: return self._callback_result else: return self.x
Block the main thead until future finish, return the future.callback_result.
def validate_no_duplicate_paths(self, resources): paths = set() for item in resources: file_name = item.get('path') if file_name in paths: raise ValueError( '%s path was specified more than once in the metadata' % file_name)...
ensure that the user has not provided duplicate paths in a list of resources. Parameters ========== resources: one or more resources to validate not duplicated
def getRoom(self, _id): if SockJSRoomHandler._room.has_key(self._gcls() + _id): return SockJSRoomHandler._room[self._gcls() + _id] return None
Retrieve a room from it's id
def transpose(self): graph = self.graph transposed = DAG() for node, edges in graph.items(): transposed.add_node(node) for node, edges in graph.items(): for edge in edges: transposed.add_edge(edge, node) return transposed
Builds a new graph with the edges reversed. Returns: :class:`stacker.dag.DAG`: The transposed graph.
def cv(params, dtrain, num_boost_round=10, nfold=3, metrics=(), obj=None, feval=None, fpreproc=None, as_pandas=True, show_progress=None, show_stdv=True, seed=0): results = [] cvfolds = mknfold(dtrain, nfold, params, seed, metrics, fpreproc) for i in range(num_boost_round): for fold in ...
Cross-validation with given paramaters. Parameters ---------- params : dict Booster params. dtrain : DMatrix Data to be trained. num_boost_round : int Number of boosting iterations. nfold : int Number of folds in CV. metrics : list of strings Evaluati...
def iter_options(self): for section in self.sections: name = str(section) for key, value in section._get_options(): yield name, key, value
Iterates configuration sections groups options.
def run_preassembly_duplicate(preassembler, beliefengine, **kwargs): logger.info('Combining duplicates on %d statements...' % len(preassembler.stmts)) dump_pkl = kwargs.get('save') stmts_out = preassembler.combine_duplicates() beliefengine.set_prior_probs(stmts_out) logger.info('%d u...
Run deduplication stage of preassembly on a list of statements. Parameters ---------- preassembler : indra.preassembler.Preassembler A Preassembler instance beliefengine : indra.belief.BeliefEngine A BeliefEngine instance. save : Optional[str] The name of a pickle file to sa...
def order_derived_parameters(component): if len(component.derived_parameters) == 0: return [] ordering = [] dps = [] for dp in component.derived_parameters: dps.append(dp.name) maxcount = 5 count = maxcount while count > 0 and dps != []: count = count - 1 for ...
Finds ordering of derived_parameters. @param component: Component containing derived parameters. @type component: lems.model.component.Component @return: Returns ordered list of derived parameters. @rtype: list(string) @raise SimBuildError: Raised when a proper ordering of derived parameters ...
def main(): tar_file = TMPDIR + '/' + BINARY_URL.split('/')[-1] chksum = TMPDIR + '/' + MD5_URL.split('/')[-1] if precheck() and os_packages(distro.linux_distribution()): stdout_message('begin download') download() stdout_message('begin valid_checksum') valid_checksum(tar_fil...
Check Dependencies, download files, integrity check
def codingthreads(self): printtime('Extracting CDS features', self.start) for i in range(self.cpus): threads = Thread(target=self.codingsequences, args=()) threads.setDaemon(True) threads.start() for sample in self.runmetadata.samples: self.codingq...
Find CDS features in .gff files to filter out non-coding sequences from the analysis
def document(self): doc = {'mode': self.__mongos_mode} if self.__tag_sets not in (None, [{}]): doc['tags'] = self.__tag_sets if self.__max_staleness != -1: doc['maxStalenessSeconds'] = self.__max_staleness return doc
Read preference as a document.
def _prepare_data_dir(self, data): logger.debug(__("Preparing data directory for Data with id {}.", data.id)) with transaction.atomic(): temporary_location_string = uuid.uuid4().hex[:10] data_location = DataLocation.objects.create(subpath=temporary_location_string) da...
Prepare destination directory where the data will live. :param data: The :class:`~resolwe.flow.models.Data` object for which to prepare the private execution directory. :return: The prepared data directory path. :rtype: str
def orbit(self, x1_px, y1_px, x2_px, y2_px): px_per_deg = self.vport_radius_px / float(self.orbit_speed) radians_per_px = 1.0 / px_per_deg * np.pi / 180.0 t2p = self.position - self.target M = Matrix4x4.rotation_around_origin((x1_px - x2_px) * radians_per_px, ...
Causes the camera to "orbit" around the target point. This is also called "tumbling" in some software packages.
def toggle(self): for device in self: if isinstance(device, (OutputDevice, CompositeOutputDevice)): device.toggle()
Toggle all the output devices. For each device, if it's on, turn it off; if it's off, turn it on.
def set_data(self, pos=None, color=None, width=None, connect=None): if pos is not None: self._bounds = None self._pos = pos self._changed['pos'] = True if color is not None: self._color = color self._changed['color'] = True if width is ...
Set the data used to draw this visual. Parameters ---------- pos : array Array of shape (..., 2) or (..., 3) specifying vertex coordinates. color : Color, tuple, or array The color to use when drawing the line. If an array is given, it must be of shap...
def c2r(self): return matrix(a=self.tt.__complex_op('M'), n=_np.concatenate( (self.n, [2])), m=_np.concatenate((self.m, [2])))
Get real matrix from complex one suitable for solving complex linear system with real solver. For matrix :math:`M(i_1,j_1,\\ldots,i_d,j_d) = \\Re M + i\\Im M` returns (d+1)-dimensional matrix :math:`\\tilde{M}(i_1,j_1,\\ldots,i_d,j_d,i_{d+1},j_{d+1})` of form :math:`\\begin{bmatrix}\\Re M & -\\...
def contains_duplicates(values: Iterable[Any]) -> bool: for v in Counter(values).values(): if v > 1: return True return False
Does the iterable contain any duplicate values?
def flatten_check(out:Tensor, targ:Tensor) -> Tensor: "Check that `out` and `targ` have the same number of elements and flatten them." out,targ = out.contiguous().view(-1),targ.contiguous().view(-1) assert len(out) == len(targ), f"Expected output and target to have the same number of elements but got {len(o...
Check that `out` and `targ` have the same number of elements and flatten them.
def secgroup_info(call=None, kwargs=None): if call != 'function': raise SaltCloudSystemExit( 'The secgroup_info function must be called with -f or --function.' ) if kwargs is None: kwargs = {} name = kwargs.get('name', None) secgroup_id = kwargs.get('secgroup_id', Non...
Retrieves information for the given security group. Either a name or a secgroup_id must be supplied. .. versionadded:: 2016.3.0 name The name of the security group for which to gather information. Can be used instead of ``secgroup_id``. secgroup_id The ID of the security group...
def resize(att_mat, max_length=None): for i, att in enumerate(att_mat): if att.ndim == 3: att = np.expand_dims(att, axis=0) if max_length is not None: att = att[:, :, :max_length, :max_length] row_sums = np.sum(att, axis=2) att /= row_sums[:, :, np.newaxis] att_mat[i] = att retur...
Normalize attention matrices and reshape as necessary.
def clean(self, elements): cleanelements = [] for i in xrange(len(elements)): if isempty(elements[i]): return [] next = elements[i] if isinstance(elements[i], (list, tuple)): next = self.clean(elements[i]) if next: cleanelements.append(elements[i]) return cleanelements
Removes empty or incomplete answers.
def ENUM(self, _cursor_type): _decl = _cursor_type.get_declaration() name = self.get_unique_name(_decl) if self.is_registered(name): obj = self.get_registered(name) else: log.warning('Was in ENUM but had to parse record declaration ') obj = self.parse_...
Handles ENUM typedef.
def query_by_assignment(self, assignment_id, end_time=None, start_time=None): path = {} data = {} params = {} path["assignment_id"] = assignment_id if start_time is not None: params["start_time"] = start_time if end_time is not None: params...
Query by assignment. List grade change events for a given assignment.
def construct_sls_str(self, node): obj = self.construct_scalar(node) if six.PY2: obj = obj.encode('utf-8') return SLSString(obj)
Build the SLSString.
def ignore_nan_inf(kde_method): def new_kde_method(events_x, events_y, xout=None, yout=None, *args, **kwargs): bad_in = get_bad_vals(events_x, events_y) if xout is None: density = np.zeros_like(events_x, dtype=float) bad_out = bad_in xo = yo...
Ignores nans and infs from the input data Invalid positions in the resulting density are set to nan.
def emit(self, record): if self.triggerLevelNo is not None and record.levelno>=self.triggerLevelNo: self.triggered = True logging.handlers.BufferingHandler.emit(self,record)
Emit record after checking if message triggers later sending of e-mail.
def export_to_json(self): return { hostname: sorted(self._encode_key(key) for key in pins) for hostname, pins in self._storage.items() }
Return a JSON dictionary which contains all the pins stored in this store.
def cd(path_to): if path_to == '-': if not cd.previous: raise PathError('No previous directory to return to') return cd(cd.previous) if not hasattr(path_to, 'cd'): path_to = makepath(path_to) try: previous = os.getcwd() except OSError as e: if 'No such...
cd to the given path If the path is a file, then cd to its parent directory Remember current directory before the cd so that we can cd back there with cd('-')
def get_inline_expression(self, text): text = text.strip() if not text.startswith(self.inline_tags[0]) or not text.endswith(self.inline_tags[1]): return return text[2:-2]
Extract an inline expression from the given text.
def clean_zeros(a, b, M): M2 = M[a > 0, :][:, b > 0].copy() a2 = a[a > 0] b2 = b[b > 0] return a2, b2, M2
Remove all components with zeros weights in a and b
def findLeftBrace(self, block, column): block, column = self.findBracketBackward(block, column, '{') try: block, column = self.tryParenthesisBeforeBrace(block, column) except ValueError: pass return self._blockIndent(block)
Search for a corresponding '{' and return its indentation If not found return None
def peek_string(self, lpBaseAddress, fUnicode = False, dwMaxSize = 0x1000): if not lpBaseAddress or dwMaxSize == 0: if fUnicode: return u'' return '' if not dwMaxSize: dwMaxSize = 0x1000 szString = self.peek(lpBaseAddress, dwMaxSize) if...
Tries to read an ASCII or Unicode string from the address space of the process. @see: L{read_string} @type lpBaseAddress: int @param lpBaseAddress: Memory address to begin reading. @type fUnicode: bool @param fUnicode: C{True} is the string is expected to be Unicode,...
def get_library_name(): from os.path import split, abspath __lib_name = split(split(abspath(sys.modules[__name__].__file__))[0])[1] assert __lib_name in ["sframe", "turicreate"] return __lib_name
Returns either sframe or turicreate depending on which library this file is bundled with.
def save(self, obj, id_code): filestream = open('{0}/{1}'.format(self.data_path, id_code), 'w+') pickle.dump(obj, filestream) filestream.close()
Save an object, and use id_code in the filename obj - any object id_code - unique identifier
def _get_body(self): " Return the Container object for the current CLI. " new_hash = self.pymux.arrangement.invalidation_hash() app = get_app() if app in self._bodies_for_app: existing_hash, container = self._bodies_for_app[app] if existing_hash == new_hash: ...
Return the Container object for the current CLI.
def _apply_task(task: Task, args: Tuple, kwargs: Dict[str, Any]) -> Any: if args is None: args = () if kwargs is None: kwargs = {} start = monotonic() try: return task.apply(*args, **kwargs) finally: delta = monotonic() - start ...
Logs the time spent while running the task.
def GetDefault(self, fd=None, default=None): if callable(self.default): return self.default(fd) if self.default is not None: if isinstance(self.default, rdfvalue.RDFValue): default = self.default.Copy() default.attribute_instance = self return self(default) else: ...
Returns a default attribute if it is not set.
def _exception_free_callback(self, callback, *args, **kwargs): try: return callback(*args, **kwargs) except Exception: self._logger.exception("An exception occurred while calling a hook! ",exc_info=True) return None
A wrapper that remove all exceptions raised from hooks
def to_dict(self, xml): children = list(xml) if not children: return xml.text else: out = {} for node in list(xml): if node.tag in out: if not isinstance(out[node.tag], list): out[node.tag] = [out[nod...
Convert XML structure to dict recursively, repeated keys entries are returned as in list containers.
def copy_shell(self): cls = self.__class__ new_i = cls() new_i.uuid = self.uuid for prop in cls.properties: if hasattr(self, prop): if prop in ['members', 'unknown_members']: setattr(new_i, prop, []) else: ...
Copy the group properties EXCEPT the members. Members need to be filled after manually :return: Itemgroup object :rtype: alignak.objects.itemgroup.Itemgroup :return: None
def timed_call(self, ms, callback, *args, **kwargs): return self.loop.timed_call(ms, callback, *args, **kwargs)
Invoke a callable on the main event loop thread at a specified time in the future. Parameters ---------- ms : int The time to delay, in milliseconds, before executing the callable. callback : callable The callable object to execute at some po...
def doUpdate(self, timeout=1): namespace = Fritz.getServiceType("doUpdate") uri = self.getControlURL(namespace) results = self.execute(uri, namespace, "X_AVM-DE_DoUpdate", timeout=timeout) return results["NewUpgradeAvailable"], results["NewX_AVM-DE_UpdateState"]
Do a software update of the Fritz Box if available. :param float timeout: the timeout to wait for the action to be executed :return: a list of if an update was available and the update state (bool, str) :rtype: tuple(bool, str)
def get_version(path="src/devpy/__init__.py"): init_content = open(path, "rt").read() pattern = r"^__version__ = ['\"]([^'\"]*)['\"]" return re.search(pattern, init_content, re.M).group(1)
Return the version of by with regex intead of importing it
def qd2apex(self, qlat, qlon, height): alat, alon = self._qd2apex(qlat, qlon, height) return np.float64(alat), np.float64(alon)
Converts quasi-dipole to modified apex coordinates. Parameters ========== qlat : array_like Quasi-dipole latitude qlon : array_like Quasi-dipole longitude height : array_like Altitude in km Returns ======= alat : ndarr...
def db_for_read(self, model, **hints): if model._meta.app_label in self._apps: return getattr(model, '_db_alias', model._meta.app_label) return None
If the app has its own database, use it for reads
def _fill_vao(self): with self.vao: self.vbos = [] for loc, verts in enumerate(self.arrays): vbo = VBO(verts) self.vbos.append(vbo) self.vao.assign_vertex_attrib_location(vbo, loc)
Put array location in VAO for shader in same order as arrays given to Mesh.
def configure_urls(apps, index_view=None, prefixes=None): prefixes = prefixes or {} urlpatterns = patterns('') if index_view: from django.views.generic.base import RedirectView urlpatterns += patterns('', url(r'^$', RedirectView.as_view(pattern_name=index_view, permanent=False)),...
Configure urls from a list of apps.
def get_proficiency_search_session(self, proxy): if not self.supports_proficiency_search(): raise Unimplemented() try: from . import sessions except ImportError: raise OperationFailed() proxy = self._convert_proxy(proxy) try: sessio...
Gets the ``OsidSession`` associated with the proficiency search service. :param proxy: a proxy :type proxy: ``osid.proxy.Proxy`` :return: a ``ProficiencySearchSession`` :rtype: ``osid.learning.ProficiencySearchSession`` :raise: ``NullArgument`` -- ``proxy`` is ``null`` :...
def popenCLIExecutable(command, **kwargs): cliExecutable = command[0] ma = re_slicerSubPath.search(cliExecutable) if ma: wrapper = os.path.join(cliExecutable[:ma.start()], 'Slicer') if sys.platform.startswith('win'): wrapper += '.exe' if os.path.exists(wrapper): ...
Wrapper around subprocess.Popen constructor that tries to detect Slicer CLI modules and launches them through the Slicer launcher in order to prevent potential DLL dependency issues. Any kwargs are passed on to subprocess.Popen(). If you ever try to use this function to run a CLI, you might want to ...
def _integer_to_interval(arg, unit='s'): op = ops.IntervalFromInteger(arg, unit) return op.to_expr()
Convert integer interval with the same inner type Parameters ---------- unit : {'Y', 'M', 'W', 'D', 'h', 'm', s', 'ms', 'us', 'ns'} Returns ------- interval : interval value expression
def _plot(self): for serie in self.series[::-1 if self.stack_from_top else 1]: self.bar(serie) for serie in self.secondary_series[::-1 if self.stack_from_top else 1]: self.bar(serie, True)
Draw bars for series and secondary series
def stopDtmfAcknowledge(): a = TpPd(pd=0x3) b = MessageType(mesType=0x32) packet = a / b return packet
STOP DTMF ACKNOWLEDGE Section 9.3.30
def create_model(schema, collection, class_name=None): if not class_name: class_name = camelize(str(collection.name)) model_class = type(class_name, (Model,), dict(schema=schema, _collection_factory=staticmethod(lambda: collection))) model_class.__module...
Main entry point to creating a new mongothon model. Both schema and Pymongo collection objects must be provided. Returns a new class which can be used as a model class. The class name of the model class by default is inferred from the provided collection (converted to camel case). Optionally, a cl...
def is_applicable_python_file(rel_path: str) -> bool: return (rel_path.endswith('.py') and not any(re.search(pat, rel_path) for pat in IGNORED_FILE_PATTERNS))
Determines if a file should be included in incremental coverage analysis. Args: rel_path: The repo-relative file path being considered. Returns: Whether to include the file.
def add_general_optgroup(parser): g = parser.add_argument_group("General Options") g.add_argument("-q", "--quiet", dest="silent", action="store_true", default=False) g.add_argument("-v", "--verbose", nargs=0, action=_opt_cb_verbose) g.add_argument("-o", "--output", dest="output", defa...
option group for general-use features of all javatool CLIs
def RegisterMountPoint(cls, mount_point, path_spec): if mount_point in cls._mount_points: raise KeyError('Mount point: {0:s} already set.'.format(mount_point)) cls._mount_points[mount_point] = path_spec
Registers a path specification mount point. Args: mount_point (str): mount point identifier. path_spec (PathSpec): path specification of the mount point. Raises: KeyError: if the corresponding mount point is already set.
def objref(obj): ref = _objrefs.get(obj) if ref is None: clsname = obj.__class__.__name__.split('.')[-1] seqno = _lastids.setdefault(clsname, 1) ref = '{}-{}'.format(clsname, seqno) _objrefs[obj] = ref _lastids[clsname] += 1 return ref
Return a string that uniquely and compactly identifies an object.
def _get_norms_of_rows(data_frame, method): if method == 'vector': norm_vector = np.linalg.norm(data_frame.values, axis=1) elif method == 'last': norm_vector = data_frame.iloc[:, -1].values elif method == 'mean': norm_vector = np.mean(data_frame.values, axis=1) elif method == 'fi...
return a column vector containing the norm of each row
def date_sorted_sources(*sources): sorted_stream = heapq.merge(*(_decorate_source(s) for s in sources)) for _, message in sorted_stream: yield message
Takes an iterable of sources, generating namestrings and piping their output into date_sort.
def edit(self, billing_email=None, company=None, email=None, location=None, name=None): json = None data = {'billing_email': billing_email, 'company': company, 'email': email, 'location': location, 'name': name} sel...
Edit this organization. :param str billing_email: (optional) Billing email address (private) :param str company: (optional) :param str email: (optional) Public email address :param str location: (optional) :param str name: (optional) :returns: bool
def compression_details(self): event_type = self.findtext("event_type") if event_type != "compression": raise AttributeError( 'PREMIS events of type "{}" have no compression' " details".format(event_type) ) parsed_compression_event_detail =...
Return as a 3-tuple, this PREMIS compression event's program, version, and algorithm used to perform the compression.
def remove_redis_keyword(self, keyword): redisvr.srem(CMS_CFG['redis_kw'] + self.userinfo.user_name, keyword) return json.dump({}, self)
Remove the keyword for redis.
def open(self, target_uri, **kwargs): target = urlsplit(target_uri, scheme=self.default_opener) opener = self.get_opener(target.scheme) query = opener.conform_query(target.query) target = opener.get_target( target.scheme, target.path, target.fragment, ...
Open target uri. :param target_uri: Uri to open :type target_uri: string :returns: Target object