
vÅÏ^»	  ã               @   sx   d  Z  d d l Z d d l Z d d l m Z d	 Z e j d k rb Gd d „  d e ƒ Z e Z n	 e j Z e j	 Z	 d S)
a6  
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.

The custom version of NamedTemporaryFile doesn't support the same keyword
arguments available in tempfile.NamedTemporaryFile.

1: https://mail.python.org/pipermail/python-list/2005-December/336957.html
2: https://bugs.python.org/issue14243
é    N)ÚFileProxyMixinÚNamedTemporaryFileÚ
gettempdirÚntc               @   sj   e  Z d  Z d Z d d d d d d d „ Z e j Z d d	 „  Z d
 d „  Z d d „  Z	 d d „  Z
 d S)ÚTemporaryFilea.  
        Temporary file object constructor that supports reopening of the
        temporary file in Windows.

        Unlike tempfile.NamedTemporaryFile from the standard library,
        __init__() doesn't support the 'delete', 'buffering', 'encoding', or
        'newline' keyword arguments.
        zw+bé   Ú Nc             C   sR   t  j d | d | d | ƒ \ } } | |  _ t j | | | ƒ |  _ d |  _ d  S)NÚsuffixÚprefixÚdirF)ÚtempfileÚmkstempÚnameÚosÚfdopenÚfileÚclose_called)ÚselfÚmodeÚbufsizer	   r
   r   Úfdr   © r   ú8/tmp/pip-build-8lau8j11/django/django/core/files/temp.pyÚ__init__%   s    $	zTemporaryFile.__init__c             C   se   |  j  sa d |  _  y |  j j ƒ  Wn t k
 r7 Yn Xy |  j |  j ƒ Wn t k
 r` Yn Xd  S)NT)r   r   ÚcloseÚOSErrorÚunlinkr   )r   r   r   r   r   0   s    		zTemporaryFile.closec             C   s   |  j  ƒ  d  S)N)r   )r   r   r   r   Ú__del__<   s    zTemporaryFile.__del__c             C   s   |  j  j ƒ  |  S)N)r   Ú	__enter__)r   r   r   r   r   ?   s    zTemporaryFile.__enter__c             C   s   |  j  j | | | ƒ d  S)N)r   Ú__exit__)r   ÚexcÚvalueÚtbr   r   r   r   C   s    zTemporaryFile.__exit__éÿÿÿÿ)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r   r   r   r      s   		r   )zNamedTemporaryFilez
gettempdir)
r'   r   r   Zdjango.core.files.utilsr   Ú__all__r   r   r   r   r   r   r   r   Ú<module>   s   *		