
    	                         S r SSKJr  SSKJr  SSKJr  SSKJr  SSKrSSKrSSKr " S S\	5      r
\R                  S
S	 j5       rg)z~Alternate tempfile.NamedTemporaryFile that's easier to use on Windows.

(Windows locks files from simultaneous writes/reads).
    )absolute_import)division)print_function)unicode_literalsNc                   *    \ rS rSrSrS rS rS rSrg)_WindowsNamedTempFile   zWrapper around named temporary file for Windows.

NamedTemporaryFiles cannot be read by other processes on windows because
only one process can open a file at a time. This file will be unlinked
at the end of the context.
c                     UR                  SS5      U l        Xl        UR                  5       U l        SU R                  S'   S U l        g )NdeleteTF)get_requested_delete_argscopy_kwargs_f)selfargskwargss      ?lib/googlecloudsdk/command_lib/code/cross_platform_temp_file.py__init___WindowsNamedTempFile.__init__&   s<    #ZZ$7DJ;;=DL"DLLDG    c                 x    [         R                  " U R                  0 U R                  D6U l        U R                  $ N)tempfileNamedTemporaryFiler   r   r   )r   s    r   	__enter___WindowsNamedTempFile.__enter__-   s*    ))4::FFDG77Nr   c                     U R                   (       a>  U R                  (       a,   [        R                  " U R                  R                  5        g g g ! [
         a     g f = fr   )r   r   osunlinknameOSError)r   exc_type	exc_valuetbs       r   __exit___WindowsNamedTempFile.__exit__1   sF    $''
		$'',, #*  s   *A 
AA)r   r   r   r   N)	__name__
__module____qualname____firstlineno____doc__r   r   r'   __static_attributes__ r   r   r   r      s    r   r   c              #     #    [        SXUS9n[        R                  S:X  a:  [        S0 UD6 nUR	                  U 5        UR                  5         Uv   SSS5        g[        R                  " S0 UD6 nUR	                  U 5        UR                  5         Uv   SSS5        g! , (       d  f       g= f! , (       d  f       g= f7f)zWrite a named temporary with given contents.

Args:
  contents: (str) File contents.
  prefix: (str) File base name prefix.
  suffix: (str) Filename suffix.
  delete: (bool) Delete file on __exit__.

Yields:
  The temporary file object.
zw+t)modeprefixsuffixr   ntNr/   )	dictr    r"   r   writecloser   r   flush)contentsr2   r3   r   common_argsfs         r   NamedTempFiler<   :   s      %fM+WW_		-	-gghggig 
.	-
 
	$	$	3{	3qgghggig 
4	3 
.	-
 
4	3s4   +C&B!C2&B2	C!
B/+C2
C <C)tmp T)r-   
__future__r   r   r   r   
contextlibr    r   objectr   contextmanagerr<   r/   r   r   <module>rC      sG   
 '  % '  	 F 8  r   