async def get_image_bytes(self): if self._image_bytes is not None: return self._image_bytes logger.debug("retrieving vCard %s", self._remote_jid) vcard = await self._vcard.get_vcard(self._remote_jid) photo = vcard.get_photo_data() if photo is None: raise RuntimeError("Avatar image is not set") logger.debug("returning vCard avatar %s", self._remote_jid) return photo
def get_image_bytes(self): if self._image_bytes is not None: return self._image_bytes logger.debug("retrieving vCard %s", self._remote_jid) vcard = yield from self._vcard.get_vcard(self._remote_jid) photo = vcard.get_photo_data() if photo is None: raise RuntimeError("Avatar image is not set") logger.debug("returning vCard avatar %s", self._remote_jid) return photo
async def _calculate_vcard_id(self): self.logger.debug("updating vcard hash") vcard = await self._vcard.get_vcard() self.logger.debug("got vcard for hash update: %s", vcard) photo = vcard.get_photo_data() # if no photo is set in the vcard, set an empty <photo> element # in the update; according to the spec this means the avatar # is disabled if photo is None: self.logger.debug("no photo in vcard, advertising as such") return "" sha1 = hashlib.sha1() sha1.update(photo) new_hash = sha1.hexdigest().lower() self.logger.debug("updated hash to %s", new_hash) return new_hash
def _calculate_vcard_id(self): self.logger.debug("updating vcard hash") vcard = yield from self._vcard.get_vcard() self.logger.debug("got vcard for hash update: %s", vcard) photo = vcard.get_photo_data() # if no photo is set in the vcard, set an empty <photo> element # in the update; according to the spec this means the avatar # is disabled if photo is None: self.logger.debug("no photo in vcard, advertising as such") return "" sha1 = hashlib.sha1() sha1.update(photo) new_hash = sha1.hexdigest().lower() self.logger.debug("updated hash to %s", new_hash) return new_hash
def _get_avatar_metadata_vcard(self, jid): logger.debug("trying vCard avatar as fallback for %s", jid) vcard = yield from self._vcard.get_vcard(jid) photo = vcard.get_photo_data() mime_type = vcard.get_photo_mime_type() if photo is None: return [] logger.debug("success vCard avatar as fallback for %s", jid) sha1 = hashlib.sha1() sha1.update(photo) return [VCardAvatarDescriptor( remote_jid=jid, id_=sha1.hexdigest(), mime_type=mime_type, nbytes=len(photo), vcard=self._vcard, image_bytes=photo, )]
async def _get_avatar_metadata_vcard(self, jid): logger.debug("trying vCard avatar as fallback for %s", jid) vcard = await self._vcard.get_vcard(jid) photo = vcard.get_photo_data() mime_type = vcard.get_photo_mime_type() if photo is None: return [] logger.debug("success vCard avatar as fallback for %s", jid) sha1 = hashlib.sha1() sha1.update(photo) return [ VCardAvatarDescriptor( remote_jid=jid, id_=sha1.hexdigest(), mime_type=mime_type, nbytes=len(photo), vcard=self._vcard, image_bytes=photo, ) ]