Commit d233b545 authored by Christophe Benz's avatar Christophe Benz
Browse files

Internalize BytesLoader in validate function

parent dc3a251a
......@@ -3,7 +3,6 @@ from io import BytesIO
from openpyxl import Workbook
from tabulator.loader import Loader
from validata_validate import validate
schema_abc = {
......@@ -225,19 +224,7 @@ a;c"""
def validate_xlsx_bytes(**options):
return validate(scheme='bytes', format='xlsx',
pre_checks_conf=pre_checks_conf, custom_loaders={"bytes": BytesLoader}, **options)
class BytesLoader(Loader):
""" Custom loader for bytes string """
options = []
def __init__(self, bytes_sample_size, **options):
pass
def load(self, source, mode='t', encoding=None):
return BytesIO(source)
return validate(scheme='bytes', format='xlsx', pre_checks_conf=pre_checks_conf, **options)
def build_one_cell_xlsx(cell):
......
......@@ -7,6 +7,7 @@ from toolz import thread_first, update_in
import goodtables
from . import pre_checks
from .loaders import BytesLoader
log = logging.getLogger(__name__)
......@@ -50,6 +51,8 @@ def validate(source, schema, checks=None, pre_checks_conf=None, **options):
skip_checks=['non-matching-header', 'extra-header', 'missing-header'],
row_limit=VALIDATA_MAX_ROWS)
options = {**options, "custom_loaders": {"bytes": BytesLoader}}
for pre_check_conf in pre_checks_conf or []:
pre_check_name = pre_check_conf['name']
pre_check_options = {**options, **pre_check_conf.get('params', {})}
......
from io import BytesIO
from tabulator.loader import Loader
class BytesLoader(Loader):
"""Custom loader for bytes string"""
def __init__(self, bytes_sample_size, **options):
pass
def load(self, source, mode, encoding=None):
return BytesIO(source)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment