
    g                     V    d dl Z d dlZd dlZd dlmZ d dlmZ  G d d      Z e       Zy)    N)CacheAdapter)check_property_enabledc                   |    e Zd ZdZd Zd Zed        Zed        Z	e
d        Ze
d        Ze
d        Ze
d	        Zy
)ResponsiveBreakpointsCachez6
    Caches breakpoint values for image resources
    c                 V    d| _         |j                  d      }| j                  |       y)za
        Initialize the cache

        :param cache_options: Cache configuration options
        Ncache_adapter)_cache_adaptergetset_cache_adapter)selfcache_optionsr   s      B/opt/Tautulli/lib/cloudinary/cache/responsive_breakpoints_cache.py__init__z#ResponsiveBreakpointsCache.__init__   s*     #%))/:}-    c                 8    |t        |t              sy|| _        y)z
        Assigns cache adapter

        :param cache_adapter: The cache adapter used to store and retrieve values

        :return: Returns True if the cache_adapter is valid
        FT)
isinstancer   r	   )r   r   s     r   r   z,ResponsiveBreakpointsCache.set_cache_adapter   s!      
=,(O+r   c                     | j                   duS )zs
        Indicates whether cache is enabled or not

        :return: Rrue if a _cache_adapter has been set
        N)r	   r   s    r   enabledz"ResponsiveBreakpointsCache.enabled*   s     ""$..r   c                      t        j                  |       }t        j                  j                  di |\  }}| j                  dd      }| j                  dd      }| j                  dd      }||||fS )z
        Extract the parameters required in order to calculate the key of the cache.

        :param options: Input options

        :return: A list of values used to calculate the cache key
        format typeuploadresource_typeimage )copydeepcopy
cloudinaryutilsgenerate_transformation_stringr
   )optionsoptions_copytransformation_file_formatstorage_typer   s          r   _options_to_parametersz1ResponsiveBreakpointsCache._options_to_parameters3   so     }}W-&,,KK[l[kk(B/{{684OW=]NKGGr   c                 `     | j                   di |} | j                  j                  |g| S )a'  
        Retrieve the breakpoints of a particular derived resource identified by the public_id and options

        :param public_id: The public ID of the resource
        :param options: The public ID of the resource

        :return: Array of responsive breakpoints, None if not found
        r   )r)   r	   r
   r   	public_idr#   paramss       r   r
   zResponsiveBreakpointsCache.getD   s7     -,,7w7&t""&&y:6::r   c                     t        |t        t        f      st        d       | j                  di |\  }}}}| j
                  j                  ||||||      S )a(  
        Set responsive breakpoints identified by public ID and options

        :param public_id: The public ID of the resource
        :param value:  Array of responsive breakpoints to set
        :param options: Additional options

        :return: True on success or False on failure
        z!A list of breakpoints is expectedr   )r   listtuple
ValueErrorr)   r	   set)r   r,   valuer#   r(   r   r%   r'   s           r   r2   zResponsiveBreakpointsCache.setR   s`     54-0@AAC^4C^C^CiahCi@m^[""&&y,~_jlqrrr   c                 `     | j                   di |} | j                  j                  |g| S )z
        Delete responsive breakpoints identified by public ID and options

        :param public_id: The public ID of the resource
        :param options: Additional options

        :return: True on success or False on failure
        r   )r)   r	   deleter+   s       r   r5   z!ResponsiveBreakpointsCache.deleted   s7     -,,7w7)t"")))=f==r   c                 6    | j                   j                         S )zd
        Flush all entries from cache

        :return: True on success or False on failure
        )r	   	flush_allr   s    r   r7   z$ResponsiveBreakpointsCache.flush_allr   s     "",,..r   N)__name__
__module____qualname____doc__r   r   propertyr   staticmethodr)   r   r
   r2   r5   r7   r   r   r   r   r   
   s    . / / H H  ; ; s s" > > / /r   r   )	r   collectionsr    &cloudinary.cache.adapter.cache_adapterr   cloudinary.utilsr   r   instancer   r   r   <module>rB      s+       ? 3o/ o/d &'r   