
    HR-e|+                        d Z ddlZddlmZ  G d dej                  Z G d dej                  Z G d	 d
ej                  Z	 G d de          Z
 G d de          Z G d de	          Z G d de          Z G d de	          Z G d dej                  Z G d de          Z G d de          Z G d de          Z G d de	          Z G d d ej                  Z G d! d"e          Z G d# d$e          Z G d% d&e	          Z G d' d(e          Z G d) d*e          Z G d+ d,e          ZdS )-a+  An extensible ASCII table reader and writer.

basic.py:
  Basic table read / write functionality for simple character
  delimited files with various options for column header definition.

:Copyright: Smithsonian Astrophysical Observatory (2011)
:Author: Tom Aldcroft (aldcroft@head.cfa.harvard.edu)
    N   )corec                       e Zd ZdZdZdZdZdS )BasicHeaderz
    Basic table Header Reader.

    Set a few defaults for common ascii table formats
    (start at line 0, comments begin with ``#`` and possibly white space)
    r   \s*## N__name__
__module____qualname____doc__
start_linecommentwrite_comment     6lib/python3.11/site-packages/astropy/io/ascii/basic.pyr   r      )          JGMMMr   r   c                       e Zd ZdZdZdZdZdS )	BasicDataz
    Basic table Data Reader.

    Set a few defaults for common ascii table formats
    (start at line 1, comments begin with ``#`` and possibly white space)
    r   r   r   Nr	   r   r   r   r   r      r   r   r   c                   (    e Zd ZdZdZdZdgZeZe	Z
dS )Basica  Character-delimited table with a single header line at the top.

    Lines beginning with a comment character (default='#') as the first
    non-whitespace character are comments.

    Example table::

      # Column definition is the first uncommented line
      # Default delimiter is the space character.
      apples oranges pears

      # Data starts after the header column definition, blank lines ignored
      1 2 3
      4 5 6
    basicz"Basic table with custom delimitersasciiN)r
   r   r   r   _format_name_description_io_registry_format_aliasesr   header_classr   
data_classr   r   r   r   r   ,   s6           L7L#*)LJJJr   r   c                       e Zd ZdZdZdS )NoHeaderHeaderz
    Reader for table header without a header.

    Set the start of header line number to `None`, which tells the basic
    reader there is no header line.
    Nr
   r   r   r   r   r   r   r   r!   r!   E   s          JJJr   r!   c                       e Zd ZdZdZdS )NoHeaderDataz{
    Reader for table data without a header.

    Data starts at first uncommented line since there is no header line.
    r   Nr"   r   r   r   r$   r$   P   s          JJJr   r$   c                   "    e Zd ZdZdZdZeZeZ	dS )NoHeadera6  Character-delimited table with no header line.

    When reading, columns are autonamed using header.auto_format which defaults
    to "col%d".  Otherwise this reader the same as the :class:`Basic` class
    from which it is derived.  Example::

      # Table data
      1 2 "hello there"
      3 4 world

    	no_headerzBasic table with no headersN)
r
   r   r   r   r   r   r!   r   r$   r   r   r   r   r&   r&   Z   s.        
 
 L0L!LJJJr   r&   c                       e Zd ZdZd Zd ZdS )CommentedHeaderHeaderz
    Header class for which the column definition line starts with the
    comment character.  See the :class:`CommentedHeader` class  for an example.
    c              #      K   t          j        | j                  }|D ]7}|                    |          }|r||                                d         V  8dS )z
        Return only lines that start with the comment regexp.  For these
        lines strip out the matching characters.
        N)recompiler   matchend)selflines
re_commentliner-   s        r   process_linesz#CommentedHeaderHeader.process_liness   sk      
 Z--
 	* 	*D$$T**E *599;;==))))	* 	*r   c                 z    |                     | j        | j                            | j                  z              d S )N)appendr   splitterjoincolnames)r/   r0   s     r   writezCommentedHeaderHeader.write~   s4    T'$-*<*<T]*K*KKLLLLLr   N)r
   r   r   r   r3   r9   r   r   r   r)   r)   m   sA         
	* 	* 	*M M M M Mr   r)   c                   8     e Zd ZdZdZdZeZeZ	 fdZ
