a
    �Ï?eï   ã                   @   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0 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_forzµThe 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   úQ/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/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y6   | j|t ¡ d� tƒ ‚Y n0 |�V zt |¡W W  d   ƒ S  ty‚   | j	|t ¡ d� tƒ ‚Y n0 W d   ƒ n1 s˜0    Y  d S )N©ÚpathÚexc_info)
ÚopenÚFileNotFoundErrorÚfilenotfound_errorÚsysr#   r   ÚjsonÚloadr   Úparsing_error)Úselfr"   Úfiler   r   r   r)   6   s    z_Outputter.loadc                 K   s   | j  | jjf i |¤Ž¡ d S ©N)Ú_stderrÚwriteÚ
_formatterr&   ©r+   Úkwargsr   r   r   r&   D   s    z_Outputter.filenotfound_errorc                 K   s   | j  | jjf i |¤Ž¡ d S r-   )r.   r/   r0   r*   r1   r   r   r   r*   G   s    z_Outputter.parsing_errorc                 K   s   | j  | jjf i |¤Ž¡ d S r-   )r.   r/   r0   Úvalidation_errorr1   r   r   r   r3   J   s    z_Outputter.validation_errorc                 K   s   | j  | jjf i |¤Ž¡ d S r-   )Ú_stdoutr/   r0   Úvalidation_successr1   r   r   r   r5   M   s    z_Outputter.validation_successN)r   r   r   r   r0   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&   ^   s
    ýz#_PrettyFormatter.filenotfound_errorc                 C   s2   |\}}}d  t |||¡¡}| jj||j|d�S )NÚ r7   )ÚjoinÚ	tracebackÚformat_exceptionr:   r;   r   )r+   r"   r#   Úexc_typeÚ	exc_valueÚexc_tracebackZ	exc_linesr   r   r   r*   e   s    
ÿýz_PrettyFormatter.parsing_errorc                 C   s   | j j||jj|d�S )Nr7   )r:   r;   Ú	__class__r   ©r+   Úinstance_pathÚerrorr   r   r   r3   p   s
    ýz!_PrettyFormatter.validation_errorc                 C   s   | j j|d�S )N)r"   )Ú_SUCCESS_MSGr;   ©r+   rF   r   r   r   r5   w   s    z#_PrettyFormatter.validation_successN)
r   r   r   r   r:   rH   r&   r*   r3   r5   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{!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_namerG   )Ú_error_formatr;   rE   r   r   r   r3   ‰   s    z _PlainFormatter.validation_errorc                 C   s   dS )Nr=   r   rI   r   r   r   r5   Œ   s    z"_PlainFormatter.validation_successN)	r   r   r   r   rN   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    rQ   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.
    )rW   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ÚdefaultrW   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.
    )r8   rW   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ÚversionZ
jsonschema)rU   rZ   Ú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r4|d r4t d¡‚|d dkrT|d d u rTd|d< |S )Nz--help©Úargsr   r   r   z3--error-format can only be used with --output plainz"{error.instance}: {error.message}
)ÚvarsÚparserÚ
parse_argsrG   )r]   r   r   r   r   r`   Ô   s    ÿr`   c                 C   s:   d}|  |¡D ]}d}|j| |d� q|s6|j| d� |S )NFT©rF   rG   )rF   )Ziter_errorsr3   r5   )rF   ÚinstanceÚ	validatorÚ	outputterÚinvalidrG   r   r   r   Ú_validate_instanceß   s    rf   rK   c                 C   s   t  tt| d�d�¡ d S )Nr\   )r   )r'   ÚexitÚrunr`   r\   r   r   r   Úmainê   s    ri   c              
      s@  t j| ||d�‰ zˆ  | d ¡}W n ty6   Y dS 0 | d }|d u rPt|ƒ}z| |¡ W n8 ty– } z ˆ j| d |d� W Y d }~dS d }~0 0 | d r²ˆ j| d  }}n‡ ‡fdd„}d	g}| d
 d urât| d
 |d�nd }	|||	d�}
d}|D ]@}z||ƒ}W n t�y"   d}Y n0 |t	|||
ˆ d�O }� qú|S )N)r   r   r   r[   rK   rc   ra   rT   c                    s<   zt  ˆ¡W S  ty6   ˆ jdt ¡ d� tƒ ‚Y n0 d S )NrJ   r!   )r(   r)   r   r*   r'   r#   r   )Ú_©rd   Ústdinr   r   r)   
  s    ÿzrun.<locals>.loadrJ   Úbase_uri)rm   Zreferrer)Úresolverr   )rF   rb   rc   rd   )
r   r    r)   r   r   Zcheck_schemar	   r3   r
   rf   )r   r   r   rl   r[   Z	ValidatorrG   r)   rT   rn   rc   Z	exit_codeZeachrb   r   rk   r   rh   î   sZ    ýþ
ýþý
ürh   )+Ú__doc__Ú	importlibr   r(   r   Útextwrapr   Úargparser'   r?   ÚwarningsÚpkgutilr   ÚImportErrorZpkgutil_resolve_nameÚattrsr   r   Zjsonschema.exceptionsr	   Zjsonschema.validatorsr
   r   ÚwarnÚDeprecationWarningÚ	Exceptionr   r   r   r   rQ   ÚArgumentParserr_   Úadd_argumentrZ   r`   rf   Úargvri   r   r   rl   rh   r   r   r   r   Ú<module>   sŠ   ù))ÿü
þü
ý	þýþ