
    (\i                     \    d dl Z d dlmZ d dlmZmZ  G d de      Z G d de      Zd	dZy)
    N)StrEnum)SimpleLazyObjectemptyc                   <    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZy)CSPa  
    Content Security Policy constants for directive values and special tokens.

    These constants represent:
    1. Standard quoted string values from the CSP spec (e.g., 'self',
       'unsafe-inline')
    2. Special placeholder tokens (NONCE) that get replaced by the middleware

    Using this enum instead of raw strings provides better type checking,
    autocompletion, and protection against common mistakes like:

    - Typos (e.g., 'noone' instead of 'none')
    - Missing quotes (e.g., ["self"] instead of ["'self'"])
    - Inconsistent quote styles (e.g., ["'self'", ""unsafe-inline""])

    Example usage in Django settings:

        SECURE_CSP = {
            "default-src": [CSP.NONE],
            "script-src": [CSP.SELF, CSP.NONCE],
        }

    zContent-Security-Policyz#Content-Security-Policy-Report-Onlyz'none'z'report-sample'z'self'z'strict-dynamic'z'unsafe-eval'z'unsafe-hashes'z'unsafe-inline'z'wasm-unsafe-eval'z<CSP_NONCE_SENTINEL>N)__name__
__module____qualname____doc__HEADER_ENFORCEHEADER_REPORT_ONLYNONEREPORT_SAMPLESELFSTRICT_DYNAMICUNSAFE_EVALUNSAFE_HASHESUNSAFE_INLINEWASM_UNSAFE_EVALNONCE     `/home/devuser/fomin/mqttuser/mqtt_project/myenv/lib/python3.12/site-packages/django/utils/csp.pyr   r      sF    2 /N> D%MD'N!K%M%M+
 #Er   r   c                   .     e Zd ZdZ fdZd Zd Z xZS )	LazyNoncea{  
    Lazily generates a cryptographically secure nonce string, for use in CSP
    headers.

    The nonce is only generated when first accessed (e.g., via string
    interpolation or inside a template).

    The nonce will evaluate as `True` if it has been generated, and `False` if
    it has not. This is useful for third-party Django libraries that want to
    support CSP without requiring it.

    Example Django template usage with context processors enabled:

        <script{% if csp_nonce %} nonce="{{ csp_nonce }}"...{% endif %}>

    The `{% if %}` block will only render if the nonce has been evaluated
    elsewhere.

    c                 8    t         |   | j                         y N)super__init__	_generate)self	__class__s    r   r   zLazyNonce.__init__I   s    (r   c                 ,    t        j                  d      S )N   )secretstoken_urlsafer!   s    r   r    zLazyNonce._generateL   s    $$R((r   c                 &    | j                   t        uS r   )_wrappedr   r'   s    r   __bool__zLazyNonce.__bool__O   s    }}E))r   )r   r	   r
   r   r   r    r*   __classcell__)r"   s   @r   r   r   4   s    ())*r   r   c                 (   g }| j                         D ]  \  }}|dv r|du rd}nt        |t              rt        |      }nt        |t        t
        z        s|g}t        j                  |v x}r+|r)|D cg c]  }|t        j                  k(  rd| dn| }}n%|r#|D cg c]  }|t        j                  k7  s| }}|sdj                  |      }|j                  | d| j                                 dj                  |      S c c}w c c}w )N)NFT z'nonce-' z; )items
isinstancesetsortedlisttupler   r   joinappendrstrip)confignoncepolicy	directivevaluesrendered_valuehas_sentinelvs           r   build_policyrA   S   s   F#\\^ @	6]"T>N&#&  u5  !$		V 333OUV!SYYGE7!,AEVV%+>qCII~!>> XXf-N1^$45<<>?5@8 99V W>s   5"D
 D9Dr   )	r%   enumr   django.utils.functionalr   r   r   r   rA   r   r   r   <module>rD      s-      ;*#' *#Z*  *>r   