
    MȂi                     d    S SK r S SKJr  S SKJrJr   " S S\5      r " S S\5      rS rS
S	 jr	g)    N)StrEnum)SimpleLazyObjectemptyc                   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	       AD:\sksbv-state-backend\venv\Lib\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$ )	LazyNonce4   aK  
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                 ,   > [         TU ]  [        5        g N)super__init__generate_nonce)self	__class__s    r   r#   LazyNonce.__init__I   s    (r   c                 &    U R                   [        L$ r!   )_wrappedr   )r%   s    r   __bool__LazyNonce.__bool__L   s    }}E))r   r	   )	r
   r   r   r   r   r#   r*   r   __classcell__)r&   s   @r   r   r   4   s    ()* *r   r   c                  .    [         R                  " S5      $ )N   )secretstoken_urlsafer	   r   r   r$   r$   P   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(       a2  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)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_policyrF   T   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   $D6 D;D;r!   )
r/   enumr   django.utils.functionalr   r   r   r   r$   rF   r	   r   r   <module>rI      s2      ;*#' *#Z*  *8%r   