stanza: fix a bunch of type errors
This commit is contained in:
parent
0971bab30a
commit
af958fd1fe
6 changed files with 25 additions and 17 deletions
|
@ -3,7 +3,7 @@
|
|||
# This file is part of Slixmpp.
|
||||
# See the file LICENSE for copying permission.
|
||||
from __future__ import annotations
|
||||
from typing import Optional
|
||||
from typing import Optional, Dict, Type, ClassVar
|
||||
from slixmpp.xmlstream import ElementBase, ET
|
||||
|
||||
|
||||
|
@ -50,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',
|
||||
|
@ -66,7 +66,7 @@ class Error(ElementBase):
|
|||
condition_ns: str = 'urn:ietf:params:xml:ns:xmpp-stanzas'
|
||||
types = {'cancel', 'continue', 'modify', 'auth', 'wait'}
|
||||
|
||||
def setup(self, xml: Optional[ET.Element]=None):
|
||||
def setup(self, xml: Optional[ET.Element] = None):
|
||||
"""
|
||||
Populate the stanza object using an optional XML object.
|
||||
|
||||
|
@ -83,7 +83,9 @@ 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) -> str:
|
||||
"""Return the condition element's name."""
|
||||
|
@ -106,7 +108,7 @@ class Error(ElementBase):
|
|||
self.xml.append(ET.Element("{%s}%s" % (self.condition_ns, value)))
|
||||
return self
|
||||
|
||||
def del_condition(self) -> None:
|
||||
def del_condition(self) -> Error:
|
||||
"""Remove the condition element."""
|
||||
for child in self.xml:
|
||||
if "{%s}" % self.condition_ns in child.tag:
|
||||
|
|
|
@ -4,6 +4,7 @@
|
|||
# See the file LICENSE for copying permission.
|
||||
|
||||
from slixmpp.xmlstream import StanzaBase
|
||||
from typing import Optional
|
||||
|
||||
|
||||
class Handshake(StanzaBase):
|
||||
|
@ -18,7 +19,7 @@ class Handshake(StanzaBase):
|
|||
def set_value(self, value: str):
|
||||
self.xml.text = value
|
||||
|
||||
def get_value(self) -> str:
|
||||
def get_value(self) -> Optional[str]:
|
||||
return self.xml.text
|
||||
|
||||
def del_value(self):
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
# See the file LICENSE for copying permission.
|
||||
from slixmpp.stanza.rootstanza import RootStanza
|
||||
from slixmpp.xmlstream import StanzaBase, ET
|
||||
from slixmpp.basexmpp import BaseXMPP
|
||||
|
||||
|
||||
ORIGIN_NAME = '{urn:xmpp:sid:0}origin-id'
|
||||
|
@ -61,7 +62,7 @@ class Message(RootStanza):
|
|||
"""
|
||||
StanzaBase.__init__(self, *args, **kwargs)
|
||||
if not recv and self['id'] == '':
|
||||
if self.stream is not None and self.stream.use_message_ids:
|
||||
if isinstance(self.stream, BaseXMPP) and self.stream.use_message_ids:
|
||||
self['id'] = self.stream.new_id()
|
||||
else:
|
||||
del self['origin_id']
|
||||
|
@ -93,7 +94,7 @@ class Message(RootStanza):
|
|||
|
||||
self.xml.attrib['id'] = value
|
||||
|
||||
if self.stream and not self.stream.use_origin_id:
|
||||
if isinstance(self.stream, BaseXMPP) and not self.stream.use_origin_id:
|
||||
return None
|
||||
|
||||
sub = self.xml.find(ORIGIN_NAME)
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
# See the file LICENSE for copying permission.
|
||||
from slixmpp.stanza.rootstanza import RootStanza
|
||||
from slixmpp.xmlstream import StanzaBase
|
||||
from slixmpp.basexmpp import BaseXMPP
|
||||
|
||||
|
||||
class Presence(RootStanza):
|
||||
|
@ -69,7 +70,7 @@ class Presence(RootStanza):
|
|||
"""
|
||||
StanzaBase.__init__(self, *args, **kwargs)
|
||||
if not recv and self['id'] == '':
|
||||
if self.stream is not None and self.stream.use_presence_ids:
|
||||
if isinstance(self.stream, BaseXMPP) and self.stream.use_presence_ids:
|
||||
self['id'] = self.stream.new_id()
|
||||
|
||||
def set_show(self, show: str):
|
||||
|
|
|
@ -4,7 +4,8 @@
|
|||
# This file is part of Slixmpp.
|
||||
# See the file LICENSE for copying permission.
|
||||
from slixmpp.stanza.error import Error
|
||||
from slixmpp.xmlstream import StanzaBase
|
||||
from slixmpp.xmlstream import StanzaBase, ET
|
||||
from typing import Optional, Dict, Union
|
||||
|
||||
|
||||
class StreamError(Error, StanzaBase):
|
||||
|
@ -64,17 +65,18 @@ class StreamError(Error, StanzaBase):
|
|||
'unsupported-version'}
|
||||
condition_ns: str = 'urn:ietf:params:xml:ns:xmpp-streams'
|
||||
|
||||
def get_see_other_host(self) -> str:
|
||||
def get_see_other_host(self) -> Union[str, Dict[str, str]]:
|
||||
ns = self.condition_ns
|
||||
return self._get_sub_text('{%s}see-other-host' % ns, '')
|
||||
|
||||
def set_see_other_host(self, value: str) -> None:
|
||||
def set_see_other_host(self, value: str) -> Optional[ET.Element]:
|
||||
if value:
|
||||
del self['condition']
|
||||
ns = self.condition_ns
|
||||
return self._set_sub_text('{%s}see-other-host' % ns, value)
|
||||
elif self['condition'] == 'see-other-host':
|
||||
del self['condition']
|
||||
return None
|
||||
|
||||
def del_see_other_host(self) -> None:
|
||||
self._del_sub('{%s}see-other-host' % self.condition_ns)
|
||||
|
|
|
@ -3,7 +3,8 @@
|
|||
# Copyright (C) 2010 Nathanael C. Fritz
|
||||
# This file is part of Slixmpp.
|
||||
# See the file LICENSE for copying permission.
|
||||
from slixmpp.xmlstream import StanzaBase
|
||||
from slixmpp.xmlstream import StanzaBase, ElementBase
|
||||
from typing import ClassVar, Dict, Type
|
||||
|
||||
|
||||
class StreamFeatures(StanzaBase):
|
||||
|
@ -15,8 +16,8 @@ class StreamFeatures(StanzaBase):
|
|||
namespace = 'http://etherx.jabber.org/streams'
|
||||
interfaces = {'features', 'required', 'optional'}
|
||||
sub_interfaces = interfaces
|
||||
plugin_tag_map = {}
|
||||
plugin_attrib_map = {}
|
||||
plugin_attrib_map: ClassVar[Dict[str, Type[ElementBase]]] = {}
|
||||
plugin_tag_map: ClassVar[Dict[str, Type[ElementBase]]] = {}
|
||||
|
||||
def setup(self, xml):
|
||||
StanzaBase.setup(self, xml)
|
||||
|
|
Loading…
Reference in a new issue