o
    gg!                     @   s  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
zddlmZ W n ey?   ddlmZ Y n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d G dd deZeG dd dZeG dd dZeG dd dZdd ZejddZ e j!dddddd e j!dd d!d" e j!d#d$d%d&gd%d'd( e j!d)d*ed+d, e j!d-d.d" e j!d/d0e"d1d2 e j!d3d4d" d5d6 Z#d7d8 Z$ej%d9d fd:d;Z&ej'ej(ej)fd<d=Z*dS )>z"
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                   @   s   e Zd ZdS )_CannotLoadFileN)__name__
__module____qualname__ r   r   J/var/www/html/chatdoc2/venv/lib/python3.10/site-packages/jsonschema/cli.pyr   #   s    r   c                   @   sR   e Zd Ze Ze Ze Zedd Zdd Z	dd Z
dd Zd	d
 Zdd ZdS )
_Outputterc                 C   s:   |d dkrt |d }n	|d dkrt }| |||dS )Noutputplainerror_formatpretty)	formatterstdoutstderr)_PlainFormatter_PrettyFormatter)cls	argumentsr   r   r   r   r   r   from_arguments.   s
   z_Outputter.from_argumentsc                 C   s   zt |}W n ty } z| j|t d t |d }~ww |( zt|W W  d    S  tyI } z| j	|t d t |d }~ww 1 sMw   Y  d S )Npathexc_info)
openFileNotFoundErrorfilenotfound_errorsysr#   r   jsonloadr   parsing_error)selfr"   fileerrorr   r   r   r)   6   s"   
z_Outputter.loadc                 K      | j | jjdi | d S Nr   )_stderrwrite
_formatterr&   r+   kwargsr   r   r   r&   D      z_Outputter.filenotfound_errorc                 K   r.   r/   )r0   r1   r2   r*   r3   r   r   r   r*   G   r5   z_Outputter.parsing_errorc                 K   r.   r/   )r0   r1   r2   validation_errorr3   r   r   r   r6   J   r5   z_Outputter.validation_errorc                 K   r.   r/   )_stdoutr1   r2   validation_successr3   r   r   r   r8   M   r5   z_Outputter.validation_successN)r   r   r   r   r2   r7   r0   classmethodr    r)   r&   r*   r6   r8   r   r   r   r   r   '   s    
r   c                   @   s8   e Zd ZedZdZdd Zdd Zdd Zd	d
 Z	dS )r   z`        ===[{type}]===({path})===

        {body}
        -----------------------------
        z===[SUCCESS]===({path})===
c                 C   s   | j j|d|ddS )Nr%   z does not exist.r"   typebody)
_ERROR_MSGformatr+   r"   r#   r   r   r   r&   ^   s
   z#_PrettyFormatter.filenotfound_errorc                 C   s2   |\}}}d t|||}| jj||j|dS )N r:   )join	tracebackformat_exceptionr=   r>   r   )r+   r"   r#   exc_type	exc_valueexc_traceback	exc_linesr   r   r   r*   e   s   
z_PrettyFormatter.parsing_errorc                 C   s   | j j||jj|dS )Nr:   )r=   r>   	__class__r   r+   instance_pathr-   r   r   r   r6   p   s
   z!_PrettyFormatter.validation_errorc                 C   s   | j j|dS )N)r"   )_SUCCESS_MSGr>   r+   rJ   r   r   r   r8   w   s   z#_PrettyFormatter.validation_successN)
r   r   r   r   r=   rK   r&   r*   r6   r8   r   r   r   r   r   Q   s    r   c                   @   s2   e Zd Ze Zdd Zdd Zdd Zdd Zd	S )
r   c                 C   s
   |dS )Nz does not exist.
r   r?   r   r   r   r&      s   
z"_PlainFormatter.filenotfound_errorc                 C   s    d |dkrdnt||d S )NzFailed to parse {}: {}
<stdin>   )r>   reprr?   r   r   r   r*      s   z_PlainFormatter.parsing_errorc                 C   s   | j j||dS )N)	file_namer-   )_error_formatr>   rI   r   r   r   r6      s   z _PlainFormatter.validation_errorc                 C   s   dS )Nr@   r   rL   r   r   r   r8      s   z"_PlainFormatter.validation_successN)	r   r   r   r   rQ   r&   r*   r6   r8   r   r   r   r   r   {   s    r   c                 C   s   d| vrd|  } t | S )N.zjsonschema.r   )namer   r   r   _resolve_name_with_default   s   rT   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.
    )rZ   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defaultrZ   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.
    )r;   rZ   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)rX   r]   schemaz=the path to a JSON Schema to validate with (i.e. schema.json)c                 C   sX   t tj| pdgd}|d dkr|d rtd|d dkr*|d d u r*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_argsr-   )ra   r   r   r   r   rd      s   rd   c                 C   s:   d}| |D ]}d}|j| |d q|s|j| d |S )NFTrJ   r-   )rJ   )iter_errorsr6   r8   )rJ   instance	validator	outputterinvalidr-   r   r   r   _validate_instance   s   rk   rN   c                 C   s   t tt| dd d S )Nr`   )r   )r'   exitrunrd   r`   r   r   r   main   s   rn   c              
      s<  t j| ||d z	 | d }W n
 ty   Y dS w | d }|d u r(t|}z|| W n tyK } z j| d |d W Y d }~dS d }~ww | d rY j| d }}n
 fdd}d	g}| d
 d urqt| d
 |dnd }	|||	d}
d}|D ]}z||}W n ty   d}Y q}w |t	|||
 dO }q}|S )N)r   r   r   r_   rN   rh   re   rW   c              
      s@   zt W S  ty } z jdt d t |d }~ww )NrM   r!   )r(   r)   r   r*   r'   r#   r   )_r-   ri   stdinr   r   r)   
  s   zrun.<locals>.loadrM   base_uri)rr   referrer)resolverr   )rJ   rg   rh   ri   )
r   r    r)   r   r   check_schemar	   r6   r
   rk   )r   r   r   rq   r_   	Validatorr-   r)   rW   rt   rh   	exit_codeeachrg   r   rp   r   rm      sb   
rm   )+__doc__	importlibr   r(   r   textwrapr   argparser'   rB   warningspkgutilr   ImportErrorpkgutil_resolve_nameattrsr   r   jsonschema.exceptionsr	   jsonschema.validatorsr
   r   warnDeprecationWarning	Exceptionr   r   r   r   rT   ArgumentParserrc   add_argumentr]   rd   rk   argvrn   r   r   rq   rm   r   r   r   r   <module>   s    ))

	