Ë
    ãš¾jÑA  ã                  óˆ	  — U d dl mZ d dlZd dlZd dlZd dlmZ d dlmZ d dl	m
Z
mZ ddlmZ ddlmZmZ ej"                  d	k(  �rod dlZd dlZd d
lmZ dZded<   dZded<   dZded<   eez  ez  Zded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZded<   dZ ded<   dZ!ded <   ee z  e!z  Z"ded!<   dZ#ded"<   dZ$ded#<   dZ%ded$<   d%Z&ded&<   d'Z'ded(<   d Z(ded)<   d*Z)ded+<   d,Z*ded-<   d.Z+ded/<   d0Z,d1ed2<   d3Z-d1ed4<    ej\                  d5«      Z/d6ed7<    ej\                  d8d9¬:«      Z0d6ed;<    G d<„ d=ejb                  «      Z2 G d>„ d?ejb                  «      Z3 G d@„ dAejb                  «      Z4 G dB„ dCejb                  «      Z5 G dD„ dEejb                  «      Z6ejn                  e/jp                  _9         ejt                  ejv                  «      ejx                   ejt                  e3«       ejt                  e4«       ejt                  ejz                  «      ej|                  ej|                  ej|                  ej|                  ej~                  ej|                  ge/jp                  _@        ejn                  e/j‚                  _9        ej„                   ejt                  e2«      ej~                  ej~                  ge/j‚                  _@        de/j†                  _9         ejt                  e2«      ge/j†                  _@        ej|                  e/jˆ                  _9        ejn                  ge/jˆ                  _@        ejv                  ge0jŠ                  _@        ejŒ                  e0jŠ                  _9        ejv                   ejt                  e6«      ge0jŽ                  _@        ejŒ                  e0jŽ                  _9        ejv                  ejx                  ejx                  ejx                  ejx                   ejt                  e5«      ge0j�                  _@        ejŒ                  e0j�                  _9        ejv                  ejx                  ejx                  ejx                   ejt                  e5«      ge0j’                  _@        ejŒ                  e0j’                  _9        dMdF„ZJdNdG„ZK G dH„ dIe«      ZLdOdJ„ZMdPdK„ZNdIgZOy G dL„ dIe«      ZLdIgZOy)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_GRACEgü©ñÒMb`?Ú_ACCESS_DENIED_RETRYÚntdllzFinal[ctypes.WinDLL]Ú_ntdllÚkernel32T)Úuse_last_errorÚ	_kernel32c                  ó^   — e Zd Zdej                  fdej                  fdej
                  ffZy)Ú_UNICODE_STRINGÚLengthÚMaximumLengthÚBufferN)Ú__name__Ú
__module__Ú__qualname__r   ÚUSHORTÚLPWSTRÚ_fields_© ó    ú[/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/filelock/_windows.pyr2   r2   =   s-   „ à�x—‘Ð'Ø˜hŸo™oÐ.Ø�x—‘Ð'ð
‰r=   r2   c                  ó¸   — e Zd Zdej                  fdej
                  fd ej                  e«      fdej                  fdej                  fdej                  ffZ
y)Ú_OBJECT_ATTRIBUTESr3   ÚRootDirectoryÚ
ObjectNameÚ
AttributesÚSecurityDescriptorÚSecurityQualityOfServiceN)r6   r7   r8   r   ÚULONGÚHANDLEÚctypesÚPOINTERr2   Úc_void_pr;   r<   r=   r>   r@   r@   D   sX   „ à�x—~‘~Ð&Ø˜hŸo™oÐ.Ø˜>˜6Ÿ>™>¨/Ó:Ð;Ø˜8Ÿ>™>Ð*Ø! 6§?¡?Ð3Ø'¨¯©Ð9ð
‰r=   r@   c                  óD   — e Zd Zdej                  fdej                  ffZy)Ú_IO_STATUS_BLOCKÚStatusÚInformationN)r6   r7   r8   rH   rJ   r;   r<   r=   r>   rL   rL   N   s!   „ à�v—‘Ð'Ø˜FŸO™OÐ,ð
‰r=   rL   c                  ó’   — e Zd Zdej                  fdej                  fdej                  fdej                  fdej                  ffZy)Ú_OVERLAPPEDÚInternalÚInternalHighÚOffsetÚ
OffsetHighÚhEventN)	r6   r7   r8   rH   rJ   r   ÚDWORDrG   r;   r<   r=   r>   rP   rP   T   sE   „ à˜Ÿ™Ð)Ø˜VŸ_™_Ð-Ø�x—~‘~Ð&Ø˜8Ÿ>™>Ð*Ø�x—‘Ð'ð
‰r=   rP   c                  ó  — e Zd Zdej                  fdej
                  fdej
                  fdej
                  fdej                  fdej                  fdej                  fdej                  fd	ej                  fd
