ó
ø¢TQc           @   s<   d  Z  d d l m Z d e f d „  ƒ  YZ e d „ Z d S(   sM   
Utility functions for handling images.

Requires PIL, as you might imagine.
iÿÿÿÿ(   t   Filet	   ImageFilec           B   sA   e  Z d  Z d „  Z e e ƒ Z d „  Z e e ƒ 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(    (    s1   ../Django//lib/python/django/core/files/images.pyt
   _get_width   s    c         C   s   |  j  ƒ  d S(   Ni   (   R   (   R   (    (    s1   ../Django//lib/python/django/core/files/images.pyt   _get_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   (    (    s1   ../Django//lib/python/django/core/files/images.pyR      s
    	
(	   t   __name__t
   __module__t   __doc__R   t   propertyt   widthR   t   heightR   (    (    (    s1   ../Django//lib/python/django/core/files/images.pyR   	   s   		c         C   s  y d d l  m } Wn t k
 r3 d d l } n X| j ƒ  } t |  d ƒ rq |  } | j ƒ  } | j d ƒ n t |  d ƒ } t } zW d } xF | j	 | ƒ } | s« Pn  | j
 | ƒ | j rË | j j S| d } q’ d 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   Nt   readi    t   rbi   i   (   t   PILR   t   ImportErrort   ParserR   t   tellt   seekR
   t   TrueR   t   feedt   imaget   sizet   NoneR   (   t   file_or_pathR   t   PILImageFilet   pt   filet   file_post
   chunk_sizet   data(    (    s1   ../Django//lib/python/django/core/files/images.pyR      s2    	
N(   R   t   django.core.filesR    R   t   FalseR   (    (    (    s1   ../Django//lib/python/django/core/files/images.pyt   <module>   s   