a
    d=icC                     @   s   d Z ddlZddlmZ ddlZddlmZ ddlm	Z
 ddlmZ e Zddgg d	d
Zg dZG dd dejZe ZG dd dejZe Zdd Zdd Zdd Zdd Zdd Z	G dd dZdS )z<Provides utilities that may be especially useful to plugins.    N)Cleaner)context)experiment_id)
tb_logginghreftitle)srcr   Zalt)aimg)ZulolZlipprecodeZ
blockquoteZh1Zh2Zh3Zh4Zh5Zh6hrbrstrongZemr	   r
   tableZtheadZtbodytdtrthc                   @   s   e Zd Zdd ZdS )_MarkdownStorec                 C   s   t jddgd| _ d S )Nzmarkdown.extensions.tableszmarkdown.extensions.fenced_code)
extensions)markdownMarkdownself r   h/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/tensorboard/plugin_util.py__init__E   s
    z_MarkdownStore.__init__N__name__
__module____qualname__r   r   r   r   r   r   D   s   r   c                   @   s   e Zd Zdd ZdS )_CleanerStorec                 C   s   t ttd| _d S )N)tags
attributes)r   _ALLOWED_TAGS_ALLOWED_ATTRIBUTEScleanerr   r   r   r   r   T   s    z_CleanerStore.__init__Nr   r   r   r   r   r#   S   s   r#   c                 C   s$   d}t | tr| d} tj| S )zReturn the input as a str, sanitized for insertion into the DOM.

    Arguments:
      unsafe_string: A Unicode string or UTF-8--encoded bytestring
        possibly containing unsafe HTML markup.

    Returns:
      A string containing safe HTML.
    r   utf-8)
isinstancebytesdecode_CLEANER_STOREr(   clean)unsafe_stringtotal_null_bytesr   r   r   	safe_html]   s    


r1   c                 C   s   t | gdd S )a  Convert Markdown to HTML that's safe to splice into the DOM.

    Arguments:
      markdown_string: A Unicode string or UTF-8--encoded bytestring
        containing Markdown source. Markdown tables are supported.

    Returns:
      A string containing safe HTML.
    c                 S   s   | d S )Nr   r   )Zxsr   r   r   <lambda>w       z'markdown_to_safe_html.<locals>.<lambda>)markdowns_to_safe_html)Zmarkdown_stringr   r   r   markdown_to_safe_htmlm   s    
r5   c           
      C   s   g }d}| D ]N}t |trD|d}|dd}|t|t| 7 }tj|}|| q||}t	j
|}d}	|rd| }	|	| S )a  Convert multiple Markdown documents to one safe HTML document.

    One could also achieve this by calling `markdown_to_safe_html`
    multiple times and combining the results. Compared to that approach,
    this function may be faster, because HTML sanitization (which can be
    expensive) is performed only once rather than once per input. It may
    also be less precise: if one of the input documents has unsafe HTML
    that is sanitized away, that sanitization might affect other
    documents, even if those documents are safe.

    Args:
      markdown_strings: List of Markdown source strings to convert, as
        Unicode strings or UTF-8--encoded bytestrings. Markdown tables
        are supported.
      combine: Callback function that takes a list of unsafe HTML
        strings of the same shape as `markdown_strings` and combines
        them into a single unsafe HTML string, which will be sanitized
        and returned.

    Returns:
      A string containing safe HTML.
    r   r)     zR<!-- WARNING: discarded %d null bytes in markdown string after UTF-8 decoding -->
)r*   r+   r,   replacelen_MARKDOWN_STOREr   convertappendr-   r(   r.   )
Zmarkdown_stringscombineZunsafe_htmlsr0   sourceZsource_decodedZunsafe_htmlZunsafe_combinedZsanitized_combinedwarningr   r   r   r4   z   s"    

r4   c                 C   s
   t | S )znGet a TensorBoard `RequestContext` from a WSGI environment.

    Returns:
      A `RequestContext` value.
    )_contextZfrom_environenvironr   r   r   r      s    r   c                 C   s   |  tjdS )a  Determine the experiment ID associated with a WSGI request.

    Each request to TensorBoard has an associated experiment ID, which is
    always a string and may be empty. This experiment ID should be passed
    to data providers.

    Args:
      environ: A WSGI environment `dict`. For a Werkzeug request, this is
        `request.environ`.

    Returns:
      A experiment ID, as a possibly-empty `str`.
    r7   )get_experiment_idZWSGI_ENVIRON_KEYrA   r   r   r   r      s    r   c                   @   s(   e Zd ZdZdd Zdd Zdd ZdS )	_MetadataVersionCheckera  TensorBoard-internal utility for warning when data is too new.

    Specify a maximum known `version` number as stored in summary
    metadata, and automatically reject and warn on data from newer
    versions. This keeps a (single) bit of internal state to handle
    logging a warning to the user at most once.

    This should only be used by plugins bundled with TensorBoard, since
    it may instruct users to upgrade their copy of TensorBoard.
    c                 C   s   || _ || _d| _dS )a%  Initialize a `_MetadataVersionChecker`.

        Args:
          data_kind: A human-readable description of the kind of data
            being read, like "scalar" or "histogram" or "PR curve".
          latest_known_version: Highest tolerated value of `version`,
            like `0`.
        FN)
_data_kind_latest_known_version_warned)r   Z	data_kindZlatest_known_versionr   r   r   r      s    	z _MetadataVersionChecker.__init__c                 C   s0   d|  kr| j krn ndS | ||| dS )z3Test whether `version` is permitted, else complain.r   TF)rG   _maybe_warnr   versionruntagr   r   r   ok   s    z_MetadataVersionChecker.okc                 C   s(   | j r
d S d| _ td| j||| d S )NTzSome %s data is too new to be read by this version of TensorBoard. Upgrading TensorBoard may fix this. (sample: run %r, tag %r, data version %r))rH   loggerr?   rF   rJ   r   r   r   rI      s    z#_MetadataVersionChecker._maybe_warnN)r    r!   r"   __doc__r   rN   rI   r   r   r   r   rE      s   rE   )rP   	threadingZ$tensorboard._vendor.bleach.sanitizerr   r   Ztensorboardr   r@   Ztensorboard.backendr   rD   Ztensorboard.utilr   Z
get_loggerrO   r'   r&   localr   r:   r#   r-   r1   r5   r4   rE   r   r   r   r   <module>   s*   
2	