Exemplo n.º 1
0
    def _json_yaml_convert(self, exclude=[]):
        """
        Helper to convert to a dict before converting to JSON.

        :param exclude: list of fields to exclude.
        :type exclude: list
        :returns: json
        """

        d = self.to_dict(exclude)
        if 'filedata' not in exclude:
            (d['filedata'], ext) = format_file(self.filedata.read(), 'base64')
        return json.dumps(d, default=json_handler)
Exemplo n.º 2
0
    def _json_yaml_convert(self, exclude=[]):
        """
        Helper to convert to a dict before converting to JSON.

        :param exclude: list of fields to exclude.
        :type exclude: list
        :returns: json
        """

        d = self.to_dict(exclude)
        if 'filedata' not in exclude:
            (d['filedata'], ext) = format_file(self.filedata.read(), 'base64')
        return json.dumps(d, default=json_handler)
Exemplo n.º 3
0
    def _format_data(self, filedata, file_format=None):
        """
        Format filedata based on request.

        :param filedata: The filedata to format.
        :type filedata: str
        :param file_format: The format the file should be in:
                            "base64", "zlib", "raw", "invert".
        :type file_format: str
        :returns: list of [<formatted data>, <file extension>]
        """

        if file_format not in ('base64', 'zlib', 'raw', 'invert'):
            file_format = 'raw'
        return format_file(filedata, file_format)[0]
Exemplo n.º 4
0
    def _format_data(self, filedata, file_format=None):
        """
        Format filedata based on request.

        :param filedata: The filedata to format.
        :type filedata: str
        :param file_format: The format the file should be in:
                            "base64", "zlib", "raw", "invert".
        :type file_format: str
        :returns: list of [<formatted data>, <file extension>]
        """

        if file_format not in ('base64', 'zlib', 'raw', 'invert'):
            file_format = 'raw'
        return format_file(filedata, file_format)[0]