§
    ´¯¸jÊN ã                  óê  — U d Z 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dl
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dlZddlZddlZddlmZ ddlmZmZmZmZ ddlmZmZmZmZ  e
j        e¦  «        Z dZ!d	Z"d
Z#ej$        j%        ej$        j&        z  Z'ddgZ(ddœdOd„Z) e*ej+        ej,        ej-        ej.        f¦  «        Z/de0d<   dPd„Z1dZ2de0d<   dQd#„Z3dRd$„Z4ej5        	 dSdTd)„¦   «         Z6 ej7        d*¦  «        Z8ej9        r0dd+l:m7Z;  e;d,ej<        ej=                 ej<        e>         ¬-¦  «        Z?n" ej7        d,ej<        ej=                 ¬.¦  «        Z? ej@        ¦   «         ZAd/e0d0<   dUd1„ZB eCed2d¦  «        ZDeD� eDeB¬3¦  «          G d4„ d5ejE        ejF        e8         ¦  «        ZGdVd6„ZHdWd9„ZIdXd<„ZJ G d=„ deGe?         ¦  «        ZK G d>„ d?eKe?         ¦  «        ZLdYd@„ZM ejN        ¦   «         ZOdAe0dB<   dUdC„ZP ejQ        eP¦  «          G dD„ dEeKej<        e>                  ¦  «        ZR G dF„ dGeR¦  «        ZS G dH„ dIejT        d         ¦  «        ZU G dJ„ dKeGdL         ¦  «        ZV G dM„ dNeV¦  «        ZWdS )ZaÇ  High level locking utilities built on the low level lockers.

Where `portalocker.portalocker` wraps a single locking syscall, this module
turns that primitive into ready-to-use objects: context managers that open,
lock, retry, unlock and close a file for you.

The hierarchy:

- `LockBase`: the abstract base. It owns the ``timeout`` /
  ``check_interval`` / ``fail_when_locked`` retry semantics that every other
  class here inherits, and the `LockBase._timeout_generator` that implements
  them.
- `Lock`: the workhorse. Opens a file, locks it, and hands the filehandle
  to the caller.
- `RLock`: a `Lock` that may be acquired several times by the same
  instance and is only released once the acquire count drops to zero.
- `TemporaryFileLock`: a `Lock` whose lock file is unlinked on release,
  including at interpreter exit.
- `PidFileLock`: a `TemporaryFileLock` that publishes the owning PID, so a
  contender can report *who* holds the lock instead of merely failing.
- `BoundedSemaphore` / `NamedBoundedSemaphore`: N-slot counting
  semaphores built from N separate lock files.

`open_atomic` is unrelated to locking: it writes to a temporary file and
renames it into place, so readers never observe a partially written file.

Only `Lock` and `open_atomic` are listed in this module's ``__all__``, but
every concrete class above is re-exported from the `portalocker` package
itself. The abstract `LockBase` is not; import it from here.

Example:
    >>> import portalocker
    >>> with portalocker.Lock('somefile', 'w', timeout=1) as fh:
    ...     _ = fh.write('the file is locked for the duration of the block')

See Also:
    `portalocker.portalocker`: the platform specific locking primitives
    this module builds on.
