
    Rhw                     "   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g dZdZej                  j                  d      rdZn ej                         Z G d de      Ze j                  d        Zd	 Zdd
Z	 	 ddZd ZddZedk(  r e        yy)    N)ZipAppErrorcreate_archiveget_interpreterz8# -*- coding: utf-8 -*-
import {module}
{module}.{fn}()
winutf-8c                       e Zd Zy)r   N)__name__
__module____qualname__     /usr/lib/python3.12/zipapp.pyr   r   !   s    r   r   c              #      K   t        | t        t        j                  f      rt	        | |      5 }| d d d        y |  y # 1 sw Y   y xY wwN)
isinstancestrosPathLikeopen)archivemodefs      r   _maybe_openr   %   sJ     'C-.'4  	AG	 	 	 	s   -AAAAAc                 b    |r-d|j                  t              z   dz   }| j                  |       yy)zWrite a shebang line.   #!   
N)encodeshebang_encodingwrite)r   interpretershebangs      r   _write_file_prefixr"   .   s1    +,,-=>>F	 r   c                    t        | d      5 }|j                  d      }|dk(  rd}|j                          t        |d      5 }t        ||       |j	                  |       t        j                  ||       ddd       ddd       |rVt        |t              rEt        j                  |t        j                  |      j                  t        j                  z         yyy# 1 sw Y   jxY w# 1 sw Y   nxY w)z8Copy an application archive, modifying the shebang line.rb   r   r   wbN)r   readreadliner"   r   shutilcopyfileobjr   r   r   chmodstatst_modeS_IEXEC)r   new_archiver    srcfirst_2dsts         r   _copy_archiver3   5   s    	Wd	# )s ((1+eGLLNd+ 	)ssK0 IIgsC(	))" z+s3
bggk2::T\\IJ 4{	) 	)) )s#   5C+4C6C+C(	$C++C4c                 H   d}t        | d      rt        | d      rd}n't        j                  |       } | j                         rd}|rt	        | ||       y| j                         st        d      | dz  j                         }|r|rt        d      |s|st        d	      d}|r|j                  d
      \  }	}
}t        d |	j                  d      D              }t        d |j                  d      D              }|
d
k(  r|r|st        d|z         t        j                  |	|      }|| j                  d      }n!t        |d      st        j                  |      }t        |d      5 }t        ||       |rt        j                   nt        j"                  }t        j$                  |d|      5 }t'        | j)                  d            D ]>  }|j+                  |       }|	 ||      s|j-                  ||j/                                @ |r!|j1                  d|j3                  d             ddd       ddd       |rHt        |d      s;|j5                  |j7                         j8                  t6        j:                  z         yyy# 1 sw Y   \xY w# 1 sw Y   `xY w)ab  Create an application archive from SOURCE.

    The SOURCE can be the name of a directory, or a filename or a file-like
    object referring to an existing archive.

    The content of SOURCE is packed into an application archive in TARGET,
    which can be a filename or a file-like object.  If SOURCE is a directory,
    TARGET can be omitted and will default to the name of SOURCE with .pyz
    appended.

    The created application archive will have a shebang line specifying
    that it should run with INTERPRETER (there will be no shebang line if
    INTERPRETER is None), and a __main__.py which runs MAIN (if MAIN is
    not specified, an existing __main__.py will be used).  It is an error
    to specify MAIN for anything other than a directory source with no
    __main__.py, and it is an error to omit MAIN if the directory has no
    __main__.py.
    Fr'   r(   TNzSource does not existz__main__.pyz8Cannot specify entry point if the source has __main__.pyzArchive has no entry point:c              3   <   K   | ]  }|j                           y wr   isidentifier.0parts     r   	<genexpr>z!create_archive.<locals>.<genexpr>{   s     DTT&&(D   .c              3   <   K   | ]  }|j                           y wr   r7   r9   s     r   r<   z!create_archive.<locals>.<genexpr>|   s     BDD%%'Br=   zInvalid entry point: )modulefnz.pyzr   r&   w)compression*r   )hasattrpathlibPathis_filer3   existsr   	partitionallsplitMAIN_TEMPLATEformatwith_suffixr   r"   zipfileZIP_DEFLATED
ZIP_STOREDZipFilesortedrglobrelative_tor   as_posixwritestrr   r+   r,   r-   r.   )sourcetargetr    mainfilter
compressedsource_is_filehas_mainmain_pymodseprA   mod_okfn_okfdrC   zchildarcnames                      r   r   r   L   s`   * Nvv76:#>f%>>!Nffk2 ==?122&//1HFH 	HH677G~~c*S"DSYYs^DDBBHHSMBBs
v%5<==&&cb&9~##F+VW%f%	VT	" 
Cb2{+/9w++)) 	__R+> 	C!S 12 7++F3>VG_GGE7#3#3#567 

='..*AB	C	
C 7673V[[]**T\\9: 4{	C 	C	
C 
Cs,   +AJ29J,AJ1JJ	JJ!c                     t        | d      5 }|j                  d      dk(  r:|j                         j                         j	                  t
              cd d d        S 	 d d d        y # 1 sw Y   y xY w)Nr$   r%   r   )r   r'   r(   stripdecoder   )r   r   s     r   r   r      sd    	Wd	# Aq66!9::<%%'../?@A AA A As   AA&&A/c                 B   ddl }|j                         }|j                  dddd       |j                  dddd	       |j                  d
ddd       |j                  dddd       |j                  dddd       |j                  dd       |j                  |       } | j                  r|t
        j                  j                  | j                        st        d      t        | j                        }t        dj                  |xs d             t        j                  d       t
        j                  j                  | j                        r| j                  ]t
        j                  j!                  | j                        r?t
        j                  j#                  | j                  | j                        rt        d      | j$                  rt        d      t'        | j                  | j                  | j(                  | j$                  | j*                         y)zRun the zipapp command line interface.

    The ARGS parameter lets you specify the argument list directly.
    Omitting ARGS (or setting it to None) works as for argparse, using
    sys.argv[1:] as the argument list.
    r   Nz--outputz-ozAThe name of the output archive. Required if SOURCE is an archive.)defaulthelpz--pythonz-pzEThe name of the Python interpreter to use (default: no shebang line).z--mainz-mzLThe main function of the application (default: use an existing __main__.py).z
--compressz-c
store_truezQCompress files with the deflate method. Files are stored uncompressed by default.)actionrn   z--infoFz)Display the interpreter from the archive.)rm   rp   rn   rY   z'Source directory (or existing archive).)rn   z%Can only get info for an archive filezInterpreter: {}z<none>z-In-place editing of archives is not supportedz,Cannot change the main function when copying)r    r[   r]   )argparseArgumentParseradd_argument
parse_argsinfor   pathisfilerY   
SystemExitr   printrN   sysexitoutputrI   samefiler[   r   pythoncompress)argsrq   parserr    s       r   r[   r[      s    $$&F

D$5  6 
D$/  0 $;  < d<=  > %<  >
:  < T"D yyww~~dkk*DEE%dkk2&&{'>h?@	ww~~dkk";;277>>$++#>#%77#3#3DKK#MLMM99KLL4;;#{{"mm-r   __main__r   )NNNNF)
contextlibr   rF   r)   r,   rz   rP   __all__rM   platform
startswithr   getfilesystemencoding
ValueErrorr   contextmanagerr   r"   r3   r   r   r[   r	   r   r   r   <module>r      s     	    
 
> <<5!0s002	* 	  K. @D+0G;TA.-b zF r   