§
    ´¯¸j˜È  ã                   óÌ  — U d 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 ddlm	Z	m
Z
mZ e	j        Z G d„ dej        ¦  «        Z G d	„ d
ej        ¦  «        Z G d„ d¦  «        Zeeej        z  egef         eeef         z  ez  ee         z  Zeed<   i Zeee         ef         ed<   dedeeef         dz  fd„Zdeddfd„ZddddddœZeeef         ed<   dedeeef         fd„Zej        dk    r„ddl Z dej!        deeej"        e         dz  edz  f         fd„Z#dedej"        e         dz  d edz  ddfd!„Z$ G d"„ d#e¦  «        Z% G d$„ d%e¦  «        Z&e&Z'd&ej!        deddfd'„Z(d&ej!        ddfd(„Z)dS ddl*Z*ddl+Z+ej!        ej        z  Z, G d)„ d*e¦  «        Z- G d+„ d,e-¦  «        Z. G d-„ d.e-¦  «        Z/e+j0        Z' e-¦   «         Z1d&ej!        deddfd/„Z(d&ej!        ddfd0„Z)dS )1aÐ  Module portalocker.

This module provides cross-platform file locking functionality.

On POSIX systems locking is provided by ``fcntl.flock`` (or ``fcntl.lockf``
via :class:`LockfLocker`), with no extra dependencies.

On Windows the default locker is :class:`MsvcrtLocker`, which needs no
extra dependencies for *exclusive* locks (it uses the built-in ``msvcrt``
module). *Shared* locks require the Win32 API
(``win32file.LockFileEx``/``UnlockFileEx``) provided by the optional
``pywin32`` package, installable through the ``win32`` extra::

    pip install "portalocker[win32]"

Without ``pywin32``, acquiring a shared lock on Windows raises
``ImportError``. :class:`Win32Locker` can be used directly to lock through
the Win32 API exclusively; it always requires ``pywin32``.

This version uses classes to encapsulate locking logic, while maintaining
the original external API, including the LOCKER constant for specific
backwards compatibility (POSIX) and Windows behavior.
é    N)ÚCallable)ÚAnyÚcasté   )Ú	constantsÚ
exceptionsÚtypesc                   ó0   — e Zd ZdZdej        deddfd„ZdS )ÚLockCallableaI  Call signature of the locking half of a ``LOCKER`` pair.

    `LOCKER` may be set to a ``(lock, unlock)`` tuple of two plain
    callables instead of to a `BaseLocker`; this protocol describes the
    first element. It is a typing construct only: it types `LockerType`
    and the pair returned by `_resolve_locker_pair`, and nothing checks
    it at runtime.

    The bound `lock` method of every locker in this module matches it,
    which is why ``(locker.lock, locker.unlock)`` is a valid `LOCKER`.

    See Also:
        `UnlockCallable`: the unlocking half of the same pair.
    Úfile_objÚflagsÚreturnNc                 ó   — dS )a(  Acquire a lock on `file_obj`.

        Args:
            file_obj: An open file object, an object exposing `fileno()`,
                or a raw file descriptor.
            flags: The `LockFlags` combination describing the lock to
                take, e.g. ``EXCLUSIVE | NON_BLOCKING``.
        N© ©Úselfr   r   s      úg/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/portalocker/portalocker.pyÚ__call__zLockCallable.__call__>   s	   € ð 	ˆó    )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   ÚFileArgumentÚ	LockFlagsr   r   r   r   r   r   .   sJ   € € € € € ðð ð	 Ô!3ð 	¸Ið 	È$ð 	ð 	ð 	ð 	ð 	ð 	r   r   c                   ó,   — e Zd ZdZdej        ddfd„ZdS )ÚUnlockCallableai  Call signature of the unlocking half of a ``LOCKER`` pair.

    The counterpart of `LockCallable`: the second element of a
    ``(lock, unlock)`` tuple assigned to `LOCKER`. It takes no flags
    because releasing a lock needs no options - the locker already knows
    what it took.

    See Also:
        `LockCallable`: the locking half of the same pair.
    r   r   Nc                 ó   — dS )zÓRelease a lock previously taken on `file_obj`.

        Args:
            file_obj: The same file object, `fileno()` provider or raw
                file descriptor that was passed to the lock callable.
        Nr   ©r   r   s     r   r   zUnlockCallable.__call__V   s	   € ð 	ˆr   )r   r   r   r   r	   r   r   r   r   r   r   r   J   sC   € € € € € ð	ð 	ð Ô!3ð ¸ð ð ð ð ð ð r   r   c                   óJ   — e Zd ZdZdej        deddfd„Zdej        ddfd„ZdS )Ú
BaseLockera}  Base class for locker implementations.

    A locker is the thin layer between `portalocker.lock` and the
    platform's locking system call. Each platform branch of this module
    defines its own subclasses - `Win32Locker` and `MsvcrtLocker` on
    Windows, `PosixLocker` and friends on POSIX - and `LOCKER` names the
    one the module-level `lock` / `unlock` dispatch to.

    Subclass it to plug in a custom mechanism: implement both methods,
    then assign the class or an instance of it to `LOCKER`. Both forms
    are accepted (see `_resolve_locker_pair`); the class form is
    instantiated once, on first use, and cached.
    r   r   r   Nc                 ó   — t           ‚)aó  Lock `file_obj` according to `flags`.

        Implementations must keep contention and real failure apart,
        because the retry machinery in `portalocker.utils.Lock.acquire`
        acts on the distinction: raise
        `~portalocker.exceptions.AlreadyLocked` when somebody else holds
        a conflicting lock, and a plain
        `~portalocker.exceptions.LockException` for any other failure.
        Only `AlreadyLocked` is retried until the timeout expires. Any
        other exception is treated as permanent and aborts the acquire
        immediately, so a custom locker that reports contention as a
        plain `LockException` loses all retrying. The bundled lockers
        follow the contract; mirror them.

        Args:
            file_obj: An open file object, an object exposing `fileno()`,
                or a raw file descriptor.
            flags: The `LockFlags` combination to apply.

        Raises:
            NotImplementedError: Always; subclasses must override this.
        ©ÚNotImplementedErrorr   s      r   ÚlockzBaseLocker.locko   s
   € õ. "Ð!r   c                 ó   — t           ‚)a  Release a lock previously taken by `lock`.

        Args:
            file_obj: The same file object, `fileno()` provider or raw
                file descriptor that was passed to `lock`.

        Raises:
            NotImplementedError: Always; subclasses must override this.
        r#   r   s     r   ÚunlockzBaseLocker.unlockˆ   s
   € õ "Ð!r   )	r   r   r   r   r	   r   r   r%   r'   r   r   r   r!   r!   `   so   € € € € € ðð ð"˜UÔ/ð "¸	ð "Àdð "ð "ð "ð "ð2
