xep_0317: add initial stanza support for hats
This commit is contained in:
parent
5226858e0c
commit
9266486f46
@ -85,6 +85,7 @@ PLUGINS = [
|
||||
# 'xep_0302', # XMPP Compliance Suites 2012. Don’t automatically load
|
||||
'xep_0308', # Last Message Correction
|
||||
'xep_0313', # Message Archive Management
|
||||
'xep_0317', # Hats
|
||||
'xep_0319', # Last User Interaction in Presence
|
||||
# 'xep_0323', # IoT Systems Sensor Data. Don’t automatically load
|
||||
# 'xep_0325', # IoT Systems Control. Don’t automatically load
|
||||
|
11
slixmpp/plugins/xep_0317/__init__.py
Normal file
11
slixmpp/plugins/xep_0317/__init__.py
Normal file
@ -0,0 +1,11 @@
|
||||
# Slixmpp: The Slick XMPP Library
|
||||
# This file is part of Slixmpp.
|
||||
# See the file LICENSE for copying permission.
|
||||
from slixmpp.plugins import register_plugin
|
||||
from slixmpp.plugins.xep_0317 import stanza
|
||||
from slixmpp.plugins.xep_0317.hats import XEP_0317
|
||||
from slixmpp.plugins.xep_0317.stanza import Hat, Hats
|
||||
|
||||
register_plugin(XEP_0317)
|
||||
|
||||
__all__ = ['stanza', 'XEP_317']
|
20
slixmpp/plugins/xep_0317/hats.py
Normal file
20
slixmpp/plugins/xep_0317/hats.py
Normal file
@ -0,0 +1,20 @@
|
||||
from slixmpp.plugins import BasePlugin
|
||||
from slixmpp import Presence
|
||||
from slixmpp.xmlstream import register_stanza_plugin
|
||||
from . import stanza
|
||||
|
||||
|
||||
class XEP_0317(BasePlugin):
|
||||
"""
|
||||
XEP-0317: Hats
|
||||
"""
|
||||
|
||||
name = 'xep_0317'
|
||||
description = 'XEP-0317: Hats'
|
||||
dependencies = {'xep_0030', 'xep_0050'}
|
||||
stanza = stanza
|
||||
namespace = stanza.NS
|
||||
|
||||
def plugin_init(self):
|
||||
register_stanza_plugin(stanza.Hat, stanza.Hats)
|
||||
register_stanza_plugin(stanza.Hats, Presence)
|
43
slixmpp/plugins/xep_0317/stanza.py
Normal file
43
slixmpp/plugins/xep_0317/stanza.py
Normal file
@ -0,0 +1,43 @@
|
||||
from slixmpp.xmlstream import ElementBase
|
||||
|
||||
NS = 'urn:xmpp:hats:0'
|
||||
|
||||
|
||||
class Hats(ElementBase):
|
||||
"""
|
||||
Hats element, container for multiple hats:
|
||||
|
||||
.. code-block::xml
|
||||
|
||||
|
||||
<hats xmlns='urn:xmpp:hats:0'>
|
||||
<hat title='Host' uri='http://schemas.example.com/hats#host' xml:lang='en-us'>
|
||||
<badge xmlns="urn:example:badges" fgcolor="#000000" bgcolor="#58C5BA"/>
|
||||
</hat>
|
||||
<hat title='Presenter' uri='http://schemas.example.com/hats#presenter' xml:lang='en-us'>
|
||||
<badge xmlns="urn:example:badges" fgcolor="#000000" bgcolor="#EC0524"/>
|
||||
</hat>
|
||||
</hats>
|
||||
|
||||
"""
|
||||
|
||||
name = 'hats'
|
||||
namespace = NS
|
||||
plugin_attrib = 'hats'
|
||||
|
||||
|
||||
class Hat(ElementBase):
|
||||
"""
|
||||
Hat element, has a title and url, may contain arbitrary sub-elements.
|
||||
|
||||
.. code-block::xml
|
||||
|
||||
<hat title='Host' uri='http://schemas.example.com/hats#host' xml:lang='en-us'>
|
||||
<badge xmlns="urn:example:badges" fgcolor="#000000" bgcolor="#58C5BA"/>
|
||||
</hat>
|
||||
|
||||
"""
|
||||
name = 'hat'
|
||||
namespace = NS
|
||||
plugin_attrib = 'hat'
|
||||
interfaces = {'title', 'uri'}
|
31
tests/test_stanza_xep_0317.py
Normal file
31
tests/test_stanza_xep_0317.py
Normal file
@ -0,0 +1,31 @@
|
||||
import unittest
|
||||
from slixmpp import Presence
|
||||
from slixmpp.test import SlixTest
|
||||
import slixmpp.plugins.xep_0317 as xep_0317
|
||||
from slixmpp.xmlstream import register_stanza_plugin
|
||||
|
||||
|
||||
class TestStanzaHats(SlixTest):
|
||||
|
||||
def setUp(self):
|
||||
register_stanza_plugin(Presence, xep_0317.Hats)
|
||||
register_stanza_plugin(xep_0317.Hats, xep_0317.Hats)
|
||||
|
||||
def testCreateHats(self):
|
||||
raw_xml = """
|
||||
<hats xmlns="urn:xmpp:hats:0">
|
||||
<hat uri="http://example.com/hats#Teacher" title="Teacher"/>
|
||||
</hats>
|
||||
"""
|
||||
|
||||
hats = xep_0317.Hats()
|
||||
|
||||
hat = xep_0317.Hat()
|
||||
hat['uri'] = 'http://example.com/hats#Teacher'
|
||||
hat['title'] = 'Teacher'
|
||||
hats.append(hat)
|
||||
|
||||
self.check(hats, raw_xml, use_values=False)
|
||||
|
||||
|
||||
suite = unittest.TestLoader().loadTestsFromTestCase(TestStanzaHats)
|
Loading…
Reference in New Issue
Block a user