
    ybjA                    	   % S SK Jr  S SKrS SKrS SKrS SKJr  S SKJr  S SK	J
r
Jr  SSKJr  SSKJrJr  \R"                  S	:X  Gam  S SKrS SKrS S
KJr  SrS\S'   SrS\S'   SrS\S'   \\-  \-  rS\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   SrS\S'   Sr S\S'   Sr!S\S '   \\ -  \!-  r"S\S!'   Sr#S\S"'   Sr$S\S#'   Sr%S\S$'   S%r&S\S&'   S'r'S\S('   S r(S\S)'   S*r)S\S+'   S,r*S\S-'   S.r+S\S/'   S0r,S1\S2'   S3r-S1\S4'   \R\                  " S55      r/S6\S7'   \R\                  " S8S9S:9r0S6\S;'    " S< S=\Rb                  5      r2 " S> S?\Rb                  5      r3 " S@ SA\Rb                  5      r4 " SB SC\Rb                  5      r5 " SD SE\Rb                  5      r6\Rn                  \/Rp                  l9        \Rt                  " \Rv                  5      \Rx                  \Rt                  " \35      \Rt                  " \45      \Rt                  " \Rz                  5      \R|                  \R|                  \R|                  \R|                  \R~                  \R|                  /\/Rp                  l@        \Rn                  \/R                  l9        \R                  \Rt                  " \25      \R~                  \R~                  /\/R                  l@        S\/R                  l9        \Rt                  " \25      /\/R                  l@        \R|                  \/R                  l9        \Rn                  /\/R                  l@        \Rv                  /\0R                  l@        \R                  \0R                  l9        \Rv                  \Rt                  " \65      /\0R                  l@        \R                  \0R                  l9        \Rv                  \Rx                  \Rx                  \Rx                  \Rx                  \Rt                  " \55      /\0R                  l@        \R                  \0R                  l9        \Rv                  \Rx                  \Rx                  \Rx                  \Rt                  " \55      /\0R                  l@        \R                  \0R                  l9        SMSF jrJSNSG jrK " SH SI\5      rLSOSJ jrMSPSK jrNO " SL SI\5      rLSI/rOg)Q    )annotationsN)suppress)Path)Finalcast   )BaseFileLock)ensure_directory_existsraise_on_not_writable_filewin32)wintypesl        z
Final[int]_GENERIC_READi   @_GENERIC_WRITEi   _SYNCHRONIZE_DESIRED_ACCESS   _FILE_SHARE_READ_WRITE_FILE_OPEN_IF_FILE_ATTRIBUTE_READONLY   _FILE_ATTRIBUTE_NORMALi   _FILE_ATTRIBUTE_REPARSE_POINT    _FILE_SYNCHRONOUS_IO_NONALERT@   _FILE_NON_DIRECTORY_FILEi    _FILE_OPEN_REPARSE_POINT_CREATE_OPTIONS_OBJ_CASE_INSENSITIVE_OWNER_WRITE_LOCKFILE_FAIL_IMMEDIATELY   _LOCKFILE_EXCLUSIVE_LOCK!   _ERROR_LOCK_VIOLATION_STATUS_SUCCESSl   "    _STATUS_ACCESS_DENIEDl   C    _STATUS_SHARING_VIOLATIONl   V    _STATUS_DELETE_PENDINGg      ?zFinal[float]_ACCESS_DENIED_GRACEgMb`?_ACCESS_DENIED_RETRYntdllzFinal[ctypes.WinDLL]_ntdllkernel32T)use_last_error	_kernel32c                  f    \ rS rSrS\R
                  4S\R
                  4S\R                  44rSrg)_UNICODE_STRING=   LengthMaximumLengthBuffer N)	__name__
