code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def invoke_in_mainloop(func, *args, **kwargs): results = queue.Queue() @gcall def run(): try: data = func(*args, **kwargs) results.put(data) results.put(None) except BaseException: results.put(None) results.put(sys.exc_info()) ...
Invoke a function in the mainloop, pass the data back.
def get_adapted_session(adapter): session = requests.Session() session.mount("http://", adapter) session.mount("https://", adapter) return session
Mounts an adapter capable of communication over HTTP or HTTPS to the supplied session. :param adapter: A :class:`requests.adapters.HTTPAdapter` instance :return: The adapted :class:`requests.Session` instance
def _fetch_router_chunk_data(self, router_ids=None): curr_router = [] if len(router_ids) > self.sync_routers_chunk_size: for i in range(0, len(router_ids), self.sync_routers_chunk_size): routers = self.plugin_rpc.get_routers( ...
Fetch router data from the routing plugin in chunks. :param router_ids: List of router_ids of routers to fetch :return: List of router dicts of format: [ {router_dict1}, {router_dict2},.....]
def make_file_cm(filename, mode='a'): @contextlib.contextmanager def cm(): with open(filename, mode=mode) as fh: yield fh return cm
Open a file for appending and yield the open filehandle. Close the filehandle after yielding it. This is useful for creating a context manager for logging the output of a `Vagrant` instance. filename: a path to a file mode: The mode in which to open the file. Defaults to 'a', append Usage exam...
def to_json(value, **kwargs): serial_list = [ val.serialize(**kwargs) if isinstance(val, HasProperties) else val for val in value ] return serial_list
Return a copy of the tuple as a list If the tuple contains HasProperties instances, they are serialized.
def execute(self, *args, **kwargs): args = self.parser.parse_args(*args, **kwargs) self.process(args)
Initializes and runs the tool. This is shorhand to parse command line arguments, then calling: self.setup(parsed_arguments) self.process()
def get_alert_community(self, channel=None): if channel is None: channel = self.get_network_channel() rsp = self.xraw_command(netfn=0xc, command=2, data=(channel, 16, 0, 0)) return rsp['data'][1:].partition('\x00')[0]
Get the current community string for alerts Returns the community string that will be in SNMP traps from this BMC :param channel: The channel to get configuration for, autodetect by default :returns: The community string
def doWaitWebRequest(url, method="GET", data=None, headers={}): completed = False while not completed: completed = True try: response, content = doWebRequest(url, method, data, headers) except urllib2.URLError: completed = False waitForURL(url) ret...
Same as doWebRequest, but with built in wait-looping
def is_visit_primitive(obj): from .base import visit if (isinstance(obj, tuple(PRIMITIVE_TYPES)) and not isinstance(obj, STR) and not isinstance(obj, bytes)): return True if (isinstance(obj, CONTAINERS) and not isinstance(obj, STR) and not isinstance(obj, bytes)): return Fals...
Returns true if properly visiting the object returns only the object itself.
def finish(self): self.update(self.maxval) if self.signal_set: signal.signal(signal.SIGWINCH, signal.SIG_DFL)
Used to tell the progress is finished.
def fulfill_access_secret_store_condition(event, agreement_id, did, service_agreement, consumer_address, publisher_account): logger.debug(f"release reward after event {event}.") name_to_parameter = {param.name: param for param in service_agreeme...
Fulfill the access condition. :param event: AttributeDict with the event data. :param agreement_id: id of the agreement, hex str :param did: DID, str :param service_agreement: ServiceAgreement instance :param consumer_address: ethereum account address of consumer, hex str :param publisher_accou...
def open(self, name, *args, **kwargs): if self.basedir is not None: name = os.path.join(self.basedir, name) return em.Subsystem.open(self, name, *args, **kwargs)
Open file, possibly relative to a base directory.
def publish_post(self): payload = {'content': self.content_base64.decode('utf-8')} sha_blob = self.get_sha_blob() if sha_blob: commit_msg = 'ghPublish UPDATE: {}'.format(self.title) payload.update(sha=sha_blob) payload.update(message=commit_msg) else: ...
If it's a new file, add it. Else, update it.
def _get_form_defaults(self): return { 'response_format': 'html', 'geometry_type': 'esriGeometryPoint', 'projection': pyproj.Proj(str(self.service.projection)), 'return_geometry': True, 'maximum_allowable_offset': 2, 'geometry_precision': 3...
Returns default values for the identify form
def constrain_cfgdict_list(cfgdict_list_, constraint_func): cfgdict_list = [] for cfg_ in cfgdict_list_: cfg = cfg_.copy() if constraint_func(cfg) is not False and len(cfg) > 0: if cfg not in cfgdict_list: cfgdict_list.append(cfg) return cfgdict_list
constrains configurations and removes duplicates
def use_quandl_data(self, authtoken): dfs = {} st = self.start.strftime("%Y-%m-%d") at = authtoken for pair in self.pairs: symbol = "".join(pair) qsym = "CURRFX/{}".format(symbol) dfs[symbol] = qdl.get(qsym,authtoken=at, trim_start=st)['Rate'] ...
Use quandl data to build conversion table
def highlight_matches(self): if self.is_code_editor and self.highlight_button.isChecked(): text = self.search_text.currentText() words = self.words_button.isChecked() regexp = self.re_button.isChecked() self.editor.highlight_found_results(text, words=words, ...
Highlight found results
def connect_to_apple_tv(details, loop, protocol=None, session=None): service = _get_service_used_to_connect(details, protocol) if session is None: session = ClientSession(loop=loop) airplay = _setup_airplay(loop, session, details) if service.protocol == PROTOCOL_DMAP: return DmapAppleTV(...
Connect and logins to an Apple TV.
def read(self): try: buf = os.read(self._fd, 8) except OSError as e: raise LEDError(e.errno, "Reading LED brightness: " + e.strerror) try: os.lseek(self._fd, 0, os.SEEK_SET) except OSError as e: raise LEDError(e.errno, "Rewinding LED bright...
Read the brightness of the LED. Returns: int: Current brightness. Raises: LEDError: if an I/O or OS error occurs.
def update_contact(self, um_from_user, um_to_user, message): contact, created = self.get_or_create(um_from_user, um_to_user, message) if not created: contact.latest_message = message conta...
Get or update a contacts information
def add_def(self, def_item): self.defs.append(def_item) for other in self.others: other.add_def(def_item)
Adds a def universally.
def create_knowledge_base(self, parent, knowledge_base, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None): ...
Creates a knowledge base. Example: >>> import dialogflow_v2beta1 >>> >>> client = dialogflow_v2beta1.KnowledgeBasesClient() >>> >>> parent = client.project_path('[PROJECT]') >>> >>> # TODO: Initialize ``knowledge_base``: ...
def remove_network(self, action, n_name, **kwargs): c_kwargs = self.get_network_remove_kwargs(action, n_name, **kwargs) res = action.client.remove_network(**c_kwargs) del self._policy.network_names[action.client_name][n_name] return res
Removes a network. :param action: Action configuration. :type action: dockermap.map.runner.ActionConfig :param n_name: Network name or id. :type n_name: unicode | str :param kwargs: Additional keyword arguments. :type kwargs: dict
def update_state_from_api(self): if self.last_api_call is not None: difference = (datetime.datetime.now() - self.last_api_call).seconds else: difference = 301 if difference >= 300: url = BASE_URL + "/rest/item" payload = {'usertoken': self.token} ...
Pull and update the current state from the API.
def create(cls, entry): try: module = import_module(entry) except ImportError: module = None mod_path, _, cls_name = entry.rpartition('.') if not mod_path: raise else: try: entry = module.default_bot ...
Factory that creates an bot config from an entry in INSTALLED_APPS.
def from_bundle(cls, b, feature): feature_ps = b.get_feature(feature) freq = feature_ps.get_value('freq', unit=u.d**-1) radamp = feature_ps.get_value('radamp', unit=u.dimensionless_unscaled) l = feature_ps.get_value('l', unit=u.dimensionless_unscaled) m = feature_ps.get_value('m'...
Initialize a Pulsation feature from the bundle.
def graph_from_edges(edges): M = nx.MultiGraph() for e in edges: n0, n1, weight, key = e M.add_edge(n0, n1, weight=weight, key=key) return M
Constructs an undirected multigraph from a list containing data on weighted edges. Parameters ---------- edges : list List of tuples each containing first node, second node, weight, key. Returns ------- M : :class:`networkx.classes.multigraph.MultiGraph
def as_dataframe(self, pattern='*', max_rows=None): data = [] for i, group in enumerate(self.list(pattern)): if max_rows is not None and i >= max_rows: break parent = self._group_dict.get(group.parent_id) parent_display_name = '' if parent is None else parent.display_name data.ap...
Creates a pandas dataframe from the groups that match the filters. Args: pattern: An optional pattern to further filter the groups. This can include Unix shell-style wildcards. E.g. ``"Production *"``, ``"*-backend"``. max_rows: The maximum number of groups to return. If None, retur...
def keyPressEvent(self, event): if event.key() == Qt.Key_Down: self.select_row(1) elif event.key() == Qt.Key_Up: self.select_row(-1)
Reimplement Qt method to allow cyclic behavior.
def set_cache_value(self, name, value): dev_info = self.json_state.get('deviceInfo') if dev_info.get(name.lower()) is None: logger.error("Could not set %s for %s (key does not exist).", name, self.name) logger.error("- dictionary %s", dev_info) r...
Set a variable in the local state dictionary. This does not change the physical device. Useful if you want the device state to refect a new value which has not yet updated drom Vera.
def get_all_database_accessions(chebi_ids): all_database_accessions = [get_database_accessions(chebi_id) for chebi_id in chebi_ids] return [x for sublist in all_database_accessions for x in sublist]
Returns all database accessions
def remove_obsolete_folders(states, path): elements_in_folder = os.listdir(path) state_folders_in_file_system = [] for folder_name in elements_in_folder: if os.path.exists(os.path.join(path, folder_name, FILE_NAME_CORE_DATA)) or \ os.path.exists(os.path.join(path, folder_name, FILE_N...
Removes obsolete state machine folders This function removes all folders in the file system folder `path` that do not belong to the states given by `states`. :param list states: the states that should reside in this very folder :param str path: the file system path to be checked for valid folders
def thumbUrl(self): key = self.firstAttr('thumb', 'parentThumb', 'granparentThumb') return self._server.url(key, includeToken=True) if key else None
Return url to for the thumbnail image.
def cancel(self): with self._condition: if self._state in [RUNNING, FINISHED]: return False if self._state in [CANCELLED, CANCELLED_AND_NOTIFIED]: return True self._state = CANCELLED self._condition.notify_all() self._invoke...
Cancel the future if possible. Returns True if the future was cancelled, False otherwise. A future cannot be cancelled if it is running or has already completed.
def addMonitor(self, monitorFriendlyName, monitorURL): url = self.baseUrl url += "newMonitor?apiKey=%s" % self.apiKey url += "&monitorFriendlyName=%s" % monitorFriendlyName url += "&monitorURL=%s&monitorType=1" % monitorURL url += "&monitorAlertContacts=%s" % monitorAlertContacts...
Returns True if Monitor was added, otherwise False.
def get_annotations(self) -> Dict: return { EVIDENCE: self.evidence, CITATION: self.citation.copy(), ANNOTATIONS: self.annotations.copy() }
Get the current annotations.
def edit(filename, connection=None): c = connection or connect() rev = c.ls(filename) if rev: rev[0].edit()
Checks out a file into the default changelist :param filename: File to check out :type filename: str :param connection: Connection object to use :type connection: :py:class:`Connection`
def mesh_stable_pose(mesh, T_obj_table, T_table_world=RigidTransform(from_frame='table', to_frame='world'), style='wireframe', smooth=False, color=(0.5,0.5,0.5), dim=0.15, plot_table=True, plot_com=False, name=None): T_obj_table = T_obj_...
Visualize a mesh in a stable pose. Parameters ---------- mesh : trimesh.Trimesh The mesh to visualize. T_obj_table : autolab_core.RigidTransform Pose of object relative to table. T_table_world : autolab_core.RigidTransform Pose of table relati...
def change_state(self, key, value): if key not in VALID_KEYS: raise InvalidState self._data[key] = value
Changes the state of the instance data with the given ``key`` and the provided ``value``. Wrapping with a decorator is probably not necessary. :param key: A ``str`` containing the key to update :param value: A value to change the ``key`` to :return: None
def stop(self, sig=signal.SIGINT): for cpid in self.sandboxes: logger.warn('Stopping %i...' % cpid) try: os.kill(cpid, sig) except OSError: logger.exception('Error stopping %s...' % cpid) for cpid in list(self.sandboxes): tr...
Stop all the workers, and then wait for them
def get_params(self): return self.timeout, self.xonxoff, self.rtscts, self.baudrate
Get parameters as a tuple. :return: timeout, xonxoff, rtscts, baudrate
def integer_binning(data=None, **kwargs) -> StaticBinning: if "range" in kwargs: kwargs["range"] = tuple(r - 0.5 for r in kwargs["range"]) return fixed_width_binning(data=data, bin_width=kwargs.pop("bin_width", 1), align=True, bin_shift=0.5, **kwargs)
Construct fixed-width binning schema with bins centered around integers. Parameters ---------- range: Optional[Tuple[int]] min (included) and max integer (excluded) bin bin_width: Optional[int] group "bin_width" integers into one bin (not recommended)
def havdalah(self): today = HDate(gdate=self.date, diaspora=self.location.diaspora) tomorrow = HDate(gdate=self.date + dt.timedelta(days=1), diaspora=self.location.diaspora) if today.is_shabbat or today.is_yom_tov: if tomorrow.is_shabbat or tomorrow.is_yom_to...
Return the time for havdalah, or None if not applicable. If havdalah_offset is 0, uses the time for three_stars. Otherwise, adds the offset to the time of sunset and uses that. If it's currently a multi-day YomTov, and the end of the stretch is after today, the havdalah value is defined...
def space_out_camel_case(stringAsCamelCase): pattern = re.compile(r'([A-Z][A-Z][a-z])|([a-z][A-Z])') if stringAsCamelCase is None: return None return pattern.sub(lambda m: m.group()[:1] + " " + m.group()[1:], stringAsCamelCase)
Adds spaces to a camel case string. Failure to space out string returns the original string. >>> space_out_camel_case('DMLSServicesOtherBSTextLLC') 'DMLS Services Other BS Text LLC'
def monthly(self): if self._monthly is None: self._monthly = MonthlyList(self._version, account_sid=self._solution['account_sid'], ) return self._monthly
Access the monthly :returns: twilio.rest.api.v2010.account.usage.record.monthly.MonthlyList :rtype: twilio.rest.api.v2010.account.usage.record.monthly.MonthlyList
def get_tensors_by_names(names): ret = [] G = tfv1.get_default_graph() for n in names: opn, varn = get_op_tensor_name(n) ret.append(G.get_tensor_by_name(varn)) return ret
Get a list of tensors in the default graph by a list of names. Args: names (list):
def dfbool2intervals(df,colbool): df.index=range(len(df)) intervals=bools2intervals(df[colbool]) for intervali,interval in enumerate(intervals): df.loc[interval[0]:interval[1],f'{colbool} interval id']=intervali df.loc[interval[0]:interval[1],f'{colbool} interval start']=interval[0] ...
ds contains bool values
def send_note(self, to, subject="", body="", noetid=""): if self.standard_grant_type is not "authorization_code": raise DeviantartError("Authentication through Authorization Code (Grant Type) is required in order to connect to this endpoint.") response = self._req('/notes/send', post_data={ ...
Send a note :param to: The username(s) that this note is to :param subject: The subject of the note :param body: The body of the note :param noetid: The UUID of the note that is being responded to
def convert_from_rosetta(self, residue_id, to_scheme): assert(type(residue_id) == types.IntType) chain_id = None for c, sequence in self.rosetta_sequences.iteritems(): for id, r in sequence: if r.ResidueID == residue_id: assert(chain_id == None) ...
A simpler conversion function to convert from Rosetta numbering without requiring the chain identifier.
def json_pretty_print(s): s = json.loads(s) return json.dumps(s, sort_keys=True, indent=4, separators=(',', ': '))
pretty print JSON
def getPageType(name,number=False): if not name in pageNames(): return None pageType=PyOrigin.Pages(name).GetType() if number: return str(pageType) if pageType==1: return "matrix" if pageType==2: return "book" if pageType==3: return "graph" if pageType...
Returns the type of the page with that name. If that name doesn't exist, None is returned. Args: name (str): name of the page to get the folder from number (bool): if True, return numbers (i.e., a graph will be 3) if False, return words where appropriate (i.e, "graph") Returns:...
def SummaryMetadata(self, run, tag): accumulator = self.GetAccumulator(run) return accumulator.SummaryMetadata(tag)
Return the summary metadata for the given tag on the given run. Args: run: A string name of the run for which summary metadata is to be retrieved. tag: A string name of the tag whose summary metadata is to be retrieved. Raises: KeyError: If the run is not found, or the tag is...
def callback(cfunc): return C.c_voidp.from_address(C.cast(cfunc, C.c_voidp).value)
Turn a ctypes CFUNCTYPE instance into a value which can be passed into PyROOT
def _remove_debug_handlers(self): remove = list() for handler in self.config[self.HANDLERS]: if self.config[self.HANDLERS][handler].get('debug_only'): remove.append(handler) for handler in remove: del self.config[self.HANDLERS][handler] for log...
Remove any handlers with an attribute of debug_only that is True and remove the references to said handlers from any loggers that are referencing them.
def get_or_create(cls, issue, header, text=None): for comment in get_comments(issue): try: if comment.body.splitlines()[0] == header: obj = cls(comment, header) break except IndexError: pass else: ...
Get or create the dashboard comment in this issue.
def _compile(self, dirpath, makename, compiler, debug, profile): from os import path options = "" if debug: options += " DEBUG=true" if profile: options += " GPROF=true" from os import system codestr = "cd {}; make -f '{}' F90={} FAM={}" + options ...
Compiles the makefile at the specified location with 'compiler'. :arg dirpath: the full path to the directory where the makefile lives. :arg compiler: one of ['ifort', 'gfortran']. :arg makename: the name of the make file to compile.
def _rgetattr(obj, key): for k in key.split("."): obj = getattr(obj, k) return obj
Recursive getattr for handling dots in keys.
def decrypt_filedata(data, keys): data.seek(-16, 2) tag = data.read() data.seek(-16, 2) data.truncate() data.seek(0) plain = tempfile.NamedTemporaryFile(mode='w+b', delete=False) pbar = progbar(fileSize(data)) obj = Cryptodome.Cipher.AES.new(keys.encryptKey, Cryptodome.Cipher.AES.MODE_GC...
Decrypts a file from Send
def _spawn(self): self.queue = Queue(maxsize=self.num_threads * 10) for i in range(self.num_threads): t = Thread(target=self._consume) t.daemon = True t.start()
Initialize the queue and the threads.
def make_context(self, docker_file=None): kwargs = {"silent_build": self.harpoon.silent_build, "extra_context": self.commands.extra_context} if docker_file is None: docker_file = self.docker_file with ContextBuilder().make_context(self.context, **kwargs) as ctxt: self.add...
Determine the docker lines for this image
def unit_doomed(unit=None): if not has_juju_version("2.4.1"): raise NotImplementedError("is_doomed") if unit is None: unit = local_unit() gs = goal_state() units = gs.get('units', {}) if unit not in units: return True return units[unit]['status'] in ('dying', 'dead')
Determines if the unit is being removed from the model Requires Juju 2.4.1. :param unit: string unit name, defaults to local_unit :side effect: calls goal_state :side effect: calls local_unit :side effect: calls has_juju_version :return: True if the unit is being removed, already gone, or neve...
def poke(library, session, address, width, data): if width == 8: return poke_8(library, session, address, data) elif width == 16: return poke_16(library, session, address, data) elif width == 32: return poke_32(library, session, address, data) raise ValueError('%s is not a valid ...
Writes an 8, 16 or 32-bit value from the specified address. Corresponds to viPoke* functions of the VISA library. :param library: the visa library wrapped by ctypes. :param session: Unique logical identifier to a session. :param address: Source address to read the value. :param width: Number of bi...
def print_yielded(func): print_all = functools.partial(map, print) print_results = compose(more_itertools.recipes.consume, print_all, func) return functools.wraps(func)(print_results)
Convert a generator into a function that prints all yielded elements >>> @print_yielded ... def x(): ... yield 3; yield None >>> x() 3 None
def copy_shell__(self, new_i): for prop in ONLY_COPY_PROP: setattr(new_i, prop, getattr(self, prop)) return new_i
Create all attributes listed in 'ONLY_COPY_PROP' and return `self` with these attributes. :param new_i: object to :type new_i: object :return: object with new properties added :rtype: object
def remove_spawned_gates(self, spawn_gate=None): if spawn_gate is None: for sg in list(self.spawn_list): self.spawn_list.remove(sg) sg.remove() else: spawn_gate.remove() self.spawn_list.remove(spawn_gate)
Removes all spawned gates.
def update_resource(self, resource, underlined=None): try: pymodule = self.project.get_pymodule(resource) modname = self._module_name(resource) self._add_names(pymodule, modname, underlined) except exceptions.ModuleSyntaxError: pass
Update the cache for global names in `resource`
def blank_object(obj: T, fieldlist: Sequence[str]) -> None: for f in fieldlist: setattr(obj, f, None)
Within "obj", sets all fields in the fieldlist to None.
def refresh(self): table = self.tableType() search = nativestring(self._pywidget.text()) if search == self._lastSearch: return self._lastSearch = search if not search: return if search in self._cache: records = self._cache[s...
Refreshes the contents of the completer based on the current text.
def check_outputs(self): self.outputs = self.expand_filenames(self.outputs) result = False if self.files_exist(self.outputs): if self.dependencies_are_newer(self.outputs, self.inputs): result = True print("Dependencies are newer than outputs.") ...
Check for the existence of output files
def _get_cookies_as_dict(): config = ConfigParser.SafeConfigParser() config.read(_config) if config.has_section('cookies'): cookie_dict = {} for option in config.options('cookies'): option_key = option.upper() if option == 'jsessionid' else option cookie_dict[option_k...
Get cookies as a dict
def tuple_len(self): try: return self._tuple_len except AttributeError: raise NotImplementedError("Class {} does not implement attribute 'tuple_len'.".format(self.__class__.__name__))
Length of tuples produced by this generator.
def _k_value_square_reduction(ent_pipe_id, exit_pipe_id, re, f): if re < 2500: return (1.2 + (160 / re)) * ((ent_pipe_id / exit_pipe_id) ** 4) else: return (0.6 + 0.48 * f) * (ent_pipe_id / exit_pipe_id) ** 2\ * ((ent_pipe_id / exit_pipe_id) ** 2 - 1)
Returns the minor loss coefficient for a square reducer. Parameters: ent_pipe_id: Entrance pipe's inner diameter. exit_pipe_id: Exit pipe's inner diameter. re: Reynold's number. f: Darcy friction factor.
def remove_not_requested_analyses_view(portal): logger.info("Removing 'Analyses not requested' view ...") ar_ptype = portal.portal_types.AnalysisRequest ar_ptype._actions = filter(lambda act: act.id != "analyses_not_requested", ar_ptype.listActions())
Remove the view 'Not requested analyses" from inside AR
def count_unique(table, field=-1): from collections import Counter try: ans = {} for row in table.distinct().values(field).annotate(field_value_count=models.Count(field)): ans[row[field]] = row['field_value_count'] return ans except: try: return Counte...
Use the Django ORM or collections.Counter to count unique values of a field in a table `table` is one of: 1. An iterable of Django model instances for a database table (e.g. a Django queryset) 2. An iterable of dicts or lists with elements accessed by row[field] where field can be an integer or string ...
def node2geoff(node_name, properties, encoder): if properties: return '({0} {1})'.format(node_name, encoder.encode(properties)) else: return '({0})'.format(node_name)
converts a NetworkX node into a Geoff string. Parameters ---------- node_name : str or int the ID of a NetworkX node properties : dict a dictionary of node attributes encoder : json.JSONEncoder an instance of a JSON encoder (e.g. `json.JSONEncoder`) Returns ------- ...
def get_model(self, ids): to_get_ids = [i for i in ids if i not in self._known_models] models = [dxl_to_model(m) for m in self._get_model(to_get_ids, convert=False)] self._known_models.update(zip(to_get_ids, models)) return tuple(self._known_models[id] for id in ids)
Gets the model for the specified motors.
def backupIds(self) -> Sequence[int]: return [id for id in self.started.keys() if id != 0]
Return the list of replicas that don't belong to the master protocol instance
def read_pcap_from_source(self): if self._capture_node: compute = self._capture_node["node"].compute return compute.stream_file(self._project, "tmp/captures/" + self._capture_file_name)
Return a FileStream of the Pcap from the compute node
def _compute_length(nodes): r _, num_nodes = np.shape(nodes) first_deriv = (num_nodes - 1) * (nodes[:, 1:] - nodes[:, :-1]) if num_nodes == 2: return np.linalg.norm(first_deriv[:, 0], ord=2) if _scipy_int is None: raise OSError("This function requires SciPy for quadrature.") size...
r"""Approximately compute the length of a curve. .. _QUADPACK: https://en.wikipedia.org/wiki/QUADPACK If ``degree`` is :math:`n`, then the Hodograph curve :math:`B'(s)` is degree :math:`d = n - 1`. Using this curve, we approximate the integral: .. math:: \int_{B\left(\left[0, 1\right]\rig...
def config_get(self, pattern='*'): result = {} for name, value in self.redis_config.items(): if fnmatch.fnmatch(name, pattern): try: result[name] = int(value) except ValueError: result[name] = value return result
Get one or more configuration parameters.
def _replace(self, **kwds): 'Return a new NamedTuple object replacing specified fields with new values' result = self._make(map(kwds.pop, self._fields, self)) if kwds: raise ValueError('Got unexpected field names: %r' % kwds.keys()) return result
Return a new NamedTuple object replacing specified fields with new values
def handle(self, *args, **options): comments = Comment.objects.filter( Q(classifiedcomment__isnull=True) | Q(classifiedcomment__cls='unsure')).order_by('?') if options['count']: comments = comments[:options['count']] comment_count = comments.count() se...
Collect all comments that hasn't already been classified or are classified as unsure. Order randomly so we don't rehash previously unsure classifieds when count limiting.
def find_local_id(self, name_id): try: return self.db[name_id.text] except KeyError: logger.debug("name: %s", name_id.text) return None
Only find persistent IDs :param name_id: :return:
async def auth(self): credentials = await self.atv.airplay.generate_credentials() await self.atv.airplay.load_credentials(credentials) try: await self.atv.airplay.start_authentication() pin = await _read_input(self.loop, 'Enter PIN on screen: ') await self.atv...
Perform AirPlay device authentication.
def repr_args(args): res = [] for x in args: if isinstance(x, tuple) and len(x) == 2: key, value = x res += ["%s=%s" % (key, repr_arg(value))] else: res += [repr_arg(x)] return ', '.join(res)
formats a list of function arguments prettily but as working code (kwargs are tuples (argname, argvalue)
def facetintervallookupone(table, key, start='start', stop='stop', value=None, include_stop=False, strict=True): trees = facettupletrees(table, key, start=start, stop=stop, value=value) out = dict() for k in trees: out[k] = IntervalTreeLookupOne(trees[k], include_stop=incl...
Construct a faceted interval lookup for the given table, returning at most one result for each query. If ``strict=True``, queries returning more than one result will raise a `DuplicateKeyError`. If ``strict=False`` and there is more than one result, the first result is returned.
def filter_whitespace(mode: str, text: str) -> str: if mode == "all": return text elif mode == "single": text = re.sub(r"([\t ]+)", " ", text) text = re.sub(r"(\s*\n\s*)", "\n", text) return text elif mode == "oneline": return re.sub(r"(\s+)", " ", text) else: ...
Transform whitespace in ``text`` according to ``mode``. Available modes are: * ``all``: Return all whitespace unmodified. * ``single``: Collapse consecutive whitespace with a single whitespace character, preserving newlines. * ``oneline``: Collapse all runs of whitespace into a single space ...
def tail(self, n=None, **kwargs): if n is None: n = options.display.max_rows return self._handle_delay_call('execute', self, tail=n, **kwargs)
Return the last n rows. Execute at once. :param n: :return: result frame :rtype: :class:`odps.df.backends.frame.ResultFrame`
def build_insert(table_name, attributes): sql = "INSERT INTO %s" %(table_name) column_str = u"" value_str = u"" for index, (key, value) in enumerate(attributes.items()): if index > 0: column_str += u"," value_str += u"," column_str += key value_str += valu...
Given the table_name and the data, return the sql to insert the data
def highpass(timeseries, frequency, filter_order=8, attenuation=0.1): if not isinstance(timeseries, TimeSeries): raise TypeError("Can only resample time series") if timeseries.kind is not 'real': raise TypeError("Time series must be real") lal_data = timeseries.lal() _highpass_func[times...
Return a new timeseries that is highpassed. Return a new time series that is highpassed above the `frequency`. Parameters ---------- Time Series: TimeSeries The time series to be high-passed. frequency: float The frequency below which is suppressed. filter_order: {8, int}, opti...
def expose(*methods): def setup(base): return expose_as(base.__name__, base, *methods) return setup
A decorator for exposing the methods of a class. Parameters ---------- *methods : str A str representation of the methods that should be exposed to callbacks. Returns ------- decorator : function A function accepting one argument - the class whose methods will be expose...
def _next_file(self): while True: if self._bucket_iter: try: return self._bucket_iter.next().filename except StopIteration: self._bucket_iter = None self._bucket = None if self._index >= len(self._filenames): return filename = self._filenames[s...
Find next filename. self._filenames may need to be expanded via listbucket. Returns: None if no more file is left. Filename otherwise.
def get_level(): handler, logger = find_handler(logging.getLogger(), match_stream_handler) return handler.level if handler else DEFAULT_LOG_LEVEL
Get the logging level of the root handler. :returns: The logging level of the root handler (an integer) or :data:`DEFAULT_LOG_LEVEL` (if no root handler exists).
def list_vnets(access_token, subscription_id): endpoint = ''.join([get_rm_endpoint(), '/subscriptions/', subscription_id, '/providers/Microsoft.Network/', '/virtualNetworks?api-version=', NETWORK_API]) return do_get(endpoint, access_token)
List the VNETs in a subscription . Args: access_token (str): A valid Azure authentication token. subscription_id (str): Azure subscription id. Returns: HTTP response. JSON body of VNets list with properties.
def tvdb_refresh_token(token): url = "https://api.thetvdb.com/refresh_token" headers = {"Authorization": "Bearer %s" % token} status, content = _request_json(url, headers=headers, cache=False) if status == 401: raise MapiProviderException("invalid token") elif status != 200 or not content.ge...
Refreshes JWT token Online docs: api.thetvdb.com/swagger#!/Authentication/get_refresh_token=
def _callback(self, ch, method, properties, body): get_logger().info("Message received! Calling listeners...") topic = method.routing_key dct = json.loads(body.decode('utf-8')) for listener in self.listeners: listener(self, topic, dct)
Internal method that will be called when receiving message.
def __load(self, redirect=True, preload=False): query_params = { "prop": "info|pageprops", "inprop": "url", "ppprop": "disambiguation", "redirects": "", } query_params.update(self.__title_query_param()) request = self.mediawiki.wiki_request...
load the basic page information
def name(self): try: return TIFF.TAGS[self.code] except KeyError: return str(self.code)
Return name of tag from TIFF.TAGS registry.
def total_number(slug, kind='1'): return TabPost.select().join( TabPost2Tag, on=(TabPost.uid == TabPost2Tag.post_id) ).where( (TabPost2Tag.tag_id == slug) & (TabPost.kind == kind) ).count()
Return the number of certian slug.
def child(self, **kwargs): return AutomatorDeviceObject( self.device, self.selector.clone().child(**kwargs) )
set childSelector.