
    HR-e                         d dl Z d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ ddlmZmZ ddlmZ dd	lmZ d
 Z	 ddZ	 ddZ ej        dee            ej        dee            ej        dee           dS )    N)registry)Table)
BaseColumn)Quantity)NOT_OVERWRITING_MSG   )
from_tableparse)VOTableFilec                     ddl m} | dk    ro|>	  ||          }|                    d           n# |                    d           w xY w|S | ||          S t          |d         t          t
          f          S dS )a7  
    Reads the header of a file to determine if it is a VOTable file.

    Parameters
    ----------
    origin : str or readable file-like
        Path or file object containing a VOTABLE_ xml file.

    Returns
    -------
    is_votable : bool
        Returns `True` if the given file is a VOTable file.
    r   )
is_votablereadNr   F) r   seek
isinstancer   VOTable)originfilepathfileobjargskwargsr   results          :lib/python3.11/site-packages/astropy/io/votable/connect.pyr   r      s      #G,,QQM!:h'''$q'K#9::: us	   1 AFc                 z   t          | t          t          f          st          | f||d|} t	                      }g }t          | t                    r=|                                 D ](}|j        
|||j        <   |                    |           )t          |          dk    r|6t          dd
                    |           dt          |           d          t          |t                    r ||v r	||         }nt          d| d	          t          |t                    r?|t          |          k     r	||         }nft          d
| dt          |           d          nBt          |          dk    r	|d         }n&t          d          t          | t                    r| }|                    |          S )a  
    Read a Table object from an VO table file.

    Parameters
    ----------
    input : str or `~astropy.io.votable.tree.VOTableFile` or `~astropy.io.votable.tree.Table`
        If a string, the filename to read the table from. If a
        :class:`~astropy.io.votable.tree.VOTableFile` or
        :class:`~astropy.io.votable.tree.Table` object, the object to extract
        the table from.

    table_id : str or int, optional
        The table to read in.  If a `str`, it is an ID corresponding
        to the ID of the table in the file (not all VOTable files
        assign IDs to their tables).  If an `int`, it is the index of
        the table in the file, starting at 0.

    use_names_over_ids : bool, optional
        When `True` use the ``name`` attributes of columns as the names
        of columns in the `~astropy.table.Table` instance.  Since names
        are not guaranteed to be unique, this may cause some columns
        to be renamed by appending numbers to the end.  Otherwise
        (default), use the ID attributes as the column names.

    verify : {'ignore', 'warn', 'exception'}, optional
        When ``'exception'``, raise an error when the file violates the spec,
        otherwise either issue a warning (``'warn'``) or silently continue
        (``'ignore'``). Warnings may be controlled using the standard Python
        mechanisms.  See the `warnings` module in the Python standard library
        for more information. When not provided, uses the configuration setting
        ``astropy.io.votable.verify``, which defaults to ``'ignore'``.

    **kwargs
        Additional keyword arguments are passed on to
        :func:`astropy.io.votable.table.parse`.
    )table_idverifyNr   zcMultiple tables found: table id should be set via the table_id= argument. The available tables are z, z, or integers less than .zNo tables with id=z foundzTable index z is out of range. z tables foundr   zNo table found)use_names_over_ids)r   r   r   r
   dictiter_tablesIDappendlen
ValueErrorjoinstrint
IndexErrorto_table)inputr   r   r   r   table_id_mappingtablestables           r   read_table_votabler.   0   s   N ek7344 IeHhvHHHH vvF%%%  &&(( 	! 	!Ex#-2 *MM%    v;;?? '		"233' ' F' ' '   Hc** ///,X6EE$%J(%J%J%JKKKHc** c&kk))"8,EE$!x ! !3v;; ! ! !  	 [[A1IEE-...	E7	#	#  >>-?>@@@    c                    | j                             t          t          f          }|rd |D             }t	          d| d          t          |t                    rWt          j        	                    |          r8|rt          j
        |           n!t          t          j        |                    t          | |          }|                    ||           dS )a  
    Write a Table object to an VO table file.

    Parameters
    ----------
    input : Table
        The table to write out.

    output : str
        The filename to write the table to.

    table_id : str, optional
        The table ID to use. If this is not specified, the 'ID' keyword in the
        ``meta`` object of the table will be used.

    overwrite : bool, optional
        Whether to overwrite any existing file without warning.

    tabledata_format : str, optional
        The format of table data to write.  Must be one of ``tabledata``
        (text representation), ``binary`` or ``binary2``.  Default is
        ``tabledata``.  See :ref:`astropy:votable-serialization`.
    c                 &    g | ]}|j         j        S  )infoname).0cols     r   
<listcomp>z'write_table_votable.<locals>.<listcomp>   s    GGGsSX]GGGr/   z(cannot write table with mixin column(s) z to VOTable)r   )tabledata_formatN)columnsnot_isinstancer   r   r$   r   r&   ospathexistsremoveOSErrorr   formatr	   to_xml)r*   outputr   	overwriter8   unsupported_colsunsupported_names
table_files           r   write_table_votablerG      s    6 }33Z4JKK 
GG6FGGGU7HUUU
 
 	

 &# >27>>&#9#9 > 	>If-4V<<=== EH555J f/?@@@@@r/   votable)NFN)r;   
astropy.ior   io_registryastropy.tabler   astropy.table.columnr   astropy.unitsr   astropy.utils.miscr   r   r	   r
   treer   r   r   r.   rG   register_readerregister_writerregister_identifierr2   r/   r   <module>rS      sH   
			 . . . . . .       + + + + + + " " " " " " 2 2 2 2 2 2         " " " " " "        @ <@PA PA PA PAh EI-A -A -A -A`  Iu.@ A A A  Iu.A B B B  	5* = = = = =r/   