__module____qualname____firstlineno__r   USHORTLPWSTR_fields___static_attributes__r7       ڍ/tmp/claude-0/-home-danvics-docker-quiz/c1e0577a-e42c-4a3d-b1ea-3edd61103a4e/scratchpad/stt/lib/python3.13/site-packages/filelock/_windows.pyr2   r2   =   s-    x'hoo.x'
r@   r2   c                      \ rS rSrS\R
                  4S\R                  4S\R                  " \	5      4S\R
                  4S\R                  4S\R                  44rSrg	)
_OBJECT_ATTRIBUTESD   r4   RootDirectory
ObjectName
AttributesSecurityDescriptorSecurityQualityOfServicer7   N)r8   r9   r:   r;   r   ULONGHANDLEctypesPOINTERr2   c_void_pr>   r?   r7   r@   rA   rC   rC   D   sV    x~~&hoo.6>>/:;8>>*!6??3'9
r@   rC   c                  L    \ rS rSrS\R
                  4S\R
                  44rSrg)_IO_STATUS_BLOCKN   StatusInformationr7   N)r8   r9   r:   r;   rL   rN   r>   r?   r7   r@   rA   rP   rP   N   s!    v'FOO,
r@   rP   c                      \ rS rSrS\R
                  4S\R
                  4S\R                  4S\R                  4S\R                  44r	Sr
g)	_OVERLAPPEDT   InternalInternalHighOffset
OffsetHighhEventr7   N)r8   r9   r:   r;   rL   rN   r   DWORDrK   r>   r?   r7   r@   rA   rU   rU   T   sE    )V__-x~~&8>>*x'
r@   rU   c                     \ rS rSrS\R
                  4S\R                  4S\R                  4S\R                  4S\R
                  4S\R
                  4S\R
                  4S	\R
                  4S
\R
                  4S\R
                  44