d Z xZS )CommentedHeadera
  Character-delimited table with column names in a comment line.

    When reading, ``header_start`` can be used to specify the
    line index of column names, and it can be a negative index (for example -1
    for the last commented line).  The default delimiter is the <space>
    character.

    This matches the format produced by ``np.savetxt()``, with ``delimiter=','``,
    and ``header='<comma-delimited-column-names-list>'``.

    Example::

      # col1 col2 col3
      # Comment line
      1 2 3
      4 5 6

    commented_headerz Column names in a commented linec                 P   t                                          |          }d|j        v rz| j        j        }|dk     rt          |j        d                   |z   }|j        d         d|         |j        d         |dz   d         z   |j        d<   |j        d         s|j        d= |S )z
        Read input data (file-like object, filename, list of strings, or
        single string) into a Table and return the result.
        commentsr   Nr   )superreadmetaheaderr   len)r/   tableoutidx	__class__s       r   r@   zCommentedHeader.read   s    
 ggll5!! !!+(CQww#(:.//#5$TcT*SXj-A#'))-LL HZ  8J' )HZ(
r   c                 p    | j                             |           | j                             ||           dS )zL
        Write comment lines after, rather than before, the header.
        N)rB   r9   write_comments)r/   r0   rA   s      r   write_headerzCommentedHeader.write_header   s8     	%   ""5$/////r   )r
   r   r   r   r   r   r)   r   r$   r   r@   rJ   __classcell__)rG   s   @r   r;   r;      sg         & &L5L(LJ    *0 0 0 0 0 0 0r   r;   c                       e Zd ZdZdZd ZdS )TabHeaderSplitterz0Split lines on tab and do not remove whitespace.	c                     |dz   S )N
r   )r/   r2   s     r   process_linezTabHeaderSplitter.process_line   s    d{r   N)r
   r   r   r   	delimiterrQ   r   r   r   rM   rM      s.        ::I    r   rM   c                       e Zd ZdZdZdZdS )TabDataSplitterzT
    Don't strip data value whitespace since that is significant in TSV tables.
    NF)r
   r   r   r   process_valskipinitialspacer   r   r   rT   rT      s'          Kr   rT   c                       e Zd ZdZeZdS )	TabHeaderz@
    Reader for header of tables with tab separated header.
    N)r
   r   r   r   rM   splitter_classr   r   r   rX   rX      s          'NNNr   rX   c                       e Zd ZdZeZdS )TabDataz<
    Reader for data of tables with tab separated data.
    N)r
   r   r   r   rT   rY   r   r   r   r[   r[      s          %NNNr   r[   c                   "    e Zd ZdZdZdZeZeZ	dS )Taba  Tab-separated table.

    Unlike the :class:`Basic` reader, whitespace is not stripped from the
    beginning and end of either lines or individual column values.

    Example::

      col1 <tab> col2 <tab> col3
      # Comment line
      1 <tab> 2 <tab> 5

    tabz%Basic table with tab-separated valuesN)
r
   r   r   r   r   r   rX   r   r[   r   r   r   r   r]   r]      s.          L:LLJJJr   r]   c                       e Zd ZdZdZdS )CsvSplitterz@
    Split on comma for CSV (comma-separated-value) tables.
    ,N)r
   r   r   r   rR   r   r   r   r`   r`      s          IIIr   r`   c                       e Zd ZdZeZdZdZdS )	CsvHeaderzK
    Header that uses the :class:`astropy.io.ascii.basic.CsvSplitter`.
    N)r
   r   r   r   r`   rY   r   r   r   r   r   rc   rc      s)          !NGMMMr   rc   c                   2    e Zd ZdZeZej        dfgZdZ	dZ
dS )CsvDatazI
    Data that uses the :class:`astropy.io.ascii.basic.CsvSplitter`.
     N)r
   r   r   r   r`   rY   r   maskedfill_valuesr   r   r   r   r   re   re     s8          !NK$%KGMMMr   re   c                   6    e Zd ZdZdZdgZdZdZdZe	Z
eZd ZdS )Csva  CSV (comma-separated-values) table.

    This file format may contain rows with fewer entries than the number of
    columns, a situation that occurs in output from some spreadsheet editors.
    The missing entries are marked as masked in the output table.

    Masked values (indicated by an empty '' field value when reading) are
    written out in the same way with an empty ('') field.  This is different
    from the typical default for `astropy.io.ascii` in which missing values are
    indicated by ``--``.

    Since the `CSV format <https://tools.ietf.org/html/rfc4180>`_ does not
    formally support comments, any comments defined for the table via
    ``tbl.meta['comments']`` are ignored by default. If you would still like to
    write those comments then include a keyword ``comment='#'`` to the
    ``write()`` call.

    Example::

      num,ra,dec,radius,mag
      1,32.23222,10.1211
      2,38.12321,-88.1321,2.2,17.0

    csvTz.csvzComma-separated-valuesc                 ~    t          |          |k     r)|                    |t          |          z
  dgz             |S )aQ  
        Adjust row if it is too short.

        If a data row is shorter than the header, add empty values to make it the
        right length.
        Note that this will *not* be called if the row already matches the header.

        Parameters
        ----------
        str_vals : list
            A list of value strings from the current row of the table.
        ncols : int
            The expected number of entries from the table header.

        Returns
        -------
        str_vals : list
            List of strings to be parsed into data entries in the output table.
        rf   )rC   extend)r/   str_valsncolss      r   inconsistent_handlerzCsv.inconsistent_handler/  s>    ( x==5  OOUS]]2rd:;;;r   N)r
   r   r   r   r   r   _io_registry_can_write_io_registry_suffixr   rc   r   re   r   rp   r   r   r   rj   rj     sW         2 L#('! +LLJ    r   rj   c                   B    e Zd ZdZej        ej        dZd Zd Z	d Z
