
 Xv                 @   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)
aG  
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
    N)FileProxyMixinNamedTemporaryFile
gettempdirntc               @   s|   e  Z d  Z d Z d d d d d d d  Z e j Z d d	   Z e 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.

        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+.
        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   D/home/ubuntu/projects/ifolica/build/django/django/core/files/temp.py__init__&   s    $	zTemporaryFile.__init__c             C   sn   |  j  sj d |  _  y |  j j   Wn t t f k
 r= Yn Xy |  j |  j  Wqj t k
 rf Yqj Xn  d  S)NT)r   r   closeOSErrorIOErrorunlinkr   )r   r   r   r   r   1   s    		zTemporaryFile.closec             C   s
   |  j  j S)z
            This attribute needs to be accessible in certain situations,
            because this class is supposed to mock the API of the class
            tempfile.NamedTemporaryFile in the Python standard library.
            )r   closed)r   r   r   r   r   =   s    zTemporaryFile.closedc             C   s   |  j    d  S)N)r   )r   r   r   r   __del__F   s    zTemporaryFile.__del__c             C   s   |  j  j   |  S)N)r   	__enter__)r   r   r   r   r    I   s    zTemporaryFile.__enter__c             C   s   |  j  j | | |  d  S)N)r   __exit__)r   excvaluetbr   r   r   r!   M   s    zTemporaryFile.__exit__)__name__
__module____qualname____doc__r   r   r   r   propertyr   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   4		