_id stringlengths 2 7 | title stringlengths 1 88 | partition stringclasses 3 values | text stringlengths 31 13.1k | language stringclasses 1 value | meta_information dict |
|---|---|---|---|---|---|
q700 | PresenceClient.get_most_available_stanza | train | def get_most_available_stanza(self, peer_jid):
"""
Obtain the stanza describing the most-available presence of the
contact.
:param peer_jid: Bare JID of the contact.
:type peer_jid: :class:`aioxmpp.JID`
:rtype: :class:`aioxmpp.Presence` or :data:`None`
:return: The presence stanza of the most available resource or
:data:`None` if there is no available resource.
The "most available" resource is the one whose presence state orderest
highest according to :class:`~aioxmpp.PresenceState`.
If there is no available resource for a given `peer_jid`, :data:`None`
| python | {
"resource": ""
} |
q701 | PresenceClient.get_peer_resources | train | def get_peer_resources(self, peer_jid):
"""
Return a dict mapping resources of the given bare `peer_jid` to the
presence state last received for that resource.
Unavailable presence states are not included. If the bare JID is in a
error state (i.e. an error presence stanza has been received), the
| python | {
"resource": ""
} |
q702 | PresenceServer.make_stanza | train | def make_stanza(self):
"""
Create and return a presence stanza with the current settings.
:return: Presence stanza
:rtype: :class:`aioxmpp.Presence`
"""
stanza = aioxmpp.Presence()
| python | {
"resource": ""
} |
q703 | PresenceServer.set_presence | train | def set_presence(self, state, status={}, priority=0):
"""
Change the presence broadcast by the client.
:param state: New presence state to broadcast
:type state: :class:`aioxmpp.PresenceState`
:param status: New status information to broadcast
:type status: :class:`dict` or :class:`str`
:param priority: New priority for the resource
:type priority: :class:`int`
:return: Stanza token of the presence stanza or :data:`None` if the
presence is unchanged or the stream is not connected.
:rtype: :class:`~.stream.StanzaToken`
If the client is currently connected, the new presence is broadcast
immediately.
`status` must be either a string or something which can be passed to
the :class:`dict` constructor. If it is a string, it is wrapped into a
dict using ``{None: status}``. The mapping must map
:class:`~.LanguageTag` objects (or :data:`None`) to strings. The
information will be used to generate internationalised presence status
information. If you do not need internationalisation, simply use the
string version of the argument.
"""
if not isinstance(priority, numbers.Integral):
raise TypeError(
"invalid priority: got {}, expected integer".format(
type(priority)
| python | {
"resource": ""
} |
q704 | PresenceServer.resend_presence | train | def resend_presence(self):
"""
Re-send the currently configured presence.
:return: Stanza token of the presence stanza or :data:`None` if the
stream is not established.
:rtype: :class:`~.stream.StanzaToken`
.. note::
:meth:`set_presence` automatically broadcasts | python | {
"resource": ""
} |
q705 | AbstractPinStore.export_to_json | train | def export_to_json(self):
"""
Return a JSON dictionary which contains all the pins stored in this
store.
"""
return {
| python | {
"resource": ""
} |
q706 | SASLProvider._find_supported | train | def _find_supported(self, features, mechanism_classes):
"""
Find the first mechansim class which supports a mechanism announced in
the given stream features.
:param features: Current XMPP stream features
:type features: :class:`~.nonza.StreamFeatures`
:param mechanism_classes: SASL mechanism classes to use
:type mechanism_classes: iterable of :class:`SASLMechanism`
sub\\ *classes*
:raises aioxmpp.errors.SASLUnavailable: if the peer does not announce
SASL support
:return: the :class:`SASLMechanism` subclass to use and a token
:rtype: pair
Return a supported SASL mechanism class, by looking | python | {
"resource": ""
} |
q707 | SASLProvider._execute | train | def _execute(self, intf, mechanism, token):
"""
Execute a SASL authentication process.
:param intf: SASL interface to use
:type intf: :class:`~.sasl.SASLXMPPInterface`
:param mechanism: SASL mechanism to use
:type mechanism: :class:`aiosasl.SASLMechanism`
:param token: The opaque token argument for the mechanism
:type token: not :data:`None`
:raises aiosasl.AuthenticationFailure: if authentication failed due to
bad credentials
:raises aiosasl.SASLFailure: on other SASL error conditions (such as
protocol violations)
| python | {
"resource": ""
} |
q708 | AbstractConversation.send_message | train | def send_message(self, body):
"""
Send a message to the conversation.
:param msg: The message to send.
:type msg: :class:`aioxmpp.Message`
:return: The stanza token obtained from sending.
:rtype: :class:`~aioxmpp.stream.StanzaToken`
The default implementation simply calls :meth:`send_message_tracked`
and immediately cancels the tracking object, returning only the stanza
token.
There is no need to provide proper address attributes on `msg`.
Implementations will override those attributes with the values
appropriate for the conversation. Some implementations may allow the
user to choose a :attr:`~aioxmpp.Message.type_`, but others may simply
stamp it over.
Subclasses | python | {
"resource": ""
} |
q709 | AbstractConversation.invite | train | def invite(self, address, text=None, *,
mode=InviteMode.DIRECT,
allow_upgrade=False):
"""
Invite another entity to the conversation.
:param address: The address of the entity to invite.
:type address: :class:`aioxmpp.JID`
:param text: A reason/accompanying text for the invitation.
:param mode: The invitation mode to use.
:type mode: :class:`~.im.InviteMode`
:param allow_upgrade: Whether to allow creating a new conversation to
satisfy the invitation.
:type allow_upgrade: :class:`bool`
:raises NotImplementedError: if the requested `mode` is not supported
:raises ValueError: if `allow_upgrade` is false, but a new conversation
is required.
:return: The stanza token for the invitation and the possibly new
conversation object
:rtype: tuple of :class:`~.StanzaToken` and
:class:`~.AbstractConversation`
.. note::
Even though this is a coroutine, it returns a stanza token. The
coroutine-ness may be needed to generate the invitation in the
first place. Sending the actual invitation is done non-blockingly
and the stanza token for that is returned. To wait until the
invitation has been sent, unpack the stanza token from the result
and await it.
Return the new conversation object to use. In many cases, this will
simply be the current conversation object, but in some cases (e.g. when
someone is invited to a one-on-one conversation), a new conversation
must be created and used.
| python | {
"resource": ""
} |
q710 | stdout_writer | train | async def stdout_writer():
"""
This is a bit complex, as stdout can be a pipe or a file.
If it is a file, we cannot use
:meth:`asycnio.BaseEventLoop.connect_write_pipe`.
"""
if sys.stdout.seekable():
# it’s a file
return sys.stdout.buffer.raw
| python | {
"resource": ""
} |
q711 | first_signal | train | def first_signal(*signals):
"""
Connect to multiple signals and wait for the first to emit.
:param signals: Signals to connect to.
:type signals: :class:`AdHocSignal`
:return: An awaitable for the first signal to emit.
The awaitable returns the first argument passed to the signal. If the first
argument is an exception, the exception is re-raised from the awaitable.
A common use-case is a situation where a class exposes a "on_finished" type
signal and an "on_failure" type signal. :func:`first_signal` can be used
to combine those nicely::
# e.g. a aioxmpp.im.conversation.AbstractConversation
conversation = ...
await first_signal(
# emits without arguments when the conversation is successfully
# entered
conversation.on_enter,
# emits with an exception when entering the conversation fails
conversation.on_failure,
)
# await first_signal(...) will either raise an exception (failed) or
# return None (success)
.. warning::
| python | {
"resource": ""
} |
q712 | AdHocSignal.connect | train | def connect(self, f, mode=None):
"""
Connect an object `f` to the signal. The type the object needs to have
depends on `mode`, but usually it needs to be a callable.
:meth:`connect` returns an opaque token which can be used with
:meth:`disconnect` to disconnect the object from the signal.
The default value for `mode` is :attr:`STRONG`. Any decorator can be
used as argument for `mode` and it is applied to `f`. The result is
stored internally and is what will be called when the signal is being
emitted.
If the result of `mode` returns a false value during emission, the
connection is removed.
.. note::
| python | {
"resource": ""
} |
q713 | AdHocSignal.fire | train | def fire(self, *args, **kwargs):
"""
Emit the signal, calling all connected objects in-line with the given
arguments and in the order they were registered.
:class:`AdHocSignal` provides full isolation with respect to
exceptions. If a connected listener raises an exception, the other
listeners are executed as normal, but the raising listener is removed
from the signal. The exception is logged to :attr:`logger` and *not*
re-raised, so that the caller of the signal is also not affected.
Instead of calling :meth:`fire` explicitly, the ad-hoc signal object
itself can be called, too.
| python | {
"resource": ""
} |
q714 | SyncAdHocSignal.connect | train | def connect(self, coro):
"""
The coroutine `coro` is connected to the signal. The coroutine must
return a true value, unless it wants to be disconnected from the
signal.
.. note::
This is different from the return value convention with
:attr:`AdHocSignal.STRONG` and :attr:`AdHocSignal.WEAK`.
| python | {
"resource": ""
} |
q715 | SyncAdHocSignal.fire | train | def fire(self, *args, **kwargs):
"""
Emit the signal, calling all coroutines in-line with the given
arguments and in the order they were registered.
This is obviously a coroutine.
Instead of calling :meth:`fire` explicitly, the ad-hoc signal object
itself can be called, too.
| python | {
"resource": ""
} |
q716 | Filter.register | train | def register(self, func, order):
"""
Add a function to the filter chain.
:param func: A callable which is to be added to the filter chain.
:param order: An object indicating the ordering of the function
relative to the others.
:return: Token representing the registration.
Register the function `func` as a filter into the chain. `order` must
be a value which is used as a sorting key to order the functions
registered in the chain.
The type of `order` depends on the use of the filter, as does the
number of arguments and keyword arguments which `func` must accept.
This will generally be documented at the place where the
:class:`Filter` is used.
Functions with the same order | python | {
"resource": ""
} |
q717 | Filter.filter | train | def filter(self, obj, *args, **kwargs):
"""
Filter the given object through the filter chain.
:param obj: The object to filter
:param args: Additional arguments to pass to each filter function.
:param kwargs: Additional keyword arguments to pass to each filter
| python | {
"resource": ""
} |
q718 | Filter.unregister | train | def unregister(self, token_to_remove):
"""
Unregister a filter function.
:param token_to_remove: The token as returned by :meth:`register`.
Unregister a function from the filter chain using the token returned by
:meth:`register`.
"""
for i, (_, token, _) in | python | {
"resource": ""
} |
q719 | MessageTracker.set_timeout | train | def set_timeout(self, timeout):
"""
Automatically close the tracker after `timeout` has elapsed.
:param timeout: The timeout after which the tracker is closed
automatically.
:type timeout: :class:`numbers.Real` or :class:`datetime.timedelta`
| python | {
"resource": ""
} |
q720 | MessageTracker._set_state | train | def _set_state(self, new_state, response=None):
"""
Set the state of the tracker.
:param new_state: The new state of the tracker.
:type new_state: :class:`~.MessageState` member
:param response: A stanza related to the new state.
:type response: :class:`~.StanzaBase` or :data:`None`
:raise ValueError: if a forbidden state transition is attempted.
:raise RuntimeError: if the tracker is closed.
The state of the tracker is set to the `new_state`. The
:attr:`response` is also overriden with the new value, no matter if the
new or old value is :data:`None` or not. The :meth:`on_state_changed`
event is emitted.
The following transitions are forbidden and attempting to perform them
will raise :class:`ValueError`:
* any state -> :attr:`~.MessageState.IN_TRANSIT`
* :attr:`~.MessageState.DELIVERED_TO_RECIPIENT` ->
:attr:`~.MessageState.DELIVERED_TO_SERVER`
* :attr:`~.MessageState.SEEN_BY_RECIPIENT` ->
:attr:`~.MessageState.DELIVERED_TO_RECIPIENT`
* :attr:`~.MessageState.SEEN_BY_RECIPIENT` ->
:attr:`~.MessageState.DELIVERED_TO_SERVER`
* :attr:`~.MessageState.ABORTED` -> any state
* :attr:`~.MessageState.ERROR` -> any state
If the tracker is already :meth:`close`\\ -d, :class:`RuntimeError` is
raised. This check happens *before* a test is made whether the
transition is valid.
This method is part of the "protected" interface.
"""
if self._closed:
raise RuntimeError("message tracker is closed")
| python | {
"resource": ""
} |
q721 | BasicTrackingService.send_tracked | train | def send_tracked(self, stanza, tracker):
"""
Send a message stanza with tracking.
:param stanza: Message stanza to send.
:type stanza: :class:`aioxmpp.Message`
:param tracker: Message tracker to use.
:type tracker: :class:`~.MessageTracker`
:rtype: :class:`~.StanzaToken`
:return: The token used to send the stanza.
If `tracker` is :data:`None`, a new :class:`~.MessageTracker` is
created.
This configures tracking for the stanza as if by calling
:meth:`attach_tracker` with a `token` and sends the stanza through the
stream.
| python | {
"resource": ""
} |
q722 | BasicTrackingService.attach_tracker | train | def attach_tracker(self, stanza, tracker=None, token=None):
"""
Configure tracking for a stanza without sending it.
:param stanza: Message stanza to send.
:type stanza: :class:`aioxmpp.Message`
:param tracker: Message tracker to use.
:type tracker: :class:`~.MessageTracker` or :data:`None`
:param token: Optional stanza token for more fine-grained tracking.
:type token: :class:`~.StanzaToken`
:rtype: :class:`~.MessageTracker`
:return: The message tracker.
If `tracker` is :data:`None`, a new :class:`~.MessageTracker` is
created.
If `token` is not :data:`None`, updates to the stanza `token` are
reflected in the `tracker`.
If an error reply is received, the tracker will enter
:class:`~.MessageState.ERROR` and the error will be set as
:attr:`~.MessageTracker.response`.
You should use :meth:`send_tracked` if possible. This method however is
very useful if you need to track carbon copies of sent messages, as a
stanza token is not available here and re-sending the message to obtain
one is generally not desirable ☺.
"""
| python | {
"resource": ""
} |
q723 | MUCPinger.start | train | def start(self):
"""
Start the pinging coroutine using the client and event loop which was
passed to the constructor.
| python | {
"resource": ""
} |
q724 | MUCPinger._interpret_result | train | def _interpret_result(self, task):
"""
Interpret the result of a ping.
:param task: The pinger task.
The result or exception of the `task` is interpreted as follows:
* :data:`None` result: *positive*
* :class:`aioxmpp.errors.XMPPError`, ``service-unavailable``:
*positive*
* :class:`aioxmpp.errors.XMPPError`, ``feature-not-implemented``:
*positive*
* :class:`aioxmpp.errors.XMPPError`, ``item-not-found``: *inconclusive*
* :class:`aioxmpp.errors.XMPPError`: *negative*
* :class:`asyncio.TimeoutError`: *inconclusive*
* Any other exception: *inconclusive*
"""
if task.exception() is None:
self._on_fresh()
| python | {
"resource": ""
} |
q725 | MUCMonitor.reset | train | def reset(self):
"""
Reset the monitor.
Reset the aliveness timeouts. Clear the stale state. Cancel and stop
pinging.
Call `on_fresh` if the stale state was set.
| python | {
"resource": ""
} |
q726 | DeliveryReceiptsService.attach_tracker | train | def attach_tracker(self, stanza, tracker=None):
"""
Return a new tracker or modify one to track the stanza.
:param stanza: Stanza to track.
:type stanza: :class:`aioxmpp.Message`
:param tracker: Existing tracker to attach to.
:type tracker: :class:`.tracking.MessageTracker`
:raises ValueError: if the stanza is of type
:attr:`~aioxmpp.MessageType.ERROR`
:raises ValueError: if the stanza contains a delivery receipt
:return: The message tracker for the stanza.
:rtype: :class:`.tracking.MessageTracker`
The `stanza` gets a :xep:`184` reciept request attached and internal
handlers are set up to update the `tracker` state once a confirmation
is received.
.. warning::
See the :ref:`api-tracking-memory`.
"""
if stanza.xep0184_received is not None:
raise ValueError(
"requesting delivery receipts for delivery receipts is not "
| python | {
"resource": ""
} |
q727 | PrivateXMLService.get_private_xml | train | def get_private_xml(self, query_xso):
"""
Get the private XML data for the element `query_xso` from the
server.
:param query_xso: the object to retrieve.
:returns: the stored private XML data.
`query_xso` *must* serialize to an empty XML node of the
wanted namespace and type and *must* be registered as private
XML | python | {
"resource": ""
} |
q728 | PrivateXMLService.set_private_xml | train | def set_private_xml(self, xso):
"""
Store the serialization of `xso` on the server as the private XML
data for the namespace of `xso`.
:param xso: the XSO whose serialization is send as private XML data.
"""
iq = aioxmpp.IQ( | python | {
"resource": ""
} |
q729 | BookmarkClient._get_bookmarks | train | def _get_bookmarks(self):
"""
Get the stored bookmarks from the server.
:returns: a list of bookmarks
"""
| python | {
"resource": ""
} |
q730 | BookmarkClient._set_bookmarks | train | def _set_bookmarks(self, bookmarks):
"""
Set the bookmarks stored on the server.
"""
storage = bookmark_xso.Storage()
| python | {
"resource": ""
} |
q731 | BookmarkClient.get_bookmarks | train | def get_bookmarks(self):
"""
Get the stored bookmarks from the server. Causes signals to be
fired to reflect the changes.
:returns: a list of bookmarks
"""
with (yield from self._lock):
| python | {
"resource": ""
} |
q732 | BookmarkClient.set_bookmarks | train | def set_bookmarks(self, bookmarks):
"""
Store the sequence of bookmarks `bookmarks`.
Causes signals to be fired to reflect the changes.
.. note:: This should normally not be used. It does not
mitigate the race condition between clients
concurrently modifying the bookmarks and may lead to
data loss. Use :meth:`add_bookmark`,
:meth:`discard_bookmark` and :meth:`update_bookmark`
instead. This method still has use-cases | python | {
"resource": ""
} |
q733 | BookmarkClient.add_bookmark | train | def add_bookmark(self, new_bookmark, *, max_retries=3):
"""
Add a bookmark and check whether it was successfully added to the
bookmark list. Already existant bookmarks are not added twice.
:param new_bookmark: the bookmark to add
:type new_bookmark: an instance of :class:`~bookmark_xso.Bookmark`
:param max_retries: the number of retries if setting the bookmark
fails
:type max_retries: :class:`int`
:raises RuntimeError: if the bookmark is not in the bookmark list
after `max_retries` retries.
After setting the bookmark it is checked, whether the bookmark
is in the online storage, if it is not it is tried again at most
`max_retries` times to add the bookmark. A :class:`RuntimeError`
is raised if the bookmark could not be added successfully after
`max_retries`.
"""
with (yield from self._lock):
bookmarks = yield from self._get_bookmarks()
try:
modified_bookmarks = list(bookmarks)
if new_bookmark not in bookmarks:
| python | {
"resource": ""
} |
q734 | BookmarkClient.discard_bookmark | train | def discard_bookmark(self, bookmark_to_remove, *, max_retries=3):
"""
Remove a bookmark and check it has been removed.
:param bookmark_to_remove: the bookmark to remove
:type bookmark_to_remove: a :class:`~bookmark_xso.Bookmark` subclass.
:param max_retries: the number of retries of removing the bookmark
fails.
:type max_retries: :class:`int`
:raises RuntimeError: if the bookmark is not removed from
bookmark list after `max_retries`
retries.
If there are multiple occurences of the same bookmark exactly
one is removed.
This does nothing if the bookmarks does not match an existing
bookmark according to bookmark-equality.
After setting the bookmark it is checked, whether the bookmark
is removed in the online storage, if it is not it is tried
again at most `max_retries` times to remove the bookmark. A
| python | {
"resource": ""
} |
q735 | BookmarkClient.update_bookmark | train | def update_bookmark(self, old, new, *, max_retries=3):
"""
Update a bookmark and check it was successful.
The bookmark matches an existing bookmark `old` according to
bookmark equalitiy and replaces it by `new`. The bookmark
`new` is added if no bookmark matching `old` exists.
:param old: the bookmark to replace
:type bookmark_to_remove: a :class:`~bookmark_xso.Bookmark` subclass.
:param new: the replacement bookmark
:type bookmark_to_remove: a :class:`~bookmark_xso.Bookmark` subclass.
:param max_retries: the number of retries of removing the bookmark
fails.
:type max_retries: :class:`int`
:raises RuntimeError: if the bookmark is not in the bookmark list
after `max_retries` retries.
After replacing the bookmark it is checked, whether the
bookmark `new` is in the online storage, if it is not it is
tried again at most `max_retries` times to replace the
bookmark. A :class:`RuntimeError` is raised if the bookmark
could not be replaced successfully after `max_retries`.
.. note:: Do not modify a bookmark retrieved from the signals
or from :meth:`get_bookmarks` to obtain the bookmark
`new`, this will lead to data corruption as they are
passed by reference. Instead use :func:`copy.copy`
and modify the copy.
"""
def replace_bookmark(bookmarks, old, new):
modified_bookmarks = list(bookmarks)
try:
i = bookmarks.index(old)
modified_bookmarks[i] = new
except ValueError:
modified_bookmarks.append(new)
return modified_bookmarks
with (yield from self._lock):
| python | {
"resource": ""
} |
q736 | Node.iter_identities | train | def iter_identities(self, stanza=None):
"""
Return an iterator of tuples describing the identities of the node.
:param stanza: The IQ request stanza
:type stanza: :class:`~aioxmpp.IQ` or :data:`None`
:rtype: iterable of (:class:`str`, :class:`str`, :class:`str` or
:data:`None`, :class:`str` or :data:`None`) tuples
:return: :xep:`30` identities of this node
`stanza` can be the :class:`aioxmpp.IQ` stanza of the request. This can
be used to hide a node depending on who is asking. If the returned
iterable is empty, the :class:`~.DiscoServer` returns an
| python | {
"resource": ""
} |
q737 | Node.iter_features | train | def iter_features(self, stanza=None):
"""
Return an iterator which yields the features of the node.
:param stanza: The IQ request stanza
:type stanza: :class:`~aioxmpp.IQ`
:rtype: iterable of :class:`str`
:return: :xep:`30` features of this node
`stanza` is the :class:`aioxmpp.IQ` stanza of the request. This can be
used to filter the list according to who is asking (not recommended).
`stanza` may be :data:`None` if the features are queried without
a specific request context. In that case, implementors should assume
that the result is visible to everybody.
.. note::
| python | {
"resource": ""
} |
q738 | Node.register_feature | train | def register_feature(self, var):
"""
Register a feature with the namespace variable `var`.
If the feature is already registered or part of the default :xep:`30`
features, a :class:`ValueError` is raised.
"""
if var in self._features or var | python | {
"resource": ""
} |
q739 | Node.register_identity | train | def register_identity(self, category, type_, *, names={}):
"""
Register an identity with the given `category` and `type_`.
If there is already a registered identity with the same `category` and
`type_`, :class:`ValueError` is raised.
`names` may be a mapping which maps :class:`.structs.LanguageTag`
instances to strings. This mapping will be used to produce
``<identity/>`` declarations with the respective ``xml:lang`` and | python | {
"resource": ""
} |
q740 | DiscoClient.query_info | train | def query_info(self, jid, *,
node=None, require_fresh=False, timeout=None,
no_cache=False):
"""
Query the features and identities of the specified entity.
:param jid: The entity to query.
:type jid: :class:`aioxmpp.JID`
:param node: The node to query.
:type node: :class:`str` or :data:`None`
:param require_fresh: Boolean flag to discard previous caches.
:type require_fresh: :class:`bool`
:param timeout: Optional timeout for the response.
:type timeout: :class:`float`
:param no_cache: Boolean flag to forbid caching of the request.
:type no_cache: :class:`bool`
:rtype: :class:`.xso.InfoQuery`
:return: Service discovery information of the `node` at `jid`.
The requests are cached. This means that only one request is ever fired
for a given target (identified by the `jid` and the `node`). The
request is re-used for all subsequent requests to that identity.
If `require_fresh` is set to true, the above does not hold and a fresh
request is always created. The new request is the request which will be
used as alias for subsequent requests to the same identity.
The visible effects of this are twofold:
* Caching: Results of requests are implicitly cached
* Aliasing: Two concurrent requests will be aliased to one request to
save computing resources
Both can be turned off by using `require_fresh`. In general, you should
not need to use `require_fresh`, as all requests are implicitly
cancelled whenever the underlying session gets destroyed.
`no_cache` can be set to true to prevent future requests to be aliased
to this request, i.e. the request is not stored in the internal request
cache. This does not affect `require_fresh`, i.e. if a cached result is
available, it is used.
The `timeout` can be used to restrict the time to wait for a
response. If the timeout triggers, :class:`TimeoutError` is raised.
If :meth:`~.Client.send` raises an
exception, all queries which were running simultanously for the same
target re-raise that exception. The result is not cached though. If a
new query is sent at a later point for the same target, a new query is
actually sent, independent of the value chosen for `require_fresh`.
.. versionchanged:: 0.9
The `no_cache` argument was added.
"""
key = jid, node
if not require_fresh: | python | {
"resource": ""
} |
q741 | DiscoClient.query_items | train | def query_items(self, jid, *,
node=None, require_fresh=False, timeout=None):
"""
Query the items of the specified entity.
:param jid: The entity to query.
:type jid: :class:`aioxmpp.JID`
:param node: The node to query.
:type node: :class:`str` or :data:`None`
:param require_fresh: Boolean flag to discard previous caches.
:type require_fresh: :class:`bool`
:param timeout: Optional timeout for the response.
:type timeout: :class:`float`
:rtype: :class:`.xso.ItemsQuery`
:return: Service discovery items of the `node` at `jid`.
The arguments have the same semantics as with :meth:`query_info`, as
does the caching and error handling.
"""
key = jid, node
if not require_fresh:
try:
| python | {
"resource": ""
} |
q742 | RosterClient.export_as_json | train | def export_as_json(self):
"""
Export the whole roster as currently stored on the client side into a
JSON-compatible dictionary and return that dictionary.
"""
return {
"items": { | python | {
"resource": ""
} |
q743 | RosterClient.set_entry | train | def set_entry(self, jid, *,
name=_Sentinel,
add_to_groups=frozenset(),
remove_from_groups=frozenset(),
timeout=None):
"""
Set properties of a roster entry or add a new roster entry. The roster
entry is identified by its bare `jid`.
If an entry already exists, all values default to those stored in the
existing entry. For example, if no `name` is given, the current name of
the entry is re-used, if any.
If the entry does not exist, it will be created on the server side.
The `remove_from_groups` and `add_to_groups` arguments have to be based
on the locally cached state, as XMPP does not support sending
diffs. `remove_from_groups` takes precedence over `add_to_groups`.
`timeout` is the time in seconds to wait for a confirmation by the
server.
Note that the changes may not be visible immediately after his
coroutine returns in the :attr:`items` and :attr:`groups`
attributes. The :class:`Service` waits for the "official" roster push
from the server for updating the data structures and firing events, to
ensure that consistent state with other clients is achieved.
This may raise arbitrary :class:`.errors.XMPPError` exceptions if the
server replies with an error and also any kind of connection error if
| python | {
"resource": ""
} |
q744 | RosterClient.remove_entry | train | def remove_entry(self, jid, *, timeout=None):
"""
Request removal of the roster entry identified by the given bare
`jid`. If the entry currently has any subscription state, the server
will send the corresponding unsubscribing presence stanzas.
`timeout` is the maximum time in seconds to wait for a reply from the
server.
This may raise arbitrary :class:`.errors.XMPPError` exceptions if the
server replies with an error and also any kind of connection error if
the connection gets fatally terminated while waiting for a response.
"""
yield from self.client.send(
| python | {
"resource": ""
} |
q745 | RosterClient.subscribe | train | def subscribe(self, peer_jid):
"""
Request presence subscription with the given `peer_jid`.
This is deliberately not a coroutine; we don’t know whether the peer is
online (usually) and they may defer the confirmation very long, if they
confirm at all. Use :meth:`on_subscribed` to get notified when a peer
accepted | python | {
"resource": ""
} |
q746 | RosterClient.unsubscribe | train | def unsubscribe(self, peer_jid):
"""
Unsubscribe from the presence of the given `peer_jid`.
"""
self.client.enqueue( | python | {
"resource": ""
} |
q747 | message_handler | train | def message_handler(type_, from_):
"""
Register the decorated function as message handler.
:param type_: Message type to listen for
:type type_: :class:`~.MessageType`
:param from_: Sender JIDs to listen for
:type from_: :class:`aioxmpp.JID` or :data:`None`
:raise TypeError: if the decorated object is a coroutine function
.. seealso::
:meth:`~.StanzaStream.register_message_callback`
for more details on the `type_` and `from_` arguments
.. versionchanged:: 0.9
This is now based on
:class:`aioxmpp.dispatcher.SimpleMessageDispatcher`.
"""
def decorator(f):
if asyncio.iscoroutinefunction(f):
| python | {
"resource": ""
} |
q748 | presence_handler | train | def presence_handler(type_, from_):
"""
Register the decorated function as presence stanza handler.
:param type_: Presence type to listen for
:type type_: :class:`~.PresenceType`
:param from_: Sender JIDs to listen for
:type from_: :class:`aioxmpp.JID` or :data:`None`
:raise TypeError: if the decorated object is a coroutine function
.. seealso::
:meth:`~.StanzaStream.register_presence_callback`
for more details on the `type_` and `from_` arguments
.. versionchanged:: 0.9
This is now based on
:class:`aioxmpp.dispatcher.SimplePresenceDispatcher`.
"""
def decorator(f):
if asyncio.iscoroutinefunction(f):
| python | {
"resource": ""
} |
q749 | SimpleStanzaDispatcher._feed | train | def _feed(self, stanza):
"""
Dispatch the given `stanza`.
:param stanza: Stanza to dispatch
:type stanza: :class:`~.StanzaBase`
:rtype: :class:`bool`
:return: true if the stanza was dispatched, false otherwise.
Dispatch the stanza to up to one handler registered on the dispatcher.
If no handler is found for the stanza, :data:`False` is returned.
Otherwise, | python | {
"resource": ""
} |
q750 | SimpleStanzaDispatcher.register_callback | train | def register_callback(self, type_, from_, cb, *,
wildcard_resource=True):
"""
Register a callback function.
:param type_: Stanza type to listen for, or :data:`None` for a
wildcard match.
:param from_: Sender to listen for, or :data:`None` for a full wildcard
match.
:type from_: :class:`aioxmpp.JID` or :data:`None`
:param cb: Callback function to register
:param wildcard_resource: Whether to wildcard the resourcepart of the
JID.
:type wildcard_resource: :class:`bool`
:raises ValueError: if another function is already registered for the
callback slot.
`cb` will be called whenever a stanza with the matching `type_` and
`from_` is processed. The following wildcarding rules apply:
1. If the :attr:`~aioxmpp.stanza.StanzaBase.from_` attribute of the
stanza has a resourcepart, the following lookup order for callbacks is used:
+---------------------------+----------------------------------+----------------------+
|``type_`` |``from_`` |``wildcard_resource`` |
+===========================+==================================+======================+
|:attr:`~.StanzaBase.type_` |:attr:`~.StanzaBase.from_` |*any* |
+---------------------------+----------------------------------+----------------------+
|:attr:`~.StanzaBase.type_` |*bare* :attr:`~.StanzaBase.from_` |:data:`True` |
+---------------------------+----------------------------------+----------------------+
|:data:`None` |:attr:`~.StanzaBase.from_` |*any* |
+---------------------------+----------------------------------+----------------------+
|:data:`None` |*bare* :attr:`~.StanzaBase.from_` |:data:`True` |
+---------------------------+----------------------------------+----------------------+
|:attr:`~.StanzaBase.type_` |:data:`None` |*any* |
+---------------------------+----------------------------------+----------------------+
|:data:`None` |:data:`None` |*any* |
+---------------------------+----------------------------------+----------------------+
2. If the :attr:`~aioxmpp.stanza.StanzaBase.from_` attribute of the
stanza does *not* have a resourcepart, the following | python | {
"resource": ""
} |
q751 | SimpleStanzaDispatcher.unregister_callback | train | def unregister_callback(self, type_, from_, *,
wildcard_resource=True):
"""
Unregister a callback function.
:param type_: Stanza type to listen for, or :data:`None` for a
wildcard match.
:param from_: Sender to listen for, or :data:`None` for a full wildcard
match.
:type from_: :class:`aioxmpp.JID` or :data:`None`
:param wildcard_resource: Whether to wildcard the resourcepart of the
| python | {
"resource": ""
} |
q752 | SimpleStanzaDispatcher.handler_context | train | def handler_context(self, type_, from_, cb, *, wildcard_resource=True):
"""
Context manager which temporarily registers a callback.
The arguments are the same as for :meth:`register_callback`.
When the context is entered, the callback `cb` is registered. When the
context is exited, no matter if an exception is raised or not, the
callback is unregistered.
"""
self.register_callback(
type_, from_, cb,
| python | {
"resource": ""
} |
q753 | BoundField.load | train | def load(self, field_xso):
"""
Load the field information from a data field.
:param field_xso: XSO describing the field.
:type field_xso: :class:`~.Field`
This loads the current value, description, label and possibly options
from the `field_xso`, shadowing the information from the declaration of
the field on the class.
This method is must | python | {
"resource": ""
} |
q754 | BoundMultiValueField.value | train | def value(self):
"""
A tuple of values. This attribute can be set with any iterable; the
iterable is then evaluated into a tuple and stored at the bound field.
Whenever values are written to this attribute, they are passed through
the :meth:`~.AbstractCDataType.coerce` method of the
:attr:`~.AbstractField.type_` of the field. To revert the
| python | {
"resource": ""
} |
q755 | write_single_xso | train | def write_single_xso(x, dest):
"""
Write a single XSO `x` to a binary file-like object `dest`.
"""
| python | {
"resource": ""
} |
q756 | read_xso | train | def read_xso(src, xsomap):
"""
Read a single XSO from a binary file-like input `src` containing an XML
document.
`xsomap` must be a mapping which maps :class:`~.XSO` subclasses
to callables. These will be registered at a newly created
:class:`.xso.XSOParser` instance which will be used to parse the document
in `src`.
The `xsomap` is thus used to determine | python | {
"resource": ""
} |
q757 | XMPPXMLGenerator.startPrefixMapping | train | def startPrefixMapping(self, prefix, uri, *, auto=False):
"""
Start a prefix mapping which maps the given `prefix` to the given
`uri`.
Note that prefix mappings are handled transactional. All announcements
of prefix mappings are collected until the next call to
:meth:`startElementNS`. At that point, the mappings are collected and
start to override the previously declared mappings until the
corresponding :meth:`endElementNS` call.
Also note that calling :meth:`startPrefixMapping` is not mandatory; you
can use any namespace you like at any time. If you use a namespace
whose URI has not been associated with a prefix yet, a free prefix will
automatically be chosen. To avoid unneccessary performance penalties,
do not use prefixes of the form ``"ns{:d}".format(n)``, for any
non-negative number of `n`.
It is however required to call :meth:`endPrefixMapping` after a
:meth:`endElementNS` call for all namespaces which have been announced
directly before the :meth:`startElementNS` call (except for those which
have been chosen automatically). Not doing so will result in a
:class:`RuntimeError` at the next :meth:`startElementNS` or
:meth:`endElementNS` call.
During a transaction, it is not allowed to declare the same prefix | python | {
"resource": ""
} |
q758 | XMPPXMLGenerator.buffer | train | def buffer(self):
"""
Context manager to temporarily buffer the output.
:raise RuntimeError: If two :meth:`buffer` context managers are used
nestedly.
If the context manager is left without exception, the buffered output
is sent to the actual sink. Otherwise, it is discarded.
In addition to the output being buffered, buffer also captures the
entire state of the XML generator and restores it to the previous state
if the context manager is left with an exception.
This can be used to fail-safely attempt to serialise a subtree and
return to a well-defined state if serialisation fails.
:meth:`flush` is not called automatically.
If :meth:`flush` is called while a :meth:`buffer` context manager is
active, no actual flushing happens (but unfinished opening tags are
closed as usual, see the `short_empty_arguments` parameter).
"""
if self._buf_in_use:
raise RuntimeError("nested use of buffer() is not supported")
self._buf_in_use = True
old_write = self._write
old_flush = self._flush
if self._buf is None:
| python | {
"resource": ""
} |
q759 | XMLStreamWriter.start | train | def start(self):
"""
Send the stream header as described above.
"""
attrs = {
(None, "to"): str(self._to),
(None, "version"): ".".join(map(str, self._version))
}
if self._from:
attrs[None, "from"] = str(self._from)
self._writer.startDocument()
for prefix, | python | {
"resource": ""
} |
q760 | XMLStreamWriter.send | train | def send(self, xso):
"""
Send a single XML stream object.
:param xso: Object to serialise and send.
:type xso: :class:`aioxmpp.xso.XSO`
:raises Exception: from any serialisation errors, usually
:class:`ValueError`.
Serialise the `xso` and send it over | python | {
"resource": ""
} |
q761 | XMLStreamWriter.abort | train | def abort(self):
"""
Abort the stream.
The stream is flushed and the internal data structures are cleaned up.
No stream footer is sent. The stream is | python | {
"resource": ""
} |
q762 | ResultSetMetadata.fetch_page | train | def fetch_page(cls, index, max_=None):
"""
Return a query set which requests a specific page.
:param index: Index of the first element of the page to fetch.
:type index: :class:`int`
:param max_: Maximum number of elements to fetch
:type max_: :class:`int` or :data:`None`
:rtype: :class:`ResultSetMetadata`
:return: A new request set up to request a page starting with the
element indexed by `index`.
.. note::
| python | {
"resource": ""
} |
q763 | ResultSetMetadata.limit | train | def limit(self, max_):
"""
Limit the result set to a given number of items.
:param max_: Maximum number of items to return.
:type max_: :class:`int` or :data:`None`
:rtype: :class:`ResultSetMetadata`
:return: A new request set up to request at most `max_` items.
This method can be called on the class and on objects. When called on
objects, it returns a | python | {
"resource": ""
} |
q764 | ResultSetMetadata.next_page | train | def next_page(self, max_=None):
"""
Return a query set which requests the page after this response.
:param max_: Maximum number of items to return.
:type max_: :class:`int` or :data:`None`
:rtype: :class:`ResultSetMetadata`
:return: A new request set up to request the next page.
| python | {
"resource": ""
} |
q765 | ResultSetMetadata.previous_page | train | def previous_page(self, max_=None):
"""
Return a query set which requests the page before this response.
:param max_: Maximum number of items to return.
:type max_: :class:`int` or :data:`None`
:rtype: :class:`ResultSetMetadata`
:return: A new request set up to request the previous page.
| python | {
"resource": ""
} |
q766 | ResultSetMetadata.last_page | train | def last_page(self_or_cls, max_=None):
"""
Return a query set which requests the last page.
:param max_: Maximum number of items to return.
:type max_: :class:`int` | python | {
"resource": ""
} |
q767 | FieldType.allow_upcast | train | def allow_upcast(self, to):
"""
Return true if the field type may be upcast to the other field type
`to`.
This relation specifies when it is safe to transfer data from this
field type to the given other field type `to`.
This is the case if any of the following holds true:
* `to` is equal to | python | {
"resource": ""
} |
q768 | Data.get_form_type | train | def get_form_type(self):
"""
Extract the ``FORM_TYPE`` from the fields.
:return: ``FORM_TYPE`` value or :data:`None`
:rtype: :class:`str` or :data:`None`
Return :data:`None` if no well-formed ``FORM_TYPE`` field is found | python | {
"resource": ""
} |
q769 | get_registration_fields | train | def get_registration_fields(xmlstream,
timeout=60,
):
"""
A query is sent to the server to obtain the fields that need to be
filled to register with the server.
:param xmlstream: Specifies the stream connected to the server where
the account will be created.
:type xmlstream: :class:`aioxmpp.protocol.XMLStream`
:param timeout: Maximum time in seconds to wait for an IQ response, or
:data:`None` to disable the timeout.
:type timeout: :class:`~numbers.Real` or :data:`None`
:return: :attr:`list`
"""
iq = aioxmpp.IQ(
to=aioxmpp.JID.fromstr(xmlstream._to), | python | {
"resource": ""
} |
q770 | register | train | def register(xmlstream,
query_xso,
timeout=60,
):
"""
Create a new account on the server.
:param query_xso: XSO with the information needed for the registration.
:type query_xso: :class:`~aioxmpp.ibr.Query`
:param xmlstream: Specifies the stream connected to the server where
the account will be created.
:type xmlstream: :class:`aioxmpp.protocol.XMLStream`
:param timeout: Maximum time in seconds to wait for an IQ response, or
:data:`None` to disable the timeout.
:type timeout: :class:`~numbers.Real` or :data:`None`
"""
iq = aioxmpp.IQ(
to=aioxmpp.JID.fromstr(xmlstream._to), | python | {
"resource": ""
} |
q771 | get_used_fields | train | def get_used_fields(payload):
"""
Get a list containing the names of the fields that are used in the
xso.Query.
:param payload: Query object o be
:type payload: :class:`~aioxmpp.ibr.Query`
:return: :attr:`list`
"""
return [
tag
| python | {
"resource": ""
} |
q772 | RegistrationService.get_client_info | train | def get_client_info(self):
"""
A query is sent to the server to obtain the client's data stored at the
server.
:return: :class:`~aioxmpp.ibr.Query`
"""
iq = aioxmpp.IQ(
to=self.client.local_jid.bare().replace(localpart=None),
| python | {
"resource": ""
} |
q773 | RegistrationService.change_pass | train | def change_pass(self,
new_pass):
"""
Change the client password for 'new_pass'.
:param new_pass: New password of the client.
:type new_pass: :class:`str`
:param old_pass: Old password of the client.
:type old_pass: :class:`str`
"""
iq = | python | {
"resource": ""
} |
q774 | RegistrationService.cancel_registration | train | def cancel_registration(self):
"""
Cancels the currents client's account with the server.
Even if the cancelation is succesful, this method will raise an
exception due to he account no longer exists for the server, so the
client | python | {
"resource": ""
} |
q775 | discover_connectors | train | def discover_connectors(
domain: str,
loop=None,
logger=logger):
"""
Discover all connection options for a domain, in descending order of
preference.
This coroutine returns options discovered from SRV records, or if none are
found, the generic option using the domain name and the default XMPP client
port.
Each option is represented by a triple ``(host, port, connector)``.
`connector` is a :class:`aioxmpp.connector.BaseConnector` instance which is
suitable to connect to the given host and port.
`logger` is the logger used by the function.
The following sources are supported:
* :rfc:`6120` SRV records. One option is returned per SRV record.
If one of the SRV records points to the root name (``.``),
:class:`ValueError` is raised (the domain specifically said that XMPP is
not supported here).
* :xep:`368` SRV records. One option is returned per SRV record.
* :rfc:`6120` fallback process (only if no SRV records are found). One
option is returned for the host name with the default XMPP client port.
The options discovered from SRV records are mixed together, ordered by
priority and then within priorities are shuffled according to their weight.
Thus, if there are multiple records of equal priority, the result of the
function is not deterministic.
.. versionadded:: 0.6
"""
domain_encoded = domain.encode("idna") + b"."
starttls_srv_failed = False
tls_srv_failed = False
try:
starttls_srv_records = yield from network.lookup_srv(
domain_encoded,
"xmpp-client",
)
starttls_srv_disabled = False
except dns.resolver.NoNameservers as exc:
starttls_srv_records = []
starttls_srv_disabled = False
starttls_srv_failed = True
starttls_srv_exc = exc
logger.debug("xmpp-client SRV lookup for domain %s failed "
"(may not be fatal)",
domain_encoded,
exc_info=True)
except ValueError:
starttls_srv_records = []
starttls_srv_disabled = True
try:
tls_srv_records = yield from network.lookup_srv(
domain_encoded,
"xmpps-client",
)
tls_srv_disabled = False
except dns.resolver.NoNameservers:
tls_srv_records = []
tls_srv_disabled = False
tls_srv_failed = True
logger.debug("xmpps-client SRV lookup for domain | python | {
"resource": ""
} |
q776 | Client.stop | train | def stop(self):
"""
Stop the client. This sends a signal to the clients main task which
makes it terminate.
It may take some cycles through the event loop to stop the client
task. To check whether the task has actually stopped, query
:attr:`running`.
| python | {
"resource": ""
} |
q777 | Client.enqueue | train | def enqueue(self, stanza, **kwargs):
"""
Put a `stanza` in the internal transmission queue and return a token to
track it.
:param stanza: Stanza to send
:type stanza: :class:`IQ`, :class:`Message` or :class:`Presence`
:param kwargs: see :class:`StanzaToken`
:raises ConnectionError: if the stream is not :attr:`established`
yet.
:return: token which tracks the stanza
:rtype: :class:`StanzaToken`
The `stanza` is enqueued in the active queue for transmission and will
be sent on the next opportunity. The relative ordering of stanzas
enqueued is always preserved.
Return a fresh :class:`StanzaToken` instance which traks the progress
of the transmission of the `stanza`. The `kwargs` are forwarded to the
| python | {
"resource": ""
} |
q778 | Client.send | train | def send(self, stanza, *, timeout=None, cb=None):
"""
Send a stanza.
:param stanza: Stanza to send
:type stanza: :class:`~.IQ`, :class:`~.Presence` or :class:`~.Message`
:param timeout: Maximum time in seconds to wait for an IQ response, or
:data:`None` to disable the timeout.
:type timeout: :class:`~numbers.Real` or :data:`None`
:param cb: Optional callback which is called synchronously when the
reply is received (IQ requests only!)
:raise OSError: if the underlying XML stream fails and stream
management is not disabled.
:raise aioxmpp.stream.DestructionRequested:
if the stream is closed while sending the stanza or waiting for a
response.
:raise aioxmpp.errors.XMPPError: if an error IQ response is received
:raise aioxmpp.errors.ErroneousStanza: if the IQ response could not be
parsed
:raise ValueError: if `cb` is given and `stanza` is not an IQ request.
:return: IQ response :attr:`~.IQ.payload` or :data:`None`
Send the stanza and wait for it to be sent. If the stanza is an IQ
request, the response is awaited and the :attr:`~.IQ.payload` of the
response is returned.
If the stream is currently not ready, this method blocks until the
stream is ready to send payload stanzas. Note that this may be before
initial presence has been sent. To synchronise with that type of
events, use the appropriate signals.
The `timeout` as well as any of the exception cases referring to a
"response" do not apply for IQ response stanzas, message stanzas or
presence stanzas sent with this method, as this method only waits for
a reply if an IQ *request* stanza is being sent.
If `stanza` is an IQ request and the response is not received within
`timeout` seconds, :class:`TimeoutError` (not
:class:`asyncio.TimeoutError`!) is raised.
If `cb` is given, `stanza` must be an IQ request (otherwise,
:class:`ValueError` is raised before the stanza is sent). It must be a
callable returning an awaitable. It receives the response stanza as
first and only argument. The returned awaitable is awaited by
:meth:`send` and the result is returned instead of the original
payload. `cb` is called synchronously from the stream handling loop
when the response is received, so it can benefit from the strong
ordering guarantees given by XMPP XML Streams.
The `cb` may also return :data:`None`, in which case :meth:`send` will
simply return the IQ payload as if `cb` was not given. Since the return
value of coroutine functions is awaitable, it is valid and supported to
pass a coroutine function as `cb`.
.. warning::
Remember that it is an implementation detail of the event loop when
a coroutine is scheduled after it awaited an awaitable; this
implies that if the caller of :meth:`send` is merely awaiting the
:meth:`send` coroutine, the strong ordering guarantees of | python | {
"resource": ""
} |
q779 | ping | train | def ping(client, peer):
"""
Ping a peer.
:param peer: The peer to ping.
:type peer: :class:`aioxmpp.JID`
:raises aioxmpp.errors.XMPPError: as received
Send a :xep:`199` ping IQ to `peer` and wait for the reply.
This is a low-level version of :meth:`aioxmpp.PingService.ping`.
**When to use this function vs. the service method:** See
:meth:`aioxmpp.PingService.ping`.
.. note::
If the peer does not support :xep:`199`, they will respond with
a ``cancel`` ``service-unavailable`` error. However, some
implementations return a ``cancel`` ``feature-not-implemented``
error instead. Callers should be prepared for the
| python | {
"resource": ""
} |
q780 | SHIMService.register_header | train | def register_header(self, name):
"""
Register support for the SHIM header with the given `name`.
If the header has already been registered as supported,
:class:`ValueError` is raised.
| python | {
"resource": ""
} |
q781 | SHIMService.unregister_header | train | def unregister_header(self, name):
"""
Unregister support for the SHIM header with the given `name`.
If the header is currently not registered as supported,
:class:`KeyError` is raised.
| python | {
"resource": ""
} |
q782 | VCardService.set_vcard | train | def set_vcard(self, vcard):
"""
Store the vCard `vcard` for the connected entity.
:param vcard: the vCard to store.
.. note::
`vcard` should always be derived from the result of
`get_vcard` to preserve the elements | python | {
"resource": ""
} |
q783 | ChatStateManager.handle | train | def handle(self, state, message=False):
"""
Handle a state update.
:param state: the new chat state
:type state: :class:`~aioxmpp.chatstates.ChatState`
:param message: pass true to indicate that we handle the
:data:`ACTIVE` state that is implied by
sending a content message.
:type message: :class:`bool`
:returns: whether a standalone notification must be sent for
this state update, respective if a chat state
notification must be included with the message.
:raises ValueError: if `message` is true | python | {
"resource": ""
} |
q784 | XMLStream.close | train | def close(self):
"""
Close the XML stream and the underlying transport.
This gracefully shuts down the XML stream and the transport, if
possible by writing the eof using :meth:`asyncio.Transport.write_eof`
after sending the stream footer.
After a call to :meth:`close`, no other stream manipulating or sending
method can be called; doing so will result in a
:class:`ConnectionError` exception or any exception caused by the
transport during shutdown.
Calling :meth:`close` while the stream is closing or closed is a
no-op.
"""
if (self._smachine.state == State.CLOSING or
| python | {
"resource": ""
} |
q785 | XMLStream.reset | train | def reset(self):
"""
Reset the stream by discarding all state and re-sending the stream
header.
Calling :meth:`reset` when the stream is disconnected or currently
disconnecting results in either :class:`ConnectionError` being raised
or the exception which caused the stream to die (possibly a received
stream error or a transport error) to be reraised. | python | {
"resource": ""
} |
q786 | XMLStream.abort | train | def abort(self):
"""
Abort the stream by writing an EOF if possible and closing the
transport.
The transport is closed using :meth:`asyncio.BaseTransport.close`, so
buffered data is sent, but no more data will be received. The stream is
in :attr:`State.CLOSED` state afterwards.
This also works if the stream is currently closing, that is, waiting
for the peer to send a stream footer. In that case, the stream will be
closed locally as if the stream footer had been received.
.. versionadded:: 0.5
"""
| python | {
"resource": ""
} |
q787 | XMLStream.starttls | train | def starttls(self, ssl_context, post_handshake_callback=None):
"""
Start TLS on the transport and wait for it to complete.
The `ssl_context` and `post_handshake_callback` arguments are forwarded
to the transports
:meth:`aioopenssl.STARTTLSTransport.starttls` coroutine method.
If the transport does not support starttls, :class:`RuntimeError` is
raised; support for starttls can be discovered by querying
:meth:`can_starttls`.
After :meth:`starttls` returns, you must call :meth:`reset`. Any other
method may fail in interesting ways as the internal state is discarded
when starttls succeeds, for security reasons. :meth:`reset` re-creates
| python | {
"resource": ""
} |
q788 | XMLStream.error_future | train | def error_future(self):
"""
Return a future which will receive the next XML stream error as
exception.
It is safe to cancel the future at any time.
"""
| python | {
"resource": ""
} |
q789 | PubSubClient.get_features | train | def get_features(self, jid):
"""
Return the features supported by a service.
:param jid: Address of the PubSub service to query.
:type jid: :class:`aioxmpp.JID`
:return: Set of supported features
:rtype: set containing :class:`~.pubsub.xso.Feature` enumeration
members.
This simply uses service discovery to obtain the set of features and
converts the features to :class:`~.pubsub.xso.Feature` enumeration
members. To get the full feature information, resort to using
:meth:`.DiscoClient.query_info` directly on `jid`.
Features returned by the peer which are not valid pubsub features are
| python | {
"resource": ""
} |
q790 | PubSubClient.subscribe | train | def subscribe(self, jid, node=None, *,
subscription_jid=None,
config=None):
"""
Subscribe to a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to subscribe to.
:type node: :class:`str`
:param subscription_jid: The address to subscribe to the service.
:type subscription_jid: :class:`aioxmpp.JID`
:param config: Optional configuration of the subscription
:type config: :class:`~.forms.Data`
:raises aioxmpp.errors.XMPPError: as returned by the service
:return: The response from the server.
:rtype: :class:`.xso.Request`
By default, the subscription request will be for the bare JID of the
client. It can be specified explicitly using the `subscription_jid`
argument.
If the service requires it or if it makes sense for other reasons, the
subscription configuration :class:`~.forms.Data` form can be passed
using the `config` argument.
On success, the whole :class:`.xso.Request` object returned by the
server is returned. It contains a :class:`.xso.Subscription`
:attr:`~.xso.Request.payload` which has information on the nature of
the subscription (it may be ``"pending"`` or ``"unconfigured"``) and
the :attr:`~.xso.Subscription.subid` which may be required for other
| python | {
"resource": ""
} |
q791 | PubSubClient.unsubscribe | train | def unsubscribe(self, jid, node=None, *,
subscription_jid=None,
subid=None):
"""
Unsubscribe from a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to unsubscribe from.
:type node: :class:`str`
:param subscription_jid: The address to subscribe from the service.
:type subscription_jid: :class:`aioxmpp.JID`
:param subid: Unique ID of the subscription to remove.
:type subid: :class:`str`
:raises aioxmpp.errors.XMPPError: as returned by the service
By default, the unsubscribe request will be for the bare JID of the
client. It can be specified explicitly using the `subscription_jid`
| python | {
"resource": ""
} |
q792 | PubSubClient.get_subscription_config | train | def get_subscription_config(self, jid, node=None, *,
subscription_jid=None,
subid=None):
"""
Request the current configuration of a subscription.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to query.
:type node: :class:`str`
:param subscription_jid: The address to query the configuration for.
:type subscription_jid: :class:`aioxmpp.JID`
:param subid: Unique ID of the subscription to query.
:type subid: :class:`str`
:raises aioxmpp.errors.XMPPError: as returned by the service
:return: The current configuration of the subscription.
:rtype: :class:`~.forms.Data`
By default, the request will be on behalf of the bare JID of the
client. It can be overriden using the `subscription_jid` argument.
| python | {
"resource": ""
} |
q793 | PubSubClient.get_default_config | train | def get_default_config(self, jid, node=None):
"""
Request the default configuration of a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to query.
:type node: :class:`str`
:raises aioxmpp.errors.XMPPError: as returned by the service
| python | {
"resource": ""
} |
q794 | PubSubClient.get_node_config | train | def get_node_config(self, jid, node=None):
"""
Request the configuration of a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to query.
:type node: :class:`str`
:raises aioxmpp.errors.XMPPError: as returned by the service
:return: The configuration of the node.
:rtype: :class:`~.forms.Data`
On success, the :class:`~.forms.Data` form is returned.
If an error occurs, the corresponding :class:`~.errors.XMPPError` is
raised.
| python | {
"resource": ""
} |
q795 | PubSubClient.set_node_config | train | def set_node_config(self, jid, config, node=None):
"""
Update the configuration of a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param config: Configuration form
:type config: :class:`aioxmpp.forms.Data`
:param node: Name of the PubSub node to query.
:type node: :class:`str`
:raises aioxmpp.errors.XMPPError: as returned by the service
:return: The configuration of the node.
:rtype: :class:`~.forms.Data`
.. seealso::
:class:`aioxmpp.pubsub.NodeConfigForm`
| python | {
"resource": ""
} |
q796 | PubSubClient.get_items | train | def get_items(self, jid, node, *, max_items=None):
"""
Request the most recent items from a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to query.
:type node: :class:`str`
:param max_items: Number of items to return at most.
:type max_items: :class:`int` or :data:`None`
:raises aioxmpp.errors.XMPPError: as returned by the service
:return: The response from the server.
:rtype: :class:`.xso.Request`.
By default, as many as possible items are requested. If `max_items` is
given, it must be a positive integer specifying the maximum number of
| python | {
"resource": ""
} |
q797 | PubSubClient.get_items_by_id | train | def get_items_by_id(self, jid, node, ids):
"""
Request specific items by their IDs from a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to query.
:type node: :class:`str`
:param ids: The item IDs to return.
:type ids: :class:`~collections.abc.Iterable` of :class:`str`
:raises aioxmpp.errors.XMPPError: as returned by the service
:return: The response from the service
:rtype: :class:`.xso.Request`
`ids` must be an iterable of :class:`str` of the IDs of the items to
request from the pubsub node. If the iterable is empty,
:class:`ValueError` is raised (as otherwise, the request would be
identical to calling :meth:`get_items` without `max_items`).
| python | {
"resource": ""
} |
q798 | PubSubClient.get_subscriptions | train | def get_subscriptions(self, jid, node=None):
"""
Return all subscriptions of the local entity to a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to query.
:type node: :class:`str`
:raises aioxmpp.errors.XMPPError: as returned by the | python | {
"resource": ""
} |
q799 | PubSubClient.publish | train | def publish(self, jid, node, payload, *,
id_=None,
publish_options=None):
"""
Publish an item to a node.
:param jid: Address of the PubSub service.
:type jid: :class:`aioxmpp.JID`
:param node: Name of the PubSub node to publish to.
:type node: :class:`str`
:param payload: Registered payload to publish.
:type payload: :class:`aioxmpp.xso.XSO`
:param id_: Item ID to use for the item.
:type id_: :class:`str` or :data:`None`.
:param publish_options: A data form with the options for the publish
request
:type publish_options: :class:`aioxmpp.forms.Data`
:raises aioxmpp.errors.XMPPError: as returned by the service
:raises RuntimeError: if `publish_options` is not :data:`None` but
the service does not support `publish_options`
:return: The Item ID which was used to publish the item.
:rtype: :class:`str` or :data:`None`
Publish the given `payload` (which must be a :class:`aioxmpp.xso.XSO`
registered with :attr:`.xso.Item.registered_payload`).
The item is published to `node` at `jid`. If `id_` is given, it is used
as the ID for the item. If an item with the same ID already exists at
the node, it is replaced. If no ID is given, a ID is generated by the
server.
If `publish_options` is given, it is passed as ``<publish-options/>``
element to the server. This needs to be a data form which allows to
define e.g. node configuration as a pre-condition to publishing. If
the publish-options cannot be satisfied, the server will raise a
:attr:`aioxmpp.ErrorCondition.CONFLICT` error.
If `publish_options` is given and the server does not announce the
| python | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.