ó
¶qëcc           @   s
  d  d l  Z  d  d l Z y d  d l m Z Wn! e k
 rO d  d l m Z n Xd  d l m Z d  d l m	 Z	 d  d l
 m Z y d  d l m Z Wn e k
 r³ d  d l Z n Xd  d l m Z d	 e	 f d
 „  ƒ  YZ d e f d „  ƒ  YZ d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t	   cStringIO(   t   BytesIO(   t   ContentFile(   t   FileSystemStorage(   t   TestCase(   t   Image(   t   settingst   TemporaryStoragec           B   s#   e  Z d  Z d d „ Z d „  Z RS(   s¬   
    A storage class useful for tests that uses a temporary location to store
    all files and provides a method to remove this location when it is finished
    with.
    c         O   sG   | d k r$ t j ƒ  } | |  _ n  t t |  ƒ j d | | | Ž d S(   s0   
        Create the temporary location.
        t   locationN(   t   Nonet   tempfilet   mkdtempt   temporary_locationt   superR   t   __init__(   t   selfR   t   argst   kwargs(    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR      s
    c         C   s,   t  |  d d ƒ } | r( t j | ƒ n  d S(   s¨   
        Delete the temporary directory created during initialisation.
        This storage class should not be used again after this method is
        called.
        R   N(   t   getattrR	   t   shutilt   rmtree(   R   R   (    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyt   delete_temporary_storage$   s    N(   t   __name__t
   __module__t   __doc__R	   R   R   (    (    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR      s   
t   FakeRemoteStoragec           B   sA   e  Z d  Z e Z d „  Z d „  Z d „  Z d „  Z d „  Z	 RS(   sc   
    A temporary storage class that acts similar to remote storage.

    It's not thread safe.
    c         O   s+   |  j  r t ‚ n  t t |  ƒ j | | Ž  S(   s†   
        Raise ``NotImplementedError``, since this is the way that
        easy-thumbnails determines if a storage is remote.
        (   t   remote_modet   NotImplementedErrorR   R   t   path(   R   R   R   (    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR   7   s    		c         O   s@   |  j  } t |  _  z t t |  ƒ j | | Ž  SWd  | |  _  Xd  S(   N(   R   t   FalseR   R   t   exists(   R   R   R   t   original_remote_mode(    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR   @   s
    		c         O   s7   t  |  _ z t t |  ƒ j | | Ž  SWd  t |  _ Xd  S(   N(   R   R   R   R   t   savet   True(   R   R   R   (    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR    H   s    	c         O   s7   t  |  _ z t t |  ƒ j | | Ž  SWd  t |  _ Xd  S(   N(   R   R   R   R   t   openR!   (   R   R   R   (    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR"   O   s    	c         O   s7   t  |  _ z t t |  ƒ j | | Ž  SWd  t |  _ Xd  S(   N(   R   R   R   R   t   deleteR!   (   R   R   R   (    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR#   V   s    	(
   R   R   R   R   R   R   R   R    R"   R#   (    (    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR   /   s   					t   BaseTestc           B   s2   e  Z d  Z d „  Z d „  Z d d d d „ Z RS(	   s¸   
    Remove any customised THUMBNAIL_* settings in a project's ``settings``
    configuration module before running the tests to ensure there is a
    consistent test environment.
    c         C   s"   t  t |  ƒ j ƒ  } t t _ | S(   s'   
        Isolate all settings.
        (   R   R$   t   setUpR!   R   t   isolated(   R   t   output(    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR%   e   s    	c         C   s&   t  t _ t j ƒ  t t |  ƒ j ƒ  S(   s;   
        Restore settings to their original state.
        (   R   R   R&   t   revertR   R$   t   tearDown(   R   (    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR)   m   s    	
i   iX  t   RGBt   JPEGc         C   s^   t  ƒ  } t j | | ƒ j | | ƒ | j d ƒ | s< | St | j ƒ  ƒ } | j | | ƒ S(   sÀ   
        Generate a test image, returning the filename that it was saved as.

        If ``storage`` is ``None``, the BytesIO containing the image data
        will be passed instead.
        i    (   R   R   t   newR    t   seekR   t   read(   R   t   storaget   filenamet   sizet
   image_modet   image_formatt   datat
   image_file(    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyt   create_imageu   s    	(   i   iX  (   R   R   R   R%   R)   R6   (    (    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyR$   ^   s
   		(   R   R
   R    R   t   ImportErrort   django.utils.sixt   django.core.files.baseR   t   django.core.files.storageR   t   django.testR   t   PILR   t   easy_thumbnails.confR   R   R   R$   (    (    (    sy   /Users/danaskwith/.local/share/virtualenvs/svtgbi-git-reqaUha4/lib/python2.7/site-packages/easy_thumbnails/tests/utils.pyt   <module>   s    /