é    )ÚannotationsN)Ú	FrameTypeé   )Ú	constantsÚ
exceptionsÚportalockerÚtypes)Ú
BinaryModeÚFilenameÚModeÚTextModeé   g      Ð?FÚLockÚopen_atomic)Ú
test_valueÚargsú
typing.Anyr   Úreturnc                ó<   ‡ — t          ˆ fd„|D ¦   «         d¦  «        S )aŽ  Simple coalescing function that returns the first value that is not
    equal to the `test_value`. Or `None` if no value is valid. Usually this
    means that the last given value is the default value.

    Note that the `test_value` is compared using an identity check
    (i.e. `value is not test_value`) so changing the `test_value` won't work
    for all values.

    >>> coalesce(None, 1)
    1
    >>> coalesce()

    >>> coalesce(0, False, True)
    0
    >>> coalesce(0, False, True, test_value=0)
    False

    # This won't work because of the `is not test_value` type testing:
    >>> coalesce([], dict(spam='eggs'), test_value=[])
    []
    c              3  ó$   •K  — | ]
}|‰u¯|V — Œd S ©N© )Ú.0Úargr   s     €úa/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/portalocker/utils.pyú	<genexpr>zcoalesce.<locals>.<genexpr>c   s-   øè è € Ð>Ð>˜¨°:Ð(=Ð(=�Ð(=Ð(=Ð(=Ð(=Ð>Ð>ó    N)Únext)r   r   s   ` r   Úcoalescer   M   s*   ø€ õ, Ð>Ð>Ð>Ð> Ð>Ñ>Ô>ÀÑEÔEÐEr   zfrozenset[int]Ú_HARD_LINK_FALLBACK_ERRNOSÚerrorÚBaseExceptionÚ	temp_nameÚstrÚNonec                ó’   — d|› �}t          | t          ¦  «        r| j        r| j        › d|› d�| _        dS g | j        ¢|‘R | _        dS )aã  Record on ``error`` that the written payload survives on disk.

    `open_atomic` keeps its temporary file when publication fails, so the
    caller's data is never silently destroyed. This helper welds the
    location of that file onto the exception the caller is about to
    receive, since the temporary name is random and otherwise unknowable.

    Args:
        error: The exception about to be re-raised by `open_atomic`. For
            an `OSError` carrying a ``strerror`` the note is appended
            there, so it shows up in ``str(error)`` and the traceback.
            Any other exception gets the note appended to its ``args``
            for the same effect.
        temp_name: Path of the preserved temporary file.
    zpayload preserved at z (ú)N)Ú
isinstanceÚOSErrorÚstrerrorr   )r!   r#   Únotes      r   Ú_annotate_preserved_payloadr,   x   sd   € ð  4¨	Ð3Ð3€DÝ�%�Ñ!Ô!ð ) e¤nð )Ø!œNÐ5Ð5¨dÐ5Ð5Ð5ˆŒˆˆà(�u”zÐ( 4Ð(Ð(ˆŒ
ˆ
ˆ
r   i'  ÚintÚ_TEMP_NAME_ATTEMPTSÚpathúpathlib.PathÚbinaryÚboolútuple[types.IO, str]c                óX  — dd„}t          t          ¦  «        D ]n}t          | j        dt	          j        d¦  «                             ¦   «         › d	�z  ¦  «        }	 t          ||rd
nd|¬¦  «        }n# t          $ r Y Œew xY w||fc S t          dt          | j        ¦  «        ›�¦  «        ‚)a·  Create `open_atomic`'s temporary file next to its destination.

    The file is created with mode ``0o666`` passed straight to `os.open`,
    so the kernel subtracts the process umask at creation time, exactly
    like a plain `open` call. That is deliberate: `tempfile` would create
    a private ``0o600`` file, which both publication primitives preserve,
    and correcting the mode afterwards would take either a ``chmod``
    (refused by some network mounts) or a umask round-trip (a
    process-global mutation that briefly leaks mode ``0o777`` file
    creation to every other thread). No global state is touched here.

    The temporary basename is a fixed 33 bytes
    (``.portalocker.<16 hex>.tmp``) and deliberately does not embed the
    destination's name: a destination basename near the usual 255 byte
    filesystem limit must not push the temporary name over it. ``O_EXCL``
    guards the randomly generated name against collisions and symlinks:
    an occupied name is rolled again, at most `_TEMP_NAME_ATTEMPTS`
    times.

    Args:
        path: The destination the temporary file will be published to.
            The temporary file lands in the same directory under a hidden
            randomized name.
        binary: Open the file in binary mode (``'wb'``) rather than text
            mode (``'w'``).

    Returns:
        The open filehandle and the temporary file's path.

    Raises:
        OSError: No free temporary name was found within
            `_TEMP_NAME_ATTEMPTS` attempts, which practically means the
            randomness source is broken. Raised as plain `OSError`, never
            `FileExistsError`, so it cannot be mistaken for the
            destination existing.
    Úopener_pathr$   Úflagsr-   r   c                óH   — t          j        | |t           j        z  d¦  «        S )z:Open ``opener_path`` exclusively with kernel-applied mode.i¶  )ÚosÚopenÚO_EXCL)r5   r6   s     r   Ú_exclusive_openerz/_open_exclusive_temp.<locals>._exclusive_opener¿   s   € åŒw�{ E­B¬IÑ$5°uÑ=Ô=Ð=r   z.portalocker.é   ú.tmpÚwbÚw)Úopenerz'no usable temporary file name found in N)r5   r$   r6   r-   r   r-   )
Úranger.   r$   Úparentr8   ÚurandomÚhexr9   ÚFileExistsErrorr)   )r/   r1   r;   Ú_r#   Útemp_fhs         r   Ú_open_exclusive_temprH   –   sõ   € ðR>ð >ð >ð >õ Õ&Ñ'Ô'ð "ð "ˆÝØŒKÐC­"¬*°Q©-¬-×*;Ò*;Ñ*=Ô*=ÐCÐCÐCÑCñ
ô 
ˆ	ð
	õ !%ØØÐ'�� CØ(ð!ñ !ô !ˆGˆGøõ
 ð 	ð 	ð 	àˆHð	øøøð ˜	Ð!Ð!Ð!Ð!å
ØFµ#°d´kÑ2BÔ2BÐFÐFñô ð s   ÁA2Á2
A?Á>A?c                óÀ  — t           j        dk    rt          j        | |¦  «         dS 	 t          j        | |¦  «         dS # t          $ r“}|j        t          vr‚ t           j                             |¦  «        rEt          t
          j
        t          j        t
          j
        ¦  «        t          |¦  «        ¦  «        |‚t          j        | |¦  «         Y d}~dS d}~ww xY w)a
  Publish ``temp_name`` at ``path``, refusing an existing target.

    Windows renames, which refuses an existing destination on its own.
    POSIX hard links, and on filesystems that cannot hard link (errno in
    `_HARD_LINK_FALLBACK_ERRNOS`) falls back to an existence check plus
    rename. The fallback keeps the content atomic but cannot reliably
    refuse concurrent publishers. See the `open_atomic` docstring.

    Args:
        temp_name: The written and synchronized temporary file.
        path: The destination. Its directory already exists.

    Raises:
        FileExistsError: The destination exists, either reported by the
            platform primitive or found by the fallback's check.
        OSError: The publication primitive failed for another reason.
    ÚntN)r8   ÚnameÚrenameÚlinkr)   Úerrnor    r/   ÚlexistsrE   ÚEEXISTr*   r$   )r#   r/   Ú
link_errors      r   Ú_publish_exclusiverR   Ù   sç   € õ$ 
„w�$‚€Ý
Œ	�)˜TÑ"Ô"Ð"Ð"Ð"ð	'ÝŒG�I˜tÑ$Ô$Ð$Ð$Ð$øÝð 	'ð 	'ð 	'ØÔÕ'AÐAÐAØõ
 Œw�Š˜tÑ$Ô$ð "Ý%Ý”LÝ”K¥¤Ñ-Ô-Ý˜‘I”Iñô ð "ð	"õ
 ŒI�i Ñ&Ô&Ð&Ð&Ð&Ð&Ð&Ð&Ð&øøøøð	'øøøs   ©A  Á 
CÁ
BCÃCTÚfilenamer   ú#collections.abc.Generator[types.IO]c              #  ó(  K  — t          | t          j        ¦  «        r| }nt          j        | ¦  «        }|                     ¦   «         rDt	          t
          j        t          j        t
          j        ¦  «        t          |¦  «        ¦  «        ‚|j
                             dd¬¦  «         t          ||¦  «        \  }}	 |5  |V — |j        rbt          j        |t          j        ¦  «        }	 t          j        |¦  «         t          j        |¦  «         nS# t          j        |¦  «         w xY w|                     ¦   «          t          j        |                     ¦   «         ¦  «         ddd¦  «         n# 1 swxY w Y   n™# t(          $ rŒ t+          j        t.          ¦  «        5  |                     ¦   «          ddd¦  «         n# 1 swxY w Y   t+          j        t.          ¦  «        5  t          j        |¦  «         ddd¦  «         n# 1 swxY w Y   ‚ w xY w	 t3          ||¦  «         n## t.          $ r}t5          ||¦  «         ‚ d}~ww xY wt+          j        t.          ¦  «        5  t          j        |¦  «         ddd¦  «         dS # 1 swxY w Y   dS )aã
  Open a new file for atomic writing without replacing an existing file.

    The destination must not exist when entering or publishing the context.
    A destination that exists on entry raises :class:`FileExistsError`
    straight away. If another actor creates it while the context is open,
    publication raises :class:`FileExistsError` as well and leaves that
    destination untouched.

    The implementation writes and synchronizes a temporary file in the
    destination directory, then publishes it with an operation that refuses
    an existing destination. Windows uses an atomic rename and POSIX an
    atomic hard link. On POSIX filesystems without hard link support (exFAT
    and some SMB, NFS and FUSE mounts) the hard link fails with an errno in
    `_HARD_LINK_FALLBACK_ERRNOS` and publication falls back to an existence
    check followed by a rename. The fallback still publishes the content
    atomically, but it does not reliably refuse concurrent publishers:
    two of them can both pass the check, and the later rename then
    replaces the earlier file. The strong no-replace guarantee requires
    hard link support.

    The two failure directions clean up differently. When the caller's
    body raises, the temporary file is removed: the payload is incomplete
    and keeping it would leak one file per failed attempt. When the body
    completed but *publication* fails, for any reason, the temporary file
    is kept so the finished payload is not destroyed, and the raised
    exception names its path. Publication succeeding is the only other
    thing that removes it.

    The published file carries the permissions a plain `open` would have
    given it: the temporary file is created with mode ``0o666``, so the
    kernel applies the process umask at creation time and the
    process-wide umask itself is never touched. A body that closes the
    handle itself is fine: the file is synchronized through a fresh
    descriptor instead.

    Note:
        The destination *content* is synchronized to disk before
        publication, but the directory entry is not (no ``fsync`` on the
        directory). After a power loss the name may be missing even
        though the context exited cleanly.

    https://docs.python.org/3/library/os.html#os.link

    >>> filename = 'test_file.txt'
    >>> if os.path.exists(filename):
    ...     os.remove(filename)

    >>> with open_atomic(filename) as fh:
    ...     written = fh.write(b'test')
    >>> assert os.path.exists(filename)
    >>> os.remove(filename)

    >>> import pathlib
    >>> path_filename = pathlib.Path('test_file.txt')

    >>> with open_atomic(path_filename) as fh:
    ...     written = fh.write(b'test')
    >>> assert path_filename.exists()
    >>> path_filename.unlink()
    T)ÚparentsÚexist_okN)r(   ÚpathlibÚPathÚexistsrE   rN   rP   r8   r*   r$   rB   ÚmkdirrH   Úclosedr9   ÚO_RDWRÚfsyncÚcloseÚflushÚfilenor"   Ú
contextlibÚsuppressÚ	ExceptionÚremoverR   r,   )rS   r1   r/   rG   r#   Úsync_fdr!   s          r   r   r      so  è è € õF �(�GœLÑ)Ô)ð &ØˆˆåŒ|˜HÑ%Ô%ˆà‡{‚{�}„}ð 
ÝÝŒLÝŒK�œÑ%Ô%Ý�‰IŒIñ
ô 
ð 	
ð 	„K×Ò˜d¨TÐÑ2Ô2Ð2å-¨d°FÑ;Ô;Ñ€GˆYðØð 	+ð 	+ØˆMˆMˆMØŒ~ð 
+õ  "œw yµ"´)Ñ<Ô<�ð&Ý”H˜WÑ%Ô%Ð%å”H˜WÑ%Ô%Ð%Ð%ø•B”H˜WÑ%Ô%Ð%Ð%øøøà—’‘”�Ý”˜ŸšÑ)Ô)Ñ*Ô*Ð*ð	+ð 	+ð 	+ñ 	+ô 	+ð 	+ð 	+ð 	+ð 	+ð 	+ð 	+øøøð 	+ð 	+ð 	+ð 	+øøõ ð ð ð õ Ô ¥Ñ+Ô+ð 	ð 	Ø�MŠM‰OŒOˆOð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	åÔ ¥Ñ+Ô+ð 	!ð 	!ÝŒI�iÑ Ô Ð ð	!ð 	!ð 	!ñ 	!ô 	!ð 	!ð 	!ð 	!ð 	!ð 	!ð 	!øøøð 	!ð 	!ð 	!ð 	!àðøøøðÝ˜9 dÑ+Ô+Ð+Ð+øÝð ð ð õ 	$ E¨9Ñ5Ô5Ð5Øøøøøð	øøøõ 
Ô	�YÑ	'Ô	'ð ð Ý
Œ	�)ÑÔÐðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð sº   Â<E> Â>+E2Ã*DÃ>E2ÄD)Ä)=E2Å&E> Å2E6Å6E> Å9E6Å:E> Å>#HÆ!GÆ6HÇG	ÇHÇ	G	Ç
HÇ&HÇ;HÈH	ÈHÈH	ÈHÈH) È)
I	È3IÉI	É%JÊJÊJÚAcquireReturnT)ÚTypeVarÚIOT)ÚboundÚdefault)rj   z%weakref.WeakSet[LockBase[typing.Any]]Ú_live_locksc                 ó    — t          t          ¦  «        D ]8} |                      ¦   «         }|D ]}t          |dd¦  «        }|�
 |¦   «          Œ Œ9dS )a´  Reset every live instance's Python locks in a freshly forked child.

    A child forked while any thread holds an instance state lock inherits
    that lock in its locked state, owned by a thread that does not exist
    in the child, and the child's first `release`, `acquire` or
    interpreter-exit cleanup then deadlocks on it forever. The window is
    real: any state-lock scope that reaches the operating system releases
    the GIL, so an unlucky ``os.fork`` from another thread lands inside
    it. This is the same problem the standard library's ``logging``
    module has with its handler locks, solved the same way: registered
    with ``os.register_at_fork`` below, the child gets every registered
    lock reinitialized to a fresh unlocked one before it runs any Python
    code of its own. Each instance reports its locks through
    `LockBase._fork_reinit_locks` - the state lock for every lock kind,
    plus whatever else a subclass guards with its own Python lock (the
    mode lock of `~portalocker.redis.RedisLock`, held by its worker
    thread for every ping answer). Only Python locks are reset; which OS
    locks the child actually holds is unchanged, since those live on
    file descriptors, not on Python locks.

    On Windows this function is a quiet no-op. CPython only compiles
    ``_at_fork_reinit`` into its lock types on platforms with ``fork``
    (the method sits behind ``#ifdef HAVE_FORK`` in
    ``Modules/_threadmodule.c``), so ``nt`` builds lack it entirely.
    Nothing is lost by skipping such locks: without ``fork`` there is no
    inherited-lock problem to repair, but a direct call (tests, embedders
    running platform-neutral cleanup) must not explode either.
    Ú_at_fork_reinitN)Úlistrl   Ú_fork_reinit_locksÚgetattr)ÚlockÚinstance_locksÚinstance_lockÚreinits       r   Ú_reinit_state_locks_after_forkrv   š  s}   € õ: •[Ñ!Ô!ð ð ˆà×#Ò#Ñ%Ô%ð 	ð ,ð 	ð 	ˆMõ
 8?ØØ!Øñ8ô 8ˆFð
 Ð!Ø�‘”�øð	ð	ð r   Úregister_at_fork)Úafter_in_childc                  óÀ   — e Zd ZU dZded<   ded<   ded<   ded<   	 	 	 d!d"d„Zd#d„Zej        	 	 	 d!d$d„¦   «         Z	d%d„Z
ej        d&d„¦   «         Zd'd„Zd(d„Zd)d „Zd	S )*ÚLockBaseaî  Abstract base class for every lock in portalocker.

    It contributes two things to its subclasses: the retry policy stored in
    the three attributes below, and the `LockBase._timeout_generator` that
    turns that policy into a sequence of attempts. Subclasses only have to
    implement `acquire` and `release`, and the context manager protocol
    and the descriptor hook come for free.

    Garbage collection of a lock object deliberately leaves the lock
    alone. Portalocker 4.0.0 released held locks from a ``__del__``
    finalizer, which tore down locks whose filehandle the caller was still
    using (``fh = Lock(...).acquire()`` keeps the filehandle alive, not
    the lock object). 4.2.0 removed that finalizer and restored the 3.2.0
    behaviour.

    The class is generic over `AcquireReturnT`, the type `acquire` returns
    and therefore the type bound by ``with``. `Lock` and its descendants
    specialize it to an open filehandle, `RedisLock` to itself and
    `BoundedSemaphore` to the `Lock` it took, or `None` when it gave up
    without one.

    Attributes:
        timeout: Total number of seconds `acquire` keeps retrying a lock
            that is held by somebody else, before giving up and raising.
            Defaults to `DEFAULT_TIMEOUT` (5 seconds). The clock starts
            *after* the first attempt, so a timeout of ``0`` still means
            "try exactly once". Retrying only makes sense for non-blocking
            lock flags: with a blocking flag the operating system itself
            waits inside the very first attempt, which is why `Lock` warns
            when a timeout is combined with blocking flags.
        check_interval: Seconds between two attempts while waiting for
            `timeout` to expire. Defaults to `DEFAULT_CHECK_INTERVAL`
            (0.25 seconds). It is a target rather than a plain sleep: the
            time the attempt itself took is subtracted, see
            `LockBase._timeout_generator`.
        fail_when_locked: Whether to give up as soon as the *first* attempt
            finds the lock taken, instead of retrying until `timeout`
            expires. Defaults to `DEFAULT_FAIL_WHEN_LOCKED` (`False`,
            i.e. retry). Either way a lock that stays contended surfaces
            as `AlreadyLocked`: with `fail_when_locked` after the first
            attempt, without it once the timeout runs out. Contention is
            also the only condition that is retried at all. Any other
            failure, such as a `LockException` from a backend that
            cannot lock the file, is permanent and propagates
            immediately instead of burning the timeout. The timing
            matters when several processes race to create the same file
            and you would rather hear about the contention immediately
            than a handful of seconds later.

    Note:
        Every one of the three is also a per-call argument of `acquire`.
        The argument wins when it is not `None`; otherwise the attribute
        set here is used.

    Note:
        A single lock instance shared across threads is synchronized for
        state consistency only, not for granted-lock semantics: the
        internal bookkeeping (which filehandle is held, the acquire
        count, which semaphore slot is taken) cannot be corrupted by
        concurrent calls, but which thread's `acquire` wins, or whether a
        concurrent `release` makes another thread's `acquire` succeed, is
        still scheduling. Two threads racing `acquire` on one instance
        is explicitly unsupported: with a per-process locker (POSIX
        ``lockf``) both lock calls succeed, the second publication
        overwrites the first, and the overwritten descriptor's eventual
        close releases the process's record locks on the file. Use one
        instance per thread, or a `threading.Lock` of your own, when you
        need per-thread mutual exclusion.

    See Also:
        `Lock`: the file based implementation nearly everything else in
        this module derives from.
    ÚfloatÚtimeoutÚcheck_intervalr2   Úfail_when_lockedzthreading.RLockÚ_state_lockNúfloat | Noneúbool | Noner   r%   c           
     óÌ  — d|fd|ff}|D ]X\  }}t          |t          ¦  «        r>t          j        |› d|›dt	          |¦  «        › d�t
          t          ¦   «         ¬¦  «         ŒYt          |t          ¦  «        | _	        t          |t          ¦  «        | _        t          |t          ¦  «        | _        t          j        ¦   «         | _        t"                               | ¦  «         dS )aG  Store the retry policy shared by every lock.

        Args:
            timeout: Value for the `timeout` attribute. `None` selects
                `DEFAULT_TIMEOUT`.
            check_interval: Value for the `check_interval` attribute.
                `None` selects `DEFAULT_CHECK_INTERVAL`.
            fail_when_locked: Value for the `fail_when_locked` attribute.
                `None` selects `DEFAULT_FAIL_WHEN_LOCKED`.

        Warns:
            DeprecationWarning: When ``timeout`` or ``check_interval``
                is a bool. The stacklevel is computed by
                `_stacklevel_beyond_module`, so the warning names the
                caller's own file however many subclass constructors sit
                between them and here.

        Note:
            The defaults are resolved through `coalesce`, which uses an
            identity check. Passing ``0`` therefore keeps that value; only a
            literal `None` falls back to the default. ``fail_when_locked``
            remains a bool.

        .. deprecated:: 4.4.0
            Passing a bool as ``timeout`` or ``check_interval``. ``bool``
            subclasses `int`, so ``True`` means one second and ``False``
            means zero rather than anything the caller intended. It still
            behaves that way for now and will raise `TypeError` in 5.0.
        r|   r}   ú=z/ is a bool. bool subclasses int, so this means zX. Pass a number or None instead. Passing a bool will raise TypeError in portalocker 5.0.©Ú
stacklevelN)r(   r2   ÚwarningsÚwarnr-   ÚDeprecationWarningÚ_stacklevel_beyond_moduler   ÚDEFAULT_TIMEOUTr|   ÚDEFAULT_CHECK_INTERVALr}   ÚDEFAULT_FAIL_WHEN_LOCKEDr~   Ú	threadingÚRLockr   rl   Úadd)Úselfr|   r}   r~   ÚcheckedrK   Úvalues          r   Ú__init__zLockBase.__init__3  s  € ðT ˜Ð Ø˜~Ð.ð3
ˆð #ð 		ð 		‰KˆD�%Ý˜%¥Ñ&Ô&ð Ý”Øð 5ð 5˜eð 5ð 5Ý*-¨e©*¬*ð5ð 5ð 5õ 'Ý8Ñ:Ô:ðñ ô ð øõ   ­Ñ9Ô9ˆŒÝ& ~Õ7MÑNÔNˆÔÝ (ØÝ$ñ!
ô !
ˆÔõ %œ?Ñ,Ô,ˆÔõ 	�Š˜ÑÔÐÐÐr   ú,tuple[threading.Lock | threading.RLock, ...]c                ó   — | j         fS )aî  Report the Python locks a forked child must reinitialize.

        Consumed by `_reinit_state_locks_after_fork`: everything listed
        here is reset to a fresh unlocked lock in a freshly forked
        child, because the child may have inherited it locked by a
        thread that does not exist there. A subclass that guards state
        with an extra per-instance Python lock extends the tuple
        (`~portalocker.redis.RedisLock` adds the mode lock its worker
        thread takes for every ping answer). The hook resets each lock
        independently and acquires none of them, so listing several
        locks creates no ordering between them.

        Returns:
            The locks to reinitialize; the state lock alone here.
        )r   ©r�   s    r   rp   zLockBase._fork_reinit_locksv  s   € ð$ Ô Ð"Ð"r   rg   c                ó   — dS )a  Take the lock, retrying until `timeout` expires.

        Abstract; see `Lock.acquire` for the reference implementation and
        `RLock.acquire`, `BoundedSemaphore.acquire` and `RedisLock.acquire`
        for the variations.

        Args:
            timeout: Overrides the `timeout` attribute for this call only.
            check_interval: Overrides the `check_interval` attribute for
                this call only.
            fail_when_locked: Overrides the `fail_when_locked` attribute
                for this call only.

        Returns:
            Whatever the concrete lock guards. For every file based lock in
            this module that is the open, locked filehandle.

        Raises:
            ~portalocker.exceptions.AlreadyLocked: The first attempt failed and
                `fail_when_locked` was set.
            ~portalocker.exceptions.LockException: The lock could not be taken
                before `timeout` expired, or the underlying locking call failed
                for a reason other than contention.
        Nr   )r�   r|   r}   r~   s       r   ÚacquirezLockBase.acquireŠ  ó   € € € r   útyping.Iterator[int]c           	   #  ó¶  K  — t          || j        d¦  «        }t          || j        d¦  «        }dV — d}t          j        ¦   «         }||z   }|t          j        ¦   «         k    ru|dz  }|V — t          j        ¦   «         }||z  ||z
  z
  }	||z
  }
t          j        t          dt          |	|
¦  «        ¦  «        ¦  «         |t          j        ¦   «         k    °sdS dS )a‡  Yield an attempt number per lock attempt, pacing the retries.

        The generator is the whole retry policy. A caller loops over it and
        tries to lock once per iteration; the sleeping happens inside the
        generator, in between.

        Attempt ``0`` is yielded before the clock even starts, so a
        `timeout` of ``0`` still buys exactly one attempt. The sleep for an
        attempt happens after control returns from it, and it targets a
        fixed schedule instead of a fixed pause: attempt ``i`` sleeps until
        ``i * check_interval`` seconds have passed since the clock started,
        so a slow attempt eats into its own interval rather than adding to
        it. A sleep is also capped at the time left until the deadline, so
        a ``check_interval`` larger than the remaining `timeout` cannot
        stretch the total wait past the timeout itself. The sleep never
        drops below a millisecond, which keeps a ``check_interval`` of
        ``0`` from spinning the CPU flat out.

        One consequence worth knowing: because the sleep trails the yield,
        attempts ``0`` and ``1`` both happen right away, and only from
        there on are attempts spaced out. Iteration stops as soon as the
        deadline has passed, so the caller decides what a final failure
        means; the generator itself never raises.

        Args:
            timeout: Seconds to keep retrying. `None` uses the `timeout`
                attribute.
            check_interval: Seconds between attempts. `None` uses the
                `check_interval` attribute.

        Yields:
            The attempt number, starting at ``0``.
        ç        r   r   gü©ñÒMbP?N)r   r|   r}   ÚtimeÚperf_counterÚsleepÚmaxÚmin)r�   r|   r}   Ú	f_timeoutÚf_check_intervalÚiÚ
start_timeÚdeadlineÚnowÚ	scheduledÚ	remainings              r   Ú_timeout_generatorzLockBase._timeout_generatorª  sñ   è è € õL ˜W d¤l°CÑ8Ô8ˆ	Ý# N°DÔ4GÈÑMÔMÐàˆˆˆØˆå Ô-Ñ/Ô/ˆ
Ø$ yÑ0ˆØ�Ô*Ñ,Ô,Ò,Ð,Ø�‰FˆAØˆGˆGˆGõ Ô*Ñ,Ô,ˆCØ !Ð$4Ñ 4¸¸zÑ9IÑJˆIØ'¨#™~ˆIÝŒJ•s˜5¥# i°Ñ";Ô";Ñ<Ô<Ñ=Ô=Ð=ð �Ô*Ñ,Ô,Ò,Ð,Ð,Ð,Ð,Ð,r   c                ó   — dS )a  Give up the lock.

        Abstract; the implementations differ in how much they clean up.
        `Lock.release` unlocks and closes the filehandle,
        `TemporaryFileLock.release` also unlinks the lock file, and
        `RLock.release` only does either once the acquire count reaches
        zero.

        Implementations are expected to tolerate being called on an
        instance that holds nothing: double releases and the ``atexit``
        fallback of `TemporaryFileLock` both do exactly that.
        Nr   r–   s    r   ÚreleasezLockBase.releaseå  r™   r   c                ó*   — |                       ¦   «         S )z·Acquire the lock with the instance defaults.

        Returns:
            Whatever `acquire` returns, which is the value bound by
            ``as`` in a ``with`` statement.
        ©r˜   r–   s    r   Ú	__enter__zLockBase.__enter__ô  s   € ð �|Š|‰~Œ~Ðr   Úexc_typeútype[BaseException] | NoneÚ	exc_valueúBaseException | NoneÚ	tracebackr   c                ó.   — |                       ¦   «          dS )a‘  Release the lock when the ``with`` block ends.

        Args:
            exc_type: Type of the exception leaving the block, if any.
            exc_value: The exception instance, if any.
            traceback: The traceback of that exception, if any.

        Returns:
            `None`, so an exception raised inside the block keeps
            propagating once the lock has been released.
        N©r¬   ©r�   r°   r²   r´   s       r   Ú__exit__zLockBase.__exit__ý  s   € ð" 	�Š‰ŒˆØˆtr   ÚinstanceÚobjectc                ó.   — |                       ¦   «          dS )a:  Release this lock when it is deleted from an owning object.

        Python routes ``del owner.attribute`` here when a lock instance is
        stored as a class attribute of ``owner``, which lets a lock be
        released by deleting the attribute that holds it. The lock itself
        is the descriptor, so it is this lock's own `release` that runs.
        The owning object is received as `instance` and is not touched.

        Args:
            instance: The object the attribute was deleted from. Unused,
                since the lock releases itself.
        Nr¶   )r�   r¹   s     r   Ú
__delete__zLockBase.__delete__  s   € ð 	�Š‰Œˆˆˆr   ©NNN)r|   r€   r}   r€   r~   r�   r   r%   )r   r”   )r|   r€   r}   r€   r~   r�   r   rg   )r|   r€   r}   r€   r   rš   ©r   r%   )r   rg   ©r°   r±   r²   r³   r´   r   r   r�   )r¹   rº   r   r%   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r“   rp   ÚabcÚabstractmethodr˜   rª   r¬   r¯   r¸   r¼   r   r   r   rz   rz   Õ  s;  € € € € € € ðHð HðV €N€N�NàÐÐÑàÐÐÑð !Ð Ð Ñ ð !%Ø'+Ø(,ð	Að Að Að Að AðF#ð #ð #ð #ð( 	Ôð !%Ø'+Ø(,ð	ð ð ð ñ Ôðð>9>ð 9>ð 9>ð 9>ðv 	Ôðð ð ñ Ôððð ð ð ðð ð ð ð(ð ð ð ð ð r   rz   c                 óº   — t          j        ¦   «         } | €dS | j        } d}| �8| j        j        t
          k    r#|dz  }| j        } | �| j        j        t
          k    °#|S )a
  Return the `warnings.warn` stacklevel of the first foreign frame.

    Computed for the caller: starting from the function that called this
    helper, every consecutive stack frame that still lives in this
    module is skipped, and the returned stacklevel makes
    `warnings.warn`, invoked from that caller, attribute the warning to
    the first frame outside the module. That keeps warnings pointing at
    the user's own code no matter how many subclass constructors or
    ``acquire`` wrappers sit in between: `Lock` warns through one
    internal frame, `RLock` and `TemporaryFileLock` through two,
    `PidFileLock` through three.

    Python 3.12 grew ``warnings.warn(skip_file_prefixes=...)`` for
    exactly this job. This helper is the 3.10 compatible spelling.

    Returns:
        The stacklevel to pass to `warnings.warn` from the caller's
        frame, at least ``1``. Falls back to ``1``, which names the
        caller itself, when the interpreter offers no frame
        introspection (CPython always does).
    Nr   )ÚinspectÚcurrentframeÚf_backÚf_codeÚco_filenameÚ__file__)Úframer…   s     r   r‰   r‰   !  sl   € õ, &Ô2Ñ4Ô4€EØ€}ØˆqàŒL€EØ€JØ
Ð
 ¤Ô 8½HÒ DÐ DØ�a‰ˆ
Ø”ˆð Ð
 ¤Ô 8½HÒ DÐ Dð Ðr   Úfhútypes.IOc                óÀ   — ddl }|                      ¦   «         }|                      ||j        ¦  «        }|                      ||j        |t          j         z  ¦  «         dS )aÓ  Clear the kernel append flag so ``fh`` honours seek positions.

    `Lock` opens a mode containing ``w`` as ``a`` to defer the truncation
    until the lock is held, but ``O_APPEND`` makes the kernel ignore the
    seek position on every ``write``: ``fh.write('x'); fh.seek(0);
    fh.write('y')`` yields ``'xy'`` where plain ``open(mode='w')`` yields
    ``'y'``. Clearing the flag after the truncation restores the write
    semantics the caller asked for.

    POSIX only: Windows has no ``fcntl`` and offers no way to drop the
    append flag from an open handle, so there the substitution keeps
    append semantics and is documented instead.

    Args:
        fh: The open, locked, already truncated filehandle.
    r   N)Úfcntlra   ÚF_GETFLÚF_SETFLr8   ÚO_APPEND)rÏ   rÒ   Úfdr6   s       r   Ú_restore_positional_writesr×   C  sV   € ð" €L€L€Là�iŠi‰kŒk€BØ—’˜R ¤Ñ/Ô/€EØ	‡K‚K��E”M 5­B¬K¨<Ñ#7Ñ8Ô8Ð8Ð8Ð8r   r²   Úrelease_errorc                ó,  — | j         }||_         |}d}|�1|dk     r+|j         | u rd|_         |j        p|j         }|dz  }|�|dk     °+|| _         t          j        t          ¦  «        5  |                      d¦  «         ddd¦  «         dS # 1 swxY w Y   dS )aË  Chain a release failure under the exception leaving a block.

    The body-exception-wins discipline shared by `Lock.__exit__` and
    `~portalocker.redis.RedisLock.__exit__`: the release error becomes
    the ``__context__`` of the exception already propagating out of the
    ``with`` block and a note is attached, so both remain visible in
    the traceback while the block's own exception is what the caller
    sees.

    Errors raised while ``exc_value`` was in flight carry it as their
    implicit ``__context__``. Splicing the release error underneath
    ``exc_value`` would then close a reference cycle that loops naive
    chain walkers, so those back links are snipped first. The walk is
    bounded instead of tracked, because a release chain deeper than
    this is not worth preserving.

    Args:
        exc_value: The exception leaving the ``with`` block.
        release_error: What `release` raised while ``exc_value`` was in
            flight.
    r   Né
   r   z1portalocker release failed; see exception context)Ú__context__Ú	__cause__rb   rc   rd   Úadd_note)r²   rØ   Úprevious_contextrM   Údepths        r   Ú_chain_release_errorrà   [  s  € ð2 .7Ô-BÐØ 0€MÔØ!.€DØ€EØ
Ð
˜u ršz˜zØÔ˜yÐ(Ð(Ø#ˆDÔØŒ~Ð1 Ô!1ˆØ�‰
ˆð	 Ð
˜u ršz˜zð
 *€IÔÝ	Ô	�YÑ	'Ô	'ð 
ð 
Ø×ÒØ?ñ	
ô 	
ð 	
ð
ð 
ð 
ñ 
ô 
ð 
ð 
ð 
ð 
ð 
ð 
ð 
øøøð 
ð 
ð 
ð 
ð 
ð 
s   Á&B	Â	BÂBc                  óª  ‡ — e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   d	ed<   ded<   ded<   ded<   ded<   dZded<   ej        ddee	e
fddœd<d„¦   «         Zej        dee	e
fddœd=d"„¦   «         Zej        dee	e
fddœd>d%„¦   «         Zddee	e
fddœd?d&„Zd?ˆ fd'„Zd@d(„Z	 	 	 dAdBd+„ZdCd,„ZdDd-„ZdEd3„ZdFd4„ZdGd6„ZdHd8„ZdDd9„ZdCd:„ZdCd;„Zˆ xZS )Ir   a«	  Lock manager with built-in timeout.

    The class most users want. It opens `filename`, locks it, retries for
    as long as the inherited retry policy allows, and hands the open
    filehandle to the caller. Releasing unlocks and closes that handle; the
    file itself stays behind, which is what makes the lock usable as a
    plain data file as well as a mutex.

    The class is generic over the filehandle it hands out, and the open
    mode decides the specialization: a text mode yields a
    ``Lock[IO[str]]``, a binary mode a ``Lock[IO[bytes]]``, so type
    checkers know whether ``fh.read()`` produces `str` or `bytes`
    (issue #97). A bare ``Lock`` annotation means ``Lock[IO[str]]``,
    matching the default mode of ``'a'``.

    Example:
        >>> import portalocker
        >>> with portalocker.Lock('somefile', 'w', timeout=1) as fh:
        ...     _ = fh.write('locked while the block runs')

    Warning:
        The file is opened before it is locked, so letting `open` truncate
        would discard another holder's data *before* anybody checks whether
        the lock is free. That is why a mode containing ``w`` is silently
        turned into ``a`` and the truncation is deferred to
        `Lock._prepare_fh`, which runs only after the lock has been taken.

    Warning:
        The ``a`` substitution has a side effect on Windows: the handle
        keeps the kernel's append semantics, so every ``write`` lands at
        the end of the file no matter where you ``seek``. A positioned
        rewrite such as ``fh.write('x'); fh.seek(0); fh.write('y')``
        produces ``'xy'`` there, where plain ``open(mode='w')`` produces
        ``'y'``. On POSIX portalocker clears the append flag once the
        truncation is done, so ``w`` and ``w+`` behave exactly like the
        builtin ``open``. If you need positioned writes on Windows,
        reopen the file after acquiring, or lock with mode ``r+`` and
        truncate explicitly.

    Note:
        Locking is per open filehandle, not per process. Two `Lock`
        instances on the same path in the same process do contend with each
        other, which is what makes single process examples and tests
        meaningful.

    See Also:
        `LockBase`: documents the ``timeout``, ``check_interval`` and
        ``fail_when_locked`` retry semantics shared by every lock.
        `RLock`: the reentrant variant.
        `TemporaryFileLock`: removes the lock file on release.
    z
IOT | NonerÏ   r$   rS   Úmoder2   Útruncater{   r|   r}   r~   úconstants.LockFlagsr6   Úraise_on_release_errorzdict[str, typing.Any]Úfile_open_kwargsFÚ_timeout_warnedÚaN©rå   r�   úLock[typing.IO[str]]r   r   r€   r   r   r%   c               ó   — d S r   r   ©	r�   rS   râ   r|   r}   r~   r6   rå   ræ   s	            r   r“   zLock.__init__Ê  ó	   € ð ˆsr   úLock[typing.IO[bytes]]r
   c               ó   — d S r   r   rì   s	            r   r“   zLock.__init__Ø  rí   r   úLock[typing.IO[typing.Any]]r   c               ó   — d S r   r   rì   s	            r   r“   zLock.__init__ì  rí   r   c               ó0   —  | j         ||||||fd|i|¤Ž dS )a�	  Configure the lock; nothing is opened or locked yet.

        Args:
            filename: Path of the file to lock. Anything `str` accepts,
                including a `pathlib.Path`. It is stored as an absolute
                path string: a relative path is resolved against the
                working directory once, here, so an ``os.chdir`` between
                acquire and release (the daemonize idiom does
                ``chdir('/')``) cannot redirect the release, or the
                interpreter-exit cleanup of the subclasses, at another
                process's equally-named lock files. Changed in 4.2.0;
                the ``filename`` attribute used to keep the path as
                given.
            mode: Open mode for the file. Use ``'a'`` or ``'ab'`` to write.
                A mode containing ``w`` is rewritten to ``a`` and the
                truncation is postponed until the lock has been taken, see
                the class warning.
            timeout: See `LockBase`. `None` selects `DEFAULT_TIMEOUT`.
            check_interval: See `LockBase`.
            fail_when_locked: See `LockBase`.
            flags: Locking flags, defaulting to
                ``LockFlags.EXCLUSIVE | LockFlags.NON_BLOCKING``. Shared
                locks (``LockFlags.SHARED``) on Windows require the
                optional ``pywin32`` package
                (``pip install "portalocker[win32]"``). Without it
                `acquire` fails with a `LockException` wrapping the
                ``ImportError`` that names the extra; the bare
                ``ImportError`` only escapes `portalocker.lock`, which
                does no wrapping.
            raise_on_release_error: Report errors that happen while
                unlocking or closing in `release`, instead of swallowing
                them. Off by default for backwards compatibility.
            **file_open_kwargs: Passed straight through to `open`, for
                things like ``encoding`` or ``buffering``.

        Warns:
            UserWarning: An explicit `timeout` was combined with blocking
                `flags`, i.e. flags without ``LockFlags.NON_BLOCKING``.
                The operating system blocks inside the first attempt in
                that case, so there is nothing left for the timeout to do.
                The warning is emitted at most once per instance: here,
                or on the first `acquire` that passes a timeout.
        rå   N)Ú_initrì   s	            r   r“   zLock.__init__ú  sP   € ðn 	ˆŒ
ØØØØØØð		
ð 		
ð $:ð		
ð ð		
ð 		
ð 		
ð 		
ð 		
r   c               ó¤  •— d|v r1d}	t          j        t          |                     dd¦  «        ¦  «        }nd}	d| _        t
          j                             |¦  «        | _        || _	        |	| _
        || _        || _        || _        d| _        |€t          }n|                      |¦  «         t#          ¦   «                              |||¦  «         dS )aÌ  Shared constructor body behind the overloaded `__init__`.

        `__init__` is overloaded so the open mode picks the filehandle
        specialization, and an overloaded method cannot be super-called
        from a generic subclass: no overload's ``self`` type matches the
        subclass's still-unsolved type variable. Generic subclasses such
        as `RLock` therefore run their parent initialization through this
        plain method instead.
        r?   Trè   FN)ÚtypingÚcastr   ÚreplacerÏ   r8   r/   ÚabspathrS   râ   rã   r6   rå   ræ   rç   rŠ   Ú_warn_blocking_timeoutÚsuperr“   )r�   rS   râ   r|   r}   r~   r6   rå   ræ   rã   Ú	__class__s             €r   ró   z
Lock._init<  sÅ   ø€ ð* �$ˆ;ˆ;ØˆHÝ”;�t T§\¢\°#°sÑ%;Ô%;Ñ<Ô<ˆDˆDàˆHàˆŒÝœŸš¨Ñ1Ô1ˆŒØˆŒ	Ø ˆŒØˆŒ
Ø&<ˆÔ#Ø 0ˆÔà$ˆÔØˆ?Ý%ˆGˆGà×'Ò'¨Ñ0Ô0Ð0Ý‰Œ×Ò˜ .Ð2BÑCÔCÐCÐCÐCr   c                óº   — |�-| j         s&t          | j        t          j        j        z  ¦  «        rdS d| _         t          j        dt          ¦   «         ¬¦  «         dS )a(  Warn that `timeout` cannot work with blocking flags, only once.

        With flags lacking ``LockFlags.NON_BLOCKING`` the operating
        system waits inside the locking call itself, so a timeout has
        nothing left to do. The warning fires at most once per instance,
        whether that happens at construction or on the first `acquire`
        that passes a timeout. Its stacklevel is computed by
        `_stacklevel_beyond_module`, so it names the caller's own file
        for every entry point: a `Lock` built directly, the `RLock`,
        `TemporaryFileLock` and `PidFileLock` constructors, and the
        ``acquire`` chains of all four.

        Args:
            timeout: The caller-provided timeout, or `None` when the
                caller did not pass one, which never warns.
        NTz&timeout has no effect in blocking moder„   )	rç   r2   r6   r   Ú	LockFlagsÚNON_BLOCKINGr†   r‡   r‰   )r�   r|   s     r   rù   zLock._warn_blocking_timeoutf  so   € ð$ ˆOØÔ#ð å�D”J¥Ô!4Ô!AÑAÑBÔBð ð ˆFØ#ˆÔÝŒØ4Ý0Ñ2Ô2ð	
ñ 	
ô 	
ð 	
ð 	
ð 	
r   r�   ri   c                ó®  — t          || j        ¦  «        }|                      |¦  «         | j        }|r|S |                      ¦   «         }	 d}|                      ||¦  «        D ]˜}d}	 |                      |¦  «        } n}# t          j        $ r:}|}|r,t          j        |j	        |j        t          |dd¦  «        dœŽ|‚Y d}~Œ`d}~wt          j        $ r ‚ t          $ r}t          j        |¦  «        |‚d}~ww xY w|r|‚|                      |¦  «        }n™# t          $ rŒ t          j        t          ¦  «        5  t#          j        |¦  «         ddd¦  «         n# 1 swxY w Y   t          j        t          ¦  «        5  |                     ¦   «          ddd¦  «         n# 1 swxY w Y   ‚ w xY w| j        5  || _        ddd¦  «         n# 1 swxY w Y   |S )aS  Open the file, lock it and return the filehandle.

        Calling this on a lock that is already held is cheap and safe: the
        filehandle taken earlier is returned as is, without touching the
        operating system.

        Two threads *racing* this method on one instance is unsupported.
        The instance's bookkeeping stays consistent, but with a
        per-process locker (POSIX ``lockf``) both lock calls succeed,
        one thread's filehandle overwrites the other's, and the
        orphaned descriptor's eventual close releases the process's
        record locks on the file, the winner's included: that is how
        POSIX record locks work, and no publication strategy on this
        side can paper over it. Give each thread its own lock instance
        instead.

        Args:
            timeout: Overrides `timeout` for this call. See `LockBase`.
            check_interval: Overrides `check_interval` for this call.
            fail_when_locked: Overrides `fail_when_locked` for this call.

        Returns:
            The open, locked filehandle. It is stored on the instance as
            well, and stays valid until `release`.

        Raises:
            ~portalocker.exceptions.AlreadyLocked: The first attempt found the
                file locked and `fail_when_locked` was set, or `timeout`
                expired while the file stayed locked by somebody else.
                Only contention is retried: the locking backend signals it
                by raising `AlreadyLocked` itself.
            ~portalocker.exceptions.LockException: The backend failed for
                a reason other than contention, such as a filesystem
                without locking support or refused flags. This is
                permanent, so it is raised immediately without burning
                the timeout, and without being dressed up as
                `AlreadyLocked`. A non-portalocker error from the locking
                call is wrapped in this type as well.
            OSError: Opening or preparing the file failed, for instance
                because the directory does not exist or the mode is not
                permitted. Only locking failures are translated. Failures
                from `open` and from the deferred truncation propagate
                untouched. When the failure happens after the lock was
                taken, the file is unlocked and closed again first.

        Warns:
            UserWarning: A `timeout` was passed while the lock uses
                blocking flags, where it has no effect. Emitted at most
                once per instance, counting the constructor's warning.

        Example:
            >>> import portalocker
            >>> lock = portalocker.Lock('somefile', timeout=1)
            >>> fh = lock.acquire()
            >>> fh is lock.acquire()
            True
            >>> lock.release()
        NÚ