"˜uÔ1ð 
"°dð 
"ð 
"ð 
"ð 
"ð 
"ð 
"r   r!   ÚLOCKERÚ_locker_instancesÚlockerr   c                 ó|  — t          | t          ¦  «        r| j        | j        fS t          | t          ¦  «        r t          d| ¦  «        }|d         |d         fS t          | t          ¦  «        rNt          d| ¦  «        }t                               |¦  «        }|€ |¦   «         x}t          |<   |j        |j        fS dS )aó  Resolve the non-callable ``LockerType`` forms to a ``(lock, unlock)``
    pair.

    Handles the three high-level forms shared by every platform: a
    ``BaseLocker`` instance, a ``(lock, unlock)`` tuple, and a ``BaseLocker``
    subclass (instantiated once and cached in :data:`_locker_instances`).

    Returns ``None`` for the plain POSIX-style ``fcntl`` callable, which each
    platform resolves itself: POSIX applies its own error translation while
    Windows rejects it. ``locker`` is typed ``object`` because this is a
    runtime dispatch over the ``LockerType`` union; the type checkers cannot
    narrow the parameterised ``tuple`` / ``type`` members from ``isinstance``
    alone, so the concrete forms are recovered with explicit casts.
    z#tuple[LockCallable, UnlockCallable]r   r   ztype[BaseLocker]N)	Ú
isinstancer!   r%   r'   Útupler   Útyper)   Úget)r*   ÚpairÚ
locker_clsÚinstances       r   Ú_resolve_locker_pairr3   ¨   s¿   € õ" �&�*Ñ%Ô%ð *ØŒ{˜FœMÐ)Ð)Ý�&�%Ñ Ô ð  ÝÐ9¸6ÑBÔBˆØ�AŒw˜˜QœÐÐÝ�&�$ÑÔð .ÝÐ,¨fÑ5Ô5ˆ
Ý$×(Ò(¨Ñ4Ô4ˆØÐØ7A°z±|´|ÐCˆHÕ(¨Ñ4ØŒ}˜hœoÐ-Ð-Øˆ4r   r   c                 óò   — | t           j        z  rt          d¦  «        ‚| t           j        z  r| t           j        z  rt          d¦  «        ‚| t           j        t           j        z  z  st          d¦  «        ‚dS )aÖ  Reject flag combinations that cannot describe a lock request.

    Called by the module-level `lock` on every platform, before any
    system call, so nonsense flags fail loudly instead of doing something
    silently wrong. Three combinations are rejected:

    - Anything carrying `LockFlags.UNBLOCK`. Passing it to `lock` used to
      silently *release* a held lock on POSIX, because the bit went
      straight through to ``fcntl``. Releasing is `unlock`'s job.
    - ``SHARED | EXCLUSIVE``. The two lock types contradict each other,
      and what actually happened depended on the platform.
    - A flag set naming no lock type at all, such as ``LockFlags(0)`` or
      `LockFlags.NON_BLOCKING` on its own. `NON_BLOCKING` only says *how*
      to wait, not *what* to take.

    Note:
        On Windows ``LockFlags.UNBLOCK`` is ``msvcrt.LK_UNLCK``, which is
        0, so the UNBLOCK check cannot trigger there. A bare
        ``LockFlags.UNBLOCK`` still fails on Windows, through the
        no-lock-type check, since the flag adds no bits.

    Args:
        flags: The `LockFlags` combination passed to `lock`.

    Raises:
        RuntimeError: `flags` matches one of the rejected combinations
            described above.
    zolock() cannot release locks: LockFlags.UNBLOCK is not a valid flag for lock(). Call unlock() to release a lock.zZLockFlags.SHARED and LockFlags.EXCLUSIVE are mutually exclusive. Pass exactly one of them.zYlock() needs a lock type: combine the flags with LockFlags.SHARED or LockFlags.EXCLUSIVE.N)r   ÚUNBLOCKÚRuntimeErrorÚSHAREDÚ	EXCLUSIVE)r   s    r   Ú_validate_lock_flagsr9   Ç   sŸ   € ð: �yÔ Ñ ð 
Ýð@ñ
ô 
ð 	
ð �yÔÑð 
 E­IÔ,?Ñ$?ð 
Ýð3ñ
ô 
ð 	
ð •IÔ$¥yÔ':Ñ:Ñ;ð 
Ýð7ñ
ô 
ð 	
ð
ð 
r   é   é   é   )ÚLK_UNLCKÚLK_LOCKÚLK_NBLCKÚLK_RLCKÚ	LK_NBRLCKÚ_MSVCRT_LOCK_MODE_DEFAULTSÚmsvcrt_modulec                 óN   ‡ — ˆ fd„t                                ¦   «         D ¦   «         S )a¥  Resolve the ``LK_*`` locking modes for an ``msvcrt``-like module.

    Prefers the constants the module itself defines and falls back to
    `_MSVCRT_LOCK_MODE_DEFAULTS` for any it lacks. The module is never
    mutated: before 4.2.0 the fallbacks were ``setattr``'d onto the
    shared stdlib ``msvcrt`` module, and the fallback table itself was
    wrong (``LK_LOCK`` fell back to 0, which is ``LK_UNLCK``, so a
    "blocking lock" through it would have issued an unlock).

    Args:
        msvcrt_module: The module to read ``LK_*`` constants from.
            Typed ``object`` so tests can pass a stub. On Windows this is
            the real ``msvcrt``, whose CPython builds have defined all
            five constants for as long as the module has existed, so the
            fallbacks are pure defence in depth.

    Returns:
        A mapping from constant name (``'LK_LOCK'`` etc.) to its integer
        locking mode.
    c                 óV   •— i | ]%\  }}|t          d t          ‰||¦  «        ¦  «        “Œ&S )Úint)r   Úgetattr)Ú.0ÚnameÚdefaultrC   s      €r   ú
