_id
stringlengths 2
7
| title
stringlengths 1
88
| partition
stringclasses 3
values | text
stringlengths 31
13.1k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q800
|
PubSubClient.retract
|
train
|
def retract(self, jid, node, id_, *, notify=False):
"""
Retract a previously published item from a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to send a notify from.
:type node: :class:`str`
:param id_: The ID of the item to retract.
:type id_: :class:`str`
:param notify: Flag indicating whether subscribers shall be notified
about the retraction.
:type notify: :class:`bool`
:raises aioxmpp.errors.XMPPError: as returned by the service
Retract an item previously published to `node` at `jid`. `id_` must be
the ItemID of the item to retract.
If `notify`
|
python
|
{
"resource": ""
}
|
q801
|
PubSubClient.create
|
train
|
def create(self, jid, node=None):
"""
Create a new node at a service.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to create.
:type node: :class:`str` or :data:`None`
:raises aioxmpp.errors.XMPPError: as returned by the service
:return: The name of the created node.
:rtype: :class:`str`
If `node` is :data:`None`, an instant node is created (see :xep:`60`).
The server may not support or allow the creation of instant nodes.
Return the actual `node` identifier.
"""
create
|
python
|
{
"resource": ""
}
|
q802
|
PubSubClient.delete
|
train
|
def delete(self, jid, node, *, redirect_uri=None):
"""
Delete an existing node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to delete.
:type node: :class:`str` or :data:`None`
:param redirect_uri: A URI to send to subscribers to indicate a
replacement for the deleted node.
:type redirect_uri: :class:`str` or :data:`None`
:raises aioxmpp.errors.XMPPError: as returned by the service
Optionally, a `redirect_uri` can be given. The `redirect_uri` will be
sent to subscribers in the message notifying them about the node
deletion.
|
python
|
{
"resource": ""
}
|
q803
|
PubSubClient.get_nodes
|
train
|
def get_nodes(self, jid, node=None):
"""
Request all nodes at a service or collection node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the collection node to query
:type node: :class:`str` or :data:`None`
:raises aioxmpp.errors.XMPPError: as returned by the service
:return: The list of nodes at the service or collection node.
:rtype: :class:`~collections.abc.Sequence` of tuples consisting of the
node name and its description.
Request the nodes available at `jid`. If `node` is not :data:`None`,
the request returns the children of the :xep:`248` collection node
`node`. Make sure to check for the appropriate server feature first.
Return a list of tuples consisting of the node names and their
|
python
|
{
"resource": ""
}
|
q804
|
PubSubClient.get_node_affiliations
|
train
|
def get_node_affiliations(self, jid, node):
"""
Return the affiliations of other jids at a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the node to query
:type node: :class:`str`
:raises aioxmpp.errors.XMPPError: as returned by the service
:return: The response from the service.
:rtype: :class:`.xso.OwnerRequest`
The affiliations are returned as :class:`.xso.OwnerRequest` instance
|
python
|
{
"resource": ""
}
|
q805
|
PubSubClient.change_node_affiliations
|
train
|
def change_node_affiliations(self, jid, node, affiliations_to_set):
"""
Update the affiliations at a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the node to modify
:type node: :class:`str`
:param affiliations_to_set: The affiliations to set at the node.
:type affiliations_to_set: :class:`~collections.abc.Iterable` of tuples
consisting of the JID to affiliate and the affiliation to use.
:raises aioxmpp.errors.XMPPError: as returned by the service
|
python
|
{
"resource": ""
}
|
q806
|
PubSubClient.change_node_subscriptions
|
train
|
def change_node_subscriptions(self, jid, node, subscriptions_to_set):
"""
Update the subscriptions at a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the node to modify
:type node: :class:`str`
:param subscriptions_to_set: The subscriptions to set at the node.
:type subscriptions_to_set: :class:`~collections.abc.Iterable` of
tuples consisting of the JID to (un)subscribe and the subscription
level to use.
:raises aioxmpp.errors.XMPPError: as returned by
|
python
|
{
"resource": ""
}
|
q807
|
PubSubClient.purge
|
train
|
def purge(self, jid, node):
"""
Delete all items from a node.
:param jid: JID of the PubSub service
:param node: Name of the PubSub node
:type node: :class:`str`
Requires :attr:`.xso.Feature.PURGE`.
"""
iq = aioxmpp.stanza.IQ(
type_=aioxmpp.structs.IQType.SET,
|
python
|
{
"resource": ""
}
|
q808
|
Child.from_events
|
train
|
def from_events(self, instance, ev_args, ctx):
"""
Detect the object to instanciate from the arguments `ev_args` of the
``"start"`` event. The new object is
|
python
|
{
"resource": ""
}
|
q809
|
XSOParser.add_class
|
train
|
def add_class(self, cls, callback):
"""
Add a class `cls` for parsing as root level element. When an object of
`cls` type has been completely parsed, `callback` is called with the
object as argument.
"""
if cls.TAG in self._tag_map:
raise
|
python
|
{
"resource": ""
}
|
q810
|
check_bidi
|
train
|
def check_bidi(chars):
"""
Check proper bidirectionality as per stringprep. Operates on a list of
unicode characters provided in `chars`.
"""
# the empty string is valid, as it cannot violate the RandALCat constraints
if not chars:
return
# first_is_RorAL = unicodedata.bidirectional(chars[0]) in {"R", "AL"}
|
python
|
{
"resource": ""
}
|
q811
|
check_prohibited_output
|
train
|
def check_prohibited_output(chars, bad_tables):
"""
Check against prohibited output, by checking whether any of the characters
from `chars` are in any of the `bad_tables`.
|
python
|
{
"resource": ""
}
|
q812
|
check_unassigned
|
train
|
def check_unassigned(chars, bad_tables):
"""
Check that `chars` does not contain any unassigned code points as per
the given list of `bad_tables`.
Operates on a list of unicode code points provided in `chars`.
"""
bad_tables = (
stringprep.in_table_a1,)
violator = check_against_tables(chars, bad_tables)
|
python
|
{
"resource": ""
}
|
q813
|
AvatarSet.add_avatar_image
|
train
|
def add_avatar_image(self, mime_type, *, id_=None,
image_bytes=None, width=None, height=None,
url=None, nbytes=None):
"""
Add a source of the avatar image.
All sources of an avatar image added to an avatar set must be
*the same image*, in different formats and sizes.
:param mime_type: The MIME type of the avatar image.
:param id_: The SHA1 of the image data.
:param nbytes: The size of the image data in bytes.
:param image_bytes: The image data, this must be supplied only
in one call.
:param url: The URL of the avatar image.
:param height: The height of the image in pixels (optional).
:param width: The width of the image in pixels (optional).
`id_` and `nbytes` may be omitted if and only if `image_data`
is given and `mime_type` is ``image/png``. If they are
supplied *and* image data is given, they are checked to match
the image data.
It is the caller's responsibility to assure that the provided
links exist and the files have the correct SHA1 sums.
"""
if mime_type == "image/png":
if image_bytes is not None:
if self._image_bytes is not None:
raise RuntimeError(
"Only one avatar image may be published directly."
|
python
|
{
"resource": ""
}
|
q814
|
AvatarService.get_avatar_metadata
|
train
|
def get_avatar_metadata(self, jid, *, require_fresh=False,
disable_pep=False):
"""
Retrieve a list of avatar descriptors.
:param jid: the JID for which to retrieve the avatar metadata.
:type jid: :class:`aioxmpp.JID`
:param require_fresh: if true, do not return results from the
avatar metadata chache, but retrieve them again from the server.
:type require_fresh: :class:`bool`
:param disable_pep: if true, do not try to retrieve the avatar
via pep, only try the vCard fallback. This usually only
useful when querying avatars via MUC, where the PEP request
would be invalid (since it would be for a full jid).
:type disable_pep: :class:`bool`
:returns: an iterable of avatar descriptors.
:rtype: a :class:`list` of
:class:`~aioxmpp.avatar.service.AbstractAvatarDescriptor`
instances
Returning an empty list means that the avatar not set.
We mask a :class:`XMPPCancelError` in the case that it is
``feature-not-implemented`` or
|
python
|
{
"resource": ""
}
|
q815
|
AvatarService.publish_avatar_set
|
train
|
def publish_avatar_set(self, avatar_set):
"""
Make `avatar_set` the current avatar of the jid associated with this
connection.
If :attr:`synchronize_vcard` is true and PEP is available the
vCard is only synchronized if the PEP update is successful.
This means publishing the ``image/png`` avatar data and the
avatar metadata set in pubsub. The `avatar_set` must be an
instance of :class:`AvatarSet`. If :attr:`synchronize_vcard` is
true the avatar is additionally published in the user vCard.
"""
id_ = avatar_set.png_id
done = False
with (yield from self._publish_lock):
if (yield from self._pep.available()):
yield from self._pep.publish(
namespaces.xep0084_data,
avatar_xso.Data(avatar_set.image_bytes),
id_=id_
)
yield from self._pep.publish(
|
python
|
{
"resource": ""
}
|
q816
|
AvatarService.disable_avatar
|
train
|
def disable_avatar(self):
"""
Temporarily disable the avatar.
If :attr:`synchronize_vcard` is true, the vCard avatar is
disabled (even if disabling the PEP avatar fails).
This is done by setting the avatar metadata node empty and if
:attr:`synchronize_vcard` is true, downloading the vCard,
removing the avatar data and re-uploading the vCard.
This method does not error if neither protocol is active.
:raises aioxmpp.errors.GatherError: if an exception is raised
by the spawned tasks.
"""
with (yield from self._publish_lock):
|
python
|
{
"resource": ""
}
|
q817
|
AvatarService.wipe_avatar
|
train
|
def wipe_avatar(self):
"""
Remove all avatar data stored on the server.
If :attr:`synchronize_vcard` is true, the vCard avatar is
disabled even if disabling the PEP avatar fails.
This is equivalent to :meth:`disable_avatar` for vCard-based
avatars, but will also remove the data PubSub node for
PEP avatars.
This method does not error if neither protocol is active.
:raises aioxmpp.errors.GatherError: if an exception is raised
by the spawned tasks.
"""
@asyncio.coroutine
def _wipe_pep_avatar():
yield from self._pep.publish(
namespaces.xep0084_metadata,
avatar_xso.Metadata()
)
yield from self._pep.publish(
namespaces.xep0084_data,
|
python
|
{
"resource": ""
}
|
q818
|
BlockingClient.block_jids
|
train
|
def block_jids(self, jids_to_block):
"""
Add the JIDs in the sequence `jids_to_block` to the client's
blocklist.
"""
yield from self._check_for_blocking()
if not jids_to_block:
return
cmd =
|
python
|
{
"resource": ""
}
|
q819
|
BlockingClient.unblock_jids
|
train
|
def unblock_jids(self, jids_to_unblock):
"""
Remove the JIDs in the sequence `jids_to_block` from the
client's blocklist.
"""
yield from self._check_for_blocking()
if not jids_to_unblock:
return
cmd =
|
python
|
{
"resource": ""
}
|
q820
|
DescriptorClass._register_descriptor_keys
|
train
|
def _register_descriptor_keys(self, descriptor, keys):
"""
Register the given descriptor keys for the given descriptor at the
class.
:param descriptor: The descriptor for which the `keys` shall be
registered.
:type descriptor: :class:`AbstractDescriptor` instance
:param keys: An iterable of descriptor keys
:raises TypeError: if the specified keys are already handled by a
descriptor.
:raises TypeError: if this class has subclasses or if it is not the
:attr:`~AbstractDescriptor.root_class` of the given
descriptor.
If the method raises, the caller must assume that registration was not
successful.
.. note::
The intended audience for this method are developers of
:class:`AbstractDescriptor` subclasses, which are generally only
expected to live in the :mod:`aioxmpp` package.
Thus, you should not expect this API to be stable. If you have a
use-case for using this function outside of :mod:`aioxmpp`, please
let me know through the usual issue reporting means.
"""
|
python
|
{
"resource": ""
}
|
q821
|
FormClass.from_xso
|
train
|
def from_xso(self, xso):
"""
Construct and return an instance from the given `xso`.
.. note::
This is a static method (classmethod), even though sphinx does not
document it as such.
:param xso: A :xep:`4` data form
:type xso: :class:`~.Data`
:raises ValueError: if the ``FORM_TYPE`` mismatches
:raises ValueError: if field types mismatch
:return: newly created instance of this class
The fields from the given `xso` are matched against the fields on the
form. Any matching field loads its data from the `xso` field. Fields
which occur on the form template but not in the `xso` are skipped.
Fields which occur in the `xso` but not on the form template are also
skipped (but are re-emitted when the form is rendered as reply, see
:meth:`~.Form.render_reply`).
If the form template has a ``FORM_TYPE`` attribute and the incoming
`xso` also has a ``FORM_TYPE`` field, a mismatch between the two values
leads to a :class:`ValueError`.
The field types of matching fields are checked. If the field type on
the incoming XSO may not be upcast to the field type declared on the
form (see :meth:`~.FieldType.allow_upcast`), a :class:`ValueError` is
raised.
If the :attr:`~.Data.type_` does not indicate an actual form (but
rather a cancellation request or tabular result), :class:`ValueError`
is raised.
"""
my_form_type = getattr(self, "FORM_TYPE", None)
f = self()
for field in xso.fields:
if field.var == "FORM_TYPE":
if (my_form_type is not None and
field.type_ == forms_xso.FieldType.HIDDEN and
field.values):
if my_form_type != field.values[0]:
raise ValueError(
|
python
|
{
"resource": ""
}
|
q822
|
PEPClient.claim_pep_node
|
train
|
def claim_pep_node(self, node_namespace, *,
register_feature=True, notify=False):
"""
Claim node `node_namespace`.
:param node_namespace: the pubsub node whose events shall be
handled.
:param register_feature: Whether to publish the `node_namespace`
as feature.
:param notify: Whether to register the ``+notify`` feature to
receive notification without explicit subscription.
:raises RuntimeError: if a handler for `node_namespace` is already
set.
:returns: a :class:`~aioxmpp.pep.service.RegisteredPEPNode` instance
representing the claim.
.. seealso::
:class:`aioxmpp.pep.register_pep_node`
a descriptor which can be used with
:class:`~aioxmpp.service.Service` subclasses to claim a PEP node
automatically.
This registers `node_namespace` as feature for service discovery
unless ``register_feature=False`` is passed.
.. note::
For `notify` to work, it is required that
:class:`aioxmpp.EntityCapsService` is loaded and that presence is
re-sent soon after
:meth:`~aioxmpp.EntityCapsService.on_ver_changed` fires. See the
documentation of
|
python
|
{
"resource": ""
}
|
q823
|
PEPClient.available
|
train
|
def available(self):
"""
Check whether we have a PEP identity associated with our account.
"""
disco_info = yield from self._disco_client.query_info(
|
python
|
{
"resource": ""
}
|
q824
|
PEPClient.publish
|
train
|
def publish(self, node, data, *, id_=None, access_model=None):
"""
Publish an item `data` in the PubSub node `node` on the
PEP service associated with the user's JID.
:param node: The PubSub node to publish to.
:param data: The item to publish.
:type data: An XSO representing the paylaod.
:param id_: The id the published item shall have.
:param access_model: The access model to enforce on the node. Defaults
to not enforcing any access model.
:returns: The PubSub id of the published item or
:data:`None` if it is unknown.
:raises RuntimeError: if PEP is not supported.
:raises RuntimeError: if `access_model` is set and `publish_options` is
not supported by the server
If no `id_` is given it is generated by the server (and may be
returned).
`access_model` defines a pre-condition on the access model used for the
`node`. The valid values
|
python
|
{
"resource": ""
}
|
q825
|
RegisteredPEPNode.close
|
train
|
def close(self):
"""
Unclaim the PEP node and unregister the registered features.
It is not necessary to call close if this claim is managed by
:class:`~aioxmpp.pep.register_pep_node`.
"""
if self._closed:
|
python
|
{
"resource": ""
}
|
q826
|
DjangoNode.full_clean
|
train
|
def full_clean(self, exclude, validate_unique=False):
"""
Validate node, on error raising ValidationErrors which can be handled by django forms
:param exclude:
:param validate_unique: Check if conflicting node exists in the labels
|
python
|
{
"resource": ""
}
|
q827
|
AbstractUser.email_user
|
train
|
def email_user(self, subject, message, from_email=None):
"""
|
python
|
{
"resource": ""
}
|
q828
|
UserAdmin.activate_users
|
train
|
def activate_users(self, request, queryset):
"""
Activates the selected users, if they are not already
activated.
"""
n = 0
for user in queryset:
if not user.is_active:
user.activate()
n += 1
self.message_user(
request,
|
python
|
{
"resource": ""
}
|
q829
|
UserAdmin.send_activation_email
|
train
|
def send_activation_email(self, request, queryset):
"""
Send activation emails for the selected users, if they are not already
activated.
"""
n = 0
for user in queryset:
if not user.is_active and settings.USERS_VERIFY_EMAIL:
send_activation_email(user=user, request=request)
|
python
|
{
"resource": ""
}
|
q830
|
UserManager.get_queryset
|
train
|
def get_queryset(self):
"""
Fixes get_query_set vs get_queryset for Django <1.6
"""
try:
qs = super(UserManager, self).get_queryset()
|
python
|
{
"resource": ""
}
|
q831
|
Poller.is_ready
|
train
|
def is_ready(self):
"""Is Socket Ready.
:rtype: tuple
"""
try:
ready, _, _ = self.select.select([self.fileno], [], [],
|
python
|
{
"resource": ""
}
|
q832
|
IO.close
|
train
|
def close(self):
"""Close Socket.
:return:
"""
self._wr_lock.acquire()
self._rd_lock.acquire()
try:
self._running.clear()
if self.socket:
self._close_socket()
if self._inbound_thread:
|
python
|
{
"resource": ""
}
|
q833
|
IO.open
|
train
|
def open(self):
"""Open Socket and establish a connection.
:raises AMQPConnectionError: Raises if the connection
encountered an error.
:return:
"""
self._wr_lock.acquire()
self._rd_lock.acquire()
try:
self.data_in = EMPTY_BUFFER
self._running.set()
sock_addresses = self._get_socket_addresses()
|
python
|
{
"resource": ""
}
|
q834
|
IO.write_to_socket
|
train
|
def write_to_socket(self, frame_data):
"""Write data to the socket.
:param str frame_data:
:return:
"""
self._wr_lock.acquire()
try:
total_bytes_written = 0
bytes_to_send = len(frame_data)
while total_bytes_written < bytes_to_send:
try:
if not self.socket:
raise socket.error('connection/socket error')
bytes_written = (
self.socket.send(frame_data[total_bytes_written:])
)
if bytes_written == 0:
raise socket.error('connection/socket error')
total_bytes_written += bytes_written
|
python
|
{
"resource": ""
}
|
q835
|
IO._close_socket
|
train
|
def _close_socket(self):
"""Shutdown and close the Socket.
:return:
"""
try:
|
python
|
{
"resource": ""
}
|
q836
|
IO._get_socket_addresses
|
train
|
def _get_socket_addresses(self):
"""Get Socket address information.
:rtype: list
"""
family = socket.AF_UNSPEC
if not socket.has_ipv6:
family = socket.AF_INET
try:
|
python
|
{
"resource": ""
}
|
q837
|
IO._find_address_and_connect
|
train
|
def _find_address_and_connect(self, addresses):
"""Find and connect to the appropriate address.
:param addresses:
:raises AMQPConnectionError: Raises if the connection
encountered an error.
:rtype: socket.socket
"""
error_message = None
for address in addresses:
sock = self._create_socket(socket_family=address[0])
try:
sock.connect(address[4])
except (IOError, OSError) as why:
|
python
|
{
"resource": ""
}
|
q838
|
IO._create_socket
|
train
|
def _create_socket(self, socket_family):
"""Create Socket.
:param int socket_family:
:rtype: socket.socket
"""
sock = socket.socket(socket_family, socket.SOCK_STREAM, 0)
sock.settimeout(self._parameters['timeout'] or None)
if self.use_ssl:
if not compatibility.SSL_SUPPORTED:
|
python
|
{
"resource": ""
}
|
q839
|
IO._ssl_wrap_socket
|
train
|
def _ssl_wrap_socket(self, sock):
"""Wrap SSLSocket around the Socket.
:param socket.socket sock:
:rtype: SSLSocket
"""
context = self._parameters['ssl_options'].get('context')
if context is not None:
hostname = self._parameters['ssl_options'].get('server_hostname')
return context.wrap_socket(
sock, do_handshake_on_connect=True,
server_hostname=hostname
)
if 'ssl_version' not
|
python
|
{
"resource": ""
}
|
q840
|
IO._create_inbound_thread
|
train
|
def _create_inbound_thread(self):
"""Internal Thread that handles all incoming traffic.
:rtype: threading.Thread
"""
inbound_thread = threading.Thread(target=self._process_incoming_data,
|
python
|
{
"resource": ""
}
|
q841
|
IO._process_incoming_data
|
train
|
def _process_incoming_data(self):
"""Retrieve and process any incoming data.
:return:
"""
|
python
|
{
"resource": ""
}
|
q842
|
IO._receive
|
train
|
def _receive(self):
"""Receive any incoming socket data.
If an error is thrown, handle it and return an empty string.
:return: data_in
:rtype: bytes
"""
data_in = EMPTY_BUFFER
try:
data_in = self._read_from_socket()
except socket.timeout:
pass
except (IOError, OSError) as why:
if
|
python
|
{
"resource": ""
}
|
q843
|
IO._read_from_socket
|
train
|
def _read_from_socket(self):
"""Read data from the socket.
:rtype: bytes
"""
if not self.use_ssl:
if not self.socket:
raise socket.error('connection/socket error')
return self.socket.recv(MAX_FRAME_SIZE)
with self._rd_lock:
|
python
|
{
"resource": ""
}
|
q844
|
Heartbeat.start
|
train
|
def start(self, exceptions):
"""Start the Heartbeat Checker.
:param list exceptions:
:return:
"""
if not self._interval:
return False
self._running.set()
with self._lock:
self._threshold = 0
|
python
|
{
"resource": ""
}
|
q845
|
Heartbeat.stop
|
train
|
def stop(self):
"""Stop the Heartbeat Checker.
:return:
"""
self._running.clear()
with self._lock:
|
python
|
{
"resource": ""
}
|
q846
|
Heartbeat._check_for_life_signs
|
train
|
def _check_for_life_signs(self):
"""Check Connection for life signs.
First check if any data has been sent, if not send a heartbeat
to the remote server.
If we have not received any data what so ever within two
intervals, we need to raise an exception so that we can
close the connection.
:rtype: bool
"""
if not self._running.is_set():
|
python
|
{
"resource": ""
}
|
q847
|
Heartbeat._raise_or_append_exception
|
train
|
def _raise_or_append_exception(self):
"""The connection is presumably dead and we need to raise or
append an exception.
If we have a list for exceptions, append the exception and let
the connection handle it, if not raise the exception here.
:return:
"""
message = (
'Connection dead, no heartbeat or data received in >= '
'%ds' % (
|
python
|
{
"resource": ""
}
|
q848
|
Heartbeat._start_new_timer
|
train
|
def _start_new_timer(self):
"""Create a timer that will be used to periodically check the
connection for heartbeats.
:return:
"""
if not self._running.is_set():
return False
self._timer = self.timer_impl(
|
python
|
{
"resource": ""
}
|
q849
|
Queue.get
|
train
|
def get(self, queue, virtual_host='/'):
"""Get Queue details.
:param queue: Queue name
:param str virtual_host: Virtual host name
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises if there was a connectivity issue.
:rtype: dict
|
python
|
{
"resource": ""
}
|
q850
|
Queue.list
|
train
|
def list(self, virtual_host='/', show_all=False):
"""List Queues.
:param str virtual_host: Virtual host name
:param bool show_all: List all Queues
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises if there was a connectivity issue.
:rtype: list
|
python
|
{
"resource": ""
}
|
q851
|
Queue.bindings
|
train
|
def bindings(self, queue, virtual_host='/'):
"""Get Queue bindings.
:param str queue: Queue name
:param str virtual_host: Virtual host name
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises if there was a connectivity issue.
:rtype: list
"""
|
python
|
{
"resource": ""
}
|
q852
|
Exchange.get
|
train
|
def get(self, exchange, virtual_host='/'):
"""Get Exchange details.
:param str exchange: Exchange name
:param str virtual_host: Virtual host name
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises if there was a connectivity issue.
:rtype: dict
|
python
|
{
"resource": ""
}
|
q853
|
Exchange.list
|
train
|
def list(self, virtual_host='/', show_all=False):
"""List Exchanges.
:param str virtual_host: Virtual host name
:param bool show_all: List all Exchanges
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises if there was a connectivity issue.
:rtype: list
|
python
|
{
"resource": ""
}
|
q854
|
Exchange.bindings
|
train
|
def bindings(self, exchange, virtual_host='/'):
"""Get Exchange bindings.
:param str exchange: Exchange name
:param str virtual_host: Virtual host name
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises if there was a connectivity issue.
:rtype: list
"""
|
python
|
{
"resource": ""
}
|
q855
|
Connection.check_for_errors
|
train
|
def check_for_errors(self):
"""Check Connection for errors.
:raises AMQPConnectionError: Raises if the connection
encountered an error.
:return:
|
python
|
{
"resource": ""
}
|
q856
|
Connection.open
|
train
|
def open(self):
"""Open Connection.
:raises AMQPConnectionError: Raises if the connection
encountered an error.
"""
LOGGER.debug('Connection Opening')
self.set_state(self.OPENING)
self._exceptions = []
self._channels = {}
|
python
|
{
"resource": ""
}
|
q857
|
Connection.write_frame
|
train
|
def write_frame(self, channel_id, frame_out):
"""Marshal and write an outgoing pamqp frame to the Socket.
:param int channel_id: Channel ID.
:param specification.Frame frame_out: Amqp frame.
:return:
"""
|
python
|
{
"resource": ""
}
|
q858
|
Connection.write_frames
|
train
|
def write_frames(self, channel_id, frames_out):
"""Marshal and write multiple outgoing pamqp frames to the Socket.
:param int channel_id: Channel ID/
:param list frames_out: Amqp frames.
:return:
"""
data_out = EMPTY_BUFFER
|
python
|
{
"resource": ""
}
|
q859
|
Connection._close_remaining_channels
|
train
|
def _close_remaining_channels(self):
"""Forcefully close all open channels.
:return:
"""
for channel_id in list(self._channels):
|
python
|
{
"resource": ""
}
|
q860
|
Connection._handle_amqp_frame
|
train
|
def _handle_amqp_frame(self, data_in):
"""Unmarshal a single AMQP frame and return the result.
:param data_in: socket data
:return: data_in, channel_id, frame
"""
if not data_in:
return data_in, None, None
try:
byte_count, channel_id, frame_in = pamqp_frame.unmarshal(data_in)
return data_in[byte_count:], channel_id, frame_in
except pamqp_exception.UnmarshalingException:
|
python
|
{
"resource": ""
}
|
q861
|
Connection._read_buffer
|
train
|
def _read_buffer(self, data_in):
"""Process the socket buffer, and direct the data to the appropriate
channel.
:rtype: bytes
"""
while data_in:
data_in, channel_id, frame_in = self._handle_amqp_frame(data_in)
if frame_in is None:
break
self.heartbeat.register_read()
if channel_id == 0:
|
python
|
{
"resource": ""
}
|
q862
|
Connection._cleanup_channel
|
train
|
def _cleanup_channel(self, channel_id):
"""Remove the the channel from the list of available channels.
:param int channel_id: Channel id
:return:
"""
with self.lock:
|
python
|
{
"resource": ""
}
|
q863
|
Connection._validate_parameters
|
train
|
def _validate_parameters(self):
"""Validate Connection Parameters.
:return:
"""
if not compatibility.is_string(self.parameters['hostname']):
raise AMQPInvalidArgument('hostname should be a string')
elif not compatibility.is_integer(self.parameters['port']):
raise AMQPInvalidArgument('port should be an integer')
elif not compatibility.is_string(self.parameters['username']):
|
python
|
{
"resource": ""
}
|
q864
|
Connection._wait_for_connection_state
|
train
|
def _wait_for_connection_state(self, state=Stateful.OPEN, rpc_timeout=30):
"""Wait for a Connection state.
:param int state: State that we expect
:raises AMQPConnectionError: Raises if we are unable to establish
a connection to RabbitMQ.
:return:
"""
start_time = time.time()
|
python
|
{
"resource": ""
}
|
q865
|
Consumer.start
|
train
|
def start(self):
"""Start the Consumers.
:return:
"""
if not self.connection:
self.create_connection()
while True:
try:
channel = self.connection.channel()
channel.queue.declare('simple_queue')
channel.basic.consume(self, 'simple_queue', no_ack=False)
channel.start_consuming()
if not channel.consumer_tags:
|
python
|
{
"resource": ""
}
|
q866
|
ScalableConsumer.stop
|
train
|
def stop(self):
"""Stop all consumers.
:return:
"""
while self._consumers:
consumer = self._consumers.pop()
|
python
|
{
"resource": ""
}
|
q867
|
ScalableConsumer._stop_consumers
|
train
|
def _stop_consumers(self, number_of_consumers=0):
"""Stop a specific number of consumers.
:param number_of_consumers:
:return:
"""
|
python
|
{
"resource": ""
}
|
q868
|
ScalableConsumer._start_consumer
|
train
|
def _start_consumer(self, consumer):
"""Start a consumer as a new Thread.
:param Consumer consumer:
:return:
"""
thread = threading.Thread(target=consumer.start,
|
python
|
{
"resource": ""
}
|
q869
|
Tx.select
|
train
|
def select(self):
"""Enable standard transaction mode.
This will enable transaction mode on the channel. Meaning that
messages will be kept in the remote server buffer until such a
time that either commit or rollback is called.
|
python
|
{
"resource": ""
}
|
q870
|
Tx.rollback
|
train
|
def rollback(self):
"""Abandon the current transaction.
Rollback all messages published during the current transaction
session to the remote server.
Note that all messages published during this transaction session
will be lost, and will have to be published again.
|
python
|
{
"resource": ""
}
|
q871
|
rpc_call
|
train
|
def rpc_call(payload):
"""Simple Flask implementation for making asynchronous Rpc calls. """
# Send the request and store the requests Unique ID.
corr_id = RPC_CLIENT.send_request(payload)
# Wait until we have received a
|
python
|
{
"resource": ""
}
|
q872
|
RpcClient._create_process_thread
|
train
|
def _create_process_thread(self):
"""Create a thread responsible for consuming messages in response
|
python
|
{
"resource": ""
}
|
q873
|
Message.create
|
train
|
def create(channel, body, properties=None):
"""Create a new Message.
:param Channel channel: AMQPStorm Channel
:param bytes|str|unicode body: Message payload
:param dict properties: Message properties
:rtype: Message
"""
properties = properties or {}
if 'correlation_id' not in properties:
properties['correlation_id'] = str(uuid.uuid4())
|
python
|
{
"resource": ""
}
|
q874
|
Message.body
|
train
|
def body(self):
"""Return the Message Body.
If auto_decode is enabled, the body will automatically be
decoded using decode('utf-8') if possible.
:rtype: bytes|str|unicode
"""
if not self._auto_decode:
return self._body
|
python
|
{
"resource": ""
}
|
q875
|
Message.publish
|
train
|
def publish(self, routing_key, exchange='', mandatory=False,
immediate=False):
"""Publish Message.
:param str routing_key: Message routing key
:param str exchange: The exchange to publish the message to
:param bool mandatory: Requires the message is published
:param bool immediate: Request immediate delivery
:raises AMQPInvalidArgument: Invalid Parameters
:raises AMQPChannelError: Raises if the channel encountered an error.
:raises AMQPConnectionError: Raises if the connection
encountered an error.
|
python
|
{
"resource": ""
}
|
q876
|
Message._update_properties
|
train
|
def _update_properties(self, name, value):
"""Update properties, and keep cache up-to-date if auto decode is
enabled.
:param str name: Key
:param obj value: Value
:return:
"""
|
python
|
{
"resource": ""
}
|
q877
|
Message._try_decode_utf8_content
|
train
|
def _try_decode_utf8_content(self, content, content_type):
"""Generic function to decode content.
:param object content:
:return:
"""
if not self._auto_decode or not content:
return content
if content_type in self._decode_cache:
return self._decode_cache[content_type]
|
python
|
{
"resource": ""
}
|
q878
|
Message._try_decode_dict
|
train
|
def _try_decode_dict(self, content):
"""Decode content of a dictionary.
:param dict content:
:return:
"""
result = dict()
for key, value in content.items():
key = try_utf8_decode(key)
if isinstance(value, dict):
result[key] = self._try_decode_dict(value)
elif isinstance(value,
|
python
|
{
"resource": ""
}
|
q879
|
Message._try_decode_list
|
train
|
def _try_decode_list(content):
"""Decode content of a list.
:param list|tuple content:
:return:
"""
result = list()
|
python
|
{
"resource": ""
}
|
q880
|
Basic.get
|
train
|
def get(self, queue, virtual_host='/', requeue=False, to_dict=False,
count=1, truncate=50000, encoding='auto'):
"""Get Messages.
:param str queue: Queue name
:param str virtual_host: Virtual host name
:param bool requeue: Re-queue message
:param bool to_dict: Should incoming messages be converted to a
dictionary before delivery.
:param int count: How many messages should we try to fetch.
:param int truncate: The maximum length in bytes, beyond that the
server will truncate the message.
:param str encoding: Message encoding.
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises if there was a connectivity issue.
:rtype: list
"""
ackmode = 'ack_requeue_false'
if requeue:
ackmode = 'ack_requeue_true'
get_messages = json.dumps(
{
'count': count,
'requeue': requeue,
'ackmode': ackmode,
|
python
|
{
"resource": ""
}
|
q881
|
VirtualHost.get
|
train
|
def get(self, virtual_host):
"""Get Virtual Host details.
:param str virtual_host: Virtual host name
:raises ApiError: Raises if the remote server encountered an
|
python
|
{
"resource": ""
}
|
q882
|
VirtualHost.create
|
train
|
def create(self, virtual_host):
"""Create a Virtual Host.
:param str virtual_host: Virtual host name
:raises ApiError: Raises if the remote server encountered an
|
python
|
{
"resource": ""
}
|
q883
|
VirtualHost.delete
|
train
|
def delete(self, virtual_host):
"""Delete a Virtual Host.
:param str virtual_host: Virtual host name
:raises ApiError: Raises if the remote server encountered an
|
python
|
{
"resource": ""
}
|
q884
|
VirtualHost.get_permissions
|
train
|
def get_permissions(self, virtual_host):
"""Get all Virtual hosts permissions.
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises if there was a connectivity issue.
:rtype: dict
"""
virtual_host = quote(virtual_host,
|
python
|
{
"resource": ""
}
|
q885
|
BaseChannel.add_consumer_tag
|
train
|
def add_consumer_tag(self, tag):
"""Add a Consumer tag.
:param str tag: Consumer tag.
:return:
"""
if not is_string(tag):
|
python
|
{
"resource": ""
}
|
q886
|
BaseChannel.remove_consumer_tag
|
train
|
def remove_consumer_tag(self, tag=None):
"""Remove a Consumer tag.
If no tag is specified, all all tags will be removed.
:param str|None tag: Consumer tag.
:return:
"""
if tag is not None:
|
python
|
{
"resource": ""
}
|
q887
|
BaseMessage.to_dict
|
train
|
def to_dict(self):
"""Message to Dictionary.
:rtype: dict
"""
return {
'body': self._body,
'method': self._method,
|
python
|
{
"resource": ""
}
|
q888
|
BaseMessage.to_tuple
|
train
|
def to_tuple(self):
"""Message to Tuple.
:rtype: tuple
"""
|
python
|
{
"resource": ""
}
|
q889
|
Connection.close
|
train
|
def close(self, connection, reason='Closed via management api'):
"""Close Connection.
:param str connection: Connection name
:param str reason: Reason for closing connection.
:raises ApiError: Raises if the remote server encountered an error.
:raises ApiConnectionError: Raises if there was a connectivity issue.
:rtype: None
"""
close_payload = json.dumps({
'name': connection,
'reason': reason
})
|
python
|
{
"resource": ""
}
|
q890
|
Rpc.on_frame
|
train
|
def on_frame(self, frame_in):
"""On RPC Frame.
:param specification.Frame frame_in: Amqp frame.
:return:
"""
if frame_in.name not in self._request:
return False
uuid = self._request[frame_in.name]
|
python
|
{
"resource": ""
}
|
q891
|
Rpc.register_request
|
train
|
def register_request(self, valid_responses):
"""Register a RPC request.
:param list valid_responses: List of possible Responses that
|
python
|
{
"resource": ""
}
|
q892
|
Rpc.get_request
|
train
|
def get_request(self, uuid, raw=False, multiple=False,
connection_adapter=None):
"""Get a RPC request.
:param str uuid: Rpc Identifier
:param bool raw: If enabled return the frame as is, else return
result as a dictionary.
:param bool multiple: Are we expecting multiple frames.
:param obj connection_adapter: Provide custom connection adapter.
:return:
"""
if uuid not in self._response:
return
self._wait_for_request(
|
python
|
{
"resource": ""
}
|
q893
|
Rpc._get_response_frame
|
train
|
def _get_response_frame(self, uuid):
"""Get a response frame.
:param str uuid: Rpc Identifier
:return:
"""
frame = None
frames
|
python
|
{
"resource": ""
}
|
q894
|
Rpc._wait_for_request
|
train
|
def _wait_for_request(self, uuid, connection_adapter=None):
"""Wait for RPC request to arrive.
:param str uuid: Rpc Identifier.
:param obj connection_adapter: Provide custom connection adapter.
:return:
"""
start_time = time.time()
|
python
|
{
"resource": ""
}
|
q895
|
Rpc._raise_rpc_timeout_error
|
train
|
def _raise_rpc_timeout_error(self, uuid):
"""Gather information and raise an Rpc exception.
:param str uuid: Rpc Identifier.
:return:
"""
requests = []
for key, value in self._request.items():
|
python
|
{
"resource": ""
}
|
q896
|
get_default_ssl_version
|
train
|
def get_default_ssl_version():
"""Get the highest support TLS version, if none is available, return None.
:rtype: bool|None
"""
if hasattr(ssl, 'PROTOCOL_TLSv1_2'):
return ssl.PROTOCOL_TLSv1_2
elif hasattr(ssl, 'PROTOCOL_TLSv1_1'):
|
python
|
{
"resource": ""
}
|
q897
|
is_string
|
train
|
def is_string(obj):
"""Is this a string.
:param object obj:
:rtype: bool
"""
|
python
|
{
"resource": ""
}
|
q898
|
is_integer
|
train
|
def is_integer(obj):
"""Is this an integer.
:param object obj:
:return:
"""
if PYTHON3:
|
python
|
{
"resource": ""
}
|
q899
|
try_utf8_decode
|
train
|
def try_utf8_decode(value):
"""Try to decode an object.
:param value:
:return:
"""
if not value or not is_string(value):
return value
elif PYTHON3 and not isinstance(value, bytes):
return value
|
python
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.