How to use the aioxmpp.errors function in aioxmpp

To help you get started, we’ve selected a few aioxmpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github horazont / aioxmpp / tests / test_errors.py View on Github external
def test_is_value_and_user_error(self):
        self.assertTrue(issubclass(
            errors.UserValueError,
            errors.UserError,
        ))
        self.assertTrue(issubclass(
            errors.UserValueError,
            ValueError
        ))
github jabbercat / jabbercat / tests / test_avatar.py View on Github external
def test__get_image_tries_next_if_image_bytes_not_available(self):
        client = self._prep_client()

        self.ap.prepare_client(client)

        base = unittest.mock.Mock()
        base.avatar1 = unittest.mock.Mock(
            spec=aioxmpp.avatar.service.AbstractAvatarDescriptor)
        base.avatar1.get_image_bytes = CoroutineMock()

        base.avatar2 = unittest.mock.Mock(
            spec=aioxmpp.avatar.service.AbstractAvatarDescriptor)
        base.avatar2.get_image_bytes = CoroutineMock()
        base.avatar2.get_image_bytes.side_effect = \
            aioxmpp.errors.XMPPCancelError(("foo", "bar"))

        base.avatar3 = unittest.mock.Mock(
            spec=aioxmpp.avatar.service.AbstractAvatarDescriptor)
        base.avatar3.get_image_bytes = CoroutineMock()
        base.avatar3.get_image_bytes.return_value = \
            unittest.mock.sentinel.image_bytes

        self.avatar.get_avatar_metadata.return_value = [
            base.avatar2,
            base.avatar3,
            base.avatar1,
        ]

        with unittest.mock.patch("jabbercat.Qt.QImage") as QImage:
            QImage.fromData.return_value.isNull.return_value = False
github horazont / aioxmpp / aioxmpp / node.py View on Github external
def _try_resume_stream_management(self, xmlstream, features):
        try:
            yield from self.stream.resume_sm(xmlstream)
        except errors.StreamNegotiationFailure as exc:
            self.logger.warn("failed to resume stream (%s)",
                             exc)
            return False
        return True
github horazont / aioxmpp / aioxmpp / node.py View on Github external
exceptions,
        jid, metadata, negotiation_timeout, loop, logger,
    )
    if result is not None:
        return result

    if not options and not override_peer:
        raise ValueError("no options to connect to XMPP domain {!r}".format(
            jid.domain
        ))

    for exc in exceptions:
        if isinstance(exc, errors.TLSFailure):
            raise exc

    raise errors.MultiOSError(
        "failed to connect to XMPP domain {!r}".format(jid.domain),
        exceptions
    )
github jabbercat / jabbercat / jabbercat / avatar.py View on Github external
def _get_image(self, address: aioxmpp.JID) -> typing.Optional[Qt.QImage]:
        try:
            metadata = yield from self._avatar_svc.get_avatar_metadata(address)
        except (aioxmpp.errors.XMPPError,
                aioxmpp.errors.ErroneousStanza) as exc:
            self.logger.warning("cannot fetch avatar from %s: %s",
                                address, exc)
            return

        for descriptor in metadata:
            try:
                data = yield from descriptor.get_image_bytes()
            except (NotImplementedError, RuntimeError,
                    aioxmpp.errors.XMPPCancelError):
                continue
            img = Qt.QImage.fromData(data)
            if not img.isNull():
                return img
github horazont / aioxmpp / aioxmpp / version / service.py View on Github external
def handle_query(self, iq: aioxmpp.IQ) -> version_xso.Query:
        if self._name is None:
            raise aioxmpp.errors.XMPPCancelError(
                aioxmpp.errors.ErrorCondition.SERVICE_UNAVAILABLE,
            )

        result = version_xso.Query()
        result.name = self._name
        result.os = self._os
        result.version = self._version or "unspecified"
        return result
github horazont / aioxmpp / aioxmpp / ibb / service.py View on Github external
try:
                    yield from self._service.client.send(
                        stanza
                    )
                except errors.XMPPWaitError:
                    # wait and try again unless max retries have been reached
                    if self._retries < self._service.max_retries:
                        yield from asyncio.sleep(self._wait_time)
                        self._wait_time *= self._service.wait_backoff_factor
                        self._retries += 1
                        continue
                    else:
                        e = asyncio.TimeoutError()
                        break
                except errors.StanzaError as _e:
                    # break the loop to close the connection
                    e = _e
                    break
                # update the internal state after the successful
                # write: remove the written data from the buffer and
                # increment the sequence number
                self._write_buffer = self._write_buffer[len(data):]
                self._outgoing_seq += 1
                self._outgoing_seq &= 0xffff

                # reset the wait time
                self._wait_time = \
                    self._service.initial_wait_time.total_seconds()
                self._retries = 0

            if len(self._write_buffer) < self._output_buffer_limit_low:
github horazont / aioxmpp / aioxmpp / stream.py View on Github external
If called with an erroneous remote stanza counter
        :class:`.errors.StreamNegotationFailure` will be raised.

        Attempting to call this without Stream Management enabled results in a
        :class:`RuntimeError`.
        """

        if not self._sm_enabled:
            raise RuntimeError("Stream Management is not enabled")

        self._logger.debug("sm_ack(%d)", remote_ctr)
        to_drop = (remote_ctr - self._sm_outbound_base) & 0xffffffff
        self._logger.debug("sm_ack: to drop %d, unacked: %d",
                           to_drop, len(self._sm_unacked_list))
        if to_drop > len(self._sm_unacked_list):
            raise errors.StreamNegotiationFailure(
                "acked more stanzas than have been sent "
                "(outbound_base={}, remote_ctr={})".format(
                    self._sm_outbound_base,
                    remote_ctr
                )
            )

        acked = self._sm_unacked_list[:to_drop]
        del self._sm_unacked_list[:to_drop]
        self._sm_outbound_base = remote_ctr

        if acked:
            self._logger.debug("%d stanzas acked by remote", len(acked))
        for token in acked:
            token._set_state(StanzaState.ACKED)
github horazont / aioxmpp / aioxmpp / xml.py View on Github external
def comment(cls, data):
        raise errors.StreamError(
            errors.StreamErrorCondition.RESTRICTED_XML,
            "comments are not allowed in XMPP"
        )
github horazont / aioxmpp / aioxmpp / stanza.py View on Github external
.. automethod:: as_application_condition

    Conversion to and from exceptions is supported with the following methods:

    .. automethod:: to_exception

    .. automethod:: from_exception

    """

    TAG = (namespaces.client, "error")

    DECLARE_NS = {}

    EXCEPTION_CLS_MAP = {
        structs.ErrorType.MODIFY: errors.XMPPModifyError,
        structs.ErrorType.CANCEL: errors.XMPPCancelError,
        structs.ErrorType.AUTH: errors.XMPPAuthError,
        structs.ErrorType.WAIT: errors.XMPPWaitError,
        structs.ErrorType.CONTINUE: errors.XMPPContinueError,
    }

    UNKNOWN_CHILD_POLICY = xso.UnknownChildPolicy.DROP

    UNKNOWN_ATTR_POLICY = xso.UnknownAttrPolicy.DROP

    type_ = xso.Attr(
        tag="type",
        type_=xso.EnumCDataType(
            structs.ErrorType,
            allow_coerce=True,
            deprecate_coerce=True,