summaryrefslogtreecommitdiff
path: root/slixmpp/stanza/error.py
diff options
context:
space:
mode:
Diffstat (limited to 'slixmpp/stanza/error.py')
-rw-r--r--slixmpp/stanza/error.py27
1 files changed, 15 insertions, 12 deletions
diff --git a/slixmpp/stanza/error.py b/slixmpp/stanza/error.py
index 54ace5a8..76c6b9cc 100644
--- a/slixmpp/stanza/error.py
+++ b/slixmpp/stanza/error.py
@@ -1,8 +1,9 @@
-
# Slixmpp: The Slick XMPP Library
# Copyright (C) 2010 Nathanael C. Fritz
# This file is part of Slixmpp.
# See the file LICENSE for copying permission.
+from __future__ import annotations
+from typing import Optional, Dict, Type, ClassVar
from slixmpp.xmlstream import ElementBase, ET
@@ -49,10 +50,10 @@ class Error(ElementBase):
name = 'error'
plugin_attrib = 'error'
interfaces = {'code', 'condition', 'text', 'type',
- 'gone', 'redirect', 'by'}
+ 'gone', 'redirect', 'by'}
sub_interfaces = {'text'}
- plugin_attrib_map = {}
- plugin_tag_map = {}
+ plugin_attrib_map: ClassVar[Dict[str, Type[ElementBase]]] = {}
+ plugin_tag_map: ClassVar[Dict[str, Type[ElementBase]]] = {}
conditions = {'bad-request', 'conflict', 'feature-not-implemented',
'forbidden', 'gone', 'internal-server-error',
'item-not-found', 'jid-malformed', 'not-acceptable',
@@ -62,10 +63,10 @@ class Error(ElementBase):
'remote-server-timeout', 'resource-constraint',
'service-unavailable', 'subscription-required',
'undefined-condition', 'unexpected-request'}
- condition_ns = 'urn:ietf:params:xml:ns:xmpp-stanzas'
+ condition_ns: str = 'urn:ietf:params:xml:ns:xmpp-stanzas'
types = {'cancel', 'continue', 'modify', 'auth', 'wait'}
- def setup(self, xml=None):
+ def setup(self, xml: Optional[ET.Element] = None):
"""
Populate the stanza object using an optional XML object.
@@ -82,9 +83,11 @@ class Error(ElementBase):
self['type'] = 'cancel'
self['condition'] = 'feature-not-implemented'
if self.parent is not None:
- self.parent()['type'] = 'error'
+ parent = self.parent()
+ if parent:
+ parent['type'] = 'error'
- def get_condition(self):
+ def get_condition(self) -> str:
"""Return the condition element's name."""
for child in self.xml:
if "{%s}" % self.condition_ns in child.tag:
@@ -93,7 +96,7 @@ class Error(ElementBase):
return cond
return ''
- def set_condition(self, value):
+ def set_condition(self, value: str) -> Error:
"""
Set the tag name of the condition element.
@@ -105,7 +108,7 @@ class Error(ElementBase):
self.xml.append(ET.Element("{%s}%s" % (self.condition_ns, value)))
return self
- def del_condition(self):
+ def del_condition(self) -> Error:
"""Remove the condition element."""
for child in self.xml:
if "{%s}" % self.condition_ns in child.tag:
@@ -139,14 +142,14 @@ class Error(ElementBase):
def get_redirect(self):
return self._get_sub_text('{%s}redirect' % self.condition_ns, '')
- def set_gone(self, value):
+ def set_gone(self, value: str):
if value:
del self['condition']
return self._set_sub_text('{%s}gone' % self.condition_ns, value)
elif self['condition'] == 'gone':
del self['condition']
- def set_redirect(self, value):
+ def set_redirect(self, value: str):
if value:
del self['condition']
ns = self.condition_ns