
    j_                         d Z ddlZddlZddlZddlZddlmZ ej        dk    rdZndZdd	Z	d
 Z
ddZd Zd ZddZddZddZddZdS )z~
Utilities for working with strings and text.

Inheritance diagram:

.. inheritance-diagram:: IPython.utils.text
   :parts: 3
    N)	Formatterwin32z	%B %d, %Yz
%B %-d, %Y   Fc                 F   | dS d|z  d|z  z   }|r t          j        dt           j                  }nt          j        dt           j                  }t          j        |||           }|                    t
          j        |z             r|dt          |                    S |S )a  Indent a string a given number of spaces or tabstops.

    indent(str,nspaces=4,ntabs=0) -> indent str by ntabs+nspaces.

    Parameters
    ----------

    instr : basestring
        The string to be indented.
    nspaces : int (default: 4)
        The number of spaces to be indented.
    ntabs : int (default: 0)
        The number of tabs to be indented.
    flatten : bool (default: False)
        Whether to scrub existing indentation.  If True, all lines will be
        aligned to the same indentation.  If False, existing indentation will
        be strictly increased.

    Returns
    -------

    str|unicode : string indented by ntabs and nspaces.

    N	 z^\s*^)recompile	MULTILINEsubendswithoslineseplen)instrnspacesntabsflattenindpatoutstrs          5lib/python3.11/site-packages/ipython_genutils/text.pyindentr      s    2 }
u*S[
 C -j",//jr|,,VCe$$Frz#~&& jCyj!!    c                 .   |                      d          rt          j        |           S |                     dd          }t	          |          dk    rt          j        |           S |\  }}t          j        |          }d                    ||g          S )zEquivalent of textwrap.dedent that ignores unindented first line.

    This means it will still dedent strings like:
    '''foo
    is a bar
    '''

    For use in wrap_paragraphs.
    
   )
startswithtextwrapdedentsplitr   join)textsplitsfirstrests       r   r!   r!   ?   s     t %t$$$ ZZQF
6{{at$$$KE4?4  D99eT]###r   P   c                    t          j        dt           j                  }t          |                                           } |                    |           ddd         }g }t          j        dt           j                  }|D ]A}|                    |          t          j        ||          }|	                    |           B|S )a  Wrap multiple paragraphs to fit a specified width.

    This is equivalent to textwrap.wrap, but with support for multiple
    paragraphs, as separated by empty lines.

    Returns
    -------

    list of complete paragraphs, wrapped to fill `ncols` columns.
    z
\n(\s*\n)+N   z\n\s+)
r
   r   r   r!   stripr"   searchr    fillappend)r$   ncolsparagraph_re
paragraphsout_ps	indent_reps          r   wrap_paragraphsr5   Z   s     :mR\::L$<<D##D))##A#.JF
8R\22I   A&a''AaMr   c                 .    t          j        dd|           S )z
    Remove ansi escape codes from text.
    
    Parameters
    ----------
    source : str
        Source to remove the ansi from
    z\033\[(\d|;)+?m )r
   r   )sources    r   
