
    ,h                         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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win32zWindows only)reasonc                   ,    e Zd Zed        Zed        Zy)WrapperTesterc                 d    t        j                  t        j                  g      }|t	               z  S )N)
subprocesslist2cmdlinesys
executablelocals)clstemplate
python_exes      h/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/setuptools/tests/test_windows_wrappers.pyprep_scriptzWrapperTester.prep_script   s&    ,,cnn-=>
&(""    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GGFO	 s'''--d3 	q--lC<N<NOAGGAJ	 			 		 	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/   7   s8    ^##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.
        r3   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_basiczTestCLI.test_basicR   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_dirr3   r5   r6   r7   r8   r9   Tr:   r;   r@   rA   rB   rC   N)mkdirr"   pathlibPath
symlink_torD   r   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 = '---'
            r2   r   Nr3   Tr:   r<   r=   stderrr>   r?   rA   rB   zV
            \foo-script.py
            []
            ''
            ---
            )r"   rI   rJ   rK   r   r   r   rD   r   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GGD$$T*+	,6I%&'??//$$
 **,-??
 &( 	 !!!+	, 	,s   	!DDN)r#   r$   r%   r   r   r/   r   rI   rJ   rK   r   rR   rZ   r`   r'   r   r   r1   r1   @   sH    !KL%e,N!(//		 fh ."`#"J."r   r1   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 ArgumentTr:   r\   rbasciiN)r"   rD   r   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" "#**+

 ??//$$
 ))+((..t4 	2ZZ\((1F	2o....	2 	2s   # 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!(//	 eg /r   rb   )rk   rV   r,   r   r
   rI   pytestr   markskipif
pytestmarkr   r/   r1   rb   r'   r   r   <module>rq      sm       
   [[ 7O
 6"U"m U"p*/m */r   