rSrg)_BY_HANDLE_FILE_INFORMATION]   dwFileAttributesftCreationTimeftLastAccessTimeftLastWriteTimedwVolumeSerialNumbernFileSizeHighnFileSizeLownNumberOfLinksnFileIndexHighnFileIndexLowr7   N)	r8   r9   r:   r;   r   r\   FILETIMEr>   r?   r7   r@   rA   r^   r^   ]   s    0x001!2!23 1 12#X^^4hnn-X^^,x~~.x~~.hnn-
r@   r^   c           
     ,   [        5       n[        [        -  n[        R	                  [
        R                  " U 5      USSS[        R                  " U5      5      (       a  g[        R                  " 5       nU[        :X  a  g[        R                  " U5      e)Nr   r   TF)rU   r#   r!   r0   
LockFileExmsvcrtget_osfhandlerL   byrefget_last_errorr%   WinError)fd
overlappedflagserrs       rA   _lock_fd_nonblockingrv      sr     !]
(+EE 4 4R 8%Aq&,,WaJbcc##%''ooc""r@   c           	         [        5       n[        R                  [        R                  " U 5      SSS[
        R                  " U5      5      (       d)  [
        R                  " [
        R                  " 5       5      eg )Nr   r   )	rU   r0   UnlockFileExrm   rn   rL   ro   rq   rp   )rr   rs   s     rA   
_unlock_fdry      sU     ]
%%f&:&:2&>1aV`Iabb//&"7"7"9:: cr@   c                  ,    \ rS rSrSrSS jrSS jrSrg)WindowsFileLock   aQ  
Uses ``LockFileEx`` to hard lock a byte range of the lock file on Windows systems.

Lock file cleanup: Windows attempts to delete the lock file after release, but deletion is
not guaranteed in multi-threaded scenarios where another thread holds an open handle. The lock
file may persist on disk, which does not affect lock correctness.
c                v   [        U R                  5        [        U R                  5        [        U R                  U R	                  5       5      nUc  g  [        U5      nU(       a  U R                  U5        U(       d  [        R                  " U5        g g ! [         a    [        R                  " U5        e f = fN)
r   	lock_filer
   _open_non_reparse_fd
_open_moderv   _mark_descriptor_ownedBaseExceptionosclose)selfrr   lockeds      rA   _acquireWindowsFileLock._acquire   s    &t~~6#DNN3 &dnndoo6GHBz-b1//3   ! s   #B "B8c                V   [        SU R                  R                  5      n[        U5        U R	                  5         U R                  USS9  U R                  (       d<  [        [        5         [        U R                  5      R                  5         S S S 5        g g ! , (       d  f       g = f)NintF)default_suppresses)r   _contextlock_file_fdry   _mark_descriptor_released_close_released_fd_preserve_lock_filer   OSErrorr   r   unlink)r   rr   s     rA   _releaseWindowsFileLock._release   sz    eT]]778B rN**,##B5#A++g&(//1 '& ,&&s   ,$B
B(r7   NreturnNoner8   r9   r:   r;   __doc__r   r   r?   r7   r@   rA   r{   r{      s    		&
	2r@   r{   c                   [         R                  " SU S[        R                  [        R                  -  5        U[
        -  (       + n[        XS9u  p4U[        :X  a  [        R                  " 5       [        -   nU[        :X  ac  [        R                  " 5       U:  aJ  [        R                  " [        5        [        XS9u  p4U[        :X  a  [        R                  " 5       U:  a  MJ  U[        :w  aU  U[        [        1;   a  g[         R#                  U5      n[%        S[&        R(                  " U5      R+                  5       X5      e[-        5       n[.        R1                  U[&        R2                  " U5      5      (       d@  [&        R4                  " 5       n[.        R7                  U5        [&        R8                  " U5      eUR:                  [<        -  (       a%  [.        R7                  U5        SU  3n	[%        U	5      e [>        R@                  " U[        R                  [        RB                  -  5      $ ! [D         a    [.        R7                  U5        e f = f)a
  
Open *path* for locking while refusing reparse points, bound to the handle actually locked.

The file is opened through ``NtCreateFile`` with ``FILE_OPEN_REPARSE_POINT`` so a symlink or junction planted
at the path is not followed, and the reparse decision is read from *that* handle via
``GetFileInformationByHandle`` rather than from a prior pathname query. Reading the held handle closes the
check-then-open race: an attacker cannot swap the path between validation and use because both act on the same
handle. Share mode omits delete so a peer cannot unlink or rename the file out from under a live holder,
matching ``os.open``'s ``_SH_DENYNO``.

``NtCreateFile`` is used instead of ``CreateFileW`` because its return value carries the raw ``NTSTATUS``.
Windows collapses a transient delete-pending name and a permanent access denial into the same Win32
``ERROR_ACCESS_DENIED``; the status keeps them apart, so a real denial fails fast instead of spinning until the
caller's timeout (#604).

The reparse option only guards the final path component; Windows still follows reparse points in intermediate
directories. This assumes the lock file sits in a lock directory untrusted users cannot modify. A path with
attacker-controlled parent directories would need component-by-component handle validation.

:param path: the lock file path.
:param mode: the permission mode; as ``os.open`` does on Windows, a cleared owner-write bit creates the file
    read-only. The attribute only takes effect when the file is created, not when an existing one is opened.

:returns: a file descriptor owning the opened handle, or ``None`` on a sharing violation or a delete-pending
    name the caller should treat as contention and retry.

:raises OSError: if the path resolves to a reparse point, or the open fails for any other reason, raised with
    the Win32 error the status maps to. An access denial is raised only once it outlasts a short grace, since
    a peer unlinking the file as it releases can make the open answer ``STATUS_ACCESS_DENIED`` for a moment.

openN)	read_onlyz1Lock file is a reparse point (symlink/junction): )#sysauditr   O_RDWRO_CREATr    _nt_openr'   time	monotonicr*   sleepr+   r&   r(   r)   r-   RtlNtStatusToDosErrorr   rL   FormatErrorstripr^   r0   GetFileInformationByHandlero   rp   CloseHandlerq   r`   r   rm   open_osfhandleO_NOINHERITr   )
pathmoder   handlestatusdeadlinewinerrorinforu   msgs
             rA   r   r      s   B 			&$bii"**&<=|++	!$<**~~'*>>H11dnn6F6Q

/0!)$!D 11dnn6F6Q _$35KLL33F;H$ 2 28 < B B DdUU*,33FFLL<NOO'')C!!&)//#&&  #@@!!&)EdVLC#,	((R^^1KLL 	!!&)	s   ;5H1 1!Ic               d   [        5       n[        R                  U [        R                  " U5      SS5      S-  nU[
        :w  a  SU4$  [        5       n[        R                  " [        5      Ul        [        R                  " U5      Ul
        [        Ul        [        R                  " 5       n[        5       n[        R!                  [        R                  " U5      ["        [        R                  " U5      [        R                  " U5      SU(       a  [$        O[&        [(        [*        [,        SS5      S-  n[        R/                  [        R                  " U5      5        U[
        :w  a  SU4$ UR0                  =(       d    SU4$ ! [        R/                  [        R                  " U5      5        f = f)as  
Open *path* through ``NtCreateFile`` and return ``(handle, status)``.

``RtlDosPathNameToNtPathName_U_WithStatus`` translates the Win32 path to the NT namespace, handling relative,
drive, UNC and extended-length path forms as Win32 itself would, and allocates a buffer that
``RtlFreeUnicodeString`` releases. The handle is ``0`` unless the status is ``STATUS_SUCCESS``.
Nl    r   )r2   r-   'RtlDosPathNameToNtPathName_U_WithStatusrL   ro   r&   rC   sizeofr4   pointerrF   r   rG   r   rK   rP   NtCreateFiler   r   r   r   r   r   RtlFreeUnicodeStringvalue)r   r   nt_namer   
attributesr   	io_statuss          rA   r   r     sK    "#??fllSZF[]acghkuu_$f9	?+-J &.@ AJ$*NN7$;J!$9J!__&F(*I##LL(#LL,LL+09,?U*!#  " ''W(=>_$f9|| q&(( ''W(=>s   	C-F +F/c                  ,    \ rS rSrSrSS jrSS jrSrg)r{   iC  zRUses ``LockFileEx`` to hard lock a byte range of the lock file on Windows systems.c                    [         er~   NotImplementedErrorr   s    rA   r   r   F      %%r@   c                    [         er~   r   r   s    rA   r   r   I  r   r@   r7   Nr   r   r7   r@   rA   r{   r{   C  s    `	&	&r@   )rr   r   r   bool)rr   r   r   r   )r   strr   r   r   z
int | None)r   r   r   r   r   ztuple[int, int])P
__future__r   r   r   r   
contextlibr   pathlibr   typingr   r   _apir	   _utilr
   r   platformrL   rm   r   r   __annotations__r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r#   r%   r&   r'   r(   r)   r*   r+   WinDLLr-   r0   	Structurer2   rC   rP   rU   r^   LONGr   restyperM   rK   r\   
c_longlongrJ   rN   argtypesr   LPCWSTRr   r   r   BOOLr   rl   rx   rv   ry   r{   r   r   __all__r7   r@   rA   <module>r      s:   " 	 
      F<<7 *M:*!+NJ+)L*)"/."@<"OOZO J  !"M:!+5j5)3J30:!:: 1;!::+5j5+5j5"?BZ"Z]u"uOZu(2:2$L*$ .8
7+5j5(*:*
 #-OZ,(2:2,6z6)3J3 *-,,).,.#)==#9F 9&,mmJt&TI#T
&** 

V-- 

6++ 

f&& 

f&6&6 
 #+--Fx')*'(v(()$F  >F]]F22:'	?F22; +/F',2NN?,K+LF(+3>>F  (-5]]OF  )&.oo%6I"$,MMI!5=__fnnUpFq4rI((13;==I((0{#%I! $,==I {#'I# &.]]I"#;&2, &2P?B')V&, & r@   