
    gg!                     4   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 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 jC                  ddddd       e jC                  ddd !       e jC                  d"d#d$d%gd$d&'       e jC                  d(d)ed*+       e jC                  d,d-!       e jC                  d.d/ ejD                  d0      1       e jC                  d2d3!       d4 Z#d5 Z$ejJ                  d6d fd7Z&ejN                  ejP                  ejR                  fd8Z*y# e$ r
 ddlmZ Y fw xY w)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y)_CannotLoadFileN)__name__
__module____qualname__     C/var/www/openai/venv/lib/python3.12/site-packages/jsonschema/cli.pyr   r   #   s    r   r   c                   d    e Zd Z e       Z e       Z e       Zed        Zd Z	d Z
d Zd Zd Zy)
_Outputterc                 j    |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.   sB    X')'	.(ABIx H,(*IYvfEEr   c                 z   	 t        |      }|5  	 t        j                  |      cd d d        S # t        $ r5}| j                  |t        j                                t               |d }~ww xY w# t        $ r5}| j                  |t        j                                t               |d }~ww xY w# 1 sw Y   y xY w)Npathexc_info)
openFileNotFoundErrorfilenotfound_errorsysr)   r   jsonloadr   parsing_error)selfr(   fileerrors       r   r/   z_Outputter.load6   s    	/:D
 3yy T	 ! 	/###G!#.	/ # 3""s||~"F%'U23 Ts<   / B1A0	A-0A((A-0	B.90B))B..B11B:c                 n    | j                   j                   | j                  j                  di |       y Nr   )_stderrwrite
_formatterr,   r1   kwargss     r   r,   z_Outputter.filenotfound_errorD   )    =4??==GGHr   c                 n    | j                   j                   | j                  j                  di |       y r5   )r6   r7   r8   r0   r9   s     r   r0   z_Outputter.parsing_errorG   s)    84??88B6BCr   c                 n    | j                   j                   | j                  j                  di |       y r5   )r6   r7   r8   validation_errorr9   s     r   r>   z_Outputter.validation_errorJ   s)    ;4??;;EfEFr   c                 n    | j                   j                   | j                  j                  di |       y r5   )_stdoutr7   r8   validation_successr9   s     r   rA   z_Outputter.validation_successM   r;   r   N)r   r   r   r	   r8   r@   r6   classmethodr%   r/   r,   r0   r>   rA   r   r   r   r   r   '   sJ     JgGgGF F3IDGIr   r   c                   8    e Zd Z ed      ZdZd Zd Zd Zd Z	y)r"   z`        ===[{type}]===({path})===

        {body}
        -----------------------------
        z===[SUCCESS]===({path})===
c                 D    | j                   j                  |d|d      S )Nr+   z does not exist.r(   typebody)
_ERROR_MSGformatr1   r(   r)   s      r   r,   z#_PrettyFormatter.filenotfound_error^   s/    %%$8+, & 
 	
r   c                     |\  }}}dj                  t        j                  |||            }| j                  j	                  ||j
                  |      S )N rE   )join	tracebackformat_exceptionrH   rI   r   )r1   r(   r)   exc_type	exc_valueexc_traceback	exc_liness          r   r0   z_PrettyFormatter.parsing_errore   s[    -5*)]GG&&xMJ
	 %%"" & 
 	
r   c                 f    | j                   j                  ||j                  j                  |      S )NrE   )rH   rI   	__class__r   r1   instance_pathr3   s      r   r>   z!_PrettyFormatter.validation_errorp   s1    %%)) & 
 	
r   c                 :    | j                   j                  |      S )N)r(   )_SUCCESS_MSGrI   r1   rW   s     r   rA   z#_PrettyFormatter.validation_successw   s      '']';;r   N)
r   r   r   r   rH   rY   r,   r0   r>   rA   r   r   r   r"   r"   Q   s.     	J 2L
	

<r   r"   c                   2    e Zd Z e       Zd Zd Zd Zd Zy)r!   c                     |dS )Nz does not exist.
r   rJ   s      r   r,   z"_PlainFormatter.filenotfound_error   s    +,,r   c                 L    dj                  |dk(  rdn
t        |      |d         S )NzFailed to parse {}: {}
<stdin>   )rI   reprrJ   s      r   r0   z_PlainFormatter.parsing_error   s,    )00*IT
QK
 	
r   c                 <    | j                   j                  ||      S )N)	file_namer3   )_error_formatrI   rV   s      r   r>   z _PlainFormatter.validation_error   s    !!((=(NNr   c                      y)NrL   r   rZ   s     r   rA   z"_PlainFormatter.validation_success   s    r   N)	r   r   r   r	   rc   r,   r0   r>   rA   r   r   r   r!   r!   {   s      GM-
Or   r!   c                 *    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.
    )rF   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        j                  | xs dg            }|d   dk7  r|d   rt        j                  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_argsr3   )rv   r$   s     r   ry   ry      sr    V&&D,>XJ&?@Ig%)N*CllA
 	
 g%)N*C*K$I	.!r   c                     d}|j                  |      D ]  }d}|j                  | |        |s|j                  |        |S )NFTrW   r3   )rW   )iter_errorsr>   rA   )rW   instance	validator	outputterinvalidr3   s         r   _validate_instancer      sO    G&&x0""e"L 1 $$=$ANr   r_   c                 V    t        j                  t        t        |                    y )Nru   )r$   )r-   exitrunry   ru   s    r   mainr      s    HHS:4012r   c                    t         j                  | ||      	 j                  | d         }| d   }|t	        |      }	 |j                  |       | d   rj                  | d   }}n	fd}dg}| d	   t        | d	   |
      nd }	 |||	      }
d}|D ]  }	  ||      }|t        |||
      z  } |S # t        $ r Y yw xY w# t        $ r }j                  | d   |       Y d }~yd }~ww xY w# t        $ r d}Y jw xY w)N)r$   r   r    rs   r_   r~   r{   rk   c                     	 t        j                        S # t        $ r5}j                  dt	        j
                                t               |d }~ww xY w)Nr^   r'   )r.   r/   r   r0   r-   r)   r   )_r3   r   stdins     r   r/   zrun.<locals>.load
  sR    3yy''" 3''"S\\^ (  &'U2	3s    	A0AAr^   base_uri)r   referrer)resolverr   )rW   r}   r~   r   )
r   r%   r/   r   r   check_schemar
   r>   r   r   )r$   r   r    r   rs   	Validatorr3   r/   rk   r   r~   	exit_codeeachr}   r   s      `          @r   r   r      so   )) * I	( 34 +&I!&)	v& #..)K*@i	3 K	
 
:		* :& 15 
 &84II
	DzH +"!##	 I  c    ""#H- 	# 	
 <  	I	s;   B; C
 C6;	CC
	C3C..C36DD)+__doc__	importlibr   r.   r   textwrapr   argparser-   rN   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$   - = 	: 	i 	 &I &I &IR &< &< &<R   ( 
!	 	 ,
   ,	
	  	   

  
   *h
	  	   -	#
     
     H\*  
   	H   hhqrl 3 **SZZsyy :}  2112s   F FF