Commit d56945cc authored by Philipp Hörist's avatar Philipp Hörist

Use error_factory() everywhere

parent 2f4a79e0
......@@ -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'
......
......@@ -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)
......@@ -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):
......
......@@ -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
......
......@@ -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)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment