Commit d85d8f44 authored by Link Mauve's avatar Link Mauve

Merge branch 'xep-0335' into 'master'

Add xep_0335: JSON Containers

See merge request poezio/slixmpp!5
parents fb75f7cd 31f5e846
"""
Slixmpp: The Slick XMPP Library
Copyright (C) 2018 Maxime “pep” Buquet
This file is part of Slixmpp.
See the file LICENSE for copying permission.
"""
from slixmpp.plugins.base import register_plugin
from slixmpp.plugins.xep_0335.stanza import JSON_Container
from slixmpp.plugins.xep_0335.json_containers import XEP_0335
register_plugin(XEP_0335)
"""
Slixmpp: The Slick XMPP Library
Copyright (C) 2018 Maxime “pep” Buquet
This file is part of Slixmpp.
See the file LICENSE for copying permission.
"""
from slixmpp import Message
from slixmpp.plugins import BasePlugin
from slixmpp.xmlstream import register_stanza_plugin
from slixmpp.plugins.xep_0335 import JSON_Container
class XEP_0335(BasePlugin):
name = 'xep_0335'
description = 'XEP-0335: JSON Containers'
stanza = stanza
def plugin_init(self):
register_stanza_plugin(Message, JSON_Container)
"""
Slixmpp: The Slick XMPP Library
Copyright (C) 2018 Maxime “pep” Buquet
This file is part of Slixmpp.
See the file LICENSE for copying permission.
"""
import json
from slixmpp.xmlstream import ElementBase
class JSON_Container(ElementBase):
name = 'json'
plugin_attrib = 'json'
namespace = 'urn:xmpp:json:0'
interfaces = {'value'}
def get_value(self):
return json.loads(self.xml.text)
def set_value(self, value):
if not isinstance(value, str):
value = json.dumps(value)
self.xml.text = value
def del_value(self):
self.xml.text = ''
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment