Update XEP-0085 plugin to work with both ElementTree and cElementTree
Each state element must have its own stanza class now. A stanza class with an empty name field causes errors in ElementTree, even though it works fine with cElementTree.
This commit is contained in:
parent
ecd6ad6930
commit
e3d596c9fa
3 changed files with 30 additions and 2 deletions
|
@ -37,7 +37,11 @@ class xep_0085(base_plugin):
|
|||
StanzaPath('message@chat_state=%s' % state),
|
||||
self._handle_chat_state))
|
||||
|
||||
register_stanza_plugin(Message, ChatState)
|
||||
register_stanza_plugin(Message, stanza.Active)
|
||||
register_stanza_plugin(Message, stanza.Composing)
|
||||
register_stanza_plugin(Message, stanza.Gone)
|
||||
register_stanza_plugin(Message, stanza.Inactive)
|
||||
register_stanza_plugin(Message, stanza.Paused)
|
||||
|
||||
def post_init(self):
|
||||
base_plugin.post_init(self)
|
||||
|
|
|
@ -71,3 +71,23 @@ class ChatState(ElementBase):
|
|||
if state_xml is not None:
|
||||
self.xml = ET.Element('')
|
||||
parent.xml.remove(state_xml)
|
||||
|
||||
|
||||
class Active(ChatState):
|
||||
name = 'active'
|
||||
|
||||
|
||||
class Composing(ChatState):
|
||||
name = 'composing'
|
||||
|
||||
|
||||
class Gone(ChatState):
|
||||
name = 'gone'
|
||||
|
||||
|
||||
class Inactive(ChatState):
|
||||
name = 'inactive'
|
||||
|
||||
|
||||
class Paused(ChatState):
|
||||
name = 'paused'
|
||||
|
|
|
@ -4,7 +4,11 @@ import sleekxmpp.plugins.xep_0085 as xep_0085
|
|||
class TestChatStates(SleekTest):
|
||||
|
||||
def setUp(self):
|
||||
register_stanza_plugin(Message, xep_0085.ChatState)
|
||||
register_stanza_plugin(Message, xep_0085.stanza.Active)
|
||||
register_stanza_plugin(Message, xep_0085.stanza.Composing)
|
||||
register_stanza_plugin(Message, xep_0085.stanza.Gone)
|
||||
register_stanza_plugin(Message, xep_0085.stanza.Inactive)
|
||||
register_stanza_plugin(Message, xep_0085.stanza.Paused)
|
||||
|
||||
def testCreateChatState(self):
|
||||
"""Testing creating chat states."""
|
||||
|
|
Loading…
Reference in a new issue