<commit_before>"""
:copyright: (c) 2012 - 2015 by <NAME> <<EMAIL>>
:license: BSD-3
"""
from __future__ import absolute_import

import codecs
import glob
import os.path
import os
import sys

import jinja2_cli.compat

try:
    from anyconfig.api import container, load
except ImportError:
    container = dict

    try:
        import json
    except ImportError:
        try:
            import simplejson as json
        except ImportError:
            raise ("Could not import any json module to load contexts!"
                   " Aborting...")

    def load(filepath, _ftype):
        return json.load(open(filepath))


def get_locale_sensitive_stdout(encoding=jinja2_cli.compat.ENCODING):
    """
    :param encoding: Chart sets encoding
    :return: sys.stdout can output encoded strings
    """
    return codecs.getwriter(encoding)(sys.stdout)


def get_locale_sensitive_stdin(encoding=jinja2_cli.compat.ENCODING):
    """
    :param encoding: Chart sets encoding
    :return: sys.stdout can output encoded strings
    """
    return codecs.getreader(encoding)(sys.stdin)


def uniq(xs):
    """Remove duplicates in given list with its order kept.

    >>> uniq([])
    []
    >>> uniq([1, 4, 5, 1, 2, 3, 5, 10])
    [1, 4, 5, 2, 3, 10]
    """
    acc = xs[:1]
    for x in xs[1:]:
        if x not in acc:
            acc += [x]

    return acc


def chaincalls(callables, x):
    """<commit_msg>add doctests (actually does nothing except for running the target code, into jinja2_cli.utils.get_locale_sensitive_std{out,in}<commit_after>"""
:copyright: (c) 2012 - 2015 by <NAME> <<EMAIL>>
:license: BSD-3
"""
from __future__ import absolute_import

import codecs
import glob
import os.path
import os
import sys

import jinja2_cli.compat

try:
    from anyconfig.api import container, load
except ImportError:
    container = dict

    try:
        import json
    except ImportError:
        try:
            import simplejson as json
        except ImportError:
            raise ("Could not import any json module to load contexts!"
                   " Aborting...")

    def load(filepath, _ftype):
        return json.load(open(filepath))


def get_locale_sensitive_stdout(encoding=jinja2_cli.compat.ENCODING):
    """
    :param encoding: Chart sets encoding
    :return: sys.stdout can output encoded strings

    >>> _t = get_locale_sensitive_stdout("UTF-8")
    """
    return codecs.getwriter(encoding)(sys.stdout)


def get_locale_sensitive_stdin(encoding=jinja2_cli.compat.ENCODING):
    """
    :param encoding: Chart sets encoding
    :return: sys.stdout can output encoded strings

    >>> _t = get_locale_sensitive_stdin("UTF-8")
    """
    return codecs.getreader(encoding)(sys.stdin)


def uniq(xs):
    """Remove duplicates in given list with its order kept.

    >>> uniq([])
    []
    >>> uniq([1, 4, 5, 1, 2, 3, 5, 10])
    [1, 4, 5, 2, 3, 10]
    """
    acc = xs[:1]
    for x in xs[1:]:
        if x not in acc:
            acc += [x]

    return acc


def chaincalls(callables, x):
    """
{'fraction_non_alphanumeric': 0.11335095836087244, 'fraction_numerical': 0.020819563780568408, 'mean_word_length': 2.788485607008761, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 27, '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': '1414309', 'n_tokens_mistral': 1034, 'n_tokens_neox': 934, 'n_words': 292}