o
    ›Œh   ã                   @   sV   d dl mZ G dd„ deƒZG dd„ dƒZ				ddeded	ed
edef
dd„ZdS )é    )ÚEnumc                   @   s$   e Zd ZdZdZdZdZdZdZdS )Ú	CacheModea@  
    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ÚbypassN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚENABLEDÚDISABLEDÚ	READ_ONLYÚ
WRITE_ONLYÚBYPASS© r   r   úS/var/www/Befach/backend/venv/lib/python3.10/site-packages/crawl4ai/cache_context.pyr      s    
r   c                   @   sV   e Zd ZdZddededefdd„Zdefd	d
„Zdefdd„Z	e
defdd„ƒZdS )ÚCacheContexta2  
    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).
    FÚurlÚ
cache_modeÚalways_bypassc                 C   s\   || _ || _|| _| d¡| _| d¡| _| d¡| _| d¡| _| js)|| _dS d| _dS )a9  
        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   r   r   r   Ú__init__'   s   	zCacheContext.__init__Úreturnc                 C   ó"   | j s| jsdS | jtjtjfv S )aK  
        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!   r   r   r   Úshould_read9   ó   zCacheContext.should_readc                 C   r$   )aR  
        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%   r   r   r   Úshould_writeH   r'   zCacheContext.should_writec                 C   s   | j S )z"Returns the URL in display format.)r    r%   r   r   r   Údisplay_urlW   s   zCacheContext.display_urlN)F)r	   r
   r   r   Ústrr   Úboolr"   r&   r(   Úpropertyr)   r   r   r   r   r      s    r   FÚdisable_cacheÚbypass_cacheÚno_cache_readÚno_cache_writer#   c                 C   s<   | rt jS |r
t jS |r|rt jS |rt jS |rt jS t jS )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/   r0   r   r   r   Ú_legacy_to_cache_mode]   s   r1   N)FFFF)Úenumr   r   r   r+   r1   r   r   r   r   Ú<module>   s$    Hüÿþýüû