validata_util.py 1010 Bytes
Newer Older
1 2 3 4 5 6 7 8
""" Call validation code """

import logging
from io import BytesIO

import validata_core
from validata_core.source_helpers import build_tabulator_params

9 10
from .validate_helper import ValidatorHelper

11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39
log = logging.getLogger(__name__)


class ValidataSource():
    """ Handy class to handle different sort of data source """

    def __init__(self, type, name, source):
        """ Initialization """
        self.type = type
        self.name = name
        self.source = source

        info = build_tabulator_params(type, name, source)
        self.source = info.get('source')
        self.format = info.get('format')
        self.scheme = info.get('scheme')

    def get_tabulator_params(self):
        """ Creates source ready to be ingested by tabulator """

        return {'source': self.source, 'format': self.format, 'scheme': self.scheme}


def bytes_data(f):
    """Gets bytes data from Werkzeug FileStorage instance"""
    iob = BytesIO()
    f.save(iob)
    iob.seek(0)
    return iob.getvalue()