ó
¶qëcc           @   sC   d  d l  m Z d  d l m Z d e f d „  ƒ  YZ e ƒ  Z d S(   iÿÿÿÿ(   t   six(   t   settingst   Aliasesc           B   sh   e  Z d  Z e d „ Z d „  Z d	 d „ Z d	 d „ Z d	 e d „ Z	 d „  Z
 e d „ Z d „  Z RS(
   s_   
    A container which stores and retrieves named easy-thumbnail options
    dictionaries.
    c         C   s    i  |  _  | r |  j ƒ  n  d S(   sÏ   
        Initialize the Aliases object.

        :param populate_from_settings: If ``True`` (default) then populate the
            initial aliases from settings. See :meth:`populate_from_settings`.
        N(   t   _aliasest   populate_from_settings(   t   selfR   (    (    ss   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/alias.pyt   __init__   s    	c         C   sU   t  j } | rQ x? | j ƒ  D]. \ } } |  j j | i  ƒ } | j | ƒ q Wn  d S(   sN   
        Populate the aliases from the ``THUMBNAIL_ALIASES`` setting.
        N(   R   t   THUMBNAIL_ALIASESt   itemsR   t
   setdefaultt   update(   R   t   settings_aliasest   targett   aliasest   target_aliases(    (    ss   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/alias.pyR      s
    	c         C   s8   |  j  | ƒ p d } |  j j | i  ƒ } | | | <d S(   s%  
        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).
        t    N(   t   _coerce_targetR   R	   (   R   t   aliast   optionsR   R   (    (    ss   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/alias.pyt   set!   s    
c         C   sF   x? t  t |  j | ƒ ƒ ƒ D]" } |  j | | ƒ } | r | Sq Wd S(   sî   
        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(   t   reversedt   listt   _get_targetst   _get(   R   R   R   t   target_partR   (    (    ss   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/alias.pyt   get/   s    	"c         C   sC   i  } x6 |  j  | | ƒ D]" } | j |  j j | i  ƒ ƒ q W| S(   s©  
        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   t   include_globalR   R   (    (    ss   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/alias.pyt   all=   s     c         C   s'   | |  j  k r d S|  j  | j | ƒ S(   s:   
        Internal method to get a specific alias.
        N(   R   R   (   R   R   R   (    (    ss   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/alias.pyR   P   s    c         c   sm   |  j  | ƒ } | r d Vn  | s' d S| j d ƒ } x0 t t | ƒ ƒ D] } d j | | d  ƒ VqI Wd S(   s  
        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   Nt   .i   (   R   t   splitt   ranget   lent   join(   R   R   R   t   target_bitst   i(    (    ss   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/alias.pyR   X   s    
c         C   sƒ   | s t  | t j ƒ r | St | d ƒ s0 d St | j d t ƒ rW | j j j	 } n | j j
 } d | j j | j | j j f S(   s¶   
        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.
        t   instancet	   _deferreds   %s.%s.%sN(   t
   isinstanceR    t   string_typest   hasattrt   Nonet   getattrR#   t   Falset   _metat   proxy_for_modelt	   __class__t	   app_labelt   __name__t   fieldt   name(   R   R   t   model(    (    ss   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/alias.pyR   k   s    	N(   R/   t
   __module__t   __doc__t   TrueR   R   R(   R   R   R   R   R   R   (    (    (    ss   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/alias.pyR      s   	
	N(   t   django.utilsR    t   easy_thumbnails.confR   t   objectR   R   (    (    (    ss   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/alias.pyt   <module>   s   }