Commit d56945cc authored by lovetox's avatar lovetox
Browse files

Use error_factory() everywhere

parent 2f4a79e0
Loading
Loading
Loading
Loading
+0 −30
Changes for nbxmpp/const.py: 0 added lines, 30 removed lines.
Original line number Diff line number Diff line
@@ -255,36 +255,6 @@ class Role(Enum):
        return self == Role.NONE


class Error(Enum):
    BAD_REQUEST = 'bad-request'
    CONFLICT = 'conflict'
    FEATURE_NOT_IMPLEMENTED = 'feature-not-implemented'
    FORBIDDEN = 'forbidden'
    GONE = 'gone'
    INTERNAL_SERVER_ERROR = 'internal-server-error'
    ITEM_NOT_FOUND = 'item-not-found'
    JID_MALFORMED = 'jid-malformed'
    NOT_ACCEPTABLE = 'not-acceptable'
    NOT_ALLOWED = 'not-allowed'
    NOT_AUTHORIZED = 'not-authorized'
    PAYMENT_REQUIRED = 'payment-required'
    RECIPIENT_UNAVAILABLE = 'recipient-unavailable'
    REDIRECT = 'redirect'
    REGISTRATION_REQUIRED = 'registration-required'
    REMOTE_SERVER_NOT_FOUND = 'remote-server-not-found'
    REMOTE_SERVER_TIMEOUT = 'remote-server-timeout'
    RESOURCE_CONSTRAINT = 'resource-constraint'
    SERVICE_UNAVAILABLE = 'service-unavailable'
    SUBSCRIPTION_REQUIRED = 'subscription-required'
    UNDEFINED_CONDITION = 'undefined-condition'
    UNEXPECTED_REQUEST = 'unexpected-request'
    POLICY_VIOLATION = 'policy-violation'
    UNKNOWN_ERROR = 'unknown-error'

    def __str__(self):
        return self.value


class BookmarkStoreType(Enum):
    PUBSUB = 'pubsub'
    PRIVATE = 'private'
+2 −2
Changes for nbxmpp/modules/iq.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ from nbxmpp.protocol import Error as ErrorStanza
from nbxmpp.protocol import ERR_BAD_REQUEST
from nbxmpp.protocol import NodeProcessed
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import ErrorProperties
from nbxmpp.util import error_factory
from nbxmpp.const import IqType

log = logging.getLogger('nbxmpp.m.iq')
@@ -57,4 +57,4 @@ class BaseIq:
        properties.query = stanza.getQuery()

        if properties.type.is_error:
            properties.error = ErrorProperties(stanza)
            properties.error = error_factory(stanza)
+2 −2
Changes for nbxmpp/modules/message.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -19,8 +19,8 @@ import logging

from nbxmpp.protocol import NodeProcessed
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import ErrorProperties
from nbxmpp.structs import StanzaIDData
from nbxmpp.util import error_factory
from nbxmpp.const import MessageType

log = logging.getLogger('nbxmpp.m.message')
@@ -50,7 +50,7 @@ class BaseMessage:
            properties.stanza_id = StanzaIDData(id=id_, by=by)

        if properties.type.is_error:
            properties.error = ErrorProperties(stanza)
            properties.error = error_factory(stanza)

    @staticmethod
    def _process_message_after_base(_con, stanza, properties):
+2 −2
Changes for nbxmpp/modules/presence.py: 2 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -21,7 +21,7 @@ from nbxmpp.protocol import Error as ErrorStanza
from nbxmpp.protocol import ERR_BAD_REQUEST
from nbxmpp.protocol import NodeProcessed
from nbxmpp.structs import StanzaHandler
from nbxmpp.structs import ErrorProperties
from nbxmpp.util import error_factory
from nbxmpp.const import PresenceType
from nbxmpp.const import PresenceShow

@@ -46,7 +46,7 @@ class BasePresence:
        properties.status = stanza.getStatus()

        if properties.type.is_error:
            properties.error = ErrorProperties(stanza)
            properties.error = error_factory(stanza)

        own_jid = self._client.get_bound_jid()
        properties.self_presence = own_jid == properties.jid
+0 −18
Changes for nbxmpp/structs.py: 0 added lines, 18 removed lines.
Original line number Diff line number Diff line
@@ -29,7 +29,6 @@ from nbxmpp.const import MessageType
from nbxmpp.const import AvatarState
from nbxmpp.const import StatusCode
from nbxmpp.const import PresenceType
from nbxmpp.const import Error
from nbxmpp.const import LOCATION_DATA
from nbxmpp.const import AdHocStatus

@@ -648,20 +647,3 @@ class PresenceProperties:
            return self.muc_user.role
        except Exception:
            return None


class ErrorProperties:
    def __init__(self, stanza):
        for child in stanza.getTag('error').getChildren():
            if child.getNamespace() == NS_STANZAS:
                try:
                    self.type = Error(child.name)
                except ValueError:
                    self.type = Error('unknown-error')
                break
        self.legacy_code = stanza.getErrorCode()
        self.legacy_type = stanza.getErrorType()
        self.message = stanza.getErrorMsg()

    def __str__(self):
        return '%s %s' % (self.type, self.message)