o ]LbC%@sddlmZmZddlZddlZddlZddlZddlZddl m Z ddl m Z m Z ddZ d+d d Ze jseZd ZejZe jd rMejZejZejZneZeZejZGd ddejZGdddejZGdddejZej ej!"dddZ#e e#ddZ$e$re edej%e$_&eje'eejfe$_(nddZ$ddZ)ddZ*dSddl+Z+ej,j-Z.ej/Z0ej1Z2Z3ej4Z5e5dj6Z7d Z8dZ9dZ:dZ;d Zd"Z?d#Z@dZAdZBd$ZCd%ZDd&ZEe2e0e0ej4e0e0e5ge.jF_(e5e.jF_&d'd(ZGGd)d*d*eHZdS),)absolute_importdivisionN)getattr)encodingpycompatcCstt|rtjSt|rtjSt|rtjSt|r tjSt |r(tj St |r0tj St |r8tjS|SN)statmodS_ISREGS_IFREGS_ISDIRS_IFDIRS_ISLNKS_IFLNKS_ISBLKS_IFBLKS_ISCHRS_IFCHRS_ISFIFOS_IFIFOS_ISSOCKS_IFSOCK)moder7/usr/lib/python3/dist-packages/mercurial/pure/osutil.py _mode_to_kinds       rFcCsg}|}|tjs|tj7}t|}||D]/}t||}||kr1t|j r1gS|r?| |t |j |fq| |t |j fq|S)alistdir(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) ) endswithrosseposlistdirsortlstatr r st_modeappendr)pathstatskipresultprefixnamesfnstrrrr)s   rslinuxc@s eZdZdejfdejfgZdS)_ioveciov_baseiov_lenN)__name__ __module__ __qualname__ctypesc_void_pc_size_t_fields_rrrrr-Ysr-c@sFeZdZdejfdefdeefdefdejfde fdej fgZ dS) _msghdrmsg_name msg_namelenmsg_iov msg_iovlen msg_controlmsg_controllen msg_flagsN) r0r1r2r3r4 _socklen_tPOINTERr- _msg_iovlen_t_msg_controllen_tc_intr6rrrrr7_s r7c@s2eZdZdefdejfdejfdejdfgZdS)_cmsghdrcmsg_len cmsg_level cmsg_type cmsg_datarN)r0r1r2 _cmsg_len_tr3rCc_ubyter6rrrrrDjs  rDcT) use_errnorecvmsg c_ssize_tcCstd)Nsunsupported platform)NotImplementedError)sockfdmsgflagsrrr_recvmsg}srScCs.|jttkr dSt|jtt}|jSr)r=r3sizeofrDcastr<r@contents)msghcmsgptrrrr_CMSG_FIRSTHDRsrYc stjd}tt|tjt|}td}tddt|dt|tjt|d}t |t |d}|dkrFt }t |t |t|}|sNgS|jtjksY|jtkr[gSt|jttj|jtjjttj}fddt|DS)z+receive list of file descriptors via socketr,Nrcsg|]}|qSrr).0irfdsrr szrecvfds..)r3rJr-rUr4rTcreate_string_bufferr7pointerrSbyref get_errnoOSErrorrstrerrorrYrFsocket SOL_SOCKETrG _SCM_RIGHTSrHr@rCrErDoffsetrxrange) rPdummyiovcbufrWrecmsg rfdscountrr]rrecvfdss6        rrli@i@icCs$t}t|jdt||jf)Nz%s: %s)r3WinErrorIOErrorerrnor strfromlocalre)nameerrrrr _raiseioerrorsr~c@sBeZdZdZdddZddZdd Zd d Zd d ZddZ dS) posixfileaka 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.rrsc Csd|vrt}nt}|dd}|dkrd|vr|tO}t}n|tO}ttB}|dkr-t}n|dkr4t}n|dkr?t}|t O}n t dt |t ||ttBtBd|td}|tkr_t|t||} | d krrt |t|t| t ||} t|d |t|d | dS) Nbrr,r+wazinvalid mode: %srsr|_file) _O_BINARY_O_TEXT _O_RDONLY _GENERIC_READ_O_RDWR_GENERIC_WRITE_OPEN_EXISTING_CREATE_ALWAYS _OPEN_ALWAYS _O_APPEND ValueErrorrsysstr _kernel32 CreateFileA_FILE_SHARE_READ_FILE_SHARE_WRITE_FILE_SHARE_DELETE_FILE_ATTRIBUTE_NORMAL_INVALID_HANDLE_VALUEr~msvcrtopen_osfhandle CloseHandlerfdopenobject __setattr__) selfr|rbufsizerRm0accesscreationfhfdfrrr__init__sF      zposixfile.__init__cCs|jSr)rrrrr__iter__szposixfile.__iter__cCs t|j|Sr)rr)rr|rrr __getattr__!s zposixfile.__getattr__cCs|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' )rr)rr|valuerrrr$szposixfile.__setattr__cCs|j|Sr)r __enter__rrrrr,s zposixfile.__enter__cCs|j|||Sr)r__exit__)rexc_type exc_valueexc_tbrrrr0szposixfile.__exit__N)rrs) r0r1r2__doc__rrrrrrrrrrrs 2 r)FN)I __future__rrr3 ctypes.utilrrfr%r rrrrr iswindowsopenrrhc_uintr? sysplatform startswithr5rIrBrArC Structurer-r7rDCDLLutil find_library_libcrSc_longrestyper@argtypesrYrrrwindllkernel32rc_ulong_DWORDc_char_p_LPCSTR_LPSTRr4_HANDLErrrrrrrrrrrrrrrrrr~rrrrrs      $