<dictcomp>z._resolve_msvcrt_lock_modes.<locals>.<dictcomp>  sE   ø€ ð ð ð áˆD�'ð 	�d�5�' -°°wÑ?Ô?Ñ@Ô@ðð ð r   )rB   Úitems)rC   s   `r   Ú_resolve_msvcrt_lock_modesrM     s:   ø€ ð*ð ð ð å7×=Ò=Ñ?Ô?ðñ ô ð r   Úntr   c                 óf  — t          | t          j        ¦  «        rp|                      ¦   «         }|                      ¦   «         }|dk    r|                      d¦  «         |t          j        t          j        t                   | ¦  «        |fS t          | t          ¦  «        r| }n1t          j        t          j        | ¦  «                             ¦   «         }	 t          j        |dt          j        ¦  «        }|dk    r t          j        |dt          j        ¦  «         n# t"          $ r d}Y nw xY w|d|fS )aE  Prepare file for Windows: get fd, seek to 0 and save prior pos.

        ``msvcrt.locking`` and ``LockFileEx`` lock a byte range relative to
        the *current* file position, so every path must seek to byte 0 first
        for consistent mutual exclusion (otherwise two locks taken at
        different positions on files larger than the lock length do not
        conflict). Full IO objects are seeked/restored via ``seek``/``tell``;
        raw descriptors (``int`` / ``HasFileno``) via ``os.lseek``.

        Args:
            file_obj: An open file object, an object exposing `fileno()`,
                or a raw file descriptor.

        Returns:
            A ``(fd, io_obj, original_pos)`` triple to hand straight to
            `_restore_windows_file_pos` once the lock or unlock call has
            returned. ``io_obj`` is the file object when there was one and
            `None` for raw descriptors; ``original_pos`` is `None` when the
            descriptor is not seekable (a pipe, socket or standard stream)
            and therefore has no position worth restoring.
        r   N)r,   ÚioÚIOBaseÚfilenoÚtellÚseekÚtypingr   ÚIOr   rF   r	   Ú	HasFilenoÚosÚlseekÚSEEK_CURÚSEEK_SETÚOSError)r   ÚfdÚoriginal_poss      r   Ú_prepare_windows_filer_   '  s  € õ4 �h¥¤	Ñ*Ô*ð 	KØ—o’oÑ'Ô'ˆBØ#Ÿ=š=™?œ?ˆLØ˜qÒ Ð Ø—’˜aÑ Ô Ð Ø•v”{¥6¤9­S¤>°8Ñ<Ô<¸lÐJÐJõ �h¥Ñ$Ô$ð 	AØˆBˆBå”�Uœ_¨hÑ7Ô7×>Ò>Ñ@Ô@ˆBð
	 Ýœ8 B¨­2¬;Ñ7Ô7ˆLØ˜qÒ Ð Ý”˜˜Q¥¤Ñ,Ô,Ð,øøÝð 	 ð 	 ð 	 ØˆLˆLˆLð	 øøøà�4˜Ð%Ð%s   ÃAD ÄD+Ä*D+r]   Úfile_io_objr^   c                 óŒ   — |�|dk    rdS |�|                      |¦  «         dS t          j        | |t          j        ¦  «         dS )a  Restore a saved file position after a lock/unlock operation.

        IO objects are restored via ``seek``; raw descriptors (no IO object)
        via ``os.lseek`` on ``fd``.

        Args:
            fd: The file descriptor `_prepare_windows_file` returned.
            file_io_obj: The file object it returned, or `None` when the
                caller passed a raw descriptor.
            original_pos: The position it returned. `None` (non-seekable)
                and ``0`` (already at the start) are both no-ops.
        Nr   )rT   rX   rY   r[   )r]   r`   r^   s      r   Ú_restore_windows_file_posrb   \  sU   € ð" Ð <°1Ò#4Ð#4ØˆFØÐ"Ø×Ò˜\Ñ*Ô*Ð*Ð*Ð*åŒH�R˜¥r¤{Ñ3Ô3Ð3Ð3Ð3r   c                   ór   — e Zd ZU dZdZeed<   dd„Zdedefd„Zd	e	j
        d
eddfd„Zd	e	j
        ddfd„ZdS )ÚWin32Lockera1  Locker using Win32 API (LockFileEx/UnlockFileEx).

        This is the only locker on Windows that can take a *shared* lock:
        ``LockFileEx`` locks shared unless ``LOCKFILE_EXCLUSIVE_LOCK`` is
        requested, whereas ``msvcrt.locking`` has no shared mode at all.
        `MsvcrtLocker`, the default, delegates its shared locks here.

        It is not the default because it needs the optional ``pywin32``
        package. Since 4.0.0 that package is no longer installed with
        portalocker; ``pip install "portalocker[win32]"`` adds it, and
        without it merely constructing this class raises `ImportError`.

        Example:
            .. code-block:: python

                from portalocker import LockFlags
                from portalocker.portalocker import Win32Locker

                locker = Win32Locker()
                with open('example.txt', 'w') as fh:
                    locker.lock(fh, LockFlags.SHARED)
                    locker.unlock(fh)

        See Also:
            `MsvcrtLocker`: the dependency-free Windows default.
        i  ÿÿÚ_lock_bytes_lowr   Nc                 óT   — 	 ddl }dS # t          $ r}t          d¦  «        |‚d}~ww xY w)a_  Verify that ``pywin32`` is importable.

            Nothing is cached here. In particular the ``OVERLAPPED``
            structure handed to ``LockFileEx``/``UnlockFileEx`` is
            created fresh for every call (see `lock` / `unlock`): the
            Win32 API forbids sharing one ``OVERLAPPED`` between
            concurrent calls, which a cached instance would do the moment
            two threads lock through the same locker.

            Raises:
                ImportError: ``pywin32`` is not installed. The message
                    names the ``win32`` extra that provides it.
            r   NzaWin32Locker requires the win32 extra (pywin32). Install it with: pip install "portalocker[win32]")Ú
pywintypesÚImportError)r   rg   Úes      r   Ú__init__zWin32Locker.__init__’  sU   € ðà!Ð!Ð!Ð!Ð!Ð!øÝð ð ð Ý!ðHñô ð ðøøøøðøøøs   ‚ ˆ
'’"¢'r]   c                 óP   — t          t          t          j        |¦  «        ¦  «        S )aœ  Translate a C runtime descriptor into a Win32 file handle.

            ``LockFileEx`` and ``UnlockFileEx`` operate on OS handles
            rather than on the descriptors Python hands out, so both go
            through ``msvcrt.get_osfhandle`` first.

            Args:
                fd: The file descriptor to translate.

            Returns:
                The Win32 file handle owning `fd`.
            )r   rF   ÚmsvcrtÚget_osfhandle)r   r]   s     r   Ú_get_os_handlezWin32Locker._get_os_handle©  s   € õ ��VÔ1°"Ñ5Ô5Ñ6Ô6Ð6r   r   r   c                 óü  — ddl }ddl}ddl}ddl}t	          |¦  «        \  }}}	d}
|t
          j        z  r
|
|j        z  }
|t
          j        z  r
|
|j	        z  }
	 |  
                    |¦  «        }|                     ¦   «         }|                     ||
d| j        |¦  «         n³# |j        $ rm}|j        |j        k    r,t!          j        t           j        j        |j        |¬¦  «        |‚t!          j        t           j        j        |j        |¬¦  «        |‚d}~wt*          $ r1}t!          j        t           j        j        |j        |¬¦  «        |‚d}~ww xY w	 t-          |||	¦  «         dS # t-          |||	¦  «         w xY w)aH  Lock `file_obj` through ``win32file.LockFileEx``.

            The file position is normalized to byte 0 before the call and
            restored afterwards (see `_prepare_windows_file`), so that two
            processes holding the file at different offsets still contend
            for the same range.

            Args:
                file_obj: An open file object, an object exposing
                    `fileno()`, or a raw file descriptor.
                flags: `LockFlags.EXCLUSIVE` adds
                    ``LOCKFILE_EXCLUSIVE_LOCK`` and
                    `LockFlags.NON_BLOCKING` adds
                    ``LOCKFILE_FAIL_IMMEDIATELY``. `LockFlags.SHARED` sets
                    neither, which is ``LockFileEx``'s own default and is
                    how a shared lock is expressed.

            Raises:
                ~portalocker.exceptions.AlreadyLocked: Windows reported
                    ``ERROR_LOCK_VIOLATION``, i.e. someone else holds a
                    conflicting lock on the range.
                ~portalocker.exceptions.LockException: Any other Win32 error,
                    or an ``OSError`` such as ``msvcrt.get_osfhandle``
                    rejecting a stale file descriptor. Neither a raw
                    ``pywintypes.error`` nor a raw ``OSError`` escapes this
                    method.
            r   N©Úfh)rg   Úwin32conÚ	win32fileÚwinerrorr_   r   ÚNON_BLOCKINGÚLOCKFILE_FAIL_IMMEDIATELYr8   ÚLOCKFILE_EXCLUSIVE_LOCKrn   Ú
