<commit_before># Copyright 2017 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is part of Project monotable.

"""ASCII table: per column format specs, plug-in format functions, multi-line.

   Formats 2D array of Python objects to ASCII table format.
   The table looks pretty when printed in a monospaced font.
   See class MonoTable docstring for details.

   Classes:
   MonoTable   Format Python objects to ASCII table for monospaced font.

   Exceptions:
   MonoTableCellError  Created when formatting a cell fails.

   Attributes:
   HR             In column 0 of a row, horizontal rule should be inserted.
"""


import copy
import numbers
import sys
import textwrap
import traceback

import monotable.plugin
import monotable.scanner

from monotable.monoblock import MonoBlock

from monotable.alignment import NOT_SPECIFIED
from monotable.alignment import LEFT
from monotable.alignment import RIGHT

# repository: https://github.com/tmarktaylor/monotable
# Docstrings are Google Style for Sphinx plugin sphinx.ext.napoleon.


def _transpose(grid):
    """Swap rows for columns or columns for rows."""

    return list(zip(*grid))


class _HR:
    """Type to distinguish a horizontal rule from other cell types."""
    pass


HR = _HR()
"""Placed in column 0 of a *row* in a cellgrid to insert a horizontal rule.

A row that starts with a HR is omitted from the
table and a heading guideline is inserted in its place.
"""


class MonoTable:
    """Create an aligned and formatted text table from a grid of cells.

    Pass a sequence of heading strings and a
    sequence of format strings to the constructor.  Call
    :py:meth:`~MonoTable.table` passing a sequence of sequence of
    cells and a title string.
    The return value is a string ready for printing.

    Call :py:meth:`~MonoTable.bordered_table` with the same arguments
    to format a table with character borders.

    Call :py:meth:`~MonoTable.row_strings` passing a sequence of sequence of
    cells to return a tuple of lists of formatted headings and
    list of list of cells.

    Heading strings, title strings, and formatted cells may contain
    newlines.

    Cells that inherit from numbers.Number are *Auto-Aligned* to the right
    and all other cell types are auto aligned to the left.

    align_spec
        One of the characters '<', '^', '>'.  The characters
        indicate left, center, and right justification.
        To configure, override the class variable
        :py:attr:`~MonoTable.align_spec_chars`.

    Heading String
        [align_spec]string

    Format String
        [align_spec][option_spec][format_spec]

    Title String
        [align_spec][wrap_spec]string

    * The format string syntax is described by the
      :py:meth:`~MonoTable.__init__` argument **formats** below.

    * Heading alignment is determined by this decision order:

        1. align_spec if present in the heading string.
        2. align_spec if present in the format string.
        3. Auto-Alignment for the cell in the first row.

    * Cell alignment is determined by this decision order:

        1. align_spec if present in the format string.
        2. Auto-Alignment for the cell in the first row.

    * The title is auto-aligned to center.

    :note:
        The align_spec prefix may be omitted, but is required if the
        rest of the string starts with one of the align_spec_chars.
        Or the user can put in any empty option_spec for example '()'.

    :note:
        align_spec scanning/parsing can be disabled by setting the
        class variable :py:attr:`~MonoTable.align_spec_chars` to
        the empty string.

    There is one format string for each column of cells.
    Please see description of :py:meth:`~MonoTable.__init__`
    argument **formats**.

    Formatting, by default, is done by ``<built-in function format>``.

        * The user can specify a different default format function for the
          table by overriding the class variable
          :py:attr:`~MonoTable.format_func`.  Be sure to use staticmethod().
        * In option_spec the user can specify a format function for
          a column which takes precedence over the table default format
          function.

          =============  ========================  =========================<commit_msg>Docstring style changes.<commit_after># Copyright 2017 <NAME>
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This file is part of Project monotable.

"""ASCII table: per column format specs, plug-in format functions, multi-line.

   Formats 2D array of Python objects to ASCII table format.
   The table looks pretty when printed in a monospaced font.
   See class MonoTable docstring for details.

   Classes:
   MonoTable   Format Python objects to ASCII table for monospaced font.

   Exceptions:
   MonoTableCellError  Created when formatting a cell fails.

   Attributes:
   HR             In column 0 of a row, horizontal rule should be inserted.
"""


import copy
import numbers
import sys
import textwrap
import traceback

import monotable.plugin
import monotable.scanner

from monotable.monoblock import MonoBlock

from monotable.alignment import NOT_SPECIFIED
from monotable.alignment import LEFT
from monotable.alignment import RIGHT

# repository: https://github.com/tmarktaylor/monotable
# Docstrings are Google Style for Sphinx plugin sphinx.ext.napoleon.


def _transpose(grid):
    """Swap rows for columns or columns for rows."""

    return list(zip(*grid))


class _HR:
    """Type to distinguish a horizontal rule from other cell types."""
    pass


HR = _HR()
"""Placed in column 0 of a *row* in a cellgrid to insert a horizontal rule.

A row that starts with a HR is omitted from the
table and a heading guideline is inserted in its place.
"""


class MonoTable:
    """Create an aligned and formatted text table from a grid of cells.

    Pass a sequence of heading strings and a
    sequence of format strings to the constructor.  Call
    :py:meth:`~MonoTable.table` passing a sequence of sequence of
    cells and a title string.
    The return value is a string ready for printing.

    Call :py:meth:`~MonoTable.bordered_table` with the same arguments
    to format a table with character borders.

    Call :py:meth:`~MonoTable.row_strings` passing a sequence of sequence of
    cells to return a tuple of lists of formatted headings and
    list of list of cells.

    Heading strings, title strings, and formatted cells may contain
    newlines.

    Cells that inherit from numbers.Number are *Auto-Aligned* to the right
    and all other cell types are auto aligned to the left.

    Definitions:

    :align_spec: One of the characters '<', '^', '>'.  The characters
        indicate left, center, and right justification.
        To configure, override the class variable
        :py:attr:`~MonoTable.align_spec_chars`.

    :Heading String: [align_spec]string

    :Format String: [align_spec][option_spec][format_spec]
    
    :Title String: [align_spec][wrap_spec]string

    * The format string syntax is described by the
      :py:meth:`~MonoTable.__init__` argument **formats** below.

    * Heading alignment is determined by this decision order:

        1. align_spec if present in the heading string.
        2. align_spec if present in the format string.
        3. Auto-Alignment for the cell in the first row.

    * Cell alignment is determined by this decision order:

        1. align_spec if present in the format string.
        2. Auto-Alignment for the cell in the first row.

    * The title is auto-aligned to center.

    :note: The align_spec prefix may be omitted, but is required if the
        rest of the string starts with one of the align_spec_chars.
        Or the user can put in any empty option_spec for example '()'.

    :note: align_spec scanning/parsing can be disabled by setting the
        class variable :py:attr:`~MonoTable.align_spec_chars` to
        the empty string.

    There is one format string for each column of cells.
    Please see description of :py:meth:`~MonoTable.__init__`
    argument **formats**.

    Formatting, by default, is done by ``<built-in function format>``.

        * The user can specify a different default format function for the
          table by overriding the class variable
          :py:attr:`~MonoTable.format_func`.  Be sure to use staticmethod().
        * In option_spec the user can specify a format function for
          a column which takes precedence over the table default format
          function.

          =============  ========================  =========================
{'fraction_non_alphanumeric': 0.07293506493506494, 'fraction_numerical': 0.003324675324675325, 'mean_word_length': 3.2034934497816594, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '4581546', 'n_tokens_mistral': 2611, 'n_tokens_neox': 2443, 'n_words': 1209}