Revision 633566303164 () - Diff

Link to this snippet: https://friendpaste.com/5OGWZfDN96mjkqrhzAOnLK
Embed:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# Imagine this one script

"""
<iq type='set' to= 'roomname@conference.chat.oonair.net' id='id1'>
<oo xmlns='http://oonair.com/muc#share'>
<item name='Falda tubo' thumbnail='http://webpage.info/falda_tn.jpg' id='itemid1' action='add' url='http://webpage.info/f
<metadata path=' ' />
</item>
</oo>
</iq>
"""

class Item(ElementBase):
name = 'item'
namespace = 'http://oonair.com/muc#share'
plugin_attrib = 'item'

# Using this will allow for `iq['oo']['items']` to return a list of the child
# Item stanzas. Defining this field is typically a good idea if the stanza
# will be registered with iterable=True
plugin_multi_attrib = 'items'

interfaces = set(('name', 'thumbnail', 'id', 'action', 'url', 'metadata'))


# You had 'metadata' as a subinterface, which would produce results like:
# <item ...>
# <metadata>foo</metadata>
# </item>
#
# If you only want to manipulate the path attribute, below is how you
# would do that.

def get_metadata(self):
meta = self.xml.find('{%s}metadata' % self.namespace)
if meta is not None:
return meta.attrib.get('path', '')
return path

def set_metadata(self, value):
self.del_metadata()
if value:
meta = ET.Element('{%s}metadata' % self.namepace)
meta.attrib['path'] = value
self.xml.append(meta)

def del_metadata(self):
meta = self.xml.find('{%s}metadata' % self.namespace)
if meta is not None:
self.xml.remove(meta)


class OO(ElementBase):
name = 'oo'
namespace = 'http://oonair.com/muc#share'
plugin_attrib = 'oo_muc_share'
interfaces = set()

# You included 'items' as both an interface and subinterface. However,
# because that is the same as the plugin_attrib for your Item stanza,
# the two conflict with each other. Plugins are given lower priority
# than interfaces defined by the parent stanza. Stanzas should only
# list interfaces that they are explicitly providing themselves, not
# what is also expected to be available through plugins.


# And this one will be going in the xmpp client script

# Registering stanza plugins only occurs between two stanzas at a time, you were trying to use three at once.
# The first stanza is the parent, and the second is the child plugin.
register_stanza_plugin(Iq, OO)
register_stanza_plugin(OO, Item, iterable=True)