Unnamed: 0
int64
0
389k
code
stringlengths
26
79.6k
docstring
stringlengths
1
46.9k
1,400
def forgot_password(): form_class = _security.forgot_password_form if request.is_json: form = form_class(MultiDict(request.get_json())) else: form = form_class() if form.validate_on_submit(): send_reset_password_instructions(form.user) if not request.is_json: ...
View function that handles a forgotten password request.
1,401
def get_method_documentation(method): from inspect import getargspec result = { : method.__name__, : .join([name.capitalize() for name in method.__name__.split()]), } arg_specs = getargspec(method) arguments = {} if not arg_specs.defaults: if len(arg_specs.args[1:])...
This function uses "inspect" to retrieve information about a method. Also, if you place comment on the method, method can be docummented with "reStructured Text". :param method: method to describe :returns: { 'name' : <string> - name of the method, 'friendly_na...
1,402
def add_state_editor(self, state_m): state_identifier = self.get_state_identifier(state_m) if state_identifier in self.closed_tabs: state_editor_ctrl = self.closed_tabs[state_identifier][] state_editor_view = state_editor_ctrl.view handler_id = self.closed_t...
Triggered whenever a state is selected. :param state_m: The selected state model.
1,403
def register_converter(operator_name, conversion_function, overwrite=False): if not overwrite and operator_name in _converter_pool: raise ValueError() _converter_pool[operator_name] = conversion_function
:param operator_name: A unique operator ID. It is usually a string but you can use a type as well :param conversion_function: A callable object :param overwrite: By default, we raise an exception if the caller of this function is trying to assign an existing key (i.e., operator_name) a new value (i.e., conv...
1,404
def get_all_apps(): LOG.info() url = .format(API_URL) response = requests.get(url, verify=GATE_CA_BUNDLE, cert=GATE_CLIENT_CERT) assert response.ok, pipelines = response.json() LOG.debug(, pipelines) return pipelines
Get a list of all applications in Spinnaker. Returns: requests.models.Response: Response from Gate containing list of all apps.
1,405
def filterAcceptsRow(self, row, parentindex): if not super(ReftrackSortFilterModel, self).filterAcceptsRow(row, parentindex): return False if parentindex.isValid(): m = parentindex.model() else: m = self.sourceModel() i = m.index(row, 18, par...
Return True, if the filter accepts the given row of the parent :param row: the row to filter :type row: :class:`int` :param parentindex: the parent index :type parentindex: :class:`QtCore.QModelIndex` :returns: True, if the filter accepts the row :rtype: :class:`bool` ...
1,406
def getmlsthelper(referencefilepath, start, organism, update): from accessoryFunctions.accessoryFunctions import GenObject organismset = set() organism = organism if organism != else organismdictionary = {: , : , : , ...
Prepares to run the getmlst.py script provided in SRST2
1,407
def neighsol(addr, src, iface, timeout=1, chainCC=0): nsma = in6_getnsma(inet_pton(socket.AF_INET6, addr)) d = inet_ntop(socket.AF_INET6, nsma) dm = in6_getnsmac(nsma) p = Ether(dst=dm) / IPv6(dst=d, src=src, hlim=255) p /= ICMPv6ND_NS(tgt=addr) p /= ICMPv6NDOptSrcLLAddr(lladdr=get_if_hwad...
Sends and receive an ICMPv6 Neighbor Solicitation message This function sends an ICMPv6 Neighbor Solicitation message to get the MAC address of the neighbor with specified IPv6 address address. 'src' address is used as source of the message. Message is sent on iface. By default, timeout waiting for an...
1,408
def load_yaml_config(self, conf): with open(conf) as fd: self.config = recursive_dict_update(self.config, yaml.load(fd, Loader=UnsafeLoader))
Load a YAML configuration file and recursively update the overall configuration.
1,409
def list_policies(self, filters=None): _, policy_list = self.handler.streamed_request("list-policies", "list-policy", filters) return policy_list
Retrieve installed trap, drop and bypass policies. :param filters: retrieve only matching policies (optional) :type filters: dict :return: list of installed trap, drop and bypass policies :rtype: list
1,410
def add_extension_attribute(self, ext_name, key, value): attributes = self.extension_attributes.pop(ext_name, {}) attributes[key] = value self.extension_attributes[ext_name] = attributes
Banana banana
1,411
def watcher(self) -> Watcher: if not hasattr(self, "_watcher"): self._watcher = Watcher() return self._watcher
Gives an access to action's watcher. :return: Action's watcher instance.
1,412
def GetResources(filename, types=None, names=None, languages=None): hsrc = win32api.LoadLibraryEx(filename, 0, LOAD_LIBRARY_AS_DATAFILE) res = _GetResources(hsrc, types, names, languages) win32api.FreeLibrary(hsrc) return res
Get resources from dll/exe file. types = a list of resource types to search for (None = all) names = a list of resource names to search for (None = all) languages = a list of resource languages to search for (None = all) Return a dict of the form {type_: {name: {language: data}}} which might a...
1,413
def gen_anytext(*args): bag = [] for term in args: if term is not None: if isinstance(term, list): for term2 in term: if term2 is not None: bag.append(term2) else: bag.append(term) return .join...
Convenience function to create bag of words for anytext property
1,414
def write(self, values): filtered = {_id: value for _id, value in values.items() if _id in self._document_ids} if not filtered: return bulk = self.get_collection().initialize_ordered_bulk_op() for _id, value in filtered.items(): bulk.find({: _i...
Write values to the targeted documents Values need to be a dict as : {document_id: value}
1,415
def _parse_values(self): data = [] if self.has_tabs: def _parse_tab_text(tab): if tab.select_one(".visible_normal"): return tab.select_one(".visible_normal").text else: return tab.text ...
Get values
1,416
def complete_modules(text): import MAVProxy.modules, pkgutil modlist = [x[1] for x in pkgutil.iter_modules(MAVProxy.modules.__path__)] ret = [] loaded = set(complete_loadedmodules()) for m in modlist: if not m.startswith("mavproxy_"): continue name = m[9:] if...
complete mavproxy module names
1,417
def create_sequence_sites(chain, seq_site_length): seq_ids = sorted(list(chain.keys()), key=int) slices = [itertools.islice(seq_ids, i, None) for i in range(seq_site_length)] seq_site_ids = list(zip(*slices)) sequence_sites = [] for seq_site_id in seq_site_ids: ...
Create sequence sites using sequence ids. :param dict chain: Chain object that contains chemical shift values and assignment information. :param int seq_site_length: Length of a single sequence site. :return: List of sequence sites. :rtype: :py:class:`list`
1,418
def from_dict(input_dict, data=None): import copy input_dict = copy.deepcopy(input_dict) model_class = input_dict.pop() input_dict["name"] = str(input_dict["name"]) import GPy model_class = eval(model_class) return model_class._build_from_input_dict(input...
Instantiate an object of a derived class using the information in input_dict (built by the to_dict method of the derived class). More specifically, after reading the derived class from input_dict, it calls the method _build_from_input_dict of the derived class. Note: This method should n...
1,419
def sha256_fingerprint_from_raw_ssh_pub_key(raw_key): digest = hashlib.sha256(raw_key).digest() h = base64.b64encode(digest).decode() h = h.rstrip().rstrip() return + h
Encode a raw SSH key (string of bytes, as from `str(paramiko.AgentKey)`) to a fingerprint in the SHA256 form: SHA256:j2WoSeOWhFy69BQ39fuafFAySp9qCZTSCEyT2vRKcL+s
1,420
def to_json(model, sort=False, **kwargs): obj = model_to_dict(model, sort=sort) obj[u"version"] = JSON_SPEC return json.dumps(obj, allow_nan=False, **kwargs)
Return the model as a JSON document. ``kwargs`` are passed on to ``json.dumps``. Parameters ---------- model : cobra.Model The cobra model to represent. sort : bool, optional Whether to sort the metabolites, reactions, and genes or maintain the order defined in the model. ...
1,421
def update(self, index, id, doc_type="_doc", body=None, params=None): for param in (index, id): if param in SKIP_IN_PATH: raise ValueError("Empty value passed for a required argument.") return self.transport.perform_request( "POST", _make_path(index, doc_...
Update a document based on a script or partial data provided. `<http://www.elastic.co/guide/en/elasticsearch/reference/current/docs-update.html>`_ :arg index: The name of the index :arg id: Document ID :arg body: The request definition using either `script` or partial `doc` :arg...
1,422
def get_django_user(self, username, password=None): try: user = User.objects.get(username=username) except User.DoesNotExist: user = User(username=username) if password is not None: user.set_password(password) user.save() return ...
Get the Django user with the given username, or create one if it doesn't already exist. If `password` is given, then set the user's password to that (regardless of whether the user was created or not).
1,423
def increase_volume(percentage): if percentage > 100 or percentage < 0: raise ValueError() if system.get_name() == : pass elif system.get_name() == : volume_int = percentage / 10 old_volume = get() new_volume = old_volume + volume_int if new_volume > 10: new_volume = 10 set_volume(new_...
Increase the volume. Increase the volume by a given percentage. Args: percentage (int): The percentage (as an integer between 0 and 100) to increase the volume by. Raises: ValueError: if the percentage is >100 or <0.
1,424
def __init_configsvrs(self, params): self._configsvrs = [] for cfg in params: cfg = self._strip_auth(cfg) server_id = cfg.pop(, None) version = cfg.pop(, self._version) cfg.update({: True}) if self.enable_ipv6: ...
create and start config servers
1,425
def _file_write(path, content): with salt.utils.files.fopen(path, ) as fp_: fp_.write(salt.utils.stringutils.to_str(content)) fp_.close()
Write content to a file
1,426
def pager_fatality_rates(): theta = 13.249 beta = 0.151 mmi_range = list(range(2, 11)) fatality_rate = {mmi: 0 if mmi < 4 else log_normal_cdf( mmi, median=theta, sigma=beta) for mmi in mmi_range} return fatality_rate
USGS Pager fatality estimation model. Fatality rate(MMI) = cum. standard normal dist(1/BETA * ln(MMI/THETA)). Reference: Jaiswal, K. S., Wald, D. J., and Hearne, M. (2009a). Estimating casualties for large worldwide earthquakes using an empirical approach. U.S. Geological Survey Open-File Report ...
1,427
def _find_players(self, year): if not year: year = utils._find_year_for_season() url = self._create_url(year) page = self._pull_team_page(url) if not page: output = ("Cantable player_id = self._get_id(player) if self._slim: ...
Find all player IDs for the requested team. For the requested team and year (if applicable), pull the roster table and parse the player ID for all players on the roster and create an instance of the Player class for the player. All player instances are added to the 'players' property to...
1,428
def tent_map(x, steps, mu=2): for _ in range(steps): x = mu * x if x < 0.5 else mu * (1 - x) yield x
Generates a time series of the tent map. Characteristics and Background: The name of the tent map is derived from the fact that the plot of x_i vs x_i+1 looks like a tent. For mu > 1 one application of the mapping function can be viewed as stretching the surface on which the value is located and then...
1,429
def nexec(statement, globals=None, locals=None, **kwargs): try: import __builtin__ as builtins except ImportError: import builtins from ast import parse from napi.transformers import NapiTransformer from ast import fix_missing_locations as fml try: node = parse(sta...
Execute *statement* using *globals* and *locals* dictionaries as *global* and *local* namespace. *statement* is transformed using :class:`.NapiTransformer`.
1,430
def _draw_frame(self, framedata): original = self.read_frame() if original is None: self.update_info(self.info_string(message=, frame=framedata)) return if self.original is not None: processed = self.proc...
Reads, processes and draws the frames. If needed for color maps, conversions to gray scale are performed. In case the images are no color images and no custom color maps are defined, the colormap `gray` is applied. This function is called by TimedAnimation. Args: f...
1,431
def match_any_learning_objective(self, match): match_key = param = if match: flag = else: flag = if match_key in self._my_osid_query._query_terms: self._my_osid_query._query_terms[match_key][param] = flag else: ...
Matches an item with any objective. arg: match (boolean): ``true`` to match items with any learning objective, ``false`` to match items with no learning objectives *compliance: mandatory -- This method must be implemented.*
1,432
def set_poll_func(self, func, func_err_handler=None): if not func_err_handler: func_err_handler = traceback.print_exception self._pa_poll_cb = c.PA_POLL_FUNC_T(ft.partial(self._pulse_poll_cb, func, func_err_handler)) c.pa.mainloop_set_poll_func(self._loop, self._pa_poll_cb, None)
Can be used to integrate pulse client into existing eventloop. Function will be passed a list of pollfd structs and timeout value (seconds, float), which it is responsible to use and modify (set poll flags) accordingly, returning int value >= 0 with number of fds that had any new events within timeout. fu...
1,433
def eeg_microstates_relabel(method, results, microstates_labels, reverse_microstates=None): microstates = list(method[]) for index, microstate in enumerate(method[]): if microstate in list(reverse_microstates.keys()): microstates[index] = reverse_microstates[microstate] m...
Relabel the microstates.
1,434
def _(s: Influence) -> bool: return is_grounded(s.subj) and is_grounded(s.obj)
Check if an Influence statement is grounded
1,435
def channel(self): if not self._channel: self._channel_ref = weakref.ref(self.connection.get_channel()) return self._channel
If no channel exists, a new one is requested.
1,436
def _reduce(self): for reduction, methname in self.reducers: token_num = len(reduction) if (len(self.tokens) >= token_num and self.tokens[-token_num:] == reduction): meth = getattr(self, methname) ...
Perform a greedy reduction of token stream. If a reducer method matches, it will be executed, then the :meth:`reduce` method will be called recursively to search for any more possible reductions.
1,437
def check(ctx): check_command = f"twine check {ctx.directory!s}/dist/*" report.info(ctx, "package.check", "checking package") ctx.run(check_command)
Check built package is valid.
1,438
def get_collections(self, data): collections = self._filter_queryset(, data.collection_set.all()) from .collection import CollectionSerializer class CollectionWithoutDataSerializer(WithoutDataSerializerMixin, CollectionSerializer): return self._serialize_items(Co...
Return serialized list of collection objects on data that user has `view` permission on.
1,439
def get_network_by_id(self, network_id: int) -> Network: return self.session.query(Network).get(network_id)
Get a network from the database by its identifier.
1,440
def set_active_vectors(self, name, preference=): _, field = get_scalar(self, name, preference=preference, info=True) if field == POINT_DATA_FIELD: self.GetPointData().SetActiveVectors(name) elif field == CELL_DATA_FIELD: self.GetCellData().SetActiveVectors(name) ...
Finds the vectors by name and appropriately sets it as active
1,441
def run(self): try: build_ext.build_ext.run(self) build_dir = os.path.abspath(self.build_lib) root_dir = os.path.abspath(os.path.join(__file__, "..")) target_dir = build_dir if not self.inplace else root_dir src_file = os.path.j...
Run. :raises BuildFailed: extension build failed and need to skip cython part.
1,442
def iam(self): iam = { : self.format[].format(**self.data), : self.format[].format(**self.data), : self.format[].format(**self.data), : self.format[].format(**self.data), : self.format[].format(**self.data), : self.format[].format(...
Generate iam details.
1,443
def update_loadbalancer(self, lbaas_loadbalancer, body=None): return self.put(self.lbaas_loadbalancer_path % (lbaas_loadbalancer), body=body)
Updates a load balancer.
1,444
def get_default_config_help(self): config_help = super(MemoryLxcCollector, self).get_default_config_help() config_help.update({ "sys_path": "Defaults to ", }) return config_help
Return help text for collector configuration.
1,445
def from_json(self, resource_root, data): if data is None: return None if self._atype == datetime.datetime: return datetime.datetime.strptime(data, self.DATE_FMT) elif self._atype == ApiConfig: if not data[]: return { } first = data[][0] retur...
Parses the given JSON value into an appropriate python object. This means: - a datetime.datetime if 'atype' is datetime.datetime - a converted config dictionary or config list if 'atype' is ApiConfig - if the attr is an API list, an ApiList with instances of 'atype' - an instance of 'atype' if ...
1,446
def getKeywordsForText(self, retina_name, body, ): resourcePath = method = queryParams = {} headerParams = {: , : } postData = None queryParams[] = retina_name postData = body response = self.apiClient._callAPI(resourcePath, method, queryPara...
Get a list of keywords from the text Args: retina_name, str: The retina name (required) body, str: The text to be evaluated (required) Returns: Array[str]
1,447
def pack_image(filename, max_size, form_field=): try: if os.path.getsize(filename) > (max_size * 1024): raise IdeaScalyError( % max_size) except os.error as e: raise IdeaScalyError( % e.strerror) fp = open(filename, ) f...
Pack an image from file into multipart-formdata post body
1,448
def _convert_types(schema, col_type_dict, row): converted_row = [] for col_name, col_val in zip(schema, row): if type(col_val) in (datetime, date): col_val = time.mktime(col_val.timetuple()) elif isinstance(col_val, Decimal): col_val = flo...
Takes a value from MySQLdb, and converts it to a value that's safe for JSON/Google cloud storage/BigQuery. Dates are converted to UTC seconds. Decimals are converted to floats. Binary type fields are encoded with base64, as imported BYTES data must be base64-encoded according to Bigquery SQL ...
1,449
def plot_signal(signal, sig_len, n_sig, fs, time_units, sig_style, axes): "Plot signal channels" if len(sig_style) == 1: sig_style = n_sig * sig_style if time_units == : t = np.linspace(0, sig_len-1, sig_len) else: downsample_factor = {:fs, :fs * 60, ...
Plot signal channels
1,450
def is_scalar(value): return np.isscalar(value) or (isinstance(value, np.ndarray) and (len(np.squeeze(value).shape) == 0))
Test if the given value is a scalar. This function also works with memory mapped array values, in contrast to the numpy is_scalar method. Args: value: the value to test for being a scalar value Returns: boolean: if the given value is a scalar or not
1,451
def noisy_operation(self, operation: ) -> : if not hasattr(self.noisy_moments, ): return self.noisy_moments([ops.Moment([operation])], operation.qubits) if not hasattr(self.noisy_moment, ): return self.noisy_moment(ops.Moment([opera...
Adds noise to an individual operation. Args: operation: The operation to make noisy. Returns: An OP_TREE corresponding to the noisy operations implementing the noisy version of the given operation.
1,452
def do_check_artifact_cache(self, vts, post_process_cached_vts=None): if not vts: return [], [], [] read_cache = self._cache_factory.get_read_cache() items = [(read_cache, vt.cache_key, vt.current_results_dir if self.cache_target_dirs else None) for vt in vts] res = self.context...
Checks the artifact cache for the specified list of VersionedTargetSets. Returns a tuple (cached, uncached, uncached_causes) of VersionedTargets that were satisfied/unsatisfied from the cache.
1,453
def is_dict_like(obj): dict_like_attrs = ("__getitem__", "keys", "__contains__") return (all(hasattr(obj, attr) for attr in dict_like_attrs) and not isinstance(obj, type))
Check if the object is dict-like. Parameters ---------- obj : The object to check Returns ------- is_dict_like : bool Whether `obj` has dict-like properties. Examples -------- >>> is_dict_like({1: 2}) True >>> is_dict_like([1, 2, 3]) False >>> is_dict_like(...
1,454
def set_fixed_image(self, image): if not isinstance(image, iio.ANTsImage): raise ValueError() if image.dimension != self.dimension: raise ValueError( % (image.dimension, self.dimension)) self._metric.setFixedImage(image.pointer, False) self.fixed_image ...
Set Fixed ANTsImage for metric
1,455
def _translate_key(key): d = _get_deprecated_option(key) if d: return d.rkey or key else: return key
if key id deprecated and a replacement key defined, will return the replacement key, otherwise returns `key` as - is
1,456
def _generate_processed_key_name(process_to, upload_name): timestamp = datetime.now().strftime() name, extension = os.path.splitext(upload_name) digest = md5(.join([timestamp, upload_name])).hexdigest() return os.path.join(process_to, .format(digest, extension))
Returns a key name to use after processing based on timestamp and upload key name.
1,457
def get_relative_from_paths(self, filepath, paths): for systempath in paths_by_depth(paths): if filepath.startswith(systempath): return os.path.relpath(filepath, systempath) raise FinderException(" could not " "find filepath start from ...
Find the relative filepath from the most relevant multiple paths. This is somewhat like a ``os.path.relpath(path[, start])`` but where ``start`` is a list. The most relevant item from ``paths`` will be used to apply the relative transform. Args: filepath (str): Path to tran...
1,458
def find_dangerous_changes( old_schema: GraphQLSchema, new_schema: GraphQLSchema ) -> List[DangerousChange]: return ( find_arg_changes(old_schema, new_schema).dangerous_changes + find_values_added_to_enums(old_schema, new_schema) + find_interfaces_added_to_object_types(old_schema, n...
Find dangerous changes. Given two schemas, returns a list containing descriptions of all the types of potentially dangerous changes covered by the other functions down below.
1,459
def desc(self) -> str: kind, value = self.kind.value, self.value return f"{kind} {value!r}" if value else kind
A helper property to describe a token as a string for debugging
1,460
def _get_content_type(self, filename): mntype = mimetypes.guess_type(filename)[0] filename, fileExtension = os.path.splitext(filename) if mntype is None and\ fileExtension.lower() == ".csv": mntype = "text/csv" elif mntype is None and \ fileEx...
gets the content type of a file
1,461
def set(self, project, date, data, data_ts): data[] = { : project, : date.strftime(), : time.time(), : VERSION, : data_ts } fpath = self._path_for_file(project, date) logger.debug(, project, date.st...
Set the cache data for a specified project for the specified date. :param project: project name to set data for :type project: str :param date: date to set data for :type date: datetime.datetime :param data: data to cache :type data: dict :param data_ts: maximum ...
1,462
def _button_plus_clicked(self, n): self._button_save.setEnabled(True) self.insert_colorpoint(self._colorpoint_list[n][0], self._colorpoint_list[n][1], self._colorpoint_list[n][2]) self._build_gui()
Create a new colorpoint.
1,463
def Unlock(fd, path): try: fcntl.flock(fd, fcntl.LOCK_UN | fcntl.LOCK_NB) except IOError as e: if e.errno == errno.EWOULDBLOCK: raise IOError( % path) else: raise IOError( % (path, str(e)))
Release the lock on the file. Args: fd: int, the file descriptor of the file to unlock. path: string, the name of the file to lock. Raises: IOError, raised from flock while attempting to release a file lock.
1,464
def _set_linkinfo_domain_reachable(self, v, load=False): if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=RestrictedClassType(base_type=unicode, restriction_dict={: u, : [u]}), is_leaf=True, yang_name="linkinfo-domain-reachable", rest_name="linkinfo-domain-reachable", paren...
Setter method for linkinfo_domain_reachable, mapped from YANG variable /brocade_fabric_service_rpc/show_linkinfo/output/show_link_info/linkinfo_domain_reachable (linkinfo-domain-reachable-type) If this variable is read-only (config: false) in the source YANG file, then _set_linkinfo_domain_reachable is consider...
1,465
def linear_exprs(A, x, b=None, rref=False, Matrix=None): if b is None: b = [0]*len(x) if rref: rA, rb = linear_rref(A, b, Matrix) if Matrix is None: from sympy import Matrix return [lhs - rhs for lhs, rhs in zip(rA * Matrix(len(x), 1, x), rb)] else: r...
Returns Ax - b Parameters ---------- A : matrix_like of numbers Of shape (len(b), len(x)). x : iterable of symbols b : array_like of numbers (default: None) When ``None``, assume zeros of length ``len(x)``. Matrix : class When ``rref == True``: A matrix class which suppo...
1,466
def decompressBuffer(buffer): "complements the compressBuffer function in CacheClient" zbuf = cStringIO.StringIO(buffer) zfile = gzip.GzipFile(fileobj=zbuf) deflated = zfile.read() zfile.close() return deflated
complements the compressBuffer function in CacheClient
1,467
def login(self, username, json_document): url = .format(self.url, username) make_request( url, method=, body=json_document, timeout=self.timeout)
Send user identity information to the identity manager. Raise a ServerError if an error occurs in the request process. @param username The logged in user. @param json_document The JSON payload for login.
1,468
def extract_largest(self, inplace=False): mesh = self.connectivity(largest=True) if inplace: self.overwrite(mesh) else: return mesh
Extract largest connected set in mesh. Can be used to reduce residues obtained when generating an isosurface. Works only if residues are not connected (share at least one point with) the main component of the image. Parameters ---------- inplace : bool, optional ...
1,469
def to_image_list(tensors, size_divisible=0): if isinstance(tensors, torch.Tensor) and size_divisible > 0: tensors = [tensors] if isinstance(tensors, ImageList): return tensors elif isinstance(tensors, torch.Tensor): assert tensors.dim() == 4 image_sizes = [ten...
tensors can be an ImageList, a torch.Tensor or an iterable of Tensors. It can't be a numpy array. When tensors is an iterable of Tensors, it pads the Tensors with zeros so that they have the same shape
1,470
def getSolutionIter(self): domains, constraints, vconstraints = self._getArgs() if not domains: return iter(()) return self._solver.getSolutionIter(domains, constraints, vconstraints)
Return an iterator to the solutions of the problem Example: >>> problem = Problem() >>> list(problem.getSolutionIter()) == [] True >>> problem.addVariables(["a"], [42]) >>> iter = problem.getSolutionIter() >>> next(iter) {'a': 42} >>> next(iter) ...
1,471
def find_multiplex_by_name(self, multiplex_name: str) -> Multiplex: for multiplex in self.multiplexes: if multiplex.name == multiplex_name: return multiplex raise AttributeError(f)
Find and return a multiplex in the influence graph with the given name. Raise an AttributeError if there is no multiplex in the graph with the given name.
1,472
def get_suppliers_per_page(self, per_page=1000, page=1, params=None): return self._get_resource_per_page(resource=SUPPLIERS, per_page=per_page, page=page, params=params)
Get suppliers per page :param per_page: How many objects per page. Default: 1000 :param page: Which page. Default: 1 :param params: Search parameters. Default: {} :return: list
1,473
def key_exists(self, section, key): LOGGER.debug("> Checking key existence in section.".format(key, section)) self.__settings.beginGroup(section) exists = self.__settings.contains(key) self.__settings.endGroup() return exists
Checks if given key exists. :param section: Current section to check key in. :type section: unicode :param key: Current key to check. :type key: unicode :return: Key existence. :rtype: bool
1,474
def _decode_embedded_dict(src): output = {} for key, val in six.iteritems(src): if isinstance(val, dict): val = _decode_embedded_dict(val) elif isinstance(val, list): val = _decode_embedded_list(val) elif isinstance(val, bytes): try: ...
Convert enbedded bytes to strings if possible. Dict helper.
1,475
def _filter_headers(self): headers = {} for user in self.usernames: headers["fedora_messaging_user_{}".format(user)] = True for package in self.packages: headers["fedora_messaging_rpm_{}".format(package)] = True for container in self.containers: ...
Add headers designed for filtering messages based on objects. Returns: dict: Filter-related headers to be combined with the existing headers
1,476
def import_app_module(app_name, module_name): name_split = app_name.split() if name_split[-1][0].isupper(): app_name = .join(name_split[:-2]) module = import_module(app_name) try: sub_module = import_module( % (app_name, module_name)) return sub_module except: ...
Returns a module from a given app by its name. :param str app_name: :param str module_name: :rtype: module or None
1,477
def dig(host): * cmd = .format(salt.utils.network.sanitize_host(host)) return __salt__[](cmd)
Performs a DNS lookup with dig CLI Example: .. code-block:: bash salt '*' network.dig archlinux.org
1,478
def create_filter(self): return Filter( self.networkapi_url, self.user, self.password, self.user_ldap)
Get an instance of filter services facade.
1,479
def _check_connections(self): for server in self._servers: if self._is_reachable(server): server[] = 0 else: server[] = time.time() + 5
Checks if all configured redis servers are reachable
1,480
def clean(self): self._table.clear() for item in self._usage_recency: self._usage_recency.remove(item)
Empties the cache
1,481
def fit(self, X, y, **fit_params): return default_client().sync(self._fit, X, y, **fit_params)
Find the best parameters for a particular model. Parameters ---------- X, y : array-like **fit_params Additional partial fit keyword arguments for the estimator.
1,482
def json_data(self): def stringify_keys(d): if not isinstance(d, dict): return d return dict((str(k), stringify_keys(v)) for k, v in d.items()) data = self.make_data() json_data = json.dumps(stringify_keys(data)) return json_data
Returns data as JSON Returns: json_data (str): JSON representation of data, as created in make_data
1,483
def fetch_assets(self): packages = set( env.instance.config.get(, ).split()) packages.update([]) cmd = env.instance.config.get(, ) items = sorted(self.bootstrap_files.items()) for filename, asset in items: if asset.url: if...
download bootstrap assets to control host. If present on the control host they will be uploaded to the target host during bootstrapping.
1,484
def _serialize_value_for_xml(self, value): if value is not None: value_serialized = self.serializer.serialize(value) else: value_serialized = return value_serialized
See base class.
1,485
def applyIndex(self, lst, right): if len(right) != 1: raise exceptions.EvaluationError( % (self.left, self.right)) right = right[0] if isinstance(right, int): return lst[right] raise exceptions.EvaluationError("Can't apply %r to argument (%r): integer expected, got %r" % (self.left, s...
Apply a list to something else.
1,486
def indication(self, pdu): if _debug: TCPServer._debug("indication %r", pdu) self.request += pdu.pduData
Requests are queued for delivery.
1,487
def get_partition_dciId(self, org_name, part_name, part_info=None): if part_info is None: part_info = self._get_partition(org_name, part_name) LOG.info("query result from dcnm for partition info is %s", part_info) if part_info is not None and "dciId"...
get DCI ID for the partition. :param org_name: name of organization :param part_name: name of partition
1,488
def load_vectors(self, vectors, **kwargs): if not isinstance(vectors, list): vectors = [vectors] for idx, vector in enumerate(vectors): if six.PY2 and isinstance(vector, str): vector = six.text_type(vector) if isinstance(vector, six.string_typ...
Arguments: vectors: one of or a list containing instantiations of the GloVe, CharNGram, or Vectors classes. Alternatively, one of or a list of available pretrained vectors: charngram.100d fasttext.en.300d fasttext.simple.300d ...
1,489
def detach(self, ids=None, touch=True): if isinstance(ids, orator.orm.model.Model): ids = ids.get_key() if ids is None: ids = [] query = self._new_pivot_query() if not isinstance(ids, list): ids = [ids] if len(ids) > 0: ...
Detach models from the relationship.
1,490
def tValueForPoint(self, point): if self.segmentType == "curve": on1 = self.previousOnCurve off1 = self.points[0].coordinates off2 = self.points[1].coordinates on2 = self.points[2].coordinates return _tValueForPointOnCubicCurve(point, (on1, of...
get a t values for a given point required: the point must be a point on the curve. in an overlap cause the point will be an intersection points wich is alwasy a point on the curve
1,491
def delete_messages(self, messages): url = "/2/messages/?%s" % urlencode([(, ",".join(messages))]) data = self._delete_resource(url) return data
Delete existing messages. http://dev.wheniwork.com/#delete-existing-message
1,492
def getTypeName(data_type_oid, type_modifier): if data_type_oid == VerticaType.BOOL: return "Boolean" elif data_type_oid == VerticaType.INT8: return "Integer" elif data_type_oid == VerticaType.FLOAT8: return "Float" elif data_type_oid == VerticaType.CHAR: return "Ch...
Returns the base type name according to data_type_oid and type_modifier
1,493
def parse(self, args=None): s `[]` field. s in the world can_', []).append(name) return opts
Parse a list of arguments, returning a dict. Flags are only boolean if they are not followed by a non-flag argument. All positional arguments not associable with a flag will be added to the return dictionary's `['_']` field.
1,494
def readline(self): self.lineno += 1 if self._buffer: return self._buffer.pop() else: return self.input.readline()
Get the next line including the newline or '' on EOF.
1,495
def max_intensity(item_a, time_a, item_b, time_b, max_value): intensity_a = item_a.max_intensity(time_a) intensity_b = item_b.max_intensity(time_b) diff = np.sqrt((intensity_a - intensity_b) ** 2) return np.minimum(diff, max_value) / float(max_value)
RMS difference in maximum intensity Args: item_a: STObject from the first set in ObjectMatcher time_a: Time integer being evaluated item_b: STObject from the second set in ObjectMatcher time_b: Time integer being evaluated max_value: Maximum distance value used as scaling va...
1,496
def parser(self): if self._command_parser is None: parents = [] if self.need_verbose: parents.append(_verbose_parser) if self.need_settings: parents.append(_settings_parser) self._command_parser = self._main_parser.add_par...
Returns the appropriate parser to use for adding arguments to your command.
1,497
def read(self, filename): with tarfile.open(filename, "r:*") as arc: temp_dir = tempfile.mkdtemp() arc.extractall(path=temp_dir, members=_safemembers(arc)) tribe_dir = glob.glob(temp_dir + os.sep + )[0] self._read_from_folder(dirname=tribe_dir) sh...
Read a tribe of templates from a tar formatted file. :type filename: str :param filename: File to read templates from. .. rubric:: Example >>> tribe = Tribe(templates=[Template(name='c', st=read())]) >>> tribe.write('test_tribe') Tribe of 1 templates >>> tribe_...
1,498
def build(path, query=None, fragment=): url = nstr(path) keys = projex.text.findkeys(path) if keys: if query is None: query = {} opts = {} for key in keys: opts[key] = query.pop(key, .format(key)) url %= opts if query: if...
Generates a URL based on the inputted path and given query options and fragment. The query should be a dictionary of terms that will be generated into the URL, while the fragment is the anchor point within the target path that will be navigated to. If there are any wildcards within the path that are f...
1,499
def unpack(self, buff, offset=0): super().unpack(buff, offset) if self.tpid.value: self._validate() self.tpid = self.tpid.value self.pcp = self._tci.value >> 13 self.cfi = (self._tci.value >> 12) & 1 self.vid = self._tci.value & 4095 ...
Unpack a binary struct into this object's attributes. Return the values instead of the lib's basic types. After unpacking, the abscence of a `tpid` value causes the assignment of None to the field values to indicate that there is no VLAN information. Args: buff (by...