§
    dŠtjÔ  ã                  óø   — U d dl mZ d dlZd dlZd dlZd dlZd dlmZmZm	Z	 d dl
mZ d dlmZ d d„Zd!d„Zd"d„Zd#d„Zddœd$d„Zej        dk    oej        ej        v Zded<   ej        ej        v Zded<   g d¢ZdS )%é    )ÚannotationsN)ÚEACCESÚEIOÚEISDIR)ÚPath)ÚFinalÚfdÚintÚdataÚbytesÚreturnÚNonec                ó¤   — t          |¦  «        }|r>t          j        | |¦  «        x}dk    rt          t          d¦  «        ‚||d…         }|°<dS dS )ac  
    Write the whole buffer to *fd*, looping over the short writes ``os.write`` is allowed to make.

    A marker written with a bare ``os.write`` can land partially: a peer reading it mid-write parses a truncated record
    as malformed or as a foreign holder. Looping until the buffer drains keeps the record atomic in the process and
    kernel view. No ``fsync``: filelock needs a complete record, not crash-durable storage.

    :param fd: file descriptor open for writing.
    :param data: bytes to write in full.

    :raises OSError: if a write reports zero progress before the record is complete.

    r   z5os.write wrote 0 bytes before the record was completeN)Ú
memoryviewÚosÚwriteÚOSErrorr   )r	   r   Ú	remainingÚwrittens       úL/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/filelock/_util.pyÚ	write_allr      sr   € õ ˜4Ñ Ô €IØ
ð (Ý”x  IÑ.Ô.Ð.ˆG°1Ò4Ð4Ý�#ÐVÑWÔWÐWØ˜g˜h˜hÔ'ˆ	ð ð (ð (ð (ð (ð (ó    ÚfilenameÚstrc                óR  — 	 t          j        | ¦  «        }n# t          $ r Y dS w xY w|j        t          j        z  st          t          d| ¦  «        ‚t	          j        |j        ¦  «        r<t          j
        dk    rt          t          d| ¦  «        ‚t          t          d| ¦  «        ‚dS )a  
    Raise an exception if attempting to open the file for writing would fail.

    Separates files that can never be written from files that are writable but currently locked.

    :param filename: file to check

    :raises OSError: as if the file was opened for writing.

    NzPermission deniedÚwin32zIs a directory)r   Úlstatr   Úst_modeÚstatÚS_IWUSRÚPermissionErrorr   ÚS_ISDIRÚsysÚplatformÚIsADirectoryErrorr   )r   Ú	file_stats     r   Úraise_on_not_writable_filer'   !   s¹   € ðõ
 ”H˜XÑ&Ô&ˆ	ˆ	øÝð ð ð Øˆˆðøøøð Ô¥¤Ñ,ð EÝ�fÐ&9¸8ÑDÔDÐDå„|�IÔ%Ñ&Ô&ð DÝŒ<˜7Ò"Ð"Ý!¥&Ð*=¸xÑHÔHÐHÝ¥Ð(8¸(ÑCÔCÐCðDð Ds   ‚ —
%¤%ú
Path | strc                óX   — t          | ¦  «        j                             dd¬¦  «         dS )zp
    Ensure the directory containing the file exists (create it if necessary).

    :param filename: file.

    T)ÚparentsÚexist_okN)r   ÚparentÚmkdir)r   s    r   Úensure_directory_existsr.   A   s,   € õ 	ˆ�N„NÔ×Ò¨°tÐÑ<Ô<Ð<Ð<Ð<r   Ú	lock_fileÚmtime_beforeÚfloatÚ
