
    i1K                         S r SSKrSSKrSSKrSSKrSSKrSSKrSSKJrJ	r	  SSK
JrJrJr  SSKJrJrJr   " S S5      r " S S	5      r " S
 S5      rg)zl
Utilities to create data structures for embedding Python modules and additional files into the executable.
    N)get_code_objectreplace_filename_in_code_object)BYTECODE_MAGICis_winstrict_collect_mode)PYZ_ITEM_MODULEPYZ_ITEM_NSPKGPYZ_ITEM_PKGc                   >    \ rS rSrSrSrSrSrS
S jr\	S 5       r
S	rg)ZlibArchiveWriter   z
Writer for PyInstaller's PYZ (ZlibArchive) archive. The archive is used to store collected byte-compiled Python
modules, as individually-compressed entries.
s   PYZ       Nc                 X   U=(       d    0 n[        US5       nUR                  SU R                  -  5        / nU H&  nU R                  XFU5      nUR	                  U5        M(     UR                  5       n[        R                  " U5      n	UR                  U	5        UR                  S[        R                  5        UR                  U R                  5        UR                  [        5        UR                  [        R                  " SU5      5        SSS5        g! , (       d  f       g= f)a  
filename
    Target filename of the archive.
entries
    An iterable containing entries in the form of tuples: (name, src_path, typecode), where `name` is the name
    under which the resource is stored (e.g., python module name, without suffix), `src_path` is name of the
    file from which the resource is read, and `typecode` is the Analysis-level TOC typecode (`PYMODULE`).
code_dict
    Optional code dictionary containing code objects for analyzed/collected python modules.
wb    r   z!iN)openwrite_HEADER_LENGTH_write_entryappendtellmarshaldumpsseekosSEEK_SET_PYZ_MAGIC_PATTERNr   structpack)
selffilenameentries	code_dictfptocentry	toc_entry
toc_offsettoc_datas
             HC:\des-py\RoboSAPF\venv\Lib\site-packages\PyInstaller\archive\writers.py__init__ZlibArchiveWriter.__init__$   s     O	(D!RHHUT0001 C  --bC	

9% !
 J}}S)HHHX GGAr{{#HHT,,-HH^$HHV[[z231 "!!s   C:D
D)c                    Uu  pEnUS;   d   eUS;   a  U[         UR                  5       S44$ X4   n[        R                  R	                  [        R                  R                  U5      5      u  pUS:X  a8  [        n[        R                  R                  " / UR                  S5      QSP76 n
O5[        n[        R                  R                  " UR                  S5      6 S-   n
[        Xz5      n[        R                  " U5      n[        R                  " XR                  5      nXFUR                  5       [!        U5      44nUR#                  U5        U$ )N>   PYMODULE
PYMODULE-1
PYMODULE-2>   N-r   r,   .z__init__.py.py)r	   r   r   pathsplitextbasenamer
   joinsplitr   r   r   r   zlibcompress_COMPRESSION_LEVELlenr   )clsr%   r'   r$   namesrc_pathtypecodecode_objectsrc_basename_co_filenamedataobjr(   s                 r+   r   ZlibArchiveWriter._write_entryK   s   #( CCCC{" >2779a899o''**277+;+;H+EF:%#H'',,G

3GGK&H'',,

385@K 6kO }}[) mmD"8"89 bggiS:;	 	     )N)__name__
__module____qualname____firstlineno____doc__r   r   r<   r,   classmethodr   __static_attributes__rJ   rI   r+   r   r      s4     "N%4N # #rI   r   c                       \ rS rSrSrSrSr\R                  " \5      r	Sr
\R                  " \
5      rSrS rS rSS	\4S
 jjrSS jr\S 5       rSrg)CArchiveWriterr   aT  
Writer for PyInstaller's CArchive (PKG) archive.

This archive contains all files that are bundled within an executable; a PYZ (ZlibArchive), DLLs, Python C
extensions, and other data files that are bundled in onefile mode.

The archive can be read from either C (bootloader code at application's run-time) or Python (for debug purposes).
s   MEI
z
!8sIIII64sz!IIIIBc	   c                 X   [        5       U l        [        US5       n/ nU H%  nU R                  XF5      nUR	                  U5        M'     UR                  5       nU R                  U5      n	[        U	5      n
UR                  U	5        X-   U R                  -   n[        R                  S   S-  [        R                  S   -   n[        R                  " U R                  U R                  UUU
UUR!                  S5      5      nUR                  U5        SSS5        g! , (       d  f       g= f)a  
filename
    Target filename of the archive.
entries
    An iterable containing entries in the form of tuples: (dest_name, src_name, compress, typecode), where
    `dest_name` is the name under which the resource is stored in the archive (and name under which it is
    extracted at runtime), `src_name` is name of the file from which the resouce is read, `compress` is a
    boolean compression flag, and `typecode` is the Analysis-level TOC typecode.
pylib_name
    Name of the python shared library.
r   r   d      asciiN)set_collected_namesr   r   r   r   _serialize_tocr=   r   _COOKIE_LENGTHsysversion_infor   r    _COOKIE_FORMAT_COOKIE_MAGIC_PATTERNencode)r!   r"   r#   
pylib_namer%   r&   r'   r(   r)   r*   
toc_lengtharchive_lengthpyverscookie_datas                 r+   r,   CArchiveWriter.__init__   s    !$(D!RC  --b8	

9% !
 J**3/HXJHHX (4t7J7JJN%%a(3.1A1A!1DDF ++##**!!'*K HH[!7 "!!s   C6D
D)c                 8   Uu  p4pVUS:X  a  U R                  USX65      $ [        R                  R                  U5      n[        (       ax  [        R                  R
                  S:X  aZ  UR                  [        R                  R
                  S5      nUS:X  a*  UR                  [        R                  R
                  S5      n[        (       ak  S nUS;   a  O[        R                  R                  U5      nU(       a<  XpR                  ;   a  [        SU SU S	35      eU R                  R                  U5        US
:X  a  U R                  USU SU 3U5      $ US;   aj  SSSS.U   n[        X4US9n	U[        R                  R                  U5      S   -   n
[        X5      n	U R                  U[        R                   " U	5      USUS9$ US;   a  [#        US5       nUR%                  5       nS S S 5        WS S [&        :X  d   e[        R(                  " USS  5      n	US-   n
[        X5      n	U R                  U[        R                   " U	5      X6US9$ US:X  a%  UR+                  S5      S-   nU R                  XX6US9$ U R-                  XX6US9$ ! , (       d  f       N= f)NorI   /\n>   Mmss1s2z7Attempting to collect a duplicated file into CArchive: z (type: )d:>   rp   rq   rr   r   rX      )rp   rq   rr   )optimizerp   )r;   )ro   rn   rb      r4   utf-8r   )_write_blobr   r5   normpathr   sepreplacer   normcaser[   
ValueErroraddr   r6   r   r   r   r   readr   loadsrb   _write_file)r!   r%   r'   	dest_namesrc_namer;   rA   normalized_destoptim_levelcoderE   in_fprF   s                r+   r   CArchiveWriter._write_entry   s   27/	X s?##BYAA GG$$Y/	6bggkkS( "))"''++t<I 3#++BGGKK> "O66 #%''"2"29"="&;&;;$QRaQbbjksjttuv  %%))/:s? ##Bz9+-FQQ** !"!4X>K"9MD#bgg&6&6x&@&CCK24ED##Bd(;YV^#__# h%zz| &8~---==bc+D#e+K24ED ##Bd(;Y[c#dd_??7+g5D##BiH#UU##B)PX#YY &%s   J
Jblobc                     UR                  5       n[        U5      nU(       a  [        R                  " X R                  S9nUR                  U5        U[        U5      U[        U5      XC4$ )zv
Write the binary contents (**blob**) of a small file to the archive and return the corresponding CArchive TOC
entry.
)level)r   r=   r:   r;   r<   r   int)r!   out_fpr   r   rA   r;   data_offsetdata_lengths           r+   r|   CArchiveWriter._write_blob   sT    
 kkm$i==-D-DEDTSYS]HXXrI   c                 <   UR                  5       n[        R                  " U5      R                  n[	        US5       nU(       a  [        S5      n	[        R                  " U R                  5      n
 UR                  U	5      nU(       d  O%UR                  U
R                  U	SU 5      5        M>  UR                  U
R                  5       5        O[        R                  " X5        SSS5        XaR                  5       U-
  U[        U5      XC4$ ! , (       d  f       N.= f)z\
Stream copy a large file into the archive and return the corresponding CArchive TOC entry.
rx   i @  N)r   r   statst_sizer   	bytearrayr:   compressobjr<   readintor   r;   flushshutilcopyfileobjr   )r!   r   r   r   rA   r;   r   r   r   
tmp_buffer
compressornum_reads               r+   r   CArchiveWriter._write_file  s     kkmggh'//(D!U&y1
!--d.E.EF
$~~j9H#LL!4!4Z	5J!KL	 
 Z--/0""51 " [[][8+s8}V^jj "!s   B(D
Dc                    / nU H  nUu  pEpgpU	R                  S5      n	[        U	5      S-   n
U R                  U
-   nUS-  S:w  a  SUS-  -
  nX-  n
[        R                  " U R
                  U
 S3-   U R                  U
-   UUUUUR                  S5      U	5      nUR                  U5        M     SR                  U5      $ )Nr{   rX   rz   r   rp   rY   rI   )rb   r=   _TOC_ENTRY_LENGTHr   r    _TOC_ENTRY_FORMATr   r8   )r>   r&   serialized_tocr(   r   compressed_lengthr   r;   rA   r?   name_lengthentry_lengthpadding_lengthserialized_entrys                 r+   r\   CArchiveWriter._serialize_toc  s    IT]QKK8 ;;w'Dd)a-K
 00;>Lb A%!#|b'8!9-  &{{%%;-q(99%%3!(	  !!"237 : xx''rI   )r[   N)F)rK   rL   rM   rN   rO   ra   r`   r   calcsizer]   r   r   r<   r,   r   bytesr|   r   rP   r\   rQ   rJ   rI   r+   rS   rS   r   sv     7 "N__^4N!(9:)"VEZNY Yk* ( (rI   rS   c                   F    \ rS rSrSrSr\R                  " \5      rS r	Sr
g)SplashWriteri=  z
Writer for the splash screen resources archive.

The resulting archive is added as an entry into the CArchive with the typecode PKG_ITEM_SPLASH.
z!32s 32s 16s II II IIc                    S nU V	s/ s H
  o" U	5      PM     nn	[        US5       n
U
R                  SU R                  -  5        SnU
R                  5       nU H6  n	U	R	                  S5      S-   n	U
R                  U	5        U[        U	5      -  nM8     U
R                  5       n[        U5      nU
R                  UR	                  S5      5        U
R                  5       n[        U[        5      (       a  [        U5      nU
R                  U5        OB[        US5       nUR                  5       nSSS5        [        W5      nU
R                  U5        AS n[        R                  " U R                  U" US	S
5      U" USS
5      U" USS5      UUUUUU5
      nU
R                  S[        R                  5        U
R                  U5        SSS5        gs  sn	f ! , (       d  f       N= f! , (       d  f       g= f)a  
Writer for splash screen resources that are bundled into the CArchive as a single archive/entry.

:param filename: The filename of the archive to create
:param name_list: List of filenames for the requirements array
:param str tcl_libname: Name of the tcl shared library file
:param str tk_libname: Name of the tk shared library file
:param str tklib: Root of tk library (e.g. tk/)
:param Union[str, bytes] image: Image like object
:param str script: The tcl/tk script to execute to create the screen.
c                     [         R                  R                  U 5      n [        (       aH  [         R                  R                  S:X  a*  U R                  [         R                  R                  S5      n U $ )Nrk   rl   )r   r5   r}   r   r~   r   )r"   s    r+   _normalize_filename2SplashWriter.__init__.<locals>._normalize_filenamel  sK    ww''1Hv"''++, $++BGGKK>OrI   r   r   r   r{   rx   Nc           	          U R                  S5      n[        U5      U:  a  [        SU< S[        U5       SU S35      eU$ )Nr{   zLength of the encoded field z (z&) is greater or equal to the limit of z characters!)rb   r=   r   )value
field_namelimit	enc_values       r+   _encode_str*SplashWriter.__init__.<locals>._encode_str  sU    !LL1	y>U*$6znBs9~FV W$$)7,8 
 ! rI   tcl_libname    
tk_libnametklibrz   )r   r   r   r   rb   r=   
isinstancer   r   r   r    _HEADER_FORMATr   r   r   )r!   r"   	name_listr   r   r   imagescriptr   r?   r%   requirements_lenrequirements_offsetscript_offset
script_lenimage_offset	image_lenimage_fp
image_datar   header_datas                        r+   r,   SplashWriter.__init__]  s   	 <EE94(.9	E(D!RHHUT0001
  !"$'')!{{7+e3 CI-  " GGIMVJHHV]]7+, 779L%''J	 %&(!)J '
O	$
! !++##K;Jb9E7B/ #K GGAr{{#HH[!} "! F< '&9 "!s*   GC6G'G.BG'
G$	 G''
G5rJ   N)rK   rL   rM   rN   rO   r   r   r   r   r,   rQ   rJ   rI   r+   r   r   =  s"    4 -N__^4NW"rI   r   )rO   r   r   r   r   r^   r:   PyInstaller.building.utilsr   r   PyInstaller.compatr   r   r   #PyInstaller.loader.pyimod01_archiver   r	   r
   r   rS   r   rJ   rI   r+   <module>r      sS     	   
  W J J ] ]T TnH( H(Vw" w"rI   