ó
    ¯iJ<  ã                   ó0  • S r SSKrSSKrSSKJr  SSKJr  SSKJr  \	" \S\R                  5      r
S\4S jr\R                  \R                  -  4S	\4S
 jjrS	\S\4S jr\R$                  (       d  Sr\rSrSrSrSrS rO…\R4                  (       d  SrSrSrSrSrSr\" S5      rS rO\Sr\r\R8                  (       a  SrOSrSr\R8                  (       a  SrOSrSr\R:                  (       a  \" S5      rS rO\" S5      rS r\" S\-   S -   \-   S!-   \-   S"-   \-   S#-   \-   S$-   \-   S%-   \-   S&-   \-   S'-   5      r\" S(\-   S)-   \-   S*-   5      rS+\4S, jr S-\S.\S/\4S0 jr!S-\S.\S/\"4S1 jr#S.\S/\"4S2 jr$S8S3\%S.\S/\&4S4 jjr'S.\S/\&4S5 jr(S6\4S7 jr)g)9aX  
Tools for searching bytecode for key statements that indicate the need for additional resources, such as data files
and package metadata.

By *bytecode* I mean the ``code`` object given by ``compile()``, accessible from the ``__code__`` attribute of any
non-builtin function or, in PyInstallerLand, the ``PyiModuleGraph.node("some.module").code`` attribute. The best
guide for bytecode format I have found is the disassembler reference: https://docs.python.org/3/library/dis.html

This parser implementation aims to combine the flexibility and speed of regex with the clarity of the output of
``dis.dis(code)``. It has not achieved the 2nd, but C'est la vie...

The biggest clarity killer here is the ``EXTENDED_ARG`` opcode which can appear almost anywhere and therefore needs
to be tiptoed around at every step. If this code needs to expand significantly, I would recommend an upgrade to a
regex-based grammar parsing library such as Reparse. This way, little steps like unpacking ``EXTENDED_ARGS`` can be
defined once then simply referenced forming a nice hierarchy rather than copied everywhere its needed.
é    N)ÚCodeType)ÚPattern)ÚcompatÚ
_all_opmapÚxc                 óP   • [         R                  " [        [        U    /5      5      $ )z?
Get a regex-escaped opcode byte from its human readable name.
)ÚreÚescapeÚbytesÚopmap)r   s    ÚHC:\des-py\RoboSAPF\venv\Lib\site-packages\PyInstaller\depend\bytecode.pyÚ_instruction_to_regexr   )   s   € ô �9Š9”UœE !™H˜:Ó&Ó'Ð'ó    Úpatternc                 óŠ   • [        U [        5      (       d   e[        R                  " SS U 5      n [        R                  " XS9$ )aª  
A regex-powered Python bytecode matcher.

``bytecode_regex`` provides a very thin wrapper around :func:`re.compile`.

  * Any opcode names wrapped in backticks are substituted for their corresponding opcode bytes.
  * Patterns are compiled in VERBOSE mode by default so that whitespace and comments may be used.

This aims to mirror the output of :func:`dis.dis`, which is far more readable than looking at raw byte strings.
s   `(\w+)`c                 ó:   • [        U S   R                  5       5      $ )Né   )r   Údecode)Úms    r   Ú<lambda>Ú bytecode_regex.<locals>.<lambda>@   s   € Ô'¨¨!©¯©«Ô6r   )Úflags)Ú
isinstancer   r	   ÚsubÚcompile)r   r   s     r   Úbytecode_regexr   0   sA   € ô �gœu×%Ñ%Ð%Ð%ô �fŠfØÙ6Øó€Gô
 �:Š:�gÑ+Ð+r   Ústringc              #   ó  #   • [        U[        5      (       d   e[        U5      nU R                  U5      n U HB  nUR	                  5       S-  S:X  a  Uv •  M   U R                  XR	                  5       S-   5      n  O   gMK  7f)a  
Call ``pattern.finditer(string)``, but remove any matches beginning on an odd byte (i.e., matches where
match.start() is not a multiple of 2).

