
    HR-e                     h    d dl Z d dlZd dlZddlmZ ddgZ G d d          Z G d de          ZdS )    N   )IORegistryErrorUnifiedReadWriteMethodUnifiedReadWritec                   @    e Zd ZdZddZed             ZddZ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                 N    |ddl m} || _        || _        || _        || _        d S )Nr   )default_registry)astropy.io.registry.compatr	   	_registry	_instance_cls_method_name)selfinstanceclsmethod_nameregistrys        =lib/python3.11/site-packages/astropy/io/registry/interface.py__init__zUnifiedReadWrite.__init__)   s=    OOOOOO!!	'    c                     | j         S )zUnified I/O registry instance.)r   )r   s    r   r   zUnifiedReadWrite.registry2   s     ~r   c                 d   | j         }| j        }|dk    r| j        j        n| j        j        }	 |r |||          }|r|j         d| d| d}|j        }n"|j         d| d}t          ||          j        }t          j	        dd|          }	|	|z  }	|	t          j	        dd|          z  }	|	t          j        z  }	||	t          j        |          z  }	n)# t          $ r}
dt          |
          z   }	Y d}
~
nd}
~
ww xY w|d	dl}|                    |	           dS |                    |	           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)
        read.z	(format='z') documentation
z general documentation
=NzERROR: r   )r   r   r   
get_reader
get_writer__name____doc__getattrresuboslinesepinspectcleandocr   strpydocpagerwrite)r   formatoutr   r   get_funcread_write_funcheaderdoc
reader_docerrr(   s               r   helpzUnifiedReadWrite.help7   s    i'
 f$$ N%%* 	
	4 8"*(63"7"7  	8 |VVkVVFVVV  &-  LPP;PPPc;//7S&11J& J"&c6222J"*$Jg.s333
'  	. 	. 	."SXX-JJJJJJ	.* ;LLLKK
#####IIj!!!!!s   C 
C;C66C;c                 (   | j                             | j        | j                                                  }|d= ||                    dd           n=|                    d                    |                    dd                               |S )zPrint 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   get_formatsr   r   
capitalizepprintr*   joinpformat)r   r,   tbls      r   list_formatszUnifiedReadWrite.list_formatsm   s     n((D4E4P4P4R4RSS;JJrJ2222IIdiibB G GHHIII
r   N)NN)	r   
__module____qualname__r   r   propertyr   r3   r?    r   r   r   r      sv         2( ( ( (   X4" 4" 4" 4"l     r   c                       e Zd ZdZ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                 .    |                      ||          S r@   )fget)r   r   	owner_clss      r   __get__zUnifiedReadWriteMethod.__get__   s    yy9---r   N)r   rA   rB   r   rI   rD   r   r   r   r      s-         2. . . . .r   )	r%   r#   r!   baser   __all__r   rC   r   rD   r   r   <module>rL      s     				 				 ! ! ! ! ! !#%7
8l l l l l l l ld. . . . .X . . . . .r   