strip_ansir9   t   s     6$b&111r   c              #   j   K   t          dt          |           |          D ]}| |||z            V  dS )z'Yield successive n-sized chunks from l.r   N)ranger   )lnis      r   _chunksr?      sH      1c!ffa    !A#h r   r*   c           
      4   t          dt          |           dz             D ]a}t          t          t          t          | |                              }t          |          }t          |          }|||dz
  z  z   |k    r nb||dz
  r||z
  |dz
  z  nd||dS )z4Calculate optimal info to columnize a list of stringr   r   )columns_numbersoptimal_separator_widthrows_numberscolumns_width)r;   r   listmapmaxr?   sum)rlistseparator_sizedisplaywidthnrowchk	sumlengthr/   s          r   _find_optimalrO      s    aUA&&  3s75$//0011HH	C^U1W--==E > %OTVWx&_|i'?%'&J&J^_!!  r   c                 <    |t          |           k    r|S | |         S )z2return list item number, or default if don't exist)r   )mylistr>   defaults      r   _get_or_defaultrS      s"    CKKayr   c                      t          t          t          t                               g|R i |}|d         |d         c fdt	                    D             |fS )a  Returns a nested list, and info to columnize items

    Parameters
    ----------

    items
        list of strings to columize
    empty : (default None)
        default value to fill list if needed
    separator_size : int (default=2)
        How much caracters will be used as a separation between each columns.
    displaywidth : int (default=80)
        The width of the area onto wich the columns should enter

    Returns
    -------

    strings_matrix

        nested list of string, the outer most list contains as many list as
        rows, the innermost lists have each as many element as colums. If the
        total number of elements in `items` does not equal the product of
        rows*columns, the last element of some lists are filled with `None`.

    dict_info
        some info to make columnize easier:

        columns_numbers
          number of columns
        rows_numbers
          number of rows
        columns_width
          list of with of each columns
        optimal_separator_width
          best separator width between columns

    Examples
    --------
    ::

        In [1]: l = ['aaa','b','cc','d','eeeee','f','g','h','i','j','k','l']
           ...: compute_item_matrix(l,displaywidth=12)
        Out[1]:
            ([['aaa', 'f', 'k'],
            ['b', 'g', 'l'],
            ['cc', 'h', None],
            ['d', 'i', None],
            ['eeeee', 'j', None]],
            {'columns_numbers': 3,
            'columns_width': [5, 1, 1],
            'optimal_separator_width': 2,
            'rows_numbers': 5})
    rC   rA   c                 N    g | ] fd t                    D             !S )c                 @    g | ]}t          |z  z              S ))rR   )rS   ).0cemptyr>   itemsrL   s     r   
<listcomp>z2compute_item_matrix.<locals>.<listcomp>.<listcomp>   s0    UUU1uafQh>>>UUUr   )r;   )rW   r>   rY   rZ   ncolrL   s    @r   r[   z'compute_item_matrix.<locals>.<listcomp>   s?    lllZ[UUUUUUUdUUUlllr   )rO   rE   rF   r   r;   )rZ   rY   argskwargsinfor\   rL   s   ``   @@r   compute_item_matrixr`      s    l c#uoo..@@@@@@Dn%t,='>JD$lllllll_dei_j_jlllnrssr     c                     | sdS t          | t                    |          \  }d |D             }fd}d                    t          ||                    dz   S )a   Transform a list of strings into a single string with columns.

    Parameters
    ----------
    items : sequence of strings
        The strings to process.

    separator : str, optional [default is two spaces]
        The string that separates columns.

    displaywidth : int, optional [default is 80]
        Width of the display in number of characters.

    Returns
    -------
    The formatted string.
    r   )rJ   rK   c                 .    g | ]}t          d |          S N)filter)rW   xs     r   r[   zcolumnize.<locals>.<listcomp>   s     ///1vdA///r   c                 j                         d t          | d                   D                       S )Nc                 @    g | ]\  }}|                     |d           S )r   )ljust)rW   yws      r   r[   z/columnize.<locals>.<lambda>.<locals>.<listcomp>   s(    &b&b&bDAq3&b&b&br   rD   )r#   zip)rf   r_   	separators    r   <lambda>zcolumnize.<locals>.<lambda>   s2    y~~&b&bC4P_K`DaDa&b&b&bcc r   )r`   r   r#   rF   )rZ   rm   rK   matrixfmatrixsjoinr_   s    `    @r   	columnizerr      sw    $  t&uS^^ZfgggLFD/////GcccccE99S(())$..r   )r   r   F)r(   )r*   r(   rd   )ra   r(   )__doc__r   r
   sysr    stringr   platformdate_formatr   r!   r5   r9   r?   rO   rS   r`   rr    r   r   <module>ry      s    
			 				 



        <7KKK$ $ $ $N$ $ $6   4	2 	2 	2         8t 8t 8t 8tv/ / / / / /r   