
    HR-e                         d Z ddlZddlZddlZddlZddlmZ ddlmZ  ej	        d          Z
d                                Zd Zd Zd	 Zd
 Zd Zd ZddZdS )a  
``fitscheck`` is a command line script based on astropy.io.fits for verifying
and updating the CHECKSUM and DATASUM keywords of .fits files.  ``fitscheck``
can also detect and often fix other FITS standards violations.  ``fitscheck``
facilitates re-writing the non-standard checksums originally generated by
astropy.io.fits with standard checksums which will interoperate with CFITSIO.

``fitscheck`` will refuse to write new checksums if the checksum keywords are
missing or their values are bad.  Use ``--force`` to write new checksums
regardless of whether or not they currently exist or pass.  Use
``--ignore-missing`` to tolerate missing checksum keywords without comment.

Example uses of fitscheck:

1. Add checksums::

    $ fitscheck --write *.fits

2. Write new checksums, even if existing checksums are bad or missing::

    $ fitscheck --write --force *.fits

3. Verify standard checksums and FITS compliance without changing the files::

    $ fitscheck --compliance *.fits

4. Only check and fix compliance problems,  ignoring checksums::

    $ fitscheck --checksum none --compliance --write *.fits

5. Verify standard interoperable checksums::

    $ fitscheck *.fits

6. Delete checksum keywords::

    $ fitscheck --checksum remove --write *.fits

    N)__version__)fits	fitscheckag  
e.g. fitscheck example.fits

Verifies and optionally re-writes the CHECKSUM and DATASUM keywords
for a .fits file.
Optionally detects and fixes FITS standard compliance problems.

This script is part of the Astropy package. See
https://docs.astropy.org/en/latest/io/fits/usage/scripts.html#module-astropy.io.fits.scripts.fitscheck
for further documentation.
c                 0   t          |           sdg} t          j        t          t          j                  }|                    dddt                      |                    ddd	d
           |                    dddg ddd           |                    dddddd           |                    dddddd           |                    ddd d!dd           |                    d"d#d$d%dd           |                    d&d'd(d)dd           |                    |           at          j	        d*k    rdt          _	        nEt          j	        dk    rd+t          _	        n(t          j	        d,k    rd+t          _
        d+t          _        t          j        S )-Nz-h)descriptionformatter_classz	--versionversionz	%(prog)s )actionr	   
fits_filesfile+z.fits files to process.)metavarnargshelpz-kz
--checksumchecksum_kind)standardremovenonez6Choose FITS checksum mode or none.  Defaults standard.r   )destchoicesr   defaultz-wz--write
write_filez6Write out file checksums and/or FITS compliance fixes.F
store_true)r   r   r   r
   z-fz--forceforcez1Do file update even if original checksum was bad.z-cz--compliance
compliancez-Do FITS compliance checking; fix if possible.z-iz--ignore-missingignore_missingzIgnore missing checksums.z-vz	--verboseverbosezGenerate extra output.r   Tr   )lenargparseArgumentParserDESCRIPTIONRawDescriptionHelpFormatteradd_argumentr   
parse_argsOPTIONSr   r   r   r   )argsparsers     Alib/python3.11/site-packages/astropy/io/fits/scripts/fitscheck.pyhandle_optionsr)   B   s'   t99 v$1U  F I/H;/H/H     fC6O     ...E     E     @     <     (     %     %%G&& %		*	,	, $		(	*	*!    c                     t           j                                         t          j        r%t                               t          j                   n$t                               t          j                   t          j	                    } | 
                    t          j        d                     t                               |            d S )Nz%(message)s)loghandlersclearr%   r   setLevelloggingINFOWARNINGStreamHandlersetFormatter	Formatter
