code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def to_utc_date(date): return datetime.utcfromtimestamp(float(date.strftime('%s'))).replace(tzinfo=None) if date else None
Convert a datetime object from local to UTC format >>> import datetime >>> d = datetime.datetime(2017, 8, 15, 18, 24, 31) >>> to_utc_date(d) datetime.datetime(2017, 8, 16, 1, 24, 31) Args: date (`datetime`): Input datetime object Returns: `datetime`
def add_matplotlib_cmaps(fail_on_import_error=True): try: from matplotlib import cm as _cm from matplotlib.cbook import mplDeprecation except ImportError: if fail_on_import_error: raise return for name in _cm.cmap_d: if not isinstance(name, str): ...
Add all matplotlib colormaps.
def fit(self, data, debug=False): data = util.apply_filter_query(data, self.fit_filters) unique = data[self.segmentation_col].unique() value_counts = data[self.segmentation_col].value_counts() gone = set(self._group.models) - set(unique) for g in gone: del self._group...
Fit each segment. Segments that have not already been explicitly added will be automatically added with default model and ytransform. Parameters ---------- data : pandas.DataFrame Must have a column with the same name as `segmentation_col`. debug : bool I...
def assign(self, pm): if isinstance(pm, QPixmap): self._pm = pm else: self._xpmstr = pm self._pm = None self._icon = None
Reassign pixmap or xpm string array to wrapper
def _get_deleted_at_column(self, builder): if len(builder.get_query().joins) > 0: return builder.get_model().get_qualified_deleted_at_column() else: return builder.get_model().get_deleted_at_column()
Get the "deleted at" column for the builder. :param builder: The query builder :type builder: orator.orm.builder.Builder :rtype: str
def pause(self, message: Optional[Message_T] = None, **kwargs) -> None: if message: asyncio.ensure_future(self.send(message, **kwargs)) raise _PauseException
Pause the session for further interaction.
def _resolve_key(self, key): with self._reserve(key): factory = self.factory_for(key) with self._profiler(key): component = factory(self) invoke_resolve_hook(component) return self.assign(key, component)
Attempt to lazily create a component. :raises NotBoundError: if the component does not have a bound factory :raises CyclicGraphError: if the factory function requires a cycle :raises LockedGraphError: if the graph is locked
def _recursive_merged_items(self, index): subdirs = [os.path.join(d, "parts", str(index)) for d in self.localdirs] m = ExternalMerger(self.agg, self.memory_limit, self.serializer, subdirs, self.scale * self.partitions, self.partitions, self.batch) m.pdata = [{} for _ i...
merge the partitioned items and return the as iterator If one partition can not be fit in memory, then them will be partitioned and merged recursively.
def create_alarm_subscription(self, on_data=None, timeout=60): manager = WebSocketSubscriptionManager(self._client, resource='alarms') subscription = AlarmSubscription(manager) wrapped_callback = functools.partial( _...
Create a new alarm subscription. :param on_data: Function that gets called with :class:`.AlarmEvent` updates. :param float timeout: The amount of seconds to wait for the request to complete. :return: A Future that can be used to manage the...
def from_file(cls, h5_file): return cls({ country: HDF5DailyBarReader.from_file(h5_file, country) for country in h5_file.keys() })
Construct from an h5py.File. Parameters ---------- h5_file : h5py.File An HDF5 daily pricing file.
def geometricBar(weights, alldistribT): assert(len(weights) == alldistribT.shape[1]) return np.exp(np.dot(np.log(alldistribT), weights.T))
return the weighted geometric mean of distributions
def read_plugin_config(self): folders = self.config["pluginfolders"] modules = plugins.get_plugin_modules(folders) for pluginclass in plugins.get_plugin_classes(modules): section = pluginclass.__name__ if self.has_section(section): self.config["enabledplug...
Read plugin-specific configuration values.
def download(self, streamed=False, action=None, chunk_size=1024, **kwargs): path = '/projects/%s/export/download' % self.project_id result = self.manager.gitlab.http_get(path, streamed=streamed, raw=True, **kwargs) return utils.response_content(resul...
Download the archive of a project export. Args: streamed (bool): If True the data will be processed by chunks of `chunk_size` and each chunk is passed to `action` for reatment action (callable): Callable responsible of dealing with chunk of ...
def _build_idp_config_endpoints(self, config, providers): idp_endpoints = [] for endp_category in self.endpoints: for func, endpoint in self.endpoints[endp_category].items(): for provider in providers: _endpoint = "{base}/{provider}/{endpoint}".format( ...
Builds the final frontend module config :type config: dict[str, Any] :type providers: list[str] :rtype: dict[str, Any] :param config: The module config :param providers: A list of backend names :return: The final config
def handle(): try: cli = ZappaCLI() sys.exit(cli.handle()) except SystemExit as e: cli.on_exit() sys.exit(e.code) except KeyboardInterrupt: cli.on_exit() sys.exit(130) except Exception as e: cli.on_exit() click.echo("Oh no! An " + click.sty...
Main program execution handler.
def get_instance(self, payload): return AuthCallsCredentialListMappingInstance( self._version, payload, account_sid=self._solution['account_sid'], domain_sid=self._solution['domain_sid'], )
Build an instance of AuthCallsCredentialListMappingInstance :param dict payload: Payload response from the API :returns: twilio.rest.api.v2010.account.sip.domain.auth_types.auth_calls_mapping.auth_calls_credential_list_mapping.AuthCallsCredentialListMappingInstance :rtype: twilio.rest.api.v201...
def build_cycle_time(self, build_id): json_form = self.__retrieve_as_json(self.builds_path % build_id) return BuildCycleTime( build_id, json_form[u'buildTypeId'], as_date(json_form, u'startDate'), (as_date(json_form, u'finishDate') - as_date(json_form, u'q...
Returns a BuildCycleTime object for the given build
def _get_cmd(cmd): check_cmd = "RunTHetA.py" try: local_cmd = subprocess.check_output(["which", check_cmd]).strip() except subprocess.CalledProcessError: return None return [sys.executable, "%s/%s" % (os.path.dirname(os.path.realpath(local_cmd)), cmd)]
Retrieve required commands for running THetA with our local bcbio python.
def process_wildcard(fractions): wildcard_zs = set() total_fraction = 0.0 for z, fraction in fractions.items(): if fraction == '?': wildcard_zs.add(z) else: total_fraction += fraction if not wildcard_zs: return fractions balance_fraction = (1.0 - total...
Processes element with a wildcard ``?`` weight fraction and returns composition balanced to 1.0.
def download_file(self, url, local_path): response = requests.get(url, stream=True) with open(local_path, 'wb') as f: for chunk in tqdm(response.iter_content(chunk_size=1024), unit='KB'): if chunk: f.write(chunk) f.flush()
Download a file from a remote host.
def list_values(hive, key=None, use_32bit_registry=False, include_default=True): r return __utils__['reg.list_values'](hive=hive, key=key, use_32bit_registry=use_32bit_registry, include_defaul...
r''' Enumerates the values in a registry key or hive. Args: hive (str): The name of the hive. Can be one of the following: - HKEY_LOCAL_MACHINE or HKLM - HKEY_CURRENT_USER or HKCU - HKEY_USER or HKU - HKEY_CLASSES_ROOT or HKC...
def lazy_property(fn): attr_name = '_lazy_' + fn.__name__ @property @wraps(fn) def _lazy_property(self): if not hasattr(self, attr_name): setattr(self, attr_name, fn(self)) return getattr(self, attr_name) return _lazy_property
Decorator that makes a property lazy-evaluated whilst preserving docstrings. Args: fn (function): the property in question Returns: evaluated version of the property.
def get_opener(self, name): if name not in self.registry: raise NoOpenerError("No opener for %s" % name) index = self.registry[name] return self.openers[index]
Retrieve an opener for the given protocol :param name: name of the opener to open :type name: string :raises NoOpenerError: if no opener has been registered of that name
def connect(self, nice_quit_ev): _logger.debug("Connecting to explicit server node: [%s]", self.server_host) try: c = self.primitive_connect() except gevent.socket.error: _logger.exception("Could not connect to explicit server: [%s]", ...
Connect the server. We expect this to implement connection logistics for servers that were explicitly prescribed to us.
def iterate_schema(fields, schema, path_prefix=''): if path_prefix and path_prefix[-1] != '.': path_prefix += '.' for field_schema in schema: name = field_schema['name'] if 'group' in field_schema: for rvals in iterate_schema(fields[name] if name in fields else {}, ...
Iterate over all schema sub-fields. This will iterate over all field definitions in the schema. Some field v alues might be None. :param fields: field values to iterate over :type fields: dict :param schema: schema to iterate over :type schema: dict :param path_prefix: dot separated path p...
def add_ds_ids_from_files(self): for file_handlers in self.file_handlers.values(): try: fh = file_handlers[0] avail_ids = fh.available_datasets() except NotImplementedError: continue for ds_id, ds_info in avail_ids: ...
Check files for more dynamically discovered datasets.
def case_sensitive_name(self, package_name): if len(self.environment[package_name]): return self.environment[package_name][0].project_name
Return case-sensitive package name given any-case package name @param project_name: PyPI project name @type project_name: string
def download_if_not_exists(url: str, filename: str, skip_cert_verify: bool = True, mkdir: bool = True) -> None: if os.path.isfile(filename): log.info("No need to download, already have: {}", filename) return if mkdir: directory, basen...
Downloads a URL to a file, unless the file already exists.
def is_valid(obj: JSGValidateable, log: Optional[Union[TextIO, Logger]] = None) -> bool: return obj._is_valid(log)
Determine whether obj is valid :param obj: Object to validate :param log: Logger to record validation failures. If absent, no information is recorded
def reset(self): self._current_index = -1 self._current_value = self._default_value self._current_rendered = self._default_rendered self.offset = None
Reset the field to its default state
def _create_scaling_policies(conn, as_name, scaling_policies): 'helper function to create scaling policies' if scaling_policies: for policy in scaling_policies: policy = autoscale.policy.ScalingPolicy( name=policy["name"], as_name=as_name, adju...
helper function to create scaling policies
def load_xml(self, xmlfile): self.logger.info('Loading XML') for c in self.components: c.load_xml(xmlfile) for name in self.like.sourceNames(): self.update_source(name) self._fitcache = None self.logger.info('Finished Loading XML')
Load model definition from XML. Parameters ---------- xmlfile : str Name of the input XML file.
def blocks(self, lines): state = markdown.blockparser.State() blocks = [] state.set('start') currblock = 0 for line in lines: line += '\n' if state.isstate('start'): if line[:3] == '```': state.set('```') ...
Groups lines into markdown blocks
def graph_edges(self): edges = nx.get_edge_attributes(self._graph, 'branch').items() edges_sorted = sorted(list(edges), key=lambda _: (''.join(sorted([repr(_[0][0]),repr(_[0][1])])))) for edge in edges_sorted: yield {'adj_nodes': edge[0], 'branch': edge[1]}
Returns a generator for iterating over graph edges The edge of a graph is described by the two adjacent node and the branch object itself. Whereas the branch object is used to hold all relevant power system parameters. Yields ------ int Description #TODO che...
def incr(self, att, val=1): if att not in self.counters: raise ValueError("%s is not a counter.") self.db.hincrby(self.key(), att, val)
Increments a counter.
def _write_scalar(self, name:str, scalar_value, iteration:int)->None: "Writes single scalar value to Tensorboard." tag = self.metrics_root + name self.tbwriter.add_scalar(tag=tag, scalar_value=scalar_value, global_step=iteration)
Writes single scalar value to Tensorboard.
def GetClientOs(client_id, token=None): if data_store.RelationalDBEnabled(): kb = data_store.REL_DB.ReadClientSnapshot(client_id).knowledge_base else: with aff4.FACTORY.Open(client_id, token=token) as client: kb = client.Get(client.Schema.KNOWLEDGE_BASE) return kb.os
Returns last known operating system name that the client used.
def _resize(self, ratio_x, ratio_y, resampling): new_width = int(np.ceil(self.width * ratio_x)) new_height = int(np.ceil(self.height * ratio_y)) dest_affine = self.affine * Affine.scale(1 / ratio_x, 1 / ratio_y) if self.not_loaded(): window = rasterio.windows.Window(0, 0, sel...
Return raster resized by ratio.
def listen_tta(self, target, timeout): info = "{device} does not support listen as Type A Target" raise nfc.clf.UnsupportedTargetError(info.format(device=self))
Listen as Type A Target is not supported.
def deprecated(instructions): def decorator(func): @functools.wraps(func) def wrapper(*args, **kwargs): message = 'Call to deprecated function {}. {}'.format(func.__name__, instructions) frame = inspect.current...
Flags a method as deprecated. :param instructions: A human-friendly string of instructions, such as: 'Please migrate to add_proxy() ASAP.' :return: DeprecatedWarning
def get_app_content_types(self): from django.contrib.contenttypes.models import ContentType return [ContentType.objects.get_for_model(c) for c in self.get_app_model_classes()]
Return a list of all content_types for this app.
def setup_rabbitmq(self): if not self.rabbitmq_key: self.rabbitmq_key = '{}:start_urls'.format(self.name) self.server = connection.from_settings(self.crawler.settings) self.crawler.signals.connect(self.spider_idle, signal=signals.spider_idle) self.crawler.signals.connect(self...
Setup RabbitMQ connection. Call this method after spider has set its crawler object. :return: None
def format_exc_skip(skip, limit=None): etype, val, tb = sys.exc_info() for i in range(skip): tb = tb.tb_next return (''.join(format_exception(etype, val, tb, limit))).rstrip()
Like traceback.format_exc but allow skipping the first frames.
def _add_variable_proxy_methods(var, proxy_tensor): proxy_tensor.read_value = lambda: tf.identity(proxy_tensor) proxy_tensor.assign_sub = var.assign_sub proxy_tensor.assign = var.assign proxy_tensor.initialized_value = var.initialized_value
Proxy methods of underlying variable. This enables our custom getters to still work with, e.g., batch norm. Args: var: Variable to proxy proxy_tensor: Tensor that is identity of var
def has_cwd(state, dir, incorrect_msg="Your current working directory should be `{{dir}}`. Use `cd {{dir}}` to navigate there."): expr = "[[ $PWD == '{}' ]]".format(dir) _msg = state.build_message(incorrect_msg, fmt_kwargs={ 'dir': dir }) has_expr_exit_code(state, expr, output="0", incorrect_msg=_msg) r...
Check whether the student is in the expected directory. This check is typically used before using ``has_expr_output()`` to make sure the student didn't navigate somewhere else. Args: state: State instance describing student and solution code. Can be omitted if used with ``Ex()``. dir: Dire...
def timed(function): @wraps(function) def function_wrapper(obj, *args, **kwargs): name = obj.__class__.__name__ + '.' + function.__name__ start = time.clock() result = function(obj, *args, **kwargs) print('{}: {:.4f} seconds'.format(name, time.clock() - start)) return res...
Decorator timing the method call and printing the result to `stdout`
def create_datasource(jboss_config, name, datasource_properties, profile=None): log.debug("======================== MODULE FUNCTION: jboss7.create_datasource, name=%s, profile=%s", name, profile) ds_resource_description = __get_datasource_resource_description(jboss_config, name, profile) operation = '/subsy...
Create datasource in running jboss instance jboss_config Configuration dictionary with properties specified above. name Datasource name datasource_properties A dictionary of datasource properties to be created: - driver-name: mysql - connection-url: 'jdbc:mysql:/...
def start(self): scheduler_threads = [ Thread(target=self._monitor_events, daemon=True), Thread(target=self._processing_controller_status, daemon=True), Thread(target=self._schedule_processing_blocks, daemon=True), Thread(target=self._monitor_pbc_status, daemon=Tr...
Start the scheduler threads.
def newAddress(self, currency='btc', label=''): request = '/v1/deposit/' + currency + '/newAddress' url = self.base_url + request params = { 'request': request, 'nonce': self.get_nonce() } if label != '': params['label'] = label return ...
Send a request for a new cryptocurrency deposit address with an optional label. Return the response. Arguements: currency -- a Gemini supported cryptocurrency (btc, eth) label -- optional label for the deposit address
def import_address(self, address, account="*", rescan=False): response = self.make_request("importaddress", [address, account, rescan]) error = response.get('error') if error is not None: raise Exception(error) return response
param address = address to import param label= account name to use
async def _wrap_ws(self, handler, *args, **kwargs): try: method = self.request_method() data = await handler(self, *args, **kwargs) status = self.responses.get(method, OK) response = { 'type': 'response', 'key': getattr(self.request...
wraps a handler by receiving a websocket request and returning a websocket response
def deinstall(name): portpath = _check_portname(name) old = __salt__['pkg.list_pkgs']() result = __salt__['cmd.run_all']( ['make', 'deinstall', 'BATCH=yes'], cwd=portpath, python_shell=False ) __context__.pop('pkg.list_pkgs', None) new = __salt__['pkg.list_pkgs']() re...
De-install a port. CLI Example: .. code-block:: bash salt '*' ports.deinstall security/nmap
def create(self): assert not self.called return self.klass(*self.args, **self.kw)
Create a normal field from the lazy field
def bisine_wave(frequency): f_hi = frequency f_lo = frequency / 2.0 with tf.name_scope('hi'): sine_hi = sine_wave(f_hi) with tf.name_scope('lo'): sine_lo = sine_wave(f_lo) return tf.concat([sine_lo, sine_hi], axis=2)
Emit two sine waves, in stereo at different octaves.
def column(self, column, option=None, **kw): config = False if option == 'type': return self._column_types[column] elif 'type' in kw: config = True self._column_types[column] = kw.pop('type') if kw: self._visual_drag.column(ttk.Treeview.col...
Query or modify the options for the specified column. If `kw` is not given, returns a dict of the column option values. If `option` is specified then the value for that option is returned. Otherwise, sets the options to the corresponding values. :param id: the column's identifier (read...
def run(self, args): jlink = self.create_jlink(args) mcu = args.name[0].lower() if pylink.unlock(jlink, mcu): print('Successfully unlocked device!') else: print('Failed to unlock device!')
Unlocks the target device. Args: self (UnlockCommand): the ``UnlockCommand`` instance args (Namespace): the arguments passed on the command-line Returns: ``None``
def create_send_message(self, string_message, controller, zone=None, parameter=None): cc = hex(int(controller) - 1).replace('0x', '') if zone is not None: zz = hex(int(zone) - 1).replace('0x', '') else: zz = '' if parameter is not None: pr = hex(int(pa...
Creates a message from a string, substituting the necessary parameters, that is ready to send to the socket
def update_firmware(self, file, data=None, progress=None, bank=None): self.oem_init() if progress is None: progress = lambda x: True return self._oem.update_firmware(file, data, progress, bank)
Send file to BMC to perform firmware update :param filename: The filename to upload to the target BMC :param data: The payload of the firmware. Default is to read from specified filename. :param progress: A callback that will be given a dict describing ...
def _get_snmp(self, oid): if self.snmp_version in ["v1", "v2c"]: return self._get_snmpv2c(oid) else: return self._get_snmpv3(oid)
Wrapper for generic SNMP call.
def extern_store_i64(self, context_handle, i64): c = self._ffi.from_handle(context_handle) return c.to_value(i64)
Given a context and int32_t, return a new Handle to represent the int32_t.
def pypi( click_ctx, requirements, index=None, python_version=3, exclude_packages=None, output=None, subgraph_check_api=None, no_transitive=True, no_pretty=False, ): requirements = [requirement.strip() for requirement in requirements.split("\\n") if requirement] if not requir...
Manipulate with dependency requirements using PyPI.
def analyze(self, using=None, **kwargs): return self._get_connection(using).indices.analyze(index=self._name, **kwargs)
Perform the analysis process on a text and return the tokens breakdown of the text. Any additional keyword arguments will be passed to ``Elasticsearch.indices.analyze`` unchanged.
def _normalize_server_settings(**settings): ret = dict() settings = salt.utils.args.clean_kwargs(**settings) for setting in settings: if isinstance(settings[setting], dict): value_from_key = next(six.iterkeys(settings[setting])) ret[setting] = "{{{0}}}".format(value_from_key)...
Convert setting values that has been improperly converted to a dict back to a string.
def filename(self): if self._filename is None: self._filename = storage.get_file(self.basename, self.ccd, ext=self.extension, version=self.type, ...
Name if the MOP formatted file to parse. @rtype: basestring @return: filename
def _should_resolve_subgraph(subgraph_check_api: str, package_name: str, package_version: str, index_url: str) -> bool: _LOGGER.info( "Checking if the given dependency subgraph for package %r in version %r from index %r should be resolved", package_name, package_version, index_url, ...
Ask the given subgraph check API if the given package in the given version should be included in the resolution. This subgraph resolving avoidence serves two purposes - we don't need to resolve dependency subgraphs that were already analyzed and we also avoid analyzing of "core" packages (like setuptools) ...
def render_build_args(options, ns): build_args = options.get('buildArgs', {}) for key, value in build_args.items(): build_args[key] = value.format(**ns) return build_args
Get docker build args dict, rendering any templated args. Args: options (dict): The dictionary for a given image from chartpress.yaml. Fields in `options['buildArgs']` will be rendered and returned, if defined. ns (dict): the namespace used when rendering templated arguments
def delete(self, *, auto_commit=False): try: db.session.delete(self.resource) if auto_commit: db.session.commit() except SQLAlchemyError: self.log.exception('Failed deleting resource: {}'.format(self.id)) db.session.rollback()
Removes a resource from the database Args: auto_commit (bool): Automatically commit the transaction. Default: `False` Returns: `None`
def _get_lt_from_user_by_id(self, user, lt_id): req = meta.Session.query(LayerTemplate).select_from(join(LayerTemplate, User)) try: return req.filter(and_(User.login==user, LayerTemplate.id==lt_id)).one() except Exception, e: return None
Get a layertemplate owned by a user from the database by lt_id.
def _notify_listeners(self, sender, message): uid = message['uid'] msg_topic = message['topic'] self._ack(sender, uid, 'fire') all_listeners = set() for lst_topic, listeners in self.__listeners.items(): if fnmatch.fnmatch(msg_topic, lst_topic): all_lis...
Notifies listeners of a new message
def get_partial_DOS(self): warnings.warn("Phonopy.get_partial_DOS is deprecated. " "Use Phonopy.get_projected_dos_dict.", DeprecationWarning) pdos = self.get_projected_dos_dict() return pdos['frequency_points'], pdos['projected_dos']
Return frequency points and partial DOS as a tuple. Projection is done to atoms and may be also done along directions depending on the parameters at run_partial_dos. Returns ------- A tuple with (frequency_points, partial_dos). frequency_points: ndarray sha...
def confirm_login_allowed(self, user): if not user.is_active: raise forms.ValidationError( self.error_messages['inactive'], code='inactive', )
Controls whether the given User may log in. This is a policy setting, independent of end-user authentication. This default behavior is to allow login by active users, and reject login by inactive users. If the given user cannot log in, this method should raise a ``forms.ValidationError`...
def verify_registration(request): user = process_verify_registration_data(request.data) extra_data = None if registration_settings.REGISTER_VERIFICATION_AUTO_LOGIN: extra_data = perform_login(request, user) return get_ok_response('User verified successfully', extra_data=extra_data)
Verify registration via signature.
def calc_temperature_stats(self): self.temp.max_delta = melodist.get_shift_by_data(self.data.temp, self._lon, self._lat, self._timezone) self.temp.mean_course = melodist.util.calculate_mean_daily_course_by_month(self.data.temp, normalize=True)
Calculates statistics in order to derive diurnal patterns of temperature
def _get_data_from_bigquery(self, queries): all_df = [] for query in queries: all_df.append(query.execute().result().to_dataframe()) df = pd.concat(all_df, ignore_index=True) return df
Get data from bigquery table or query.
def create_directory(self, path=None): if path is None: path = self.get_path() if not os.path.exists(path): os.makedirs(path)
Create the directory for the given path. If path is None use the path of this instance :param path: the path to create :type path: str :returns: None :rtype: None :raises: OSError
def writeline(self, line=b'', sep=b'\n', echo=None): self.writelines([line], sep, echo)
Write a byte sequences to the channel and terminate it with carriage return and line feed. Args: line(bytes): The line to send. sep(bytes): The separator to use after each line. echo(bool): Whether to echo the written data to stdout. Raises: EOFE...
def _fail_if_contains_errors(response, sync_uuid=None): if response.status_code != _HTTP_OK: raise RequestError(response) response_json = response.json() if sync_uuid and 'sync_status' in response_json: status = response_json['sync_status'] if sync_uuid in status and 'error' in statu...
Raise a RequestError Exception if a given response does not denote a successful request.
def auth_from_hass_config(path=None, **kwargs): if path is None: path = config.find_hass_config() return Auth(os.path.join(path, ".storage/auth"), **kwargs)
Initialize auth from HASS config.
def merge_data(path_data, request_data): merged = request_data.copy() if request_data else {} merged.update(path_data or {}) return merged
Merge data from the URI path and the request. Path data wins.
def num_inputs(self): num = 0 for walker, _ in self.inputs: if not isinstance(walker, InvalidStreamWalker): num += 1 return num
Return the number of connected inputs. Returns: int: The number of connected inputs
def incident_exists(name, message, status): incidents = cachet.Incidents(endpoint=ENDPOINT) all_incidents = json.loads(incidents.get()) for incident in all_incidents['data']: if name == incident['name'] and \ status == incident['status'] and \ message.strip() == incident['messa...
Check if an incident with these attributes already exists
def secondary_xi(mass1, mass2, spin1x, spin1y, spin2x, spin2y): spinx = secondary_spin(mass1, mass2, spin1x, spin2x) spiny = secondary_spin(mass1, mass2, spin1y, spin2y) return xi2_from_mass1_mass2_spin2x_spin2y(mass1, mass2, spinx, spiny)
Returns the effective precession spin argument for the smaller mass.
def remove(self, bw): try: self.__ranges.remove(bw) except KeyError: if not bw.oneshot: raise
Removes a buffer watch identifier. @type bw: L{BufferWatch} @param bw: Buffer watch identifier. @raise KeyError: The buffer watch identifier was already removed.
def parse_type(field): if field.type_id == 'string': if 'size' in field.options: return "parser.getString(%d)" % field.options['size'].value else: return "parser.getString()" elif field.type_id in JAVA_TYPE_MAP: return "parser.get" + field.type_id.capitalize() + "()" if field.type_id == 'a...
Function to pull a type from the binary payload.
def write_hyper_response(self, links=[], meta={}, entity_name=None, entity=None, notifications=[], actions=[]): assert entity_name is not None assert entity is not None meta.update({ "status": self.get_status() }) self.write({ "links": links, "...
Writes a hyper media response object :param list links: A list of links to the resources :param dict meta: The meta data for this response :param str entity_name: The entity name :param object entity: The Entity itself :param list notifications: List of notifications :pa...
def broadcast_identifier(self): if self.handler_type is not BROADCAST: return None if self.reliable_delivery: raise EventHandlerConfigurationError( "You are using the default broadcast identifier " "which is not compatible with reliable delivery. S...
A unique string to identify a service instance for `BROADCAST` type handlers. The `broadcast_identifier` is appended to the queue name when the `BROADCAST` handler type is used. It must uniquely identify service instances that receive broadcasts. The default `broadcast_identifi...
def pastdate(self, prompt, default=None): prompt = prompt if prompt is not None else "Enter a past date" if default is not None: prompt += " [" + default.strftime('%d %m %Y') + "]" prompt += ': ' return self.input(curry(filter_pastdate, default=default), prompt)
Prompts user to input a date in the past.
def add_photometry(self, compare_to_existing=True, **kwargs): self._add_cat_dict( Photometry, self._KEYS.PHOTOMETRY, compare_to_existing=compare_to_existing, **kwargs) return
Add a `Photometry` instance to this entry.
def get_paginated_response(self, data): metadata = { 'next': self.get_next_link(), 'previous': self.get_previous_link(), 'count': self.get_result_count(), 'num_pages': self.get_num_pages(), } if isinstance(data, dict): if 'results' not ...
Annotate the response with pagination information
def input_option(message, options="yn", error_message=None): def _valid(character): if character not in options: print(error_message % character) return input("%s [%s]" % (message, options), _valid, True, lambda a: a.lower())
Reads an option from the screen, with a specified prompt. Keeps asking until a valid option is sent by the user.
def guess_content_type_and_encoding(path): for ext, content_type in _EXTENSION_TO_MIME_TYPE.items(): if path.endswith(ext): return content_type content_type, encoding = mimetypes.guess_type(path) content_type = content_type or "application/binary" return content_type, encoding
Guess the content type of a path, using ``mimetypes``. Falls back to "application/binary" if no content type is found. Args: path (str): the path to guess the mimetype of Returns: str: the content type of the file
def delete_network(self, network): net_id = self._find_network_id(network) ret = self.network_conn.delete_network(network=net_id) return ret if ret else True
Deletes the specified network
def update_extent_from_rectangle(self): self.show() self.canvas.unsetMapTool(self.rectangle_map_tool) self.canvas.setMapTool(self.pan_tool) rectangle = self.rectangle_map_tool.rectangle() if rectangle: self.bounding_box_group.setTitle( self.tr('Boundin...
Update extent value in GUI based from the QgsMapTool rectangle. .. note:: Delegates to update_extent()
def to_representation(self, obj): representation = {} for name, field in self.fields.items(): if field.write_only: continue attribute = self.get_attribute(obj, field.source or name) if attribute is None: representation[name] = [] if fie...
Convert given internal object instance into representation dict. Representation dict may be later serialized to the content-type of choice in the resource HTTP method handler. This loops over all fields and retrieves source keys/attributes as field values with respect to optional field...
def config(name, config, write=True): _build_config_tree(name, config) configs = _render_configuration() if __opts__.get('test', False): comment = 'State syslog_ng will write \'{0}\' into {1}'.format( configs, __SYSLOG_NG_CONFIG_FILE ) re...
Builds syslog-ng configuration. This function is intended to be used from the state module, users should not use it directly! name : the id of the Salt document or it is the format of <statement name>.id config : the parsed YAML code write : if True, it writes the config into the configuration file, ...
def mach2tas(Mach, H): a = vsound(H) Vtas = Mach*a return Vtas
Mach number to True Airspeed
def add_child_book(self, book_id, child_id): if self._catalog_session is not None: return self._catalog_session.add_child_catalog(catalog_id=book_id, child_id=child_id) return self._hierarchy_session.add_child(id_=book_id, child_id=child_id)
Adds a child to a book. arg: book_id (osid.id.Id): the ``Id`` of a book arg: child_id (osid.id.Id): the ``Id`` of the new child raise: AlreadyExists - ``book_id`` is already a parent of ``child_id`` raise: NotFound - ``book_id`` or ``child_id`` not found ...
def progress_status(self): if self.line % self.freq == 0: text = self.statustext.format(nele=self.line, totalele=self.total_lines) if self.main_window.grid.actions.pasting: try: post_command_event(self.main_win...
Displays progress in statusbar
def generate_ppi_network( ppi_graph_path: str, dge_list: List[Gene], max_adj_p: float, max_log2_fold_change: float, min_log2_fold_change: float, ppi_edge_min_confidence: Optional[float] = None, current_disease_ids_path: Optional[str] = None, disease_associ...
Generate the protein-protein interaction network. :return Network: Protein-protein interaction network with information on differential expression.
def read_float(self, registeraddress, functioncode=3, numberOfRegisters=2): _checkFunctioncode(functioncode, [3, 4]) _checkInt(numberOfRegisters, minvalue=2, maxvalue=4, description='number of registers') return self._genericCommand(functioncode, registeraddress, numberOfRegisters=numberOfRegist...
Read a floating point number from the slave. Floats are stored in two or more consecutive 16-bit registers in the slave. The encoding is according to the standard IEEE 754. There are differences in the byte order used by different manufacturers. A floating point value of 1.0 is encoded...