o
    iF!                     @   s  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zddl	m
Z
 W n ey7   ddlZ
Y nw zddlmZ W n eyO   ddlmZ Y nw ddl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jG dd dZejG dd dZej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.d/e
"d0d1 e j!d2d3d! d4d5 Z#d6d7 Z$ej%d8d fd9d:Z&ej'ej(ej)fd;d<Z*dS )=z"
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                   @   s   e Zd ZdS )_CannotLoadFileN)__name__
__module____qualname__ r   r   I/var/www/edux/Edux_v2/venv/lib/python3.10/site-packages/jsonschema/cli.pyr   '   s    r   c                   @   sX   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_arguments2   s
   z_Outputter.from_argumentsc              	   C   s   zt |}W n ty   | j|t d t w |" zt|W W  d    S  ty=   | j	|t d t w 1 sAw   Y  d S )Npathexc_info)
openFileNotFoundErrorfilenotfound_errorsysr!   r   jsonloadr   parsing_error)selfr    filer   r   r   r'   :   s   
z_Outputter.loadc                 K      | j | jjdi | d S Nr   )_stderrwrite
_formatterr$   r)   kwargsr   r   r   r$   H      z_Outputter.filenotfound_errorc                 K   r+   r,   )r-   r.   r/   r(   r0   r   r   r   r(   K   r2   z_Outputter.parsing_errorc                 K   r+   r,   )r-   r.   r/   validation_errorr0   r   r   r   r3   N   r2   z_Outputter.validation_errorc                 K   r+   r,   )_stdoutr.   r/   validation_successr0   r   r   r   r5   Q   r2   z_Outputter.validation_successN)r   r   r   attribr/   r4   r-   classmethodr   r'   r$   r(   r3   r5   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{!r} does not exist.r    typebody)
_ERROR_MSGformatr)   r    r!   r   r   r   r$   b   s
   z#_PrettyFormatter.filenotfound_errorc                 C   s2   |\}}}d t|||}| jj||j|dS )N r9   )join	tracebackformat_exceptionr<   r=   r   )r)   r    r!   exc_type	exc_valueexc_traceback	exc_linesr   r   r   r(   i   s   
z_PrettyFormatter.parsing_errorc                 C   s   | j j||jj|dS )Nr9   )r<   r=   	__class__r   r)   instance_patherrorr   r   r   r3   t   s
   z!_PrettyFormatter.validation_errorc                 C   s   | j j|dS )N)r    )_SUCCESS_MSGr=   r)   rI   r   r   r   r5   {   s   z#_PrettyFormatter.validation_successN)
r   r   r   r   r<   rK   r$   r(   r3   r5   r   r   r   r   r   U   s    r   c                   @   s4   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{!r} 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_namerJ   )_error_formatr=   rH   r   r   r   r3      s   z _PlainFormatter.validation_errorc                 C   s   dS )Nr?   r   rL   r   r   r   r5      s   z"_PlainFormatter.validation_successN)
r   r   r   r6   r7   rQ   r$   r(   r3   r5   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_argsrJ   )ra   r   r   r   r   rd      s   rd   c                 C   s:   d}| |D ]}d}|j| |d q|s|j| d |S )NFTrI   rJ   )rI   )iter_errorsr3   r5   )rI   instance	validator	outputterinvalidrJ   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              
      sD  t j| ||d z	 | d }W n
 ty   Y dS w | d d u r(t|| d< z	| d | W n tyM } z j| d |d W Y d }~dS d }~ww | d r[ j| d }}n
 fdd}d	g}| d
 d urst| d
 |dnd }| d ||d}	d}
|D ]}z||}W n ty   d}
Y qw |
t	|||	 dO }
q|
S )N)r   r   r   r_   rN   rh   re   rW   c                    s4   zt W S  ty    jdt d t w )NrM   r   )r&   r'   r   r(   r%   r!   r   )_ri   stdinr   r   r'     s   zrun.<locals>.loadrM   base_uri)rr   referrer)resolverr   )rI   rg   rh   ri   )
r   r   r'   r   r	   check_schemar   r3   r   rk   )r   r   r   rq   r_   rJ   r'   rW   rt   rh   	exit_codeeachrg   r   rp   r   rm      s`   
rm   )+__doc__r&   r   textwrapr   argparser%   rA   warnings	importlibr   ImportErrorimportlib_metadatapkgutilr   pkgutil_resolve_namer6   jsonschema.exceptionsr   jsonschema.validatorsr   r	   warnDeprecationWarning	Exceptionr   sr   r   r   rT   ArgumentParserrc   add_argumentr]   rd   rk   argvrn   r   r   rq   rm   r   r   r   r   <module>   s    ))

	