<commit_before>#! /usr/bin/env python
"""
Example usage:
    sndump -n -o -q -op --format=wiki > standard_names.wiki
"""
from __future__ import print_function

import os
import sys
import argparse

from ..registry import NamesRegistry
from ..utilities import FORMATTERS


_FORMATS = FORMATTERS.keys()


def sndump(file=None, format='plain', sorted=True, keys=None, newline=None):
    """Dump a registry to different formats.

    Parameters
    ----------
    file : str, optional
        Name of a registry file of names.
    format : {'plain'}, optional
        Output format.
    sorted : bool, optional
        Sort results.
    keys : {'names, 'objects', 'quantities', 'operators'} or iterable
        Standard Name element or elements to print.
    newline : str, optional
        Specify the newline character to use for output.

    Examples
    --------
    >>> from __future__ import print_function
    >>> import os
    >>> from six.moves import StringIO
    >>> import standard_names as csn

    >>> lines = os.linesep.join(['air__temperature', 'water__temperature'])
    >>> names = StringIO(lines)

    >>> print(csn.cmd.sndump.sndump(names))
    air__temperature
    water__temperature
    """
    newline = newline or os.linesep
    keys = keys or ('names', )
    if file:
        args = (file, )
    else:
        args = ()

    names = NamesRegistry(*args)

    lines = []
    formatter = FORMATTERS[format]
    for key in keys:
        list_to_print = getattr(names, key)
        lines.append(formatter(list_to_print, sorted=sorted, heading=key,
                               level=2))

    return newline.join(lines)

<commit_msg>Added REPORT_NDIFF for doctest.<commit_after>#! /usr/bin/env python
"""
Example usage:
    sndump -n -o -q -op --format=wiki > standard_names.wiki
"""
from __future__ import print_function

import os
import sys
import argparse

from ..registry import NamesRegistry
from ..utilities import FORMATTERS


_FORMATS = FORMATTERS.keys()


def sndump(file=None, format='plain', sorted=True, keys=None, newline=None):
    """Dump a registry to different formats.

    Parameters
    ----------
    file : str, optional
        Name of a registry file of names.
    format : {'plain'}, optional
        Output format.
    sorted : bool, optional
        Sort results.
    keys : {'names, 'objects', 'quantities', 'operators'} or iterable
        Standard Name element or elements to print.
    newline : str, optional
        Specify the newline character to use for output.

    Examples
    --------
    >>> from __future__ import print_function
    >>> import os
    >>> from six.moves import StringIO
    >>> import standard_names as csn

    >>> lines = os.linesep.join(['air__temperature', 'water__temperature'])
    >>> names = StringIO(lines)

    >>> print(csn.cmd.sndump.sndump(names)) # doctest: +REPORT_NDIFF
    air__temperature
    water__temperature
    """
    newline = newline or os.linesep
    keys = keys or ('names', )
    if file:
        args = (file, )
    else:
        args = ()

    names = NamesRegistry(*args)

    lines = []
    formatter = FORMATTERS[format]
    for key in keys:
        list_to_print = getattr(names, key)
        lines.append(formatter(list_to_print, sorted=sorted, heading=key,
                               level=2))

    return newline.join(lines)


{'fraction_non_alphanumeric': 0.11539611360239163, 'fraction_numerical': 0.0005979073243647235, 'mean_word_length': 2.582441113490364, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 47, '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': '3282355', 'n_tokens_mistral': 1001, 'n_tokens_neox': 967, 'n_words': 295}