예제 #1
0
    def _prepare(self, body, serializer=None,
            content_type=None, content_encoding=None, compression=None,
            headers=None):

        # No content_type? Then we're serializing the data internally.
        if not content_type:
            serializer = serializer or self.serializer
            (content_type, content_encoding,
             body) = encode(body, serializer=serializer)
        else:
            # If the programmer doesn't want us to serialize,
            # make sure content_encoding is set.
            if isinstance(body, unicode):
                if not content_encoding:
                    content_encoding = 'utf-8'
                body = body.encode(content_encoding)

            # If they passed in a string, we can't know anything
            # about it. So assume it's binary data.
            elif not content_encoding:
                content_encoding = 'binary'

        if compression:
            body, headers["compression"] = compress(body, compression)

        return body, content_type, content_encoding
예제 #2
0
    def _prepare(self,
                 body,
                 serializer=None,
                 content_type=None,
                 content_encoding=None,
                 compression=None,
                 headers=None):

        # No content_type? Then we're serializing the data internally.
        if not content_type:
            serializer = serializer or self.serializer
            (content_type, content_encoding,
             body) = encode(body, serializer=serializer)
        else:
            # If the programmer doesn't want us to serialize,
            # make sure content_encoding is set.
            if isinstance(body, unicode):
                if not content_encoding:
                    content_encoding = 'utf-8'
                body = body.encode(content_encoding)

            # If they passed in a string, we can't know anything
            # about it. So assume it's binary data.
            elif not content_encoding:
                content_encoding = 'binary'

        if compression:
            body, headers["compression"] = compress(body, compression)

        return body, content_type, content_encoding
예제 #3
0
 def serialize(self, data):
     """serialize data structure into string"""
     assert self._key is not None
     assert self._cert is not None
     with reraise_errors('Unable to serialize: {0!r}', (Exception, )):
         content_type, content_encoding, body = encode(
                 data, serializer=self._serializer)
         # What we sign is the serialized body, not the body itself.
         # this way the receiver doesn't have to decode the contents
         # to verify the signature (and thus avoiding potential flaws
         # in the decoding step).
         return self._pack(body, content_type, content_encoding,
                           signature=self._key.sign(body, self._digest),
                           signer=self._cert.get_id())
예제 #4
0
 def serialize(self, data):
     """serialize data structure into string"""
     assert self._key is not None
     assert self._cert is not None
     with reraise_errors('Unable to serialize: {0!r}', (Exception, )):
         content_type, content_encoding, body = encode(
                 data, serializer=self._serializer)
         # What we sign is the serialized body, not the body itself.
         # this way the receiver doesn't have to decode the contents
         # to verify the signature (and thus avoiding potential flaws
         # in the decoding step).
         body = ensure_bytes(body)
         return self._pack(body, content_type, content_encoding,
                           signature=self._key.sign(body, self._digest),
                           signer=self._cert.get_id())
예제 #5
0
 def serialize(self, data):
     """serialize data structure into string"""
     assert self._key is not None
     assert self._cert is not None
     try:
         content_type, content_encoding, body = encode(
                 data, serializer=self._serializer)
         # What we sign is the serialized body, not the body itself.
         # this way the receiver doesn't have to decode the contents
         # to verify the signature (and thus avoiding potential flaws
         # in the decoding step).
         return self._pack(body, content_type, content_encoding,
                           signature=self._key.sign(body, self._digest),
                           signer=self._cert.get_id())
     except Exception, exc:
         raise SecurityError, SecurityError(
                 "Unable to serialize: %r" % (exc, )), sys.exc_info()[2]
예제 #6
0
 def serialize(self, data):
     """serialize data structure into string"""
     assert self._key is not None
     assert self._cert is not None
     try:
         content_type, content_encoding, body = encode(
             data, serializer=self._serializer)
         # What we sign is the serialized body, not the body itself.
         # this way the receiver doesn't have to decode the contents
         # to verify the signature (and thus avoiding potential flaws
         # in the decoding step).
         return self._pack(body,
                           content_type,
                           content_encoding,
                           signature=self._key.sign(body, self._digest),
                           signer=self._cert.get_id())
     except Exception, exc:
         raise SecurityError("Unable to serialize: %r" % (exc, ))
예제 #7
0
파일: messaging.py 프로젝트: sebleier/kombu
    def prepare(self, message_data, serializer=None,
            content_type=None, content_encoding=None):
        # No content_type? Then we're serializing the data internally.
        if not content_type:
            serializer = serializer or self.serializer
            (content_type, content_encoding,
             message_data) = serialization.encode(message_data,
                                                  serializer=serializer)
        else:
            # If the programmer doesn't want us to serialize,
            # make sure content_encoding is set.
            if isinstance(message_data, unicode):
                if not content_encoding:
                    content_encoding = 'utf-8'
                message_data = message_data.encode(content_encoding)

            # If they passed in a string, we can't know anything
            # about it.  So assume it's binary data.
            elif not content_encoding:
                content_encoding = 'binary'

        return message_data, content_type, content_encoding
예제 #8
0
파일: base.py 프로젝트: JonPeel/celery
 def encode(self, data):
     _, _, payload = serialization.encode(data, serializer=self.serializer)
     return payload
예제 #9
0
파일: base.py 프로젝트: liushigit/celery
 def encode(self, data):
     _, _, payload = encode(data, serializer=self.serializer)
     return payload