U
    e»{jœ  ã                   @   sN   d dl Z d dlZd dlZddlmZ ddgZG dd„ dƒZG dd„ deƒZdS )é    Né   )ÚIORegistryErrorÚUnifiedReadWriteMethodÚUnifiedReadWritec                   @   s:   e Zd ZdZddd„Zedd„ ƒZddd„Zdd	d
„ZdS )r   a  Base class for the worker object used in unified read() or write() methods.

    This lightweight object is created for each `read()` or `write()` call
    via ``read`` / ``write`` descriptors on the data object class.  The key
    driver is to allow complete format-specific documentation of available
    method options via a ``help()`` method, e.g. ``Table.read.help('fits')``.

    Subclasses must define a ``__call__`` method which is what actually gets
    called when the data object ``read()`` or ``write()`` method is called.

    For the canonical example see the `~astropy.table.Table` class
    implementation (in particular the ``connect.py`` module there).

    Parameters
    ----------
    instance : object
        Descriptor calling instance or None if no instance
    cls : type
        Descriptor calling class (either owner class or instance class)
    method_name : str
        Method name, e.g. 'read' or 'write'
    registry : ``_UnifiedIORegistryBase`` or None, optional
        The IO registry.
    Nc                 C   s0   |d krddl m} || _|| _|| _|| _d S )Nr   )Údefault_registry)Zastropy.io.registry.compatr   Ú	_registryZ	_instanceÚ_clsÚ_method_name)ÚselfÚinstanceÚclsÚmethod_nameÚregistry© r   ú\/var/www/html/bwave/python/venv/lib/python3.8/site-packages/astropy/io/registry/interface.pyÚ__init__)   s    zUnifiedReadWrite.__init__c                 C   s   | j S )zUnified I/O registry instance.)r   )r
   r   r   r   r   2   s    zUnifiedReadWrite.registryc              
   C   s  | j }| j}|dkr| jjn| jj}z|r4|||ƒ}W n. tk
rd } zdt|ƒ }W 5 d}~X Y nŒX |rŠ|j› d|› d|› d�}	|j}
n|j› d|› d�}	t	||ƒj}
t
 dd|	¡}||	7 }|t
 dd|	¡7 }|tj7 }|
dk	rð|t |
¡7 }|dk�rd	dl}| |¡ n
| |¡ dS )
aó  Output help documentation for the specified unified I/O ``format``.

        By default the help output is printed to the console via ``pydoc.pager``.
        Instead one can supplied a file handle object as ``out`` and the output
        will be written to that handle.

        Parameters
        ----------
        format : str
            Unified I/O format name, e.g. 'fits' or 'ascii.ecsv'
        out : None or path-like
            Output destination (default is stdout via a pager)
        ÚreadzERROR: NÚ.z	(format='z') documentation
z general documentation
ú=r   )r   r	   r   Z
get_readerZ
get_writerr   ÚstrÚ__name__Ú__doc__ÚgetattrÚreÚsubÚosÚlinesepÚinspectÚcleandocÚpydocÚpagerÚwrite)r
   ÚformatÚoutr   r   Zget_funcZread_write_funcÚerrZ
reader_docÚheaderÚdocr   r   r   r   Úhelp7   s6    ÿ
ýÿ

zUnifiedReadWrite.helpc                 C   sR   | j  | j| j ¡ ¡}|d= |dkr4|jddd� n| d |jddd�¡¡ |S )z¶Print a list of available formats to console (or ``out`` filehandle)

        out : None or file handle object
            Output destination (default is stdout via a pager)
        z
Data classNéÿÿÿÿ)Ú	max_linesÚ	max_widthÚ
)	r   Zget_formatsr   r	   Ú
capitalizeÚpprintr!   ÚjoinÚpformat)r
   r#   Ztblr   r   r   Úlist_formatsm   s    zUnifiedReadWrite.list_formats)N)NN)N)	r   Ú
__module__Ú__qualname__r   r   Úpropertyr   r'   r0   r   r   r   r   r      s   
	

6c                   @   s   e Zd ZdZdd„ ZdS )r   a¥  Descriptor class for creating read() and write() methods in unified I/O.

    The canonical example is in the ``Table`` class, where the ``connect.py``
    module creates subclasses of the ``UnifiedReadWrite`` class.  These have
    custom ``__call__`` methods that do the setup work related to calling the
    registry read() or write() functions.  With this, the ``Table`` class
    defines read and write methods as follows::

      read = UnifiedReadWriteMethod(TableRead)
      write = UnifiedReadWriteMethod(TableWrite)

    Parameters
    ----------
    func : `~astropy.io.registry.UnifiedReadWrite` subclass
        Class that defines read or write functionality

    c                 C   s   |   ||¡S )N)Úfget)r
   r   Z	owner_clsr   r   r   Ú__get__›   s    zUnifiedReadWriteMethod.__get__N)r   r1   r2   r   r5   r   r   r   r   r   �   s   )	r   r   r   Úbaser   Ú__all__r   r3   r   r   r   r   r   Ú<module>   s   r