§ w<ˆj¼ãóè—dZddlZddlZddlZddlZddlZddlZddlmZej   ejdkd¬¦«Z Gd„d¦«Z d „Z Gd „d e ¦«ZGd „d e ¦«ZdS)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)Ú resourcesÚwin32z Windows only)Úreasoncó:—eZdZed„¦«Zed„¦«ZdS)Ú WrapperTestercób—tjtjg¦«}|t ¦«zS)N)Ú subprocessÚ list2cmdlineÚsysÚ executableÚlocals)ÚclsÚtemplateÚ python_exes úx/builddir/build/BUILD/cloudlinux-venv-1.0.12/venv/lib/python3.11/site-packages/setuptools/tests/test_windows_wrappers.pyÚ prep_scriptzWrapperTester.prep_scripts&€åÔ,­c¬nÐ-=Ñ>Ô>ˆ Ø�&™(œ(Ñ"Ð"ócóà—| |j¦«}||jz  d¦«5}| |¦«ddd¦«n #1swxYwY||jz  d¦«5}t jd¦« |j ¦«  ¦«}| |¦«ddd¦«dS#1swxYwYdS)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_namerÚfilesÚjoinpathÚwrapper_sourceÚ read_bytes)rÚtmpdirÚscriptÚfrs rÚ create_scriptzWrapperTester.create_script"sM€ð—’ ¤Ñ1Ô1ˆà�s”Ñ&× ,Ò ,¨SÑ 1Ô 1ð °QØ �GŠG�F‰OŒOˆOð ð ð ñ ô ð ð ð ð ð ð øøøð ð ð ð ð�sÔ'Ñ'× -Ò -¨dÑ 3Ô 3ð °qÝ”  Ñ-Ô-×6Ò6°sÔ7IÑJÔJ×UÒUÑWÔWˆAØ �GŠG�A‰JŒJˆJð ð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð s$¸AÁAÁ!AÂAC#Ã#C'Ã*C'N)Ú__name__Ú __module__Ú __qualname__Ú classmethodrr$©rrrrsH€€€€€Øð#ð#ñ„[ð#ðððñ„[ðððrrcóP—|dvsJ‚tj¦«dkr|›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_exer17sE€à �^Ð #Ð #Ð #Ð #ÝÔÑÔ˜WÒ$Ð$ØÐ$Ð$Ð$Ð$àÐ!Ð!Ð!Ð!rcó‚—eZdZdZdZed¦«Zejd¦«  ¦«Z d„Z d„Z d„Z dS) Ú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ór—| |¦«t|dz ¦«dddddg}tj|tjtjdd¬ ¦«}| d ¦«\}}| d d ¦«}tjd ¦«  ¦«}||ksJ‚dS)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. r5Ú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$Ústrr ÚPopenÚPIPEÚ communicateÚreplaceÚtextwrapÚdedentÚlstrip)Úselfr!ÚcmdÚprocr>Ú_stderrÚactualÚexpecteds rÚ test_basiczTestCLI.test_basicRsÔ€ð( ×Ò˜6Ñ"Ô"Ð"å �˜Ñ"Ñ #Ô #Ø Ø Ø Ø Ø ð  ˆõÔØ Ý”?Ý”/ØØð  ñ ô ˆð×*Ò*Ð+;Ñ<Ô<‰ˆ�Ø—’ ¨Ñ-Ô-ˆÝ”?ð ñ ô ÷ Š&‰(Œ(ð ð˜Ò!Ð!Ð!Ð!Ð!Ð!rcó—|dz }| ¦«| |¦«tj|dz ¦«}| |dz ¦«t |dz ¦«dddddg}t j|t jt jdd ¬ ¦«}|  d ¦«\}}|  d d ¦«}tj d¦«  ¦«} || ksJ‚dS)zK Ensure that symlink for the foo.exe is working correctly. Ú script_dirr5r7r8r9r:r;Tr<r=rBrCrDrEN)Úmkdirr$ÚpathlibÚPathÚ symlink_torFr rGrHrIrJrKrLrM) rNr!rVÚsymlinkrOrPr>rQrRrSs rÚ test_symlinkzTestCLI.test_symlink‚s€ð˜lÑ*ˆ Ø×ÒÑÔÐØ ×Ò˜:Ñ&Ô&Ð&Ý”,˜v¨ Ñ1Ñ2Ô2ˆØ×Ò˜:¨ Ñ1Ñ2Ô2Ð2õ �˜Ñ"Ñ #Ô #Ø Ø Ø Ø Ø ð  ˆõÔØ Ý”?Ý”/ØØð  ñ ô ˆð×*Ò*Ð+;Ñ<Ô<‰ˆ�Ø—’ ¨Ñ-Ô-ˆÝ”?ð ñ ô ÷ Š&‰(Œ(ð ð˜Ò!Ð!Ð!Ð!Ð!Ð!rcóx—| |¦«tjd¦« ¦«}|dz  d¦«5}| | |¦«¦«ddd¦«n #1swxYwYt|dz ¦«g}tj |tj tj tj dd¬¦«}|  ¦«\}}|  d d ¦«}tjd ¦« ¦«} || ksJ‚dS) 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 = '---' r4rNr5Tr<©r>r?Ústderrr@rArCrDzV \foo-script.py [] '' --- )r$rKrLrMrrrrFr rGrHÚSTDOUTrIrJ) rNr!Útmplr#rOrPr>rQrRrSs rÚtest_with_optionszTestCLI.test_with_options§su€ð ×Ò˜6Ñ"Ô"Ð"ÝŒð ñ  ô  ÷ Š&‰(Œ(ð ð�Ñ&× ,Ò ,¨SÑ 1Ô 1ð ,°QØ �GŠG�D×$Ò$ TÑ*Ô*Ñ +Ô +Ð +ð ,ð ,ð ,ñ ,ô ,ð ,ð ,ð ,ð ,ð ,ð ,øøøð ,ð ,ð ,ð ,å�6˜IÑ%Ñ&Ô&Ð'ˆÝÔØ Ý”?Ý”/ÝÔ$ØØð  ñ ô ˆð×*Ò*Ñ,Ô,‰ˆ�Ø—’ ¨Ñ-Ô-ˆÝ”?ð ñ ô ÷ Š&‰(Œ(ð ð˜Ò!Ð!Ð!Ð!Ð!Ð!sÁ)B  B ÂB N)r%r&r'rrr1rrKrLrMrrTr\rbr)rrr3r3@sƒ€€€€€Ø!€KØ€LØ%Ð% eÑ,Ô,€Nà!�(”/ð ñ ô ÷ ‚f�h„hðð."ð."ð."ð`#"ð#"ð#"ðJ."ð."ð."ð."ð."rr3cóz—eZdZdZdZed¦«ZdZej d¦«  ¦«Z d„Z dS)ÚTestGUIz= Testing the GUI Version ----------------------- zbar-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ó—| |¦«t|dz ¦«t|dz ¦«dg}tj|tjtjtjdd¬¦«}| ¦«\}}|rJ‚|rJ‚|dz  d¦«5}| ¦«  d¦«}d d d ¦«n #1swxYwY|td¦«ksJ‚d S) z:Test the GUI version with the simple script, bar-script.pyreztest_output.txtz Test ArgumentTr<r^ÚrbÚasciiN) r$rFr rGrHr`rIrÚreadÚdecodeÚrepr)rNr!rOrPr>r_Úf_outrRs rrTzTestGUI.test_basicìsH€à ×Ò˜6Ñ"Ô"Ð"õ �˜Ñ"Ñ #Ô #Ý �Ð*Ñ*Ñ +Ô +Ø ð ˆõ ÔØ Ý”?Ý”/ÝÔ$ØØð  ñ ô ˆð×)Ò)Ñ+Ô+‰ˆ�ØÐЈzØÐЈzØÐ(Ñ(× .Ò .¨tÑ 4Ô 4ð 2¸Ø—Z’Z‘\”\×(Ò(¨Ñ1Ô1ˆFð 2ð 2ð 2ñ 2ô 2ð 2ð 2ð 2ð 2ð 2ð 2øøøð 2ð 2ð 2ð 2à�˜oÑ.Ô.Ò.Ð.Ð.Ð.Ð.Ð.sÂ*(CÃC"Ã%C"N) r%r&r'Ú__doc__rr1rrrKrLÚstriprrTr)rrrdrdØso€€€€€ððð #€KØ%Ð% eÑ,Ô,€NØ€Là!�(”/ð ñô÷ ‚e�g„gðð/ð/ð/ð/ð/rrd)rmrXr.r r rKÚpytestÚsetuptools._importlibrÚmarkÚskipifÚ pytestmarkrr1r3rdr)rrúrtsðð ð ð€€€Ø€€€ØÐÐÐØ € € € Ø€€€à € € € à+Ð+Ð+Ð+Ð+Ð+à Œ[× Ò  ¤ °Ò 7ÀÐ Ñ OÔ O€ ðððððñôðð6"ð"ð"ðU"ðU"ðU"ðU"ðU"ˆmñU"ôU"ðU"ðp*/ð*/ð*/ð*/ð*/ˆmñ*/ô*/ð*/ð*/ð*/r