Serialize a python data type for transmission or storage.

		:param data: The python object to serialize.
		:return: The serialized representation of the object.
		:rtype: bytes
967019
def dumps(self, data):
		
		data = g_serializer_drivers[self.name]['dumps'](data)
		if sys.version_info[0] == 3 and isinstance(data, str):
			data = data.encode(self._charset)
		if self._compression == 'zlib':
			data = zlib.compress(data)
		assert isinstance(data, bytes)
		return data
819971
def json_dumps(self, data):
        
        return json.dumps(
            data, 
            separators=(',', ':'), 
            sort_keys=True, 
            cls=self.json_encoder, 
            ensure_ascii=False
        ).encode('utf8')
1213682
def unpack(cls, data):
        
        header, data = APPHeader.unpack(data)

        if len(data) < header.payload_length:
            raise ProtocolViolation("Payload too small")
        payload = data[:header.payload_length]
        body = cls()
        body._header = header
        body._payload = payload
        return body, data[header.payload_length:]
794670
def decode_base64(data: str) -> bytes:
    
    missing_padding = len(data) % 4
    if missing_padding != 0:
        data += "=" * (4 - missing_padding)
    return base64.decodebytes(data.encode("utf-8"))
826234
def decode(data, encoding='utf-8', errors='strict'):
    
    data_type = type(data)

    if data_type == bytes:
        return bytes2unicode(data, encoding, errors)
    if data_type in (dict, list, tuple):
        if data_type == dict:
            data = data.items()
        return data_type(map(decode, data))
    return data
1296491
def serialize(self, data):
        

        super(Serializer, self).serialize(data)
        self.resp.body = json.dumps(data)
1003085
def serialize(self) -> dict:
        
        data = {**self}
        if "attachments" in self:
            data["attachments"] = json.dumps(self["attachments"])
        return data
352918
def serialize(self, data):
        

        super(Serializer, self).serialize(data)

        self.resp.content_type += '; header=present'
        import pprint
        pprint.PrettyPrinter().pprint(data)
926516
def write(self, data):
        

        if not data:
            return None

        self.buffer += data
        self.do_write()

        return len(data)
602187
def send_data(self, data):
        ''' 
        '''
        for frontend_data in data:
            serialized_data = self.serialize_data(frontend_data)
            if sys.version_info >= (3, 0):
                serialized_data = serialized_data.encode('utf-8')
            for actual_backend in self.backends:
                actual_backend[1].send(serialized_data)
248993
def import_data(self, data):
        
        if self.get_read_only() and self.is_locked():
            return

        if isinstance(data, BaseModel):
            data = data.export_data()

        if not isinstance(data, (dict, Mapping)):
            raise TypeError('Impossible to import data')

        self._import_data(data)
1210189
def data(self):
        
        if self._data_type == int:
            if self._pb.HasField("int64_data"):
                return self._pb.int64_data
            if self._pb.HasField("int32_data"):
                return self._pb.int32_data
            if self._pb.HasField("uint64_data"):
                return self._pb.uint64_data
            if self._pb.HasField("uint32_data"):
                return self._pb.uint32_data
        elif self._data_type == float:
            if self._pb.HasField("float32_data"):
                return self._pb.float32_data
            if self._pb.HasField("float64_data"):
                return self._pb.float64_data
        elif self._data_type == str:
            return self._pb.string_data
        elif self._data_type == bool:
            return self._pb.bool_data
        elif self._data_type == bytes:
            return self._pb.bytes_data
        return None
1033951
def serialize(self):
        

        self.data = bytearray()
        r = self.protocols[::-1]
        for i, p in enumerate(r):
            if isinstance(p, packet_base.PacketBase):
                if i == len(r) - 1:
                    prev = None
                else:
                    prev = r[i + 1]
                data = p.serialize(self.data, prev)
            else:
                data = six.binary_type(p)
            self.data = bytearray(data + self.data)
1208967
def loads(self, data):
        
        st = BytesIO(data)
        try:
            return self.load(st)
        finally:
            st.close()
1058175
def encode_safely(self, data):
        
        
        encoder = self.base_encoder
        result = settings.null

        try:
            result = encoder(pickle.dumps(data))
        except:
            warnings.warn("Data could not be serialized.", RuntimeWarning)
        return result
713746
def data_to_unicode(self, data):
        
        if isinstance(data, dict):
            return {self.to_unicode(k): self.to_unicode(v) for k, v in data.iteritems()}
        if isinstance(data, list):
            return [self.to_unicode(l) for l in data]
        else:
            return self.to_unicode(data)
266428
def _pure_data(self, data: Any) -> Any:
        
        if not isinstance(data, dict) and not isinstance(data, list):
            try:
                return dict(data)
            except TypeError:
                ...
        return data