This should be used to avoid false positive matches where a bytecode pair's argument is mistaken for an opcode.
é   r   r   N)r   r   Ú_cleanup_bytecode_stringÚfinditerÚstart)r   r   ÚmatchesÚmatchs       r   r!   r!   F   sƒ   é € ô �fœe×$Ñ$Ð$Ð$Ü% fÓ-€FØ×Ñ˜vÓ&€GØ
ÛˆEØ�{‰{‹}˜qÑ  AÓ%à”ð "×*Ñ*¨6·;±;³=À1Ñ3DÓE�Ùñ ð ñ ùs   ‚B Bs   `EXTENDED_ARG`s%   `LOAD_NAME`|`LOAD_GLOBAL`|`LOAD_FAST`s   `LOAD_ATTR`|`LOAD_METHOD`s   `LOAD_CONST`s0   `CALL_FUNCTION`|`CALL_METHOD`|`CALL_FUNCTION_EX`c                 ó   • U $ ©N© ©Úbytecodes    r   r    r    p   s   € Øˆr   s#   `EXTENDED_ARG`|`EXTENDED_ARG_QUICK`s"   `EXTENDED_ARG``EXTENDED_ARG_QUICK`s   `PRECALL`|`CALL_FUNCTION_EX`s   (`CACHE`.)|(..)c                 ó.   • [         R                  SU 5      $ ©Ns   \2©Ú_cache_instruction_filterr   r(   s    r   r    r    ƒ   s   € Ü(×,Ñ,¨V°XÓ>Ð>r   s8   `LOAD_NAME`|`LOAD_GLOBAL`|`LOAD_FAST`|`LOAD_FAST_BORROW`s   `LOAD_ATTR`s3   `LOAD_CONST`|`LOAD_SMALL_INT`|`LOAD_CONST_IMMORTAL`s   `CALL`|`CALL_FUNCTION_EX`s   (`CACHE`.)|(`PUSH_NULL`.)|(..)c                 ó.   • [         R                  SU 5      $ )Ns   \3r,   r(   s    r   r    r        ó   € Ü,×0Ñ0°¸ÓBÐBr   c                 ó.   • [         R                  SU 5      $ r+   r,   r(   s    r   r    r    ¥   r/   r   s¼   
    # Matches `global_function('some', 'constant', 'arguments')`.

    # Load the global function. In code with >256 of names, this may require extended name references.
    (
     (?:(?:s   ).)*
     (?:(?:sÎ   ).)
    )

    # For foo.bar.whizz(), the above is the 'foo', below is the 'bar.whizz' (one opcode per name component, each
    # possibly preceded by name reference extension).
    (
     (?:
       (?:(?:s   ).)*
       (?:sÈ   ).
     )*
    )

    # Load however many arguments it takes. These (for now) must all be constants.
    # Again, code with >256 constants may need extended enumeration.
    (
      (?:
        (?:(?:s   ).)*
        (?:sÉ   ).
      )*
    )

    # Call the function. If opcode is CALL_FUNCTION_EX, the parameter are flags. For other opcodes, the parameter
    # is the argument count (which may be > 256).
    (
      (?:(?:s   ).)*
      (?:s	   ).
    )
s:   (
    # Arbitrary number of EXTENDED_ARG pairs.
    (?:(?:sG   ).)*

    # Followed by some other instruction (usually a LOAD).
    [^s   ].
)Úextended_argsc                 ó:   • [         R                  U SSS2   S5      $ )a9  
Unpack the (extended) integer used to reference names or constants.

The input should be a bytecode snippet of the following form::

    EXTENDED_ARG    ?      # Repeated 0-4 times.
    LOAD_xxx        ?      # Any of LOAD_NAME/LOAD_CONST/LOAD_METHOD/...

Each ? byte combined together gives the number we want.
r   Nr   Úbig)ÚintÚ
from_bytes)r1   s    r   Úextended_argumentsr6   Û   s    € ô �>‰>˜-¨¨¨1¨Ñ-¨uÓ5Ð5r   ÚrawÚcodeÚreturnc                 ó¬  • [        U 5      nU S   [        S   :X  a  UR                  U   $ U S   [        S   :X  a  UR                  U   $ [        R
                  (       a"  U S   [        S   :X  a  UR                  US-	     $ [        R                  (       a"  U S   [        S   :X  a  UR                  US-	     $ [        R                  (       a  U S   [        S   :X  a  U$ [        R                  (       a  U S   [        S   :X  a  UR                  U   $ [        R                  (       a  U S   [        S	   :X  a  UR                  U   $ UR                  U   $ )
z+
Parse an (extended) LOAD_xxx instruction.
éþÿÿÿÚ	LOAD_FASTÚ
LOAD_CONSTÚLOAD_GLOBALr   Ú	LOAD_ATTRÚLOAD_SMALL_INTÚLOAD_CONST_IMMORTALÚLOAD_FAST_BORROW)	r6   r   Úco_varnamesÚ	co_constsr   Úis_py311Úco_namesÚis_py312Úis_py314)r7   r8   Úindexs      r   ÚloadrJ   é   s&  € ô
 ˜sÓ#€Eð
 ˆ2�w”%˜Ñ$Ó$à×Ñ Ñ&Ð&à
ˆ2�w”%˜Ñ%Ó%à�~‰~˜eÑ$Ð$ä‡‡˜3˜r™7¤e¨MÑ&:Ó:à�}‰}˜U a™ZÑ(Ð(Ü‡‡˜3˜r™7¤e¨KÑ&8Ó8à�}‰}˜U a™ZÑ(Ð(Ü‡‡˜3˜r™7¤eÐ,<Ñ&=Ó=àˆÜ‡‡˜3˜r™7¤eÐ,AÑ&BÓBð �~‰~˜eÑ$Ð$Ü‡‡˜3˜r™7¤eÐ,>Ñ&?Ó?ð ×Ñ Ñ&Ð&à�=‰=˜ÑÐr   c                 ój   • [         R                  U 5       Vs/ s H  n[        X!5      PM     sn$ s  snf )z©
Parse multiple consecutive LOAD_xxx instructions. Or load() in a for loop.

May be used to unpack a function's parameters or nested attributes ``(foo.bar.pop.whack)``.
)Ú_extended_arg_bytecodeÚfindallrJ   )r7   r8   Úis      r   ÚloadsrO     s-   € ô $:×#AÑ#AÀ#Ô#FÓGÒ#F˜aŒD�ŽMÑ#FÑGÐGùÒGs   ˜0c                 óð  • / n[        [        U R                  5       HÕ  nUR                  5       u  p4pV[	        X05      n[        X@5      nSR                  U/U-   5      n[        XP5      nUS   [        S   :X  aK  [        U5      nUS:w  a  Mo  [        U5      S:w  d  [        US   [        5      (       d  M˜  [        US   5      nO[        U5      n	U	[        U5      :w  a  MÃ  UR                  Xu45        M×     U$ )zB
Scan a code object for all function calls on constant arguments.
Ú.r   ÚCALL_FUNCTION_EXr   )r!   Ú_call_function_bytecodeÚco_codeÚgroupsrJ   rO   Újoinr   r6   Úlenr   ÚtupleÚlistÚappend)
r8   Úoutr$   Úfunction_rootÚmethodsÚargsÚfunction_callÚfunctionr   Ú	arg_counts
             r   Úfunction_callsrb     sè   € ð
 €CäÔ1°4·<±<Ö@ˆØ6;·l±l³nÑ3ˆ ô ˜]Ó1ˆÜ˜Ó&ˆØ—8‘8˜]˜O¨gÑ5Ó6ˆä�TÓ ˆØ˜ÑœuÐ%7Ñ8Ó8Ü& }Ó5ˆEØ˜‹záô �4‹y˜A‹~¤Z°°Q±¼×%?Ñ%?ÙÜ˜˜Q™“=‰Dä*¨=Ó9ˆIàœC ›IÓ%áà�
‰
�HÐ#Ö$ñ; Að> €Jr   Úsearchc                 óš   • Uc  0 nX;  a@  U " U5      X!'   UR                    H&  n[        U[        5      (       d  M  [        XU5        M(     U$ )ze
Apply a search function to a code object, recursing into child code objects (function definitions).
)rD   r   r   Úsearch_recursively)rc   r8   Ú_memoÚconsts       r   re   re   B  sK   € ð �}ØˆØÓÙ˜T“lˆ‰Ø—^”^ˆEÜ˜%¤×*Ó*Ü" 6°%Ö8ñ $ð €Lr   c                 ó"   • [        [        U 5      $ )z…
Scan a code object for function calls on constant arguments, recursing into function definitions and bodies of
comprehension loops.
)re   rb   )r8   s    r   Úrecursive_function_callsri   P  s   € ô
 œn¨dÓ3Ð3r   Ú	full_namec              #   ó€   #   • U R                  S5      nU(       a"  SR                  U5      v •  USS nU(       a  M!  gg7f)a—  List possible aliases of a fully qualified Python name.

    >>> list(any_alias("foo.bar.wizz"))
    ['foo.bar.wizz', 'bar.wizz', 'wizz']

This crudely allows us to capture uses of wizz() under any of
::
    import foo
    foo.bar.wizz()
::
    from foo import bar
    bar.wizz()
::
    from foo.bar import wizz
    wizz()

However, it will fail for any form of aliases and quite likely find false matches.
rQ   r   N)ÚsplitrV   )rj   Úpartss     r   Ú	any_aliasrn   X  s8   é € ð& �O‰O˜CÓ €EÞ
Ø�h‰h�u‹oÒØ�a�b�	ˆ÷ Š%ùs   ‚8>¼>r&   )*Ú__doc__Údisr	   Útypesr   Útypingr   ÚPyInstallerr   Úgetattrr   Ústrr   ÚVERBOSEÚDOTALLr   r   r!   rE   Ú_OPCODES_EXTENDED_ARGÚ_OPCODES_EXTENDED_ARG2Ú_OPCODES_FUNCTION_GLOBALÚ_OPCODES_FUNCTION_LOADÚ_OPCODES_FUNCTION_ARGSÚ_OPCODES_FUNCTION_CALLr    rG   r-   rH   Úis_py313rS   rL   r6   rJ   rY   rO   rb   ÚcallableÚdictre   ri   rn   r'   r   r   Ú<module>r�      sÏ  ðñó" Û 	Ý Ý å ñ
 	��\ 3§9¡9Ó-€ð(˜Sô (ð *,¯©°b·i±iÑ)?ñ ,˜Eõ ,ð,�gð  uô ðB ‡‡à.ÐØ2ÐØHÐØ:ÐØ-ÐØQÐóà	��ð
 DÐØCÐØHÐØ:ÐØ-ÐØ=Ðñ
 !/Ð/BÓ CÐó?ð
 /ÐØ2ÐØ‡‡à#_Ñ à#LÐ Ø,ÐØ‡‡ð "YÑà!1ÐØ:Ðð ‡‡Ù$2Ð3UÓ$VÐ!ó	Cñ %3Ð3FÓ$GÐ!ò	Cñ
 )ðð
 'ñ'ð
*ñð *ñ*ð-ñð )ñ)ð,ñð 'ñ'ð*ñð, *ñ-*ð,-ñ-ð. (ñ/(ð.+ñ/ð< (ñ=(ð<+ñ=ð> &ñ?&ð>)ñ?!ó#Ð ñL (ðà%ñ&ð)
ñ
ð
 #ñ#ð
&ñóÐ ð6 eô 6ð$ ˆeð $ ˜8ð $ ¨ô $ ðNHˆuð H˜Hð H¨ô Hð&˜ð & dô &ñR˜xð ¨xð Èõ ð4 8ð 4°ô 4ð˜õ r   