holder_pid)rÏ   r   )r   r~   rù   rÏ   Ú_get_fhrª   Ú	_get_lockr   ÚAlreadyLockedr   rq   ÚLockExceptionrd   Ú_prepare_locked_fhr"   rb   rc   r   Úunlockr_   r   )r�   r|   r}   r~   rÏ   Ú	exceptionrF   Úexcs           r   r˜   zLock.acquireƒ  s  € õ@ $Ð$4°dÔ6KÑLÔLÐØ×#Ò# GÑ,Ô,Ð,ð ŒWˆØð 	ØˆIð �\Š\‰^Œ^ˆðC	ØˆIà×,Ò,¨W°nÑEÔEð )Að )A�Ø �	ð'AàŸš¨Ñ+Ô+�BØ�EøÝ!Ô/ð #ð #ð #ð !$�Ið (ð #õ )Ô6Ø œXØ"œvÝ'.¨s°LÀ$Ñ'GÔ'Gðð ð ð  #ð	#ð#ð #ð #ð #ð #øøøøõ "Ô/ð ð ð ð Ý ð Að Að Aõ %Ô2°3Ñ7Ô7¸SÐ@øøøøðAøøøð ð  à�ð ×(Ò(¨Ñ,Ô,ˆBˆBøÝð 	ð 	ð 	õ Ô$¥YÑ/Ô/ð 'ð 'ÝÔ" 2Ñ&Ô&Ð&ð'ð 'ð 'ñ 'ô 'ð 'ð 'ð 'ð 'ð 'ð 'øøøð 'ð 'ð 'ð 'åÔ$¥YÑ/Ô/ð ð Ø—’‘
”
�
ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð àð	øøøð Ôð 	ð 	ØˆDŒGð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	àˆ	sœ   ÁD Á(A?Á=D Á?C9Â0CÂ>D ÃC9ÃC4Ã4C9Ã9D Ä#F,Ä9EÅF,ÅE	ÅF,Å!E	Å"F,Å>FÆF,ÆF#	Æ#F,Æ&F#	Æ'F,Æ6G
Ç
GÇGc                ó`  — 	 |                       |¦  «        S # t          $ rŒ t          j        t          ¦  «        5  t          j        |¦  «         ddd¦  «         n# 1 swxY w Y   t          j        t          ¦  «        5  |                     ¦   «          ddd¦  «         n# 1 swxY w Y   ‚ w xY w)a  Run `Lock._prepare_fh`, rolling the lock back when it fails.

        Preparation runs after the lock was taken, so a failure there,
        for example a truncate refused by an append-only file, must give
        the lock back: the caller's traceback may keep `fh` alive
        indefinitely, and a close alone would leave the file locked for
        as long as the exception is referenced. The handle is therefore
        unlocked explicitly and closed before the original error
        escapes, both best effort so they cannot mask that error. The
        rollback covers `BaseException`, not just `Exception`: a
        ``KeyboardInterrupt`` delivered inside the preparation would
        otherwise strand the OS lock on an untracked descriptor, with
        `release` a silent no-op because ``self.fh`` was never set.

        Args:
            fh: The freshly locked filehandle.

        Returns:
            The prepared filehandle, on success.

        Raises:
            BaseException: Whatever `Lock._prepare_fh` raised, unchanged.
        N)Ú_prepare_fhr"   rb   rc   rd   r   r  r_   ©r�   rÏ   s     r   r  zLock._prepare_locked_fh  s#  € ð0	Ø×#Ò# BÑ'Ô'Ð'øÝð 	ð 	ð 	ÝÔ$¥YÑ/Ô/ð 'ð 'ÝÔ" 2Ñ&Ô&Ð&ð'ð 'ð 'ñ 'ô 'ð 'ð 'ð 'ð 'ð 'ð 'øøøð 'ð 'ð 'ð 'åÔ$¥YÑ/Ô/ð ð Ø—’‘
”
�
ðð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð àð	øøøsP   ‚ —#B-ºAÁB-ÁA	ÁB-Á"A	Á#B-Á?B ÂB-Â B$	Â$B-Â'B$	Â(B-c                ó*   — |                       ¦   «         S )aK  Acquire the lock and return the filehandle to bind with ``as``.

        Returns:
            The open, locked filehandle, exactly as `acquire` returns it.

        Example:
            >>> import portalocker
            >>> with portalocker.Lock('somefile', 'a', timeout=1) as fh:
            ...     _ = fh.write('text')
        r®   r–   s    r   r¯   zLock.__enter__8  s   € ð �|Š|‰~Œ~Ðr   r°   r±   r²   r³   r´   c                ó†   — 	 |                       ¦   «          n*# t          $ r}|€‚ t          ||¦  «         Y d}~nd}~ww xY wdS )a:  Release the lock, preserving an exception from the block.

        Overrides `LockBase.__exit__` for one reason: when the block is
        already leaving with an exception, a failure during `release` must
        not replace it. The release error is chained onto the original as
        its ``__context__`` and a note is attached, so both remain visible
        in the traceback while the original is what propagates. `release`
        only raises when ``raise_on_release_error`` is set, but the
        protection holds either way, so even a subclass whose `release`
        fails unexpectedly cannot mask the block's own exception.
        `PidFileLock` overrides ``__exit__`` with an ownership check but
        routes the actual release through this method, so the guarantee
        covers it as well.

        Args:
            exc_type: Type of the exception leaving the block, if any.
            exc_value: The exception instance, if any.
            traceback: The traceback of that exception, if any.

        Returns:
            `None`; exceptions from the block are never suppressed.

        Raises:
            Exception: Whatever `release` raises, but only when the block
                itself ended without an exception. With the default
                ``raise_on_release_error=False`` that is nothing at all.
        N)r¬   rd   rà   )r�   r°   r²   r´   rØ   s        r   r¸   zLock.__exit__E  se   € ðB	;Ø�LŠL‰NŒNˆNˆNøÝð 	;ð 	;ð 	;ØÐ àÝ  ¨MÑ:Ô:Ð:Ð:Ð:Ð:Ð:Ð:øøøøð		;øøøð
 ˆts   ‚ —
>¡9¹>c                ó`   — |                       ¦   «         }|�|                      |¦  «         dS dS )aÜ  Unlock and close the file handle, if this instance holds one.

        Doing nothing when no lock is held is deliberate: double releases
        and the ``atexit`` fallback of `TemporaryFileLock` rely on it.

        The stored handle is claimed atomically before any OS call runs:
        exactly one caller takes ownership and tears the lock down, every
        concurrent or reentrant caller finds nothing and returns. Two
        threads releasing at once therefore cannot both reach the unlock,
        where the loser used to run it on a closed, possibly reused file
        descriptor and silently dropped whichever lock that descriptor
        number belonged to by then. The claim-first ordering also means an
        interrupt escaping ``close`` (a ``KeyboardInterrupt`` during a
        buffered flush) can no longer leave the instance believing it
        still holds the lock.

        Raises:
            Exception: Only when the lock was built with
                ``raise_on_release_error=True``. The first failure of the
                unlock and close pair is raised, chained from the second
                if both failed. By default such failures are suppressed
                and logged at warning level instead.
        N)Ú	_claim_fhÚ_release_claimed_fhr  s     r   r¬   zLock.releaseo  s9   € ð0 #ŸnšnÑ.Ô.ˆØˆ>Ø×$Ò$ RÑ(Ô(Ð(Ð(Ð(ð ˆ>r   útypes.IO | Nonec                ób   — | j         5  | j        dc}| _        ddd¦  «         n# 1 swxY w Y   |S )aM  Atomically take ownership of the stored filehandle.

        The swap runs under the instance state lock, so of any number of
        concurrent callers exactly one receives the handle and everyone
        else receives `None`. The state lock is reentrant, which makes the
        claim signal safe: a handler that calls `release` while this
        thread sits inside the swap claims `None` instead of deadlocking.

        Returns:
            The filehandle this instance held, now owned by the caller,
            or `None` when another claim (or none at all) got there first.
        N)r   rÏ   r  s     r   r  zLock._claim_fh‹  sv   € ð Ôð 	(ð 	(Øœ' 4ˆKˆB�”ð	(ð 	(ð 	(ñ 	(ô 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(øøøð 	(ð 	(ð 	(ð 	(àˆ	ó   ˆ$¤(«(rÐ   c                óN  — g }	 	 t          j        |¦  «         n,# t          $ r}|                     |¦  «         Y d}~nd}~ww xY w	 |                     ¦   «          nr# t          $ r}|                     |¦  «         Y d}~nNd}~ww xY w# 	 |                     ¦   «          w # t          $ r}|                     |¦  «         Y d}~w d}~ww xY wxY w|rS| j        r&|d         }t          |¦  «        dk    r	||d         ‚|‚|D ]%}t                               d| j	        |¦  «         Œ$dS dS )a6  Unlock and close a filehandle claimed via `Lock._claim_fh`.

        Both steps are always attempted: on Windows closing the handle is
        what releases the lock, so a failing unlock must not skip the
        close. The error policy is the one documented on `Lock.release`.

        Args:
            fh: The claimed filehandle. The caller owns it exclusively;
                the instance no longer references it.

        Raises:
            Exception: Only with ``raise_on_release_error`` set, exactly
                as documented on `Lock.release`.
        Nr   r   z/suppressed error while releasing lock on %r: %r)
r   r  rd   Úappendr_   rå   ÚlenÚloggerÚwarningrS   )r�   rÏ   Úrelease_errorsr  Úprimary_errorrØ   s         r   r  zLock._release_claimed_fh�  s§  € ð +-ˆð		1ð1ÝÔ" 2Ñ&Ô&Ð&Ð&øÝð 1ð 1ð 1Ø×%Ò% iÑ0Ô0Ð0Ð0Ð0Ð0Ð0Ð0øøøøð1øøøð1Ø—’‘
”
�
�
øÝð 1ð 1ð 1Ø×%Ò% iÑ0Ô0Ð0Ð0Ð0Ð0Ð0Ð0øøøøð1øøøøð1Ø—’‘
”
�
�
øÝð 1ð 1ð 1Ø×%Ò% iÑ0Ô0Ð0Ð0Ð0Ð0Ð0Ð0øøøøð1øøøøøøð ð 	ØÔ*ð $Ø+9¸!Ô+<�Ý�~Ñ&Ô&¨Ò*Ð*Ø'¨^¸AÔ->Ð>Ø#Ð#Ø!/ð ð �Ý—’ØEØ”MØ!ñô ð ð ð	ð 	ðð sj   … ™B š
A¤>¹B ¾AÁB ÁA Á
BÁ&B Â BÂCÂ
BÂCÂ
CÂ)CÂ>CÃCÃCc                ób   — t          j        dt          | j        | j        fi | j        ¤Ž¦  «        S )z<Open the file and return the new, still unlocked filehandle.ri   )rõ   rö   r9   rS   râ   ræ   r–   s    r   r  zLock._get_fhÅ  sB   € åŒ{ØÝØ”Ø”	ðð ð Ô'ðð ñ
ô 
ð 	
r   c                ó:   — t          j        || j        ¦  «         |S )aK  Lock `fh` with the configured flags.

        Args:
            fh: The filehandle returned by `Lock._get_fh`.

        Returns:
            The same filehandle, now locked.

        Raises:
            ~portalocker.exceptions.LockException: The file is locked by
                somebody else, or the locking call failed.
        )r   rr   r6   r  s     r   r  zLock._get_lockÐ  s   € õ 	Ô˜˜TœZÑ(Ô(Ð(Øˆ	r   c                ó¦   — | j         rI|                     d¦  «         |                      d¦  «         t          j        dk    rt	          |¦  «         |S )a’  Make the locked filehandle ready for the caller.

        Truncation happens here rather than in `open`, so that a lock
        opened with mode ``w`` cannot discard the contents of a file
        somebody else is holding. On POSIX the kernel append flag the
        ``a`` substitution introduced is cleared again afterwards, so the
        handle honours seek positions exactly like the ``w`` mode the
        caller asked for, see `_restore_positional_writes`.

        Args:
            fh: The locked filehandle.

        Returns:
            The same filehandle, emptied and rewound when the lock was
            created with a truncating mode.
        r   Úposix)rã   Úseekr8   rK   r×   r  s     r   r
  zLock._prepare_fhà  sL   € ð" Œ=ð 	/Ø�GŠG�A‰JŒJˆJØ�KŠK˜‰NŒNˆNÝŒw˜'Ò!Ð!Ý*¨2Ñ.Ô.Ð.àˆ	r   )r�   rê   rS   r   râ   r   r|   r€   r}   r{   r~   r2   r6   rä   rå   r2   ræ   r   r   r%   )r�   rî   rS   r   râ   r
   r|   r€   r}   r{   r~   r2   r6   rä   rå   r2   ræ   r   r   r%   )r�   rð   rS   r   râ   r   r|   r€   r}   r{   r~   r2   r6   rä   rå   r2   ræ   r   r   r%   )rS   r   râ   r   r|   r€   r}   r{   r~   r2   r6   rä   rå   r2   ræ   r   r   r%   )r|   r€   r   r%   r½   ©r|   r€   r}   r€   r~   r�   r   ri   )rÏ   ri   r   ri   )r   ri   r¿   r¾   )r   r  ©rÏ   rÐ   r   r%   )rÀ   rÁ   rÂ   rÃ   rÄ   rç   rõ   Úoverloadr‹   rŒ   ÚLOCK_METHODr“   ró   rù   r˜   r  r¯   r¸   r¬   r  r  r  r  r
  Ú__classcell__©rû   s   @r   r   r   „  sÒ  ø€ € € € € € ð2ð 2ðh €N€N�NØ€M€M�MØ€I€I�IØ€N€N�NØ€N€N�NØÐÐÑØÐÐÑØÐÐÑØ Ð Ð Ñ Ø+Ð+Ð+Ñ+ð "€OÐ!Ð!Ð!Ñ!à„_ð Ø $Ø 6Ø!9Ø%0ðð (-ðð ð ð ð ñ „_ðð „_ð
 !%Ø 6Ø!9Ø%0ðð (-ðð ð ð ð ñ „_ðð& „_ð
 !%Ø 6Ø!9Ø%0ðð (-ðð ð ð ð ñ „_ðð  Ø $Ø 6Ø!9Ø%0ð@
ð (-ð@
ð @
ð @
ð @
ð @
ð @
ðD(Dð (Dð (Dð (Dð (Dð (DðT
ð 
ð 
ð 
ð> !%Ø'+Ø(,ð	Rð Rð Rð Rð Rðhð ð ð ðBð ð ð ð(ð (ð (ð (ðT)ð )ð )ð )ð8ð ð ð ð$&ð &ð &ð &ðP	
ð 	
ð 	
ð 	
ðð ð ð ð ð ð ð ð ð ð ð r   c                  óÒ   ‡ — e Zd ZdZej        ddedefd!d„¦   «         Zej        dedefd"d„¦   «         Zej        dedefd#d„¦   «         Zddedefd$ˆ fd„Z	 	 	 d%d&ˆ fd„Z	d'd „Z
ˆ xZS )(rŽ   a  
    A reentrant lock, functions in a similar way to threading.RLock in that it
    can be acquired multiple times.  When the corresponding number of release()
    calls are made the lock will finally release the underlying file lock.

    Like `Lock`, the open mode picks the filehandle specialization: text
    modes yield an ``RLock[IO[str]]``, binary modes an
    ``RLock[IO[bytes]]``, and a bare ``RLock`` annotation means the text
    variant.

    Reentrancy is per instance, not per process: it is this object's own
    acquire count that is tracked, so a *second* `RLock` on the same file
    still contends with the first one.

    Example:
        >>> import portalocker
        >>> lock = portalocker.RLock('somefile')
        >>> fh = lock.acquire()
        >>> fh is lock.acquire()
        True
        >>> lock.release()
        >>> fh.closed
        False
        >>> lock.release()
        >>> fh.closed
        True

    See Also:
        `Lock`: the non-reentrant version and the source of every
        constructor argument.
    rè   NFr�   úRLock[typing.IO[str]]rS   r   râ   r   r|   r€   r}   r{   r~   r2   r6   rä   r   r%   c                ó   — d S r   r   ©r�   rS   râ   r|   r}   r~   r6   s          r   r“   zRLock.__init__  ó	   € ð ˆsr   úRLock[typing.IO[bytes]]r
   c                ó   — d S r   r   r)  s          r   r“   zRLock.__init__&  r*  r   úRLock[typing.IO[typing.Any]]r   c                ó   — d S r   r   r)  s          r   r“   zRLock.__init__2  r*  r   c           	     óf   •— t          ¦   «                              ||||||d¬¦  «         d| _        dS )a§  Configure the lock and start with an acquire count of zero.

        Args:
            filename: Path of the file to lock.
            mode: Open mode for the file, see `Lock`.
            timeout: See `LockBase`. `None` selects `DEFAULT_TIMEOUT`.
                Only an explicit value counts as "a timeout was given"
                for the blocking mode warning documented on `Lock`.
            check_interval: See `LockBase`.
            fail_when_locked: See `LockBase`.
            flags: Locking flags, see `Lock`.

        Note:
            Unlike `Lock`, this constructor takes neither
            ``raise_on_release_error`` nor extra `open` keyword arguments.
        Fré   r   N)rú   ró   Ú_acquire_count)r�   rS   râ   r|   r}   r~   r6   rû   s          €r   r“   zRLock.__init__=  sI   ø€ õ8 	‰Œ�ŠØØØØØØØ#(ð 	ñ 	
ô 	
ð 	
ð  ˆÔÐÐr   r�   ri   c                ó~  •— | j         5  | j        dk    r>| j        €t          j        d¦  «        ‚| xj        dz  c_        | j        cddd¦  «         S 	 ddd¦  «         n# 1 swxY w Y   t          ¦   «                              |||¦  «        }| j         5  | xj        dz  c_        ddd¦  «         n# 1 swxY w Y   |S )ar  Take the lock, or note that this instance already has it.

        The first call locks the file through `Lock.acquire`. Every later
        call only bumps the acquire count and hands back the same
        filehandle, so the arguments are ignored once the lock is held.

        Args:
            timeout: Overrides `timeout` for the first call. See
                `LockBase`.
            check_interval: Overrides `check_interval` for the first call.
            fail_when_locked: Overrides `fail_when_locked` for the first
                call.

        Returns:
            The open, locked filehandle. The same object for every nested
            acquire.

        Raises:
            ~portalocker.exceptions.AlreadyLocked: As `Lock.acquire`, on the
                first call only.
            ~portalocker.exceptions.LockException: As `Lock.acquire`, on the
                first call only. Also raised when the instance claims to
                be acquired but holds no filehandle, which means the
                bookkeeping was corrupted, for example by tampering with
                the private state or a partially failed release. An
                ``assert`` would vanish under ``python -O`` and hand the
                caller `None` instead of a filehandle, so this is a real
                exception.
            OSError: As `Lock.acquire`, on the first call only.
        r   NzgRLock claims to be acquired but holds no filehandle, its state was corrupted. Refusing to hand out None)r   r0  rÏ   r   r  rú   r˜   )r�   r|   r}   r~   rÏ   rû   s        €r   r˜   zRLock.acquired  sl  ø€ ðJ Ôð 		ð 		ØÔ" aÒ'Ð'Ø”7�?Ý$Ô2ð+ñô ð ð
 Ð#Ô# qÑ(Ð#Ô#Ø”wð		ð 		ð 		ð 		ñ 		ô 		ð 		ð 		Ø'ð		ð 		ð 		ñ 		ô 		ð 		ð 		ð 		ð 		ð 		ð 		øøøð 		ð 		ð 		ð 		õ ‰WŒW�_Š_˜W nÐ6FÑGÔGˆØÔð 	%ð 	%ØÐÔ 1Ñ$ÐÔð	%ð 	%ð 	%ñ 	%ô 	%ð 	%ð 	%ð 	%ð 	%ð 	%ð 	%øøøð 	%ð 	%ð 	%ð 	%àˆ	s#   ‰=A Á A$Á'A$ÂB2Â2B6Â9B6c                ó  — | j         5  | j        dk    rt          j        d¦  «        ‚| xj        dz  c_        | j        dk    r|                      ¦   «         nd}ddd¦  «         n# 1 swxY w Y   |�|                      |¦  «         dS dS )at  Drop one acquire, unlocking once the count reaches zero.

        Raises:
            ~portalocker.exceptions.LockException: Released more often than
                acquired. That is a bookkeeping error rather than contention,
                so it is reported rather than ignored, unlike the tolerant
                `Lock.release` this eventually delegates to.
        r   z'Cannot release more times than acquiredr   N)r   r0  r   r  r  r  r  s     r   r¬   zRLock.release›  sú   € ð Ôð 	Hð 	HØÔ" aÒ'Ð'Ý Ô.Ø=ñô ð ð ÐÔ 1Ñ$ÐÔð &*Ô%8¸AÒ%=Ð%=�—’Ñ!Ô!Ð!À4ˆBð	Hð 	Hð 	Hñ 	Hô 	Hð 	Hð 	Hð 	Hð 	Hð 	Hð 	Høøøð 	Hð 	Hð 	Hð 	Hð ˆ>Ø×$Ò$ RÑ(Ô(Ð(Ð(Ð(ð ˆ>s   ˆAA%Á%A)Á,A))r�   r'  rS   r   râ   r   r|   r€   r}   r{   r~   r2   r6   rä   r   r%   )r�   r+  rS   r   râ   r
   r|   r€   r}   r{   r~   r2   r6   rä   r   r%   )r�   r-  rS   r   râ   r   r|   r€   r}   r{   r~   r2   r6   rä   r   r%   )rS   r   râ   r   r|   r€   r}   r{   r~   r2   r6   rä   r   r%   r½   r   r¾   )rÀ   rÁ   rÂ   rÃ   rõ   r"  r‹   r#  r“   r˜   r¬   r$  r%  s   @r   rŽ   rŽ   ú  sD  ø€ € € € € ðð ð@ „_ð Ø $Ø 6Ø!&Ø%0ðð ð ð ñ „_ðð „_ð
 !%Ø 6Ø!&Ø%0ðð ð ð ñ „_ðð „_ð
 !%Ø 6Ø!&Ø%0ðð ð ð ñ „_ðð Ø $Ø 6Ø!&Ø%0ð% ð % ð % ð % ð % ð % ð % ðR !%Ø'+Ø(,ð	5ð 5ð 5ð 5ð 5ð 5ð 5ðn)ð )ð )ð )ð )ð )ð )ð )r   rŽ   c                ó<  — 	 t           j                             t          j        |                      ¦   «         ¦  «        t          j        |¦  «        ¦  «        S # t          $ r Y dS t          $ r Y dS t          $ r!}|j	        t          j
        k    rY d}~dS ‚ d}~ww xY w)a   Return whether ``fh`` still refers to the file now at ``filename``.

    A competing releaser can unlink (and a third party recreate) ``filename``
    in the window between our ``open`` and our lock, which would leave two
    processes each holding a lock on a *different* inode for the same name
    (split-brain). Comparing the handle's inode with the path's inode detects
    that swap. This is a POSIX-only concern: on Windows a locked file cannot be
    unlinked, so no swap is possible. The comparison uses
    `os.path.samestat`, which checks the device as well as the inode, so a
    recycled inode number on another filesystem cannot alias the lock
    file.
    FN)r8   r/   ÚsamestatÚfstatra   ÚstatÚFileNotFoundErrorÚ
