How to use the tabulator.parser.Parser function in tabulator

To help you get started, we’ve selected a few tabulator examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github frictionlessdata / tabulator-py / tabulator / parsers / inline.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

import six
from ..parser import Parser
from .. import exceptions


# Module API

class InlineParser(Parser):
    """Parser to provide support for python inline lists.
    """

    # Public

    options = []

    def __init__(self, loader, force_parse=False):
        self.__loader = loader
        self.__force_parse = force_parse
        self.__extended_rows = None
        self.__encoding = None
        self.__source = None

    @property
    def closed(self):
github frictionlessdata / tabulator-py / tabulator / parsers / csv.py View on Github external
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

import csv
import six
from itertools import chain
from codecs import iterencode
from ..parser import Parser
from .. import helpers
from .. import config


# Module API

class CSVParser(Parser):
    """Parser to parse CSV data format.
    """

    # Public

    options = [
        'delimiter',
        'doublequote',
        'escapechar',
        'quotechar',
        'quoting',
        'skipinitialspace',
        'lineterminator'
    ]

    def __init__(self, loader, force_parse=False, **options):
github frictionlessdata / tabulator-py / tabulator / parsers / tsv.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

import tsv
from ..parser import Parser
from .. import helpers


# Module API

class TSVParser(Parser):
    """Parser to parse linear TSV data format.

    See: http://dataprotocols.org/linear-tsv/

    """

    # Public

    options = []

    def __init__(self, loader, force_parse=False):
        self.__loader = loader
        self.__force_parse = force_parse
        self.__extended_rows = None
        self.__encoding = None
        self.__chars = None
github frictionlessdata / datapackage-pipelines / datapackage_pipelines / utilities / tabulator_txt_parser.py View on Github external
from tabulator.parser import Parser
from tabulator.helpers import reset_stream


class TXTParser(Parser):
    """Parser to parse TXT data format.
    """

    # Public

    options = []

    def __init__(self, loader, **options):
        super(TXTParser, self).__init__(loader, **options)

        # Set attributes
        self.__options = options
        self.__extended_rows = None
        self.__loader = loader
        self.__chars = None
        self.__encoding = None
github frictionlessdata / tabulator-py / tabulator / parsers / sql.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

from sqlalchemy import create_engine, sql
from ..parser import Parser
from .. import exceptions


# Module API

class SQLParser(Parser):
    """Parser to get data from SQL database.
    """

    # Public

    options = [
        'table',
        'order_by',
    ]

    def __init__(self, loader, force_parse=False, table=None, order_by=None):

        # Ensure table
        if table is None:
            raise exceptions.TabulatorException('Format `sql` requires `table` option.')
github datahq / dataflows / dataflows / processors / load.py View on Github external
import os
import warnings
import datetime

from datapackage import Package
from tabulator import Stream
from tabulator.parser import Parser
from tabulator.helpers import reset_stream
from tableschema.schema import Schema
from .. import DataStreamProcessor
from ..base.exceptions import SourceLoadError
from ..base.schema_validator import schema_validator, ignore, drop, raise_exception
from ..helpers.resource_matcher import ResourceMatcher


class XMLParser(Parser):
    options = []

    def __init__(self, loader, force_parse, **options):
        self.__loader = loader
        self.__force_parse = force_parse
        self.__extended_rows = None
        self.__encoding = None
        self.__chars = None

    def open(self, source, encoding=None):
        self.close()
        self.__chars = self.__loader.load(source, encoding=encoding)
        self.__encoding = getattr(self.__chars, 'encoding', encoding)
        if self.__encoding:
            self.__encoding.lower()
        self.reset()
github frictionlessdata / tabulator-py / tabulator / parsers / datapackage.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

import six
import datapackage
from ..parser import Parser
from .. import exceptions


# Module API

class DataPackageParser(Parser):
    """Parser to extract data from Tabular Data Packages.
    """

    # Public

    options = [
        'resource',
    ]

    def __init__(self, loader, force_parse=False, resource=0):
        self.__force_parse = force_parse
        self.__resource_pointer = resource
        self.__extended_rows = None
        self.__encoding = None
        self.__fragment = None
        self.__resource = None
github frictionlessdata / tabulator-py / tabulator / parsers / xls.py View on Github external
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

import six
import sys
import xlrd
from ..parser import Parser
from .. import exceptions
from .. import helpers


# Module API

class XLSParser(Parser):
    """Parser to parse Excel data format.
    """

    # Public

    options = [
        'sheet',
        'fill_merged_cells',
    ]

    def __init__(self, loader, force_parse=False, sheet=1, fill_merged_cells=False):
        self.__loader = loader
        self.__sheet_pointer = sheet
        self.__fill_merged_cells = fill_merged_cells
        self.__force_parse = force_parse
        self.__extended_rows = None
github frictionlessdata / tabulator-py / tabulator / parsers / ndjson.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

import jsonlines
from ..parser import Parser
from .. import exceptions
from .. import helpers


# Module API

class NDJSONParser(Parser):
    """Parser to parse NDJSON data format.

    See: http://specs.okfnlabs.org/ndjson/
    """

    # Public

    options = []

    def __init__(self, loader, force_parse=False):
        self.__loader = loader
        self.__force_parse = force_parse
        self.__extended_rows = None
        self.__encoding = None
        self.__chars = None
github frictionlessdata / tabulator-py / tabulator / parsers / gsheet.py View on Github external
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

import re
from ..stream import Stream
from ..parser import Parser


# Module API

class GsheetParser(Parser):
    """Parser to parse Google Spreadsheets.
    """

    # Public

    options = []

    def __init__(self, loader, force_parse=False):
        self.__loader = loader
        self.__force_parse = force_parse
        self.__stream = None
        self.__encoding = None

    @property
    def closed(self):
        return self.__stream is None or self.__stream.closed