Ë
    nûàgÉ  ã                   óæ   — d 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	 ej                  j                  ej                  dk7  d¬«      Z G d„ d«      Zd	„ Z G d
„ de«      Z G d„ de«      Zy)a1  
Python Script Wrapper for Windows
=================================

setuptools includes wrappers for Python scripts that allows them to be
executed like regular windows programs.  There are 2 wrappers, one
for command-line programs, cli.exe, and one for graphical programs,
gui.exe.  These programs are almost identical, function pretty much
the same way, and are generated from the same source file.  The
wrapper programs are used by copying them to the directory containing
the script they are to wrap and with the same name as the script they
are to wrap.
é    N)Únt_quote_argÚwin32zWindows only)Úreasonc                   ó,   — e Zd Zed„ «       Zed„ «       Zy)ÚWrapperTesterc                 óN   — t        t        j                  «      }|t        «       z  S )N)r   ÚsysÚ
executableÚlocals)ÚclsÚtemplateÚ
python_exes      úd/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/setuptools/tests/test_windows_wrappers.pyÚprep_scriptzWrapperTester.prep_script   s   € ä!¤#§.¡.Ó1ˆ
Øœ&›(Ñ"Ð"ó    c                 óŠ  — | j                  | j                  «      }|| j                  z  j                  d«      5 }|j	                  |«       ddd«       || j
                  z  j                  d«      5 }t        j                  d| j                  «      }|j	                  |«       ddd«       y# 1 sw Y   ŒbxY w# 1 sw Y   yxY w)zö
        Create a simple script, foo-script.py

        Note that the script starts with a Unix-style '#!' line saying which
        Python executable to run.  The wrapper will use this line to find the
        correct Python executable.
        ÚwNÚwbÚ
setuptools)	r   Úscript_tmplÚscript_nameÚopenÚwriteÚwrapper_nameÚpkg_resourcesÚresource_stringÚwrapper_source)r   ÚtmpdirÚscriptÚfr   s        r   Úcreate_scriptzWrapperTester.create_script#   s©   € ð —‘ §¡Ó1ˆà�s—‘Ñ&×,Ñ,¨SÓ1ð 	°QØ�G‰G�FŒO÷	ð �s×'Ñ'Ñ'×-Ñ-¨dÓ3ð 	°qÜ×-Ñ-¨l¸C×<NÑ<NÓOˆAØ�G‰G�AŒJ÷	ð 	÷		ð 	ú÷	ð 	ús   ºB-Á22B9Â-B6Â9CN)Ú__name__Ú
__module__Ú__qualname__Úclassmethodr   r!   © r   r   r   r      s(   „ Øñ#ó ð#ð ñó ñr   r   c                 óP   — | dv sJ ‚t        j                  «       dk(  r| › d�S | › d�S )z=A simple routine to select launcher script based on platform.)ÚcliÚguiÚARM64z
-arm64.exez-32.exe)ÚplatformÚmachine)Úprefixs    r   Úwin_launcher_exer.   8   s;   € à�^Ñ#Ð#Ð#Ü×ÑÓ˜WÒ$Ø�˜Ð$Ð$à�˜Ð!Ð!r   c                   óv   — e Zd ZdZdZ ed«      Z ej                  d«      j                  «       Z
d„ Zd„ Zd„ Zy)	ÚTestCLIúfoo-script.pyúfoo.exer(   zç
        #!%(python_exe)s
        import sys
        input = repr(sys.stdin.read())
        print(sys.argv[0][-14:])
        print(sys.argv[1:])
        print(input)
        if __debug__:
            print('non-optimized')
        c                 óZ  — | j                  |«       t        |dz  «      dddddg}t        j                  |t        j                  t        j                  dd¬	«      }|j                  d
