summaryrefslogtreecommitdiff
path: root/slixmpp/plugins/xep_0335/stanza.py
blob: 6d5ca5b5e17d4b2f8e63606cee05e75f6624497c (plain)
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
"""
    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 = ''