
    QEe                      n   d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddl	Z	ddl
Z
	 ddlmZ n# e$ r	 ddlmZ Y nw xY wddlmZmZ ddlmZ dd	lmZmZ  e
j        d
ed            G d de          Ze G d d                      Ze G d d                      Ze G d d                      Zd Z ej        d          Z e !                    ddddd           e !                    ddd !           e !                    d"d#d$d%gd$d&'           e !                    d(d)ed*+           e !                    d,d-!           e !                    d.d/ ej"        d0          1           e !                    d2d3!           d4 Z#d5 Z$ej%        d6d         fd7Z&ej'        ej(        ej)        fd8Z*dS )9z"
The ``jsonschema`` command line.
    )metadata)JSONDecodeError)dedentNresolve_name)definefield)SchemaError)_RefResolvervalidator_forzThe jsonschema CLI is deprecated and will be removed in a future version. Please use check-jsonschema instead, which can be installed from https://pypi.org/project/check-jsonschema/   )
stacklevelc                       e Zd ZdS )_CannotLoadFileN)__name__
__module____qualname__     .lib/python3.11/site-packages/jsonschema/cli.pyr   r   #   s        Dr   r   c                   ~    e Zd Z e            Z e            Z e            Zed             Zd Z	d Z
d Zd Zd ZdS )
_Outputterc                     |d         dk    rt          |d                   }n|d         dk    rt                      } | |||          S )Noutputplainerror_formatpretty)	formatterstdoutstderr)_PlainFormatter_PrettyFormatter)cls	argumentsr   r    r   s        r   from_argumentsz_Outputter.from_arguments.   sX    X'))'	.(ABBIIx H,,(**IsYvfEEEEr   c                    	 t          |          }nD# t          $ r7 |                     |t          j                               t                      w xY w|5  	 t          j        |          cd d d            S # t          $ r7 | 	                    |t          j                               t                      w xY w# 1 swxY w Y   d S )Npathexc_info)
openFileNotFoundErrorfilenotfound_errorsysr)   r   jsonloadr   parsing_error)selfr(   files      r   r/   z_Outputter.load6   s   	$::DD  	$ 	$ 	$###GGG!###	$  	( 	((y	( 	( 	( 	( 	( 	( 	( 	( # ( ( (""s|~~"FFF%'''(	( 	( 	( 	( 	( 	( 	( 	( 	( 	(s/    AAB>A::AB;;B>>CCc                 Z    | j                              | j        j        di |           d S Nr   )_stderrwrite
_formatterr,   r1   kwargss     r   r,   z_Outputter.filenotfound_errorD   4    =4?=GGGGHHHHHr   c                 Z    | j                              | j        j        di |           d S r4   )r5   r6   r7   r0   r8   s     r   r0   z_Outputter.parsing_errorG   s4    84?8BB6BBCCCCCr   c                 Z    | j                              | j        j        di |           d S r4   )r5   r6   r7   validation_errorr8   s     r   r=   z_Outputter.validation_errorJ   s4    ;4?;EEfEEFFFFFr   c                 Z    | j                              | j        j        di |           d S r4   )_stdoutr6   r7   validation_successr8   s     r   r@   z_Outputter.validation_successM   r:   r   N)r   r   r   r	   r7   r?   r5   classmethodr%   r/   r,   r0   r=   r@   r   r   r   r   r   '   s         JeggGeggGF F [F( ( (I I ID D DG G GI I I I Ir   r   c                   @    e Zd Z ed          ZdZd Zd Zd Zd Z	dS )r"   z`        ===[{type}]===({path})===

        {body}
        -----------------------------
        z===[SUCCESS]===({path})===
