Ë
    1ÆVh<  ã                   óD   — d Z ddlZddlZddlmZ ddlmZ  G d„ d«      Zy)zDMiddleware for injecting client-side feature flags into the Context.é    N)Úcontext)Úerrorsc                   ó(   — e Zd ZdZd„ Zd„ Zd„ Zd„ Zy)ÚClientFeatureFlagsMiddlewarea€  Middleware for injecting client-side feature flags into the Context.

    The client webapp is expected to include a json-serialized version of its
    FeatureFlags in the `X-TensorBoard-Feature-Flags` header or the
    `tensorBoardFeatureFlags` query parameter. This middleware extracts the
    header or query parameter value and converts it into the client_feature_flags
    property for the DataProvider's Context object, where client_feature_flags
    is a Dict of string keys and arbitrary value types.

    In the event that both the header and query parameter are specified, the
    values from the header will take precedence.
    c                 ó   — || _         y)zxInitializes this middleware.

        Args:
          application: The WSGI application to wrap (see PEP 3333).
        N)Ú_application)ÚselfÚapplications     úX/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/backend/client_feature_flags.pyÚ__init__z%ClientFeatureFlagsMiddleware.__init__&   s   € ð (ˆÕó    c                 ó‚  — | j                  |j                  d«      «      }| j                  |j                  d«      «      }|s|s| j                  ||«      S |j	                  «       D ]
  \  }}|||<   Œ t        j                  |«      j                  |¬«      }t        j                  ||«       | j                  ||«      S )NÚ HTTP_X_TENSORBOARD_FEATURE_FLAGSÚQUERY_STRING)Úclient_feature_flags)	Ú#_parse_potential_header_param_flagsÚgetÚ"_parse_potential_query_param_flagsr   Úitemsr   Úfrom_environÚreplaceÚset_in_environ)r	   ÚenvironÚstart_responseÚheader_feature_flagsÚquery_string_feature_flagsÚflagÚvalueÚctxs           r   Ú__call__z%ClientFeatureFlagsMiddleware.__call__.   sÍ   € Ø#×GÑGØK‰KÐ:Ó;ó 
Ðð &*×%LÑ%LØK‰K˜Ó'ó&
Ð"ñ $Ñ,FØ×$Ñ$ W¨nÓ=Ð=ð 0×5Ñ5Ó7ò 	5‰KˆD%Ø/4Ð& tÒ,ð	5ô ×"Ñ" 7Ó+×3Ñ3Ø!;ð 4ó 
ˆô 	×Ñ˜w¨Ô,à× Ñ  ¨.Ó9Ð9r   c                 óÜ   — |si S 	 t        j                  |«      }t        |t        «      st        j                  d«      ‚|S # t         j                  $ r t        j                  d«      ‚w xY w)Nz3X-TensorBoard-Feature-Flags cannot be JSON decoded.z8X-TensorBoard-Feature-Flags cannot be decoded to a dict.)ÚjsonÚloadsÚJSONDecodeErrorr   ÚInvalidArgumentErrorÚ
isinstanceÚdict)r	   Úheader_stringr   s      r   r   z@ClientFeatureFlagsMiddleware._parse_potential_header_param_flagsD   sv   € ÙØˆIð	Ü#'§:¡:¨mÓ#<Ð ô Ð.´Ô5Ü×-Ñ-ØJóð ð $Ð#øô ×#Ñ#ò 	Ü×-Ñ-ØEóð ð	ús   †A Á)A+c                 óp  — |si S 	 t         j                  j                  |«      }|j	                  dg «      }|si S 	 t        j                  |d   «      }t        |t        «      st        j                  d«      ‚|S # t        $ r i cY S w xY w# t
        j                  $ r t        j                  d«      ‚w xY w)NÚtensorBoardFeatureFlagsr   z/tensorBoardFeatureFlags cannot be JSON decoded.z4tensorBoardFeatureFlags cannot be decoded to a dict.)ÚurllibÚparseÚparse_qsÚ
ValueErrorr   r"   r#   r$   r   r%   r&   r'   )r	   Úquery_stringÚquery_string_jsonÚpotential_feature_flagsr   s        r   r   z?ClientFeatureFlagsMiddleware._parse_potential_query_param_flagsV   sÍ   € ÙØˆIð	Ü &§¡× 5Ñ 5°lÓ CÐð
 #4×"7Ñ"7Ø% ró#
Ðñ 'ØˆIð	Ü#'§:¡:Ð.EÀaÑ.HÓ#IÐ ô Ð.´Ô5Ü×-Ñ-ØFóð ð $Ð#øô+ ò 	ØŠIð	ûô ×#Ñ#ò 	Ü×-Ñ-ØAóð ð	ús   †A; ¼B Á;B	ÂB	Â)B5N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r   r   © r   r   r   r      s   „ ñò(ò:ò,$ó$$r   r   )r5   r"   Úurllib.parser+   Útensorboardr   r   r   r6   r   r   ú<module>r9      s#   ðñ Kã Û å Ý ÷Y$ò Y$r   