a
    ߙfb                     @   sj   d dl Z d dlmZ d dlmZ dddZdddZdd	 Ze	d
ee e
d
ee ed
ee dS )    N)registry)Tablec                 K   s   zddl }W n ty&   tdY n0 |r8|r8td|j| fi |F}|rh||jW  d   S ||ppd W  d   S W d   n1 s0    Y  dS )a  
    Read a `~astropy.table.Table` object from an ASDF file

    This requires `asdf <https://pypi.org/project/asdf/>`_ to be installed.
    By default, this function will look for a Table object with the key of
    ``data`` in the top-level ASDF tree. The parameters ``data_key`` and
    ``find_key`` can be used to override the default behavior.

    This function is registered as the Table reader for ASDF files with the
    unified I/O interface.

    Parameters
    ----------
    filename : str or :class:`py.lath:local`
        Name of the file to be read
    data_key : str
        Optional top-level key to use for finding the Table in the tree. If not
        provided, uses ``data`` by default. Use of this parameter is not
        compatible with ``find_table``.
    find_table : function
        Optional function to be used for locating the Table in the tree. The
        function takes a single parameter, which is a dictionary representing
        the top of the ASDF tree. The function must return a
        `~astropy.table.Table` instance.

    Returns
    -------
    table : `~astropy.table.Table`
        `~astropy.table.Table` instance
    r   N8The asdf module is required to read and write ASDF filesz6Options 'data_key' and 'find_table' are not compatibledata)asdfImportError	Exception
ValueErroropentree)filenamedata_keyZ
find_tablekwargsr   af r   ;lib/python3.9/site-packages/astropy/io/misc/asdf/connect.py
read_table   s    
r   c                 K   s   zddl }W n ty&   tdY n0 |r8|r8td|rF|| }n|pLd| i}||"}|j|fi | W d   n1 s0    Y  dS )a  
    Write a `~astropy.table.Table` object to an ASDF file.

    This requires `asdf <https://pypi.org/project/asdf/>`_ to be installed.
    By default, this function will write a Table object in the top-level ASDF
    tree using the key of ``data``. The parameters ``data_key`` and
    ``make_tree`` can be used to override the default behavior.

    This function is registered as the Table writer for ASDF files with the
    unified I/O interface.

    Parameters
    ----------
    table : `~astropy.table.Table`
        `~astropy.table.Table` instance to be written
    filename : str or :class:`py.path:local`
        Name of the new ASDF file to be created
    data_key : str
        Optional top-level key in the ASDF tree to use when writing the Table.
        If not provided, uses ``data`` by default. Use of this parameter is not
        compatible with ``make_tree``.
    make_tree : function
        Optional function to be used for creating the ASDF tree. The function
        takes a single parameter, which is the `~astropy.table.Table` instance
        to be written. The function must return a `dict` representing the ASDF
        tree to be created.
    r   Nr   z5Options 'data_key' and 'make_tree' are not compatibler   )r   r   r   r	   ZAsdfFileZwrite_to)tabler   r   Z	make_treer   r   r   r   r   r   r   write_table:   s    

r   c                 O   s4   zdd l }W n ty    Y dS 0 |d uo2|dS )Nr   Fz.asdf)r   r   endswith)originfilepathZfileobjargsr   r   r   r   r   asdf_identifyh   s
    r   r   )NN)NN)	functoolsZ
astropy.ior   Zio_registryZastropy.tabler   r   r   r   Zregister_readerZregister_writerZregister_identifierr   r   r   r   <module>   s   
/
.	