ó
Žâ0_c           @   sx   d  Z  d d l Z d d l Z d d l m Z d	 Z e j d k rb d e f d     YZ e Z n	 e j Z e j	 Z	 d S(
   sG  
The temp module provides a NamedTemporaryFile that can be reopened in the same
process on any platform. Most platforms use the standard Python
tempfile.NamedTemporaryFile class, but Windows users are given a custom class.

This is needed because the Python implementation of NamedTemporaryFile uses the
O_TEMPORARY flag under Windows, which prevents the file from being reopened
if the same flag is not provided [1][2]. Note that this does not address the
more general issue of opening a file for writing and reading in multiple
processes in a manner that works across platforms.

Also note that the custom version of NamedTemporaryFile does not support the
full range of keyword arguments available in Python 2.6+ and 3.0+.

1: https://mail.python.org/pipermail/python-list/2005-December/336957.html
2: http://bugs.python.org/issue14243
i˙˙˙˙N(   t   FileProxyMixint   NamedTemporaryFilet
   gettempdirt   ntt   TemporaryFilec           B   sS   e  Z d  Z d d d d d	 d  Z e j Z d   Z d   Z d   Z	 d   Z
 RS(
   s  
        Temporary file object constructor that supports reopening of the
        temporary file in Windows.

        Note that unlike tempfile.NamedTemporaryFile from the standard library,
        __init__() does not support the 'delete' keyword argument in
        Python 2.6+, or the 'delete', 'buffering', 'encoding', or 'newline'
        keyword arguments in Python 3.0+.
        s   w+bi˙˙˙˙t    c         C   sR   t  j d | d | d |  \ } } | |  _ t j | | |  |  _ t |  _ d  S(   Nt   suffixt   prefixt   dir(   t   tempfilet   mkstempt   namet   ost   fdopent   filet   Falset   close_called(   t   selft   modet   bufsizeR   R   R   t   fdR   (    (    s8   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/temp.pyt   __init__&   s    $	c         C   sl   |  j  sh t |  _  y |  j j   Wn t t f k
 r< n Xy |  j |  j  Wqh t k
 rd qh Xn  d  S(   N(   R   t   TrueR   t   closet   OSErrort   IOErrort   unlinkR   (   R   (    (    s8   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/temp.pyR   1   s    		c         C   s   |  j    d  S(   N(   R   (   R   (    (    s8   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/temp.pyt   __del__=   s    c         C   s   |  j  j   |  S(   N(   R   t	   __enter__(   R   (    (    s8   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/temp.pyR   @   s    c         C   s   |  j  j | | |  d  S(   N(   R   t   __exit__(   R   t   exct   valuet   tb(    (    s8   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/temp.pyR   D   s    N(   t   __name__t
   __module__t   __doc__t   NoneR   R   R   R   R   R   R   (    (    (    s8   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/temp.pyR      s   						(   R   R   (
   R#   R   R	   t   django.core.files.utilsR    t   __all__R   R   R   R   (    (    (    s8   /tmp/pip-unpacked-wheel-BAJOf3/django/core/files/temp.pyt   <module>   s   +		