OVERLAPPEDÚ
LockFileExre   ÚerrorÚERROR_LOCK_VIOLATIONr   ÚAlreadyLockedÚLockExceptionÚLOCK_FAILEDÚstrerrorr\   rb   )r   r   r   rg   rr   rs   rt   r]   Ú
io_obj_ctxÚpos_ctxÚmodeÚos_fhÚ
overlappedÚ	exc_values                 r   r%   zWin32Locker.lock¸  sõ  € ð@ ÐÐÐØˆOˆOˆOØÐÐÐØˆOˆOˆOå&;¸HÑ&EÔ&EÑ#ˆB�
˜GàˆDØ•yÔ-Ñ-ð ;Ø˜Ô:Ñ:�Ø•yÔ*Ñ*ð 9Ø˜Ô8Ñ8�ð"CØ×+Ò+¨BÑ/Ô/�ð (×2Ò2Ñ4Ô4�
Ø×$Ò$Ø˜4  DÔ$8¸*ñô ð ð øð Ô#ð %ð %ð %ØÔ%¨Ô)FÒFÐFÝ$Ô2Ý"Ô0Ô<Ø!Ô*Ø#ðñ ô ð %ð	%õ %Ô2Ý"Ô0Ô<Ø!Ô*Ø#ðñ ô ð %ð	%øøøøõ
 ð !ð !ð !õ !Ô.ÝÔ,Ô8ØÔ&Øðñ ô ð !ð	!øøøøð	!øøøð'õ: *¨"¨j¸'ÑBÔBÐBÐBÐBøÕ)¨"¨j¸'ÑBÔBÐBÐBøøøs8   ÁAB! Â E( Â!
EÂ+A(DÄEÄ ,EÅEÅE( Å(E;c                 ó:  — ddl }ddl}ddl}t          |¦  «        \  }}}	 |                      |¦  «        }|                     ¦   «         }	|                     |d| j        |	¦  «         nŒ# |j        $ rF}
|
j        |j	        k    r,t          j        t          j        j        |
j        |¬¦  «        |
‚Y d}
~
nAd}
~
wt          $ r1}
t          j        t          j        j        |
j        |¬¦  «        |
‚d}
~
ww xY wt          |||¦  «         dS # t          |||¦  «         w xY w)ah  Release a lock through ``win32file.UnlockFileEx``.

            ``ERROR_NOT_LOCKED`` is swallowed, so unlocking a range that
            is not locked - releasing twice, or releasing a lock Windows
            already dropped - is harmless.

            Args:
                file_obj: The same file object, `fileno()` provider or
                    raw file descriptor that was passed to `lock`.

            Raises:
                ~portalocker.exceptions.LockException: Any Win32 error other
                    than ``ERROR_NOT_LOCKED``, or any `OSError` raised while
                    unlocking.
            r   Nrp   )rg   rs   rt   r_   rn   rx   ÚUnlockFileExre   rz   ÚERROR_NOT_LOCKEDr   r}   r~   r   r\   rb   )r   r   rg   rs   rt   r]   r€   r�   rƒ   r„   Úexcs              r   r'   zWin32Locker.unlock	  s|  € ð& ÐÐÐØÐÐÐØˆOˆOˆOå&;¸HÑ&EÔ&EÑ#ˆB�
˜GðCØ×+Ò+¨BÑ/Ô/�à'×2Ò2Ñ4Ô4�
Ø×&Ò&Ø˜1˜dÔ2°Jñô ð ð øð Ô#ð ð ð Ø”< 8Ô#<Ò<Ð<Ý$Ô2Ý"Ô0Ô<ØœØ#ðñ ô ð ð	ð =Ð<Ð<Ð<Ð<øøøøõ ð ð ð Ý Ô.ÝÔ,Ô8Ø”LØðñ ô ð ð	øøøøðøøøõ *¨"¨j¸'ÑBÔBÐBÐBÐBøÕ)¨"¨j¸'ÑBÔBÐBÐBøøøs<   ¡AA( Á'D Á(
C1Á2<B3Â.D Â3C1Ã ,C,Ã,C1Ã1D ÄD©r   N)r   r   r   r   re   rF   Ú__annotations__rj   rn   r	   r   r   r%   r'   r   r   r   rd   rd   t  sÛ   € € € € € € ð	ð 	ð6  (ˆ˜Ð'Ð'Ñ'ð	ð 	ð 	ð 	ð.	7 Sð 	7¨Sð 	7ð 	7ð 	7ð 	7ðO	CàÔ(ðO	Cð ðO	Cð ð	O	Cð O	Cð O	Cð O	Cðb.	CàÔ(ð.	Cð ð.	Cð .	Cð .	Cð .	Cð .	Cð .	Cr   rd   c                   óŒ   — e Zd ZU dZedz  ed<   eeef         ed<   dZ	eed<   dd„Z
d	ej        d
eddfd„Zd	ej        ddfd„ZdS )ÚMsvcrtLockeraa  Default Windows locker, based on ``msvcrt.locking``.

        Exclusive locks work without any extra dependencies. Shared locks
        are delegated to :class:`Win32Locker` and therefore require the
        optional ``pywin32`` package (``pip install "portalocker[win32]"``);
        without it, acquiring a shared lock raises ``ImportError``.
        NÚ_win32_lockerÚ_lock_modesi   Ú_msvcrt_lock_lengthr   c                 ó�   — 	 t          ¦   «         | _        n# t          $ r
 d| _        Y nw xY wt          t          ¦  «        | _        dS )a~  Set up the msvcrt locker and its optional win32 fallback.

            A `Win32Locker` is built eagerly, because two paths need the
            Win32 API: shared locks in `lock`, and the ``EACCES`` retry in
            `unlock`. ``pywin32`` is optional since 4.0.0, so its absence
            is recorded as `None` here rather than raised, and is only
            reported if one of those two paths is actually taken.

            The ``LK_*`` locking modes are resolved once, via
            `_resolve_msvcrt_lock_modes`, and stored on the instance.
            Before 4.2.0 any missing constant was ``setattr``'d onto the
            shared stdlib ``msvcrt`` module instead, with a fallback
            table whose values were wrong: ``LK_LOCK`` fell back to 0,
            which is ``LK_UNLCK``, so a "blocking lock" through the
            fallback would have issued an unlock.
            N)rd   rŽ   rh   rM   rl   r�   ©r   s    r   rj   zMsvcrtLocker.__init__F  sY   € ð"*Ý%0¡]¤]�Ô"Ð"øÝð *ð *ð *ð
 &*�Ô"Ð"Ð"ð*øøøõ  :½&ÑAÔAˆDÔÐÐs   ‚ –*©*r   r   c                 óæ  — |t           j        z  r]| j        }|€t          d¦  «        ‚t          d¦  «        }|t           j        z  r|t           j        z  }|                     ||¦  «         dS t          |¦  «        \  }}}|t           j        z  r| j        d         n| j        d         }	 t          j	        ||| j
        ¦  «         nƒ# t          $ rv}	|	j        dv r4t          j        t          j        j        t#          |	¦  «        |¬¦  «        |	‚t          j        t          j        j        t#          |	¦  «        |¬¦  «        |	‚d}	~	ww xY w	 t%          |||¦  «         dS # t%          |||¦  «         w xY w)a”  Lock `file_obj`, handing shared locks to `Win32Locker`.

            Exclusive locks go through ``msvcrt.locking`` and need no
            extra dependency. `LockFlags.SHARED` has no ``msvcrt``
            equivalent, so it is forwarded to the `Win32Locker` built in
            `__init__` with only `LockFlags.NON_BLOCKING` carried across.

            The msvcrt path locks ``_msvcrt_lock_length`` bytes (64 KiB)
            starting at byte 0; `_prepare_windows_file` normalizes and
            restores the position around the call because
            ``msvcrt.locking`` works relative to the current one. Before
            4.0.0 raw file descriptors were locked from wherever they
            happened to be positioned, which could leave two holders
            locking different ranges of a file larger than 64 KiB and so
            not excluding each other at all.

            Args:
                file_obj: An open file object, an object exposing
                    `fileno()`, or a raw file descriptor.
                flags: `LockFlags.NON_BLOCKING` selects ``LK_NBLCK``
                    instead of ``LK_LOCK``; `LockFlags.SHARED` switches to
                    the `Win32Locker` path entirely.

            Raises:
                ImportError: `LockFlags.SHARED` was requested but
                    ``pywin32`` is not installed. The message names the
                    ``win32`` extra that provides it.
                ~portalocker.exceptions.AlreadyLocked: ``msvcrt.locking``
                    failed with an errno that means contention (13, 16, 33 or
                    36).
                ~portalocker.exceptions.LockException: ``msvcrt.locking``
                    failed for any other reason.

            Example:
                .. code-block:: python

                    from portalocker import LockFlags
                    from portalocker.portalocker import MsvcrtLocker

                    locker = MsvcrtLocker()
                    with open('example.txt', 'w') as fh:
                        # No pywin32 needed for an exclusive lock.
                        locker.lock(fh, LockFlags.EXCLUSIVE)
                        locker.unlock(fh)
            Nz‘Shared locks on Windows require the win32 extra (pywin32); msvcrt provides no true shared lock. Install it with: pip install "portalocker[win32]"r   r?   r>   )é   é   é!   é$   rp   )r   r7   rŽ   rh   ru   r%   r_   r�   rl   Úlockingr�   r\   Úerrnor   r|   r}   r~   Ústrrb   )
