summaryrefslogtreecommitdiff
path: root/sleekxmpp/plugins/xep_0084
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp/plugins/xep_0084')
-rw-r--r--sleekxmpp/plugins/xep_0084/avatar.py19
-rw-r--r--sleekxmpp/plugins/xep_0084/stanza.py11
2 files changed, 19 insertions, 11 deletions
diff --git a/sleekxmpp/plugins/xep_0084/avatar.py b/sleekxmpp/plugins/xep_0084/avatar.py
index bbac330a..677a888d 100644
--- a/sleekxmpp/plugins/xep_0084/avatar.py
+++ b/sleekxmpp/plugins/xep_0084/avatar.py
@@ -41,6 +41,9 @@ class XEP_0084(BasePlugin):
def session_bind(self, jid):
self.xmpp['xep_0163'].register_pep('avatar_metadata', MetaData)
+ def generate_id(self, data):
+ return hashlib.sha1(data).hexdigest()
+
def retrieve_avatar(self, jid, id, url=None, ifrom=None, block=True,
callback=None, timeout=None):
return self.xmpp['xep_0060'].get_item(jid, Data.namespace, id,
@@ -54,8 +57,7 @@ class XEP_0084(BasePlugin):
payload = Data()
payload['value'] = data
return self.xmpp['xep_0163'].publish(payload,
- node=Data.namespace,
- id=hashlib.sha1(data).hexdigest(),
+ id=self.generate_id(data),
ifrom=ifrom,
block=block,
callback=callback,
@@ -67,17 +69,20 @@ class XEP_0084(BasePlugin):
metadata = MetaData()
if items is None:
items = []
+ if not isinstance(items, (list, set)):
+ items = [items]
for info in items:
metadata.add_info(info['id'], info['type'], info['bytes'],
height=info.get('height', ''),
width=info.get('width', ''),
url=info.get('url', ''))
- for pointer in pointers:
- metadata.add_pointer(pointer)
- return self.xmpp['xep_0163'].publish(payload,
- node=Data.namespace,
- id=hashlib.sha1(data).hexdigest(),
+ if pointers is not None:
+ for pointer in pointers:
+ metadata.add_pointer(pointer)
+
+ return self.xmpp['xep_0163'].publish(metadata,
+ id=info['id'],
ifrom=ifrom,
block=block,
callback=callback,
diff --git a/sleekxmpp/plugins/xep_0084/stanza.py b/sleekxmpp/plugins/xep_0084/stanza.py
index 1b204471..fd21e6f1 100644
--- a/sleekxmpp/plugins/xep_0084/stanza.py
+++ b/sleekxmpp/plugins/xep_0084/stanza.py
@@ -7,8 +7,8 @@
"""
from base64 import b64encode, b64decode
-from sleekxmpp.thirdparty.suelta.util import bytes
+from sleekxmpp.util import bytes as sbytes
from sleekxmpp.xmlstream import ET, ElementBase, register_stanza_plugin
@@ -20,12 +20,15 @@ class Data(ElementBase):
def get_value(self):
if self.xml.text:
- return b64decode(bytes(self.xml.text))
+ return b64decode(sbytes(self.xml.text))
return ''
def set_value(self, value):
if value:
- self.xml.text = b64encode(bytes(value))
+ self.xml.text = b64encode(sbytes(value))
+ # Python3 base64 encoded is bytes and needs to be decoded to string
+ if isinstance(self.xml.text, bytes):
+ self.xml.text = self.xml.text.decode()
else:
self.xml.text = ''
@@ -43,7 +46,7 @@ class MetaData(ElementBase):
info = Info()
info.values = {'id': id,
'type': itype,
- 'bytes': ibytes,
+ 'bytes': '%s' % ibytes,
'height': height,
'width': width,
'url': url}