
    dF!                        d 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Z
Y nw xY w	 ddlmZ n# e$ r	 ddlmZ Y nw xY wddlZddlmZ ddlmZmZ  ej        d	ed
            G d de          Zej         G d d                      Zej         G d d                      Zej         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"        d/          0           e !                    d1d2            d3 Z#d4 Z$ej%        d5d         fd6Z&ej'        ej(        ej)        fd7Z*dS )8z"
The ``jsonschema`` command line.
    )JSONDecodeError)dedentN)metadataresolve_name)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__     R/home/feoh/.local/pipx/venvs/poetry/lib/python3.11/site-packages/jsonschema/cli.pyr   r   '   s        Dr   r   c                       e Zd Z ej                    Z ej                    Z ej                    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_arguments2   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.load:   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*   r/   kwargss     r   r*   z_Outputter.filenotfound_errorH   4    =4?=GGGGHHHHHr   c                 Z    | j                              | j        j        di |           d S r2   )r3   r4   r5   r.   r6   s     r   r.   z_Outputter.parsing_errorK   s4    84?8BB6BBCCCCCr   c                 Z    | j                              | j        j        di |           d S r2   )r3   r4   r5   validation_errorr6   s     r   r;   z_Outputter.validation_errorN   s4    ;4?;EEfEEFFFFFr   c                 Z    | j                              | j        j        di |           d S r2   )_stdoutr4   r5   validation_successr6   s     r   r>   z_Outputter.validation_successQ   r8   r   N)r   r   r   attribr5   r=   r3   classmethodr#   r-   r*   r.   r;   r>   r   r   r   r   r   +   s         JdgiiGdgiiG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r/   r&   r'   s      r   r*   z#_PrettyFormatter.filenotfound_errorb   s8    %%$'..t44 & 
 
 	
r   c                     |\  }}}d                     t          j        |||                    }| j                            ||j        |          S )N rD   )join	tracebackformat_exceptionrG   rH   r   )r/   r&   r'   exc_type	exc_valueexc_traceback	exc_liness          r   r.   z_PrettyFormatter.parsing_errori   s`    -5*)]GG&xMJJ
 
	 %%" & 
 
 	
r   c                 P    | j                             ||j        j        |          S )NrD   )rG   rH   	__class__r   r/   instance_patherrors      r   r;   z!_PrettyFormatter.validation_errort   s/    %%) & 
 
 	
r   c                 8    | j                             |          S )N)r&   )_SUCCESS_MSGrH   r/   rV   s     r   r>   z#_PrettyFormatter.validation_success{   s     '']';;;r   N)
r   r   r   r   rG   rY   r*   r.   r;   r>   r   r   r   r    r    U   so         	 J 2L
 
 
	
 	
 	

 
 
< < < < <r   r    c                   D    e Zd Z ej                    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   r.   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?   r@   rc   r*   r.   r;   r>   r   r   r   r   r      sb         DGIIM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	          |          | d<   	 | d                             |           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}
|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   r.   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   rW   r-   rk   r   r~   	exit_codeeachr}   r   s      `         @r   r   r      s   )) *  I	( 344   qq %!.v!6!6	++++F3333   ""#H- 	# 	
 	
 	
 qqqqq   #.)K*@i	( 	( 	( 	( 	( 	( K	
 
:		* :&    15 
 '	+&vAAAII  
	tDzzH +"!##	   II  	 	 	III	 s9   = 
A
A)B 
B7B22B7D88EE)+__doc__r,   r   textwrapr   argparser+   rM   warnings	importlibr   ImportErrorimportlib_metadatapkgutilr   pkgutil_resolve_namer?   jsonschema.exceptionsr   jsonschema.validatorsr	   r
   warnDeprecationWarning	Exceptionr   sr   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 9 9 9 9 9 9s   + 	77A AA