
    h                     2    d dl mZ  G d d      Z e       Zy)    )settingsc                   J    e Zd ZdZddZd ZddZddZddZd Z	dd	Z
d
 Zy)Aliasesz_
    A container which stores and retrieves named easy-thumbnail options
    dictionaries.
    c                 8    i | _         |r| j                          yy)z
        Initialize the Aliases object.

        :param populate_from_settings: If ``True`` (default) then populate the
            initial aliases from settings. See :meth:`populate_from_settings`.
        N)_aliasespopulate_from_settings)selfr   s     E/home/dcms/DCMS/lib/python3.12/site-packages/easy_thumbnails/alias.py__init__zAliases.__init__
   s     !'') "    c                     t         j                  }|rF|j                         D ]2  \  }}| j                  j	                  |i       }|j                  |       4 yy)zN
        Populate the aliases from the ``THUMBNAIL_ALIASES`` setting.
        N)r   THUMBNAIL_ALIASESitemsr   
setdefaultupdate)r	   settings_aliasestargetaliasestarget_aliasess        r
   r   zAliases.populate_from_settings   sX     $55#3#9#9#; /!%!9!9&"!E%%g./ r   Nc                 p    | j                  |      xs d}| j                  j                  |i       }|||<   y)a%  
        Add an alias.

        :param alias: The name of the alias to add.
        :param options: The easy-thumbnails options dictonary for this alias
            (should include ``size``).
        :param target: A field, model, or app to limit this alias to
            (optional).
         N)_coerce_targetr   r   )r	   aliasoptionsr   r   s        r
   setzAliases.set   s9     $$V,211&"= 'ur   c                     t        t        | j                  |                  D ]  }| j                  ||      }|s|c S  y)z
        Get a dictionary of aliased options.

        :param alias: The name of the aliased options.
        :param target: Get alias for this specific target (optional).

        If no matching alias is found, returns ``None``.
        N)reversedlist_get_targets_get)r	   r   r   target_partr   s        r
   getzAliases.get-   s@     $D):):6)B$CD 	KiiU3G	r   c                     i }| j                  ||      D ]-  }|j                  | j                  j                  |i              / |S )a  
        Get a dictionary of all aliases and their options.

        :param target: Include aliases for this specific field, model or app
            (optional).
        :param include_global: Include all non target-specific aliases
            (default ``True``).

        For example::

            >>> aliases.all(target='my_app.MyModel')
            {'small': {'size': (100, 100)}, 'large': {'size': (400, 400)}}
        )r   r   r   r"   )r	   r   include_globalr   r!   s        r
   allzAliases.all;   sG     ,,V^D 	?KNN4==,,["=>	?r   c                 \    || j                   vry| j                   |   j                  |      S )z:
        Internal method to get a specific alias.
        N)r   r"   )r	   r   r   s      r
   r    zAliases._getN   s-     &}}V$((//r   c              #      K   | j                  |      }|rd |sy|j                  d      }t        t        |            D ]  }dj	                  |d|dz            yw)a  
        Internal iterator to split up a complete target into the possible parts
        it may match.

        For example::

            >>> list(aliases._get_targets('my_app.MyModel.somefield'))
            ['', 'my_app', 'my_app.MyModel', 'my_app.MyModel.somefield']
        r   N.   )r   splitrangelenjoin)r	   r   r$   target_bitsis        r
   r   zAliases._get_targetsV   sg      $$V,Hll3's;'( 	0A((;vA.//	0s   AA!c                     |rt        |t              r|S t        |d      sy|j                  j                  }|j
                  j                  d|j                  d|j                  j                  S )z
        Internal method to coerce a target to a string.

        The assumption is that if it is not ``None`` and not a string, it is
        a Django ``FieldFile`` object.
        instanceNr(   )

isinstancestrhasattrr1   	__class___meta	app_label__name__fieldname)r	   r   models      r
   r   zAliases._coerce_targeti   s\     FC0Mvz*))KK!!NNLL
 	
r   )T)N)NT)r8   
__module____qualname____doc__r   r   r   r"   r%   r    r   r    r   r
   r   r      s/    
	*/(&00&
r   r   N)easy_thumbnails.confr   r   r   r?   r   r
   <module>rA      s    )u
 u
p )r   