r   r   r   Úwin32_lockerÚwin32_api_flagsr]   r€   r�   r‚   r…   s
             r   r%   zMsvcrtLocker.locka  s¿  € ð\ •yÔ'Ñ'ð Ø#Ô1�ØÐ'Ý%ðLñô ð õ
 #,¨A¡,¤,�Ø�9Ô1Ñ1ð >Ø#¥yÔ'=Ñ=�OØ×!Ò! (¨OÑ<Ô<Ð<Ø�å&;¸HÑ&EÔ&EÑ#ˆB�
˜Gð �9Ô1Ñ1ð1�Ô  Ô,Ð,àÔ% iÔ0ð ðCÝ”ØØØÔ,ñô ð ð øõ
 ð !ð !ð !Ø”?Ð&6Ð6Ð6Ý$Ô2Ý"Ô0Ô<Ý˜I™œØ#ðñ ô ð %ð	%õ
 !Ô.ÝÔ,Ô8Ý˜	‘N”NØðñ ô ð !ð	!øøøøð!øøøðõ$ *¨"¨j¸'ÑBÔBÐBÐBÐBøÕ)¨"¨j¸'ÑBÔBÐBÐBøøøs+   Â*C ÃE Ã
EÃA1EÅEÅE ÅE0c           
      ó\  — t          |¦  «        \  }}}d}	 t          j        || j        d         | j        ¦  «         �n?# t
          $ �r1}|j        dk    rð| j        }|€/t          j	        t          j	        j
        |j        › d�|¬¦  «        |‚d}t          |||¦  «         	 |                     |¦  «         nº# t          j	        $ r=}t          j	        t          j	        j
        d|j        › d	|j        › d
�|¬¦  «        |‚d}~wt          $ r7}	t          j	        t          j	        j
        d|j        › d|	›�|¬¦  «        |	‚d}	~	ww xY wt          j	        t          j	        j
        |j        |¬¦  «        |‚Y d}~nd}~ww xY w|st          |||¦  «         dS dS # |st          |||¦  «         w w xY w)a¸  Release a lock through ``msvcrt.locking`` with ``LK_UNLCK``.

            If that fails with ``EACCES`` the unlock is retried through
            `Win32Locker.unlock`, which is how a lock taken by the shared
            path in `lock` gets released. When ``pywin32`` is not
            installed there is no fallback to retry with, so the original
            msvcrt failure is raised with a note naming the missing extra.

            Args:
                file_obj: The same file object, `fileno()` provider or
                    raw file descriptor that was passed to `lock`.

            Raises:
                ~portalocker.exceptions.LockException: ``msvcrt.locking``
                    failed with something other than ``EACCES``; or it failed
                    with ``EACCES`` and no fallback was available; or the
                    fallback itself failed, in which case the message reports
                    both failures.
            Fr=   r”   Nzn (the win32 unlock fallback is unavailable without pywin32; install it with: pip install "portalocker[win32]")rp   Tzmsvcrt unlock failed (z), and win32 fallback failed (ú)z4), and win32 fallback failed with unexpected error: )r_   rl   r˜   r�   r�   r\   r™   rŽ   r   r}   r~   r   rb   r'   Ú	Exception)
r   r   r]   r€   r�   Útook_fallback_pathr‰   r›   Ú	win32_excÚ	final_excs
             r   r'   zMsvcrtLocker.unlock¹  s—  € õ( '<¸HÑ&EÔ&EÑ#ˆB�
˜GØ!&Ðð2GÝ”ØØÔ$ ZÔ0ØÔ,ñô ð ñ øõ
 ð )ñ )ð )Ø”9 ’?�?Ø#'Ô#5�LØ#Ð+õ )Ô6Ý&Ô4Ô@Ø"œ|ð Gð Gð Gð  (ðñ ô ð  #ð#ð *.Ð&õ .¨b°*¸gÑFÔFÐFð)Ø$×+Ò+Ø$ñô ð ð øõ &Ô3ð )ð )ð )Ý(Ô6Ý&Ô4Ô@ðL°S´\ð Lð LØ6?Ô6HðLð Lð Là'ð	ñ ô ð
  )ð)øøøøõ %ð )ð )ð )Ý(Ô6Ý&Ô4Ô@ð-°S´\ð -ð -à(ð-ð -ð  (ðñ ô ð  )ð)øøøøð)øøøõ %Ô2Ý"Ô0Ô<ØœØ#ðñ ô ð ð	ð'ð ð ð ð øøøøð%)øøøðV *ð GÝ-¨b°*¸gÑFÔFÐFÐFÐFðGð GøÐ)ð GÝ-¨b°*¸gÑFÔFÐFÐFðGøøøs]   —&? ½F ¿E;Á
