예제 #1
0
 def __init__(self,
              content: Optional[dict] = None,
              filename: Optional[str] = None,
              data: Optional[bytes] = None,
              thumbnail: Optional[bytes] = None):
     super().__init__(content,
                      ContentType.IMAGE,
                      filename=filename,
                      data=data)
     self.__thumbnail = thumbnail
     if thumbnail is not None:
         self['thumbnail'] = base64_encode(data=thumbnail)
예제 #2
0
 def __init__(self,
              content: Optional[dict] = None,
              filename: Optional[str] = None,
              data: Optional[bytes] = None,
              snapshot: Optional[bytes] = None):
     super().__init__(content,
                      ContentType.VIDEO,
                      filename=filename,
                      data=data)
     self.__snapshot = snapshot
     if snapshot is not None:
         self['snapshot'] = base64_encode(data=snapshot)
예제 #3
0
 def __init__(self,
              content: Optional[dict] = None,
              content_type: Union[ContentType, int] = 0,
              filename: Optional[str] = None,
              data: Optional[bytes] = None):
     if content is None:
         if content_type == 0:
             content_type = ContentType.FILE
         super().__init__(content_type=content_type)
     else:
         super().__init__(content=content)
     self.__attachment = data  # attachment (file data)
     self.__password = None  # symmetric key for decryption
     # set values to inner dictionary
     if filename is not None:
         self['filename'] = filename
     if data is not None:
         self['data'] = base64_encode(data=data)
예제 #4
0
 def snapshot(self, small_image: bytes):
     self.__snapshot = small_image
     if small_image is None:
         self.pop('snapshot', None)
     else:
         self['snapshot'] = base64_encode(small_image)
예제 #5
0
 def thumbnail(self, small_image: bytes):
     self.__thumbnail = small_image
     if small_image is None:
         self.pop('thumbnail', None)
     else:
         self['thumbnail'] = base64_encode(small_image)
예제 #6
0
 def data(self, attachment: bytes):
     self.__attachment = attachment
     if attachment is None:
         self.pop('data', None)
     else:
         self['data'] = base64_encode(attachment)
예제 #7
0
 def encode_signature(self, signature: bytes, msg: SecureMessage) -> str:
     return base64_encode(data=signature)
예제 #8
0
 def encode_key(self, data: bytes, msg: InstantMessage) -> str:
     assert not is_broadcast(
         msg=msg), 'broadcast message has no key: %s' % msg
     return base64_encode(data=data)
예제 #9
0
 def encode_data(self, data: bytes, msg: InstantMessage) -> str:
     if is_broadcast(msg=msg):
         # broadcast message content will not be encrypted (just encoded to JsON),
         # so no need to encode to Base64 here
         return utf8_decode(data=data)
     return base64_encode(data=data)