
    	^c                     t   d dl Z d dlZ d dlZd dlZddlmZ ddlmZmZ d Z	ddZ
ej        seZdS d dlZe j        j        Ze j        Ze j        xZZe j        Z ed          j        Zd	ZdZd
ZdZdZd
Z dZ!dZ"dZ#d Z$dZ%dZ&dZ'dZ(eeee j        eeegej)        _*        eej)        _+        d Z, G d d          ZdS )    N   )getattr)encodingpycompatc                    t          j        |           rt           j        S t          j        |           rt           j        S t          j        |           rt           j        S t          j        |           rt           j        S t          j	        |           rt           j
        S t          j        |           rt           j        S t          j        |           rt           j        S | S N)statmodS_ISREGS_IFREGS_ISDIRS_IFDIRS_ISLNKS_IFLNKS_ISBLKS_IFBLKS_ISCHRS_IFCHRS_ISFIFOS_IFIFOS_ISSOCKS_IFSOCK)modes    7/usr/lib/python3/dist-packages/mercurial/pure/osutil.py_mode_to_kindr      s    t t t t t    K    Fc                    g }| }|                     t          j                  s|t          j        z  }t          j        |           }|                                 |D ]}t          j        ||z             }||k    rt          j        |j	                  rg c S |r+|
                    |t          |j	                  |f           i|
                    |t          |j	                  f           |S )a  listdir(path, stat=False) -> list_of_tuples

    Return a sorted list containing information about the entries
    in the directory.

    If stat is True, each element is a 3-tuple:

      (name, type, stat object)

    Otherwise, each element is a 2-tuple:

      (name, type)
    )endswithr   osseposlistdirsortlstatr	   r   st_modeappendr   )pathstatskipresultprefixnamesfnsts           r   r    r    '   s     FF??8>** !(. JtE	JJLLL ; ;Xfrk""::'/"*55:III 	;MM2}RZ88"=>>>>MM2}RZ889::::Mr            l        i   @      i @  i   c                     t          j                    }t          |j        t	          j        |           d|j                  )Nz: )ctypesWinErrorIOErrorerrnor   strfromlocalstrerror)nameerrs     r   _raiseioerrorr<   x   sB    oI8#8#>#>#>#>M
 
 	
r   c                   8    e Zd ZdZddZd Zd Zd Zd Zd	 Z	d
S )	posixfileak  a file object aiming for POSIX-like semantics

        CPython's open() returns a file that was opened *without* setting the
        _FILE_SHARE_DELETE flag, which causes rename and unlink to abort.
        This even happens if any hardlinked copy of the file is in open state.
        We set _FILE_SHARE_DELETE here, so files opened with posixfile can be
        renamed and deleted while they are held open.
        Note that if a file opened with posixfile is unlinked, the file
        remains but cannot be opened again or be recreated under the same name,
        until all reading processes have closed the file.   rr-   c           	      J   d|v rt           }nt          }|dd         }|dk    rd|vr|t          z  }t          }n|t          z  }t          t
          z  }|dk    rt          }nJ|dk    rt          }n<|dk    rt          }|t          z  }n$t          dt          j        |          z            t                              ||t          t           z  t"          z  d |t$          d           }|t&          k    rt)          |           t+          j        ||          }	|	d	k    r)t                              |           t)          |           t1          j        |	t          j        |          |          }
t4                              | d
|           t4                              | d|
           d S )N   br   r.   r?      +   w   azinvalid mode: %sr-   r:   _file)	_O_BINARY_O_TEXT	_O_RDONLY_GENERIC_READ_O_RDWR_GENERIC_WRITE_OPEN_EXISTING_CREATE_ALWAYS_OPEN_ALWAYS	_O_APPEND
ValueErrorr   sysstr	_kernel32CreateFileA_FILE_SHARE_READ_FILE_SHARE_WRITE_FILE_SHARE_DELETE_FILE_ATTRIBUTE_NORMAL_INVALID_HANDLE_VALUEr<   msvcrtopen_osfhandleCloseHandler   fdopenobject__setattr__)selfr:   r   bufsizeflagsm0accesscreationfhfdfs              r   __init__zposixfile.__init__   s   t||!acBTzzd$.."&  &7Tzz)t)t'" !3hod6K6K!KLLL&& #447II& B ***d###&r511BRxx%%b)))d###	"hod33W==A tVT222tWa00000r   c                     | j         S r   )rE   r_   s    r   __iter__zposixfile.__iter__   s
    :r   c                 ,    t          | j        |          S r   )r   rE   )r_   r:   s     r   __getattr__zposixfile.__getattr__   s    4:t,,,r   c                 8    | j                             ||          S )zmimics the read-only attributes of Python file objects
            by raising 'TypeError: readonly attribute' if someone tries:
              f = posixfile('foo.txt')
              f.name = 'bla'
            )rE   r^   )r_   r:   values      r   r^   zposixfile.__setattr__   s     :))$666r   c                 8    | j                                          | S r   )rE   	__enter__rj   s    r   rq   zposixfile.__enter__   s    J  """Kr   c                 :    | j                             |||          S r   )rE   __exit__)r_   exc_type	exc_valueexc_tbs       r   rs   zposixfile.__exit__   s    :&&xFCCCr   N)r?   r-   )
__name__
__module____qualname____doc__rh   rk   rm   r^   rq   rs    r   r   r>   r>   ~   s        		= 		=0	1 0	1 0	1 0	1d	 	 		- 	- 	-	7 	7 	7	 	 		D 	D 	D 	D 	Dr   r>   )FN)-r4   ctypes.utilr   r&   r	   r   r    r   r   r    	iswindowsopenr>   rY   windllkernel32rR   c_ulong_DWORDc_char_p_LPCSTR_LPSTRc_void_p_HANDLEro   rX   rT   rU   rV   rM   rL   rN   rI   rK   rW   rH   rJ   rO   rG   rF   rS   argtypesrestyper<   r{   r   r   <module>r      s        				                   $   >  IDIII MMM&I^F&GfoG#GBKK- ""#NNLMN! IGIGI
 	&I" %,I!
 
 
QD QD QD QD QD QD QD QD QD QDr   