ValueErrorr)   rN   ÚEBADF)rÏ   rS   r!   s      r   Ú_fh_matches_pathr:  ¶  s¯   € ðÝŒw×Ò¥¤¨¯ª©¬Ñ 5Ô 5µr´w¸xÑ7HÔ7HÑIÔIÐIøÝð ð ð àˆuˆuÝð ð ð ð
 ˆuˆuÝð ð ð ØŒ;�%œ+Ò%Ð%ð
 �5�5�5�5�5Øøøøøðøøøs*   ‚AA Á
BÁ%	BÁ1	BÁ:BÂBÂBz1weakref.WeakKeyDictionary[TemporaryFileLock, int]Ú_exit_releasesc                 ó  — t          j        ¦   «         } t          t                               ¦   «         ¦  «        D ]Q\  }}|| k    rŒt          j        t          ¦  «        5  |                     ¦   «          ddd¦  «         n# 1 swxY w Y   ŒRdS )a  Release every still-live `TemporaryFileLock` at interpreter exit.

    Registered with `atexit` exactly once, at import time, instead of once
    per constructed lock: registering per instance and never unregistering
    made a long-lived process accumulate one dead callback for every lock
    it ever constructed. Releasing is a no-op for an instance that holds
    nothing, so already-released locks cost nothing here. Errors are
    suppressed, since the interpreter is on its way out and nobody is left
    to handle them.

    Locks owned by another process are skipped. A forked child inherits
    the parent's live locks (and this hook), and releasing them on the
    child's normal exit would unlink the parent's lock files while the
    parent still believes it holds them: the classic daemonize sequence
    of acquire-then-fork lost its lock the moment either side exited.
    Ownership is recorded at construction and re-recorded on every fresh
    acquire, so the process that actually took a lock is the one that
    releases it here.
    N)	r8   Úgetpidro   r;  Úitemsrb   rc   rd   r¬   )Úcurrent_pidrr   Ú	owner_pids      r   Ú_release_locks_at_exitrA  ã  sÂ   € õ( ”y‘{”{€KÝ¥× 4Ò 4Ñ 6Ô 6Ñ7Ô7ð ð ‰ˆˆiØ˜Ò#Ð#ØÝÔ ¥Ñ+Ô+ð 	ð 	Ø�LŠL‰NŒNˆNð	ð 	ð 	ñ 	ô 	ð 	ð 	ð 	ð 	ð 	ð 	øøøð 	ð 	ð 	ð 	øðð s   ÁB Â B	ÂB	c                  óv   ‡ — e Zd ZdZddedefddœd"ˆ fd„Z	 	 	 d#d$d„Zed%d„¦   «         Z	d&d„Z
d'd „Zd'd!„Zˆ xZS )(ÚTemporaryFileLockaŒ  A `Lock` whose lock file only exists while the lock is held.

    Use it when the file is purely a mutex and leaving it behind would be
    litter. `release` unlinks the path, and a single module level
    `atexit` hook does the same for a program that forgets to release
    and still holds the lock when the interpreter shuts down. Garbage
    collection of the lock object is deliberately not a trigger. A
    finalizer that unlinked the path used to destroy locks whose
    filehandle the caller was still using.

    That hook tracks instances through a weak mapping, so it neither
    keeps a lock alive nor grows with the number of locks a process has
    ever constructed. The exit cleanup therefore needs the wrapper to
    still be referenced: a lock collected earlier drops out of the
    mapping and leaves the hook with nothing to do, so a still-locked,
    discarded wrapper leaves its file behind at exit. The OS lock itself
    is released once the filehandle is closed or collected, so the
    leftover is litter rather than a held lock. The hook also only
    releases locks owned by the exiting process itself: a forked child
    inherits the parent's live locks, and releasing them on the child's
    exit would unlink the files of a lock the parent still holds. The
    owning pid is recorded at construction and re-recorded on every
    fresh acquire, so a lock constructed in the parent but acquired
    inside a forked child is cleaned up at that child's exit, while the
    daemonize shape (acquire, fork, child exits) keeps the parent's lock
    intact.

    Warning:
        The exit hook is pid-aware, but a ``with`` block is not: a child
        forked inside ``with lock:`` inherits the block and runs
        ``__exit__`` when it falls out of it, releasing the lock and
        unlinking the file while the parent still believes it holds
        them. The classic daemonize sequence (fork inside the guarded
        block, parent exits or child does the work) must therefore
        either fork outside the ``with`` block or make sure only one of
        the two processes leaves it, for instance by ending the child
        with ``os._exit`` instead of falling through.

    Releasing an instance that does not hold the lock is a no-op. Without
    that rule a stale object, released twice or finalized after a failed
    acquire, would unlink the path out from under whoever holds the lock at
    that moment. Added in 4.0.0 as part of the split-brain fix (#115),
    together with the inode re-check in `acquire`.

    Example:
        >>> import os
        >>> import portalocker
        >>> lock = portalocker.TemporaryFileLock('somefile.lock')
        >>> _ = lock.acquire()
        >>> os.path.isfile('somefile.lock')
        True
        >>> lock.release()
        >>> os.path.isfile('somefile.lock')
        False
        >>> lock.release()

    See Also:
        `PidFileLock`: adds the owning PID to the file.
    ú.lockNTFré   rS   r   r|   r€   r}   r{   r~   r2   r6   rä   rå   r   r%   c          	     óŽ   •— t          ¦   «                              |d|||||¬¦  «         t          j        ¦   «         t          | <   dS )aÉ  Configure the lock and arm the interpreter exit cleanup.

        Args:
            filename: Path of the lock file, ``'.lock'`` by default.
                Anything `str` accepts, including `pathlib.Path`. It is
                created on acquire and removed on release.
            timeout: See `LockBase`. `None` selects `DEFAULT_TIMEOUT`.
                Only an explicit value counts as "a timeout was given"
                for the blocking mode warning documented on `Lock`.
            check_interval: See `LockBase`.
            fail_when_locked: See `LockBase`. Defaults to `True` here,
                unlike `Lock`: a lock file that exists usually means a live
                owner, so failing straight away is the more useful answer.
            flags: Locking flags, see `Lock`.
            raise_on_release_error: Report errors from `release`, the
                unlink included, instead of suppressing and logging
                them. See `Lock`. Accepted here since 4.2.0; strict mode
                used to require setting the attribute after
                construction.

        Note:
            The mode is fixed to ``'w'``, so the file is emptied once the
            lock has been taken.
        r?   )rS   râ   r|   r}   r~   r6   rå   N)rú   r“   r8   r=  r;  ©r�   rS   r|   r}   r~   r6   rå   rû   s          €r   r“   zTemporaryFileLock.__init__?  sT   ø€ õD 	‰Œ×ÒØØØØ)Ø-ØØ#9ð 	ñ 	
