ó
Žâ0_c           @   sT   d  Z  d d l Z d d l Z d d l m Z d e f d     YZ e d  Z d S(   sO   
Utility functions for handling images.

Requires Pillow as you might imagine.
i˙˙˙˙N(   t   Filet	   ImageFilec           B   s5   e  Z d  Z e d    Z e d    Z d   Z RS(   s   
    A mixin for use alongside django.core.files.base.File, which provides
    additional features for dealing with images.
    c         C   s   |  j    d S(   Ni    (   t   _get_image_dimensions(   t   self(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/images.pyt   width   s    c         C   s   |  j    d S(   Ni   (   R   (   R   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/images.pyt   height   s    c         C   sA   t  |  d  s: |  j } |  j   t |  d | |  _ n  |  j S(   Nt   _dimensions_cachet   close(   t   hasattrt   closedt   opent   get_image_dimensionsR   (   R   R   (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/images.pyR      s
    	
(   t   __name__t
   __module__t   __doc__t   propertyR   R   R   (    (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/images.pyR      s   c   	      C   s.  d d l  m } | j   } t |  d  rM |  } | j   } | j d  n t |  d  } t } z¤ d } x | j |  } | s Pn  y | j	 |  WnE t
 j k
 rĚ } | j d j d  rĆ qŕ   n t j k
 rß n X| j ró | j j S| d 9} qn Wd
 SWd	 | r| j   n | j |  Xd	 S(   sŻ   
    Returns the (width, height) of an image, given an open file or a path.  Set
    'close' to True to close the file at the end if it is initially in an open
    state.
    i˙˙˙˙(   R   t   readi    t   rbi   s   Error -5i   N(   NN(   t   PILR   t   ParserR   t   tellt   seekR
   t   TrueR   t   feedt   zlibt   errort   argst
   startswitht   structt   imaget   sizet   NoneR   (	   t   file_or_pathR   t   PillowImageFilet   pt   filet   file_post
   chunk_sizet   datat   e(    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/images.pyR   !   s:    	
(   R   R   R   t   django.core.filesR    R   t   FalseR   (    (    (    s:   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/images.pyt   <module>   s
   