c                 b    | j                             |dd                    |                    S )Nr+   z{!r} does not exist.r(   typebody)
_ERROR_MSGformatr1   r(   r)   s      r   r,   z#_PrettyFormatter.filenotfound_error^   s8    %%$'..t44 & 
 
 	
r   c                     |\  }}}d                     t          j        |||                    }| j                            ||j        |          S )N rD   )join	tracebackformat_exceptionrG   rH   r   )r1   r(   r)   exc_type	exc_valueexc_traceback	exc_liness          r   r0   z_PrettyFormatter.parsing_errore   s`    -5*)]GG&xMJJ
 
	 %%" & 
 
 	
r   c                 P    | j                             ||j        j        |          S )NrD   )rG   rH   	__class__r   r1   instance_patherrors      r   r=   z!_PrettyFormatter.validation_errorp   s/    %%) & 
 
 	
r   c                 8    | j                             |          S )N)r(   )_SUCCESS_MSGrH   r1   rV   s     r   r@   z#_PrettyFormatter.validation_successw   s     '']';;;r   N)
r   r   r   r   rG   rY   r,   r0   r=   r@   r   r   r   r"   r"   Q   so         	 J 2L
 
 
	
 	
 	

 
 
< < < < <r   r"   c                   :    e Zd Z e            Zd Zd Zd Zd ZdS )r!   c                 ,    d                     |          S )Nz{!r} does not exist.
)rH   rI   s      r   r,   z"_PlainFormatter.filenotfound_error   s    '..t444r   c                 d    d                     |dk    rdnt          |          |d                   S )NzFailed to parse {}: {}
<stdin>   )rH   reprrI   s      r   r0   z_PlainFormatter.parsing_error   s8    )00**IIT

QK
 
 	
r   c                 :    | j                             ||          S )N)	file_namerW   )_error_formatrH   rU   s      r   r=   z _PlainFormatter.validation_error   s    !((=(NNNr   c                     dS )NrK   r   rZ   s     r   r@   z"_PlainFormatter.validation_success   s    rr   N)	r   r   r   r	   rc   r,   r0   r=   r@   r   r   r   r!   r!   {   s`         EGGM5 5 5
 
 
O O O    r   r!   c                 2    d| vrd| z   } t          |           S )N.zjsonschema.r   )names    r   _resolve_name_with_defaultrh      s#    
$t#r   zJSON Schema Validation CLI)descriptionz-iz
--instanceappend	instancesz
        a path to a JSON instance (i.e. filename.json) to validate (may
        be specified multiple times). If no instances are provided via this
        option, one will be expected on standard input.
    )actiondesthelpz-Fz--error-formata  
        the format to use for each validation error message, specified
        in a form suitable for str.format. This string will be passed
        one formatted object named 'error' for each ValidationError.
        Only provide this option when using --output=plain, which is the
        default. If this argument is unprovided and --output=plain is
        used, a simple default representation will be used.
    )rn   z-oz--outputr   r   z
        an output format to use. 'plain' (default) will produce minimal
        text with one line for each error, while 'pretty' will produce
        more detailed human-readable output on multiple lines.
    )choicesdefaultrn   z-Vz--validatorz
        the fully qualified object name of a validator to use, or, for
        validators that are registered with jsonschema, simply the name
        of the class.
    )rE   rn   z
--base-uriz
        a base URI to assign to the provided schema, even if it does not
        declare one (via e.g. $id). This option can be used if you wish to
        resolve relative references to a particular URI (or local path)
    z	--versionversion
jsonschema)rl   rq   schemaz=the path to a JSON Schema to validate with (i.e. schema.json)c                     t          t                              | pdg                    }|d         dk    r"|d         rt                              d          |d         dk    r|d         d|d<   |S )Nz--helpargsr   r   r   z3--error-format can only be used with --output plainz"{error.instance}: {error.message}
)varsparser
parse_argsrW   )rv   r$   s     r   ry   ry      s    V&&D,>XJ&??@@Ig%%)N*C%llA
 
 	
 g%%)N*C*K$I	.!r   c                     d}|                     |          D ]}d}|                    | |           |s|                    |            |S )NFTrV   rW   )rV   )iter_errorsr=   r@   )rV   instance	validator	outputterinvalidrW   s         r   _validate_instancer      sl    G&&x00 M M""e"LLLL B$$=$AAANr   r_   c                 f    t          j        t          t          |                                d S )Nru   )r$   )r-   exitrunry   ru   s    r   mainr      s.    HS:400011122222r   c                 ~   t                               | ||          	                     | d                   }n# t          $ r Y dS w xY w| d         }|t	          |          }	 |                    |           n5# t          $ r(}                    | d         |           Y d }~dS d }~ww xY w| d         rj        | d         }}n	fd}dg}| d	         t          | d	         |
          nd }	 |||	          }
d}|D ]6}	  ||          }|t          |||
          z  }%# t          $ r d}Y 3w xY w|S )N)r$   r   r    rs   r_   r~   r{   rk   c                     	 t          j                  S # t          $ r7                     dt	          j                               t                      w xY w)Nr^   r'   )r.   r/   r   r0   r-   r)   r   )_r   stdins    r   r/   zrun.<locals>.load
  si    (y'''" ( ( (''"S\^^ (    &'''	(s
    AAr^   base_uri)r   referrer)resolverr   )rV   r}   r~   r   )
r   r%   r/   r   r   check_schemar
   r=   r   r   )r$   r   r    r   rs   	ValidatorrW   r/   rk   r   r~   	exit_codeeachr}   r   s      `          @r   r   r      s   )) *  I	( 344   qq +&I!&))	v&&&&   ""#H- 	# 	
 	
 	
 qqqqq   #.)K*@i	( 	( 	( 	( 	( 	( K	
 
:		* :&    15 
 	&8444II  
	tDzzH +"!##	   II  	 	 	III	 s9   = 
A
A(A> >
B0B++B0	D++D:9D:)+__doc__	importlibr   r.   r   textwrapr   argparser-   rM   warningspkgutilr   ImportErrorpkgutil_resolve_nameattrsr   r	   jsonschema.exceptionsr
   jsonschema.validatorsr   r   warnDeprecationWarning	Exceptionr   r   r"   r!   rh   ArgumentParserrx   add_argumentrq   ry   r   argvr   r   r    r   r   r   r   r   <module>r      s                              



     2$$$$$$$ 2 2 2111111112          - - - - - - = = = = = = = = 	:    	 	 	 	 	i 	 	 	 &I &I &I &I &I &I &I &IR &< &< &< &< &< &< &< &<R        (   
!	 ,
 
 
   ,	
	  	 	 	   

  
 
 
   *h
	  	 	 	   -	#
       
       H\**    
   	H         hqrrl 3 3 3 3 *SZsy : : : : : :s   1 ??