2012-02-02 13:29:27 +00:00
|
|
|
"""
|
|
|
|
SleekXMPP: The Sleek XMPP Library
|
2012-02-03 14:17:01 +00:00
|
|
|
Copyright (C) 2012 Erik Reuterborg Larsson, Nathanael C. Fritz
|
2012-02-02 13:29:27 +00:00
|
|
|
This file is part of SleekXMPP.
|
|
|
|
|
|
|
|
See the file LICENSE for copying permission.
|
|
|
|
"""
|
|
|
|
|
|
|
|
from sleekxmpp.xmlstream.stanzabase import ElementBase, ET
|
|
|
|
|
|
|
|
|
|
|
|
class Request(ElementBase):
|
|
|
|
namespace = 'urn:xmpp:receipts'
|
|
|
|
name = 'request'
|
2012-03-16 17:51:25 +00:00
|
|
|
plugin_attrib = 'request_receipt'
|
|
|
|
interfaces = set(('request_receipt',))
|
|
|
|
sub_interfaces = interfaces
|
2012-02-02 13:29:27 +00:00
|
|
|
is_extension = True
|
|
|
|
|
|
|
|
def setup(self, xml=None):
|
|
|
|
self.xml = ET.Element('')
|
|
|
|
return True
|
|
|
|
|
2012-03-16 17:51:25 +00:00
|
|
|
def set_request_receipt(self, val):
|
|
|
|
self.del_request_receipt()
|
2012-02-02 13:29:27 +00:00
|
|
|
if val:
|
2012-03-16 17:51:25 +00:00
|
|
|
parent = self.parent()
|
|
|
|
parent._set_sub_text("{%s}request" % self.namespace, keep=True)
|
2012-03-17 05:01:56 +00:00
|
|
|
if not parent['id']:
|
2012-03-17 06:42:55 +00:00
|
|
|
if parent.stream:
|
|
|
|
parent['id'] = parent.stream.new_id()
|
2012-02-02 13:29:27 +00:00
|
|
|
|
2012-03-16 17:51:25 +00:00
|
|
|
def get_request_receipt(self):
|
2012-02-02 13:29:27 +00:00
|
|
|
parent = self.parent()
|
2012-03-16 17:51:25 +00:00
|
|
|
if parent.find("{%s}request" % self.namespace) is not None:
|
2012-02-02 13:29:27 +00:00
|
|
|
return True
|
|
|
|
else:
|
|
|
|
return False
|
|
|
|
|
2012-03-16 17:51:25 +00:00
|
|
|
def del_request_receipt(self):
|
|
|
|
self.parent()._del_sub("{%s}request" % self.namespace)
|
2012-02-02 13:29:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Received(ElementBase):
|
|
|
|
namespace = 'urn:xmpp:receipts'
|
|
|
|
name = 'received'
|
2012-03-16 17:51:25 +00:00
|
|
|
plugin_attrib = 'receipt'
|
|
|
|
interfaces = set(['receipt'])
|
|
|
|
sub_interfaces = interfaces
|
|
|
|
is_extension = True
|
|
|
|
|
|
|
|
def setup(self, xml=None):
|
|
|
|
self.xml = ET.Element('')
|
|
|
|
return True
|
|
|
|
|
|
|
|
def set_receipt(self, value):
|
|
|
|
self.del_receipt()
|
|
|
|
if value:
|
|
|
|
parent = self.parent()
|
|
|
|
xml = ET.Element("{%s}received" % self.namespace)
|
|
|
|
xml.attrib['id'] = value
|
|
|
|
parent.append(xml)
|
|
|
|
|
|
|
|
def get_receipt(self):
|
|
|
|
parent = self.parent()
|
|
|
|
xml = parent.find("{%s}received" % self.namespace)
|
|
|
|
if xml is not None:
|
|
|
|
return xml.attrib.get('id', '')
|
|
|
|
return ''
|
|
|
|
|
|
|
|
def del_receipt(self):
|
|
|
|
self.parent()._del_sub('{%s}received' % self.namespace)
|