2012-02-02 17:27:23 +00:00
|
|
|
import re
|
|
|
|
import base64
|
|
|
|
|
|
|
|
from sleekxmpp.exceptions import XMPPError
|
2012-03-12 04:15:01 +00:00
|
|
|
from sleekxmpp.xmlstream import ElementBase
|
2012-02-02 17:27:23 +00:00
|
|
|
from sleekxmpp.thirdparty.suelta.util import bytes
|
|
|
|
|
|
|
|
|
|
|
|
VALID_B64 = re.compile(r'[A-Za-z0-9\+\/]*=*')
|
|
|
|
|
|
|
|
|
|
|
|
def to_b64(data):
|
|
|
|
return bytes(base64.b64encode(bytes(data))).decode('utf-8')
|
|
|
|
|
2012-03-12 04:15:01 +00:00
|
|
|
|
2012-02-02 17:27:23 +00:00
|
|
|
def from_b64(data):
|
|
|
|
return bytes(base64.b64decode(bytes(data))).decode('utf-8')
|
|
|
|
|
|
|
|
|
|
|
|
class Open(ElementBase):
|
|
|
|
name = 'open'
|
|
|
|
namespace = 'http://jabber.org/protocol/ibb'
|
|
|
|
plugin_attrib = 'ibb_open'
|
|
|
|
interfaces = set(('block_size', 'sid', 'stanza'))
|
|
|
|
|
|
|
|
def get_block_size(self):
|
|
|
|
return int(self._get_attr('block-size'))
|
|
|
|
|
|
|
|
def set_block_size(self, value):
|
|
|
|
self._set_attr('block-size', str(value))
|
|
|
|
|
|
|
|
def del_block_size(self):
|
|
|
|
self._del_attr('block-size')
|
|
|
|
|
|
|
|
|
|
|
|
class Data(ElementBase):
|
|
|
|
name = 'data'
|
|
|
|
namespace = 'http://jabber.org/protocol/ibb'
|
|
|
|
plugin_attrib = 'ibb_data'
|
|
|
|
interfaces = set(('seq', 'sid', 'data'))
|
|
|
|
sub_interfaces = set(['data'])
|
|
|
|
|
|
|
|
def get_seq(self):
|
|
|
|
return int(self._get_attr('seq', '0'))
|
|
|
|
|
|
|
|
def set_seq(self, value):
|
|
|
|
self._set_attr('seq', str(value))
|
|
|
|
|
|
|
|
def get_data(self):
|
2012-02-03 15:29:38 +00:00
|
|
|
b64_data = self.xml.text.strip()
|
2012-02-02 17:27:23 +00:00
|
|
|
if VALID_B64.match(b64_data).group() == b64_data:
|
|
|
|
return from_b64(b64_data)
|
|
|
|
else:
|
|
|
|
raise XMPPError('not-acceptable')
|
|
|
|
|
|
|
|
def set_data(self, value):
|
2012-02-03 15:03:46 +00:00
|
|
|
self.xml.text = to_b64(value)
|
2012-02-02 18:19:50 +00:00
|
|
|
|
|
|
|
def del_data(self):
|
|
|
|
self.xml.text = ''
|
2012-02-02 17:27:23 +00:00
|
|
|
|
|
|
|
|
|
|
|
class Close(ElementBase):
|
|
|
|
name = 'close'
|
|
|
|
namespace = 'http://jabber.org/protocol/ibb'
|
|
|
|
plugin_attrib = 'ibb_close'
|
|
|
|
interfaces = set(['sid'])
|