§
    ´¯¸j<  ã                  óÜ  — 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
 ej        e¦  «        j        j        Zedz  Zedz  Zedz  dz  Z ej        d¦  «        Z ej        d¦  «        Z ej        d	¦  «        Z ej        d
¦  «        ZdZ ej        e¦  «        Zd(d„Zd)d„Zd*d+d„Zd,d„Zd-d„Zd.d"„Z d/d%„Z!ed&k    r" ej"        ej#        ¬'¦  «          e¦   «          dS dS )0aP  Command-line interface for the ``portalocker`` package.

Invoked as ``python -m portalocker``. The only subcommand is `combine`,
which bundles the package into a single vendorable ``portalocker.py``
file; see `combine` for what that transform does and why it exists.

Every file this module reads while doing that -- the package's own
modules, ``README.md`` and ``LICENSE`` -- is opened with
``encoding='ascii'`` (see `_read_file` and `combine`). That means the
entire ``portalocker`` source tree, plus ``README.md`` and ``LICENSE``,
must stay ASCII-only: a non-ASCII character in any of them makes this
module raise `UnicodeDecodeError` instead of silently mis-decoding it.
``portalocker_tests/test_combined.py`` asserts the combined output can
still be produced, which is how a stray non-ASCII character elsewhere in
the package would be caught.
é    )ÚannotationsNÚportalockerÚdistzportalocker.pyz(?P<names>[^()]+)$z=^from \.(?P<from>.*?) import (?P<paren>\(?)(?P<names>[^()]+)$z^(?P<name>\w+) = \1\n$z!if (?:typing\.)?TYPE_CHECKING\s*:z'''
{}
'''

Úpathúpathlib.PathÚ	exceptionÚUnicodeDecodeErrorÚreturnÚNonec                ó²   — |j         \  }}}}}d}|t          ||z
  d¦  «        ||z   …         }t                               d| › d|› d|› d|› d|›�
¦  «         dS )	a2  Log a snippet of `path` around the bytes that failed to decode.

    Shared by every ASCII read in this module (see `_read_text_ascii`),
    so a stray non-ASCII byte in a source file, ``README.md`` or
    ``LICENSE`` always produces an error naming the offending file and
    showing the surrounding context instead of a bare traceback.

    Args:
        path: The file that failed to decode, named in the log message.
        exception: The decode failure. Its ``args`` carry the undecoded
            bytes and the offset range of the offending byte(s).
    éd   r   zInvalid encoding for z: z
 at byte (ú:z)
Snippet: N)ÚargsÚmaxÚloggerÚerror)	r   r   Ú_ÚtextÚ
start_byteÚend_byter   ÚoffsetÚsnippets	            úd/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/portalocker/__main__.pyÚ_log_decode_errorr   2   s¢   € ð  ,5¬>Ñ(€A€tˆZ˜ 5à€FØ•3�z FÑ*¨AÑ.Ô.°¸FÑ1BÐBÔC€GÝ
‡L‚Lð	  ð 	 ð 	 ¨ð 	 ð 	 Øð	 ð 	 Ø!ð	 ð 	 àð	 ð 	 ñô ð ð ð ó    Ústrc                óê   — 	 |                       d¬¦  «        S # t          $ r}t          | |¦  «         ‚ d}~wt          $ r2}t                               d| › �¦  «         t          d¦  «        |‚d}~ww xY w)aU  Read `path` as ASCII, logging a clear error on failure.

    Args:
        path: The file to read.

    Returns:
        The file's text, decoded as ASCII with universal newlines.

    Raises:
        UnicodeDecodeError: `path` contains a byte that is not valid
            ASCII. The offending snippet is logged through
            `_log_decode_error` before this is re-raised.
        SystemExit: `path` does not exist. The missing file is named in
            a logged error and the exit status is 1, instead of the raw
            ``FileNotFoundError`` traceback the CLI used to die with.
    Úascii)ÚencodingNzInput file not found: é   )Ú	read_textr	   r   ÚFileNotFoundErrorr   r   Ú