ô 	
ð 	
õ   "œy™{œ{��tÑÐÐr   r�   útyping.IO[str]c                óŽ   — | j         du }|                      | | j        |||¦  «        }|rt          j        ¦   «         t
          | <   |S )aG  Acquire the lock, guarding against split-brain path swaps.

        Re-acquiring while already holding the lock is an idempotent no-op
        that returns the held filehandle and ignores the arguments, like
        `RLock`. When a third party unlinked or replaced the lock file in
        the meantime the re-acquire raises
        `~portalocker.exceptions.LockException` instead and leaves the held
        filehandle untouched. See `TemporaryFileLock._acquire_verified` for
        the full contract.

        A fresh acquire also records the calling process as the owner for
        the interpreter-exit cleanup. Construction records it too, but a
        lock constructed before a fork and acquired inside the child
        belongs to the child, and its exit must clean the file up. The
        idempotent re-acquire deliberately leaves the recorded owner
        alone: a forked child re-acquiring an inherited held lock gets
        the shared filehandle back, and reassigning ownership to the
        child would let its exit unlink the file the parent still
        depends on.
        N)rÏ   Ú_acquire_verifiedrS   r8   r=  r;  )r�   r|   r}   r~   Úfreshly_acquiredrÏ   s         r   r˜   zTemporaryFileLock.acquires  sU   € ð4 "&¤¨D ÐØ!×3Ò3ØØŒMØØØñ
ô 
ˆð ð 	/Ý#%¤9¡;¤;�N˜4Ñ Øˆ	r   rr   rê   r$   c                óÄ  — | j         }|�;t          j        dk    r|S t          ||¦  «        r|S t	          j        |›d�¦  «        ‚t          || j        d¦  «        }t          j	        ¦   «         |z   }|}|  
                    ||¦  «        D ]±}	t                               | |||¦  «        }
|
j        r%t          d|t          j	        ¦   «         z
  ¦  «        }ŒKt          j        dk    r|
c S t          |
|¦  «        r|
c S t                               | ¦  «         t          d|t          j	        ¦   «         z
  ¦  «        }Œ²t	          j        t          j        j        |›d�¦  «        ‚)aH	  Acquire ``lock`` and confirm the handle still names ``filename``.

        A competing releaser can unlink (and a third party recreate)
        ``filename`` between our ``open`` and our lock, so two processes
        could each hold a lock on a different inode for the same name.
        After locking we verify the handle still points at the current
        path. No-op on Windows, where a locked file cannot be swapped.

        The contract, in three parts:

        * Already held and still valid: when ``lock`` holds a filehandle
          whose inode still matches ``filename``, the call is an idempotent
          no-op returning that same filehandle. The held lock is never
          released and re-acquired, since the gap between the two is a
          window a competitor can win.
        * Already held but compromised: when the held filehandle no longer
          matches ``filename``, a third party unlinked or replaced the path
          (tmpwatch cleaning ``/tmp`` is enough) and mutual exclusion is
          already lost. The call raises
          `~portalocker.exceptions.LockException` naming the external
          unlink and leaves the held filehandle untouched: it is not closed
          and the lock is not silently swapped to the new inode, because
          only the caller knows whether its pending writes still matter.
        * Fresh acquire: the verify-and-retry loop runs against one shared
          deadline. The first attempt passes the caller's ``timeout``
          through unchanged and every retry is handed only the remaining
          budget, so the total wall time respects the single timeout
          instead of compounding per retry. An iteration that finds a stale
          handle releases it and then either retries or raises. The loop
          never ends on a bare release.

        Shared by ``TemporaryFileLock`` and the ``PidFileLock`` sidecar lock so
        both surfaces get the same guarantee.

        Raises:
            ~portalocker.exceptions.LockException: The lock was already
                held, but ``filename`` was unlinked or replaced externally
                in the meantime.
            ~portalocker.exceptions.AlreadyLocked: A fresh acquire kept
                finding the path replaced until the timeout budget ran out,
                or the underlying `Lock.acquire` gave up on contention.
        NrJ   zw was unlinked or replaced externally while the lock was held: the lock is compromised, the held filehandle is untouchedrœ   z0 kept being replaced while locking (split-brain))rÏ   r8   rK   r:  r   r  r   r|   r�   rž   rª   r   r˜   r\   r    r¬   r  ÚLOCK_FAILED)rr   rS   r|   r}   r~   Úheld_fhr¢   r¦   Úattempt_timeoutrF   rÏ   s              r   rI  z#TemporaryFileLock._acquire_verified™  s�  € ðd *.¬ˆØÐÝŒw˜$ŠˆØ�Ý ¨Ñ2Ô2ð Ø�ÝÔ*Øð +ð +ð +ñô ð õ $ G¨T¬\¸3Ñ?Ô?ˆ	ÝÔ+Ñ-Ô-°	Ñ9ˆð )0ˆà×(Ò(¨°.ÑAÔAð 	ð 	ˆAÝ—’ØØØØ ñ	ô ˆBð Œyð õ #& c¨8µdÔ6GÑ6IÔ6IÑ+IÑ"JÔ"J�ØÝŒw˜$ŠˆØ�	�	�	Ý  HÑ-Ô-ð Ø�	�	�	å�LŠL˜ÑÔÐÝ!ØØ�4Ô,Ñ.Ô.Ñ.ñô ˆOˆOõ Ô&ÝÔ$Ô0ØÐKÐKÐKñ
ô 
ð 	
r   c                ó  — |                       ¦   «         }|€dS t          j        dk    r|                      |¦  «        }n|                      |¦  «        }|€dS | j        r|‚t                               d| j        |¦  «         dS )a½  Release the file lock and remove the temporary file.

        On POSIX the file is unlinked while the lock is *still held*, so a
        competing acquirer cannot grab the freshly created path in the window
        between unlock and unlink (split-brain). On Windows an open/locked
        file cannot be unlinked, so there we unlock and close first, then
        remove with a short retry for AV/scanner share violations.

        Releasing an object that holds nothing is a no-op: a stale object
        (a double release, or a release after a failed acquire) must never
        unlink the path out from under the current holder. The held
        filehandle is claimed atomically before the first OS call, so a
        release that reenters from a signal handler, or runs concurrently
        in another thread, finds the state already claimed and removes
        nothing: the outer release still holds the OS lock at that point,
        and only it unlinks the path, exactly once.

        On POSIX the unlink also only runs when the held filehandle still
        names the path. After a third party unlinked or replaced the lock
        file the path belongs to whoever recreated it, so a compromised
        holder frees its OS lock but leaves the path alone, with a warning
        in the log instead of a deleted competitor lock.

        Raises:
            Exception: An unlink failure other than the file already being
                gone, but only when ``raise_on_release_error`` is set, and
                the lock itself is always released first. By default such
                failures are suppressed and logged at warning level, like
                the unlock and close failures in `Lock.release`.
        NrJ   z0suppressed error while removing lock file %r: %r)	r  r8   rK   Ú_release_ntÚ_release_posixrå   r  r  rS   )r�   rÏ   Úunlink_errors      r   r¬   zTemporaryFileLock.releaseû  s™   € ð> #ŸnšnÑ.Ô.ˆØˆ:ð ˆFåŒ7�dŠ?ˆ?Ø×+Ò+¨BÑ/Ô/ˆLˆLà×.Ò.¨rÑ2Ô2ˆLØÐØˆFØÔ&ð 	ØÐÝ�ŠØ>ØŒMØñ	
ô 	
ð 	
ð 	
ð 	
r   rÏ   rÐ   úException | Nonec                óF  — |                       |¦  «         d}d}t          |dz   ¦  «        D ]t}	 t          j        | j        ¦  «          dS # t
          $ r Y  dS t          $ r&}|}||k     rt          j        d¦  «         Y d}~ŒWd}~wt          $ r}|cY d}~c S d}~ww xY w|S )aí  Unlock and close first, then remove the file with a short retry.

        A locked file cannot be unlinked on Windows, hence the ordering,
        and an AV or indexing scanner can hold the freshly closed file
        open for a moment, hence the retry. Only `PermissionError` is
        transient in that way, so only it is retried, and the retry sleep
        is skipped after the final attempt: sleeping after giving up only
        delays the caller. Any other failure is captured on the first
        attempt, like the POSIX path captures its unlink errors, so the
        flag contract of `release` applies to it instead of the error
        escaping regardless of the flag. Both changed in 4.2.0.

        Args:
            fh: The filehandle claimed by `release`.

        Returns:
            The unlink failure for `release` to report (the last denial
            after the retries, or the first non-retryable error), or
            `None` when the file was removed or was already gone.
        Né   r   gš™™™™™©?)
r  rA   r8   ÚunlinkrS   r7  ÚPermissionErrorr�   rŸ   rd   )r�   rÏ   rR  Úlast_attemptÚattemptr!   s         r   rP  zTemporaryFileLock._release_nt.  sò   € ð* 	× Ò  Ñ$Ô$Ð$Ø)-ˆØˆõ ˜\¨AÑ-Ñ.Ô.ð 	ð 	ˆGðÝ”	˜$œ-Ñ(Ô(Ð(ð �t�tøõ %ð ð ð à�t�t�tÝ"ð %ð %ð %Ø$�Ø˜\Ò)Ð)Ý”J˜tÑ$Ô$Ð$øøøøøøøøøÝð ð ð à��������øøøøðøøøð
 Ðs/   ¯AÁ
BÁ	BÁ"BÂBÂBÂBÂBc                óR  — d}	 t          || j        ¦  «        s!t                               d| j        ¦  «         nt	          j        | j        ¦  «         n$# t          $ r Y nt          $ r}|}Y d}~nd}~ww xY w	 |                      |¦  «         n# t          $ r}|�||‚‚ d}~ww xY w|S )a›  Unlink while the lock is still held, then unlock and close.

        The ordering closes the split-brain window: a competing acquirer
        cannot grab the path between unlock and unlink when the unlink
        comes first. The unlock must run even when the unlink fails (e.g.
        a `PermissionError` from a read-only directory), otherwise the
        error would leave the lock held forever.

        Args:
            fh: The filehandle claimed by `release`. It still carries the
                OS lock while the unlink runs.

        Returns:
            The unlink failure for the caller to report, or `None` when
            the file was removed or was already gone.

        Raises:
            Exception: Whatever `Lock._release_claimed_fh` raises, which
                it only does with ``raise_on_release_error`` set. A failed
                unlink is kept visible by chaining it onto that error.
        NzUnot unlinking %r: it no longer belongs to this lock (unlinked or replaced externally))	r:  rS   r  r  r8   rV  r7  rd   r  )r�   rÏ   rR  r!   rØ   s        r   rQ  z TemporaryFileLock._release_posixY  s÷   € ð0 *.ˆð	!Ý# B¨¬Ñ6Ô6ð 
)õ —’ð=à”Mñô ð ð õ ”	˜$œ-Ñ(Ô(Ð(øøÝ ð 	ð 	ð 	àˆDÝð 	!ð 	!ð 	!Ø ˆLˆLˆLˆLˆLˆLøøøøð	!øøøð	Ø×$Ò$ RÑ(Ô(Ð(Ð(øÝð 	ð 	ð 	ØÐ'Ø#¨Ð5Øøøøøð	øøøð Ðs6   „AA Á
A5Á 	A5Á)A0Á0A5Á9B Â
B$ÂBÂB$©rS   r   r|   r€   r}   r{   r~   r2   r6   rä   rå   r2   r   r%   r½   ©r|   r€   r}   r€   r~   r�   r   rG  )rr   rê   rS   r$   r|   r€   r}   r€   r~   r�   r   rG  r¾   )rÏ   rÐ   r   rS  )rÀ   rÁ   rÂ   rÃ   r‹   r#  r“   r˜   ÚstaticmethodrI  r¬   rP  rQ  r$  r%  s   @r   rC  rC    sö   ø€ € € € € ð:ð :ð| %Ø $Ø 6Ø!%Ø%0ð2+ð (-ð2+ð 2+ð 2+ð 2+ð 2+ð 2+ð 2+ð 2+ðl !%Ø'+Ø(,ð	$ð $ð $ð $ð $ðL ð_
ð _
ð _
ñ „\ð_
ðB1
ð 1
ð 1
ð 1
ðf)ð )ð )ð )ðV0ð 0ð 0ð 0ð 0ð 0ð 0ð 0r   rC  c                  ó¢   ‡ — e Zd ZdZddedefddœd1ˆ fd„Zd2d„Zd3d„Z	 	 	 d4d5d„Z	d6d„Z
d7d „Zd8d"„Zd6d#„Zd9ˆ fd*„Zd2d+„Zd:d.„Zd:d/„Zd;d0„Zˆ xZS )<ÚPidFileLockaÚ  
    A lock that writes the current process PID to the file and can read
    the PID of the process that currently holds the lock.

    When used as a context manager:

    - Returns None if we successfully acquired the lock
    - Returns the PID (int) if another process holds the lock
    - Raises AlreadyLocked if another process holds the lock but its PID
      cannot be read, so a missing or corrupt PID file can never make a
      bystander believe it is the holder

    The classic "only one instance of this daemon" lock. Two files are
    involved: `filename` holds the readable PID, and a sidecar
    ``<filename>.lock`` next to it carries the actual operating system
    lock. The split exists because Windows locking is mandatory, so a lock
    taken on the PID file itself would stop anyone from reading it.

    Warning:
        A ``with lock:`` block does not survive a fork inside it: the
        child inherits the block and runs ``__exit__`` when it falls out
        of it, releasing the lock and unlinking the PID and sidecar
        files while the parent still believes it holds them. The classic
        daemonize sequence must fork outside the ``with`` block, or end
        the child with ``os._exit`` so the inherited block is never
        left. The interpreter-exit cleanup itself is pid-aware and only
        runs in the process that acquired the lock.

    Example:
        >>> import os
        >>> import portalocker
        >>> with portalocker.PidFileLock('somefile.pid') as holder_pid:
        ...     holder_pid is None  # None means we are the holder
        True

    See Also:
        `PidFileLock.fail_closed`: for the common case where a contended
        lock should abort the block instead of running it.
    z.pidNTFré   rS   r   r|   r€   r}   r{   r~   r2   r6   rä   rå   r   r%   c               ó�   •— t          ¦   «                              ||||||¬¦  «         d| _        | j        › d�| _        d| _        dS )a?  Configure the lock and derive the sidecar lock file name.

        Args:
            filename: Path of the PID file, ``'.pid'`` by default.
                Anything `str` accepts, including `pathlib.Path`. The
                sidecar lock file is this path with ``.lock`` appended.
            timeout: See `LockBase`. `None` selects `DEFAULT_TIMEOUT`.
                Only has an effect together with
                ``fail_when_locked=False``.
            check_interval: See `LockBase`.
            fail_when_locked: See `LockBase`. Defaults to `True`, as for
                `TemporaryFileLock`.
            flags: Locking flags applied to the sidecar file, see `Lock`.
            raise_on_release_error: Report errors from `release`, the
                PID file and sidecar unlinks included, instead of
                suppressing and logging them. See `Lock`. Accepted here
                since 4.2.0; strict mode used to require setting the
                attribute after construction.

        Note:
            Neither file is created here; that happens on acquire.
        )rS   r|   r}   r~   r6   rå   FrD  N)rú   r“   Ú_acquired_lockrS   Ú	_lockfileÚ_inner_lockrF  s          €r   r“   zPidFileLock.__init__µ  se   ø€ õ@ 	‰Œ×ÒØØØ)Ø-ØØ#9ð 	ñ 	