ej                  ff
Zy)Ú_BY_HANDLE_FILE_INFORMATIONÚdwFileAttributesÚftCreationTimeÚftLastAccessTimeÚftLastWriteTimeÚdwVolumeSerialNumberÚnFileSizeHighÚnFileSizeLowÚnNumberOfLinksÚnFileIndexHighÚnFileIndexLowN)r6   r7   r8   r   rV   ÚFILETIMEr;   r<   r=   r>   rX   rX   ]   s‡   „ à §¡Ð0Ø˜x×0Ñ0Ð1Ø ×!2Ñ!2Ð3Ø × 1Ñ 1Ð2Ø# X§^¡^Ð4Ø˜hŸn™nÐ-Ø˜XŸ^™^Ð,Ø˜xŸ~™~Ð.Ø˜xŸ~™~Ð.Ø˜hŸn™nÐ-ð
‰r=   rX   c           
     ó  — t        «       }t        t        z  }t        j	                  t        j                  | «      |dddt        j                  |«      «      ryt        j                  «       }|t        k(  ryt        j                  |«      ‚)Nr   r   TF)rP   r#   r!   r0   Ú
LockFileExÚmsvcrtÚget_osfhandlerH   ÚbyrefÚget_last_errorr%   ÚWinError)ÚfdÚ
overlappedÚflagsÚerrs       r>   Ú_lock_fd_nonblockingro   ›   so   € ô !“]ˆ
Ü(Ô+EÑEˆÜ×Ñ¤× 4Ñ 4°RÓ 8¸%ÀÀAÀqÌ&Ï,É,ÐWaÓJbÔcØÜ×#Ñ#Ó%ˆØÔ'Ò'Øä�o‰o˜cÓ"Ð"r=   c           	     óä   — t        «       }t        j                  t        j                  | «      dddt        j                  |«      «      s't        j                  t        j                  «       «      ‚y )Nr   r   )	rP   r0   ÚUnlockFileExrf   rg   rH   rh   rj   ri   )rk   rl   s     r>   Ú
_unlock_fdrr   ©   sR   € Ü “]ˆ
ä×%Ñ%¤f×&:Ñ&:¸2Ó&>ÀÀ1ÀaÌÏÉÐV`ÓIaÔbÜ—/‘/¤&×"7Ñ"7Ó"9Ó:Ð:ð cr=   c                  ó    — e Zd ZdZdd„Zdd„Zy)ÚWindowsFileLockay  
        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                óZ  — t        | j                  «       t        | j                  «       t        | j                  | j	                  «       «      }|€y 	 t        |«      }|r| j                  |«       |st        j                  |«       y y # t        $ r t        j                  |«       ‚ w xY w©N)
r   Ú	lock_filer
   Ú_open_non_reparse_fdÚ
_open_modero   Ú_mark_descriptor_ownedÚBaseExceptionÚosÚclose)Úselfrk   Úlockeds      r>   Ú_acquirezWindowsFileLock._acquire¸   s�   € Ü& t§~¡~Ô6Ü# D§N¡NÔ3ô & d§n¡n°d·o±oÓ6GÓHˆBØˆzØðÜ-¨bÓ1�ÙØ×/Ñ/°Ô3ñ Ü—‘˜•ð øô !ò Ü—‘˜”Øðús   ÁB
 Â
 B*c                óH  — t        d| j                  j                  «      }t        |«       | j	                  «        | j                  |d¬«       | j                  s<t        t        «      5  t        | j                  «      j                  «        d d d «       y y # 1 sw Y   y xY w)NÚintF)Údefault_suppresses)r   Ú_contextÚlock_file_fdrr   Ú_mark_descriptor_releasedÚ_close_released_fdÚ_preserve_lock_filer   ÚOSErrorr   rw   Úunlink)r~   rk   s     r>   Ú_releasezWindowsFileLock._releaseË   s…   € Ü�e˜TŸ]™]×7Ñ7Ó8ˆBô �rŒNØ×*Ñ*Ô,Ø×#Ñ# B¸5Ð#ÔAØ×+Ò+ÜœgÓ&ñ 2Ü˜Ÿ™Ó(×/Ñ/Ô1÷2ð 2ð ,÷2ð 2ús   Á*$BÂB!N©ÚreturnÚNone©r6   r7   r8   Ú__doc__r€   r‹   r<   r=   r>   rt   rt   ¯   s   „ ñ	ó	ô&
	2r=   rt   c                ó|  — t        j                  d| dt        j                  t        j                  z  «       |t
        z   }t        | |¬«      \  }}|t        k(  r…t        j                  «       t        z   }|t        k(  rat        j                  «       |k  rJt        j                  t        «       t        | |¬«      \  }}|t        k(  rt        j                  «       |k  rŒJ|t        k7  rS|t        t        hv ryt         j#                  |«      }t%        dt'        j(                  |«      j+                  «       | |«      ‚t-        «       }t.        j1                  |t'        j2                  |«      «      s>t'        j4                  «       }t.        j7                  |«       t'        j8                  |«      ‚|j:                  t<        z  r%t.        j7                  |«       d| › �}	t%        |	«      ‚	 t?        j@                  |t        j                  t        jB                  z  «      S # tD        $ r t.        j7                  |«       ‚ w xY w)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‰   rH   ÚFormatErrorÚstriprX   r0   ÚGetFileInformationByHandlerh   ri   ÚCloseHandlerj   rY   r   rf   Úopen_osfhandleÚO_NOINHERITr{   )
ÚpathÚmoder“   ÚhandleÚstatusÚdeadlineÚwinerrorÚinforn   Úmsgs
             r>   rx   rx   ×   s¾  € ôB 	�	‰	�&˜$ ¤b§i¡i´"·*±*Ñ&<Ô=Øœ|Ñ+Ð+ˆ	Ü! $°)Ô<‰ˆ�ØÔ*Ò*Ü—~‘~Ó'Ô*>Ñ>ˆHØÔ1Ò1´d·n±nÓ6FÈÒ6QÜ—
‘
Ô/Ô0Ü!)¨$¸)Ô!D‘�˜ð Ô1Ò1´d·n±nÓ6FÈÓ6Qð ”_Ò$ØÔ3Ô5KÐLÑLØÜ×3Ñ3°FÓ;ˆHÜ˜$¤× 2Ñ 2°8Ó <× BÑ BÓ DÀdÈHÓUÐUä*Ó,ˆä×3Ñ3°F¼F¿L¹LÈÓ<NÔOÜ×'Ñ'Ó)ˆCÜ×!Ñ! &Ô)Ü—/‘/ #Ó&Ð&Ø× Ñ Ô#@Ò@Ü×!Ñ! &Ô)ØEÀdÀVÐLˆCÜ˜#“,Ðð	ä×(Ñ(¨´·±¼R¿^¹^Ñ1KÓLÐLøÜò 	Ü×!Ñ! &Ô)Øð	ús   Ç&4H È H;c               ó:  — t        «       }t        j                  | t        j                  |«      dd«      dz  }|t
        k7  rd|fS 	 t        «       }t        j                  t        «      |_        t        j                  |«      |_
        t        |_        t        j                  «       }t        «       }t        j!                  t        j                  |«      t"        t        j                  |«      t        j                  |«      d|rt$        nt&        t(        t*        t,        dd«      dz  }t        j/                  t        j                  |«      «       |t
        k7  rd|fS |j0                  xs d|fS # t        j/                  t        j                  |«      «       w xY w)a›  
        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_WithStatusrH   rh   r&   r@   Úsizeofr3   ÚpointerrB   r   rC   r   rG   rL   ÚNtCreateFiler   r   r   r   r   r   ÚRtlFreeUnicodeStringÚvalue)r£   r“   Únt_namer¦   Ú
attributesr¥   Ú	io_statuss          r>   r˜   r˜     sK  € ô "Ó#ˆÜ×?Ñ?ÀÄfÇlÁlÐSZÓF[Ð]aÐcgÓhÐkuÑuˆØ”_Ò$Ø�f�9Ðð	?Ü+Ó-ˆJÜ &§¡Ô.@Ó AˆJÔÜ$*§N¡N°7Ó$;ˆJÔ!Ü$9ˆJÔ!Ü—_‘_Ó&ˆFÜ(Ó*ˆIä×#Ñ#Ü—L‘L Ó(Ü#Ü—L‘L Ó,Ü—L‘L Ó+ØÙ09Õ,Ô?UÜ*Ü!Ü#ØØóð ñð ô" ×'Ñ'¬¯©°WÓ(=Ô>Ø”_Ò$Ø�f�9ÐØ�|‰|Ò ˜q &Ð(Ð(øô ×'Ñ'¬¯©°WÓ(=Õ>ús   ÁC"E0 Å0*Fc                  ó    — e Zd ZdZdd„Zdd„Zy)rt   zRUses ``LockFileEx`` to hard lock a byte range of the lock file on Windows systems.c                ó   — t         ‚rv   ©ÚNotImplementedError©r~   s    r>   r€   zWindowsFileLock._acquireF  ó   € Ü%Ð%r=   c                ó   — t         ‚rv   r·   r¹   s    r>   r‹   zWindowsFileLock._releaseI  rº   r=   NrŒ   r�   r<   r=   r>   rt   rt   C  s   „ Ù`ó	&ô	&r=   )rk   r‚   r�   Úbool)rk   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   ÚplatformrH   rf   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   r@   rL   rP   rX   ÚLONGr¯   ÚrestyperI   rG   rV   Ú
c_longlongrF   rJ   Úargtypesr¬   ÚLPCWSTRr°   rœ   r    ÚBOOLrŸ   re   rq   ro   rr   rt   rx   r˜   Ú__all__r<   r=   r>   ú<module>rÏ      s\  ðÞ "ã 	Û 
Û Ý Ý ß å ß Fà‡<�<�7ÓÛÛÝà *€M�:Ó*Ø!+€N�JÓ+Ø)€L�*Ó)Ø"/°.Ñ"@À<Ñ"O€O�ZÓOàð ˜Jó ð !"€M�:Ó!Ø+5Ð˜jÓ5Ø)3Ð˜JÓ3Ø0:Ð! :Ó:ð 1;Ð! :Ó:Ø+5Ð˜jÓ5Ø+5Ð˜jÓ5Ø"?ÐBZÑ"ZÐ]uÑ"u€O�ZÓuØ(2Ð˜:Ó2Ø$€L�*Ó$ð .8Ð 
Ó7Ø+5Ð˜jÓ5Ø(*Ð˜:Ó*ð
 #-€O�ZÓ,Ø(2Ð˜:Ó2Ø,6Ð˜zÓ6Ø)3Ð˜JÓ3ð *-Ð˜,Ó,Ø).Ð˜,Ó.à#0 6§=¡=°Ó#9€FÐ Ó9Ø&3 f§m¡m°JÈtÔ&T€IÐ#ÓTô
˜&×*Ñ*ô 
ô
˜V×-Ñ-ô 
ô
˜6×+Ñ+ô 
ô
�f×&Ñ&ô 
ô
 f×&6Ñ&6ô 
ð #+§-¡-€F×ÑÔàˆ�‰�x—‘Ó'Ø�‰Øˆ�‰Ð)Ó*Øˆ�‰Ð'Ó(Øˆ�‰�v×(Ñ(Ó)Ø�‰Ø�‰Ø�‰Ø�‰Ø�‰Ø�‰ð$€F×ÑÔ ð >F¿]¹]€F×2Ñ2Ô:à×ÑØˆ�‰�Ó'Ø�‰Ø�‰ð	?€F×2Ñ2Ô;ð +/€F×ÑÔ'Ø,:¨F¯N©N¸?Ó,KÐ+L€F×ÑÔ(Ø+3¯>©>€F× Ñ Ô(Ø-5¯]©]¨O€F× Ñ Ô)à&.§o¡oÐ%6€I×ÑÔ"Ø$,§M¡M€I×ÑÔ!Ø5=·_±_ÀnÀfÇnÁnÐUpÓFqÐ4r€I×(Ñ(Ô1Ø3;·=±=€I×(Ñ(Ô0à�‰Ø�‰Ø�‰Ø�‰Ø�‰Øˆ�‰�{Ó#ð%€I×ÑÔ!ð $,§=¡=€I×ÑÔ à�‰Ø�‰Ø�‰Ø�‰Øˆ�‰�{Ó#ð'€I×ÑÔ#ð &.§]¡]€I×ÑÔ"ó#ó;ô&2˜,ô &2óP?óB')ðl ð�ô&˜,ô &ð ð�r=   