addHandler)handlers    r(   setup_loggingr8      s    L &W\""""W_%%%#%%G*=99:::NN7r*   c           	      0   t          j        d          5 }t          j        d           t          j        | t
          j                  5 }t          |          D ]\  }}t
          j        s|j	        s9t                              d| d|             ddd           ddd           dS |j        s9t                              d| d	|             ddd           ddd           dS 	 ddd           n# 1 swxY w Y   ddd           n# 1 swxY w Y   |D ]Z}t          |j                                      d
          r1t                              d| t          |j                              dS [t                              d|            dS )zR
    Prints a message if any HDU in `filename` has a bad checksum or datasum.
    T)recordalways)checksumzMISSING z .. Checksum not found in HDU #N   z .. Datasum not found in HDU #)zChecksum verification failedzDatasum verification failedz	BAD %r %szOK r   )warningscatch_warningssimplefilterr   openr%   r   	enumerater   	_checksumr,   warning_datasumstrmessage
startswithinfo)filenamewlisthdulistihduws         r(   verify_checksumsrP      s    
	 	-	-	- !h'''Yx'*?@@@ 	!G#G,, ! !3 - 
!= !UxUURSUU    !	! 	! 	! 	! 	! 	!! ! ! ! ! ! ! ! < !TxTTQRTT    !	! 	! 	! 	! 	! 	!! ! ! ! ! ! ! !!	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	! 	!! ! ! ! ! ! ! ! ! ! ! ! ! ! !$   qy>>$$K
 
 	 KKXs19~~>>>11		 HH8   1sN   5DA	C:D,(C:D,C:.D:C>	>DC>	DDDc           
      X   t          j        |           5 }	 |                    d           ne# t           j        $ rS}t                              d| t          |                              dd                     Y d}~ddd           dS d}~ww xY w	 ddd           n# 1 swxY w Y   dS )z#Check for FITS standard compliance.	exceptionzNONCOMPLIANT %r .. %s
 Nr=   r   )r   rA   verifyVerifyErrorr,   rD   rF   replace)rJ   rL   excs      r(   verify_compliancerY      s   	8		 	NN;'''' 	 	 	KK/3s88;K;KDRU;V;VWWW111       	 (               1s6   B-BB=B
9B
BBB#&B#c                 D   t           j        rdnd}t          j                    5  t          j                     t          j        | dt           j        d          5 }|                    |           ddd           n# 1 swxY w Y   ddd           dS # 1 swxY w Y   dS )z
    Sets the ``CHECKSUM`` and ``DATASUM`` keywords for each HDU of `filename`.

    Also updates fixes standards violations if possible and requested.
    	silentfixignoreTupdate)do_not_scale_image_datar<   mode)output_verifyN)	r%   r   r>   r?   resetwarningsr   rA   r   flush)rJ   r`   rL   s      r(   r]   r]      s(    $+#5CKK8M 
	 	"	" 7 7   Y$(*	
 
 
 	7
 MMM666	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	7 	77 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7 7s5   6BA=1B=B	BB	BBBc                 2   	 t          |           }t          j        rt          |           }nd}t          j        r|dk    st          j        rt          |            ||z   S # t          $ r+}t          	                    d| d|            Y d}~dS d}~ww xY w)za
    Handle a single .fits file,  returning the count of checksum and compliance
    errors.
    r   z
EXCEPTION z .. Nr=   )
rP   r%   r   rY   r   r   r]   	Exceptionr,   error)rJ   checksum_errorscompliance_errorses       r(   process_fileri      s    
*844 	" 1( ; ; ! 	/Q"6"6'-"68!222   		2x22q22333qqqqqs   AA! !
B+ BBc                    d}t          | pt          j        dd                   }t                       |D ]}|t	          |          z  }|rt
                              | d           t          t          |                    S )z
    Processes command line parameters into options and files,  then checks
    or update FITS DATASUM and CHECKSUM keywords for the specified files.
    r   r=   Nz errors)	r)   sysargvr8   ri   r,   rD   intbool)r&   errorsr   rJ   s       r(   mainrp      s    
 F 455JOOO ) ),x((( (v&&&'''tF||r*   )N)__doc__r   r0   rk   r>   astropyr   
astropy.ior   	getLoggerr,   stripr!   r)   r8   rP   rY   r]   ri   rp    r*   r(   <module>rw      s   & &R   



             g$$
 
EGG Q Q Qh
 
 
  B  7 7 70  &     r*   