<commit_before># -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

from .table import Table
from . import loaders, parsers, errors, helpers


DEFAULT_SCHEME = 'file'

LOADERS = {
    'file': loaders.File,
    'text': loaders.Text,
    'ftp': loaders.Web,
    'ftps': loaders.Web,
    'http': loaders.Web,
    'https': loaders.Web,
}

PARSERS = {
    'csv': parsers.CSV,
    'xls': parsers.Excel,
    'xlsx': parsers.Excel,
    'json': parsers.JSON,
}


def topen(source,
          scheme=None, format=None, encoding=None,
          loader_options=None, parser_options=None):
    """Open table from source with scheme, encoding and format.

    Function `topen` is a wrapper around `Table` interface.

    Parameters
    ----------
    source: str
        Path of contents.
    scheme: str
        Scheme of source:
            - file (default)
            - text
            - http
            - https
            - ftp
            - ftps
    format: str
        Format of source:
            - None (detect)
            - csv
            - json
            - xls
            - xlsx
    encoding: str
        Encoding of source:
            - None (detect)
            - utf-8
            - <any>
    loader_options: dict
        Loader options.
    parser_options: dict
        Parser options.

    Returns
    -------
    table: `Table`
        Opened Table instance.

    """
    # Initiate if None
    if loader_options is None:
        loader_options = {}
    if parser_options is None:
        parser_options = {}

    # Get scheme, format
    if scheme is None:
        scheme = helpers.detect_scheme(source) or DEFAULT_SCHEME
    if format is None:
        format = helpers.detect_format(source)

    # Lookup and initiate loader
    if scheme not in LOADERS:
        message = 'Scheme "%s" is not supported' % scheme
        raise errors.Error(message)
    loader = LOADERS[scheme](source, encoding, **loader_options)

    # Lookup and initiate parser
    if format not in PARSERS:
        message = 'Format "%s" is not supported' % format
        raise errors.Error(message)
    parser = PARSERS[format]()

    # Initiate, open table
    table = Table(loader=loader, parser=parser, **parser_options)
    table.open()

    return table<commit_msg>[#16] loader_class, parser_class params to topen<commit_after># -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
from __future__ import absolute_import
from __future__ import unicode_literals

from .table import Table
from . import loaders, parsers, errors, helpers


DEFAULT_SCHEME = 'file'

LOADERS = {
    'file': loaders.File,
    'text': loaders.Text,
    'ftp': loaders.Web,
    'ftps': loaders.Web,
    'http': loaders.Web,
    'https': loaders.Web,
}

PARSERS = {
    'csv': parsers.CSV,
    'xls': parsers.Excel,
    'xlsx': parsers.Excel,
    'json': parsers.JSON,
}


def topen(source,
          scheme=None, format=None, encoding=None,
          loader_options=None, parser_options=None,
          loader_class=None, parser_class=None):
    """Open table from source with scheme, encoding and format.

    Function `topen` is a wrapper around `Table` interface.

    Parameters
    ----------
    source: str
        Path of contents.
    scheme: str
        Scheme of source:
            - file (default)
            - text
            - http
            - https
            - ftp
            - ftps
    format: str
        Format of source:
            - None (detect)
            - csv
            - json
            - xls
            - xlsx
    encoding: str
        Encoding of source:
            - None (detect)
            - utf-8
            - <any>
    loader_options: dict
        Loader options.
    parser_options: dict
        Parser options.
    loader_class: type
        Loader class.
    parser_class: type
        Parser class.

    Returns
    -------
    table: `Table`
        Opened Table instance.

    """
    # Initiate if None
    if loader_options is None:
        loader_options = {}
    if parser_options is None:
        parser_options = {}

    # Get loader
    if loader_class is None:
        if scheme is None:
            scheme = helpers.detect_scheme(source) or DEFAULT_SCHEME
        if scheme not in LOADERS:
            message = 'Scheme "%s" is not supported' % scheme
            raise errors.Error(message)
        loader_class = LOADERS[scheme]
    loader = loader_class(source, encoding, **loader_options)

    # Get parser
    if parser_class is None:
        if format is None:
            format = helpers.detect_format(source)
        if format not in PARSERS:
            message = 'Format "%s" is not supported' % format
            raise errors.Error(message)
        parser_class = PARSERS[format]
    parser = parser_class(**parser_options)

    # Initiate and open table
    table = Table(loader=loader, parser=parser)
    table.open()

    return table
{'fraction_non_alphanumeric': 0.09401031336771122, 'fraction_numerical': 0.001190003966679889, 'mean_word_length': 1.940524781341108, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2837165', 'n_tokens_mistral': 1501, 'n_tokens_neox': 1444, 'n_words': 441}