dS )	RdbHeaderz 
    Header for RDB tables.
    )nsc                     |j         d         S )N)raw_type)r/   cols     r   get_type_map_keyzRdbHeader.get_type_map_keyP  s    |Br   c                 n   |                      |          }d t          t          d          |                     |                    D             }t	          |          dk    rt          d          |\  | _        }t	          | j                  t	          |          k    rt          j        d          t          d |D                       rt          j        d|           | 
                                 t          | j        |          D ]&\  }}||_        |                     |          |_        'dS )av  
        Initialize the header Column objects from the table ``lines``.

        This is a specialized get_cols for the RDB type:
        Line 0: RDB col names
        Line 1: RDB col definitions
        Line 2+: RDB data rows

        Parameters
        ----------
        lines : list
            List of table lines

        Returns
        -------
        None

        c                     g | ]\  }}|S r   r   ).0_hls      r   
<listcomp>z&RdbHeader.get_cols.<locals>.<listcomp>g  s    WWW51bBWWWr      zRDB header requires 2 lineszDRDB header mismatch between number of column names and column types.c              3   X   K   | ]%}t          j        d |t           j                   V  &dS )z	\d*(N|S)$N)r+   r-   
IGNORECASE)r~   xs     r   	<genexpr>z%RdbHeader.get_cols.<locals>.<genexpr>q  s5      OO28L!R];;;OOOOOOr   z3RDB types definitions do not all match [num](N|S): N)r3   zipranger6   rC   
ValueErrornamesr   InconsistentTableErrorany_set_cols_from_namescolsry   get_col_typetype)r/   r0   header_linesheader_vals_list	raw_typesrz   ry   s          r   get_colszRdbHeader.get_colsS  sC   & ))%00WWCa$--:U:U,V,VWWW  A%%:;;; 0
Itz??c)nn,,-V   OOYOOOOO 	-QiQQ   	!!### I66 	. 	.MC#CL((--CHH	. 	.r   c                 4   |                     | j                            | j                             g }| j        D ].}|j        j        j        dv rdnd}|                     |           /|                     | j                            |                     d S )N)SUr   N)r5   r6   r7   r8   r   infodtypekind)r/   r0   	rdb_typesrz   rdb_types        r   r9   zRdbHeader.write{  s    T]''66777	9 	' 	'C!hn1Z??ssSHX&&&&T]''	2233333r   N)r
   r   r   r   r   NumTypeStrTypecol_type_mapr{   r   r9   r   r   r   rt   rt   I  s_          DL99L     &. &. &.P4 4 4 4 4r   rt   c                       e Zd ZdZdZdS )RdbDataz=
    Data reader for RDB data. Starts reading at line 2.
    r   Nr"   r   r   r   r   r     s          JJJr   r   c                   ,    e Zd ZdZdZdgZdZdZeZ	e
ZdS )Rdba4  Tab-separated file with an extra line after the column definition line that
    specifies either numeric (N) or string (S) data.

    See: https://www.drdobbs.com/rdb-a-unix-command-line-database/199101326

    Example::

      col1 <tab> col2 <tab> col3
      N <tab> S <tab> N
      1 <tab> 2 <tab> 5

    rdbz.rdbz0Tab-separated with a type definition header lineN)r
   r   r   r   r   r   rr   r   rt   r   r   r   r   r   r   r   r     s<          L#(' ELLJJJr   r   )r   r+   rf   r   
BaseHeaderr   BaseDatar   
BaseReaderr   r!   r$   r&   r)   r;   DefaultSplitterrM   rT   rX   r[   r]   r`   rc   re   rj   rt   r   r   r   r   r   <module>r      s    
			      
 
 
 
 
$/ 
 
 

 
 
 
 
 
 
 
    DO   2    [       9       u   &M M M M MK M M M*40 40 40 40 40e 40 40 40n    ,       '   ' ' ' ' ' ' ' '% % % % %i % % %    %   (    $&              i   : : : : :% : : :z:4 :4 :4 :4 :4	 :4 :4 :4z    g       #     r   