code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def not26(func): @wraps(func) def errfunc(*args, **kwargs): raise NotImplementedError if hexversion < 0x02070000: return errfunc else: return func
Function decorator for methods not implemented in Python 2.6.
def terminate(self): logger.debug('client.terminate() called (state=%s)', self.strstate) if self.state == ClientState.WAITING_FOR_RESULT: raise ClientStateError('terimate() called while state='+self.strstate) if self.state == ClientState.TERMINATING: raise ClientStateErro...
Stop the server process and change our state to TERMINATING. Only valid if state=READY.
def safe_str_to_class(s): lst = s.split(".") klass = lst[-1] mod_list = lst[:-1] module = ".".join(mod_list) if not module: module = klass mod = my_import(module) if hasattr(mod, klass): return getattr(mod, klass) else: raise ImportError('')
Helper function to map string class names to module classes.
def reset(self): query = self.backend.library.database.connection.execute(query)
Drops index table.
def patch(self, request): attrs = ('edx_video_id', 'status') missing = [attr for attr in attrs if attr not in request.data] if missing: return Response( status=status.HTTP_400_BAD_REQUEST, data={'message': u'"{missing}" params must be specified.'.forma...
Update the status of a video.
def resetSession(self, username=None, password=None, verify=True) : self.disconnectSession() self.session = AikidoSession(username, password, verify)
resets the session
def list_all(): ret = [] if _sd_version() >= 219: for line in _machinectl('list-images')['stdout'].splitlines(): try: ret.append(line.split()[0]) except IndexError: continue else: rootdir = _root() try: for dirname i...
Lists all nspawn containers CLI Example: .. code-block:: bash salt myminion nspawn.list_all
def listDatawraps() : l = {"Genomes" : [], "SNPs" : []} for f in os.listdir(os.path.join(this_dir, "bootstrap_data/genomes")) : if f.find(".tar.gz") > -1 : l["Genomes"].append(f) for f in os.listdir(os.path.join(this_dir, "bootstrap_data/SNPs")) : if f.find(".tar.gz") > -1 : l["SNPs"].append(f) return l
Lists all the datawraps pyGeno comes with
def get_nodedata(self, sort_names=False): if not self.Node.n: return if not self.pflow.solved: logger.error('Power flow not solved when getting bus data.') return tuple([False] * 7) idx = self.Node.idx names = self.Node.name V = [self.dae.y[x] ...
get dc node data from solved power flow
def add_state(self, state, storage_load=False): assert isinstance(state, State) while state.state_id == self.state_id or state.state_id in self.states: state.change_state_id() if state.state_id in self._states.keys(): raise AttributeError("State id %s already exists in th...
Adds a state to the container state. :param state: the state that is going to be added :param storage_load: True if the state was directly loaded from filesystem :return: the state_id of the new state :raises exceptions.AttributeError: if state.state_id already exist
def get_agent_settings(): ret = dict() sorted_types = sorted(_SERVICE_TYPES.items(), key=lambda x: (-x[1], x[0])) ret['services'] = list() ret['contact'] = (__utils__['reg.read_value']( _HKEY, _AGENT_KEY, 'sysContact'))['vdata'] ret['location'] = (__utils__['reg.read_value']( _HKEY, ...
Determine the value of the SNMP sysContact, sysLocation, and sysServices settings. Returns: dict: A dictionary of the agent settings. CLI Example: .. code-block:: bash salt '*' win_snmp.get_agent_settings
def namespace_lower(self, namespace): return self.namespace(namespace, key_transform=lambda key: key.lower())
Return a copy with only the keys from a given namespace, lower-cased. The keys in the returned dict will be transformed to lower case after filtering, so they can be easily passed as keyword arguments to other functions. This is just syntactic sugar for calling :meth:`~ConfigLoader.name...
def _parse_boolean(element_text, state): value = None lowered_text = element_text.lower() if lowered_text == 'true': value = True elif lowered_text == 'false': value = False else: state.raise_error(InvalidPrimitiveValue, 'Invalid boolean value "{}"'.format(element_text)) ...
Parse the raw XML string as a boolean value.
def build_submit_description(executable, output, error, user_log, query_params): all_query_params = DEFAULT_QUERY_CLASSAD.copy() all_query_params.update(query_params) submit_description = [] for key, value in all_query_params.items(): submit_description.append('%s = %s' % (key, value)) submi...
Build up the contents of a condor submit description file. >>> submit_args = dict(executable='/path/to/script', output='o', error='e', user_log='ul') >>> submit_args['query_params'] = dict() >>> default_description = build_submit_description(**submit_args) >>> assert 'executable = /path/to/script' in d...
def run(self, n_iter=-1, bg=False): if n_iter == -1: if not self.eval_at: raise ValueError('Set n_iter or define evaluate_at.') n_iter = self.eval_at[-1] + 1 self._running.set() if bg: self._t = threading.Thread(target=lambda: self._run(n_iter)...
Run the experiment. :param int n_iter: Number of run iterations, by default will run until the last evaluation step. :param bool bg: whether to run in background (using a Thread)
def create_node(self, *args, **kwargs): with (yield from self._iou_id_lock): application_id = get_next_application_id(self.nodes) node = yield from super().create_node(*args, application_id=application_id, **kwargs) return node
Creates a new IOU VM. :returns: IOUVM instance
def __eliminate_unused_constraits (self, objects): result = [] for c in self.constraints_: if c [0] in objects and c [1] in objects: result.append (c) return result
Eliminate constraints which mention objects not in 'objects'. In graph-theory terms, this is finding subgraph induced by ordered vertices.
def create_queue_service(self): try: from azure.storage.queue.queueservice import QueueService return QueueService(self.account_name, self.account_key, sas_token=self.sas_token, is_emulated=self.is_emulated) except I...
Creates a QueueService object with the settings specified in the CloudStorageAccount. :return: A service object. :rtype: :class:`~azure.storage.queue.queueservice.QueueService`
def last_written_resolver(riak_object): riak_object.siblings = [max(riak_object.siblings, key=lambda x: x.last_modified), ]
A conflict-resolution function that resolves by selecting the most recently-modified sibling by timestamp. :param riak_object: an object-in-conflict that will be resolved :type riak_object: :class:`RiakObject <riak.riak_object.RiakObject>`
def get_key_by_job_id(cls, mapreduce_id): return db.Key.from_path(cls.kind(), str(mapreduce_id))
Retrieves the Key for a Job. Args: mapreduce_id: The job to retrieve. Returns: Datastore Key that can be used to fetch the MapreduceState.
def _add_dispatcher(self, path_regex, dispatch_function): self._dispatchers.append((re.compile(path_regex), dispatch_function))
Add a request path and dispatch handler. Args: path_regex: A string regex, the path to match against incoming requests. dispatch_function: The function to call for these requests. The function should take (request, start_response) as arguments and return the contents of the response bo...
def preprocess(cls, cat): if isinstance(cat, str): cat = intake.open_catalog(cat) return cat
Function to run on each cat input
def execution_timer(self, *path): start = time.time() try: yield finally: self.record_timing(max(start, time.time()) - start, *path)
Record the time it takes to perform an arbitrary code block. :param path: elements of the metric path to record This method returns a context manager that records the amount of time spent inside of the context and submits a timing metric to the specified `path` using (:meth:`record_tim...
def inspect_swarm(self): url = self._url('/swarm') return self._result(self._get(url), True)
Retrieve low-level information about the current swarm. Returns: A dictionary containing data about the swarm. Raises: :py:class:`docker.errors.APIError` If the server returns an error.
def _parse_queue_list(list_output): queues = dict((q.split('/')[-1], q) for q in list_output['stdout']) return queues
Parse the queue to get a dict of name -> URL
def pickle_from_param(elem, name): return pickle.loads(str(get_pyvalue(elem, u"pickle:%s" % name)))
Retrieve a pickled Python object from the document tree rooted at elem.
def field_for(self, field_id): for field in self.fields: if field.id == field_id: return field return None
Fetches the field for the given Field ID. :param field_id: ID for Field to fetch. :return: :class:`ContentTypeField <ContentTypeField>` object. :rtype: contentful.ContentTypeField
def search_schema_path(self, index, **options): if not self.yz_wm_schema: raise RiakError("Yokozuna search is unsupported by this Riak node") return mkpath(self.yz_wm_schema, "schema", quote_plus(index), **options)
Builds a Yokozuna search Solr schema URL. :param index: a name of a yz solr schema :type index: string :param options: optional list of additional arguments :type index: dict :rtype URL string
def _download_movielens(dest_path): url = 'http://files.grouplens.org/datasets/movielens/ml-100k.zip' req = requests.get(url, stream=True) with open(dest_path, 'wb') as fd: for chunk in req.iter_content(): fd.write(chunk)
Download the dataset.
def DbGetDeviceAliasList(self, argin): self._log.debug("In DbGetDeviceAliasList()") if not argin: argin = "%" else: argin = replace_wildcard(argin) return self.db.get_device_alias_list(argin)
Get device alias name with a specific filter :param argin: The filter :type: tango.DevString :return: Device alias list :rtype: tango.DevVarStringArray
def frame_size(self): if self.sample_type == SampleType.S16NativeEndian: return self.sample_size * self.channels else: raise ValueError('Unknown sample type: %d', self.sample_type)
The byte size of a single frame of this format.
def load_library(self): "loads configuration options" try: filename = self.environment.get_template('chartkick.json').filename except TemplateNotFound: return {} else: options = Options() options.load(filename) return options
loads configuration options
def rename(df, **kwargs): return df.rename(columns={v: k for k, v in kwargs.items()})
Renames columns, where keyword argument values are the current names of columns and keys are the new names. Args: df (:obj:`pandas.DataFrame`): DataFrame passed in via `>>` pipe. Kwargs: **kwargs: key:value pairs where keys are new names for columns and values are current names...
def restart(uuid, **kwargs): from .worker_engine import restart_worker return text_type(restart_worker(uuid, **kwargs).uuid)
Restart the workflow from a given workflow engine UUID.
def unload_fixture(apps, schema_editor): "Brutally deleting all entries for this model..." MyModel = apps.get_model("blog", "Post") MyModel.objects.all().delete()
Brutally deleting all entries for this model...
def _hasattr(self, fieldname): special = 'history', 'raw' return (fieldname in special or fieldname in self._defn.fieldmap or fieldname in self._defn.derivationmap)
Returns True if this packet contains fieldname, False otherwise.
def list_rbac_policies(self, retrieve_all=True, **_params): return self.list('rbac_policies', self.rbac_policies_path, retrieve_all, **_params)
Fetch a list of all RBAC policies for a project.
def submit(self): self._newflg = False ret = list() for buf in self._buffer.values(): buf = copy.deepcopy(buf) if self._fdpext: buf['fpout'] = f"{self._fproot}/{buf['label']}.{self._fdpext}" else: del buf['fpout'] bu...
Submit traced TCP flows.
def logout(request): user = request.user serializer = LogoutSerializer(data=request.data) serializer.is_valid(raise_exception=True) data = serializer.validated_data if should_authenticate_session(): auth.logout(request) if should_retrieve_token() and data['revoke_token']: try: ...
Logs out the user. returns an error if the user is not authenticated.
def init(args=None, lib='standard'): if args is None: args = sys.argv _loadlib(lib) arr = (ctypes.c_char_p * len(args))() arr[:] = args _LIB.RabitInit(len(args), arr)
Intialize the rabit module, call this once before using anything. Parameters ---------- args: list of str, optional The list of arguments used to initialized the rabit usually you need to pass in sys.argv. Defaults to sys.argv when it is None. lib: {'standard', 'mock', 'mpi'} ...
def bestDescription(self, prefLanguage="en"): test_preds = [rdflib.RDFS.comment, rdflib.namespace.DCTERMS.description, rdflib.namespace.DC.description, rdflib.namespace.SKOS.definition] for pred in test_preds: test = self.getValuesForProperty(pred) if test: ...
facility for extrating the best available description for an entity ..This checks RFDS.label, SKOS.prefLabel and finally the qname local component
def handle_abort(self, obj): async_to_sync(consumer.send_event)({ WorkerProtocol.COMMAND: WorkerProtocol.ABORT, WorkerProtocol.DATA_ID: obj[ExecutorProtocol.DATA_ID], WorkerProtocol.FINISH_COMMUNICATE_EXTRA: { 'executor': getattr(settings, 'FLOW_EXECUTOR', {})...
Handle an incoming ``Data`` abort processing request. .. IMPORTANT:: This only makes manager's state consistent and doesn't affect Data object in any way. Any changes to the Data must be applied over ``handle_update`` method. :param obj: The Channels message object...
def get_group_line(self, data): idx = -1 for key in self.groups: i = self.get_group_key_line(data, key) if (i < idx and i != -1) or idx == -1: idx = i return idx
Get the next group-style key's line. :param data: the data to proceed :returns: the line number
def add_to_replication_queue(source_node_urn, sysmeta_pyxb): replica_info_model = d1_gmn.app.models.replica_info( status_str='queued', source_node_urn=source_node_urn ) local_replica_model = d1_gmn.app.models.local_replica( pid=d1_common.xml.get_req_val(sysmeta_pyxb.identifier), repl...
Add a replication request issued by a CN to a queue that is processed asynchronously. Preconditions: - sysmeta_pyxb.identifier is verified to be available for create. E.g., with d1_gmn.app.views.is_valid_pid_for_create(pid). Postconditions: - The database is set up to track a new replica, wi...
def start_circle_left(self, radius_m, velocity=VELOCITY): circumference = 2 * radius_m * math.pi rate = 360.0 * velocity / circumference self._set_vel_setpoint(velocity, 0.0, 0.0, -rate)
Start a circular motion to the left. This function returns immediately. :param radius_m: The radius of the circle (meters) :param velocity: The velocity of the motion (meters/second) :return:
def get_name_from_name_hash128( self, name ): cur = self.db.cursor() name = namedb_get_name_from_name_hash128( cur, name, self.lastblock ) return name
Get the name from a name hash
def routers_removed_from_hosting_device(self, context, router_ids, hosting_device): self._agent_notification_bulk( context, 'router_removed_from_hosting_device', router_ids, hosting_device, operation=None)
Notify cfg agent that routers have been removed from hosting device. @param: context - information about tenant, user etc @param: router-ids - list of ids @param: hosting_device - device hosting the routers
def cudnnGetConvolution2dForwardOutputDim(convDesc, inputTensorDesc, wDesc): n = ctypes.c_int() c = ctypes.c_int() h = ctypes.c_int() w = ctypes.c_int() status = _libcudnn.cudnnGetConvolution2dForwardOutputDim(convDesc, inputTensorDesc, wDesc, ctypes....
Return the dimensions of the output tensor given a convolution descriptor. This function returns the dimensions of the resulting 4D tensor of a 2D convolution, given the convolution descriptor, the input tensor descriptor and the filter descriptor. This function can help to setup the output tensor and allo...
def can_allow_multiple_input_shapes(spec): try: layers = _get_nn_layers(spec) except: raise Exception('Unable to verify that this model contains a neural network.') try: shaper = NeuralNetworkShaper(spec, False) except: raise Exception('Unable to compute shapes for this n...
Examines a model specification and determines if it can compute results for more than one output shape. :param spec: MLModel The protobuf specification of the model. :return: Bool Returns True if the model can allow multiple input shapes, False otherwise.
def map_copy(source: tcod.map.Map, dest: tcod.map.Map) -> None: if source.width != dest.width or source.height != dest.height: dest.__init__( source.width, source.height, source._order ) dest._Map__buffer[:] = source._Map__buffer[:]
Copy map data from `source` to `dest`. .. deprecated:: 4.5 Use Python's copy module, or see :any:`tcod.map.Map` and assign between array attributes manually.
def maybe_download_and_extract(): dest_directory = "/tmp/cifar" if not os.path.exists(dest_directory): os.makedirs(dest_directory) filename = DATA_URL.split('/')[-1] filepath = os.path.join(dest_directory, filename) if not os.path.exists(filepath): def _progress(count, block_size, total_size): s...
Download and extract the tarball from Alex's website.
def remove(self, game_object: Hashable) -> None: self.all.remove(game_object) for kind in type(game_object).mro(): self.kinds[kind].remove(game_object) for s in self.tags.values(): s.discard(game_object)
Remove the given object from the container. game_object: A hashable contained by container. Example: container.remove(myObject)
def _traverse_relationship_objs(self, rel2src2dsts, goobj_child, goids_seen): child_id = goobj_child.id goids_seen.add(child_id) for goid_altid in goobj_child.alt_ids: goids_seen.add(goid_altid) for reltype, recs in goobj_child.relationship.items(): if reltype in ...
Traverse from source GO up relationships.
def list_styles(self): known = sorted(self.defaults.known_styles) if not known: err_exit('No styles', 0) for style in known: if style == self.defaults.default_style: print(style, '(default)') else: print(style) sys.exit(...
Print available styles and exit.
def tail(ctx): click.echo('tailing logs') for e in ctx.tail()[-10:]: ts = datetime.utcfromtimestamp(e['timestamp'] // 1000).isoformat() click.echo("{}: {}".format(ts, e['message'])) click.echo('done')
Show the last 10 lines of the log file
def remove_user(self, workspace, params={}, **options): path = "/workspaces/%s/removeUser" % (workspace) return self.client.post(path, params, **options)
The user making this call must be an admin in the workspace. Returns an empty data record. Parameters ---------- workspace : {Id} The workspace or organization to invite the user to. [data] : {Object} Data for the request - user : {String} An identifier for the user. C...
def _get_order_by(self, request): attr = request.params.get('sort', request.params.get('order_by')) if attr is None or not hasattr(self.mapped_class, attr): return None if request.params.get('dir', '').upper() == 'DESC': return desc(getattr(self.mapped_class, attr)) ...
Return an SA order_by
def filter_data(data, filter_dict): for key, match_string in filter_dict.items(): if key not in data: logger.warning("{0} doesn't match a top level key".format(key)) continue values = data[key] matcher = re.compile(match_string) if isinstance(values, list): ...
filter a data dictionary for values only matching the filter
def _make_callsites(self, stack_pointer_tracker=None): rd = self.project.analyses.ReachingDefinitions(func=self.function, func_graph=self.graph, observe_all=True) for key in self._blocks: block = self._blocks[key] csm = self.project.analyses.AILCallSiteMaker(block, reaching_defin...
Simplify all function call statements. :return: None
def unbound_dimensions(streams, kdims, no_duplicates=True): params = stream_parameters(streams, no_duplicates) return [d for d in kdims if d not in params]
Return a list of dimensions that have not been associated with any streams.
def list_folder(cls, session, mailbox, folder): return cls( '/mailboxes/%d/folders/%s/conversations.json' % ( mailbox.id, folder.id, ), session=session, )
Return conversations in a specific folder of a mailbox. Args: session (requests.sessions.Session): Authenticated session. mailbox (helpscout.models.Mailbox): Mailbox that folder is in. folder (helpscout.models.Folder): Folder to list. Returns: RequestPag...
def update_properties(self, properties, email_to_addresses=None, email_cc_addresses=None, email_insert=None): volreq_obj = copy.deepcopy(properties) volreq_obj['operation'] = 'modify' volreq_obj['element-uri'] = self.uri body = { 'storage-volumes': [...
Update writeable properties of this storage volume on the HMC, and optionally send emails to storage administrators requesting modification of the storage volume on the storage subsystem and of any resources related to the storage volume. This method performs the "Modify Storage Group P...
def extractSurface(image, radius=0.5): fe = vtk.vtkExtractSurface() fe.SetInputData(image) fe.SetRadius(radius) fe.Update() return Actor(fe.GetOutput())
``vtkExtractSurface`` filter. Input is a ``vtkImageData``. Generate zero-crossing isosurface from truncated signed distance volume.
def replay_sync(self, live=False): 'Replay all commands in log.' self.cursorRowIndex = 0 CommandLog.currentReplay = self with Progress(total=len(self.rows)) as prog: while self.cursorRowIndex < len(self.rows): if CommandLog.currentReplay is None: ...
Replay all commands in log.
def _kill_process(proc): try: proc.kill() except AccessDenied: logs.debug(u'Rerun: process PID {} ({}) could not be terminated'.format( proc.pid, proc.exe()))
Tries to kill the process otherwise just logs a debug message, the process will be killed when thefuck terminates. :type proc: Process
def skip_connection_distance(a, b): if a[2] != b[2]: return 1.0 len_a = abs(a[1] - a[0]) len_b = abs(b[1] - b[0]) return (abs(a[0] - b[0]) + abs(len_a - len_b)) / (max(a[0], b[0]) + max(len_a, len_b))
The distance between two skip-connections.
def get_channel_comment(self, name=None, group=None, index=None): gp_nr, ch_nr = self._validate_channel_selection(name, group, index) grp = self.groups[gp_nr] channel = grp.channels[ch_nr] return extract_cncomment_xml(channel.comment)
Gets channel comment. Channel can be specified in two ways: * using the first positional argument *name* * if there are multiple occurrences for this channel then the *group* and *index* arguments can be used to select a specific group. * if there a...
def check_driver_dependencies(driver, dependencies): ret = True for key, value in six.iteritems(dependencies): if value is False: log.warning( "Missing dependency: '%s'. The %s driver requires " "'%s' to be installed.", key, driver, key ) ...
Check if the driver's dependencies are available. .. versionadded:: 2015.8.0 driver The name of the driver. dependencies The dictionary of dependencies to check.
def page(self, category=values.unset, start_date=values.unset, end_date=values.unset, include_subaccounts=values.unset, page_token=values.unset, page_number=values.unset, page_size=values.unset): params = values.of({ 'Category': category, 'StartDate...
Retrieve a single page of DailyInstance records from the API. Request is executed immediately :param DailyInstance.Category category: The usage category of the UsageRecord resources to read :param date start_date: Only include usage that has occurred on or after this date :param date en...
def _function_add_call_edge(self, addr, src_node, function_addr, syscall=False, stmt_idx=None, ins_addr=None): try: if src_node is None: self.kb.functions._add_node(function_addr, addr, syscall=syscall) else: src_snippet = self._to_snippet(cfg_node=src_nod...
Add a call edge to the function transition map. :param int addr: Address that is being called (callee). :param CFGNode src_node: The source CFG node (caller). :param int ret_addr: Address that returns to (in case the function returns). :param int function_addr: Function address.. ...
def _max_args(self, f): if f.func_defaults is None: return f.func_code.co_argcount return f.func_code.co_argcount + len(f.func_defaults)
Returns maximum number of arguments accepted by given function.
def close(self): if isinstance(self._session, requests.Session): self._session.close()
Close http session.
def connect_float_text(instance, prop, widget, fmt="{:g}"): if callable(fmt): format_func = fmt else: def format_func(x): return fmt.format(x) def update_prop(): val = widget.text() try: setattr(instance, prop, float(val)) except ValueError: ...
Connect a numerical callback property with a Qt widget containing text. Parameters ---------- instance : object The class instance that the callback property is attached to prop : str The name of the callback property widget : QtWidget The Qt widget to connect. This should i...
def get_instructions(self): tmp_ins = [] idx = 0 for i in self.method.get_instructions(): if idx >= self.start and idx < self.end: tmp_ins.append(i) idx += i.get_length() return tmp_ins
Get all instructions from a basic block. :rtype: Return all instructions in the current basic block
def distance_to_angle(distance, units='metric'): if units in ('km', 'metric'): pass elif units in ('sm', 'imperial', 'US customary'): distance *= STATUTE_MILE elif units in ('nm', 'nautical'): distance *= NAUTICAL_MILE else: raise ValueError('Unknown units type %r' % unit...
Convert a distance in to an angle along a great circle. Args: distance (float): Distance to convert to degrees units (str): Unit type to be used for distances Returns: float: Angle in degrees Raises: ValueError: Unknown value for ``units``
def select_by_key(self, key): self._selected_key = None self._selected_item = None for item in self.children.values(): item.attributes['selected'] = False if key in self.children: self.children[key].attributes['selected'] = True self._selected_key = ke...
Selects an item by its key. Args: key (str): The unique string identifier of the item that have to be selected.
def truepath_relative(path, otherpath=None): if otherpath is None: otherpath = os.getcwd() otherpath = truepath(otherpath) path_ = normpath(relpath(path, otherpath)) return path_
Normalizes and returns absolute path with so specs Args: path (str): path to file or directory otherpath (None): (default = None) Returns: str: path_ CommandLine: python -m utool.util_path --exec-truepath_relative --show Example: >>> # ENABLE_DOCTEST ...
def wrap(self, text, **kwargs): pilcrow = re.compile(r'(\n\s*\n)', re.MULTILINE) list_prefix = re.compile(r'\s*(?:\w|[0-9]+)[\.\)]\s+') paragraphs = pilcrow.split(text) wrapped_lines = [] for paragraph in paragraphs: if paragraph.isspace(): wrapped_lin...
Wraps each paragraph in ``text`` individually. Parameters ---------- text : str Returns ------- str Single string containing the wrapped paragraphs.
def Reynolds_valve(nu, Q, D1, FL, Fd, C): r return N4*Fd*Q/nu/(C*FL)**0.5*(FL**2*C**2/(N2*D1**4) + 1)**0.25
r'''Calculates Reynolds number of a control valve for a liquid or gas flowing through it at a specified Q, for a specified D1, FL, Fd, C, and with kinematic viscosity `nu` according to IEC 60534 calculations. .. math:: Re_v = \frac{N_4 F_d Q}{\nu \sqrt{C F_L}}\left(\frac{F_L^2 C^2} {N_2D^4}...
def set_value(self, value): v = 0 measure_unit = 'px' try: v = int(float(value.replace('px', ''))) except ValueError: try: v = int(float(value.replace('%', ''))) measure_unit = '%' except ValueError: pass...
The value have to be in the form '10px' or '10%', so numeric value plus measure unit
def from_samples(cls, samples_like, vectors, info, vartype, variable_labels=None): try: samples = np.asarray(samples_like, dtype=np.int8) except TypeError: samples, variable_labels = _samples_dicts_to_array(samples_like, variable_labels) assert samples.dtype == np.int8, '...
Build a response from samples. Args: samples_like: A collection of samples. 'samples_like' is an extension of NumPy's array_like to include an iterable of sample dictionaries (as returned by :meth:`.Response.samples`). data_vectors (dict[...
def to_global(s): if s.startswith('GPSTime'): s = 'Gps' + s[3:] if '_' in s: s = "".join([i.capitalize() for i in s.split("_")]) return s[0].lower() + s[1:]
Format a global variable name.
def follow(user, obj, send_action=True, actor_only=True, flag='', **kwargs): check(obj) instance, created = apps.get_model('actstream', 'follow').objects.get_or_create( user=user, object_id=obj.pk, flag=flag, content_type=ContentType.objects.get_for_model(obj), actor_only=actor_only ...
Creates a relationship allowing the object's activities to appear in the user's stream. Returns the created ``Follow`` instance. If ``send_action`` is ``True`` (the default) then a ``<user> started following <object>`` action signal is sent. Extra keyword arguments are passed to the action.send ca...
def load(self, shapefile=None): if shapefile: (shapeName, ext) = os.path.splitext(shapefile) self.shapeName = shapeName try: self.shp = open("%s.shp" % shapeName, "rb") except IOError: raise ShapefileException("Unable to open...
Opens a shapefile from a filename or file-like object. Normally this method would be called by the constructor with the file object or file name as an argument.
def calc_downsample(w, h, target=400): if w > h: return h / target elif h >= w: return w / target
Calculate downsampling value.
def get_values(self, set, selected_meta): warnings.warn("\n\nThis method assumes that the last level of the index is the sample_id.\n" "In case of single index, the index itself should be the sample_id") sample_ids = set.index.get_level_values(-1) corresponding_meta = self....
Retrieves the selected metadata values of the given set :param set: cluster that contains the data :param selected_meta: the values of the selected_meta :return: the values of the selected meta of the cluster
def target(self): task = yield self.task() if not task: yield defer.succeed(None) defer.returnValue(None) defer.returnValue(task.target)
Find the target name for this build. :returns: deferred that when fired returns the build task's target name. If we could not determine the build task, or the task's target, return None.
def async_run(self, keyword, *args, **kwargs): handle = self._last_thread_handle thread = self._threaded(keyword, *args, **kwargs) thread.start() self._thread_pool[handle] = thread self._last_thread_handle += 1 return handle
Executes the provided Robot Framework keyword in a separate thread and immediately returns a handle to be used with async_get
def setInstrument(self, instrument, override_analyses=False): analyses = [an for an in self.getAnalyses() if (not an.getInstrument() or override_analyses) and an.isInstrumentAllowed(instrument)] total = 0 for an in analyses: instr_methods = ins...
Sets the specified instrument to the Analysis from the Worksheet. Only sets the instrument if the Analysis allows it, according to its Analysis Service and Method. If an analysis has already assigned an instrument, it won't be overriden. The Analyses that don'...
def get_prop_value(name, props, default=None): if not props: return default try: return props[name] except KeyError: return default
Returns the value of a property or the default one :param name: Name of a property :param props: Dictionary of properties :param default: Default value :return: The value of the property or the default one
def open_file_like(f, mode): new_fd = isinstance(f, (str, pathlib.Path)) if new_fd: f = open(f, mode) try: yield f finally: if new_fd: f.close()
Wrapper for opening a file
def focusd(task): if registration.get_registered(event_hooks=True, root_access=True): start_cmd_srv = (os.getuid() == 0) else: start_cmd_srv = False _run = lambda: Focusd(task).run(start_cmd_srv) daemonize(get_daemon_pidfile(task), task.task_dir, _run)
Forks the current process as a daemon to run a task. `task` ``Task`` instance for the task to run.
def __ordinal(self, num): if 10 <= num % 100 < 20: return str(num) + 'th' else: ord_info = {1: 'st', 2: 'nd', 3: 'rd'}.get(num % 10, 'th') return '{}{}'.format(num, ord_info)
Returns the ordinal number of a given integer, as a string. eg. 1 -> 1st, 2 -> 2nd, 3 -> 3rd, etc.
def execute(self, query, *multiparams, **params): coro = self._execute(query, *multiparams, **params) return _SAConnectionContextManager(coro)
Executes a SQL query with optional parameters. query - a SQL query string or any sqlalchemy expression. *multiparams/**params - represent bound parameter values to be used in the execution. Typically, the format is a dictionary passed to *multiparams: await conn.execute( ...
def disable_cors(self): return self.update_cors_configuration( enable_cors=False, allow_credentials=False, origins=[], overwrite_origins=True )
Switches CORS off. :returns: CORS status in JSON format
def chart(self, x=None, y=None, chart_type=None, opts=None, style=None, label=None, options={}, **kwargs): try: self.chart_obj = self._chart(x, y, chart_type, opts, style, label, options=options, **kwargs) except Exception as e: self.err(e, self.chart, "Can not create chart")
Get a chart
def _lookup_attributes(glyph_name, data): attributes = ( data.names.get(glyph_name) or data.alternative_names.get(glyph_name) or data.production_names.get(glyph_name) or {} ) return attributes
Look up glyph attributes in data by glyph name, alternative name or production name in order or return empty dictionary. Look up by alternative and production names for legacy projects and because of issue #232.
def read_string_data(file, number_values, endianness): offsets = [0] for i in range(number_values): offsets.append(types.Uint32.read(file, endianness)) strings = [] for i in range(number_values): s = file.read(offsets[i + 1] - offsets[i]) strings.append(s.decode('utf-8')) ret...
Read string raw data This is stored as an array of offsets followed by the contiguous string data.
def loss(logits, labels): labels = tf.cast(labels, tf.int64) cross_entropy = tf.nn.sparse_softmax_cross_entropy_with_logits( labels=labels, logits=logits, name='cross_entropy_per_example') cross_entropy_mean = tf.reduce_mean(cross_entropy, name='cross_entropy') tf.add_to_collection('losses', cross_entropy...
Add L2Loss to all the trainable variables. Add summary for "Loss" and "Loss/avg". Args: logits: Logits from inference(). labels: Labels from distorted_inputs or inputs(). 1-D tensor of shape [batch_size] Returns: Loss tensor of type float.
def read_html_file(filename): with open(os.path.join(get_static_directory(), 'html/{filename}'.format(filename=filename))) as f: contents = f.read() return contents
Reads the contents of an html file in the css directory @return: Contents of the specified file