ô 	
ð 	
ð $ˆÔð !œMÐ0Ð0Ð0ˆŒØ(,ˆÔÐÐr   c                ó8  — | j         › dt          j        ¦   «         › d�}t          |dd¬¦  «        }	 	 |                     t          t          j        ¦   «         ¦  «        ¦  «         |                     ¦   «          	 t          j        |                     ¦   «         ¦  «         n7# t          $ r*}|j
        t          j        t          j        fvr‚ Y d}~nd}~ww xY wn># t          $ r1}	 |                     ¦   «          n# t          $ r}||‚d}~ww xY w‚ d}~ww xY w|                     ¦   «          t          j        || j         ¦  «         dS # t           $ rG t#          j        t          ¦  «        5  t          j        |¦  «         ddd¦  «         n# 1 swxY w Y   ‚ w xY w)ai  Atomically publish the current PID, preserving close errors.

        The PID is written to a temporary file next to `filename` and then
        moved over it with `os.replace`, so a concurrent `read_pid` sees
        either the previous holder's complete PID or ours, never a
        truncated or empty file. The old truncate-in-place approach
        exposed both windows between taking the sidecar lock and finishing
        the write. The temporary file is removed again on any failure, and
        a close failure after a write failure is chained onto the original
        error instead of replacing it.
        ú.r=   r?   Úascii)ÚencodingN)rS   r8   r=  r9   Úwriter$   r`   r^   ra   r)   rN   ÚEINVALÚENOTSUPrd   r_   r÷   r"   rb   rc   rV  )r�   Ú	temp_pathÚpid_filer!   Úclose_errors        r   Ú
_write_pidzPidFileLock._write_pidä  s	  € ð !œMÐ=Ð=­B¬I©K¬KÐ=Ð=Ð=ˆ	Ý"&ØØØð#
ñ #
ô #
ˆð
	ðØ—’�s¥2¤9¡;¤;Ñ/Ô/Ñ0Ô0Ð0Ø—’Ñ Ô Ð ðÝ”H˜XŸ_š_Ñ.Ô.Ñ/Ô/Ð/Ð/øÝð ð ð Ø”{­5¬<½¼Ð*GÐGÐGØð HÐGÐGÐGÐGøøøøðøøøøøõ ð ð ð ð1Ø—N’NÑ$Ô$Ð$Ð$øÝ ð 1ð 1ð 1Ø [Ð0øøøøð1øøøàøøøøðøøøð �NŠNÑÔÐÝŒJ�y $¤-Ñ0Ô0Ð0Ð0Ð0øÝð 	ð 	ð 	ÝÔ$¥WÑ-Ô-ð %ð %Ý”	˜)Ñ$Ô$Ð$ð%ð %ð %ñ %ô %ð %ð %ð %ð %ð %ð %øøøð %ð %ð %ð %àð	øøøs–   ³AC Á;&B" Â!C Â"
CÂ, CÃC ÃCÃC ÃE Ã
DÃ%C:Ã9DÃ:
DÄDÄDÄDÄDÄ1E Å#FÅ+FÆ FÆF	ÆFÆF	ÆFÚ
inner_lockr   rS  c                ó€  — d}	 |                      ¦   «          n# t          $ r}|}Y d}~nd}~ww xY w|j        }|�M	 |                     ¦   «          n## t          $ r}|€|}n||_        Y d}~nd}~ww xY wd|_        n# d|_        w xY w| j        5  | j        |u rd| _        d| _        ddd¦  «         n# 1 swxY w Y   |S )a  Release a failed sidecar and return any secondary cleanup error.

        ``Lock.release`` currently clears its handle without raising. Keep the
        fallback close so rollback remains safe if that contract changes or a
        custom/monkeypatched release exits early.
        NF)r¬   rd   rÏ   r_   rÜ   r   rc  ra  )r�   ro  Úcleanup_errorr!   rÏ   rm  s         r   Ú_rollback_failed_acquirez$PidFileLock._rollback_failed_acquire	  sP  € ð +/ˆð	"Ø×ÒÑ Ô Ð Ð øÝð 	"ð 	"ð 	"Ø!ˆMˆMˆMˆMˆMˆMøøøøð	"øøøð )œmˆØˆ>ð%Ø—’‘
”
�
�
øÝð :ð :ð :Ø Ð(Ø$/�M�Mà.9�MÔ+øøøøøøøøøð	:øøøð !%�
”�ø �
”Ð$Ð$Ð$Ð$ð Ôð 	,ð 	,ØÔ :Ð-Ð-Ø#'�Ô Ø&+�Ô#ð	,ð 	,ð 	,ñ 	,ô 	,ð 	,ð 	,ð 	,ð 	,ð 	,ð 	,øøøð 	,ð 	,ð 	,ð 	,ð ÐsQ   „ ™
/£*ª/¼A ÁA< Á
A1ÁA,Á'A< Á,A1Á1A< Á<	BÂB3Â3B7Â:B7r�   rG  c                ó`  — | j         }|�%|j        �|                      || j        |||¦  «        S t	          || j        ¦  «        }t	          || j        ¦  «        }t	          || j        ¦  «        }t          | j        d|du r|nd|du r|nddt          ¬¦  «        }	 |                      || j        |||¦  «        }	n$# t          $ r |                      |¦  «         ‚ w xY w	 |                      ¦   «          | j        5  || _         d| _        ddd¦  «         n# 1 swxY w Y   t          j        ¦   «         t"          | <   ns# t$          $ rG}
|                      |¦  «        }|�*|
j        }|�|}|j        �|j        }|j        ­||_        |
|‚‚ d}
~
wt          $ r |                      |¦  «         ‚ w xY w|	S )a¶
  Lock the sidecar file and publish the current PID.

        Calling this on an instance that already holds the lock first
        verifies that the sidecar lock file still names the held lock,
        then returns the held sidecar filehandle as-is: the arguments are
        ignored and neither the sidecar lock nor the PID file is touched,
        so re-acquiring while held is cheap and can never drop the lock,
        not even for an instant. When a third party unlinked or replaced
        the sidecar in the meantime the re-acquire raises
        `~portalocker.exceptions.LockException` and leaves the held
        filehandle untouched, exactly like `TemporaryFileLock.acquire`.

        Args:
            timeout: Overrides `timeout` for this call. See `LockBase`: the
                argument wins when it is not `None`, otherwise the instance
                attribute applies. Only used when `fail_when_locked`
                resolves to `False`.
            check_interval: Overrides `check_interval` for this call, under
                the same rules.
            fail_when_locked: Overrides `fail_when_locked` for this call.

        Returns:
            The filehandle of the sidecar lock file. It exists to satisfy
            the `Lock` typing contract; read the PID through
            `PidFileLock.read_pid` instead of from this handle.

        Raises:
            ~portalocker.exceptions.AlreadyLocked: Somebody else holds the
                lock, whether the contention surfaced through
                `fail_when_locked` or through an expired timeout.
                Contention is the only thing this type means here.
            ~portalocker.exceptions.LockException: A terminal, retry-proof
                failure. Either the sidecar backend cannot lock at all
                (``ENOLCK``, an unsupported filesystem), or the instance
                already holds the lock but the sidecar lock file was
                unlinked or replaced externally in the meantime. Neither
                is contention, so neither is dressed up as
                `AlreadyLocked`. Changed in 4.2.0: plain lock exceptions
                from the sidecar used to be normalized to
                `AlreadyLocked`, which told callers to retry failures
                retrying cannot fix.
            Exception: Anything else the sidecar `Lock` raises, such as an
                `OSError` from opening it, propagates unchanged. So does a
                failure to publish the PID, for instance because the
                filesystem is full; the sidecar lock is rolled back first,
                so that failure never leaves the lock held, and a rollback
                error of its own is chained onto the original.
        Nrè   Fr   rœ   T)râ   r|   r}   r~   r6   )rc  rÏ   rI  rb  r   r|   r}   r~   r   r#  r"   rr  rn  r   ra  r8   r=  r;  rd   rÜ   )r�   r|   r}   r~   Ú	held_lockÚtimeout_Úcheck_interval_Úfail_when_locked_ro  Ú
sidecar_fhr!   rq  Úpublication_causeÚ
cause_tails                 r   r˜   zPidFileLock.acquire4	  sz  € ðl "&Ô!1ˆ	ØÐ  Y¤\Ð%=ð ×)Ò)ØØ”ØØØ ñô ð õ # 7¨D¬LÑ9Ô9ˆÝ!)¨.¸$Ô:MÑ!NÔ!NˆÝ"*ØØÔ!ñ#
ô #
Ðõ ØŒNØØ 1°UÐ :Ð :�H�HÀà#4¸Ð#=Ð#=��À3à!Ýð	
ñ 	
ô 	
ˆ
ð&	ð ×/Ò/ØØ”ØØØ!ñô ˆJˆJøõ ð 	ð 	ð 	ð ×)Ò)¨*Ñ5Ô5Ð5Øð!	øøøð$ 	Ø�OŠOÑÔÐØÔ!ð +ð +Ø#-�Ô Ø&*�Ô#ð+ð +ð +ñ +ô +ð +ð +ð +ð +ð +ð +øøøð +ð +ð +ð +õ $&¤9¡;¤;�N˜4Ñ Ð øÝð 	ð 	ð 	Ø.2×.KÒ.KØñ/ô /ˆMð Ð(Ø:?¼/Ð!Ø$Ð0Ø0=�JØ$Ô.Ð:Ø%/Ô%9˜
ð %Ô.Ð:à+<�JÔ(Ø Ð.ØøøøøÝð 
	ð 
	ð 
	ð ×)Ò)¨*Ñ5Ô5Ð5Øð
	øøøð* ÐsI   ÂB9 Â9!CÃD; Ã9DÄD; ÄDÄD; ÄDÄD; Ä;
F+ÅAFÆ$F+ú
int | Nonec                ó4   — |                       ¦   «         \  }}|S )aæ  Read the PID from the lock file, if it exists and is readable.

        Returns:
            The PID recorded in the file, or `None` when the file is
            missing, unreadable, or does not contain a plain positive
            decimal number. Validation is strict on purpose: only ASCII
            digits with a value greater than zero pass, so signs,
            underscores, non-ASCII digits, zero and negative values are
            all treated as unreadable. `int` happily parses ``-1`` or
            ``1_000``, and the obvious consumer feeds the result straight
            to ``os.kill``, where ``-1`` signals every process the user
            owns. The file is read as bytes and validated as ASCII, so
            content the locale encoding cannot decode also comes back as
            `None` instead of raising ``UnicodeDecodeError`` as it did
            before 4.2.0. Digit runs longer than 20 characters are junk
            by the same rule (no real PID needs them), and rejecting
            them before the `int` call keeps CPython's 4300-digit
            conversion limit from escaping as a ``ValueError``. Note
            that a returned PID only says who *wrote* the file, the
            process may since have died.
        )Ú	_read_pid)r�   ÚpidÚ_errors      r   Úread_pidzPidFileLock.read_pidæ	  s   € ð, —n’nÑ&Ô&‰ˆˆVØˆ
r   ú!tuple[int | None, OSError | None]c                óÄ  — 	 t          | j        d¦  «        5 }|                     ¦   «         }ddd¦  «         n# 1 swxY w Y   n# t          $ r}d|fcY d}~S d}~ww xY w|                     dd¬¦  «                             ¦   «         }|                     ¦   «         r|                     ¦   «         sdS t          |¦  «        dk    rdS t          |¦  «        }|dk    r|dfS dS )	aå  Read and validate the PID, also reporting the read error.

        The error half exists for `__enter__`: when a contended entry has
        to refuse fail-open because the holder PID is unreadable, the
        raised `AlreadyLocked` chains from the actual `OSError` instead of
        swallowing it, so the traceback names the real problem (a missing
        file, a permission error). `read_pid` keeps its simpler public
        contract and drops the error half.

        Returns:
            A ``(pid, error)`` pair. ``pid`` follows the `read_pid` rules
            and ``error`` is the `OSError` that made the file unreadable,
            or `None` when the file was readable (even if its content did
            not validate).
        ÚrbNrf  r÷   )Úerrors)NNé   r   )
r9   rS   Úreadr)   ÚdecodeÚstripÚisasciiÚisdigitr  r-   )r�   ÚfÚrawr!   Úcontentr~  s         r   r}  zPidFileLock._read_pidÿ	  s7  € ð 	Ý�d”m TÑ*Ô*ð &¨aØŸVšV™XœX�ð&ð &ð &ñ &ô &ð &ð &ð &ð &ð &ð &øøøð &ð &ð &ð &øøåð 	ð 	ð 	Ø˜�;ÐÐÐÐÐÐøøøøð	øøøð —z’z '°)�zÑ<Ô<×BÒBÑDÔDˆØ—’Ñ!Ô!ð 	 g§o¢oÑ&7Ô&7ð 	Ø�:Ýˆw‰<Œ<˜"ÒÐð
 �:Ý�w‘<”<ˆØ�Š7ˆ7Ø˜�9ÐØˆzs9   ‚A —8¬A ¸<¼A ¿<Á A Á
AÁAÁAÁAú'contextlib.AbstractContextManager[None]c                ó    — t          | ¦  «        S )aù  Return a context that enters only after acquiring this lock.

        The fail-closed counterpart of using the lock directly as a context
        manager: contention aborts before the block runs instead of running
        it with a PID in hand.

        Returns:
            A context manager that binds `None` and guarantees the block
            only runs while this process owns the lock.

        Raises:
            ~portalocker.exceptions.AlreadyLocked: On entry, when another
                process holds the lock. Its ``holder_pid`` attribute
                carries the competing PID when it could be read.
            Exception: On entry, anything else `PidFileLock.acquire`
                raises, unchanged: a terminal
                `~portalocker.exceptions.LockException` from a backend
                that cannot lock at all, an `OSError` from opening the
                sidecar, or a failed PID publication; the same
                pass-through class documented on `PidFileLock.__enter__`.

        Example:
            >>> import portalocker
            >>> lock = portalocker.PidFileLock('somefile.pid')
            >>> with lock.fail_closed():
            ...     print('exclusive work happens here')
            exclusive work happens here
        )Ú_PidFileLockFailClosedContextr–   s    r   Úfail_closedzPidFileLock.fail_closed)
  s   € õ: -¨TÑ2Ô2Ð2r   c                óÒ   — 	 |                       ¦   «          nP# t          j        $ r>}|                      ¦   «         \  }}|€t          j        d¦  «        |�|n|‚|cY d}~S d}~ww xY wdS )aú  Acquire the lock, reporting the competing PID on failure.

        Deliberately breaks the `Lock.__enter__` contract: instead of
        returning a filehandle it returns who is in the way, and contention
        is *not* an error here. The body of the ``with`` block therefore
        runs either way and has to check the value it was given.

        Returns:
            `None` when the lock was acquired, or the PID of the process
            holding it.

        Raises:
            ~portalocker.exceptions.AlreadyLocked: The lock is held by
                another process *and* that holder's PID cannot be read
                (the PID file is missing, unreadable or invalid).
                Returning `None` in that case would falsely report this
                process as the holder and run the block without mutual
                exclusion, so an unreadable holder fails closed.
            Exception: Anything `acquire` raises other than
                `AlreadyLocked`. Readable contention is turned into a
                return value.

        Example:
            >>> import portalocker
            >>> lock = portalocker.PidFileLock('somefile.pid')
            >>> with lock as holder_pid:
            ...     if holder_pid is None:
            ...         print('acquired')
            ...     else:
            ...         print(f'held by {holder_pid}')
            acquired

        See Also:
            `PidFileLock.fail_closed`: refuses to enter the block at all
            when the lock is held.
        Nzdthe lock is held but the holder PID could not be read, refusing to report this process as the holder)r˜   r   r  r}  )r�   r  r   Ú
read_errors       r   r¯   zPidFileLock.__enter__J
  s�   € ðJ	Ø�LŠL‰NŒNˆNˆNøÝÔ'ð 	ð 	ð 	à%)§^¢^Ñ%5Ô%5Ñ"ˆJ˜
