Enforce <spam/> and <abuse/> quantity constraints
This commit is contained in:
parent
2e31de3f45
commit
ef961392be
1 changed files with 19 additions and 12 deletions
|
@ -26,6 +26,8 @@ class Report(ElementBase):
|
||||||
abuse -- Flag the report as abuse
|
abuse -- Flag the report as abuse
|
||||||
spam -- Flag the report as spam
|
spam -- Flag the report as spam
|
||||||
text -- Add a reason to the report
|
text -- Add a reason to the report
|
||||||
|
|
||||||
|
Only one <spam/> or <abuse/> element can be present at once.
|
||||||
"""
|
"""
|
||||||
name = "report"
|
name = "report"
|
||||||
namespace = "urn:xmpp:reporting:0"
|
namespace = "urn:xmpp:reporting:0"
|
||||||
|
@ -33,29 +35,34 @@ class Report(ElementBase):
|
||||||
interfaces = ("spam", "abuse", "text")
|
interfaces = ("spam", "abuse", "text")
|
||||||
sub_interfaces = {'text'}
|
sub_interfaces = {'text'}
|
||||||
|
|
||||||
|
def _purge_spam(self):
|
||||||
|
spam = self.xml.findall('{%s}spam' % self.namespace)
|
||||||
|
for element in spam:
|
||||||
|
self.xml.remove(element)
|
||||||
|
|
||||||
|
def _purge_abuse(self):
|
||||||
|
abuse = self.xml.findall('{%s}abuse' % self.namespace)
|
||||||
|
for element in abuse:
|
||||||
|
self.xml.remove(element)
|
||||||
|
|
||||||
def get_spam(self):
|
def get_spam(self):
|
||||||
return self.xml.find('{%s}spam' % self.namespace) is not None
|
return self.xml.find('{%s}spam' % self.namespace) is not None
|
||||||
|
|
||||||
def set_spam(self, value):
|
def set_spam(self, value):
|
||||||
if bool(value) and not self.get_spam():
|
self._purge_spam()
|
||||||
|
if bool(value):
|
||||||
|
self._purge_abuse()
|
||||||
self.xml.append(ET.Element('{%s}spam' % self.namespace))
|
self.xml.append(ET.Element('{%s}spam' % self.namespace))
|
||||||
elif not bool(value):
|
|
||||||
found = self.xml.findall('{%s}spam' % self.namespace)
|
|
||||||
if elm:
|
|
||||||
for item in found:
|
|
||||||
self.xml.remove(item)
|
|
||||||
|
|
||||||
def get_abuse(self):
|
def get_abuse(self):
|
||||||
return self.xml.find('{%s}abuse' % self.namespace) is not None
|
return self.xml.find('{%s}abuse' % self.namespace) is not None
|
||||||
|
|
||||||
def set_abuse(self, value):
|
def set_abuse(self, value):
|
||||||
if bool(value) and not self.get_abuse():
|
self._purge_abuse()
|
||||||
|
if bool(value):
|
||||||
|
self._purge_spam()
|
||||||
self.xml.append(ET.Element('{%s}abuse' % self.namespace))
|
self.xml.append(ET.Element('{%s}abuse' % self.namespace))
|
||||||
elif not bool(value):
|
|
||||||
found = self.xml.findall('{%s}abuse' % self.namespace)
|
|
||||||
if elm:
|
|
||||||
for item in found:
|
|
||||||
self.xml.remove(item)
|
|
||||||
|
|
||||||
class Text(ElementBase):
|
class Text(ElementBase):
|
||||||
name = "text"
|
name = "text"
|
||||||
|
|
Loading…
Reference in a new issue