SystemExit)r   r   s     r   Ú_read_text_asciir$   M   sŒ   € ð"+Ø�~Š~ wˆ~Ñ/Ô/Ð/øÝð ð ð Ý˜$ 	Ñ*Ô*Ð*ØøøøøÝð +ð +ð +Ý�ŠÐ4¨dÐ4Ð4Ñ5Ô5Ð5Ý˜‰mŒm Ð*øøøøð+øøøs   ‚ ˜
A2¢3³A2Á -A-Á-A2Úargvútyping.Sequence[str] | Nonec                ó`  — t          j        ¦   «         }|                     d¬¦  «        }|                     dd¬¦  «        }|                     ddt
          j        t          ¬¦  «         |                     t          ¬	¦  «         | 
                    | ¦  «        }|                     |¦  «         d
S )a
  Parse CLI arguments and dispatch to the selected subcommand.

    Currently the only subcommand is ``combine`` (see `combine`).

    Args:
        argv: Argument vector to parse, excluding the program name.
            Forwarded to `argparse.ArgumentParser.parse_args`, so it
            defaults to `sys.argv[1:]` when `None`. Tests pass an
            explicit list, e.g. ``['combine', '--output-file', ...]``,
            instead of relying on `sys.argv`.

    Raises:
        SystemExit: Argument parsing failed, or no subcommand was
            given -- the ``combine`` subparser is marked required.

    Example:
        .. code-block:: console

            $ python -m portalocker combine
            $ python -m portalocker combine --output-file dist/portalocker.py
    T)ÚrequiredÚcombinezZCombine all Python files into a single unified `portalocker.py` file for easy distribution)Úhelpz--output-filez-o)ÚtypeÚdefault)ÚfuncN)ÚargparseÚArgumentParserÚadd_subparsersÚ
add_parserÚadd_argumentÚpathlibÚPathÚ_default_output_pathÚset_defaultsr)   Ú
parse_argsr-   )r%   ÚparserÚ
subparsersÚcombine_parserr   s        r   Úmainr;   h   s¶   € õ, Ô$Ñ&Ô&€Fà×&Ò&°Ð&Ñ5Ô5€JØ×*Ò*Øð%ð +ñ ô €Nð
 ×ÒØØÝŒ\Ý$ð	  ñ ô ð ð ×Ò¥WÐÑ-Ô-Ð-Ø×Ò˜TÑ"Ô"€DØ‡I‚Iˆd�O„O€O€O€Or   Ú
seen_filesúset[pathlib.Path]útyping.Iterator[str]c           	   #  ó  K  — | |v rdS t          ¦   «         }|                     | ¦  «         d}d}d}d}t          j        t	          | ¦  «        ¦  «        D �]6}d|v rŒ|                     ¦   «         }|dt          |¦  «        t          |¦  «        z
  …         }	|r:|                     ¦   «         rt          |	¦  «        |k    rt          ||¦  «        V — Œd}|s>t           
                    |¦  «        r$d}t          |	¦  «        }t          ||¦  «        V — ŒÁ|r>d|v r|                     dd¦  «        d         }d}Œæt           
                    |¦  «        }
nt           
                    |¦  «        }
|
�r|s7t          |
                     d¦  «        ¦  «        }|
                     d	¦  «        }|rF|                     |¦  «         t!          t#          t$          |› d
�z  |¦  «        |	¦  «        E d{V —† �ŒŸ|
                     d¦  «                             d¦  «        D ]Z}|                     ¦   «         }|                     |¦  «         t!          t#          t$          |› d
�z  |¦  «        |	¦  «        E d{V —† Œ[�Œ$t          ||¦  «        V — �Œ8dS )a  Yield ``path``'s lines with relative imports inlined recursively.

    Reads ``path`` with ``encoding='ascii'`` (see the module docstring
    for why every source file under `src_path` must be ASCII). A line
    matching a relative import -- ``from .foo import bar`` or its
    parenthesised multi-line form -- is not emitted as-is; instead, the
    module(s) it names are read in turn (recursively, through this same
    function) and their lines are yielded in its place, re-indented to
    match if the import itself was indented. This is what lets `combine`
    produce a single file: a relative import would not resolve once the
    referenced module is no longer a separate file.

    ``if TYPE_CHECKING:`` blocks are the one exception: they are emitted
    verbatim rather than inlined, so the runtime guard their else-branch
    relies on is preserved. ``from __future__ import ...`` lines are
    dropped, since `combine` writes a single
    ``from __future__ import annotations`` once for the whole output.

    Args:
        path: The module to read.
        seen_files: Modules already emitted, keyed by resolved path.
            Mutated in place: `path` is added to it on entry, and a
            module reached through an inlined import is skipped (this
            generator yields nothing and returns) once its path is
            already present here, so a module referenced from more than
            one place is only inlined once.

    Yields:
        Lines of `path`'s source, in order, with relative imports
        replaced by the recursively inlined source of the module(s)
        they named.

    Raises:
        UnicodeDecodeError: `path` contains a byte that is not valid
            ASCII. The offending snippet is logged before this is
            re-raised.
    NFr   Ú
__future__Tú)r    ÚparenÚfromz.pyÚnamesú,)ÚsetÚaddÚioÚStringIOr$   ÚlstripÚlenÚstripÚ_clean_lineÚ_TYPE_CHECKING_REÚmatchÚsplitÚ	_NAMES_REÚ_RELATIVE_IMPORT_REÚboolÚgroupÚ	_reindentÚ
_read_fileÚsrc_path)r   r<   rD   rB   Úfrom_Úin_type_checkingÚtype_checking_indentÚlineÚstrippedÚindentrO   Únames               r   rV   rV   ’   sý  è è € ðR ˆzÐÐØˆå‘e”e€EØ‡N‚N�4ÑÔÐØ€EØ€EØÐØÐÝ”Õ,¨TÑ2Ô2Ñ3Ô3ð 8+ñ 8+ˆØ˜4ÐÐØà—;’;‘=”=ˆØÐ1�˜D™	œ	¥C¨¡M¤MÑ1Ð1Ô2ˆð ð 	Ø—’Ñ Ô ð	Ý$'¨¡K¤KÐ2FÒ$FÐ$Få˜d EÑ*Ô*Ð*Ð*Ð*ØØ ÐØð 	Õ*×0Ò0°Ñ:Ô:ð 	Ø#ÐÝ#& v¡;¤;Ð Ý˜d EÑ*Ô*Ð*Ð*Ð*Øàð 	8Ø�dˆ{ˆ{Ø—z’z # qÑ)Ô)¨!Ô,�Ø�Øå—O’O DÑ)Ô)ˆEˆEå'×-Ò-¨hÑ7Ô7ˆEàñ 	+Øð ,Ý˜UŸ[š[¨Ñ1Ô1Ñ2Ô2�ØŸš FÑ+Ô+�ð
 ð Ø—	’	˜%Ñ Ô Ð Ý$Ý�x¨U¨-¨-¨-Ñ7¸ÑDÔDØñô ð ð ð ð ð ð ð ñ ð
 "ŸKšK¨Ñ0Ô0×6Ò6°sÑ;Ô;ð ð �DØŸ:š:™<œ<�DØ—I’I˜d‘O”O�OÝ(Ý"¥8°¨l¨l¨lÑ#:¸JÑGÔGØñ ô  ð ð ð ð ð ð ð ð ñõ ˜d EÑ*Ô*Ð*Ð*Ð*Ñ*ðq8+ð 8+r   r[   rD   úset[str]c                óš   — |r/d                      |¦  «        }t          j        d|› d�d| ¦  «        } t                               d| ¦  «        S )aö  Strip inlined-module qualifiers and useless self-assignments.

    For example, with ``names={'constants'}``, the line
    ``x = constants.LockFlags.EXCLUSIVE\n`` becomes
    ``x = LockFlags.EXCLUSIVE\n``; with ``names=set()``, the line
    ``spam = spam\n`` becomes ``''``.

    Note:
        Not a doctest: pytest's ``--doctest-modules`` collector never
        imports files named ``__main__.py``, so an executable example
        here would silently never run.

    Args:
        line: A source line being emitted as-is (i.e. it did not itself
            match a relative import) into the combined output.
        names: Names of modules that `_read_file` has already inlined
            into the current output, for this line's source module.
            Used to turn a qualified reference such as
            ``constants.LockFlags`` into ``LockFlags``, since once a
            module has been inlined it is no longer a separate module
            to qualify names against.

    Returns:
        `line`, with any ``<name>.`` prefix removed for every `name` in
        `names`, and then with a resulting useless self-assignment
        (``spam = spam``, left behind when a qualified name turned out
        to equal its own unqualified form) removed entirely.
    ú|z\b(z)\.Ú )ÚjoinÚreÚsubÚ_USELESS_ASSIGNMENT_RE)r[   rD   Újoined_namess      r   rM   rM   ÿ   sR   € ð< ð :Ø—x’x ‘”ˆÝŒvÐ.˜\Ð.Ð.Ð.°°DÑ9Ô9ˆõ "×%Ò% b¨$Ñ/Ô/Ð/r   Úlinesr]   c              #  óh   K  — |s
| E d{V —† dS | D ] }|                      ¦   «         r|› |› �n|V — Œ!dS )a!  Prefix each non-blank inlined line with ``indent``.

    Used when a relative import is itself indented (e.g. the optional-redis
    guard's ``try`` block): the inlined module is emitted at that indentation
    so it stays inside the guard while preserving its own relative structure.
    N)rL   )rh   r]   r[   s      r   rU   rU   %  sr   è è € ð ð ØÐÐÐÐÐÐÐØˆØð :ð :ˆØ#'§:¢:¡<¤<Ð9�Ð˜ÐÐÐ°TÐ9Ð9Ð9Ð9ð:ð :r   r   úargparse.Namespacec           	     óT  — | j         }dt                               t          t          dz  ¦  «        ¦  «        t                               t          t          dz  ¦  «        ¦  «        g}t          ¦   «         }|                     t          t          dz  |¦  «        ¦  «         |j	         
                    dd¬¦  «         |                     d                     |¦  «        ¦  «         t                               d|› �¦  «         	 t          j        d	d
t#          |¦  «        gd¬¦  «         t          j        d	dddt#          |¦  «        gd¬¦  «         n*# t$          $ r t                               d¦  «         Y nw xY wt          j        t(          j        t#          |¦  «        g¦  «         dS )aÙ
  Bundle the package into a single vendorable ``portalocker.py`` file.

    This is the ``combine`` subcommand's implementation (see `main`). It
    exists for projects that cannot add ``portalocker`` as a dependency
    -- for example a vendoring or single-file-deployment constraint --
    and instead copy one generated file with the same public API into
    their own tree.

    Starting from ``portalocker/__init__.py``, the package's modules are
    read with `_read_file`, which inlines every relative import
    recursively (so the result has none left) while leaving
    ``TYPE_CHECKING`` blocks intact. That includes the optional
    ``try: from .redis import RedisLock`` guard in ``__init__.py``:
    ``redis.py`` is inlined the same way as any other sibling module,
    re-indented to stay inside the ``try``, so the combined file binds
    `RedisLock` the same way the package does -- to the stub class that
    raises ``ImportError`` on construction if importing it fails.

    Every module under `src_path`, plus ``README.md`` and ``LICENSE``,
    is read with ``encoding='ascii'`` (see the module docstring): all of
    them must be ASCII-only or this raises `UnicodeDecodeError`.
    ``README.md`` and ``LICENSE`` are also written near the top of the
    output, each wrapped in a triple-quoted string, for reference; they
    are not the output file's docstring, since the single
    ``from __future__ import annotations`` line this function writes
    first has to stay the first statement.

    All inputs are read and assembled in memory first, and the output
    file is only opened once the assembly has succeeded. Writing first
    used to truncate ``--output-file`` before the first input was read,
    so a decode failure destroyed a pre-existing build. A plain write is
    deliberate here: ``--output-file`` legitimately overwrites its
    previous build, which is exactly the no-replace semantic
    `portalocker.utils.open_atomic` exists to forbid.

    If the ``ruff`` command is available, the output is formatted and
    lint-fixed in place; if not, that step is skipped with a warning.
    Either way, the output is then executed once with `sys.executable`.
    That run's exit status is not checked, so it surfaces problems in
    the log rather than failing `combine` itself.

    Args:
        args: Parsed CLI namespace; only `args.output_file` is used.
            Populated by `main` via the ``combine`` subparser, whose
            ``--output-file``/``-o`` option defaults to
            `_default_output_path` (``dist/portalocker.py``).

    Note:
        The combined file still needs the ``redis`` package installed
        for `RedisLock` to work: combining inlines the code that binds
        to ``redis``, not ``redis`` itself.
    z#from __future__ import annotations
z	README.mdÚLICENSEz__init__.pyT)ÚparentsÚexist_okrb   zWrote combined file to ÚruffÚformaté   )ÚtimeoutÚcheckz--fixz
--fix-onlyz<Ruff is not installed. Skipping linting and formatting step.N)Úoutput_fileÚ_TEXT_TEMPLATErp   r$   Ú	base_pathrF   ÚextendrV   rW   ÚparentÚmkdirÚ
write_textrc   r   ÚinfoÚ
subprocessÚrunr   r"   ÚwarningÚsysÚ
executable)r   Úoutput_pathÚpartsr<   s       r   r)   r)   5  sŸ  € ðj !%Ô 0€Kð 	/Ý×ÒÕ.­y¸;Ñ/FÑGÔGÑHÔHÝ×ÒÕ.­y¸9Ñ/DÑEÔEÑFÔFð€Eõ %(¡E¤E€JØ	‡L‚L•�H }Ñ4°jÑAÔAÑBÔBÐBàÔ×Ò T°DÐÑ9Ô9Ð9Ø×Ò˜2Ÿ7š7 5™>œ>Ñ*Ô*Ð*å
‡K‚KÐ7¨+Ð7Ð7Ñ8Ô8Ð8ð	
ÝŒ˜ ­#¨kÑ*:Ô*:Ð;ÀQÐGÑGÔGÐGÝŒØ�W˜g |µS¸Ñ5EÔ5EÐFØð	
ñ 	
ô 	
ð 	
ð 	
øõ ð 
ð 
ð 
Ý�ŠØJñ	
ô 	
ð 	
ð 	
ð 	
ð
øøøõ „N•C”N¥C¨Ñ$4Ô$4Ð5Ñ6Ô6Ð6Ð6Ð6s   ÄAE Å$E8Å7E8Ú__main__)Úlevel)r   r   r   r	   r
   r   )r   r   r
   r   )N)r%   r&   r
   r   )r   r   r<   r=   r
   r>   )r[   r   rD   r_   r
   r   )rh   r>   r]   r   r
   r>   )r   rj   r
   r   )$Ú__doc__r@   r   r.   rH   Úloggingr3   rd   r|   r   Útypingr4   Ú__file__rx   rv   rW   Ú	dist_pathr5   ÚcompilerQ   rR   rf   rN   ru   Ú	getLoggerÚ__name__r   r   r$   r;   rV   rM   rU   r)   ÚbasicConfigÚINFO© r   r   ú<module>r�      sï  ððð ð" #Ð "Ð "Ð "Ð "Ð "à €€€Ø 	€	€	€	Ø €€€Ø €€€Ø 	€	€	€	Ø Ð Ð Ð Ø 
€
€
€
Ø €€€àˆGŒL˜Ñ"Ô"Ô)Ô0€	Ø�}Ñ$€Ø˜Ñ€	Ø  6Ñ)Ð,<Ñ<Ð àˆBŒJÐ,Ñ-Ô-€	Ø �b”jØDñô Ð ð $˜œÐ$=Ñ>Ô>Ð Ø�B”JÐCÑDÔDÐ ð€ð 
ˆÔ	˜8Ñ	$Ô	$€ðð ð ð ð6+ð +ð +ð +ð6'ð 'ð 'ð 'ð 'ðTj+ð j+ð j+ð j+ðZ#0ð #0ð #0ð #0ðL:ð :ð :ð :ð S7ð S7ð S7ð S7ðl ˆzÒÐØ€GÔ˜gœlÐ+Ñ+Ô+Ð+Ø€D�F„F€F€F€Fð Ðr   