a
    d=ic'                     @   s   d Z ddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZ edZdgZg Zg Zg Zg ZdZdZg ZedZedZed	Zeg d
ZeddgZdZdddZdd ZdS )zTensorBoard HTTP utilities.    N)	json_utilz\sdata:Tz^[^;\s]*zcharset=([-_0-9A-Za-z]+)z.(?:^|,|\s)(?:(?:x-)?gzip|\*)(?!;q=0)(?:\s|,|$))zapplication/javascriptapplication/jsonapplication/json+protobufzimage/svg+xmlztext/cssztext/csv	text/htmlztext/javascriptz
text/plainztext/tab-separated-valuesztext/x-protobufr   r   r      utf-8c	                 C   s  t |d}	t|}
|
r(|
dn|}|
p6|	tv }|	tv rjt|ttt	t
frjtjt|||
 d}||krt|tr||}t|tr||}|r|
s|	tvr|d| 7 }t| jdd}|r.|s.|r.t }tj|dddd	}|| W d
   n1 s0    Y  | }d}t|}d}|dkr|stjt|dd}td|dd
 d }tj !| j"|}d
}d}t|pg }|#dt|f |#d |r|#d|f |dkrt$j%&t'' t(| }|#d|f |#dd| f n|#d |#d |	t)krt*t+r:dndt,rFdndg dd |pZg D  }t-| }d.dd t-dgt/R   d!t-dgt0R   d"t-dd#d$gt1R   d%d&t-dd'd#d(gt2R   d)t-dgt3R   d*| g}|#d+|f | j4d,kr d
}tj5j6|||||d-S ).a	  Construct a werkzeug Response.

    Responses are transmitted to the browser with compression if: a) the browser
    supports it; b) it's sane to compress the content_type in question; and c)
    the content isn't already compressed, as indicated by the content_encoding
    parameter.

    Browser and proxy caching is completely disabled by default. If the expires
    parameter is greater than zero then the response will be able to be cached by
    the browser for that many seconds; however, proxies are still forbidden from
    caching so that developers can bypass the cache with Ctrl+Shift+R.

    For textual content that isn't JSON, the encoding parameter is used as the
    transmission charset which is automatically appended to the Content-Type
    header. That is unless of course the content_type parameter contains a
    charset parameter. If the two disagree, the characters in content will be
    transcoded to the latter.

    If content_type declares a JSON media type, then content MAY be a dict, list,
    tuple, or set, in which case this function has an implicit composition with
    json_util.Cleanse and json.dumps. The encoding parameter is used to decode
    byte strings within the JSON object; therefore transmitting binary data
    within JSON is not permitted. JSON is transmitted as ASCII unless the
    content_type parameter explicitly defines a charset parameter, in which case
    the serialized JSON bytes will use that instead of escape sequences.

    Args:
      request: A werkzeug Request object. Used mostly to check the
        Accept-Encoding header.
      content: Payload data as byte string, unicode string, or maybe JSON.
      content_type: Media type and optionally an output charset.
      code: Numeric HTTP status code to use.
      expires: Second duration for browser caching.
      content_encoding: Encoding if content is already encoded, e.g. 'gzip'.
      encoding: Input charset if content parameter has byte strings.
      csp_scripts_sha256s: List of base64 serialized sha256 of whitelisted script
        elements for script-src of the Content-Security-Policy. If it is None, the
        HTML will disallow any script to execute. It is only be used when the
        content_type is text/html.
      headers: Any additional headers to include on the response, as a
        list of key-value tuples: e.g., `[("Allow", "GET")]`. In case of
        conflict, these may be overridden with headers added by this function.

    Returns:
      A werkzeug Response object (a WSGI application).
    r      )ensure_asciiz
; charset=zAccept-Encoding wb   )fileobjmodecompresslevelmtimeNgzipFrb)r   r   z<ITzContent-Length)zX-Content-Type-OptionsZnosniffzContent-EncodingExpiresCache-Controlzprivate, max-age=%d)r   0)r   zno-cache, must-revalidatez'self'z'unsafe-eval'c                 S   s   g | ]}d  |qS )z'sha256-{}')format).0sha256 r   n/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/tensorboard/backend/http_util.py
<listcomp>   s   zRespond.<locals>.<listcomp>;zdefault-src 'self'zfont-src %szframe-src %sz
img-src %sr   zblob:zobject-src 'none'zstyle-src %szhttps://www.gstatic.comz'unsafe-inline'zconnect-src %szscript-src %szContent-Security-PolicyHEAD)responsestatusheaderscontent_typedirect_passthrough)7_EXTRACT_MIMETYPE_PATTERNsearchgroup_EXTRACT_CHARSET_PATTERN_TEXTUAL_MIMETYPES_JSON_MIMETYPES
isinstancedictlistsettuplejsondumpsr   ZCleansebytesdecodestrencode_ALLOWS_GZIP_PATTERNr"   getioBytesIOr   GzipFilewritegetvaluelenstructunpackwerkzeugZwsgi	wrap_fileenvironappendwsgirefhandlersZformat_date_timetimefloat_HTML_MIMETYPE_CSP_SCRIPT_DOMAINS_WHITELIST_CSP_SCRIPT_SELF_CSP_SCRIPT_UNSAFE_EVAL_create_csp_stringjoin_CSP_FONT_DOMAINS_WHITELIST_CSP_FRAME_DOMAINS_WHITELIST_CSP_IMG_DOMAINS_WHITELIST_CSP_STYLE_DOMAINS_WHITELIST_CSP_CONNECT_DOMAINS_WHITELISTmethodwrappersResponse)requestcontentr#   codeexpirescontent_encodingencodingZcsp_scripts_sha256sr"   mimetypeZcharset_matchcharsetZtextualZgzip_acceptedoutfcontent_lengthr$   Z	gzip_fileeZfragsZscript_srcs
csp_stringr   r   r   RespondT   s    :




*




	
"rc   c                  G   s    d dd | D }|r|S dS )N c                 S   s   g | ]}|r|qS r   r   )r   fragr   r   r   r         z&_create_csp_string.<locals>.<listcomp>z'none')rM   )Zcsp_fragmentsrb   r   r   r   rL     s    rL   )r   r   Nr   NN)__doc__r   r8   r0   rer>   rF   Zwsgiref.handlersrD   r@   Ztensorboard.backendr   compileZ_DISALLOWED_CHAR_IN_DOMAINrN   rO   rP   rI   rR   rJ   rK   rQ   r%   r(   r6   r.   r)   r*   rH   rc   rL   r   r   r   r   <module>   sR   


      
 3