_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3
values | text stringlengths 75 19.8k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q22600 | Transit.generate_random_bytes | train | def generate_random_bytes(self, n_bytes=32, output_format="base64", mount_point=DEFAULT_MOUNT_POINT):
"""Return high-quality random bytes of the specified length.
Supported methods:
POST: /{mount_point}/random(/{bytes}). Produces: 200 application/json
:param n_bytes: Specifies the ... | python | {
"resource": ""
} |
q22601 | Transit.hash_data | train | def hash_data(self, hash_input, algorithm="sha2-256", output_format="hex", mount_point=DEFAULT_MOUNT_POINT):
"""Return the cryptographic hash of given data using the specified algorithm.
Supported methods:
POST: /{mount_point}/hash(/{algorithm}). Produces: 200 application/json
:par... | python | {
"resource": ""
} |
q22602 | Transit.generate_hmac | train | def generate_hmac(self, name, hash_input, key_version=None, algorithm="sha2-256", mount_point=DEFAULT_MOUNT_POINT):
"""Return the digest of given data using the specified hash algorithm and the named key.
The key can be of any type supported by transit; the raw key will be marshaled into bytes to be us... | python | {
"resource": ""
} |
q22603 | Transit.sign_data | train | def sign_data(self, name, hash_input, key_version=None, hash_algorithm="sha2-256", context="", prehashed=False,
signature_algorithm="pss", mount_point=DEFAULT_MOUNT_POINT):
"""Return the cryptographic signature of the given data using the named key and the specified hash algorithm.
Th... | python | {
"resource": ""
} |
q22604 | Transit.backup_key | train | def backup_key(self, name, mount_point=DEFAULT_MOUNT_POINT):
"""Return a plaintext backup of a named key.
The backup contains all the configuration data and keys of all the versions along with the HMAC key. The
response from this endpoint can be used with the /restore endpoint to restore the ke... | python | {
"resource": ""
} |
q22605 | Transit.restore_key | train | def restore_key(self, backup, name=None, force=False, mount_point=DEFAULT_MOUNT_POINT):
"""Restore the backup as a named key.
This will restore the key configurations and all the versions of the named key along with HMAC keys. The input
to this endpoint should be the output of /backup endpoint.... | python | {
"resource": ""
} |
q22606 | Transit.trim_key | train | def trim_key(self, name, min_version, mount_point=DEFAULT_MOUNT_POINT):
"""Trims older key versions setting a minimum version for the keyring.
Once trimmed, previous versions of the key cannot be recovered.
Supported methods:
POST: /{mount_point}/keys/{name}/trim. Produces: 200 app... | python | {
"resource": ""
} |
q22607 | raise_for_error | train | def raise_for_error(status_code, message=None, errors=None):
"""Helper method to raise exceptions based on the status code of a response received back from Vault.
:param status_code: Status code received in a response from Vault.
:type status_code: int
:param message: Optional message to include in a r... | python | {
"resource": ""
} |
q22608 | generate_method_deprecation_message | train | def generate_method_deprecation_message(to_be_removed_in_version, old_method_name, method_name=None, module_name=None):
"""Generate a message to be used when warning about the use of deprecated methods.
:param to_be_removed_in_version: Version of this module the deprecated method will be removed in.
:type ... | python | {
"resource": ""
} |
q22609 | generate_property_deprecation_message | train | def generate_property_deprecation_message(to_be_removed_in_version, old_name, new_name, new_attribute,
module_name='Client'):
"""Generate a message to be used when warning about the use of deprecated properties.
:param to_be_removed_in_version: Version of this module t... | python | {
"resource": ""
} |
q22610 | getattr_with_deprecated_properties | train | def getattr_with_deprecated_properties(obj, item, deprecated_properties):
"""Helper method to use in the getattr method of a class with deprecated properties.
:param obj: Instance of the Class containing the deprecated properties in question.
:type obj: object
:param item: Name of the attribute being r... | python | {
"resource": ""
} |
q22611 | validate_list_of_strings_param | train | def validate_list_of_strings_param(param_name, param_argument):
"""Validate that an argument is a list of strings.
:param param_name: The name of the parameter being validated. Used in any resulting exception messages.
:type param_name: str | unicode
:param param_argument: The argument to validate.
... | python | {
"resource": ""
} |
q22612 | validate_pem_format | train | def validate_pem_format(param_name, param_argument):
"""Validate that an argument is a PEM-formatted public key or certificate
:param param_name: The name of the parameter being validate. Used in any resulting exception messages.
:type param_name: str | unicode
:param param_argument: The argument to va... | python | {
"resource": ""
} |
q22613 | Auth.list_auth_methods | train | def list_auth_methods(self):
"""List all enabled auth methods.
Supported methods:
GET: /sys/auth. Produces: 200 application/json
:return: The JSON response of the request.
:rtype: dict
"""
api_path = '/v1/sys/auth'
response = self._adapter.get(
... | python | {
"resource": ""
} |
q22614 | Auth.enable_auth_method | train | def enable_auth_method(self, method_type, description=None, config=None, plugin_name=None, local=False, path=None):
"""Enable a new auth method.
After enabling, the auth method can be accessed and configured via the auth path specified as part of the URL.
This auth path will be nested under the... | python | {
"resource": ""
} |
q22615 | Auth.disable_auth_method | train | def disable_auth_method(self, path):
"""Disable the auth method at the given auth path.
Supported methods:
DELETE: /sys/auth/{path}. Produces: 204 (empty body)
:param path: The path the method was mounted on. If not provided, defaults to the value of the "method_type"
a... | python | {
"resource": ""
} |
q22616 | Auth.read_auth_method_tuning | train | def read_auth_method_tuning(self, path):
"""Read the given auth path's configuration.
This endpoint requires sudo capability on the final path, but the same functionality can be achieved without
sudo via sys/mounts/auth/[auth-path]/tune.
Supported methods:
GET: /sys/auth/{p... | python | {
"resource": ""
} |
q22617 | Auth.tune_auth_method | train | def tune_auth_method(self, path, default_lease_ttl=None, max_lease_ttl=None, description=None,
audit_non_hmac_request_keys=None, audit_non_hmac_response_keys=None, listing_visibility='',
passthrough_request_headers=None):
"""Tune configuration parameters for a g... | python | {
"resource": ""
} |
q22618 | Seal.read_seal_status | train | def read_seal_status(self):
"""Read the seal status of the Vault.
This is an unauthenticated endpoint.
Supported methods:
GET: /sys/seal-status. Produces: 200 application/json
:return: The JSON response of the request.
:rtype: dict
"""
api_path = '/... | python | {
"resource": ""
} |
q22619 | Seal.submit_unseal_key | train | def submit_unseal_key(self, key=None, reset=False, migrate=False):
"""Enter a single master key share to progress the unsealing of the Vault.
If the threshold number of master key shares is reached, Vault will attempt to unseal the Vault. Otherwise, this
API must be called multiple times until ... | python | {
"resource": ""
} |
q22620 | Seal.submit_unseal_keys | train | def submit_unseal_keys(self, keys, migrate=False):
"""Enter multiple master key share to progress the unsealing of the Vault.
:param keys: List of master key shares.
:type keys: List[str]
:param migrate: Available in 1.0 Beta - Used to migrate the seal from shamir to autoseal or autosea... | python | {
"resource": ""
} |
q22621 | Request.request | train | def request(self, method, url, headers=None, raise_exception=True, **kwargs):
"""Main method for routing HTTP requests to the configured Vault base_uri.
:param method: HTTP method to use with the request. E.g., GET, POST, etc.
:type method: str
:param url: Partial URL path to send the r... | python | {
"resource": ""
} |
q22622 | Key.read_root_generation_progress | train | def read_root_generation_progress(self):
"""Read the configuration and process of the current root generation attempt.
Supported methods:
GET: /sys/generate-root/attempt. Produces: 200 application/json
:return: The JSON response of the request.
:rtype: dict
"""
... | python | {
"resource": ""
} |
q22623 | Key.start_root_token_generation | train | def start_root_token_generation(self, otp=None, pgp_key=None):
"""Initialize a new root generation attempt.
Only a single root generation attempt can take place at a time. One (and only one) of otp or pgp_key are
required.
Supported methods:
PUT: /sys/generate-root/attempt.... | python | {
"resource": ""
} |
q22624 | Key.generate_root | train | def generate_root(self, key, nonce):
"""Enter a single master key share to progress the root generation attempt.
If the threshold number of master key shares is reached, Vault will complete the root generation and issue the
new token. Otherwise, this API must be called multiple times until that... | python | {
"resource": ""
} |
q22625 | Key.cancel_root_generation | train | def cancel_root_generation(self):
"""Cancel any in-progress root generation attempt.
This clears any progress made. This must be called to change the OTP or PGP key being used.
Supported methods:
DELETE: /sys/generate-root/attempt. Produces: 204 (empty body)
:return: The r... | python | {
"resource": ""
} |
q22626 | Key.get_encryption_key_status | train | def get_encryption_key_status(self):
"""Read information about the current encryption key used by Vault.
Supported methods:
GET: /sys/key-status. Produces: 200 application/json
:return: JSON response with information regarding the current encryption key used by Vault.
:rtyp... | python | {
"resource": ""
} |
q22627 | Key.rotate_encryption_key | train | def rotate_encryption_key(self):
"""Trigger a rotation of the backend encryption key.
This is the key that is used to encrypt data written to the storage backend, and is not provided to operators.
This operation is done online. Future values are encrypted with the new key, while old values are ... | python | {
"resource": ""
} |
q22628 | Key.start_rekey | train | def start_rekey(self, secret_shares=5, secret_threshold=3, pgp_keys=None, backup=False, require_verification=False, recovery_key=False):
"""Initializes a new rekey attempt.
Only a single recovery key rekeyattempt can take place at a time, and changing the parameters of a rekey
requires cancelin... | python | {
"resource": ""
} |
q22629 | Key.cancel_rekey | train | def cancel_rekey(self, recovery_key=False):
"""Cancel any in-progress rekey.
This clears the rekey settings as well as any progress made. This must be called to change the parameters of the
rekey.
Note: Verification is still a part of a rekey. If rekeying is canceled during the verific... | python | {
"resource": ""
} |
q22630 | Key.rekey | train | def rekey(self, key, nonce=None, recovery_key=False):
"""Enter a single recovery key share to progress the rekey of the Vault.
If the threshold number of recovery key shares is reached, Vault will complete the rekey. Otherwise, this API
must be called multiple times until that threshold is met.... | python | {
"resource": ""
} |
q22631 | Key.rekey_multi | train | def rekey_multi(self, keys, nonce=None, recovery_key=False):
"""Enter multiple recovery key shares to progress the rekey of the Vault.
If the threshold number of recovery key shares is reached, Vault will complete the rekey.
:param keys: Specifies multiple recovery share keys.
:type ke... | python | {
"resource": ""
} |
q22632 | Key.read_backup_keys | train | def read_backup_keys(self, recovery_key=False):
"""Retrieve the backup copy of PGP-encrypted unseal keys.
The returned value is the nonce of the rekey operation and a map of PGP key fingerprint to hex-encoded
PGP-encrypted key.
Supported methods:
PUT: /sys/rekey/backup. Pro... | python | {
"resource": ""
} |
q22633 | Mount.enable_secrets_engine | train | def enable_secrets_engine(self, backend_type, path=None, description=None, config=None, plugin_name=None,
options=None, local=False, seal_wrap=False):
"""Enable a new secrets engine at the given path.
Supported methods:
POST: /sys/mounts/{path}. Produces: 204 (... | python | {
"resource": ""
} |
q22634 | Mount.disable_secrets_engine | train | def disable_secrets_engine(self, path):
"""Disable the mount point specified by the provided path.
Supported methods:
DELETE: /sys/mounts/{path}. Produces: 204 (empty body)
:param path: Specifies the path where the secrets engine will be mounted. This is specified as part of the UR... | python | {
"resource": ""
} |
q22635 | Mount.tune_mount_configuration | train | def tune_mount_configuration(self, path, default_lease_ttl=None, max_lease_ttl=None, description=None,
audit_non_hmac_request_keys=None, audit_non_hmac_response_keys=None,
listing_visibility=None, passthrough_request_headers=None, options=None):
... | python | {
"resource": ""
} |
q22636 | Mount.move_backend | train | def move_backend(self, from_path, to_path):
"""Move an already-mounted backend to a new mount point.
Supported methods:
POST: /sys/remount. Produces: 204 (empty body)
:param from_path: Specifies the previous mount point.
:type from_path: str | unicode
:param to_path... | python | {
"resource": ""
} |
q22637 | Kubernetes.configure | train | def configure(self, kubernetes_host, kubernetes_ca_cert='', token_reviewer_jwt='', pem_keys=None,
mount_point=DEFAULT_MOUNT_POINT):
"""Configure the connection parameters for Kubernetes.
This path honors the distinction between the create and update capabilities inside ACL policies.
... | python | {
"resource": ""
} |
q22638 | Azure.list_roles | train | def list_roles(self, mount_point=DEFAULT_MOUNT_POINT):
"""List all the roles that are registered with the plugin.
Supported methods:
LIST: /auth/{mount_point}/roles. Produces: 200 application/json
:param mount_point: The "path" the azure auth method was mounted on.
:type m... | python | {
"resource": ""
} |
q22639 | Azure.login | train | def login(self, role, jwt, subscription_id=None, resource_group_name=None, vm_name=None, vmss_name=None, use_token=True,
mount_point=DEFAULT_MOUNT_POINT):
"""Fetch a token.
This endpoint takes a signed JSON Web Token (JWT) and a role name for some entity. It verifies the JWT signature
... | python | {
"resource": ""
} |
q22640 | Audit.enable_audit_device | train | def enable_audit_device(self, device_type, description=None, options=None, path=None):
"""Enable a new audit device at the supplied path.
The path can be a single word name or a more complex, nested path.
Supported methods:
PUT: /sys/audit/{path}. Produces: 204 (empty body)
... | python | {
"resource": ""
} |
q22641 | Audit.disable_audit_device | train | def disable_audit_device(self, path):
"""Disable the audit device at the given path.
Supported methods:
DELETE: /sys/audit/{path}. Produces: 204 (empty body)
:param path: The path of the audit device to delete. This is part of the request URL.
:type path: str | unicode
... | python | {
"resource": ""
} |
q22642 | Audit.calculate_hash | train | def calculate_hash(self, path, input_to_hash):
"""Hash the given input data with the specified audit device's hash function and salt.
This endpoint can be used to discover whether a given plaintext string (the input parameter) appears in the
audit log in obfuscated form.
Supported meth... | python | {
"resource": ""
} |
q22643 | Policy.list_policies | train | def list_policies(self):
"""List all configured policies.
Supported methods:
GET: /sys/policy. Produces: 200 application/json
:return: The JSON response of the request.
:rtype: dict
"""
api_path = '/v1/sys/policy'
response = self._adapter.get(
... | python | {
"resource": ""
} |
q22644 | Policy.delete_policy | train | def delete_policy(self, name):
"""Delete the policy with the given name.
This will immediately affect all users associated with this policy.
Supported methods:
DELETE: /sys/policy/{name}. Produces: 204 (empty body)
:param name: Specifies the name of the policy to delete.
... | python | {
"resource": ""
} |
q22645 | Client.is_authenticated | train | def is_authenticated(self):
"""Helper method which returns the authentication status of the client
:return:
:rtype:
"""
if not self.token:
return False
try:
self.lookup_token()
return True
except exceptions.Forbidden:
... | python | {
"resource": ""
} |
q22646 | Health.read_health_status | train | def read_health_status(self, standby_ok=False, active_code=200, standby_code=429, dr_secondary_code=472,
performance_standby_code=473, sealed_code=503, uninit_code=501, method='HEAD'):
"""Read the health status of Vault.
This matches the semantics of a Consul HTTP health chec... | python | {
"resource": ""
} |
q22647 | Leader.read_leader_status | train | def read_leader_status(self):
"""Read the high availability status and current leader instance of Vault.
Supported methods:
GET: /sys/leader. Produces: 200 application/json
:return: The JSON response of the request.
:rtype: dict
"""
api_path = '/v1/sys/leade... | python | {
"resource": ""
} |
q22648 | Mfa.configure | train | def configure(self, mount_point, mfa_type='duo', force=False):
"""Configure MFA for a supported method.
This endpoint allows you to turn on multi-factor authentication with a given backend.
Currently only Duo is supported.
Supported methods:
POST: /auth/{mount_point}/mfa_co... | python | {
"resource": ""
} |
q22649 | Mfa.configure_duo_access | train | def configure_duo_access(self, mount_point, host, integration_key, secret_key):
"""Configure the access keys and host for Duo API connections.
To authenticate users with Duo, the backend needs to know what host to connect to and must authenticate with an
integration key and secret key. This end... | python | {
"resource": ""
} |
q22650 | Mfa.configure_duo_behavior | train | def configure_duo_behavior(self, mount_point, push_info=None, user_agent=None, username_format='%s'):
"""Configure Duo second factor behavior.
This endpoint allows you to configure how the original auth method username maps to the Duo username by
providing a template format string.
Sup... | python | {
"resource": ""
} |
q22651 | KikClient._on_connection_made | train | def _on_connection_made(self):
"""
Gets called when the TCP connection to kik's servers is done and we are connected.
Now we might initiate a login request or an auth request.
"""
if self.username is not None and self.password is not None and self.kik_node is not None:
... | python | {
"resource": ""
} |
q22652 | KikClient._establish_authenticated_session | train | def _establish_authenticated_session(self, kik_node):
"""
Updates the kik node and creates a new connection to kik servers.
This new connection will be initiated with another payload which proves
we have the credentials for a specific user. This is how authentication is done.
:p... | python | {
"resource": ""
} |
q22653 | KikClient.login | train | def login(self, username, password, captcha_result=None):
"""
Sends a login request with the given kik username and password
:param username: Your kik username
:param password: Your kik password
:param captcha_result: If this parameter is provided, it is the answer to the captch... | python | {
"resource": ""
} |
q22654 | KikClient.register | train | def register(self, email, username, password, first_name, last_name, birthday="1974-11-20", captcha_result=None):
"""
Sends a register request to sign up a new user to kik with the given details.
"""
self.username = username
self.password = password
register_message = sig... | python | {
"resource": ""
} |
q22655 | KikClient.send_read_receipt | train | def send_read_receipt(self, peer_jid: str, receipt_message_id: str, group_jid=None):
"""
Sends a read receipt for a previously sent message, to a specific user or group.
:param peer_jid: The JID of the user to which to send the receipt.
:param receipt_message_id: The message ID that the... | python | {
"resource": ""
} |
q22656 | KikClient.send_delivered_receipt | train | def send_delivered_receipt(self, peer_jid: str, receipt_message_id: str):
"""
Sends a receipt indicating that a specific message was received, to another person.
:param peer_jid: The other peer's JID to send to receipt to
:param receipt_message_id: The message ID for which to generate t... | python | {
"resource": ""
} |
q22657 | KikClient.send_is_typing | train | def send_is_typing(self, peer_jid: str, is_typing: bool):
"""
Updates the 'is typing' status of the bot during a conversation.
:param peer_jid: The JID that the notification will be sent to
:param is_typing: If true, indicates that we're currently typing, or False otherwise.
"""... | python | {
"resource": ""
} |
q22658 | KikClient.xiphias_get_users | train | def xiphias_get_users(self, peer_jids: Union[str, List[str]]):
"""
Calls the new format xiphias message to request user data such as profile creation date
and background picture URL.
:param peer_jids: one jid, or a list of jids
"""
return self._send_xmpp_element(xiphias.... | python | {
"resource": ""
} |
q22659 | KikClient.xiphias_get_users_by_alias | train | def xiphias_get_users_by_alias(self, alias_jids: Union[str, List[str]]):
"""
Like xiphias_get_users, but for aliases instead of jids.
:param alias_jids: one jid, or a list of jids
"""
return self._send_xmpp_element(xiphias.UsersByAliasRequest(alias_jids)) | python | {
"resource": ""
} |
q22660 | KikClient.change_group_name | train | def change_group_name(self, group_jid: str, new_name: str):
"""
Changes the a group's name to something new
:param group_jid: The JID of the group whose name should be changed
:param new_name: The new name to give to the group
"""
log.info("[+] Requesting a group name ch... | python | {
"resource": ""
} |
q22661 | KikClient.add_peer_to_group | train | def add_peer_to_group(self, group_jid, peer_jid):
"""
Adds someone to a group
:param group_jid: The JID of the group into which to add a user
:param peer_jid: The JID of the user to add
"""
log.info("[+] Requesting to add user {} into the group {}".format(peer_jid, group... | python | {
"resource": ""
} |
q22662 | KikClient.remove_peer_from_group | train | def remove_peer_from_group(self, group_jid, peer_jid):
"""
Kicks someone out of a group
:param group_jid: The group JID from which to remove the user
:param peer_jid: The JID of the user to remove
"""
log.info("[+] Requesting removal of user {} from group {}".format(peer... | python | {
"resource": ""
} |
q22663 | KikClient.ban_member_from_group | train | def ban_member_from_group(self, group_jid, peer_jid):
"""
Bans a member from the group
:param group_jid: The JID of the relevant group
:param peer_jid: The JID of the user to ban
"""
log.info("[+] Requesting ban of user {} from group {}".format(peer_jid, group_jid))
... | python | {
"resource": ""
} |
q22664 | KikClient.unban_member_from_group | train | def unban_member_from_group(self, group_jid, peer_jid):
"""
Undos a ban of someone from a group
:param group_jid: The JID of the relevant group
:param peer_jid: The JID of the user to un-ban from the gorup
"""
log.info("[+] Requesting un-banning of user {} from the group... | python | {
"resource": ""
} |
q22665 | KikClient.join_group_with_token | train | def join_group_with_token(self, group_hashtag, group_jid, join_token):
"""
Tries to join into a specific group, using a cryptographic token that was received earlier from a search
:param group_hashtag: The public hashtag of the group into which to join (like '#Music')
:param group_jid: ... | python | {
"resource": ""
} |
q22666 | KikClient.leave_group | train | def leave_group(self, group_jid):
"""
Leaves a specific group
:param group_jid: The JID of the group to leave
"""
log.info("[+] Leaving group {}".format(group_jid))
return self._send_xmpp_element(group_adminship.LeaveGroupRequest(group_jid)) | python | {
"resource": ""
} |
q22667 | KikClient.promote_to_admin | train | def promote_to_admin(self, group_jid, peer_jid):
"""
Turns some group member into an admin
:param group_jid: The group JID for which the member will become an admin
:param peer_jid: The JID of user to turn into an admin
"""
log.info("[+] Promoting user {} to admin in gro... | python | {
"resource": ""
} |
q22668 | KikClient.demote_admin | train | def demote_admin(self, group_jid, peer_jid):
"""
Turns an admin of a group into a regular user with no amidships capabilities.
:param group_jid: The group JID in which the rights apply
:param peer_jid: The admin user to demote
:return:
"""
log.info("[+] Demoting ... | python | {
"resource": ""
} |
q22669 | KikClient.add_members | train | def add_members(self, group_jid, peer_jids: Union[str, List[str]]):
"""
Adds multiple users to a specific group at once
:param group_jid: The group into which to join the users
:param peer_jids: a list (or a single string) of JIDs to add to the group
"""
log.info("[+] Ad... | python | {
"resource": ""
} |
q22670 | KikClient.set_profile_picture | train | def set_profile_picture(self, filename):
"""
Sets the profile picture
:param filename: The filename on disk of the image to set
"""
log.info("[+] Setting the profile picture to file '{}'".format(filename))
profile_pictures.set_profile_picture(filename, self.kik_node + '@... | python | {
"resource": ""
} |
q22671 | KikClient.change_display_name | train | def change_display_name(self, first_name, last_name):
"""
Changes the display name
:param first_name: The first name
:param last_name: The last name
"""
log.info("[+] Changing the display name to '{} {}'".format(first_name, last_name))
return self._send_xmpp_elem... | python | {
"resource": ""
} |
q22672 | KikClient.change_password | train | def change_password(self, new_password, email):
"""
Changes the login password
:param new_password: The new login password to set for the account
:param email: The current email of the account
"""
log.info("[+] Changing the password of the account")
return self._... | python | {
"resource": ""
} |
q22673 | KikClient.change_email | train | def change_email(self, old_email, new_email):
"""
Changes the email of the current account
:param old_email: The current email
:param new_email: The new email to set
"""
log.info("[+] Changing account email to '{}'".format(new_email))
return self._send_xmpp_eleme... | python | {
"resource": ""
} |
q22674 | KikClient._send_xmpp_element | train | def _send_xmpp_element(self, xmpp_element: XMPPElement):
"""
Serializes and sends the given XMPP element to kik servers
:param xmpp_element: The XMPP element to send
:return: The UUID of the element that was sent
"""
while not self.connected:
log.debug("[!] W... | python | {
"resource": ""
} |
q22675 | KikClient._handle_received_k_element | train | def _handle_received_k_element(self, k_element: BeautifulSoup):
"""
The 'k' element appears to be kik's connection-related stanza.
It lets us know if a connection or a login was successful or not.
:param k_element: The XML element we just received from kik.
"""
if k_elem... | python | {
"resource": ""
} |
q22676 | KikClient._kik_connection_thread_function | train | def _kik_connection_thread_function(self):
"""
The Kik Connection thread main function.
Initiates the asyncio loop and actually connects.
"""
# If there is already a connection going, than wait for it to stop
if self.loop and self.loop.is_running():
self.loop.... | python | {
"resource": ""
} |
q22677 | handle_cancellation | train | def handle_cancellation(session: CommandSession):
"""
If the input is a string of cancellation word, finish the command session.
"""
def control(value):
if _is_cancellation(value) is True:
session.finish(render_expression(
session.bot.config.SESSION_CANCEL_EXPRESSION... | python | {
"resource": ""
} |
q22678 | on_command | train | def on_command(name: Union[str, CommandName_T], *,
aliases: Iterable[str] = (),
permission: int = perm.EVERYBODY,
only_to_me: bool = True,
privileged: bool = False,
shell_like: bool = False) -> Callable:
"""
Decorator to register a funct... | python | {
"resource": ""
} |
q22679 | handle_command | train | async def handle_command(bot: NoneBot, ctx: Context_T) -> bool:
"""
Handle a message as a command.
This function is typically called by "handle_message".
:param bot: NoneBot instance
:param ctx: message context
:return: the message is handled as a command
"""
cmd, current_arg = parse_c... | python | {
"resource": ""
} |
q22680 | call_command | train | async def call_command(bot: NoneBot, ctx: Context_T,
name: Union[str, CommandName_T], *,
current_arg: str = '',
args: Optional[CommandArgs_T] = None,
check_perm: bool = True,
disable_interaction: bool = Fa... | python | {
"resource": ""
} |
q22681 | kill_current_session | train | def kill_current_session(ctx: Context_T) -> None:
"""
Force kill current session of the given context,
despite whether it is running or not.
:param ctx: message context
"""
ctx_id = context_id(ctx)
if ctx_id in _sessions:
del _sessions[ctx_id] | python | {
"resource": ""
} |
q22682 | Command.run | train | async def run(self, session, *,
check_perm: bool = True,
dry: bool = False) -> bool:
"""
Run the command in a given session.
:param session: CommandSession object
:param check_perm: should check permission before running
:param dry: just check... | python | {
"resource": ""
} |
q22683 | Command._check_perm | train | async def _check_perm(self, session) -> bool:
"""
Check if the session has sufficient permission to
call the command.
:param session: CommandSession object
:return: the session has the permission
"""
return await perm.check_permission(session.bot, session.ctx,
... | python | {
"resource": ""
} |
q22684 | CommandFunc.args_parser | train | def args_parser(self, parser_func: CommandHandler_T) -> CommandHandler_T:
"""
Decorator to register a function as the arguments parser of
the corresponding command.
"""
self.cmd.args_parser_func = parser_func
return parser_func | python | {
"resource": ""
} |
q22685 | CommandSession.is_valid | train | def is_valid(self) -> bool:
"""Check if the session is expired or not."""
if self.bot.config.SESSION_EXPIRE_TIMEOUT and \
self._last_interaction and \
datetime.now() - self._last_interaction > \
self.bot.config.SESSION_EXPIRE_TIMEOUT:
return Fa... | python | {
"resource": ""
} |
q22686 | CommandSession.current_arg_text | train | def current_arg_text(self) -> str:
"""
Plain text part in the current argument, without any CQ codes.
"""
if self._current_arg_text is None:
self._current_arg_text = Message(
self.current_arg).extract_plain_text()
return self._current_arg_text | python | {
"resource": ""
} |
q22687 | CommandSession.refresh | train | def refresh(self, ctx: Context_T, *, current_arg: str = '') -> None:
"""
Refill the session with a new message context.
:param ctx: new message context
:param current_arg: new command argument as a string
"""
self.ctx = ctx
self.current_arg = current_arg
... | python | {
"resource": ""
} |
q22688 | CommandSession.get | train | def get(self, key: str, *,
prompt: Optional[Message_T] = None,
arg_filters: Optional[List[Filter_T]] = None,
**kwargs) -> Any:
"""
Get an argument with a given key.
If the argument does not exist in the current session,
a pause exception will be raise... | python | {
"resource": ""
} |
q22689 | CommandSession.get_optional | train | def get_optional(self, key: str,
default: Optional[Any] = None) -> Optional[Any]:
"""
Simply get a argument with given key.
Deprecated. Use `session.state.get()` instead.
"""
return self.state.get(key, default) | python | {
"resource": ""
} |
q22690 | CommandSession.pause | train | def pause(self, message: Optional[Message_T] = None, **kwargs) -> None:
"""Pause the session for further interaction."""
if message:
asyncio.ensure_future(self.send(message, **kwargs))
raise _PauseException | python | {
"resource": ""
} |
q22691 | CommandSession.finish | train | def finish(self, message: Optional[Message_T] = None, **kwargs) -> None:
"""Finish the session."""
if message:
asyncio.ensure_future(self.send(message, **kwargs))
raise _FinishException | python | {
"resource": ""
} |
q22692 | RequestSession.approve | train | async def approve(self, remark: str = '') -> None:
"""
Approve the request.
:param remark: remark of friend (only works in friend request)
"""
try:
await self.bot.call_action(
action='.handle_quick_operation_async',
self_id=self.ctx.ge... | python | {
"resource": ""
} |
q22693 | RequestSession.reject | train | async def reject(self, reason: str = '') -> None:
"""
Reject the request.
:param reason: reason to reject (only works in group request)
"""
try:
await self.bot.call_action(
action='.handle_quick_operation_async',
self_id=self.ctx.get('... | python | {
"resource": ""
} |
q22694 | init | train | def init(config_object: Optional[Any] = None) -> None:
"""
Initialize NoneBot instance.
This function must be called at the very beginning of code,
otherwise the get_bot() function will return None and nothing
is gonna work properly.
:param config_object: configuration object
"""
globa... | python | {
"resource": ""
} |
q22695 | run | train | def run(host: Optional[str] = None, port: Optional[int] = None,
*args, **kwargs) -> None:
"""Run the NoneBot instance."""
get_bot().run(host=host, port=port, *args, **kwargs) | python | {
"resource": ""
} |
q22696 | context_id | train | def context_id(ctx: Context_T, *,
mode: str = 'default', use_hash: bool = False) -> str:
"""
Calculate a unique id representing the current context.
mode:
default: one id for one context
group: one id for one group or discuss
user: one id for one user
:param ctx: the c... | python | {
"resource": ""
} |
q22697 | render_expression | train | def render_expression(expr: Expression_T, *args,
escape_args: bool = True, **kwargs) -> str:
"""
Render an expression to message string.
:param expr: expression to render
:param escape_args: should escape arguments or not
:param args: positional arguments used in str.format()
... | python | {
"resource": ""
} |
q22698 | load_plugin | train | def load_plugin(module_name: str) -> bool:
"""
Load a module as a plugin.
:param module_name: name of module to import
:return: successful or not
"""
try:
module = importlib.import_module(module_name)
name = getattr(module, '__plugin_name__', None)
usage = getattr(module... | python | {
"resource": ""
} |
q22699 | load_plugins | train | def load_plugins(plugin_dir: str, module_prefix: str) -> int:
"""
Find all non-hidden modules or packages in a given directory,
and import them with the given module prefix.
:param plugin_dir: plugin directory to search
:param module_prefix: module prefix used while importing
:return: number of... | python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.