code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def load(self, filename): if not os.path.exists(filename): raise AppConfigValueException('Could not load config file {0}'. format(filename)) cfl = open(filename, 'r') if PY2: self.readfp(cfl) else: self.read_file(cfl) cfl.cl...
Load the given config file. @param filename: the filename including the path to load.
def to_json(self, propval, extraneous=False, to_json_func=None): if self.json_out: return self.json_out(propval) else: if not to_json_func: from normalize.record.json import to_json to_json_func = to_json return to_json_func(propval, ex...
This function calls the ``json_out`` function, if it was specified, otherwise continues with JSON conversion of the value in the slot by calling ``to_json_func`` on it.
def _get_image_size(self, maxcharno, maxlineno): return (self._get_char_x(maxcharno) + self.image_pad, self._get_line_y(maxlineno + 0) + self.image_pad)
Get the required image size.
def init_kerberos(app, service='HTTP', hostname=gethostname()): global _SERVICE_NAME _SERVICE_NAME = "%s@%s" % (service, hostname) if 'KRB5_KTNAME' not in environ: app.logger.warn("Kerberos: set KRB5_KTNAME to your keytab file") else: try: principal = kerberos.getServerPrinci...
Configure the GSSAPI service name, and validate the presence of the appropriate principal in the kerberos keytab. :param app: a flask application :type app: flask.Flask :param service: GSSAPI service name :type service: str :param hostname: hostname the service runs under :type hostname: st...
def setRemoveAction(self, action): if action not in ('unset', 'delete'): raise orb.errors.ValidationError('The remove action must be either "unset" or "delete"') else: self.__removeAction = action
Sets the remove action that should be taken when a model is removed from the collection generated by this reverse lookup. Valid actions are "unset" or "delete", any other values will raise an exception. :param action: <str>
def clear_cache(cls): for key in cls._cached: cls._cached[key] = None cls._cached = {}
Call this before closing tk root
def set_option(self, optionname, value): for name, parms in zip(self.opt_names, self.opt_parms): if name == optionname: defaulttype = type(parms['enabled']) if defaulttype != type(value) and defaulttype != type(None): value = (defaulttype)(value) ...
Set the named option to value. Ensure the original type of the option value is preserved.
def request_syncmodule(blink, network): url = "{}/network/{}/syncmodules".format(blink.urls.base_url, network) return http_get(blink, url)
Request sync module info. :param blink: Blink instance. :param network: Sync module network id.
def markdown_media_css(): return dict( CSS_SET=posixpath.join( settings.MARKDOWN_SET_PATH, settings.MARKDOWN_SET_NAME, 'style.css' ), CSS_SKIN=posixpath.join( 'django_markdown', 'skins', settings.MARKDOWN_EDITOR_SKIN, 'style.css' ) )
Add css requirements to HTML. :returns: Editor template context.
def get_pages(url): while True: yield url doc = html.parse(url).find("body") links = [a for a in doc.findall(".//a") if a.text and a.text.startswith("next ")] if not links: break url = urljoin(url, links[0].get('href'))
Return the 'pages' from the starting url Technically, look for the 'next 50' link, yield and download it, repeat
def start(self): logger.info("starting process") process = os.fork() time.sleep(0.01) if process != 0: logger.debug('starting child watcher') self.loop.reset() self.child_pid = process self.watcher = pyev.Child(self.child_pid, False, self.l...
Start the process, essentially forks and calls target function.
def find_deck(provider: Provider, key: str, version: int, prod: bool=True) -> Optional[Deck]: pa_params = param_query(provider.network) if prod: p2th = pa_params.P2TH_addr else: p2th = pa_params.test_P2TH_addr rawtx = provider.getrawtransaction(key, 1) deck = deck_parser((provider, r...
Find specific deck by deck id.
def generate(self, path, label): for filename in os.listdir(path): self[filename] = label
Creates default data from the corpus at `path`, marking all works with `label`. :param path: path to a corpus directory :type path: `str` :param label: label to categorise each work as :type label: `str`
def get_event(self, block=True, timeout=None): try: return self._events.get(block, timeout) except Empty: return None
Get the next event from the queue. :arg boolean block: Set to True to block if no event is available. :arg seconds timeout: Timeout to wait if no event is available. :Returns: The next event as a :class:`pygerrit.events.GerritEvent` instance, or `None` if: - `block` is...
def unpackage(package_): return salt.utils.msgpack.loads(package_, use_list=True, _msgpack_module=msgpack)
Unpackages a payload
def initLogging(verbosity=0, name="SCOOP"): global loggingConfig verbose_levels = { -2: "CRITICAL", -1: "ERROR", 0: "WARNING", 1: "INFO", 2: "DEBUG", 3: "DEBUG", 4: "NOSET", } log_handlers = { ...
Creates a logger.
def convert(obj, ids, attr_type, item_func, cdata, parent='root'): LOG.info('Inside convert(). obj type is: "%s", obj="%s"' % (type(obj).__name__, unicode_me(obj))) item_name = item_func(parent) if isinstance(obj, numbers.Number) or type(obj) in (str, unicode): return convert_kv(item_name, obj, attr...
Routes the elements of an object to the right function to convert them based on their data type
def do_format(self, event_iterable): for operation in self.formatter_chain: partial_op = functools.partial(operation, colored=self.colored) event_iterable = imap(partial_op, event_iterable) return event_iterable
Formats the given CloudWatch Logs Event dictionary as necessary and returns an iterable that will return the formatted string. This can be used to parse and format the events based on context ie. In Lambda Function logs, a formatter may wish to color the "ERROR" keywords red, or highlight a filt...
def main_update(self): try: os.nice(1) except AttributeError as er: pass time.sleep(self.refresh) try: while True: timestamp=time.time() self.update() delay=(timestamp+self.refresh)-time.time() if delay > 0: if delay > self.refresh: time.sleep(self.refresh) else: t...
Main function called by the updater thread. Direct call is unnecessary.
def write_sequences_to_fasta(path, seqs): from Bio import SeqIO from Bio.Seq import Seq from Bio.SeqRecord import SeqRecord path = Path(path) records = [] for id, seq in seqs.items(): record = SeqRecord(Seq(seq), id=id, description='') records.append(record) SeqIO.write(recor...
Create a FASTA file listing the given sequences. Arguments ========= path: str or pathlib.Path The name of the file to create. seqs: dict A mapping of names to sequences, which can be either protein or DNA.
def _new_url_record(cls, request: Request) -> URLRecord: url_record = URLRecord() url_record.url = request.url_info.url url_record.status = Status.in_progress url_record.try_count = 0 url_record.level = 0 return url_record
Return new empty URLRecord.
def write(self): self._assure_writable("write") if not self._dirty: return if isinstance(self._file_or_files, (list, tuple)): raise AssertionError("Cannot write back if there is not exactly a single file to write to, have %i files" % len(s...
Write changes to our file, if there are changes at all :raise IOError: if this is a read-only writer instance or if we could not obtain a file lock
def get_account(self, account_id, **kwargs): if 'mask' not in kwargs: kwargs['mask'] = 'status' return self.account.getObject(id=account_id, **kwargs)
Retrieves a CDN account with the specified account ID. :param account_id int: the numeric ID associated with the CDN account. :param dict \\*\\*kwargs: additional arguments to include in the object mask.
def setBreak(self,breakFlag = True): if breakFlag: _parseMethod = self._parse def breaker(instring, loc, doActions=True, callPreParse=True): import pdb pdb.set_trace() _parseMethod( instring, loc, doActions, callPreParse ) break...
Method to invoke the Python pdb debugger when this element is about to be parsed. Set breakFlag to True to enable, False to disable.
def filter_products(self, desired_prods): self.filter_prods = True self.desired_prods = set(desired_prods)
When asked for a product, filter only those on this list.
def _recv_nack(self, method_frame): if self._nack_listener: delivery_tag = method_frame.args.read_longlong() multiple, requeue = method_frame.args.read_bits(2) if multiple: while self._last_ack_id < delivery_tag: self._last_ack_id += 1 ...
Receive a nack from the broker.
def tagged(*tags: Tags) -> Callable: global GREENSIM_TAG_ATTRIBUTE def hook(event: Callable): def wrapper(*args, **kwargs): event(*args, **kwargs) setattr(wrapper, GREENSIM_TAG_ATTRIBUTE, tags) return wrapper return hook
Decorator for adding a label to the process. These labels are applied to any child Processes produced by event
def validate_lun_path(self, host_wwpn, host_port, wwpn, lun): host_wwpn_16 = format(int(host_wwpn, 16), '016x') wwpn_16 = format(int(wwpn, 16), '016x') lun_16 = format(int(lun, 16), '016x') body = { 'host-world-wide-port-name': host_wwpn_16, 'adapter-port-uri': ho...
Validate if an FCP storage volume on an actual storage subsystem is reachable from this CPC, through a specified host port and using a specified host WWPN. This method performs the "Validate LUN Path" HMC operation. If the volume is reachable, the method returns. If the volume is not ...
def create_pgroup_snapshot(self, source, **kwargs): result = self.create_pgroup_snapshots([source], **kwargs) if self._rest_version >= LooseVersion("1.4"): headers = result.headers result = ResponseDict(result[0]) result.headers = headers return result
Create snapshot of pgroup from specified source. :param source: Name of pgroup of which to take snapshot. :type source: str :param \*\*kwargs: See the REST API Guide on your array for the documentation on the request: **POST pgroup** ...
def apply_docstr(docstr_func): def docstr_applier(func): if isinstance(docstr_func, six.string_types): olddoc = meta_util_six.get_funcdoc(func) if olddoc is None: olddoc = '' newdoc = olddoc + docstr_func meta_util_six.set_funcdoc(func, newdoc)...
Changes docstr of one functio to that of another
def confirm_dialog(self, emitter): self.from_fields_to_dict() return super(ProjectConfigurationDialog,self).confirm_dialog(self)
event called pressing on OK button.
def view(self, template_name, kwargs=None): if kwargs is None: kwargs = dict() self.add_('session', self.session) content = self.render_template(template_name, **kwargs) self.write(content)
Used to render template to view Sample usage +++++++++++++ .. code:: python from bast import Controller class MyController(Controller): def index(self): self.view('index.html')
def is_parameter(self): return (isinstance(self.scope, CodeFunction) and self in self.scope.parameters)
Whether this is a function parameter.
def get_content(self, url): cache_path = self._url_to_path(url) try: with open(cache_path, 'rb') as f: return f.read() except IOError: return None
Returns the content of a cached resource. Args: url: The url of the resource Returns: The content of the cached resource or None if not in the cache
def get_host_info(): host_info = {} for k, v in host_info_gatherers.items(): try: host_info[k] = v() except IgnoreHostInfo: pass return host_info
Collect some information about the machine this experiment runs on. Returns ------- dict A dictionary with information about the CPU, the OS and the Python version of this machine.
def get_balance(self): on_date = Datum() on_date.today() return self.get_balance_on(on_date.value)
Current account balance
def _call(self, x, out=None): if out is None: return self.range.element(copy(self.constant)) else: out.assign(self.constant)
Return the constant vector or assign it to ``out``.
def _send_raw_command(ipmicmd, raw_bytes): netfn, command, data = _parse_raw_bytes(raw_bytes) response = ipmicmd.raw_command(netfn, command, data=data) return response
Use IPMI command object to send raw ipmi command to BMC :param ipmicmd: IPMI command object :param raw_bytes: string of hexadecimal values. This is commonly used for certain vendor specific commands. :returns: dict -- The response from IPMI device
def ignore_exceptions(f): @functools.wraps(f) def wrapped(*args, **kwargs): try: return f(*args, **kwargs) except: logging.exception("Ignoring exception in %r", f) return wrapped
Decorator catches and ignores any exceptions raised by this function.
def expand_source_paths(paths): for src_path in paths: if src_path.endswith(('.pyc', '.pyo')): py_path = get_py_path(src_path) if os.path.exists(py_path): src_path = py_path yield src_path
Convert pyc files into their source equivalents.
def link_type(arg_type, arg_name=None, include_bt:bool=True): "Create link to documentation." arg_name = arg_name or fn_name(arg_type) if include_bt: arg_name = code_esc(arg_name) if belongs_to_module(arg_type, 'torch') and ('Tensor' not in arg_name): return f'[{arg_name}]({get_pytorch_link(arg_type)})'...
Create link to documentation.
def gather_meta(self): if not os.path.exists(self.paths["meta"]): return "" meta_dict = utils.yaml_load(self.paths["meta"]) if meta_dict and "dependencies" in meta_dict: dep_list = [] for dependency in meta_dict["dependencies"]: if type(depende...
Return the meta file.
def _enable_thread_pool(func): @functools.wraps(func) def wrapper(*args, **kwargs): self = args[0] if self.enable_thread_pool and hasattr(self, 'thread_pool'): future = self.thread_pool.submit(func, *args, **kwargs) is_async = kwargs.get('is_async') if is_asyn...
Use thread pool for executing a task if self.enable_thread_pool is True. Return an instance of future when flag is_async is True otherwise will to block waiting for the result until timeout then returns the result.
def update(self, friendly_name=values.unset, unique_name=values.unset): return self._proxy.update(friendly_name=friendly_name, unique_name=unique_name, )
Update the FieldTypeInstance :param unicode friendly_name: A string to describe the resource :param unicode unique_name: An application-defined string that uniquely identifies the resource :returns: Updated FieldTypeInstance :rtype: twilio.rest.autopilot.v1.assistant.field_type.FieldTy...
def get_composition_metadata(self): metadata = dict(self._mdata['composition']) metadata.update({'existing_id_values': self._my_map['compositionId']}) return Metadata(**metadata)
Gets the metadata for linking this asset to a composition. return: (osid.Metadata) - metadata for the composition *compliance: mandatory -- This method must be implemented.*
def geodesic(crs, start, end, steps): r import cartopy.crs as ccrs from pyproj import Geod g = Geod(crs.proj4_init) geodesic = np.concatenate([ np.array(start[::-1])[None], np.array(g.npts(start[1], start[0], end[1], end[0], steps - 2)), np.array(end[::-1])[None] ]).trans...
r"""Construct a geodesic path between two points. This function acts as a wrapper for the geodesic construction available in `pyproj`. Parameters ---------- crs: `cartopy.crs` Cartopy Coordinate Reference System to use for the output start: (2, ) array_like A latitude-longitude pai...
def time(ctx, hours, minutes, seconds): return _time(conversions.to_integer(hours, ctx), conversions.to_integer(minutes, ctx), conversions.to_integer(seconds, ctx))
Defines a time value
def unplug(self): if not self.__plugged: return members = set([method for _, method in inspect.getmembers(self, predicate=inspect.ismethod)]) for message in global_callbacks: global_callbacks[message] -= members self.__plugged = False
Remove the actor's methods from the callback registry.
def kube_pod_status_phase(self, metric, scraper_config): metric_name = scraper_config['namespace'] + '.pod.status_phase' status_phase_counter = Counter() for sample in metric.samples: tags = [ self._label_to_tag('namespace', sample[self.SAMPLE_LABELS], scraper_config)...
Phase a pod is in.
def get_first_content(el_list, alt=None, strip=True): if not el_list: return alt content = el_list[0].getContent() if strip: content = content.strip() if not content: return alt return content
Return content of the first element in `el_list` or `alt`. Also return `alt` if the content string of first element is blank. Args: el_list (list): List of HTMLElement objects. alt (default None): Value returner when list or content is blank. strip (bool, default True): Call .strip() to...
def change_path_prefix(self, path, old_prefix, new_prefix, app_name): relative_path = os.path.relpath(path, old_prefix) return os.path.join(new_prefix, app_name, relative_path)
Change path prefix and include app name.
def _render_item(self, dstack, key, value = None, **settings): cur_depth = len(dstack) - 1 treeptrn = '' s = self._es_text(settings, settings[self.SETTING_TREE_FORMATING]) for ds in dstack: treeptrn += ' ' + self.fmt_text(self.tchar(settings[self.SETTING_TREE_STYLE], cur_dept...
Format single tree line.
def channel_names(self) -> tuple: if "channel_names" not in self.attrs.keys(): self.attrs["channel_names"] = np.array([], dtype="S") return tuple(s.decode() for s in self.attrs["channel_names"])
Channel names.
def is_topology(self, layers=None): if layers is None: layers = self.layers layers_nodle = [] result = [] for i, layer in enumerate(layers): if layer.is_delete is False: layers_nodle.append(i) while True: flag_break = True ...
valid the topology
def run(opts, args): setup_options(opts) mode = Modes.ONCE if len(args) > 0 and hasattr(Modes, args[0].upper()): _mode = args.pop(0).upper() mode = getattr(Modes, _mode) url = None if len(args) > 0: url = args.pop(0) plugin_mgr = Plugin...
The run method for the 'run' command. Executes a plugin from the command line.
def add_item(self, item): if not isinstance(item, JsonRpcResponse): raise TypeError( "Expected JsonRpcResponse but got {} instead".format(type(item).__name__)) self.items.append(item)
Adds an item to the batch.
def group(__decorated__, **Config): r _Group = Group(__decorated__, Config) if isclass(__decorated__): static(__decorated__) state.ActiveModuleMemberQ.insert(0, _Group) return _Group.Underlying
r"""A decorator to make groups out of classes. Config: * name (str): The name of the group. Defaults to __decorated__.__name__. * desc (str): The description of the group (optional). * alias (str): The alias for the group (optional).
def render(self, renderer=None, **kwargs): return Markup(get_renderer(current_app, renderer)(**kwargs).visit( self))
Render the navigational item using a renderer. :param renderer: An object implementing the :class:`~.Renderer` interface. :return: A markupsafe string with the rendered result.
def sql_get_oids(self, where=None): table = self.lconfig.get('table') db = self.lconfig.get('db_schema_name') or self.lconfig.get('db') _oid = self.lconfig.get('_oid') if is_array(_oid): _oid = _oid[0] sql = 'SELECT DISTINCT %s.%s FROM %s.%s' % (table, _oid, db, table...
Query source database for a distinct list of oids.
def update_proficiency(self, proficiency_form): collection = JSONClientValidated('learning', collection='Proficiency', runtime=self._runtime) if not isinstance(proficiency_form, ABCProficiencyForm): raise error...
Updates an existing proficiency. arg: proficiency_form (osid.learning.ProficiencyForm): the form containing the elements to be updated raise: IllegalState - ``proficiency_form`` already used in an update transaction raise: InvalidArgument - the form contains...
def make_tmp_name(name): path, base = os.path.split(name) tmp_base = ".tmp-%s-%s" % (base, uuid4().hex) tmp_name = os.path.join(path, tmp_base) try: yield tmp_name finally: safe_remove(tmp_name)
Generates a tmp name for a file or dir. This is a tempname that sits in the same dir as `name`. If it exists on disk at context exit time, it is deleted.
def reorderbydf(df2,df1): df3=pd.DataFrame() for idx,row in df1.iterrows(): df3=df3.append(df2.loc[idx,:]) return df3
Reorder rows of a dataframe by other dataframe :param df2: input dataframe :param df1: template dataframe
def cctop_save_xml(jobid, outpath): status = cctop_check_status(jobid=jobid) if status == 'Finished': result = 'http://cctop.enzim.ttk.mta.hu/php/result.php?jobId={}'.format(jobid) result_text = requests.post(result) with open(outpath, 'w') as f: f.write(result_text.text) ...
Save the CCTOP results file in XML format. Args: jobid (str): Job ID obtained when job was submitted outpath (str): Path to output filename Returns: str: Path to output filename
def date_range(start=None, end=None, periods=None, freq=None, tz=None, normalize=False, name=None, closed=None, **kwargs): if freq is None and com._any_none(periods, start, end): freq = 'D' dtarr = DatetimeArray._generate_range( start=start, end=end, periods=periods, freq=...
Return a fixed frequency DatetimeIndex. Parameters ---------- start : str or datetime-like, optional Left bound for generating dates. end : str or datetime-like, optional Right bound for generating dates. periods : integer, optional Number of periods to generate. freq : ...
def schema_exists(cls, cur, schema_name): cur.execute("SELECT EXISTS (SELECT schema_name FROM information_schema.schemata WHERE schema_name = '{0}');" .format(schema_name)) return cur.fetchone()[0]
Check if schema exists
def _oops_dump_state(self, ignore_remaining_data=False): log_error("==Oops state dump" + "=" * (30 - 17)) log_error("References: {0}".format(self.references)) log_error("Stream seeking back at -16 byte (2nd line is an actual position!):") self.object_stream.seek(-16, os.SEEK_CUR) ...
Log a deserialization error :param ignore_remaining_data: If True, don't log an error when unused trailing bytes are remaining
def addSource(self, source, data): self._aggregate(source, self._aggregators, data, self._result)
Adds the given source's stats.
def check_signature_supported(func, warn=False): function_name = func.__name__ sig_params = get_signature_params(func) has_kwargs_param = False has_kwonly_param = False for keyword_name, parameter in sig_params: if parameter.kind == Parameter.VAR_KEYWORD: has_kwargs_param = True ...
Check if we support the signature of this function. We currently do not allow remote functions to have **kwargs. We also do not support keyword arguments in conjunction with a *args argument. Args: func: The function whose signature should be checked. warn: If this is true, a warning will ...
def infer_axes(self): s = self.storable if s is None: return False self.get_attrs() return True
infer the axes of my storer return a boolean indicating if we have a valid storer or not
def flush(self): self.log.info('Flushing tables and arrays to disk...') for tab in self._tables.values(): tab.flush() self._write_ndarrays_cache_to_disk()
Flush tables and arrays to disk
def readdir(self, tid, fh): ret = [] pt = self.PathType.get(tid) try: if pt is self.PathType.main: ret = list(self.searches) elif pt is self.PathType.subdir: ret = list(self.searches[tid[0]]) elif pt is self.PathType.file: ...
Read directory contents. Lists visible elements of ``YTActions`` object. Parameters ---------- tid : str Path to file. Original `path` argument is converted to tuple identifier by ``_pathdec`` decorator. fh : int File descriptor. Ommited in the function body. ...
def get_running(): ret = set() out = __salt__['cmd.run']( _systemctl_cmd('--full --no-legend --no-pager'), python_shell=False, ignore_retcode=True) for line in salt.utils.itertools.split(out, '\n'): try: comps = line.strip().split() fullname = comps[0]...
Return a list of all running services, so far as systemd is concerned CLI Example: .. code-block:: bash salt '*' service.get_running
def get_monomers(self, ligands=True): if ligands and self.ligands: monomers = self._monomers + self.ligands._monomers else: monomers = self._monomers return iter(monomers)
Retrieves all the `Monomers` from the AMPAL object. Parameters ---------- ligands : bool, optional If true, will include ligand `Monomers`.
def _listitemify(self, item): info_type = self.info_type if hasattr(self, 'info_type') else 'video' if not hasattr(item, 'as_tuple'): if 'info_type' not in item.keys(): item['info_type'] = info_type item = xbmcswift2.ListItem.from_dict(**item) return item
Creates an xbmcswift2.ListItem if the provided value for item is a dict. If item is already a valid xbmcswift2.ListItem, the item is returned unmodified.
def get_role_model(): app_model = getattr(settings, "ARCTIC_ROLE_MODEL", "arctic.Role") try: return django_apps.get_model(app_model) except ValueError: raise ImproperlyConfigured( "ARCTIC_ROLE_MODEL must be of the " "form 'app_label.model_name'" ) except LookupError: ...
Returns the Role model that is active in this project.
def retrieve_nodes(self): self.verbose('retrieving nodes from old mysql DB...') self.old_nodes = list(OldNode.objects.all()) self.message('retrieved %d nodes' % len(self.old_nodes))
retrieve nodes from old mysql DB
def is_serializable_type(type_): if not inspect.isclass(type_): return Serializable.is_serializable(type_) return issubclass(type_, Serializable) or hasattr(type_, '_asdict')
Return `True` if the given type's instances conform to the Serializable protocol. :rtype: bool
def find_maximum(self, scores, N, k_choices): if not isinstance(scores, np.ndarray): raise TypeError("Scores input is not a numpy array") index_of_maximum = int(scores.argmax()) maximum_combo = self.nth(combinations( list(range(N)), k_choices), index_of_maximum, None) ...
Finds the `k_choices` maximum scores from `scores` Arguments --------- scores : numpy.ndarray N : int k_choices : int Returns ------- list
def reverse_dictionary(d): rev_d = {} [rev_d.update({v:k}) for k, v in d.items()] return rev_d
Reverses the key value pairs for a given dictionary. Parameters ---------- d : :obj:`dict` dictionary to reverse Returns ------- :obj:`dict` dictionary with keys and values swapped
def match_ancestor_objective_id(self, objective_id=None, match=None): if match: self._add_match('ancestorObjectiveId', objective_id) else: raise errors.Unimplemented()
Sets the objective ``Id`` for this query to match objectives that have the specified objective as an ancestor. arg: objective_id (osid.id.Id): an objective ``Id`` arg: match (boolean): ``true`` for a positive match, ``false`` for a negative match raise: NullArgument - ``o...
def add_context(self, name, indices, level=None): self._validate_context((name, indices)) if level is None: level = len(self.contexts_ranked) self.contexts_ranked.insert(level, name) self.contexts[name] = indices
Add a new context level to the hierarchy. By default, new contexts are added to the lowest level of the hierarchy. To insert the context elsewhere in the hierarchy, use the ``level`` argument. For example, ``level=0`` would insert the context at the highest level of the hierarchy. ...
def parallel_progbar(mapper, iterable, nprocs=None, starmap=False, flatmap=False, shuffle=False, verbose=True, verbose_flatmap=None, **kwargs): results = _parallel_progbar_launch(mapper, iterable, nprocs, starmap, flatmap, shuffle, verbose, verbose_flatmap, **kwargs) return [x for i, x in s...
Performs a parallel mapping of the given iterable, reporting a progress bar as values get returned :param mapper: The mapping function to apply to elements of the iterable :param iterable: The iterable to map :param nprocs: The number of processes (defaults to the number of cpu's) :param starmap: If tr...
def get_snmp_from_host2(self): if not self.snmp2: self.activity_value2 = None else: response = self.snmp2.get_oids(activity_oid) self.activity_value2 = activity[int(response[0])]
Get SNMP values from 2nd host.
def build(self, build_dir, **kwargs): del kwargs args = ["cmake", "--build", build_dir] args.extend(self._get_build_flags()) return [{"args": args}]
This function builds the cmake build command.
def get_features(self, yam): mcap = [ c for c in self.capabilities if c.parameters.get("module", None) == yam ][0] if not mcap.parameters.get("features"): return [] return mcap.parameters["features"].split(",")
Return list of features declared for module `yam`.
def constraint_to_si(expr): satisfiable = True replace_list = [ ] satisfiable, replace_list = backends.vsa.constraint_to_si(expr) for i in xrange(len(replace_list)): ori, new = replace_list[i] if not isinstance(new, Base): new = BVS(new.name, new._bits, min=new._lower_bound, ...
Convert a constraint to SI if possible. :param expr: :return:
def get_assessment_offered_bank_assignment_session(self, proxy): if not self.supports_assessment_offered_bank_assignment(): raise errors.Unimplemented() return sessions.AssessmentOfferedBankAssignmentSession(proxy=proxy, runtime=self._runtime)
Gets the session for assigning offered assessments to bank mappings. arg: proxy (osid.proxy.Proxy): a proxy return: (osid.assessment.AssessmentOfferedBankAssignmentSession) - an ``AssessmentOfferedBankAssignmentSession`` raise: NullArgument - ``proxy`` is ``null`` ra...
def section_branch_orders(neurites, neurite_type=NeuriteType.all): return map_sections(sectionfunc.branch_order, neurites, neurite_type=neurite_type)
section branch orders in a collection of neurites
async def is_bot(self): if self._bot is None: self._bot = (await self.get_me()).bot return self._bot
Return ``True`` if the signed-in user is a bot, ``False`` otherwise.
def sub_for(expr, substitutions): mapping = {k.op(): v for k, v in substitutions} substitutor = Substitutor() return substitutor.substitute(expr, mapping)
Substitute subexpressions in `expr` with expression to expression mapping `substitutions`. Parameters ---------- expr : ibis.expr.types.Expr An Ibis expression substitutions : List[Tuple[ibis.expr.types.Expr, ibis.expr.types.Expr]] A mapping from expression to expression. If any sub...
def _dispatch(self, tree): "_dispatcher function, _dispatching tree type T to method _T." if isinstance(tree, list): for t in tree: self._dispatch(t) return meth = getattr(self, "_"+tree.__class__.__name__) if tree.__class__.__name__ == 'NoneType' ...
_dispatcher function, _dispatching tree type T to method _T.
def update_share(self, share_id, **kwargs): perms = kwargs.get('perms', None) password = kwargs.get('password', None) public_upload = kwargs.get('public_upload', None) if (isinstance(perms, int)) and (perms > self.OCS_PERMISSION_ALL): perms = None if not (perms or pas...
Updates a given share :param share_id: (int) Share ID :param perms: (int) update permissions (see share_file_with_user() below) :param password: (string) updated password for public link Share :param public_upload: (boolean) enable/disable public upload for public shares :return...
def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None): num = int(num) start = start * 1. stop = stop * 1. if num <= 0: return [] if endpoint: if num == 1: return [start] step = (stop-start)/float((num-1)) if num == 1: step...
Port of numpy's linspace to pure python. Does not support dtype, and returns lists of floats.
def legislator_vote_value(self): if not hasattr(self, 'legislator'): msg = ('legislator_vote_value can only be called ' 'from a vote accessed by legislator.votes_manager.') raise ValueError(msg) leg_id = self.legislator.id for k in ('yes', 'no', 'other'...
If this vote was accessed through the legislator.votes_manager, return the value of this legislator's vote.
def transfer(self, data): settings = self.transfer_settings settings.spi_tx_size = len(data) self.transfer_settings = settings response = '' for i in range(0, len(data), 60): response += self.sendCommand(commands.SPITransferCommand(data[i:i + 60])).data ti...
Transfers data over SPI. Arguments: data: The data to transfer. Returns: The data returned by the SPI device.
def kill_cursor(self, cursor): text = cursor.selectedText() if text: cursor.removeSelectedText() self.kill(text)
Kills the text selected by the give cursor.
def close_compute_projects(self, compute): for project in self._projects.values(): if compute in project.computes: yield from project.close()
Close projects running on a compute
def post_helper(form_tag=True, edit_mode=False): helper = FormHelper() helper.form_action = '.' helper.attrs = {'data_abide': ''} helper.form_tag = form_tag fieldsets = [ Row( Column( 'text', css_class='small-12' ), ), ] ...
Post's form layout helper
def install_deny_hook(api): if api == USED_API: raise ValueError sys.meta_path.insert(0, ImportHookDeny(api))
Install a deny import hook for Qt api. Parameters ---------- api : str The Qt api whose import should be prevented Example ------- >>> install_deny_import("pyqt4") >>> import PyQt4 Traceback (most recent call last):... ImportError: Import of PyQt4 is denied.
def build_single_handler_applications(paths, argvs=None): applications = {} argvs = {} or argvs for path in paths: application = build_single_handler_application(path, argvs.get(path, [])) route = application.handlers[0].url_path() if not route: if '/' in applications: ...
Return a dictionary mapping routes to Bokeh applications built using single handlers, for specified files or directories. This function iterates over ``paths`` and ``argvs`` and calls :func:`~bokeh.command.util.build_single_handler_application` on each to generate the mapping. Args: path (...