
    Mi                     d    S SK Jr   " S S\5      r " S S5      r    SS\S\S\S	\S
\4
S jjrg)    )Enumc                   ,    \ rS rSrSrSrSrSrSrSr	Sr
g	)
	CacheMode   a  
Defines the caching behavior for web crawling operations.

Modes:
- ENABLED: Normal caching behavior (read and write)
- DISABLED: No caching at all
- READ_ONLY: Only read from cache, don't write
- WRITE_ONLY: Only write to cache, don't read
- BYPASS: Bypass cache for this operation
enableddisabled	read_only
write_onlybypass N)__name__
__module____qualname____firstlineno____doc__ENABLEDDISABLED	READ_ONLY
WRITE_ONLYBYPASS__static_attributes__r       p/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/crawl4ai/cache_context.pyr   r      s"    	 GHIJFr   r   c                   f    \ rS rSrSrSS\S\S\4S jjrS\4S jr	S\4S	 jr
\S\4S
 j5       rSrg)CacheContext   a  
Encapsulates cache-related decisions and URL handling.

This class centralizes all cache-related logic and URL type checking,
making the caching behavior more predictable and maintainable.

Attributes:
    url (str): The URL being processed.
    cache_mode (CacheMode): The cache mode for the current operation.
    always_bypass (bool): If True, bypasses caching for this operation.
    is_cacheable (bool): True if the URL is cacheable, False otherwise.
    is_web_url (bool): True if the URL is a web URL, False otherwise.
    is_local_file (bool): True if the URL is a local file, False otherwise.
    is_raw_html (bool): True if the URL is raw HTML, False otherwise.
    _url_display (str): The display name for the URL (web, local file, or raw HTML).
url
cache_modealways_bypassc                    Xl         X l        X0l        UR                  S5      U l        UR                  S5      U l        UR                  S5      U l        UR                  S5      U l        U R                  (       d  Xl        gSU l        g)a  
Initializes the CacheContext with the provided URL and cache mode.

Args:
    url (str): The URL being processed.
    cache_mode (CacheMode): The cache mode for the current operation.
    always_bypass (bool): If True, bypasses caching for this operation.
)http://https://file://)r!   r"   r#   zraw:zRaw HTMLN)	r   r   r   
startswithis_cacheable
is_web_urlis_local_fileis_raw_html_url_display)selfr   r   r   s       r   __init__CacheContext.__init__)   sn     $*NN+MN..)@A ^^I6>>&1'+'7'7CZr   returnc                     U R                   (       d  U R                  (       d  gU R                  [        R                  [        R
                  4;   $ )a  
Determines if cache should be read based on context.

How it works:
1. If always_bypass is True or is_cacheable is False, return False.
2. If cache_mode is ENABLED or READ_ONLY, return True.

Returns:
    bool: True if cache should be read, False otherwise.
F)r   r%   r   r   r   r   r*   s    r   should_readCacheContext.should_read;   s8     T%6%69#4#4i6I6I"JJJr   c                     U R                   (       d  U R                  (       d  gU R                  [        R                  [        R
                  4;   $ )a
  
Determines if cache should be written based on context.

How it works:
1. If always_bypass is True or is_cacheable is False, return False.
2. If cache_mode is ENABLED or WRITE_ONLY, return True.

Returns:
    bool: True if cache should be written, False otherwise.
F)r   r%   r   r   r   r   r/   s    r   should_writeCacheContext.should_writeJ   s8     T%6%69#4#4i6J6J"KKKr   c                     U R                   $ )z"Returns the URL in display format.)r)   r/   s    r   display_urlCacheContext.display_urlY   s        r   )r)   r   r   r%   r'   r(   r&   r   N)F)r   r   r   r   r   strr   boolr+   r0   r3   propertyr6   r   r   r   r   r   r      s\    "HC HY Ht H$KT KLd L !S ! !r   r   disable_cachebypass_cacheno_cache_readno_cache_writer-   c                    U (       a  [         R                  $ U(       a  [         R                  $ U(       a  U(       a  [         R                  $ U(       a  [         R                  $ U(       a  [         R                  $ [         R
                  $ )z
Converts legacy cache parameters to the new CacheMode enum.

This is an internal function to help transition from the old boolean flags
to the new CacheMode system.
)r   r   r   r   r   r   )r;   r<   r=   r>   s       r   _legacy_to_cache_moder@   _   s]     !!!!!!###"""r   N)FFFF)enumr   r   r   r9   r@   r   r   r   <module>rB      sb     &E! E!R   	  	
 r   