«      \  }}|j                  dd«      }t        j                  d«      j                  «       }||k(  sJ ‚y)aD  
        When the copy of cli.exe, foo.exe in this example, runs, it examines
        the path name it was run with and computes a Python script path name
        by removing the '.exe' suffix and adding the '-script.py' suffix. (For
        GUI programs, the suffix '-script.pyw' is added.)  This is why we
        named out script the way we did.  Now we can run out script by running
        the wrapper:

        This example was a little pathological in that it exercised windows
        (MS C runtime) quoting rules:

        - Strings containing spaces are surrounded by double quotes.

        - Double quotes in strings need to be escaped by preceding them with
          back slashes.

        - One or more backslashes preceding double quotes need to be escaped
          by preceding each of them with back slashes.
        r2   Úarg1úarg 2úarg "2\"úarg 4\ú	arg5 a\\bTúutf-8©ÚstdoutÚstdinÚtextÚencodingúhello
world
ú
ú
ú¤
            \foo-script.py
            ['arg1', 'arg 2', 'arg "2\\"', 'arg 4\\', 'arg5 a\\\\b']
            'hello\nworld\n'
            non-optimized
            N)
r!   ÚstrÚ
subprocessÚPopenÚPIPEÚcommunicateÚreplaceÚtextwrapÚdedentÚlstrip)Úselfr   ÚcmdÚprocr;   Ú_stderrÚactualÚexpecteds           r   Ú
test_basiczTestCLI.test_basicS   s´   € ð( 	×Ñ˜6Ô"ä�˜Ñ"Ó#ØØØØØð
ˆô ×ÑØÜ—?‘?Ü—/‘/ØØô
ˆð ×*Ñ*Ð+;Ó<‰ˆ�Ø—‘ ¨Ó-ˆÜ—?‘?ðó
÷ ‰&‹(ð 	ð ˜Ò!Ð!Ñ!r   c                 óÜ  — |dz  }|j                  «        | j                  |«       t        j                  |dz  «      }|j	                  |dz  «       t        |dz  «      dddddg}t        j                  |t        j                  t        j                  dd	¬
«      }|j                  d«      \  }}|j                  dd«      }t        j                  d«      j                  «       }	||	k(  sJ ‚y)zK
        Ensure that symlink for the foo.exe is working correctly.
        Ú
script_dirr2   r4   r5   r6   r7   r8   Tr9   r:   r?   r@   rA   rB   N)Úmkdirr!   ÚpathlibÚPathÚ
symlink_torC   rD   rE   rF   rG   rH   rI   rJ   rK   )
rL   r   rT   ÚsymlinkrM   rN   r;   rO   rP   rQ   s
             r   Útest_symlinkzTestCLI.test_symlinkƒ   sò   € ð ˜lÑ*ˆ
Ø×ÑÔØ×Ñ˜:Ô&Ü—,‘,˜v¨	Ñ1Ó2ˆØ×Ñ˜:¨	Ñ1Ô2ô �˜Ñ"Ó#ØØØØØð
ˆô ×ÑØÜ—?‘?Ü—/‘/ØØô
ˆð ×*Ñ*Ð+;Ó<‰ˆ�Ø—‘ ¨Ó-ˆÜ—?‘?ðó
÷ ‰&‹(ð 	ð ˜Ò!Ð!Ñ!r   c                 óD  — | j                  |«       t        j                  d«      j                  «       }|dz  j	                  d«      5 }|j                  | j                  |«      «       ddd«       t        |dz  «      g}t        j                  |t        j                  t        j                  t        j                  dd¬«      }|j                  «       \  }}|j                  d	d
«      }t        j                  d«      j                  «       }	||	k(  sJ ‚y# 1 sw Y   Œ­xY w)a×  
        Specifying Python Command-line Options
        --------------------------------------

        You can specify a single argument on the '#!' line.  This can be used
        to specify Python options like -O, to run in optimized mode or -i
        to start the interactive interpreter.  You can combine multiple
        options as usual. For example, to run in optimized mode and
        enter the interpreter after running the script, you could use -Oi:
        a,  
            #!%(python_exe)s  -Oi
            import sys
            input = repr(sys.stdin.read())
            print(sys.argv[0][-14:])
            print(sys.argv[1:])
            print(input)
            if __debug__:
                print('non-optimized')
            sys.ps1 = '---'
            r1   r   Nr2   Tr9   ©r;   r<   Ústderrr=   r>   r@   rA   zV
            \foo-script.py
            []
            ''
            ---
            )r!   rI   rJ   rK   r   r   r   rC   rD   rE   rF   ÚSTDOUTrG   rH   )