ØÐ!õ !Ô.ðJñô ð '1Ð&<˜
˜
À#ðGð ÐÐÐÐÐÐøøøøð!	øøøð$ ˆts   ‚ —A$¦3AÁA$ÁA$r°   r±   r²   r³   r´   r   c                ó\   •— | j         sdS t          ¦   «                              |||¦  «        S )aö  Release the lock, but only if this instance actually took it.

        `PidFileLock.__enter__` also enters the block when somebody else
        holds the lock, and in that case there is nothing to release; the
        PID and sidecar files belong to the other holder and must be left
        alone. When this instance did take the lock, the release is routed
        through `Lock.__exit__`, so its guarantees apply here unchanged: a
        release failure never replaces the exception leaving the block (it
        is chained as its ``__context__`` with a note attached), and with
        a clean block a release failure only surfaces when
        ``raise_on_release_error`` is set.

        Args:
            exc_type: Type of the exception leaving the block, if any.
            exc_value: The exception instance, if any.
            traceback: The traceback of that exception, if any.

        Returns:
            `None`; exceptions from the block keep propagating.

        Raises:
            Exception: Whatever `release` raises, but only when the block
                itself ended without an exception, exactly as documented
                on `Lock.__exit__`. With the default
                ``raise_on_release_error=False`` that is nothing at all.
        N)ra  rú   r¸   )r�   r°   r²   r´   rû   s       €r   r¸   zPidFileLock.__exit__…
  s2   ø€ ð@ Ô"ð 	Ø�4Ý‰wŒw×Ò ¨)°YÑ?Ô?Ð?r   c                ó¢  — | j         5  | j        dc}| _        d| _        ddd¦  «         n# 1 swxY w Y   |€dS |                     ¦   «         }|€dS | j        |_        t
          j        dk    r|                      ||¦  «        }n|                      ||¦  «        }|€dS | j        r|‚t           
                    d| j        | j        |¦  «         dS )aÒ	  Release the sidecar lock and remove the PID + sidecar files.

        On POSIX both the PID file and the sidecar lock file are unlinked while
        the sidecar lock is *still held*, so a competing acquirer cannot grab
        the sidecar path in the window between unlock and unlink (split-brain).
        The PID file itself carries no OS lock (the sidecar holds it), but it
        is removed in the same held window for consistency. On Windows the
        locked sidecar cannot be unlinked, so only the sidecar removal
        happens after its release. The PID file is still unlinked *before*
        the sidecar lock is dropped, since removing it afterwards could
        delete the PID a fast successor has already published.

        Releasing an object that does not hold the sidecar is a no-op: a
        stale object (a double release, or a release after a failed
        acquire) must never unlink the PID or sidecar files out from under
        the current holder. The same applies to an object whose sidecar
        `Lock` no longer holds a filehandle, for instance after an acquire
        interrupted while waiting: the files belong to whoever holds the
        sidecar lock now. Both the sidecar lock and its filehandle are
        claimed atomically before the first OS call, so a release that
        reenters from a signal handler, or runs concurrently in another
        thread, finds the state already claimed and removes nothing: the
        outer release still holds the sidecar lock at that point, and only
        it unlinks the two files, exactly once.

        On POSIX the unlinks also only run when the held sidecar handle
        still names the sidecar path. After a third party unlinked or
        replaced the files a competitor may own them already, so a
        compromised holder frees its OS lock but leaves both paths alone,
        with a warning in the log instead of a deleted competitor lock.

        Raises:
            Exception: An unlink failure other than a file already being
                gone, but only when ``raise_on_release_error`` is set,
                and the sidecar lock itself is always released first. By
                default such failures are suppressed and logged at
                warning level, matching `TemporaryFileLock.release`.
                Before 4.2.0 the flag was ignored here: the POSIX branch
                leaked unlink errors regardless of it and the Windows
                branch swallowed them regardless of it.
        NFrJ   z8suppressed error while removing lock files %r and %r: %r)r   rc  ra  r  rå   r8   rK   Ú_release_files_ntÚ_release_files_posixr  r  rS   rb  )r�   ro  rx  rR  s       r   r¬   zPidFileLock.release©
  s:  € ðV Ôð 	(ð 	(Ø+/Ô+;¸TÐ(ˆJ˜Ô(Ø"'ˆDÔð	(ð 	(ð 	(ñ 	(ô 	(ð 	(ð 	(ð 	(ð 	(ð 	(ð 	(øøøð 	(ð 	(ð 	(ð 	(ð Ðð ˆFØ&0×&:Ò&:Ñ&<Ô&<ˆ
ØÐð
 ˆFð -1Ô,Gˆ
Ô)åŒ7�dŠ?ˆ?Ø×1Ò1°*¸jÑIÔIˆLˆLà×4Ò4°ZÀÑLÔLˆLØÐØˆFØÔ&ð 	ØÐÝ�ŠØFØŒMØŒNØñ		
ô 	
ð 	
ð 	
ð 	
s   ˆ+«/²/rx  rÐ   c                ó¬  — d}	 t          j        | j        ¦  «         n$# t          $ r Y nt          $ r}|}Y d}~nd}~ww xY w	 |                     |¦  «         n# t          $ r}|�||‚‚ d}~ww xY w	 t          j        | j        ¦  «         nH# t          $ r Y n<t          $ r0}|€|}n!t                               d| j        |¦  «         Y d}~nd}~ww xY w|S )aw  Tear down the Windows way: PID file, sidecar unlock, sidecar.

        The PID file is unlinked first, while the sidecar lock is still
        held: removing it after the release could delete the PID a fast
        successor has already published. The locked sidecar file itself
        cannot be unlinked on Windows, so its removal has to follow its
        release.

        Args:
            inner_lock: The claimed sidecar `Lock`.
            sidecar_fh: Its claimed filehandle, still carrying the OS
                lock.

        Returns:
            The first unlink failure for `release` to report, or `None`.

        Raises:
            Exception: Whatever `Lock._release_claimed_fh` raises, which
                it only does with ``raise_on_release_error`` set. A failed
                PID file unlink is kept visible by chaining it onto that
                error.
        Nú1suppressed additional error while removing %r: %r)	r8   rV  rS   r7  rd   r  rb  r  r  )r�   ro  rx  rR  r!   rØ   s         r   r–  zPidFileLock._release_files_ntö
  s?  € ð6 *.ˆð	!ÝŒI�d”mÑ$Ô$Ð$Ð$øÝ ð 	ð 	ð 	ØˆDÝð 	!ð 	!ð 	!Ø ˆLˆLˆLˆLˆLˆLøøøøð	!øøøð	Ø×*Ò*¨:Ñ6Ô6Ð6Ð6øÝð 	ð 	ð 	ØÐ'Ø#¨Ð5Øøøøøð	øøøð	ÝŒI�d”nÑ%Ô%Ð%Ð%øÝ ð 	ð 	ð 	ØˆDÝð 	ð 	ð 	ØÐ#Ø$��å—’ØGØ”NØñô ð øøøøøøøøøð		øøøð ÐsJ   „ ž
?ª	?³:º?ÁA Á
A.Á#A)Á)A.Á2B Â
CÂ	CÂ!&CÃCc                óp  — d}	 t          || j        ¦  «        r|                      ¦   «         }n&t                               d| j        | j        ¦  «         	 |                     |¦  «         nK# t          $ r}|�||‚‚ d}~ww xY w# 	 |                     |¦  «         w # t          $ r}|�||‚‚ d}~ww xY wxY w|S )aÅ  Unlink both files while the sidecar lock is still held.

        The ordering closes the split-brain window, exactly like
        `TemporaryFileLock._release_posix`, and the unlinks only run when
        the held sidecar handle still names the sidecar path. The sidecar
        unlock must run even when an unlink fails (e.g. a
        `PermissionError` from a read-only directory), otherwise the
        error would leave the sidecar held forever.

        Args:
            inner_lock: The claimed sidecar `Lock`.
            sidecar_fh: Its claimed filehandle, still carrying the OS
                lock while the unlinks run.

        Returns:
            The first unlink failure for `release` to report, or `None`.

        Raises:
            Exception: Whatever `Lock._release_claimed_fh` raises, which
                it only does with ``raise_on_release_error`` set. A failed
                unlink is kept visible by chaining it onto that error.
        Nzonot unlinking %r and %r: the sidecar lock file no longer belongs to this lock (unlinked or replaced externally))r:  rb  Ú_unlink_owned_filesr  r  rS   r  rd   )r�   ro  rx  rR  rØ   s        r   r—  z PidFileLock._release_files_posix-  s   € ð6 *.ˆð	Ý 
¨D¬NÑ;Ô;ð 	Ø#×7Ò7Ñ9Ô9��å—’ð+ð ”MØ”Nñô ð ðØ×.Ò.¨zÑ:Ô:Ð:Ð:øÝð ð ð ØÐ+Ø'¨\Ð9ØøøøøðøøøøðØ×.Ò.¨zÑ:Ô:Ð:Ð:øÝð ð ð ØÐ+Ø'¨\Ð9Øøøøøðøøøøøøð ÐsH   „AB ÁA+ Á+
B Á5A;Á;B ÂB3ÂBÂB3Â
B0Â%B+Â+B0Â0B3c                óÜ   — d}| j         | j        fD ]Z}	 t          j        |¦  «         Œ# t          $ r Y Œ$t
          $ r+}|€|}nt                               d||¦  «         Y d}~ŒSd}~ww xY w|S )a‚  Unlink the PID file and the sidecar, reporting the first error.

        A file that is already gone is fine; any other failure on the
        first file must not stop the second removal, so the first error
        is captured and later ones are logged.

        Returns:
            The first unlink failure, or `None` when both files were
            removed or already gone.
        Nr™  )rS   rb  r8   rV  r7  rd   r  r  )r�   rR  r/   r!   s       r   r›  zPidFileLock._unlink_owned_files]  s¤   € ð *.ˆØ”] D¤NÐ3ð 	ð 	ˆDðÝ”	˜$‘”��øÝ$ð ð ð Ø�Ýð ð ð ØÐ'Ø#(�L�Lå—N’NØKØØñô ð øøøøøøøøøð	øøøð Ðs   ”)©
A)µ	A)¾!A$Á$A)r[  r¾   )ro  r   r   rS  r½   r\  )r   r{  )r   r�  )r   rŽ  r¿   )ro  r   rx  rÐ   r   rS  )r   rS  )rÀ   rÁ   rÂ   rÃ   r‹   r#  r“   rn  rr  r˜   r€  r}  r‘  r¯   r¸   r¬   r–  r—  r›  r$  r%  s   @r   r_  r_  Œ  s‘  ø€ € € € € ð&ð &ðT $Ø $Ø 6Ø!%Ø%0ð--ð (-ð--ð --ð --ð --ð --ð --ð --ð --ð^&ð &ð &ð &ðP&ð &ð &ð &ðT !%Ø'+Ø(,ð	pð pð pð pð pðdð ð ð ð2(ð (ð (ð (ðT3ð 3ð 3ð 3ðB9ð 9ð 9ð 9ðv"@ð "@ð "@ð "@ð "@ð "@ðHK
ð K
ð K
ð K
ðZ5ð 5ð 5ð 5ðn.ð .ð .ð .ð`ð ð ð ð ð ð ð r   r_  c                  ó*   — e Zd ZdZdd„Zdd„Zdd„ZdS )r�  aÖ  Fail-closed context adapter for :class:`PidFileLock`.

    `PidFileLock` on purpose breaks the `Lock.__enter__` contract: entering
    it succeeds whether or not the lock was acquired, because reporting
    *who* holds a pidfile is often the whole point. The price is that a
    caller who forgets to inspect the value silently runs the guarded body
    without holding anything, which is exactly the mutual exclusion bug the
    lock was supposed to prevent.

    This adapter buys the guarantee back for callers that only care about
    ownership: the block runs if and only if this process holds the lock,
    and contention raises `AlreadyLocked` before the body is entered, with
    the competing PID attached to the exception rather than returned. That
    keeps the fail-open behaviour available for the callers that want it,
    while the fail-closed one is a method call away.

    Obtained through `PidFileLock.fail_closed`; not meant to be
    instantiated directly.
    rr   r_  r   r%   c                ó   — || _         dS )zÁWrap the lock this context will acquire.

        Args:
            lock: The `PidFileLock` to guard. Only referenced; nothing is
                acquired until the context is entered.
        N)Ú_lock©r�   rr   s     r   r“   z&_PidFileLockFailClosedContext.__init__‘  s   € ð #'ˆŒ
ˆ
ˆ
r   c                ó¦   — 	 | j                              ¦   «          dS # t          j        $ r$}| j                              ¦   «         |_        ‚ d}~ww xY w)ag  Acquire the lock, or refuse to enter the block.

        Returns:
            `None`. There is nothing useful to bind: reaching the body is
            itself the confirmation that this process holds the lock.

        Raises:
            ~portalocker.exceptions.AlreadyLocked: Another process holds
                the lock. The ``holder_pid`` attribute is filled in with
                the competing PID first, or with `None` when the PID file
                could not be read.
            Exception: Anything else `PidFileLock.acquire` raises passes
                through untouched: a terminal
                `~portalocker.exceptions.LockException` from a backend
                that cannot lock at all, an `OSError` from opening the
                sidecar file, or a failure to publish the PID, with the
                rollback error chained onto it.
        N)rŸ  r˜   r   r  r€  r   )r�   r  s     r   r¯   z'_PidFileLockFailClosedContext.__enter__š  s[   € ð&	ØŒJ×ÒÑ Ô Ð Ð Ð øÝÔ'ð 	ð 	ð 	Ø!œZ×0Ò0Ñ2Ô2ˆCŒNØøøøøð	øøøs   ‚ �A¬AÁAr°   r±   r²   r³   r´   r   r�   c                ó:   — | j                              |||¦  «        S )a_  Release the lock by delegating to the wrapped lock.

        Args:
            exc_type: Type of the exception leaving the block, if any.
            exc_value: The exception instance, if any.
            traceback: The traceback of that exception, if any.

        Returns:
            Whatever `PidFileLock.__exit__` returns, which is `None`, so
            exceptions from the block keep propagating.

        Note:
            Only reached when `__enter__` succeeded, so the lock is always
            held here; the ownership check inside `PidFileLock.__exit__` is
            belt and braces.
        )rŸ  r¸   r·   s       r   r¸   z&_PidFileLockFailClosedContext.__exit__³  s   € ð, Œz×"Ò" 8¨Y¸	ÑBÔBÐBr   N)rr   r_  r   r%   r¾   r¿   )rÀ   rÁ   rÂ   rÃ   r“   r¯   r¸   r   r   r   r�  r�  z  s`   € € € € € ðð ð('ð 'ð 'ð 'ðð ð ð ð2Cð Cð Cð Cð Cð Cr   r�  c                  ó�   ‡ — e Zd ZU dZded<   dd ej        ¦   «         eedfd"ˆ fd„Z	d#d„Z
d#d„Zd$d„Z	 	 	 d%d&d„Zd'd „Zd(d!„Zˆ xZS ))ÚBoundedSemaphoreaó	  
    Bounded semaphore to prevent too many parallel processes from running.

    A slot is a lock file: `maximum` of them are generated from
    `filename_pattern`, and acquiring means locking whichever one is still
    free. Releasing does not delete the files, it only unlocks them.

    One instance holds at most one slot, atomically: threads sharing an
    instance cannot corrupt its bookkeeping, but only one of them gets
    the slot and the others see `~portalocker.exceptions.LockException`
    from the already-taken guard. Give each thread its own instance when
    every thread needs a slot of its own.

    The `fail_when_locked` handling diverges from every other lock in
    this module and is kept as it has behaved since 3.2.0. The flag is
    consulted only once the ``timeout`` has expired: a full semaphore
    always retries for the whole timeout, even with the flag set, where
    the other locks fail fast on the first attempt. And when time does
    run out, ``fail_when_locked=True`` (the default) raises
    `AlreadyLocked` while ``fail_when_locked=False`` returns `None`
    where the other locks raise, so check the return value.

    The slot files must survive for as long as a slot is held. A slot
    file that something else deletes mid-hold silently admits an extra
    holder, because the operating system lock lives on the deleted inode
    where no new acquirer can see it. The default `directory` is the
    system temporary directory, which tmp cleaners prune on many systems,
    so point `directory` somewhere exempt from cleanup for anything long
    running. On a multi-user system prefer a private directory as well: a
    slot file created by another user is typically not writable for you,
    and `acquire` then raises `PermissionError` instead of treating the
    slot as busy.

    Prefer `NamedBoundedSemaphore`, a drop-in replacement for this class.
    Without an explicit `name` this class falls back to the shared default
    name ``bounded_semaphore``, so two completely unrelated programs on the
    same machine end up sharing one semaphore; constructing one that way
    emits a `DeprecationWarning`. Passing a `name` here is equivalent and
    warning-free.

    >>> semaphore = BoundedSemaphore(2, directory='')
    >>> str(semaphore.get_filenames()[0])
    'bounded_semaphore.00.lock'
    >>> str(sorted(semaphore.get_random_filenames())[1])
    'bounded_semaphore.01.lock'

    See Also:
        `NamedBoundedSemaphore`: the same thing with a mandatory or
        generated name.
    úLock | Nonerr   Úbounded_semaphoreú{name}.{number:02d}.lockTÚmaximumr-   rK   r$   Úfilename_patternÚ	directoryr|   r€   r}   r~   r�   r   r%   c                óâ   •— || _         || _        || _        || _        d| _        t          ¦   «                              |||¬¦  «         |r|dk    rt          j        dt          d¬¦  «         dS dS )ae  Configure the semaphore; no lock file is created yet.

        Args:
            maximum: Number of slots, and therefore the number of lock
                files. That many holders may run at once.
            name: Name shared by every process that takes part in this
                semaphore. Leaving it at the default is deprecated, see
                the class documentation.
            filename_pattern: Pattern for the lock file names, formatted
                with ``name`` and ``number``.
            directory: Directory holding the lock files, the system
                temporary directory by default. It must already exist;
                acquiring inside a missing directory raises
                `FileNotFoundError`.
            timeout: See `LockBase`.
            check_interval: See `LockBase`.
            fail_when_locked: See `LockBase`. Defaults to `True` here.
                Unlike the other lock classes the flag is consulted only
                once `timeout` has expired: a full semaphore retries for
                the whole timeout first, and the flag then decides
                between raising `AlreadyLocked` and returning `None`.

        Warns:
            DeprecationWarning: `name` is empty or left at the default
                ``'bounded_semaphore'``. Use `NamedBoundedSemaphore`, or
                pass a name of your own.
        N)r|   r}   r~   r¦  z_`BoundedSemaphore` without an explicit `name` argument is deprecated, use NamedBoundedSemaphoreé   r„   )
r¨  rK   r©  rª  rr   rú   r“   r†   r‡   rˆ   ©	r�   r¨  rK   r©  rª  r|   r}   r~   rû   s	           €r   r“   zBoundedSemaphore.__init__  s¢   ø€ ðJ ˆŒØˆŒ	Ø 0ˆÔØ"ˆŒØˆŒ	Ý‰Œ×ÒØØ)Ø-ð 	ñ 	
ô 	
ð 	
ð ð 	�tÐ2Ò2Ð2õ ŒMðDå"Øð	ñ ô ð ð ð ð 3Ð2r   útyping.Sequence[pathlib.Path]c                óD   ‡ — ˆ fd„t          ‰ j        ¦  «        D ¦   «         S )ah  Return the path of every slot, in order.

        Returns:
            One path per slot, from number ``0`` up to ``maximum - 1``.

        Example:
            >>> semaphore = BoundedSemaphore(2, name='example', directory='')
            >>> [str(filename) for filename in semaphore.get_filenames()]
            ['example.00.lock', 'example.01.lock']
        c                ó:   •— g | ]}‰                      |¦  «        ‘ŒS r   )Úget_filename)r   Únr�   s     €r   ú
