ó
U³úVc           @@  s¡  d  d l  m Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d  d l Z d „  Z	 e
 d d „ Z e j d k r´e Z d Z e j Z e j d k rÁ e j Z e j Z e j Z n e Z e Z e j Z d e j f d	 „  ƒ  YZ d
 e j f d „  ƒ  YZ d e j f d „  ƒ  YZ e j e j j d ƒ d e  ƒZ! e" e! d d ƒ Z# e# r–e" e d e j$ ƒ e# _% e j e j& e ƒ e j f e# _' n	 d „  Z# d „  Z( d „  Z) né d  d l* Z* e j+ j, Z- e j. Z/ e j0 Z1 Z2 e j3 Z4 e4 d ƒ j5 Z6 d Z7 d Z8 d Z9 d Z: d Z; d Z< d Z= d Z> d Z? d  Z@ d ZA d ZB d ZC d ZD e1 e/ e/ e j3 e/ e/ e4 g e- jE _' e4 e- jE _% d „  ZF d  eG f d! „  ƒ  YZ d S("   i    (   t   absolute_importNc         C@  sž   t  j |  ƒ r t  j St  j |  ƒ r, t  j St  j |  ƒ rB t  j St  j |  ƒ rX t  j St  j	 |  ƒ rn t  j
 St  j |  ƒ r„ t  j St  j |  ƒ rš t  j S|  S(   N(   t   statmodt   S_ISREGt   S_IFREGt   S_ISDIRt   S_IFDIRt   S_ISLNKt   S_IFLNKt   S_ISBLKt   S_IFBLKt   S_ISCHRt   S_IFCHRt   S_ISFIFOt   S_IFIFOt   S_ISSOCKt   S_IFSOCK(   t   mode(    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyt   _mode_to_kind   s    c         C@  sÕ   g  } |  } | j  t j ƒ s. | t j 7} n  t j |  ƒ } | j ƒ  x‡ | D] } t j | | ƒ } | | k r‰ t j | j ƒ r‰ g  S| r± | j	 | t
 | j ƒ | f ƒ qN | j	 | t
 | j ƒ f ƒ qN W| S(   s  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)
    (   t   endswitht   ost   sept   listdirt   sortt   lstatR   R   t   st_modet   appendR   (   t   patht   statt   skipt   resultt   prefixt   namest   fnt   st(    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyR   "   s    
" t   nti   t   linux2t   _iovecc           B@  s&   e  Z d  e j f d e j f g Z RS(   t   iov_baset   iov_len(   t   __name__t
   __module__t   ctypest   c_void_pt   c_size_tt   _fields_(    (    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyR$   Q   s   t   _msghdrc           B@  s_   e  Z d  e j f d e f d e j e ƒ f d e f d e j f d e f d e j	 f g Z
 RS(   t   msg_namet   msg_namelent   msg_iovt
   msg_iovlent   msg_controlt   msg_controllent	   msg_flags(   R'   R(   R)   R*   t
   _socklen_tt   POINTERR$   t   _msg_iovlen_tt   _msg_controllen_tt   c_intR,   (    (    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyR-   W   s   			t   _cmsghdrc           B@  s?   e  Z d  e f d e j f d e j f d e j d f g Z RS(   t   cmsg_lent
   cmsg_levelt	   cmsg_typet	   cmsg_datai    (   R'   R(   t   _cmsg_len_tR)   R9   t   c_ubyteR,   (    (    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyR:   b   s   	t   ct	   use_errnot   recvmsgt	   c_ssize_tc         C@  s   t  d ƒ ‚ d  S(   Ns   unsupported platform(   t   NotImplementedError(   t   sockfdt   msgt   flags(    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyt   _recvmsgr   s    c         C@  sA   |  j  t j t ƒ k  r d  St j |  j t j t ƒ ƒ } | j S(   N(   R3   R)   t   sizeofR:   t   castR2   R6   t   contents(   t   msght   cmsgptr(    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyt   _CMSG_FIRSTHDRu   s    c         C@  ss  t  j d ƒ  } t t  j | t  j ƒ t  j | ƒ ƒ } t  j d ƒ } t d d t  j	 | ƒ d t  j | t  j ƒ t  j | ƒ d ƒ } t
 |  t  j | ƒ d ƒ } | d k  rÓ t  j ƒ  } t | t j | ƒ ƒ ‚ n  t | ƒ } | sé g  S| j t j k s
| j t k rg  St  j | j t  j t  j ƒ ƒ } | j t j j t  j t  j ƒ }	 g  t |	 ƒ D] }
 | |
 ^ q_S(   s+   receive list of file descriptors via socketi   i   i    N(   R)   R@   R$   RK   R*   RJ   t   create_string_bufferR-   t   Nonet   pointerRI   t   byreft	   get_errnot   OSErrorR   t   strerrorRO   R<   t   sockett
   SOL_SOCKETR=   t   _SCM_RIGHTSR>   R6   R9   R;   R:   t   offsett   xrange(   RF   t   dummyt   iovt   cbufRM   t   rt   et   cmsgt   rfdst	   rfdscountt   i(    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyt   recvfds~   s*    '		!iÿÿÿÿi   i   i   I   €    i   @i€   i   i @  i €  c         C@  s/   t  j ƒ  } t | j d |  | j f ƒ ‚ d  S(   Ns   %s: %s(   R)   t   WinErrort   IOErrort   errnoRV   (   t   namet   err(    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyt   _raiseioerror¿   s    t	   posixfilec           B@  sJ   e  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(	   sk  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.R_   iÿÿÿÿc         C@  sv  d | k r t  } n t } | d } | d k rP d | k rP | t O} t } n | t O} t t B} | d k ry t } nD | d k rŽ t } n/ | d k r­ t } | t	 O} n t
 d | ƒ ‚ t j | | t t Bt Bd  | t d  ƒ } | t k rÿ t | ƒ n  t j | | ƒ }	 |	 d k r7t j | ƒ t | ƒ n  t j |	 | | ƒ }
 t j |  d	 | ƒ t j |  d
 |
 ƒ d  S(   Nt   bi    R_   t   +t   wt   as   invalid mode: %siÿÿÿÿRi   t   _file(   t	   _O_BINARYt   _O_TEXTt	   _O_RDONLYt   _GENERIC_READt   _O_RDWRt   _GENERIC_WRITEt   _OPEN_EXISTINGt   _CREATE_ALWAYSt   _OPEN_ALWAYSt	   _O_APPENDt
   ValueErrort	   _kernel32t   CreateFileAt   _FILE_SHARE_READt   _FILE_SHARE_WRITEt   _FILE_SHARE_DELETERQ   t   _FILE_ATTRIBUTE_NORMALt   _INVALID_HANDLE_VALUERk   t   msvcrtt   open_osfhandlet   CloseHandleR   t   fdopent   objectt   __setattr__(   t   selfRi   R   t   bufsizeRH   t   m0t   accesst   creationt   fht   fdt   f(    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyt   __init__Ï   s:    	

	

		c         C@  s   |  j  S(   N(   Rq   (   RŠ   (    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyt   __iter__û   s    c         C@  s   t  |  j | ƒ S(   N(   t   getattrRq   (   RŠ   Ri   (    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyt   __getattr__þ   s    c         C@  s   |  j  j | | ƒ S(   sÅ   mimics the read-only attributes of Python file objects
            by raising 'TypeError: readonly attribute' if someone tries:
              f = posixfile('foo.txt')
              f.name = 'bla'  (   Rq   R‰   (   RŠ   Ri   t   value(    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyR‰     s    c         C@  s   |  j  j ƒ  S(   N(   Rq   t	   __enter__(   RŠ   (    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyR—     s    c         C@  s   |  j  j | | | ƒ S(   N(   Rq   t   __exit__(   RŠ   t   exc_typet	   exc_valuet   exc_tb(    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyR˜     s    (	   R'   R(   t   __doc__R’   R“   R•   R‰   R—   R˜   (    (    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyRl   Ã   s   
,				(H   t
   __future__R    R)   t   ctypes.utilR   RW   R   R   t   sysR   t   FalseRQ   R   Ri   t   openRl   RY   t   c_uintR5   t   platformR+   R?   R8   R7   R9   t	   StructureR$   R-   R:   t   CDLLt   utilt   find_libraryt   Truet   _libcR”   RI   t   c_longt   restypeR6   t   argtypesRO   Re   R„   t   windllt   kernel32R}   t   c_ulongt   _DWORDt   c_char_pt   _LPCSTRt   _LPSTRR*   t   _HANDLER–   Rƒ   R   R€   R   Ry   Rx   Rz   Ru   Rw   R‚   Rt   Rv   R{   Rs   Rr   R~   Rk   Rˆ   (    (    (    s9   /usr/lib/python2.7/dist-packages/mercurial/pure/osutil.pyt   <module>   sp   					!						