Bump to 1.3.1
[slixmpp.git] / sleekxmpp / plugins / xep_0079 / stanza.py
blobcb6932d67233f008c1ad2cc1792f331c9344b1b7
1 """
2 SleekXMPP: The Sleek XMPP Library
3 Copyright (C) 2013 Nathanael C. Fritz, Lance J.T. Stout
4 This file is part of SleekXMPP.
6 See the file LICENSE for copying permission.
7 """
9 from __future__ import unicode_literals
11 from sleekxmpp.xmlstream import ElementBase, register_stanza_plugin
14 class AMP(ElementBase):
15 namespace = 'http://jabber.org/protocol/amp'
16 name = 'amp'
17 plugin_attrib = 'amp'
18 interfaces = set(['from', 'to', 'status', 'per_hop'])
20 def get_from(self):
21 return JID(self._get_attr('from'))
23 def set_from(self, value):
24 return self._set_attr('from', str(value))
26 def get_to(self):
27 return JID(self._get_attr('from'))
29 def set_to(self, value):
30 return self._set_attr('to', str(value))
32 def get_per_hop(self):
33 return self._get_attr('per-hop') == 'true'
35 def set_per_hop(self, value):
36 if value:
37 return self._set_attr('per-hop', 'true')
38 else:
39 return self._del_attr('per-hop')
41 def del_per_hop(self):
42 return self._del_attr('per-hop')
44 def add_rule(self, action, condition, value):
45 rule = Rule(parent=self)
46 rule['action'] = action
47 rule['condition'] = condition
48 rule['value'] = value
51 class Rule(ElementBase):
52 namespace = 'http://jabber.org/protocol/amp'
53 name = 'rule'
54 plugin_attrib = name
55 plugin_multi_attrib = 'rules'
56 interfaces = set(['action', 'condition', 'value'])
59 class InvalidRules(ElementBase):
60 namespace = 'http://jabber.org/protocol/amp'
61 name = 'invalid-rules'
62 plugin_attrib = 'invalid_rules'
65 class UnsupportedConditions(ElementBase):
66 namespace = 'http://jabber.org/protocol/amp'
67 name = 'unsupported-conditions'
68 plugin_attrib = 'unsupported_conditions'
71 class UnsupportedActions(ElementBase):
72 namespace = 'http://jabber.org/protocol/amp'
73 name = 'unsupported-actions'
74 plugin_attrib = 'unsupported_actions'
77 class FailedRule(Rule):
78 namespace = 'http://jabber.org/protocol/amp#errors'
81 class FailedRules(ElementBase):
82 namespace = 'http://jabber.org/protocol/amp#errors'
83 name = 'failed-rules'
84 plugin_attrib = 'failed_rules'
87 class AMPFeature(ElementBase):
88 namespace = 'http://jabber.org/features/amp'
89 name = 'amp'
92 register_stanza_plugin(AMP, Rule, iterable=True)
93 register_stanza_plugin(InvalidRules, Rule, iterable=True)
94 register_stanza_plugin(UnsupportedConditions, Rule, iterable=True)
95 register_stanza_plugin(UnsupportedActions, Rule, iterable=True)
96 register_stanza_plugin(FailedRules, FailedRule, iterable=True)