
    j                     ~    S SK r S SKJr  S SKJrJr  S SKJr  Sr " S S\5      r	 " S S	\5      r
SS
 jrS rSS jrg)    N)StrEnum)SimpleLazyObjectempty)format_html	csp_noncec                   D    \ rS rSrSrSrSrSrSrSr	Sr
S	rS
rSrSrSrSrg)CSP   a  
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____firstlineno____doc__HEADER_ENFORCEHEADER_REPORT_ONLYNONEREPORT_SAMPLESELFSTRICT_DYNAMICUNSAFE_EVALUNSAFE_HASHESUNSAFE_INLINEWASM_UNSAFE_EVALNONCE__static_attributes__r       H/var/www/html/KUNJ/venv/lib/python3.13/site-packages/django/utils/csp.pyr	   r	      sF    2 /N> D%MD'N!K%M%M+
 #Er   r	   c                   2   ^  \ rS rSrSrU 4S jrS rSrU =r$ )	LazyNonce8   aw  
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 {% csp_nonce_attr %}></script>

``{% csp_nonce_attr %}`` will only render the nonce attribute if the nonce
has been evaluated (i.e. accessed) elsewhere in the request/response cycle.

c                 ,   > [         TU ]  [        5        g N)super__init__generate_nonce)self	__class__s    r   r%   LazyNonce.__init__M   s    (r   c                 &    U R                   [        L$ r#   )_wrappedr   )r'   s    r   __bool__LazyNonce.__bool__P   s    }}E))r   r   )	r   r   r   r   r   r%   r,   r   __classcell__)r(   s   @r   r    r    8   s    ()* *r   r    c                     U R                  [        5      nU(       a  UR                  Ub  SU0S9$ S S9$ Uc  g[        SU5      $ )Nnonce)attrs z
nonce="{}")getCONTEXT_KEYrenderr   )contextmediar0   s      r   
nonce_attrr8   T   sM    KK$E||e6G7E"2|RRT|RR}|U++r   c                  .    [         R                  " S5      $ )N   )secretstoken_urlsafer   r   r   r&   r&   ]   s      $$r   c                    / nU R                  5        GH  u  p4US;   a  M  USL a  SnO[        U[        5      (       a  [        U5      nO[        U[        [
        -  5      (       d  U/n[        R                  U;   =n(       a3  U(       a,  U Vs/ s H  ow[        R                  :X  a  SU S3OUPM      nnO.U(       a'  U Vs/ s H  ow[        R                  :w  d  M  UPM     nnU(       d  M  SR                  U5      nUR                  U SU 3R                  5       5        GM     SR                  U5      $ s  snf s  snf )N)NFTr2   z'nonce-' z; )items
isinstancesetsortedlisttupler	   r   joinappendrstrip)configr0   policy	directivevaluesrendered_valuehas_sentinelvs           r   build_policyrP   a   s   F#\\^	]"T>N&#&&  u55  !$		V 333OUVv!SYYGE7!,AEvV%+>VCII~!V> XXf-N1^$45<<>?5 ,8 99V W>s   %D8D=D=r#   )r;   enumr   django.utils.functionalr   r   django.utils.htmlr   r4   r	   r    r8   r&   rP   r   r   r   <module>rT      sA      ; ) *#' *#Z*  *8,%r   