Beispiel #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
Beispiel #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
Beispiel #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())
Beispiel #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())
 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]
Beispiel #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, ))
Beispiel #7
0
    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
Beispiel #8
0
 def encode(self, data):
     _, _, payload = serialization.encode(data, serializer=self.serializer)
     return payload
Beispiel #9
0
 def encode(self, data):
     _, _, payload = encode(data, serializer=self.serializer)
     return payload