B
    q\                 @   s   d dl Z d dlZd dlmZ d dlmZ G dd deZG dd deZdd	d
ddddddddgZ	G dd dZ
G dd deZdS )    N)indent)AstropyUserWarningc               @   s   e Zd ZdZdS )VerifyErrorz!
    Verify exception class.
    N)__name__
__module____qualname____doc__ r	   r	   5lib/python3.7/site-packages/astropy/io/fits/verify.pyr   
   s   r   c               @   s   e Zd ZdZdS )VerifyWarningz
    Verify warning class.
    N)r   r   r   r   r	   r	   r	   r
   r      s   r   ignorewarn	exceptionfix	silentfixz
fix+ignorezfix+warnzfix+exceptionzsilentfix+ignorezsilentfix+warnzsilentfix+exceptionc               @   s$   e Zd ZdZdddZdd	d
ZdS )_Verifyz*
    Shared methods for verification.
    r    Fixed.NTc             C   s@   |}|dkrd}n&|s"d |}n|r,|  |d| 7 }||fS )z@
        Execute the verification with selected option.
        )r   r   FzUnfixable error: {}z  )format)selfoptionZerr_textZfix_textr   fixabletextr	   r	   r
   
run_option    s    z_Verify.run_optionc             C   sh  |  }|tkrtd||dkr*dS | |}d|krL|d\}}n|dkr`|d }}n
d| }}|dkr~|dkr~dS |dkrdd	 }n |d
kr|dkrtd}nd}d}g }x0|j|dD ] \}	}
|	dk	r|	 }|	|
 qW |rd|
dd |	d |dkr|sdS |dks4|d
krR|sRx.|D ]}t|t q:W ntdd| dS )a  
        Verify all values in the instance.

        Parameters
        ----------
        option : str
            Output verification option.  Must be one of ``"fix"``,
            ``"silentfix"``, ``"ignore"``, ``"warn"``, or
            ``"exception"``.  May also be any combination of ``"fix"`` or
            ``"silentfix"`` with ``"+ignore"``, ``+warn``, or ``+exception"
            (e.g. ``"fix+warn"``).  See :ref:`verify` for more info.
        zOption {!r} not recognized.r   N+)r   r   r   r   c             S   s
   | d  S )Nr   r	   )xr	   r	   r
   <lambda>]   s    z _Verify.verify.<locals>.<lambda>r   r   F)filterzVerification reported errors:z0Note: astropy.io.fits uses zero-based indexing.
r   
)lowerVERIFY_OPTIONS
ValueErrorr   Z_verifysplitoperator
itemgetter
iter_linesappendinsertwarningsr   r   r   join)r   r   ZoptZerrsZfix_optZ
report_optZline_filterZ	unfixableZmessagesr   messageliner	   r	   r
   verify4   sB    




z_Verify.verify)r   r   r   NT)r   )r   r   r   r   r   r,   r	   r	   r	   r
   r      s    
r   c                   s4   e Zd ZdZd fdd	Zdd Zdd
dZ  ZS )_ErrListz
    Verification errors list class.  It has a nested list structure
    constructed by error messages generated by verifications at
    different class levels.
    r	   Elementc                s   t  | || _d S )N)super__init__unit)r   valr1   )	__class__r	   r
   r0      s    z_ErrList.__init__c             C   s   d dd |  D S )Nr   c             s   s   | ]}|d  V  qdS )   Nr	   ).0itemr	   r	   r
   	<genexpr>   s    z#_ErrList.__str__.<locals>.<genexpr>)r)   r%   )r   r	   r	   r
   __str__   s    z_ErrList.__str__Nr   c          	   c   s   d}x@| D ]8}t |ts
|dks(||r
|d t|d |dfV  q
W x| D ]}t |trL|j||d d}yt|}W n tk
r   d}Y nX |dk	r| jrdtd| j||dfV  |V  x|D ]
}|V  qW |d7 }qLW dS )z
        Iterate the nested structure as a list of strings with appropriate
        indentations for each level of structure.
        r   Nr4   )shift)r   r9   z{} {}:)
isinstancer-   r   r%   nextStopIterationr1   r   )r   r   r9   elementr6   Z
next_linesZ
first_liner+   r	   r	   r
   r%      s(    






z_ErrList.iter_lines)r	   r.   )Nr   )r   r   r   r   r0   r8   r%   __classcell__r	   r	   )r3   r
   r-   z   s   r-   )r#   r(   Zastropy.utilsr   Zastropy.utils.exceptionsr   	Exceptionr   r   r    r   listr-   r	   r	   r	   r
   <module>   s   

_