ó
P'—^c           @   s   d  d l  m  Z  d  d l m Z d  d l m Z d d l m Z d d l m Z d d l	 m
 Z
 d d l m Z m Z d d	 l m Z m Z m Z d d
 l m Z m Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d „  Z d „  Z d e f d „  ƒ  YZ d S(   iÿÿÿÿ(   t   copy(   t   settings(   t   ImageFieldFilei   (   t   get_default_cachefile_backend(   t   load_strategy(   t   hashers(   t   AlreadyRegisteredt   MissingSource(   t
   open_imaget   get_by_qnamet   process_image(   t   generator_registryt   registert   BaseImageSpecc           B   s;   e  Z d  Z d Z d Z e j Z d „  Z	 d „  Z
 e Z RS(   s_   
    An object that defines how an new image should be generated from a source
    image.

    c         C   s+   |  j  p t ƒ  |  _  t |  j ƒ |  _ d  S(   N(   t   cachefile_backendR   R   t   cachefile_strategy(   t   self(    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyt   __init__%   s    c         C   s
   t  ‚ d  S(   N(   t   NotImplementedError(   R   (    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyt   generate)   s    N(   t   __name__t
   __module__t   __doc__t   Nonet   cachefile_storageR   R   t#   IMAGEKIT_DEFAULT_CACHEFILE_STRATEGYR   R   R   R   (    (    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyR      s   			t	   ImageSpecc           B   sz   e  Z d  Z g  Z d Z d Z e Z d „  Z	 e
 d „  ƒ Z e
 d „  ƒ Z e j d „  ƒ Z d „  Z d „  Z d „  Z RS(	   s‘   
    An object that defines how to generate a new image from a source file using
    PIL-based processors. (See :mod:`imagekit.processors`)

    c         C   s    | |  _  t t |  ƒ j ƒ  d  S(   N(   t   sourcet   superR   R   (   R   R   (    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyR   V   s    	c         C   s)   |  j  s d  St t j d ƒ } | |  ƒ S(   Nt   namer(   R   R   R	   R   t   IMAGEKIT_SPEC_CACHEFILE_NAMER(   R   t   fn(    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyt   cachefile_nameZ   s    	c         C   s^   t  |  d d  ƒ } | sZ t  |  d d  ƒ } | rZ t  | d | d ƒ } |  _ |  ` qZ n  | S(   Nt   _sourcet   _field_datat   instancet   attname(   t   getattrR   R!   R"   (   R   t   srct
   field_data(    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyR   a   s    c         C   s   | |  _  d  S(   N(   R!   (   R   t   value(    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyR   k   s    c         C   s}   t  |  j ƒ } t |  j t ƒ ry t |  j d ƒ } i t |  j d d  ƒ d 6t | d d  ƒ d 6| d <| j d d  ƒ n  | S(   Nt   fieldR#   t   nameR$   R"   R!   (   R    t   __dict__t
   isinstanceR   R   R%   R   t   pop(   R   t   stateR)   (    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyt   __getstate__o   s    c         C   s.   t  j |  j j |  j |  j |  j |  j g ƒ S(   N(   R   t   pickleR   R*   t
   processorst   formatt   optionst   autoconvert(   R   (    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyt   get_hash„   s    	c      
   C   s    |  j  s t d |  ƒ ‚ n  y t |  j  ƒ } Wn- t k
 r^ |  j  j ƒ  t |  j  ƒ } n Xt | d |  j d |  j d |  j d |  j	 ƒ} |  j  j
 ƒ  | S(   Ns4   The spec '%s' has no source file associated with it.R1   R2   R4   R3   (   R   R   R   t
   ValueErrort   openR
   R1   R2   R4   R3   t   close(   R   t   imgt	   new_image(    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyR      s    	N(   R   R   R   R1   R   R2   R3   t   TrueR4   R   t   propertyR    R   t   setterR/   R5   R   (    (    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyR   4   s   		
			c            s/   d t  f ‡  f d †  ƒ  Y} t d | f ˆ  ƒ S(   Nt   DynamicSpecBasec              s   e  Z ‡  f d  †  Z RS(   c            sC   y |  j  } Wn t k
 r) |  j } n
 X| ƒ  } t ˆ  | f f S(   N(   R/   t   AttributeErrorR+   t   create_spec(   R   t   getstateR.   (   t   class_attrs(    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyt
   __reduce__¦   s    	(   R   R   RC   (    (   RB   (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyR>   ¥   s   t   DynamicSpec(   R   t   type(   RB   R>   (    (   RB   s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyt   create_spec_class£   s    
c         C   sS   t  |  ƒ } | j | ƒ } y | j } Wn t k
 rD | | _ n X| | ƒ | S(   N(   RF   t   __new__t   __setstate__R?   R+   (   RB   R.   t   clsR#   t   setstate(    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyR@   ²   s    
t   SpecHostc           B   s/   e  Z d  Z d d d „ Z d „  Z d „  Z RS(   sh   
    An object that ostensibly has a spec attribute but really delegates to the
    spec registry.

    c         K   si   t  d „  | j ƒ  Dƒ ƒ } | rF | r7 t d ƒ ‚ qF t | ƒ } n  | |  _ | re |  j | ƒ n  d  S(   Nc         s   s-   |  ]# \ } } | d  k	 r | | f Vq d  S(   N(   R   (   t   .0t   kt   v(    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pys	   <genexpr>Æ   s    s^   You can provide either an image spec or arguments for the ImageSpec constructor, but not both.(   t   dictt   itemst	   TypeErrorRF   t   _original_spect   set_spec_id(   R   t   spect   spec_idt   kwargst
   spec_attrs(    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyR   Ä   s    	c         C   sD   | |  _  |  j r@ y t j | |  j ƒ Wq@ t k
 r< q@ Xn  d S(   s[  
        Sets the spec id for this object. Useful for when the id isn't
        known when the instance is constructed (e.g. for ImageSpecFields whose
        generated `spec_id`s are only known when they are contributed to a
        class). If the object was initialized with a spec, it will be registered
        under the provided id.

        N(   RU   RR   R   t	   generatorR   (   R   t   id(    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyRS   Ô   s    			c         C   s;   t  |  d d ƒ s% t d |  ƒ ‚ n  t j |  j d | ƒS(   s  
        Look up the spec by the spec id. We do this (instead of storing the
        spec as an attribute) so that users can override apps' specs--without
        having to edit model definitions--simply by registering another spec
        with the same id.

        RU   s   Object %s has no spec id.R   N(   R%   R   t	   ExceptionR   t   getRU   (   R   R   (    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyt   get_specê   s    N(   R   R   R   R   R   RS   R\   (    (    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyRK   ¾   s   	N(   R    t   django.confR   t   django.db.models.fields.filesR   t   cachefiles.backendsR   t   cachefiles.strategiesR   t    R   t
   exceptionsR   R   t   utilsR   R	   R
   t   registryR   R   t   objectR   R   RF   R@   RK   (    (    (    s9   /tmp/pip-unpacked-wheel-XxTEJK/imagekit/specs/__init__.pyt   <module>   s   (o		