ino_beforec                ód  — | › dt          j        ¦   «         › dt          j        d¦  «        › �}t	          | ¦  «                             |¦  «         	 t          j        |¦  «        }n# t          $ r Y dS w xY w|j        |k    s|j	        |k    rdS t	          |¦  «         
                    ¦   «          dS )aA  
    Atomically break a stale lock file judged stale at modification time *mtime_before*.

    Rename the file to a process-private name before unlinking it, so two processes breaking the same lock cannot
    delete each other's work: only one rename of a given inode wins, the loser gets ``OSError``. After the rename,
    re-check the file. A newer modification time, or a different inode than *ino_before*, means a peer recreated the
    lock between the stale decision and the rename, so we grabbed a live file and abort, leaving the renamed file in
    place. A rollback rename is itself racy, the same trade-off as the soft read/write marker break. The inode check
    matters because filesystems with coarse modification-time granularity (NFS, FAT) can give a same-second recreation
    the old mtime, so mtime alone would miss it and unlink a live lock; the inode is the reliable identity, mirroring
    the token re-check in the soft read/write marker break. ``lstat`` avoids following a hostile symlink swapped in
    after the decision.

    The break name carries a random token so it is unguessable and unique per attempt. Without it two breakers in the
    same process share ``<lock>.break.<pid>``, and a second break can rename a recreated live lock onto that path in
    the window between the re-verify ``lstat`` above and the ``unlink`` below, deleting a live lock the inode check
    just approved. A private name keeps anyone else from targeting our break path, matching the soft read/write marker
    break.

    :param lock_file: path to the lock file to break.
    :param mtime_before: modification time observed when the lock was judged stale.
    :param ino_before: inode number observed when the lock was judged stale.

    :raises OSError: if the rename fails (e.g. the file vanished or is not owned in a sticky directory).

    z.break.ú.é   N)r   ÚgetpidÚsecretsÚ	token_hexr   Úrenamer   r   Úst_mtimeÚst_inoÚunlink)r/   r0   r2   Ú
break_pathÚst_afters        r   Úbreak_lock_filer?   K   sÁ   € ð6 ÐKÐK¥b¤i¡k¤kÐKÐKµGÔ4EÀbÑ4IÔ4IÐKÐK€JÝˆ�O„O×Ò˜:Ñ&Ô&Ð&ðÝ”8˜JÑ'Ô'ˆˆøÝð ð ð ØˆˆðøøøàÔ˜<Ò'Ð'¨8¬?¸jÒ+HÐ+HØˆÝˆÑÔ×ÒÑÔÐÐÐs   ÁA& Á&
A4Á3A4)r	   Únameú
int | Nonec               ó€   — |�t           rt          j        |d ¦  «         d S t          j        | d t           ¬¦  «         d S )N)Úfollow_symlinks)Ú_SUPPORTS_UTIME_FDr   ÚutimeÚ_SUPPORTS_UTIME_NOFOLLOW)r@   r	   s     r   ÚtouchrG   q   sF   € ð
 
€~Õ,€~Ý
Œ��TÑÔÐØˆÝ„HˆT�4Õ-EÐ)EÐFÑFÔFÐFÐFÐFr   r   zFinal[bool]rD   rF   )r?   r.   r'   rG   r   )r	   r
   r   r   r   r   )r   r   r   r   )r   r(   r   r   )r/   r   r0   r1   r2   r
   r   r   )r@   r   r	   rA   r   r   )Ú
__future__r   r   r7   r   r#   Úerrnor   r   r   Úpathlibr   Útypingr   r   r'   r.   r?   rG   r$   rE   Úsupports_fdrD   Ú__annotations__Úsupports_follow_symlinksrF   Ú__all__© r   r   ú<module>rQ      sY  ðØ "Ð "Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø €€€Ø €€€Ø 
€
€
€
Ø %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ð %Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð ð(ð (ð (ð (ð*Dð Dð Dð Dð@=ð =ð =ð =ð#ð #ð #ð #ðL *.ð Gð Gð Gð Gð Gð Gð #&¤,°'Ò"9Ð"X¸b¼hÈ"Ì.Ð>XÐ Ð XÐ XÐ XÑ Xà(*¬°BÔ4OÐ(OÐ Ð OÐ OÐ OÑ Oðð ð €€€r   