AE6Â!B7Â6E6Â7EÃ8C>Ã>EÄ2D=Ä=EÅ/E6Å1F Å6E;Å;F ÆF+rŠ   )r   r   r   r   rd   r‹   Údictrš   rF   r�   rj   r	   r   r   r%   r'   r   r   r   r�   r�   9  sà   € € € € € € ð	ð 	ð # TÑ)Ð)Ð)Ñ)Ø˜#˜s˜(”^Ð#Ð#Ñ#Ø#*Ð˜SÐ*Ð*Ñ*ð	Bð 	Bð 	Bð 	Bð6V	C Ô!3ð V	C¸Ið V	CÈ$ð V	Cð V	Cð V	Cð V	CðpI	G 5Ô#5ð I	G¸$ð I	Gð I	Gð I	Gð I	Gð I	Gð I	Gr   r�   Úfilec                 ó¾   — t          |¦  «         t          t          ¦  «        }|€%t          dt	          t          ¦  «        › d�¦  «        ‚ |d         | |¦  «         dS )aŠ  Lock `file` with the locker named by the module-level `LOCKER`.

        This is the Windows implementation of `portalocker.lock`; the
        POSIX branch of this module defines a separate one. `LOCKER`
        defaults to the `MsvcrtLocker` class and may be replaced with a
        `BaseLocker` instance, a `BaseLocker` subclass, or a
        ``(lock, unlock)`` tuple. The bare-callable form that POSIX
        accepts has no counterpart here, because there is no ``fcntl``.

        Args:
            file: An open file object, an object exposing `fileno()`, or a
                raw file descriptor.
            flags: The `LockFlags` combination to apply. Note that
                `LockFlags.SHARED` needs ``pywin32``; see `MsvcrtLocker`.

        Raises:
            RuntimeError: `flags` is a rejected combination - it carries
                `LockFlags.UNBLOCK`, combines `LockFlags.SHARED` with
                `LockFlags.EXCLUSIVE`, or names no lock type at all. See
                `_validate_lock_flags`.
            TypeError: `LOCKER` holds none of the supported forms - most
                likely a plain callable copied from POSIX code.
            ~portalocker.exceptions.AlreadyLocked: The lock is held by someone
                else and `LockFlags.NON_BLOCKING` was set.
            ~portalocker.exceptions.LockException: The locking call failed for
                any other reason.

        Example:
            .. code-block:: python

                import portalocker

                with open('example.txt', 'w') as fh:
                    portalocker.lock(fh, portalocker.LockFlags.EXCLUSIVE)
                    portalocker.unlock(fh)
        NúmLOCKER must be a BaseLocker instance, a tuple of lock and unlock functions, or a subclass of BaseLocker, got ú.r   )r9   r3   r(   Ú	TypeErrorr.   ©r¤   r   r0   s      r   r%   r%     sr   € õJ 	˜UÑ#Ô#Ð#Ý#¥FÑ+Ô+ˆØˆ<åð'å�F‘|”|ð'ð 'ð 'ñô ð ð
 	ˆˆQŒ��eÑÔÐÐÐr   c                 óž   — t          t          ¦  «        }|€%t          dt          t          ¦  «        › d�¦  «        ‚ |d         | ¦  «         dS )a  Release a lock taken by the Windows `lock`.

        Resolves `LOCKER` the same way `lock` does, so a lock and its
        unlock always go to the same implementation as long as `LOCKER`
        is not reassigned in between.

        Args:
            file: The same file object, `fileno()` provider or raw file
                descriptor that was passed to `lock`.

        Raises:
            TypeError: `LOCKER` holds none of the supported forms.
            ~portalocker.exceptions.LockException: The unlocking call failed.
        Nr¦   r§   r   )r3   r(   r¨   r.   ©r¤   r0   s     r   r'   r'   6  s\   € õ $¥FÑ+Ô+ˆØˆ<Ýð'å�F‘|”|ð'ð 'ð 'ñô ð ð
 	ˆˆQŒ�‰Œˆˆˆr   c                   óÀ   — e Zd ZU dZdZeeej        z  ege	f         dz  e
d<   edeeej        z  ege	f         fd„¦   «         Zdedefd„Zdededdfd	„Zdeddfd
„ZdS )ÚPosixLockeraT  Locker implementation using the `LOCKER` constant.

        Wraps a ``fcntl``-style callable with the parts every POSIX lock
        needs: extracting the file descriptor, rejecting a non-blocking
        request that names no lock type, and translating ``OSError`` into
        `AlreadyLocked` / `LockException`.

        Which callable it wraps depends on the class. `FlockLocker` and
        `LockfLocker` bind ``fcntl.flock`` and ``fcntl.lockf``
        respectively, while a plain `PosixLocker` follows the module-level
        `LOCKER` - so `LOCKER` selects the primitive for the default
        dispatch, and the subclasses pin one regardless of it. Both
        primitives are exposed because a program usually has to match
        whatever the other processes sharing the file already use. The
        subclasses honouring their own callable is a 4.0.0 fix; before
        that they silently used the global `LOCKER` too.

        Example:
            >>> import fcntl
            >>> from portalocker.portalocker import (
            ...     FlockLocker,
            ...     LockfLocker,
            ...     PosixLocker,
            ... )
            >>> PosixLocker().locker is fcntl.flock
            True
            >>> FlockLocker().locker is fcntl.flock
            True
            >>> LockfLocker().locker is fcntl.lockf
            True
        NÚ_lockerr   c                 ó°   — | j         €@t          t          t          t          j        z  t          gt          f         t          ¦  «        S | j         €J ‚| j         S )a�  The ``fcntl``-style callable this locker locks with.

            Subclasses set `_locker` at class level and always return
            that. An unbound `PosixLocker` returns the module-level
            `LOCKER`, read on every access, so reassigning `LOCKER`
            redirects existing instances too.

            Returns:
                A callable taking ``(fd, operation)``, normally
                ``fcntl.flock`` or ``fcntl.lockf``.

            Example:
                >>> import fcntl
                >>> from portalocker.portalocker import LockfLocker
                >>> LockfLocker().locker is fcntl.lockf
                True
            )r®   r   r   rF   r	   rW   r   r(   r’   s    r   r*   zPosixLocker.lockerx  sS   € ð& Œ|Ð#õ
 Ý�c¥E¤OÑ3µSÐ9½3Ð>Ô?Åñô ð ð ”<Ð+Ð+Ð+Ø”<Ðr   r   c                 ó¾   — t          |t          ¦  «        r|S t          |d¦  «        r(t          |j        ¦  «        r|                     ¦   «         S t          d¦  «        ‚)aî  Extract the file descriptor the ``fcntl`` call needs.

            Args:
                file_obj: A raw file descriptor, returned unchanged, or
                    any object with a callable `fileno()`.

            Returns:
                The integer file descriptor to lock.

            Raises:
                TypeError: `file_obj` is neither an `int` nor exposes a
                    callable `fileno()`.

            Example:
                >>> from portalocker.portalocker import PosixLocker
                >>> locker = PosixLocker()
                >>> locker._get_fd(0)
                0
                >>> with open('example.txt', 'w') as fh:
                ...     locker._get_fd(fh) == fh.fileno()
                True
            rR   zWArgument 'file_obj' must be an int, an IO object with fileno(), or implement HasFileno.)r,   rF   ÚhasattrÚcallablerR   r¨   r   s     r   Ú_get_fdzPosixLocker._get_fd™  sg   € õ. ˜(¥CÑ(Ô(ð Ø�å˜ 8Ñ,Ô,ð 
µ¸(¼/Ñ1JÔ1Jð 
Ø—’Ñ(Ô(Ð(õ  ð=ñô ð r   r   c                 ó,  — |t           j        z  r+|t           j        t           j        z  z  st	          d¦  «        ‚|                      |¦  «        }	 |                      ||¦  «         dS # t          $ rn}|j        t          j	        t          j
        fv r%t          j        |t          |¦  «        |¬¦  «        |‚t          j        |t          |¦  «        |¬¦  «        |‚d}~wt          $ r*}t          j        |t          |¦  «        |¬¦  «        |‚d}~ww xY w)aS  Lock `file_obj` by calling `locker` with `flags`.

            Args:
                file_obj: An open file object, an object exposing
                    `fileno()`, or a raw file descriptor.
                flags: The `LockFlags` combination to apply.
                    `LockFlags.NON_BLOCKING` only says *how* to wait, so
                    it has to be combined with `LockFlags.SHARED` or
                    `LockFlags.EXCLUSIVE` to say what to take.

            Raises:
                RuntimeError: `LockFlags.NON_BLOCKING` was passed on its
                    own, without `LockFlags.SHARED` or
                    `LockFlags.EXCLUSIVE`.
                ~portalocker.exceptions.AlreadyLocked: ``fcntl`` reported
                    ``EACCES`` or ``EAGAIN``, i.e. someone else holds a
                    conflicting lock.
                ~portalocker.exceptions.LockException: Any other ``OSError``,
                    or the ``EOFError`` seen on some network filesystems.

            Note:
                The full flag validation (rejecting UNBLOCK-bearing
                combinations, ``SHARED | EXCLUSIVE`` and flag sets naming
                no lock type) lives in the module-level `portalocker.lock`
                by design. Calling this method directly skips that guard,
                so ``lock(fh, LockFlags.UNBLOCK)`` on a bare locker still
                reaches ``fcntl`` and silently releases the lock.

            Example:
                >>> from portalocker import LockFlags
                >>> from portalocker.portalocker import PosixLocker
                >>> locker = PosixLocker()
                >>> with open('example.txt', 'w') as fh:
                ...     locker.lock(
                ...         fh, LockFlags.EXCLUSIVE | LockFlags.NON_BLOCKING
                ...     )
                ...     locker.unlock(fh)
            zcWhen locking in non-blocking mode on POSIX, the SHARED or EXCLUSIVE flag must be specified as well.rp   N)r   ru   r7   r8   r6   r³   r*   r\   r™   ÚEACCESÚEAGAINr   r|   rš   r}   ÚEOFError)r   r   r   r]   r…   s        r   r%   zPosixLocker.lock¿  sT  € ðN �	Ô.Ñ.ð ¸ÝÔ ¥9Ô#6Ñ6ñ9ð õ #ðNñô ð ð
 —’˜hÑ'Ô'ˆBð!Ø—’˜B Ñ&Ô&Ð&Ð&Ð&øÝð %ð %ð %Ø”?¥u¤|µU´\Ð&BÐBÐBÝ$Ô2Ø!Ý˜I™œØ#ðñ ô ð %ð	%õ %Ô2Ø!Ý˜I™œØ#ðñ ô ð %ð	%øøøøõ
 ð !ð !ð !Ý Ô.ØÝ˜	‘N”NØðñ ô ð !ð	!øøøøð!øøøs%   ÁA) Á)