<listcomp>z2BoundedSemaphore.get_filenames.<locals>.<listcomp>K  s'   ø€ ÐBÐBÐB¨�×!Ò! !Ñ$Ô$ÐBÐBÐBr   )rA   r¨  r–   s   `r   Úget_filenameszBoundedSemaphore.get_filenames@  s*   ø€ ð CÐBÐBÐB­e°D´LÑ.AÔ.AÐBÑBÔBÐBr   c                óp   — t          |                      ¦   «         ¦  «        }t          j        |¦  «         |S )a  Return the path of every slot, in a random order.

        A helper for callers that want to spread the contention out
        themselves: hand the result to `try_lock` and different processes
        start their sweep at different slots. `acquire` does not call this;
        it sweeps the slots in numerical order, see `BoundedSemaphore`.

        Returns:
            The same paths `get_filenames` returns, in a random order. The
            shuffle happens on a fresh list; `get_filenames` is unaffected.

        Example:
            >>> semaphore = BoundedSemaphore(2, name='example', directory='')
            >>> names = semaphore.get_random_filenames()
            >>> sorted(str(filename) for filename in names)
            ['example.00.lock', 'example.01.lock']
        )ro   r´  ÚrandomÚshuffle)r�   Ú	filenamess     r   Úget_random_filenamesz%BoundedSemaphore.get_random_filenamesM  s3   € õ$ ˜×+Ò+Ñ-Ô-Ñ.Ô.ˆ	ÝŒ�yÑ!Ô!Ð!ØÐr   Únumberr0   c                óx   — t          j        | j        ¦  «        | j                             | j        |¬¦  «        z  S )aõ  Build the path of a single slot.

        Args:
            number: The slot number. Callers normally stay within
                ``range(maximum)``, but any integer formats fine.

        Returns:
            `directory` joined with `filename_pattern` formatted with the
            semaphore `name` and this `number`.

        Example:
            >>> semaphore = BoundedSemaphore(2, name='example', directory='')
            >>> str(semaphore.get_filename(1))
            'example.01.lock'
        )rK   rº  )rX   rY   rª  r©  ÚformatrK   )r�   rº  s     r   r±  zBoundedSemaphore.get_filenamec  s@   € õ  Œ|˜DœNÑ+Ô+¨dÔ.C×.JÒ.JØ”Øð /Kñ /
ô /
ñ 
ð 	
r   Nc                óZ  — | j         �t          j        d¦  «        ‚|                      ¦   «         }|                      ||¦  «        D ]<}t
                               d||¦  «         |                      |¦  «        r	| j         c S Œ=t          || j	        ¦  «        rt          j
        ¦   «         ‚dS )aµ	  Take one of the `maximum` slots.

        The slot list is built once with `get_filenames`, so every attempt
        sweeps the slots in numerical order and keeps the first one that
        locks. The sweep repeats until a slot is free or the timeout
        expires. That order is fixed and identical in every process, so
        all contenders race for slot ``0`` first.

        Args:
            timeout: Overrides `timeout` for this call. See `LockBase`.
            check_interval: Overrides `check_interval` for this call.
            fail_when_locked: Overrides `fail_when_locked` for this call.
                Unlike the rest of the retry policy this one is consulted
                only after the timeout has expired: the semaphore always
                keeps trying for the full timeout, and this decides
                whether running out of time raises `AlreadyLocked` or
                returns `None`. Both outcomes diverge from the other lock
                classes, in timing and in type. See the class docstring.

        Returns:
            The `Lock` holding the slot that was taken, which is also
            stored as the `lock` attribute. `None` when no slot became
            free within the timeout and `fail_when_locked` resolves to
            `False`.

        Raises:
            ~portalocker.exceptions.AlreadyLocked: All slots stayed taken
                for the whole timeout and `fail_when_locked` resolves to
                `True`.
            ~portalocker.exceptions.LockException: This instance already
                holds a slot. Release it before acquiring again. Changed in
                4.2.0: this guard used to be an ``assert``, which
                ``python -O`` strips, and a second acquire then silently
                took a second slot and leaked the first. The guard is also
                enforced atomically inside `try_lock` since 4.2.0: two
                threads racing this method on one instance used to both
                take a slot, with the second publication overwriting the
                first and leaking that slot until garbage collection. Now
                exactly one thread wins and the other raises this
                exception.
            OSError: Raised straight through from `try_lock`, for instance
                `FileNotFoundError` when `directory` does not exist. The
                instance stays usable, so a later call can succeed once the
                cause is fixed.
        NúAlready lockedztrying lock (attempt %d) %r)rr   r   r  r´  rª   r  ÚdebugÚtry_lockr   r~   r  )r�   r|   r}   r~   r¸  r²  s         r   r˜   zBoundedSemaphore.acquirex  s¹   € ðf Œ9Ð ÝÔ*Ð+;Ñ<Ô<Ð<à×&Ò&Ñ(Ô(ˆ	à×(Ò(¨°.ÑAÔAð 	!ð 	!ˆAÝ�LŠLÐ6¸¸9ÑEÔEÐEØ�}Š}˜YÑ'Ô'ð !Ø”yÐ Ð Ð ð!õ Ð$ dÔ&;Ñ<Ô<ð 	-ÝÔ*Ñ,Ô,Ð,àˆtr   r¸  útyping.Sequence[Filename]r2   c                óŽ  — | j         �t          j        d¦  «        ‚|D �]%}t                               d|¦  «         t          |d¬¦  «        }d}	 	 |                     ¦   «          n# t          j        $ r Y ŒYw xY w| j        5  | j         €	|| _         d}ddd¦  «         n# 1 swxY w Y   nR# t          $ rE | j        5  | j         |u rd| _         ddd¦  «         n# 1 swxY w Y   | 
                    ¦   «          ‚ w xY w|rt                               d|¦  «          dS | 
                    ¦   «          t          j        d¦  «        ‚dS )aD	  Try each candidate file once and keep the first one that locks.

        A single sweep with no waiting: every candidate is locked with
        ``fail_when_locked=True``, so a busy slot is skipped immediately
        rather than waited on. The sweep itself runs *outside* the
        instance state lock: each slot attempt opens and locks a file,
        which releases the GIL, and holding the state lock across those
        OS calls left a wide window for ``os.fork`` in another thread to
        capture it locked and hang the child. Only the publication on
        the `lock` attribute takes the state lock, re-checking the
        already-taken guard in the same scope: a thread that locked a
        slot but finds another thread published first releases its slot
        again and raises, so two racing sweeps end with exactly one slot
        held either way.

        Args:
            filenames: The candidate slot files, tried in the given order.

        Returns:
            `True` when a slot was taken, in which case the `lock`
            attribute now holds its `Lock`. `False` when every candidate
            was already taken; the `lock` attribute is then left alone.

        Raises:
            ~portalocker.exceptions.LockException: This instance already
                holds a slot, checked when the sweep starts and re-checked
                atomically at publication. Before 4.2.0 a concurrent
                sweep took a second slot instead and the overwritten one
                leaked until garbage collection.
            Exception: Anything other than `AlreadyLocked` coming out of
                `Lock.acquire`, such as `FileNotFoundError` for a missing
                `directory`. The `lock` attribute is untouched, so the
                failure cannot brick the instance for later calls.
            BaseException: An interrupt (`KeyboardInterrupt`,
                `SystemExit`) landing between the successful slot lock
                and the end of its publication, re-raised after the
                slot has been rolled back. Without the rollback the OS
                lock would be stranded on a local that only refcount
                garbage collection releases, and a pinned traceback
                blocks the slot indefinitely - the same window
                `PidFileLock.acquire` closes for its sidecar.
        Nr¾  ztrying lock for %rT)r~   Fz	locked %r)rr   r   r  r  r¿  r   r˜   r  r   r"   r¬   )r�   r¸  rS   rr   Ú	publisheds        r   rÀ  zBoundedSemaphore.try_lockº  sû  € ðV Œ9Ð ÝÔ*Ð+;Ñ<Ô<Ð<à!ð )	=ñ )	=ˆHÝ�LŠLÐ-¨xÑ8Ô8Ð8Ý˜°4Ð8Ñ8Ô8ˆDð $ˆIððØ—L’L‘N”N�N�NøÝ!Ô/ð ð ð à�Hðøøøð Ô%ð )ð )Ø”yÐ(Ø$(˜œ	Ø$(˜	ð)ð )ð )ñ )ô )ð )ð )ð )ð )ð )ð )øøøð )ð )ð )ð )øøõ !ð ð ð ð Ô%ð )ð )Ø”y DÐ(Ð(Ø$(˜œ	ð)ð )ð )ñ )ô )ð )ð )ð )ð )ð )ð )øøøð )ð )ð )ð )ð —’‘”�Øðøøøð ð Ý—’˜[¨(Ñ3Ô3Ð3Ø�t�tð �LŠL‰NŒNˆNÝÔ*Ð+;Ñ<Ô<Ð<àˆusr   ÁA&Á%B+Á&A8Á5B+Á7A8Á8
B+ÂBÂB+ÂB#	Â#B+Â&B#	Â'B+Â+C:Â<CÃC:ÃCÃC:Ã CÃ!C:c                ó’   — | j         5  | j        dc}| _        ddd¦  «         n# 1 swxY w Y   |�|                     ¦   «          dS dS )aü  Give the slot back, if this instance holds one.

        The lock file itself is left on disk. Only the operating system
        lock is dropped, which is what makes the slot available again.
        Doing nothing when no slot is held keeps release safe to call
        any number of times, including from finalizers. The slot is
        claimed atomically under the instance state lock, so of several
        concurrent releases exactly one tears the slot lock down and the
        rest are no-ops.
        N)r   rr   r¬   r   s     r   r¬   zBoundedSemaphore.release  s�   € ð Ôð 	.ð 	.Ø"œi¨ˆOˆD�$”)ð	.ð 	.ð 	.ñ 	.ô 	.ð 	.ð 	.ð 	.ð 	.ð 	.ð 	.øøøð 	.ð 	.ð 	.ð 	.àÐØ�LŠL‰NŒNˆNˆNˆNð Ðr  )r¨  r-   rK   r$   r©  r$   rª  r$   r|   r€   r}   r€   r~   r�   r   r%   )r   r®  )rº  r-   r   r0   r½   )r|   r€   r}   r€   r~   r�   r   r¥  )r¸  rÁ  r   r2   r¾   )rÀ   rÁ   rÂ   rÃ   rÄ   ÚtempfileÚ
gettempdirrŠ   r‹   r“   r´  r¹  r±  r˜   rÀ  r¬   r$  r%  s   @r   r¤  r¤  Ì  s  ø€ € € € € € ð1ð 1ðf ÐÐÑð
 (Ø :Ø,˜Ô,Ñ.Ô.Ø /Ø'=Ø(,ð<ð <ð <ð <ð <ð <ð <ð|Cð Cð Cð Cðð ð ð ð,
ð 
ð 
ð 
ð. !%Ø'+Ø(,ð	@ð @ð @ð @ð @ðDYð Yð Yð Yðvð ð ð ð ð ð ð r   r¤  r¥  c                  óL   ‡ — e Zd ZdZdd ej        ¦   «         eedfdˆ fd„Zˆ xZ	S )ÚNamedBoundedSemaphorea\  
    Bounded semaphore to prevent too many parallel processes from running.

    The recommended form of `BoundedSemaphore`: identical behaviour, but the
    name is either yours or randomly generated, never the shared default
    that makes unrelated programs collide.

    It's also possible to specify a timeout when acquiring the lock to wait
    for a resource to become available.  This is very similar to
    `threading.BoundedSemaphore` but works across multiple processes and across
    multiple operating systems.

    Because this works across multiple processes it's important to give the
    semaphore a name.  This name is used to create the lock files.  If you
    don't specify a name, a random name will be generated.  This means that
    you can't use the same semaphore in multiple processes unless you pass the
    semaphore object to the other processes.

    The slot files live in `directory`, the shared system temporary
    directory by default. Prefer a private directory that no tmp cleaner
    prunes: see `BoundedSemaphore` for how a deleted or foreign-owned slot
    file breaks the semaphore.

    >>> semaphore = NamedBoundedSemaphore(2, name='test')
    >>> str(semaphore.get_filenames()[0])
    '...test.00.lock'

    >>> semaphore = NamedBoundedSemaphore(2)
    >>> 'bounded_semaphore' in str(semaphore.get_filenames()[0])
    True

    Nr§  Tr¨  r-   rK   ú
str | Noner©  r$   rª  r|   r€   r}   r~   r�   r   r%   c           	     óŒ   •— |€dt          j        dd¦  «        d›�}t          ¦   «                              |||||||¦  «         dS )a­  Configure the semaphore, generating a name when none is given.

        Args:
            maximum: Number of slots. See `BoundedSemaphore`.
            name: Name shared by every participating process. `None`
                generates a random one, which only makes sense when the
                semaphore object itself is handed to the other processes.
            filename_pattern: Pattern for the lock file names.
            directory: Directory holding the lock files.
            timeout: See `LockBase`.
            check_interval: See `LockBase`.
            fail_when_locked: See `LockBase`.

        Note:
            The generated name is passed on explicitly, so the default
            ``name=None`` never triggers the `DeprecationWarning` that
            `BoundedSemaphore` emits for a missing name. An explicit `name`
            is forwarded untouched, so ``''`` or ``'bounded_semaphore'``
            still warns.
        Nzbounded_semaphore.r   i@B Úd)r¶  Úrandintrú   r“   r­  s	           €r   r“   zNamedBoundedSemaphore.__init__I  sa   ø€ ð< ˆ<ØF­¬°q¸'Ñ(BÔ(BÐFÐFÐFˆDÝ‰Œ×ÒØØØØØØØñ	
ô 	
ð 	
ð 	
ð 	
r   )r¨  r-   rK   rÉ  r©  r$   rª  r$   r|   r€   r}   r€   r~   r�   r   r%   )
rÀ   rÁ   rÂ   rÃ   rÅ  rÆ  rŠ   r‹   r“   r$  r%  s   @r   rÈ  rÈ  '  sl   ø€ € € € € ðð ðH  Ø :Ø,˜Ô,Ñ.Ô.Ø /Ø'=Ø(,ð(
ð (
ð (
ð (
ð (
ð (
ð (
ð (
ð (
ð (
ð (
r   rÈ  )r   r   r   r   r   r   )r!   r"   r#   r$   r   r%   )r/   r0   r1   r2   r   r3   )r#   r$   r/   r0   r   r%   )T)rS   r   r1   r2   r   rT   r¾   )r   r-   r!  )r²   r"   rØ   r"   r   r%   )rÏ   rÐ   rS   r$   r   r2   )XrÃ   Ú
__future__r   rÅ   ÚatexitÚcollections.abcÚcollectionsrb   rN   rÈ   Úloggingr8   rX   r¶  rÅ  r�   r�   rõ   r†   Úweakrefr	   r   Ú r   r   r   r
   r   r   r   Ú	getLoggerrÀ   r  rŠ   r‹   rŒ   rý   Ú	EXCLUSIVErþ   r#  Ú__all__r   Ú	frozensetÚEPERMrj  Ú
EOPNOTSUPPÚEMLINKr    rÄ   r,   r.   rH   rR   Úcontextmanagerr   rh   rg   ÚTYPE_CHECKINGÚtyping_extensionsÚ_TypeVarWithDefaultÚIOÚAnyr$   ri   ÚWeakSetrl   rv   rq   Ú_register_at_forkÚABCÚGenericrz   r‰   r×   rà   r   rŽ   r:  ÚWeakKeyDictionaryr;  rA  ÚregisterrC  r_  ÚAbstractContextManagerr�  r¤  rÈ  r   r   r   ú<module>rè     sÏ  ðð&ð &ð &ðP #Ð "Ð "Ð "Ð "Ð "à 
€
€
€
Ø €€€Ø Ð Ð Ð Ø Ð Ð Ð Ø €€€Ø €€€Ø €€€Ø 	€	€	€	Ø €€€Ø €€€Ø €€€Ø Ð Ð Ð Ø €€€Ø €€€Ø €€€Ø €€€Ø Ð Ð Ð Ð Ð à 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ø 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7Ð 7à	ˆÔ	˜8Ñ	$Ô	$€à€ØÐ Ø Ð ØÔ!Ô+¨iÔ.AÔ.NÑN€ð Øð€ð :>ð Fð Fð Fð Fð Fð FðB .7¨YàŒØŒØÔØŒð	ñ.ô .Ð ð ð ð ñ ð)ð )ð )ð )ð6 !Ð Ð  Ð  Ð  Ñ  ð@ð @ð @ð @ðF$'ð $'ð $'ð $'ðN Ôð ðsð sð sð sñ Ôðsðr  �”Ð 0Ñ1Ô1€à	Ôð =ð AÐ@Ð@Ð@Ð@Ð@ð Ð
ØØŒi˜œ
Ô#Ø”	˜#”ðñ ô €C€Cð ˆ&Œ.˜ f¤i°´
Ô&;Ð
<Ñ
<Ô
<€Cð 6E°W´_Ñ5FÔ5F€Ð FÐ FÐ FÑ Fð,ð ,ð ,ð ,ðh �G˜BÐ 2°DÑ9Ô9Ð ØÐ ØÐØ5ðñ ô ð ð
Ið Ið Ið Ið IØ„GØ
„N�>Ô"ñIô Ið IðX
ð ð ð ðD9ð 9ð 9ð 9ð0&
ð &
ð &
ð &
ðRs	ð s	ð s	ð s	ð s	ˆ8�CŒ=ñ s	ô s	ð s	ðly)ð y)ð y)ð y)ð y)ˆD�ŒIñ y)ô y)ð y)ðxð ð ð ðR €GÔÑÔð ð ð ð ñ ð
ð ð ð ð8 €„Ð&Ñ 'Ô 'Ð 'ðGð Gð Gð Gð G˜˜VœY sœ^Ô,ñ Gô Gð GðTkð kð kð kð kÐ#ñ kô kð kð\OCð OCð OCð OCð OCØÔ% dÔ+ñOCô OCð OCðdXð Xð Xð Xð X�x Ô.ñ Xô Xð Xðv
J
ð J
ð J
ð J
ð J
Ð,ñ J
ô J
ð J
ð J
ð J
r   