U
    /e<                     @  s0  U d Z ddlmZ ddlZeeZddlZddlm	Z	m
Z
mZmZ ddlmZmZ ddlmZ ddlmZ dd	lmZ d
dlmZ e Zded< dZeG dd dZeG dd dZed ZG dd deZd*ddddddZdddddZ ej!dddd d!Z"d"dd#d$d%Z#dd&d'd(d)Z$dS )+z, Provide the ``check_integrity`` function.

    )annotationsN)IterableIteratorListSet)LiteralProtocol   )Model)settings)	dataclass   )WarningzSet[Warning]__silencers__)check_integritysilencesilencedc                   @  s.   e Zd ZU ded< ded< ded< ded< dS )ValidationIssueintcodestrnametextextraN__name__
__module____qualname____annotations__ r   r   ?/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/core/validation/check.pyr   9   s   
r   c                   @  s   e Zd ZU ded< ded< dS )ValidationIssuesList[ValidationIssue]errorwarningNr   r   r   r   r    r!   @   s   
r!   r#   r$   c                   @  s$   e Zd ZU ddddZded< dS )	Validatorr"   )returnc                 C  s   d S Nr   )selfr   r   r    __call__H       zValidator.__call__ValidatorTypevalidator_typeN)r   r   r   r*   r   r   r   r   r    r&   G   s   
r&   Tr   bool)r$   r   r'   c                 C  sB   t | tstdt|  |r,t|  n| tkr>t|  tS )a<   Silence a particular warning on all Bokeh models.

    Args:
        warning (Warning) : Bokeh warning to silence
        silence (bool) : Whether or not to silence the warning

    Returns:
        A set containing the all silenced warnings

    This function adds or removes warnings from a set of silencers which
    is referred to when running ``check_integrity``. If a warning
    is added to the silencers - then it will never be raised.

    .. code-block:: python

        >>> from bokeh.core.validation.warnings import EMPTY_LAYOUT
        >>> bokeh.core.validation.silence(EMPTY_LAYOUT, True)
        {1002}

    To turn a warning back on use the same method but with the silence
    argument set to false

    .. code-block:: python

        >>> bokeh.core.validation.silence(EMPTY_LAYOUT, False)
        set()

    z:Input to silence should be a warning object - not of type )
isinstancer   
ValueErrortyper   addremove)r$   r   r   r   r    r   K   s    

r   )r$   r'   c                 C  s   | t kS )z Check if a warning has been silenced.

    Args:
        warning (Warning) : Bokeh warning to check

    Returns:
        bool

    )r   r$   r   r   r    is_silencedp   s    
r5   zIterator[None]c              	   c  s&   t | d z
d V  W 5 t | d X d S )NTF)r   r4   r   r   r    r   |   s    

r   zIterable[Model])modelsr'   c                 C  s   t g g d}| D ]t}g }t|D ]0}|ds0q t||}t|ddr || q |D ],}|jdkrt|j|  qV|j|  qVq|S )aP   Collect all warnings associated with a collection of Bokeh models.

    Args:
        models (seq[Model]) : a collection of Models to test

    Returns:
        ValidationIssues: A collection of all warning and error messages

    This function will return an object containing all errors and/or
    warning conditions that are detected. For example, layouts without
    any children will add a warning to the collection:

    .. code-block:: python

        >>> empty_row = Row()

        >>> check_integrity([empty_row])
        ValidationIssues(
            error=[],
            warning=[
                ValidationIssue(
                    code=1002,
                    name="EMPTY_LAYOUT",
                    text="Layout has no children",
                    extra="Row(id='1001', ...)",
                ),
            ],
        )

    r%   _checkr-   Nr#   )	r!   dir
startswithgetattrappendr-   r#   extendr$   )r6   issuesmodelZ
validatorsr   objfuncr   r   r    r      s    


r   None)r=   r'   c              	   C  s  | j }dd | jD }g }t|dd dD ]<}d|j d|j d|j d	|j }|| t| q*g }t|d
d dD ]<}d|j d|j d|j d	|j }|| t | q|t	
 dkrt|rtd| n2t	
 dkrt|st|rtd||  dS )ad   Log warning and error messages for a dictionary containing warnings and error messages.

    Args:
        issues (ValidationIssue) : A collection of all warning and error messages

    Returns:
        None

    This function will emit log warning and error messages for all error or
    warning conditions in the dictionary. For example, a dictionary
    containing a warning for empty layout will trigger a warning:

    .. code-block:: python

        >>> process_validation_issues(validations)
        W-1002 (EMPTY_LAYOUT): Layout has no children: Row(id='2404a029-c69b-4e30-9b7d-4b7b6cdaad5b', ...)

    c                 S  s    g | ]}t t|js|qS r   )r5   r   Zget_by_coder   ).0issuer   r   r    
<listcomp>   s      z-process_validation_issues.<locals>.<listcomp>c                 S  s   | j S r(   r   r4   r   r   r    <lambda>   r+   z+process_validation_issues.<locals>.<lambda>)keyzW-z (z): z: c                 S  s   | j S r(   rE   )r#   r   r   r    rF      r+   zE-errorsz&Errors encountered during validation: allN)r#   r$   sortedr   r   r   r   r;   logr   Zvalidation_levellenRuntimeError)r=   rH   warningsZwarning_messagesr$   msgZerror_messagesr#   r   r   r    process_validation_issues   s$    $
$
rP   )T)%__doc__
__future__r   logging	getLoggerr   rK   
contextlibtypingr   r   r   r   Ztyping_extensionsr   r   r>   r
   r   Zutil.dataclassesr   rC   r   setr   r   __all__r   r!   r,   r&   r   r5   contextmanagerr   r   rP   r   r   r   r    <module>   s0   

%1