Unnamed: 0
int64
0
389k
code
stringlengths
26
79.6k
docstring
stringlengths
1
46.9k
20,800
def pagination_for(context, current_page, page_var="page", exclude_vars=""): querystring = context["request"].GET.copy() exclude_vars = [v for v in exclude_vars.split(",") if v] + [page_var] for exclude_var in exclude_vars: if exclude_var in querystring: del querystring[exclude_var]...
Include the pagination template and data for persisting querystring in pagination links. Can also contain a comma separated string of var names in the current querystring to exclude from the pagination links, via the ``exclude_vars`` arg.
20,801
def arquire_attributes(self, attributes, active=True): attribute_update = self._post_object(self.update_api.attributes.acquire, attributes) return ExistAttributeResponse(attribute_update)
Claims a list of attributes for the current client. Can also disable attributes. Returns update response object.
20,802
def conditional_gate(control: Qubit, gate0: Gate, gate1: Gate) -> Gate: assert gate0.qubits == gate1.qubits tensor = join_gates(P0(control), gate0).tensor tensor += join_gates(P1(control), gate1).tensor gate = Gate(tensor=tensor, qubits=[control, *gate0.qubits]) return gate
Return a conditional unitary gate. Do gate0 on bit 1 if bit 0 is zero, else do gate1 on 1
20,803
def transmission_rate(self): sent = self.bytes_sent received = self.bytes_received traffic_call = time.time() time_delta = traffic_call - self.last_traffic_call upstream = int(1.0 * (sent - self.last_bytes_sent)/time_delta) downstream = int(1.0 * (received - self...
Returns the upstream, downstream values as a tuple in bytes per second. Use this for periodical calling.
20,804
def encode_request(request_line, **headers): lines = [request_line] lines.extend([ % kv for kv in headers.items()]) return (.join(lines) + ).encode()
Creates the data for a SSDP request. Args: request_line (string): The request line for the request (e.g. ``"M-SEARCH * HTTP/1.1"``). headers (dict of string -> string): Dictionary of header name - header value pairs to present in the request. Returns: bytes: The...
20,805
def runGetReference(self, id_): compoundId = datamodel.ReferenceCompoundId.parse(id_) referenceSet = self.getDataRepository().getReferenceSet( compoundId.reference_set_id) reference = referenceSet.getReference(id_) return self.runGetRequest(reference)
Runs a getReference request for the specified ID.
20,806
def status(**connection_args): * dbc = _connect(**connection_args) if dbc is None: return {} cur = dbc.cursor() qry = try: _execute(cur, qry) except OperationalError as exc: err = .format(*exc.args) __context__[] = err log.error(err) return {}...
Return the status of a MySQL server using the output from the ``SHOW STATUS`` query. CLI Example: .. code-block:: bash salt '*' mysql.status
20,807
def iou_coe(output, target, threshold=0.5, axis=(1, 2, 3), smooth=1e-5): pre = tf.cast(output > threshold, dtype=tf.float32) truth = tf.cast(target > threshold, dtype=tf.float32) inse = tf.reduce_sum(tf.multiply(pre, truth), axis=axis) union = tf.reduce_sum(tf.cast(tf.add(pre, truth) >= 1, dtype=...
Non-differentiable Intersection over Union (IoU) for comparing the similarity of two batch of data, usually be used for evaluating binary image segmentation. The coefficient between 0 to 1, and 1 means totally match. Parameters ----------- output : tensor A batch of distribution with shape:...
20,808
def human_size(size): if isinstance(size, string_types): size = int(size, 10) if size < 0: return "-??? bytes" if size < 1024: return "%4d bytes" % size for unit in ("KiB", "MiB", "GiB"): size /= 1024.0 if size < 1024: return "%6.1f %s" % (size,...
Return a human-readable representation of a byte size. @param size: Number of bytes as an integer or string. @return: String of length 10 with the formatted result.
20,809
def is_analysis_edition_allowed(self, analysis_brain): if not self.context_active: return False analysis_obj = api.get_object(analysis_brain) if analysis_obj.getPointOfCapture() == : if not self.has_permission(EditFieldResu...
Returns if the analysis passed in can be edited by the current user :param analysis_brain: Brain that represents an analysis :return: True if the user can edit the analysis, otherwise False
20,810
def get_feature(self, ds, feat): if ds.config["filtering"]["enable filters"]: x = ds[feat][ds._filter] else: x = ds[feat] bad = np.isnan(x) | np.isinf(x) xout = x[~bad] return xout
Return filtered feature data The features are filtered according to the user-defined filters, using the information in `ds._filter`. In addition, all `nan` and `inf` values are purged. Parameters ---------- ds: dclab.rtdc_dataset.RTDCBase The dataset contain...
20,811
def error(self, instance, value, error_class=None, extra=): error_class = error_class or ValidationError if not isinstance(value, (list, tuple, np.ndarray)): super(Array, self).error(instance, value, error_class, extra) if isinstance(value, (list, tuple)): val_de...
Generates a ValueError on setting property to an invalid value
20,812
def connectToBroker(self, protocol): self.protocol = protocol self.protocol.onPublish = self.onPublish self.protocol.onDisconnection = self.onDisconnection self.protocol.setWindowSize(3) try: yield self.protocol.connect("TwistedMQTT-sub...
Connect to MQTT broker
20,813
def convertColors(element): numBytes = 0 if element.nodeType != Node.ELEMENT_NODE: return 0 attrsToConvert = [] if element.nodeName in [, , , , , , , , ]: attrsToConvert = [, ] elif element.nodeName in []: attrsToConvert = [] elif e...
Recursively converts all color properties into #RRGGBB format if shorter
20,814
def insert(parent: ScheduleComponent, time: int, child: ScheduleComponent, name: str = None) -> Schedule: return union(parent, (time, child), name=name)
Return a new schedule with the `child` schedule inserted into the `parent` at `start_time`. Args: parent: Schedule to be inserted into time: Time to be inserted defined with respect to `parent` child: Schedule to insert name: Name of the new schedule. Defaults to name of parent
20,815
def provideCustomerReferralCode(sender,**kwargs): s profile page can show their voucher referral code. customervouchers__enableVouchersreferrals__enableReferralProgramreferralVoucherId': vrd.referreeVoucher.voucherId }
If the vouchers app is installed and referrals are enabled, then the customer's profile page can show their voucher referral code.
20,816
def _update_statuses(self, sub_job_num=None): status_dict = dict() for val in CONDOR_JOB_STATUSES.values(): status_dict[val] = 0 for node in self.node_set: job = node.job try: job_status = job.status status_d...
Update statuses of jobs nodes in workflow.
20,817
def runserver(ctx, conf, port, foreground): config = read_config(conf) debug = config[].get(, False) click.echo(.format( if debug else )) port = port or config[][][] app_settings = { : debug, : config[][].get(, False), } handlers_settings = __create_handler_settings(c...
Run the fnExchange server
20,818
def p_const_vector_vector_list(p): if len(p[3]) != len(p[1][0]): syntax_error(p.lineno(2), ) p[0] = None return p[0] = p[1] + [p[3]]
const_vector_list : const_vector_list COMMA const_vector
20,819
def string_to_int( s ): result = 0 for c in s: if not isinstance(c, int): c = ord( c ) result = 256 * result + c return result
Convert a string of bytes into an integer, as per X9.62.
20,820
def validate(self, value, model=None, context=None): from boiler.user.services import user_service self_id = None if model: if isinstance(model, dict): self_id = model.get() else: self_id = getattr(model, ) params = dict(...
Perform validation
20,821
def _execute(self, query, commit=False, working_columns=None): log.debug("RawlBase._execute()") result = [] if working_columns is None: working_columns = self.columns with RawlConnection(self.dsn) as conn: query_id = random.randrange(9999) ...
Execute a query with provided parameters Parameters :query: SQL string with parameter placeholders :commit: If True, the query will commit :returns: List of rows
20,822
def configure_logging(info=False, debug=False): if info: logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) logging.getLogger().setLevel(logging.WARNING) logging.getLogger().setLevel(logging.WARNING) logging.getLogger().setLevel(logging.WARNIN...
Configure logging The function configures log messages. By default, log messages are sent to stderr. Set the parameter `debug` to activate the debug mode. :param debug: set the debug mode
20,823
def cwd(self, new_path): old_cwd = self._cwd self._cwd = new_path return old_cwd
Sets the cwd during reads and writes
20,824
def freeSave(self, obj) : if self.saveIniator is obj and not self.inTransaction : self.saveIniator = None self.savedObject = set() self.connection.commit() return True return False
THIS IS WHERE COMMITS TAKE PLACE! Ends a saving session, only the initiator can end a session. The commit is performed at the end of the session
20,825
def check_params(**kwargs): missing_params = [] check = True for param in kwargs: if kwargs[param] is None: missing_params.append(param) if len(missing_params) > 0: print("POT - Warning: following necessary parameters are missing") for p in missing_params: ...
check_params: check whether some parameters are missing
20,826
def _hjoin_multiline(join_char, strings): cstrings = [string.split("\n") for string in strings] max_num_lines = max(len(item) for item in cstrings) pp = [] for k in range(max_num_lines): p = [cstring[k] for cstring in cstrings] pp.append(join_char + join_char.join(p) + join_char) ...
Horizontal join of multiline strings
20,827
def add_int(self, name, min, max, warp=None): min, max = map(int, (min, max)) if max < min: raise ValueError( % name) if warp not in (None, ): raise ValueError( % (name, warp)) if min <= 0 and warp == : raise Valu...
An integer-valued dimension bounded between `min` <= x <= `max`. Note that the right endpoint of the interval includes `max`. When `warp` is None, the base measure associated with this dimension is a categorical distribution with each weight on each of the integers in [min, max]. With `...
20,828
def get_authenticated_user(self, redirect_uri, callback, scope=None, **args): code = self.get_argument(, None) if not code: self.authorize_redirect(redirect_uri, scope=scope, **args) return self.get_access_token( code, callback=(yield gen.Callback())...
class RenrenHandler(tornado.web.RequestHandler, RenrenGraphMixin): @tornado.web.asynchronous @gen.engine def get(self): self.get_authenticated_user( callback=(yield gen.Callback('key')), redirect_uri=url) user = ...
20,829
async def cancel_task(app: web.Application, task: asyncio.Task, *args, **kwargs ) -> Any: return await get_scheduler(app).cancel(task, *args, **kwargs)
Convenience function for calling `TaskScheduler.cancel(task)` This will use the default `TaskScheduler` to cancel the given task. Example: import asyncio from datetime import datetime from brewblox_service import scheduler, service async def current_time(interval): ...
20,830
def _organize_variants(samples, batch_id): caller_names = [x["variantcaller"] for x in samples[0]["variants"]] calls = collections.defaultdict(list) for data in samples: for vrn in data["variants"]: calls[vrn["variantcaller"]].append(vrn["vrn_file"]) data = samples[0] vrn_fi...
Retrieve variant calls for all samples, merging batched samples into single VCF.
20,831
def clone(self, new_object): return self.__class__(new_object, self.method, self.name)
Returns an object that re-binds the underlying "method" to the specified new object.
20,832
def response(self, model=None, code=HTTPStatus.OK, description=None, **kwargs): code = HTTPStatus(code) if code is HTTPStatus.NO_CONTENT: assert model is None if model is None and code not in {HTTPStatus.ACCEPTED, HTTPStatus.NO_CONTENT}: if code.value not in http...
Endpoint response OpenAPI documentation decorator. It automatically documents HTTPError%(code)d responses with relevant schemas. Arguments: model (flask_marshmallow.Schema) - it can be a class or an instance of the class, which will be used for OpenAPI documentation...
20,833
def get_template_sources(self, template_name, template_dirs=None): if not template_dirs: template_dirs = self.get_dirs() for template_dir in template_dirs: try: name = safe_join(template_dir, template_name) except SuspiciousFileOperation: ...
Returns the absolute paths to "template_name", when appended to each directory in "template_dirs". Any paths that don't lie inside one of the template dirs are excluded from the result set, for security reasons.
20,834
def doc(self): collector = [] for name, varname in self.components._namespace.items(): try: docstring = getattr(self.components, varname).__doc__ lines = docstring.split() collector.append({: name, : v...
Formats a table of documentation strings to help users remember variable names, and understand how they are translated into python safe names. Returns ------- docs_df: pandas dataframe Dataframe with columns for the model components: - Real names ...
20,835
def statuses_show(self, id, trim_user=None, include_my_retweet=None, include_entities=None): params = {: id} set_bool_param(params, , trim_user) set_bool_param(params, , include_my_retweet) set_bool_param(params, , include_entities) return self._get...
Returns a single Tweet, specified by the id parameter. https://dev.twitter.com/docs/api/1.1/get/statuses/show/%3Aid :param str id: (*required*) The numerical ID of the desired tweet. :param bool trim_user: When set to ``True``, the tweet's user object includes only the...
20,836
def get_files(self): return github.PaginatedList.PaginatedList( github.File.File, self._requester, self.url + "/files", None )
:calls: `GET /repos/:owner/:repo/pulls/:number/files <http://developer.github.com/v3/pulls>`_ :rtype: :class:`github.PaginatedList.PaginatedList` of :class:`github.File.File`
20,837
def create_ellipse(self,xcen,ycen,a,b,ang,resolution=40.0): import math e1=[] e2=[] ang=ang-math.radians(90) for i in range(0,int(resolution)+1): x=(-1*a+2*a*float(i)/resolution) y=1-(x/a)**2 if y < 1E-6: y=1E-6 ...
Plot ellipse at x,y with size a,b and orientation ang
20,838
def decryptWithSessionRecord(self, sessionRecord, cipherText): previousStates = sessionRecord.getPreviousSessionStates() exceptions = [] try: sessionState = SessionState(sessionRecord.getSessionState()) plaintext = self.decryptWithSessionState(sessionState, ciph...
:type sessionRecord: SessionRecord :type cipherText: WhisperMessage
20,839
def deploy_image(self, image_name, oc_new_app_args=None, project=None, name=None): self.project = project or self.get_current_project() name = name or .format(random_string=random_str(5)) oc_new_app_args = oc_new_app_args or [] new_image = self.import_image(image_nam...
Deploy image in OpenShift cluster using 'oc new-app' :param image_name: image name with tag :param oc_new_app_args: additional parameters for the `oc new-app`, env variables etc. :param project: project where app should be created, default: current project :param name:str, name of applic...
20,840
def create_or_bind_with_claims(self, source_identity): content = self._serialize.body(source_identity, ) response = self._send(http_method=, location_id=, version=, content=content) return self._de...
CreateOrBindWithClaims. [Preview API] :param :class:`<Identity> <azure.devops.v5_0.identity.models.Identity>` source_identity: :rtype: :class:`<Identity> <azure.devops.v5_0.identity.models.Identity>`
20,841
def CheckForIncludeWhatYouUse(filename, clean_lines, include_state, error, io=codecs): required = {} for linenum in xrange(clean_lines.NumLines()): line = clean_lines.elided[linenum] if not line or line[0] == : continue matched = _RE_PATT...
Reports for missing stl includes. This function will output warnings to make sure you are including the headers necessary for the stl containers and functions that you use. We only give one reason to include a header. For example, if you use both equal_to<> and less<> in a .h file, only one (the latter in the ...
20,842
def fit(self, x, y, **kwargs): self.mean = numpy.mean(y) return {}
Fit a naive model :param x: Predictors to use for fitting the data (this will not be used in naive models) :param y: Outcome
20,843
def _validate(self, inst: "InstanceNode", scope: ValidationScope, ctype: ContentType) -> None: if (scope.value & ValidationScope.syntax.value and inst.value not in self.type): raise YangTypeError(inst.json_pointer(), self.type.error_tag, ...
Extend the superclass method.
20,844
def setup_driver(scenario): if not hasattr(world, ): world.config_files = ConfigFiles() if not world.config_files.config_directory: world.config_files.set_config_directory(DriverWrappersPool.get_default_config_directory()) world.global_status = {: True} bdd_common_before_scen...
Scenario initialization :param scenario: running scenario
20,845
def PCA(x, n=False): if not n: n = x.shape[1] - 1 try: x = np.array(x) except: raise ValueError() assert type(n) == int, "Provided n is not an integer." assert x.shape[1] > n, "The requested n is bigger than \ number of features in x." e...
Principal component analysis function. **Args:** * `x` : input matrix (2d array), every row represents new sample **Kwargs:** * `n` : number of features returned (integer) - how many columns should the output keep **Returns:** * `new_x` : matrix with reduced size (lower number o...
20,846
def get_filestats(cluster, environ, topology, container, path, role=None): params = dict( cluster=cluster, environ=environ, topology=topology, container=container, path=path) if role is not None: params[] = role request_url = tornado.httputil.url_concat(create_url(FILESTATS_...
:param cluster: :param environ: :param topology: :param container: :param path: :param role: :return:
20,847
def _set_traffic_class_mutation(self, v, load=False): if hasattr(v, "_utype"): v = v._utype(v) try: t = YANGDynClass(v,base=YANGListType("name",traffic_class_mutation.traffic_class_mutation, yang_name="traffic-class-mutation", rest_name="traffic-class-mutation", parent=self, is_container=, user...
Setter method for traffic_class_mutation, mapped from YANG variable /qos/map/traffic_class_mutation (list) If this variable is read-only (config: false) in the source YANG file, then _set_traffic_class_mutation is considered as a private method. Backends looking to populate this variable should do so vi...
20,848
def create_credentials(self, environment_id, source_type=None, credential_details=None, **kwargs): if environment_id is None: raise ValueError() if credential_details is not ...
Create credentials. Creates a set of credentials to connect to a remote source. Created credentials are used in a configuration to associate a collection with the remote source. **Note:** All credentials are sent over an encrypted connection and encrypted at rest. :param str en...
20,849
def update_status(self, card_id, code, reimburse_status): return self._post( , data={ : card_id, : code, : reimburse_status, }, )
更新发票卡券的状态 详情请参考 https://mp.weixin.qq.com/wiki?id=mp1497082828_r1cI2 :param card_id: 发票卡券模板的编号 :param code: 发票卡券的编号 :param reimburse_status: 发票报销状态
20,850
def _sorted_keys(self): try: keys = self._cache[] except KeyError: keys = self._cache[] = sorted(self.keys(), key=parse_version) return keys
Return list of keys sorted by version Sorting is done based on :py:func:`pkg_resources.parse_version`
20,851
def update_entity(self, entity, if_match=): request = _update_entity(entity, if_match, self._require_encryption, self._key_encryption_key, self._encryption_resolver) self._add_to_batch(entity[], entity[], request)
Adds an update entity operation to the batch. See :func:`~azure.storage.table.tableservice.TableService.update_entity` for more information on updates. The operation will not be executed until the batch is committed. :param entity: The entity to update. Could be a...
20,852
def uninstalled(name): ret = {: name, : {}, : None, : } old = __salt__[](name) if not old: ret[] = .format(name) ret[] = True return ret else: if __opts__[]: ret[] = .format(name) ret[][] = old[0][] ...
Ensure that the named package is not installed. Args: name (str): The flatpak package. Returns: dict: The ``result`` and ``output``. Example: .. code-block:: yaml uninstall_package: flatpack.uninstalled: - name: gimp
20,853
def typed_node_from_id(id: str) -> TypedNode: filter_out_types = [ , , , , , ] node = next(get_scigraph_nodes([id])) if in node: label = node[] else: label = None types = [typ.lower() for typ in node[][] if t...
Get typed node from id :param id: id as curie :return: TypedNode object
20,854
def clear(self): self._cx, self._cy = (0, 0) self._canvas.rectangle(self._device.bounding_box, fill=self.default_bgcolor) self.flush()
Clears the display and resets the cursor position to ``(0, 0)``.
20,855
def set_attrs(self, **attrs): self.attrs.update(attrs) self._backend.set_attrs(**attrs)
Set model attributes, e.g. input resistance of a cell.
20,856
def dre_dc(self, pars): r self._set_parameters(pars) num1a = np.log(self.w * self.tau) * self.otc * np.sin(self.ang) num1b = self.otc * np.cos(self.ang) * np.pi / 2.0 term1 = (num1a + num1b) / self.denom num2 = self.otc * np.sin(self.c / np.pi) * 2 ...
r""" :math:Add formula
20,857
def _capitalize_word(text, pos): while pos < len(text) and not text[pos].isalnum(): pos += 1 if pos < len(text): text = text[:pos] + text[pos].upper() + text[pos + 1:] while pos < len(text) and text[pos].isalnum(): pos += 1 return text, pos
Capitalize the current (or following) word.
20,858
def get_class_from_settings(settings_key): cls_path = getattr(settings, settings_key, None) if not cls_path: raise NotImplementedError() try: return get_model_from_settings(settings_key=settings_key) except: try: return get_class_from_setti...
Gets a class from a setting key. This will first check loaded models, then look in installed apps, then fallback to import from lib. :param settings_key: the key defined in settings to the value for
20,859
def generate_wildcard_pem_bytes(): key = generate_private_key(u) name = x509.Name([x509.NameAttribute(NameOID.COMMON_NAME, u)]) cert = ( x509.CertificateBuilder() .issuer_name(name) .subject_name(name) .not_valid_before(datetime.today() - timedelta(days=1)) .not_...
Generate a wildcard (subject name '*') self-signed certificate valid for 10 years. https://cryptography.io/en/latest/x509/tutorial/#creating-a-self-signed-certificate :return: Bytes representation of the PEM certificate data
20,860
def validate(self, schema): try: validate(instance=self.to_dict(), schema=schema, cls=Draft4Validator) except ValidationError as e: raise ValidationError(_validate_err_template.format(VDOM_SCHEMA, e))
Validate VDOM against given JSON Schema Raises ValidationError if schema does not match
20,861
def namespace_map(self, target): self._check_target(target) return target.namespace_map or self._default_namespace_map
Returns the namespace_map used for Thrift generation. :param target: The target to extract the namespace_map from. :type target: :class:`pants.backend.codegen.targets.java_thrift_library.JavaThriftLibrary` :returns: The namespaces to remap (old to new). :rtype: dictionary
20,862
def set_format(self, column_or_columns, formatter): if inspect.isclass(formatter): formatter = formatter() if callable(formatter) and not hasattr(formatter, ): formatter = _formats.FunctionFormatter(formatter) if not hasattr(formatter, ): raise Except...
Set the format of a column.
20,863
def get_category_or_404(path): path_bits = [p for p in path.split() if p] return get_object_or_404(Category, slug=path_bits[-1])
Retrieve a Category instance by a path.
20,864
def build_application(conf): if isinstance(conf.adapter_options, list): conf[] = {key: val for _dict in conf.adapter_options for key, val in _dict.items()} elif conf.adapter_options is None: conf[] = {} else: conf[] = copy.copy(conf.adapter_opt...
Do some setup and return the wsgi app.
20,865
def var(self, ddof=0): N = len(self) if N: v = self.values() mu = sum(v) return (sum(v*v) - mu*mu/N)/(N-ddof) else: return None
Calculate variance of timeseries. Return a vector containing the variances of each series in the timeseries. :parameter ddof: delta degree of freedom, the divisor used in the calculation is given by ``N - ddof`` where ``N`` represents the length of timeseries. Default ``0``. ....
20,866
def show_in_view(self, sourceview, matches, targetname=None): append = self.options.append_view or self.options.alter_view == remove = self.options.alter_view == action_name = if append else if remove else targetname = config.engine.show(matches, targetname or s...
Show search result in ncurses view.
20,867
def set_provider_links(self, resource_ids=None): if resource_ids is None: raise NullArgument() metadata = Metadata(**settings.METADATA[]) if metadata.is_read_only(): raise NoAccess() if self._is_valid_input(resource_ids, metadata, array=True): ...
Sets a provider chain in order from the most recent source to the originating source. :param resource_ids: the new source :type resource_ids: ``osid.id.Id[]`` :raise: ``InvalidArgument`` -- ``resource_ids`` is invalid :raise: ``NoAccess`` -- ``Metadata.isReadOnly()`` is ``true``...
20,868
def process_file(self, filename): if self.config.dry_run: if not self.config.internal: self.logger.info("Dry run mode for script %s", filename) with open(filename) as handle: for line in handle: yield line[0:-1] if line[-1] == ...
Processing one file.
20,869
def _on_new_data_received(self, data: bytes): if data == b: self.callback.on_captcha_received(login.CaptchaElement(xml_element))
Gets called whenever we get a whole new XML element from kik's servers. :param data: The data received (bytes)
20,870
def expl_var(self, greenacre=True, N=None): if greenacre: greenacre_inertia = (self.K / (self.K - 1.) * (sum(self.s**4) - (self.J - self.K) / self.K**2.)) return (self._benzecri() / greenacre_inertia)[:N] else: E = self._benzecri() if self.cor else self.s**2 return (E / sum(E))[:N]
Return proportion of explained inertia (variance) for each factor. :param greenacre: Perform Greenacre correction (default: True)
20,871
def get(**kwargs): sensor = None tick = 0 driver = DHTReader(**kwargs) while not sensor and tick < TIME_LIMIT: try: sensor = driver.receive_data() except DHTException: tick += 1 return sensor
Safe sensor wrapper
20,872
def register_plugin(manager): manager.register_blueprint(player) manager.register_mimetype_function(detect_playable_mimetype) manager.register_widget( place=, type=, endpoint=, filename= ) manager.register_widget( place=, type=, ...
Register blueprints and actions using given plugin manager. :param manager: plugin manager :type manager: browsepy.manager.PluginManager
20,873
def link_contentkey_authorization_policy(access_token, ckap_id, options_id, \ ams_redirected_rest_endpoint): path = full_path = .join([path, "()", "/$links/Options"]) full_path_encoded = urllib.parse.quote(full_path, safe=) endpoint = .join([ams_rest_endpoint, full_path_encoded]) uri = .join([...
Link Media Service Content Key Authorization Policy. Args: access_token (str): A valid Azure authentication token. ckap_id (str): A Media Service Asset Content Key Authorization Policy ID. options_id (str): A Media Service Content Key Authorization Policy Options . ams_redirected_re...
20,874
def chop_into_sequences(episode_ids, unroll_ids, agent_indices, feature_columns, state_columns, max_seq_len, dynamic_max=True, _extra_padding=0): ...
Truncate and pad experiences into fixed-length sequences. Arguments: episode_ids (list): List of episode ids for each step. unroll_ids (list): List of identifiers for the sample batch. This is used to make sure sequences are cut between sample batches. agent_indices (list): List...
20,875
def LookupNamespace(self, prefix): ret = libxml2mod.xmlTextReaderLookupNamespace(self._o, prefix) return ret
Resolves a namespace prefix in the scope of the current element.
20,876
def build_data_availability(datasets_json): data_availability = None if in datasets_json and datasets_json.get(): data_availability = datasets_json.get()[0].get() return data_availability
Given datasets in JSON format, get the data availability from it if present
20,877
def param_sweep(model, sequences, param_grid, n_jobs=1, verbose=0): if isinstance(param_grid, dict): param_grid = ParameterGrid(param_grid) elif not isinstance(param_grid, ParameterGrid): raise ValueError("param_grid must be a dict or ParamaterGrid instance") iter_args = ((clone(...
Fit a series of models over a range of parameters. Parameters ---------- model : msmbuilder.BaseEstimator An *instance* of an estimator to be used to fit data. sequences : list of array-like List of sequences, or a single sequence. Each sequence should be a 1D iterable o...
20,878
def get_conn(self): if not self._conn: self._conn = storage.Client(credentials=self._get_credentials()) return self._conn
Returns a Google Cloud Storage service object.
20,879
def _data_from_dotnotation(self, key, default=None): if key is None: raise KeyError() doc = self._collection.find_one({"_id": ObjectId(self._workflow_id)}) if doc is None: return default for k in key.split(): doc = doc[k] return doc
Returns the MongoDB data from a key using dot notation. Args: key (str): The key to the field in the workflow document. Supports MongoDB's dot notation for embedded fields. default (object): The default value that is returned if the key does not exist. ...
20,880
def snapshot(self, channel=0, path_file=None, timeout=None): ret = self.command( "snapshot.cgi?channel={0}".format(channel), timeout_cmd=timeout ) if path_file: with open(path_file, ) as out_file: shutil.copyfileobj(ret.raw, out_file)...
Args: channel: Values according with Amcrest API: 0 - regular snapshot 1 - motion detection snapshot 2 - alarm snapshot If no channel param is used, default is 0 path_file: If path_file is provided...
20,881
def get_extension_rights(self): response = self._send(http_method=, location_id=, version=) return self._deserialize(, response)
GetExtensionRights. [Preview API] :rtype: :class:`<ExtensionRightsResult> <azure.devops.v5_0.licensing.models.ExtensionRightsResult>`
20,882
def expand(self, vs=None, conj=False): vs = self._expect_vars(vs) if vs: outer, inner = (And, Or) if conj else (Or, And) terms = [inner(self.restrict(p), *boolfunc.point2term(p, conj)) for p in boolfunc.iter_points(vs)] ...
Return the Shannon expansion with respect to a list of variables.
20,883
def _matches(self, url, options, general_re, domain_required_rules, rules_with_options): if general_re and general_re.search(url): return True rules = [] if in options and domain_required_rules: src_domain = options[] for domain in ...
Return if ``url``/``options`` are matched by rules defined by ``general_re``, ``domain_required_rules`` and ``rules_with_options``. ``general_re`` is a compiled regex for rules without options. ``domain_required_rules`` is a {domain: [rules_which_require_it]} mapping. ``rules...
20,884
def _checkDragDropEvent(self, ev): mimedata = ev.mimeData() if mimedata.hasUrls(): urls = [str(url.toLocalFile()) for url in mimedata.urls() if url.toLocalFile()] else: urls = [] if urls: ev.acceptProposedAction() return u...
Checks if event contains a file URL, accepts if it does, ignores if it doesn't
20,885
def container_move(object_id, input_params={}, always_retry=False, **kwargs): return DXHTTPRequest( % object_id, input_params, always_retry=always_retry, **kwargs)
Invokes the /container-xxxx/move API method. For more info, see: https://wiki.dnanexus.com/API-Specification-v1.0.0/Folders-and-Deletion#API-method%3A-%2Fclass-xxxx%2Fmove
20,886
def append(self, item): if self.should_flush(): self.flush() self.items.append(item)
Add new item to the list. If needed, append will first flush existing items and clear existing items. Args: item: an item to add to the list.
20,887
def get_response_example(cls, operation, response): path = " operation.path, operation.method, response.name) kwargs = dict(paths=[path]) if response.type in PRIMITIVE_TYPES: result = cls.get_example_value_for_primitive_type( response.type, respo...
Get example for response object by operation object :param Operation operation: operation object :param Response response: response object
20,888
def _run(self, bundle, container_id=None, empty_process=False, log_path=None, pid_file=None, sync_socket=None, command="run", log_format="kubernetes"): container_id = self.get_container_id(container_id) ...
_run is the base function for run and create, the only difference between the two being that run does not have an option for sync_socket. Equivalent command line example: singularity oci create [create options...] <container_ID> Parameters ========== bundle: th...
20,889
def visitFunctionCall(self, ctx): func_name = ctx.fnname().getText() if ctx.parameters() is not None: parameters = self.visit(ctx.parameters()) else: parameters = [] return self._functions.invoke_function(self._eval_context, func_name, parameters)
expression : fnname LPAREN parameters? RPAREN
20,890
def LazyField(lookup_name, scope): def __init__(self, stream=None): base_cls = self._pfp__scope.get_id(self._pfp__lazy_name) self.__class__.__bases__ = (base_cls,) base_cls.__init__(self, stream) new_class = type(lookup_name + "_lazy", (fields.Field,), { "__init__" ...
Super non-standard stuff here. Dynamically changing the base class using the scope and the lazy name when the class is instantiated. This works as long as the original base class is not directly inheriting from object (which we're not, since our original base class is fields.Field).
20,891
def static_serve(request, path, client): if msettings[]: combo_match = _find_combo_match(path) if combo_match: return combo_serve(request, combo_match, client) except KeyError: pass return resp
Given a request for a media asset, this view does the necessary wrangling to get the correct thing delivered to the user. This can also emulate the combo behavior seen when SERVE_REMOTE == False and EMULATE_COMBO == True.
20,892
def generate_pagerank_graph(num_vertices=250, **kwargs): g = minimal_random_graph(num_vertices, **kwargs) r = np.zeros(num_vertices) for k, pr in nx.pagerank(g).items(): r[k] = pr g = set_types_rank(g, rank=r, **kwargs) return g
Creates a random graph where the vertex types are selected using their pagerank. Calls :func:`.minimal_random_graph` and then :func:`.set_types_rank` where the ``rank`` keyword argument is given by :func:`networkx.pagerank`. Parameters ---------- num_vertices : int (optional, the default i...
20,893
def write(self, process_tile, data): data = self._prepare_array(data) if data.mask.all(): logger.debug("data empty, nothing to write") else: bucket_resource = get_boto3_bucket(self._bucket) if self._bucket else None for til...
Write data from process tiles into PNG file(s). Parameters ---------- process_tile : ``BufferedTile`` must be member of process ``TilePyramid``
20,894
def readWiggleLine(self, line): if(line.isspace() or line.startswith(" or line.startswith("browser") or line.startswith("track")): return elif line.startswith("variableStep"): self._mode = self._VARIABLE_STEP self.parseStep(line) r...
Read a wiggle line. If it is a data line, add values to the protocol object.
20,895
def field_xpath(field, attribute): if field in [, ]: xpath = elif field == : if attribute == : xpath = else: xpath = elif field == : field = if attribute == : xpath = else: xpath = elif field ==...
Field helper functions to locate select, textarea, and the other types of input fields (text, checkbox, radio) :param field: One of the values 'select', 'textarea', 'option', or 'button-element' to match a corresponding HTML element (and to match a <button> in the case of 'button-element'). Otherwise a...
20,896
def list_mapping(html_cleaned): unit_raw = html_cleaned.split() for i in unit_raw: c = CDM(i) if c.PTN is not 0: fake_title = i break init_list = [] init_dict = {} for i in unit_raw: init_list.append(len(i)) for i in range(0, len(init_list)):...
将预处理后的网页文档映射成列表和字典,并提取虚假标题 Keyword arguments: html_cleaned -- 预处理后的网页源代码,字符串类型 Return: unit_raw -- 网页文本行 init_dict -- 字典的key是索引,value是网页文本行,并按照网页文本行长度降序排序 fake_title -- 虚假标题,即网页源代码<title>中的文本行
20,897
def unmake(self): if lib.EnvUnmakeInstance(self._env, self._ist) != 1: raise CLIPSError(self._env)
This method is equivalent to delete except that it uses message-passing instead of directly deleting the instance.
20,898
def destroy(name): s running and] raises ContainerNotExists exception if the specified name is not created lxc-destroy-f-n', name] subprocess.check_call(cmd)
removes a container [stops a container if it's running and] raises ContainerNotExists exception if the specified name is not created
20,899
def conditional_distribution(self, values, inplace=True): JPD = self if inplace else self.copy() JPD.reduce(values) JPD.normalize() if not inplace: return JPD
Returns Conditional Probability Distribution after setting values to 1. Parameters ---------- values: list or array_like A list of tuples of the form (variable_name, variable_state). The values on which to condition the Joint Probability Distribution. inplace: Bo...