DÁ3A)CÃDÃ)%DÄDc                 óD  — |                       |¦  «        }	 |                      |t          j        ¦  «         dS # t          $ r*}t          j        |t          |¦  «        |¬¦  «        |‚d}~wt          $ r*}t          j        |t          |¦  «        |¬¦  «        |‚d}~ww xY w)a$  Release a lock by calling `locker` with `LockFlags.UNBLOCK`.

            Failures are translated the same way `lock` translates them,
            matching the Windows lockers: the original ``OSError`` goes
            into ``args[0]`` and onto ``__cause__``, so its ``errno``
            stays reachable.

            Args:
                file_obj: The same file object, `fileno()` provider or raw
                    file descriptor that was passed to `lock`.

            Raises:
                ~portalocker.exceptions.LockException: The unlock call
                    failed, for example with ``EBADF`` when the
                    descriptor was already closed. Wraps the ``OSError``
                    that ``fcntl`` raised, or the ``EOFError`` some NFS
                    setups produce, just like `lock` does.

            .. versionchanged:: 4.2.0
                Previously the raw ``OSError`` propagated unchanged,
                unlike on Windows where unlock failures have always been
                wrapped in `LockException`.
            rp   N)	r³   r*   r   r5   r\   r   r}   rš   r·   )r   r   r]   r…   s       r   r'   zPosixLocker.unlock  sÊ   € ð0 —’˜hÑ'Ô'ˆBð!Ø—’˜B¥	Ô 1Ñ2Ô2Ð2Ð2Ð2øÝð !ð !ð !Ý Ô.ØÝ˜	‘N”NØðñ ô ð !ð	!øøøøõ
 ð !ð !ð !Ý Ô.ØÝ˜	‘N”NØðñ ô ð !ð	!øøøøð!øøøs!   — 9 ¹
BÁ%A(Á(BÁ5%BÂB)r   r   r   r   r®   r   rF   r	   rW   r   r‹   Úpropertyr*   ÚPosixFileArgumentr³   r   r%   r'   r   r   r   r­   r­   U  s  € € € € € € ð	ð 	ð@ GKˆ�˜3 ¤Ñ0°#Ð6¸Ð;Ô<¸tÑCÐJÐJÑJà	ð	 ˜H c¨E¬OÑ&;¸SÐ%AÀ3Ð%FÔGð 	 ð 	 ð 	 ñ 
Œð	 ð@$	Ð$5ð $	¸#ð $	ð $	ð $	ð $	ðLD	!Ð!2ð D	!¸9ð D	!Èð D	!ð D	!ð D	!ð D	!ðL&	!Ð#4ð &	!¸ð &	!ð &	!ð &	!ð &	!ð &	!ð &	!r   r­   c                   óV   — e Zd ZU dZej        Zeee	j
        z  egef         dz  ed<   dS )ÚFlockLockerz>FlockLocker is a PosixLocker implementation using fcntl.flock.Nr®   )r   r   r   r   ÚfcntlÚflockr®   r   rF   r	   rW   r   r‹   r   r   r   r¼   r¼   -  sT   € € € € € € ØLÐLð ŒKð 	�˜3 ¤Ñ0°#Ð6¸Ð;Ô<¸tÑCð 	
ð 	
ñ 	
ð 	
ð 	
r   r¼   c                   óV   — e Zd ZU dZej        Zeee	j
        z  egef         dz  ed<   dS )ÚLockfLockerz>LockfLocker is a PosixLocker implementation using fcntl.lockf.Nr®   )r   r   r   r   r½   Úlockfr®   r   rF   r	   rW   r   r‹   r   r   r   rÀ   rÀ   9  sT   € € € € € € ØLÐLð ŒKð 	�˜3 ¤Ñ0°#Ð6¸Ð;Ô<¸tÑCð 	
