code
stringlengths
51
2.38k
docstring
stringlengths
4
15.2k
def pose2mat(pose): homo_pose_mat = np.zeros((4, 4), dtype=np.float32) homo_pose_mat[:3, :3] = quat2mat(pose[1]) homo_pose_mat[:3, 3] = np.array(pose[0], dtype=np.float32) homo_pose_mat[3, 3] = 1. return homo_pose_mat
Converts pose to homogeneous matrix. Args: pose: a (pos, orn) tuple where pos is vec3 float cartesian, and orn is vec4 float quaternion. Returns: 4x4 homogeneous matrix
def ls( self, rev, path, recursive=False, recursive_dirs=False, directory=False, report=() ): raise NotImplementedError
List directory or file :param rev: The revision to use. :param path: The path to list. May start with a '/' or not. Directories may end with a '/' or not. :param recursive: Recursively list files in subdirectories. :param recursive_dirs: Used when recursive=True, al...
def element_name_from_Z(Z, normalize=False): r = element_data_from_Z(Z)[2] if normalize: return r.capitalize() else: return r
Obtain an element's name from its Z number An exception is thrown if the Z number is not found If normalize is True, the first letter will be capitalized
def match(self, context, line): return line.kind == 'code' and line.partitioned[0] in self._both
Match code lines prefixed with a variety of keywords.
def reset(self): self._undo_stack.clear() self._spike_clusters = self._spike_clusters_base self._new_cluster_id = self._new_cluster_id_0
Reset the clustering to the original clustering. All changes are lost.
def _kill_process(self, pid, sig=signal.SIGKILL): try: os.kill(pid, sig) except OSError as e: if e.errno == errno.ESRCH: logging.debug("Failure %s while killing process %s with signal %s: %s", e.errno, pid, sig, e.strerror) ...
Try to send signal to given process.
def from_form(self, param_name, field): return self.__from_source(param_name, field, lambda: request.form, 'form')
A decorator that converts a request form into a function parameter based on the specified field. :param str param_name: The parameter which receives the argument. :param Field field: The field class or instance used to deserialize the request form to a Python object. :return: A function
def updateParams(self, newvalues): for (param, value) in newvalues.items(): if param not in self.model.freeparams: raise RuntimeError("Can't handle param: {0}".format( param)) if newvalues: self.model.updateParams(newvalues) sel...
Update model parameters and re-compute likelihoods. This method is the **only** acceptable way to update model parameters. The likelihood is re-computed as needed by this method. Args: `newvalues` (dict) A dictionary keyed by param name and with value as new...
def interp(self, date: timetools.Date) -> float: xnew = timetools.TOY(date) xys = list(self) for idx, (x_1, y_1) in enumerate(xys): if x_1 > xnew: x_0, y_0 = xys[idx-1] break else: x_0, y_0 = xys[-1] x_1, y_1 = xys[0] ...
Perform a linear value interpolation for the given `date` and return the result. Instantiate a 1-dimensional |SeasonalParameter| object: >>> from hydpy.core.parametertools import SeasonalParameter >>> class Par(SeasonalParameter): ... NDIM = 1 ... TYPE = float ...
def _init_content_type_params(self): ret = {} if self.content_type: params = self.content_type.split(';')[1:] for param in params: try: key, val = param.split('=') ret[naked(key)] = naked(val) except ValueErr...
Return the Content-Type request header parameters Convert all of the semi-colon separated parameters into a dict of key/vals. If for some stupid reason duplicate & conflicting params are present then the last one wins. If a particular content-type param is non-compliant ...
def send_messages(self, sms_messages): results = [] for message in sms_messages: try: assert message.connection is None except AssertionError: if not self.fail_silently: raise backend = self.backend fail_silently = self.fail_silently result = django_rq.enqueue(self._send, message, backen...
Receives a list of SMSMessage instances and returns a list of RQ `Job` instances.
def do_find(lookup, term): space = defaultdict(list) for name in lookup.keys(): space[name].append(name) try: iter_lookup = lookup.iteritems() except AttributeError: iter_lookup = lookup.items() for name, definition in iter_lookup: for keyword in definition['keywords'...
Matches term glob against short-name, keywords and categories.
def _is_common_text(self, inpath): one_suffix = inpath[-2:] two_suffix = inpath[-3:] three_suffix = inpath[-4:] four_suffix = inpath[-5:] if one_suffix in self.common_text: return True elif two_suffix in self.common_text: return True elif t...
private method to compare file path mime type to common text file types
def _load_resource_listing(resource_listing): try: with open(resource_listing) as resource_listing_file: return simplejson.load(resource_listing_file) except IOError: raise ResourceListingNotFoundError( 'No resource listing found at {0}. Note that your json file ' ...
Load the resource listing from file, handling errors. :param resource_listing: path to the api-docs resource listing file :type resource_listing: string :returns: contents of the resource listing file :rtype: dict
def _create_content_body(self, body): frames = int(math.ceil(len(body) / float(self._max_frame_size))) for offset in compatibility.RANGE(0, frames): start_frame = self._max_frame_size * offset end_frame = start_frame + self._max_frame_size body_len = len(body) ...
Split body based on the maximum frame size. This function is based on code from Rabbitpy. https://github.com/gmr/rabbitpy :param bytes|str|unicode body: Message payload :rtype: collections.Iterable
def flush_pending(function): s = boto3.Session() client = s.client('lambda') results = client.invoke( FunctionName=function, Payload=json.dumps({'detail-type': 'Scheduled Event'}) ) content = results.pop('Payload').read() pprint.pprint(results) pprint.pprint(json.loads(conten...
Attempt to acquire any pending locks.
def get_single_value(value): if not all_elements_equal(value): raise ValueError('Not all values are equal to each other.') if is_scalar(value): return value return value.item(0)
Get a single value out of the given value. This is meant to be used after a call to :func:`all_elements_equal` that returned True. With this function we return a single number from the input value. Args: value (ndarray or number): a numpy array or a single number. Returns: number: a s...
def calc_normal_std_glorot(inmaps, outmaps, kernel=(1, 1)): r return np.sqrt(2. / (np.prod(kernel) * inmaps + outmaps))
r"""Calculates the standard deviation proposed by Glorot et al. .. math:: \sigma = \sqrt{\frac{2}{NK + M}} Args: inmaps (int): Map size of an input Variable, :math:`N`. outmaps (int): Map size of an output Variable, :math:`M`. kernel (:obj:`tuple` of :obj:`int`): Convolution ke...
def parse_css(self, css): rulesets = self.ruleset_re.findall(css) for (selector, declarations) in rulesets: rule = Rule(self.parse_selector(selector)) rule.properties = self.parse_declarations(declarations) self.rules.append(rule)
Parse a css style sheet into the CSS object. For the moment this will only work for very simple css documents. It works by using regular expression matching css syntax. This is not bullet proof.
def _validate_children(self): for child in self._children: if child.__class__ not in self._allowed_children: raise ValueError( "Child %s is not allowed as a children for this %s type entity." % ( child, self.__class__ ) ...
Check that the children we have are allowed here.
def refresh(self) -> None: if not self: self.values[:] = 0. elif len(self) == 1: values = list(self._toy2values.values())[0] self.values[:] = self.apply_timefactor(values) else: for idx, date in enumerate( timetools.TOY.centred_...
Update the actual simulation values based on the toy-value pairs. Usually, one does not need to call refresh explicitly. The "magic" methods __call__, __setattr__, and __delattr__ invoke it automatically, when required. Instantiate a 1-dimensional |SeasonalParameter| object: ...
def trim_common_suffixes(strs, min_len=0): if len(strs) < 2: return 0, strs rev_strs = [s[::-1] for s in strs] trimmed, rev_strs = trim_common_prefixes(rev_strs, min_len) if trimmed: strs = [s[::-1] for s in rev_strs] return trimmed, strs
trim common suffixes >>> trim_common_suffixes('A', 1) (0, 'A')
def slice_shift(self, periods=1, axis=0): if periods == 0: return self if periods > 0: vslicer = slice(None, -periods) islicer = slice(periods, None) else: vslicer = slice(-periods, None) islicer = slice(None, periods) new_obj =...
Equivalent to `shift` without copying data. The shifted data will not include the dropped periods and the shifted axis will be smaller than the original. Parameters ---------- periods : int Number of periods to move, can be positive or negative Returns ...
def _exec_cmd(self, command, **kwargs): kwargs['command'] = command self._check_exclusive_parameters(**kwargs) requests_params = self._handle_requests_params(kwargs) session = self._meta_data['bigip']._meta_data['icr_session'] response = session.post( self._meta_data[...
Create a new method as command has specific requirements. There is a handful of the TMSH global commands supported, so this method requires them as a parameter. :raises: InvalidCommand
def remove_fields(layer, fields_to_remove): index_to_remove = [] data_provider = layer.dataProvider() for field in fields_to_remove: index = layer.fields().lookupField(field) if index != -1: index_to_remove.append(index) data_provider.deleteAttributes(index_to_remove) lay...
Remove fields from a vector layer. :param layer: The vector layer. :type layer: QgsVectorLayer :param fields_to_remove: List of fields to remove. :type fields_to_remove: list
def builtin_lookup(name): builtin_astroid = MANAGER.ast_from_module(builtins) if name == "__dict__": return builtin_astroid, () try: stmts = builtin_astroid.locals[name] except KeyError: stmts = () return builtin_astroid, stmts
lookup a name into the builtin module return the list of matching statements and the astroid for the builtin module
def num_lines(self): if self.from_stdin: return None if not self._num_lines: self._iterate_lines() return self._num_lines
Lazy evaluation of the number of lines. Returns None for stdin input currently.
def competence(s): if any([isinstance(s, cls) for cls in [distributions.Wishart, distributions.WishartCov]]): return 2 else: return 0
The competence function for MatrixMetropolis
def search_drama_series(self, query_string): result = self._android_api.list_series( media_type=ANDROID.MEDIA_TYPE_DRAMA, filter=ANDROID.FILTER_PREFIX + query_string) return result
Search drama series list by series name, case-sensitive @param str query_string string to search for, note that the search is very simplistic and only matches against the start of the series name, ex) search ...
def _detect_timezone_windows(): global win32timezone_to_en tzi = DTZI_c() kernel32 = ctypes.windll.kernel32 getter = kernel32.GetTimeZoneInformation getter = getattr(kernel32, "GetDynamicTimeZoneInformation", getter) _ = getter(ctypes.byref(tzi)) win32tz_key_name = tzi.key_name if not win32tz_key_name: ...
Detect timezone on the windows platform.
def ConfigureLogging( debug_output=False, filename=None, mode='w', quiet_mode=False): for handler in logging.root.handlers: logging.root.removeHandler(handler) logger = logging.getLogger() if filename and filename.endswith('.gz'): handler = CompressedFileHandler(filename, mode=mode) elif filename: ...
Configures the logging root logger. Args: debug_output (Optional[bool]): True if the logging should include debug output. filename (Optional[str]): log filename. mode (Optional[str]): log file access mode. quiet_mode (Optional[bool]): True if the logging should not include information...
def search_directory(self, **kwargs): search_response = self.request('SearchDirectory', kwargs) result = {} items = { "account": zobjects.Account.from_dict, "domain": zobjects.Domain.from_dict, "dl": zobjects.DistributionList.from_dict, "cos": zobj...
SearchAccount is deprecated, using SearchDirectory :param query: Query string - should be an LDAP-style filter string (RFC 2254) :param limit: The maximum number of accounts to return (0 is default and means all) :param offset: The starting offset (0, 25, etc) :param dom...
def xgb_progressbar(rounds=1000): pbar = tqdm(total=rounds) def callback(_, ): pbar.update(1) return callback
Progressbar for xgboost using tqdm library. Examples -------- >>> model = xgb.train(params, X_train, 1000, callbacks=[xgb_progress(1000), ])
def attr(obj, attr): if not obj or not hasattr(obj, attr): return '' return getattr(obj, attr, '')
Does the same thing as getattr. getattr(obj, attr, '')
def _get_hyperparameters(self): hyperparameters = {} for key in self._hyperparameters: hyperparameters[key] = getattr(self, key) return hyperparameters
Get internal optimization parameters.
def guess_mime_type(self, path): _, ext = posixpath.splitext(path) if ext in self.extensions_map: return self.extensions_map[ext] ext = ext.lower() return self.extensions_map[ext if ext in self.extensions_map else '']
Guess an appropriate MIME type based on the extension of the provided path. :param str path: The of the file to analyze. :return: The guessed MIME type of the default if non are found. :rtype: str
def moz_info(self): if 'moz_info' not in self._memo: self._memo['moz_info'] = _get_url(self.artifact_url('mozinfo.json')).json() return self._memo['moz_info']
Return the build's mozinfo
def take_ownership(self, **kwargs): path = '%s/%s/take_ownership' % (self.manager.path, self.get_id()) server_data = self.manager.gitlab.http_post(path, **kwargs) self._update_attrs(server_data)
Update the owner of a pipeline schedule. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabOwnershipError: If the request failed
def get(self, section, key): try: return self.parser.get(section, key) except (NoOptionError, NoSectionError) as e: logger.warning("%s", e) return None
get function reads the config value for the requested section and key and returns it Parameters: * **section (string):** the section to look for the config value either - oxd, client * **key (string):** the key for the config value required Returns: **value ...
def visualize_saliency(model, layer_idx, filter_indices, seed_input, wrt_tensor=None, backprop_modifier=None, grad_modifier='absolute', keepdims=False): if backprop_modifier is not None: modifier_fn = get(backprop_modifier) model = modifier_fn(model) losses = [ (Ac...
Generates an attention heatmap over the `seed_input` for maximizing `filter_indices` output in the given `layer_idx`. Args: model: The `keras.models.Model` instance. The model input shape must be: `(samples, channels, image_dims...)` if `image_data_format=channels_first` or `(samples, image...
def set_auth_key_from_file(user, source, config='.ssh/authorized_keys', saltenv='base', fingerprint_hash_type=None): lfile = __salt__['cp.cache_file'](source, saltenv) if not os.path.isfile(lfile): ...
Add a key to the authorized_keys file, using a file as the source. CLI Example: .. code-block:: bash salt '*' ssh.set_auth_key_from_file <user> salt://ssh_keys/<user>.id_rsa.pub
def randomize_es(es_queryset): return es_queryset.query( query.FunctionScore( functions=[function.RandomScore()] ) ).sort("-_score")
Randomize an elasticsearch queryset.
def __is_valid_pos(pos_tuple, valid_pos): def is_valid_pos(valid_pos_tuple): length_valid_pos_tuple = len(valid_pos_tuple) if valid_pos_tuple == pos_tuple[:length_valid_pos_tuple]: return True else: return False seq_bool_flags = [is_valid_pos(valid_pos_tuple) for ...
This function checks token's pos is with in POS set that user specified. If token meets all conditions, Return True; else return False
def attrsignal(descriptor, signal_name, *, defer=False): def decorator(f): add_handler_spec( f, _attrsignal_spec(descriptor, signal_name, f, defer) ) return f return decorator
Connect the decorated method or coroutine method to the addressed signal on a descriptor. :param descriptor: The descriptor to connect to. :type descriptor: :class:`Descriptor` subclass. :param signal_name: Attribute name of the signal to connect to :type signal_name: :class:`str` :param defer:...
async def _set_annotations(entity_tag, annotations, connection): log.debug('Updating annotations on %s', entity_tag) facade = client.AnnotationsFacade.from_connection(connection) args = client.EntityAnnotations( entity=entity_tag, annotations=annotations, ) return await facade.Set([a...
Set annotations on the specified entity. :param annotations map[string]string: the annotations as key/value pairs.
def clean_intersections(G, tolerance=15, dead_ends=False): if not dead_ends: if 'streets_per_node' in G.graph: streets_per_node = G.graph['streets_per_node'] else: streets_per_node = count_streets_per_node(G) dead_end_nodes = [node for node, count in streets_per_node....
Clean-up intersections comprising clusters of nodes by merging them and returning their centroids. Divided roads are represented by separate centerline edges. The intersection of two divided roads thus creates 4 nodes, representing where each edge intersects a perpendicular edge. These 4 nodes represen...
def __parseDatasets(self): datasets = [] if self.__dataItem.has_key('dataSets'): for dataset in self.__dataItem['dataSets']: datasets.append(DataSet(Sitools2Abstract.getBaseUrl(self), dataset)) return datasets
Returns the list of Dataset related to the project.
def replace(self, key, val, time=0, min_compress_len=0): return self._set("replace", key, val, time, min_compress_len)
Replace existing key with value. Like L{set}, but only stores in memcache if the key already exists. The opposite of L{add}. @return: Nonzero on success. @rtype: int
def write(self, string): string = string.rstrip() if string: self.logger.critical(string)
Erase newline from a string and write to the logger.
def expand(sql, args=None): sql, args = SqlModule.get_sql_statement_with_environment(sql, args) return _sql_statement.SqlStatement.format(sql._sql, args)
Expand a SqlStatement, query string or SqlModule with a set of arguments. Args: sql: a SqlStatement, %%sql module, or string containing a query. args: a string of command line arguments or a dictionary of values. If a string, it is passed to the argument parser for the SqlModule associated wi...
def _read_dataframes_100k(path): import pandas ratings = pandas.read_table(os.path.join(path, "u.data"), names=['userId', 'movieId', 'rating', 'timestamp']) movies = pandas.read_csv(os.path.join(path, "u.item"), names=['movieId', 'title'], ...
reads in the movielens 100k dataset
def construct_url(ip_address: str) -> str: if 'http://' not in ip_address and 'https://' not in ip_address: ip_address = '{}{}'.format('http://', ip_address) if ip_address[-1] == '/': ip_address = ip_address[:-1] return ip_address
Construct the URL with a given IP address.
def normalize_response(response, request=None): if isinstance(response, Response): return response if request is not None and not isinstance(request, Request): request = normalize_request(request) for normalizer in RESPONSE_NORMALIZERS: try: return normalizer(response, re...
Given a response, normalize it to the internal Response class. This also involves normalizing the associated request object.
def pieces(self, piece_type: PieceType, color: Color) -> "SquareSet": return SquareSet(self.pieces_mask(piece_type, color))
Gets pieces of the given type and color. Returns a :class:`set of squares <chess.SquareSet>`.
def simulate(self): min_ = (-sys.maxsize - 1) if self._min is None else self._min max_ = sys.maxsize if self._max is None else self._max return random.randint(min_, max_)
Generates a random integer in the available range.
def start_log(level=logging.DEBUG, filename=None): if filename is None: tstr = time.ctime() tstr = tstr.replace(' ', '.') tstr = tstr.replace(':', '.') filename = 'deblur.log.%s' % tstr logging.basicConfig(filename=filename, level=level, format='%(levelnam...
start the logger for the run Parameters ---------- level : int, optional logging.DEBUG, logging.INFO etc. for the log level (between 0-50). filename : str, optional name of the filename to save the log to or None (default) to use deblur.log.TIMESTAMP
def fit_fn(distr, xvals, alpha, thresh): xvals = numpy.array(xvals) fit = fitfn_dict[distr](xvals, alpha, thresh) numpy.putmask(fit, xvals < thresh, 0.) return fit
The fitted function normalized to 1 above threshold To normalize to a given total count multiply by the count. Parameters ---------- xvals : sequence of floats Values where the function is to be evaluated alpha : float The fitted parameter thresh : float Threshold value...
def layers(): global _cached_layers if _cached_layers is not None: return _cached_layers layers_module = tf.layers try: from tensorflow.python import tf2 if tf2.enabled(): tf.logging.info("Running in V2 mode, using Keras layers.") layers_module = tf.keras.layers except ImportError: ...
Get the layers module good for TF 1 and TF 2 work for now.
def sha_hash(self) -> str: return hashlib.sha256(self.signed_raw().encode("ascii")).hexdigest().upper()
Return uppercase hex sha256 hash from signed raw document :return:
def _generate_ngrams_with_context_helper(ngrams_iter: iter, ngrams_len: int) -> map: return map(lambda term: (term[1], term[0], term[0] + ngrams_len), enumerate(ngrams_iter))
Updates the end index
def crypto_config_from_kwargs(fallback, **kwargs): try: crypto_config = kwargs.pop("crypto_config") except KeyError: try: fallback_kwargs = {"table_name": kwargs["TableName"]} except KeyError: fallback_kwargs = {} crypto_config = fallback(**fallback_kwargs...
Pull all encryption-specific parameters from the request and use them to build a crypto config. :returns: crypto config and updated kwargs :rtype: dynamodb_encryption_sdk.encrypted.CryptoConfig and dict
def notify(self): if self._notify is None: from twilio.rest.notify import Notify self._notify = Notify(self) return self._notify
Access the Notify Twilio Domain :returns: Notify Twilio Domain :rtype: twilio.rest.notify.Notify
def unhash(text, hashes): def retrieve_match(match): return hashes[match.group(0)] while re_hash.search(text): text = re_hash.sub(retrieve_match, text) text = re_pre_tag.sub(lambda m: re.sub('^' + m.group(1), '', m.group(0), flags=re.M), text) return text
Unhashes all hashed entites in the hashes dictionary. The pattern for hashes is defined by re_hash. After everything is unhashed, <pre> blocks are "pulled out" of whatever indentation level in which they used to be (e.g. in a list).
def converter_loader(app, entry_points=None, modules=None): if entry_points: for entry_point in entry_points: for ep in pkg_resources.iter_entry_points(entry_point): try: app.url_map.converters[ep.name] = ep.load() except Exception: ...
Run default converter loader. :param entry_points: List of entry points providing to Blue. :param modules: Map of coverters. .. versionadded: 1.0.0
def deriv2(self, p): return self.power * (self.power - 1) * np.power(p, self.power - 2)
Second derivative of the power transform Parameters ---------- p : array-like Mean parameters Returns -------- g''(p) : array Second derivative of the power transform of `p` Notes ----- g''(`p`) = `power` * (`power` - 1) ...
def valid_loc(self,F=None): if F is not None: return [i for i,f in enumerate(F) if np.all(f < self.max_fit) and np.all(f >= 0)] else: return [i for i,f in enumerate(self.F) if np.all(f < self.max_fit) and np.all(f >= 0)]
returns the indices of individuals with valid fitness.
def makediagram(edges): graph = pydot.Dot(graph_type='digraph') nodes = edges2nodes(edges) epnodes = [(node, makeanode(node[0])) for node in nodes if nodetype(node)=="epnode"] endnodes = [(node, makeendnode(node[0])) for node in nodes if nodetype(node)=="EndNode"] epbr = [(node, ma...
make the diagram with the edges
def create_variable(self, varname, vtype=None): var_types = ('string', 'int', 'boolean', 'double') vname = varname var = None type_from_name = 'string' if ':' in varname: type_from_name, vname = varname.split(':') if type_from_name not in (var_types): ...
Create a tk variable. If the variable was created previously return that instance.
def calculate_set_values(self): for ac in self.asset_classes: ac.alloc_value = self.total_amount * ac.allocation / Decimal(100)
Calculate the expected totals based on set allocations
def get(self, *, search, limit=0, headers=None): return self.transport.forward_request( method='GET', path=self.path, params={'search': search, 'limit': limit}, headers=headers )
Retrieves the assets that match a given text search string. Args: search (str): Text search string. limit (int): Limit the number of returned documents. Defaults to zero meaning that it returns all the matching assets. headers (dict): Optional headers to pass...
def setEnable(self, status, wifiInterfaceId=1, timeout=1): namespace = Wifi.getServiceType("setEnable") + str(wifiInterfaceId) uri = self.getControlURL(namespace) if status: setStatus = 1 else: setStatus = 0 self.execute(uri, namespace, "SetEnable", timeou...
Set enable status for a Wifi interface, be careful you don't cut yourself off. :param bool status: enable or disable the interface :param int wifiInterfaceId: the id of the Wifi interface :param float timeout: the timeout to wait for the action to be executed
def _with_primary(max_staleness, selection): primary = selection.primary sds = [] for s in selection.server_descriptions: if s.server_type == SERVER_TYPE.RSSecondary: staleness = ( (s.last_update_time - s.last_write_date) - (primary.last_update_time - prim...
Apply max_staleness, in seconds, to a Selection with a known primary.
def verify(obj, times=1, atleast=None, atmost=None, between=None, inorder=False): if isinstance(obj, str): obj = get_obj(obj) verification_fn = _get_wanted_verification( times=times, atleast=atleast, atmost=atmost, between=between) if inorder: verification_fn = verificatio...
Central interface to verify interactions. `verify` uses a fluent interface:: verify(<obj>, times=2).<method_name>(<args>) `args` can be as concrete as necessary. Often a catch-all is enough, especially if you're working with strict mocks, bc they throw at call time on unwanted, unconfigured a...
def list_functions(region=None, key=None, keyid=None, profile=None): conn = _get_conn(region=region, key=key, keyid=keyid, profile=profile) ret = [] for funcs in __utils__['boto3.paged_call'](conn.list_functions): ret += funcs['Functions'] return ret
List all Lambda functions visible in the current scope. CLI Example: .. code-block:: bash salt myminion boto_lambda.list_functions
def push_build(id, tag_prefix): req = swagger_client.BuildRecordPushRequestRest() req.tag_prefix = tag_prefix req.build_record_id = id response = utils.checked_api_call(pnc_api.build_push, 'push', body=req) if response: return utils.format_json_list(response)
Push build to Brew
def get_processor_cpuid_leaf(self, cpu_id, leaf, sub_leaf): if not isinstance(cpu_id, baseinteger): raise TypeError("cpu_id can only be an instance of type baseinteger") if not isinstance(leaf, baseinteger): raise TypeError("leaf can only be an instance of type baseinteger") ...
Returns the CPU cpuid information for the specified leaf. in cpu_id of type int Identifier of the CPU. The CPU most be online. The current implementation might not necessarily return the description for this exact CPU. in leaf of type int CP...
def page( self, title=None, pageid=None, auto_suggest=True, redirect=True, preload=False ): if (title is None or title.strip() == "") and pageid is None: raise ValueError("Either a title or a pageid must be specified") elif title: if auto_suggest: temp...
Get MediaWiki page based on the provided title or pageid Args: title (str): Page title pageid (int): MediaWiki page identifier auto-suggest (bool): **True:** Allow page title auto-suggest redirect (bool): **True:** Follow page redirects ...
def _get_unit_data_from_expr(unit_expr, unit_symbol_lut): if isinstance(unit_expr, Number): if unit_expr is sympy_one: return (1.0, sympy_one) return (float(unit_expr), sympy_one) if isinstance(unit_expr, Symbol): return _lookup_unit_symbol(unit_expr.name, unit_symbol_lut) ...
Grabs the total base_value and dimensions from a valid unit expression. Parameters ---------- unit_expr: Unit object, or sympy Expr object The expression containing unit symbols. unit_symbol_lut: dict Provides the unit data for each valid unit symbol.
def decorate_method(wrapped): def wrapper(self): lines = Lines() if hasattr(self.model, wrapped.__name__): print(' . %s' % wrapped.__name__) lines.add(1, method_header(wrapped.__name__, nogil=True)) for line in wrapped(self): lines.add(2...
The decorated method will return a |Lines| object including a method header. However, the |Lines| object will be empty if the respective model does not implement a method with the same name as the wrapped method.
def delete(self, *args, **kwargs): hosted_zone = route53_backend.get_hosted_zone_by_name( self.hosted_zone_name) if not hosted_zone: hosted_zone = route53_backend.get_hosted_zone(self.hosted_zone_id) hosted_zone.delete_rrset_by_name(self.name)
Not exposed as part of the Route 53 API - used for CloudFormation. args are ignored
def create(self, name, address=None, enabled=True, balancing_mode='active', ipsec_vpn=True, nat_t=False, force_nat_t=False, dynamic=False, ike_phase1_id_type=None, ike_phase1_id_value=None): json = {'name': name, 'address': address, 'balancing_mode':...
Create an test_external endpoint. Define common settings for that specify the address, enabled, nat_t, name, etc. You can also omit the IP address if the endpoint is dynamic. In that case, you must also specify the ike_phase1 settings. :param str name: name of test_external endpoint ...
def _read(self, fd, mask): try: if select.select([fd],[],[],0)[0]: snew = os.read(fd, self.nbytes) if PY3K: snew = snew.decode('ascii','replace') self.value.append(snew) self.nbytes -= len(snew) else: snew = ...
Read waiting data and terminate Tk mainloop if done
def get_context_data(self): buffer_name = self['buffer_name'].get_value() structure = CreateContextName.get_response_structure(buffer_name) if structure: structure.unpack(self['buffer_data'].get_value()) return structure else: return self['buffer_data'...
Get the buffer_data value of a context response and try to convert it to the relevant structure based on the buffer_name used. If it is an unknown structure then the raw bytes are returned. :return: relevant Structure of buffer_data or bytes if unknown name
def find_function_by_name(self, name): cfg_rv = None for cfg in self._cfgs: if cfg.name == name: cfg_rv = cfg break return cfg_rv
Return the cfg of the requested function by name.
def new_method_call(celf, destination, path, iface, method) : "creates a new DBUS.MESSAGE_TYPE_METHOD_CALL message." result = dbus.dbus_message_new_method_call \ ( (lambda : None, lambda : destination.encode())[destination != None](), path.encode(), (lambda ...
creates a new DBUS.MESSAGE_TYPE_METHOD_CALL message.
def setup_logging(verbose=0, colors=False, name=None): root_logger = logging.getLogger(name) root_logger.setLevel(logging.DEBUG if verbose > 0 else logging.INFO) formatter = ColorFormatter(verbose > 0, colors) if colors: colorclass.Windows.enable() handler_stdout = logging.StreamHandler(sys....
Configure console logging. Info and below go to stdout, others go to stderr. :param int verbose: Verbosity level. > 0 print debug statements. > 1 passed to sphinx-build. :param bool colors: Print color text in non-verbose mode. :param str name: Which logger name to set handlers to. Used for testing.
def check_constraint(self, pkge=None, constr=None): if not pkge is None: return javabridge.call( self.jobject, "checkConstraint", "(Lweka/core/packageManagement/Package;)Z", pkge.jobject) if not constr is None: return javabridge.call( self.jobject,...
Checks the constraints. :param pkge: the package to check :type pkge: Package :param constr: the package constraint to check :type constr: PackageConstraint
def initialTrendSmoothingFactors(self, timeSeries): result = 0.0 seasonLength = self.get_parameter("seasonLength") k = min(len(timeSeries) - seasonLength, seasonLength) for i in xrange(0, k): result += (timeSeries[seasonLength + i][1] - timeSeries[i][1]) / seasonLength ...
Calculate the initial Trend smoothing Factor b0. Explanation: http://en.wikipedia.org/wiki/Exponential_smoothing#Triple_exponential_smoothing :return: Returns the initial trend smoothing factor b0
def ordered_load(stream, Loader=yaml.Loader, object_pairs_hook=OrderedDict): class OrderedLoader(Loader): pass def construct_mapping(loader, node): loader.flatten_mapping(node) return object_pairs_hook(loader.construct_pairs(node)) OrderedLoader.add_constructor( yaml.resolver...
Loads an ordered dict into a yaml while preserving the order :param stream: the name of the stream :param Loader: the yam loader (such as yaml.SafeLoader) :param object_pairs_hook: the ordered dict
def new(self): if self._initialized: raise pycdlibexception.PyCdlibInternalError('CE record already initialized!') self.bl_cont_area = 0 self.offset_cont_area = 0 self.len_cont_area = 0 self._initialized = True
Create a new Rock Ridge Continuation Entry record. Parameters: None. Returns: Nothing.
def extract_finditer(pos_seq, regex=SimpleNP): ss = coarse_tag_str(pos_seq) def gen(): for m in re.finditer(regex, ss): yield (m.start(), m.end()) return list(gen())
The "GreedyFSA" method in Handler et al. 2016. Returns token position spans of valid ngrams.
def _ircounts2radiance(counts, scale, offset): rad = (counts - offset) / scale return rad.clip(min=0)
Convert IR counts to radiance Reference: [IR]. Args: counts: Raw detector counts scale: Scale [mW-1 m2 cm sr] offset: Offset [1] Returns: Radiance [mW m-2 cm-1 sr-1]
def conditional_expected_number_of_purchases_up_to_time(self, t, frequency, recency, T): x = frequency r, alpha, a, b = self._unload_params("r", "alpha", "a", "b") hyp_term = hyp2f1(r + x, b + x + 1, a + b + x, t / (alpha + T + t)) first_term = (a + b + x) / (a - 1) second_term =...
Conditional expected number of repeat purchases up to time t. Calculate the expected number of repeat purchases up to time t for a randomly choose individual from the population, given they have purchase history (frequency, recency, T) See Wagner, U. and Hoppe D. (2008). Parame...
def post(self, request, *args, **kwargs): queryset = self.get_selected(request) if request.POST.get('modify'): response = self.process_action(request, queryset) if not response: url = self.get_done_url() return self.render(request, redirect_url=url...
Method for handling POST requests. Checks for a modify confirmation and performs the action by calling `process_action`.
def set_status(self, status_code: int, reason: str = None) -> None: self._status_code = status_code if reason is not None: self._reason = escape.native_str(reason) else: self._reason = httputil.responses.get(status_code, "Unknown")
Sets the status code for our response. :arg int status_code: Response status code. :arg str reason: Human-readable reason phrase describing the status code. If ``None``, it will be filled in from `http.client.responses` or "Unknown". .. versionchanged:: 5.0 ...
def _notify_remove_at(self, index, length=1): slice_ = self._slice_at(index, length) self._notify_remove(slice_)
Notify about an RemoveChange at a caertain index and length.
def tube(self, radius=None, scalars=None, capping=True, n_sides=20, radius_factor=10, preference='point', inplace=False): if n_sides < 3: n_sides = 3 tube = vtk.vtkTubeFilter() tube.SetInputDataObject(self) tube.SetCapping(capping) if radius is not None: ...
Generate a tube around each input line. The radius of the tube can be set to linearly vary with a scalar value. Parameters ---------- radius : float Minimum tube radius (minimum because the tube radius may vary). scalars : str, optional Scalar array by w...
def finalize_episode(self, params): total_reward = sum(self.intermediate_rewards) self.total_rewards.append(total_reward) self.params.append(params) self.intermediate_rewards = []
Closes the current episode, sums up rewards and stores the parameters # Argument params (object): Parameters associated with the episode to be stored and then retrieved back in sample()
def check_rotation(rotation): if rotation not in ALLOWED_ROTATION: allowed_rotation = ', '.join(ALLOWED_ROTATION) raise UnsupportedRotation('Rotation %s is not allwoed. Allowed are %s' % (rotation, allowed_rotation))
checks rotation parameter if illegal value raises exception
def set_state(self, newState, timer=0): if _debug: ServerSSM._debug("set_state %r (%s) timer=%r", newState, SSM.transactionLabels[newState], timer) SSM.set_state(self, newState, timer) if (newState == COMPLETED) or (newState == ABORTED): if _debug: ServerSSM._debug(" - remove from...
This function is called when the client wants to change state.