rL   r   Útmplr    rM   rN   r;   rO   rP   rQ   s
             r   Útest_with_optionszTestCLI.test_with_options¨   s	  € ð 	×Ñ˜6Ô"Ü�‰ð
ó
÷ ‰&‹(ð 	ð �Ñ&×,Ñ,¨SÓ1ð 	,°QØ�G‰G�D×$Ñ$ TÓ*Ô+÷	,ä�6˜IÑ%Ó&Ð'ˆÜ×ÑØÜ—?‘?Ü—/‘/Ü×$Ñ$ØØô
ˆð ×*Ñ*Ó,‰ˆ�Ø—‘ ¨Ó-ˆÜ—?‘?ðó
÷ ‰&‹(ð 	ð ˜Ò!Ð!Ñ!÷+	,ð 	,ús   Á	!DÄDN)r"   r#   r$   r   r   r.   r   rI   rJ   rK   r   rR   rZ   r`   r&   r   r   r0   r0   A   sH   „ Ø!€KØ€LÙ% eÓ,€Nà!�(—/‘/ð		ó÷ �fƒhð ò."ò`#"óJ."r   r0   c                   ón   — e Zd ZdZdZ ed«      ZdZ ej                  d«      j                  «       Zd„ Zy)ÚTestGUIz=
    Testing the GUI Version
    -----------------------
    zbar-script.pywr)   úbar.exez®
        #!%(python_exe)s
        import sys
        f = open(sys.argv[1], 'wb')
        bytes_written = f.write(repr(sys.argv[2]).encode('utf-8'))
        f.close()
        c                 óÐ  — | j                  |«       t        |dz  «      t        |dz  «      dg}t        j                  |t        j                  t        j                  t        j
                  dd¬«      }|j                  «       \  }}|rJ ‚|rJ ‚|dz  j                  d«      5 }|j                  «       j                  d«      }d	d	d	«       t        d«      k(  sJ ‚y	# 1 sw Y   ŒxY w)
z:Test the GUI version with the simple script, bar-script.pyrc   ztest_output.txtzTest ArgumentTr9   r\   ÚrbÚasciiN)r!   rC   rD   rE   rF   r^   rG   r   ÚreadÚdecodeÚrepr)rL   r   rM   rN   r;   r]   Úf_outrP   s           r   rR   zTestGUI.test_basicí   sá   € à×Ñ˜6Ô"ô �˜Ñ"Ó#Ü�Ð*Ñ*Ó+Øð
ˆô
 ×ÑØÜ—?‘?Ü—/‘/Ü×$Ñ$ØØô
ˆð ×)Ñ)Ó+‰ˆ�ÙÐˆzÙÐˆzØÐ(Ñ(×.Ñ.¨tÓ4ð 	2¸Ø—Z‘Z“\×(Ñ(¨Ó1ˆF÷	2àœ˜oÓ.Ò.Ð.Ñ.÷	2ð 	2ús   Â# CÃC%N)r"   r#   r$   Ú__doc__r   r.   r   r   rI   rJ   Ústripr   rR   r&   r   r   rb   rb   Ù   sC   „ ñð
 #€KÙ% eÓ,€NØ€Là!�(—/‘/ð	ó÷ �eƒgð ó/r   rb   )rk   rV   r+   rD   r	   rI   Úpytestr   Úsetuptools.command.easy_installr   ÚmarkÚskipifÚ
pytestmarkr   r.   r0   rb   r&   r   r   ú<module>rr      sp   ðñó Û Û Û 
Û ã ã Ý 8à�[‰[×Ñ §¡°Ñ 7ÀÐÓO€
÷ñ ò6"ôU"ˆmô U"ôp*/ˆmõ */r   