ð 	
ñ 	
ð 	
ð 	
r   rÀ   c                 ó®   — t          |¦  «         t          t          ¦  «        }|€t                               | |¦  «         dS  |d         | |¦  «         dS )aR	  Lock `file` with the locker named by the module-level `LOCKER`.

        This is the POSIX implementation of `portalocker.lock`; the
        Windows branch of this module defines a separate one. Every
        `LockerType` form is accepted:

        - a bare ``fcntl``-style callable, the default (``fcntl.flock``),
          which is routed through a shared `PosixLocker` so that it still
          gets descriptor extraction, flag validation and error
          translation;
        - a ``(lock, unlock)`` tuple, a `BaseLocker` instance, or a
          `BaseLocker` subclass, all resolved by `_resolve_locker_pair`.

        Honouring all of those forms is a 4.0.0 fix; earlier versions only
        honoured the bare callable here.

        Args:
            file: An open file object, an object exposing `fileno()`, or a
                raw file descriptor.
            flags: The `LockFlags` combination to apply.
                `LockFlags.NON_BLOCKING` must be combined with
                `LockFlags.SHARED` or `LockFlags.EXCLUSIVE`.

        Raises:
            RuntimeError: `flags` is a rejected combination - it carries
                `LockFlags.UNBLOCK`, combines `LockFlags.SHARED` with
                `LockFlags.EXCLUSIVE`, or names no lock type at all. See
                `_validate_lock_flags`.
            ~portalocker.exceptions.AlreadyLocked: The lock is held elsewhere
                and `LockFlags.NON_BLOCKING` was set.
            ~portalocker.exceptions.LockException: The locking call failed for
                another reason.
            RuntimeError: `LockFlags.NON_BLOCKING` was passed on its own,
                without `LockFlags.SHARED` or `LockFlags.EXCLUSIVE`. The
                built-in lockers reject this before touching the file,
                because on POSIX the flag only says *how* to wait and not
                what kind of lock to take.

        The exception translation above is provided by the built-in
        lockers. A raw ``(lock, unlock)`` callable tuple assigned to
        `LOCKER` is invoked as-is and owns its own error translation, so
        an untranslated ``OSError`` can escape it.

        Example:
            >>> import portalocker
            >>> with open('example.txt', 'w') as fh:
            ...     portalocker.lock(fh, portalocker.LockFlags.EXCLUSIVE)
            ...     portalocker.unlock(fh)
        Nr   )r9   r3   r(   Ú_posix_locker_instancer%   r©   s      r   r%   r%   J  s]   € õd 	˜UÑ#Ô#Ð#Ý#¥FÑ+Ô+ˆØˆ<Ý"×'Ò'¨¨eÑ4Ô4Ð4Ð4Ð4àˆD�ŒG�D˜%Ñ Ô Ð Ð Ð r   c                 óŒ   — t          t          ¦  «        }|€t                               | ¦  «         dS  |d         | ¦  «         dS )a�  Release a lock taken by the POSIX `lock`.

        Resolves `LOCKER` the same way `lock` does, so a lock and its
        unlock always go to the same implementation as long as `LOCKER`
        is not reassigned in between.

        Args:
            file: The same file object, `fileno()` provider or raw file
                descriptor that was passed to `lock`.

        Raises:
            ~portalocker.exceptions.LockException: The unlock call failed,
                wrapping the original ``OSError`` (reachable through
                ``args[0]`` and ``__cause__``), matching what the
                Windows unlock has always raised. As with `lock`, a raw
                ``(lock, unlock)`` callable tuple assigned to `LOCKER`
                owns its own error translation and can leak an
                untranslated ``OSError`` instead.

        .. versionchanged:: 4.2.0
            Previously a failing unlock raised the raw ``OSError``.

        Example:
            >>> import portalocker
            >>> with open('example.txt', 'w') as fh:
            ...     portalocker.lock(fh, portalocker.LockFlags.EXCLUSIVE)
            ...     portalocker.unlock(fh)
        Nr   )r3   r(   rÃ   r'   r«   s     r   r'   r'   ƒ  sE   € õ: $¥FÑ+Ô+ˆØˆ<Ý"×)Ò)¨$Ñ/Ô/Ð/Ð/Ð/àˆD�ŒG�D‰MŒMˆMˆMˆMr   )2r   rP   rX   rU   Úcollections.abcr   r   r   Ú r   r   r	   r   ÚProtocolr   r   r!   rF   rW   r-   r.   Ú
LockerTyper‹   r)   r£   Úobjectr3   r9   rB   rš   rM   rI   rl   r   rV   r_   rb   rd   r�   r(   r%   r'   r™   r½   rº   r­   r¼   rÀ   r¾   rÃ   r   r   r   ú<module>rÊ      sá  ððð ð ð0 
€	€	€	Ø 	€	€	€	Ø €€€Ø $Ð $Ð $Ð $Ð $Ð $ðð ð ð ð ð ð ð ð
 +Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *ð Ô€	ðð ð ð ð �6”?ñ ô ð ð8ð ð ð ð �V”_ñ ô ð ð,2"ð 2"ð 2"ð 2"ð 2"ñ 2"ô 2"ð 2"ðp ˆc�E”OÑ# SÐ)¨3Ð.Ô/àˆL˜.Ð(Ô)ñ*ð ñ	ð ˆ:Ôñð ð 	Ð Ð Ñ ð 9;Ð �4˜˜ZÔ(¨*Ð4Ô5Ð :Ð :Ñ :ðØðà
ˆ<˜Ð'Ô(¨4Ñ/ðð ð ð ð>+
 	ð +
¨dð +
ð +
ð +
ð +
ðf ØØØØð.ð .Ð ˜D  c œNð ð ñ ð¨fð ¸¸cÀ3¸h¼ð ð ð ð ð> „7ˆd‚?€?ð €M€M€Mð3&ØÔ$ð3&à	ˆs�F”I˜c”N TÑ)¨3°©:Ð5Ô	6ð3&ð 3&ð 3&ð 3&ðj4Øð4à”Y˜s”^ dÑ*ð4ð ˜D‘jð4ð 
ð	4ð 4ð 4ð 4ð0CCð CCð CCð CCð CC�jñ CCô CCð CCðJIGð IGð IGð IGð IG�zñ IGô IGð IGðV €Fð.�5Ô%ð .¨ið .¸Dð .ð .ð .ð .ð`�UÔ'ð ¨Dð ð ð ð ð ð ð2 €L€L€LØ€L€L€Lð Ô*¨U¬_Ñ<ÐðV!ð V!ð V!ð V!ð V!�jñ V!ô V!ð V!ðp

ð 

ð 

ð 

ð 

�kñ 

ô 

ð 

ð
ð 
ð 
ð 
ð 
�kñ 
ô 
ð 
ð Œ[€Fà(˜[™]œ]Ðð7!�5Ô%ð 7!¨ið 7!¸Dð 7!ð 7!ð 7!ð 7!ðr!�UÔ'ð !¨Dð !ð !ð !ð !ð !ð !r   