;iFHdZddlZddlZddlZddlZddlZddlZddlmZm Z ddl m Z m Z m Z ddlmZmZmZGddZGdd ZGd d ZdS) zl Utilities to create data structures for embedding Python modules and additional files into the executable. N)get_code_objectstrip_paths_in_code)BYTECODE_MAGICis_winstrict_collect_mode)PYZ_ITEM_MODULEPYZ_ITEM_NSPKG PYZ_ITEM_PKGc<eZdZdZdZdZdZddZedZ dS) ZlibArchiveWriterz Writer for PyInstaller's PYZ (ZlibArchive) archive. The archive is used to store collected byte-compiled Python modules, as individually-compressed entries. sPYZNcr|pi}t|d5}|d|jzg}|D].}||||}||/|}t j|} || |dtj ||j |t|tjd|ddddS#1swxYwYdS)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. wbrz!iN)openwrite_HEADER_LENGTH _write_entryappendtellmarshaldumpsseekosSEEK_SET_PYZ_MAGIC_PATTERNrstructpack) selffilenameentries code_dictfptocentry toc_entry toc_offsettoc_datas OC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\PyInstaller/archive/writers.py__init__zZlibArchiveWriter.__init__$sgO (D ! ! 4R HHUT00 1 1 1C  & & --b%CC  9%%%%J}S))H HHX    GGAr{ # # # HHT, - - - HH^ $ $ $ HHV[z22 3 3 31 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4sD D,,D03D0c|\}}}|dvsJt}|dvrt}nLtjtj|\}}|dkrt }tj||} tj | |j } ||| t| ff} || | S)N> PYMODULE-1 PYMODULE-2PYMODULE)-Nr+)rr rpathsplitextbasenamer rrzlibcompress_COMPRESSION_LEVELrlenr) clsr$r&r#namesrc_pathtypecode src_basename_dataobjr's r*rzZlibArchiveWriter._write_entryKs#( hCCCCC" { " "&HH g..rw/?/?/I/IJJOL!z))'}Yt_--mD#"899HbggiiS:;   )N) __name__ __module__ __qualname____doc__rrr6r+ classmethodrr@r*r r sa"N%4%4%4%4N[r@r ceZdZdZdZdZejeZdZ eje Z dZ dZ dZ dd efd Zdd Zed Zd S)CArchiveWriterah 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). sMEI z !8sIIII64sz!IIIIBc c ~t|_t|d5}g}|D]-}|||}||.|}||} t| } || || z|j z} tj ddztj dz} tj |j|j| || | |d} || ddddS#1swxYwYdS)aH 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. rrdasciiN)set_collected_namesrrrr_serialize_tocr7r_COOKIE_LENGTHsys version_inforr_COOKIE_FORMAT_COOKIE_MAGIC_PATTERNencode)r r!r" pylib_namer$r%r&r'r(r) toc_lengtharchive_lengthpyvers cookie_datas r*r+zCArchiveWriter.__init__{s!$ (D ! ! "RC  & & --b%88  9%%%%J**3//HXJ HHX   (*4t7JJN%a(3.1A!1DDF +#*!!'**K HH[ ! ! !7 " " " " " " " " " " " " " " " " " "sDD22D69D6c.|\}}}}|dkr||d||Stj|}tretjjdkrP|tjjd}|dkr%|tjjd}trad}|dvrntj|}|r9||j vrtd|d|d |j ||d kr||d|d ||S|d vrYd ddd|}t|||} t| } ||tj| |d|S|dvrt!|d5} | } dddn #1swxYwY| ddt$ksJtj| dd} t| } ||tj| |||S|dkr2|ddz} ||| |||S||||||S)Nor@/\n>Mmss1s2z7Attempting to collect a duplicated file into CArchive: z (type: )d:>rcrdrerrL)rcrdre)optimizerc)r5)rbrarbutf-8r) _write_blobrr1normpathrsepreplacernormcaserO ValueErroraddrrrrrreadrloadsrV _write_file) r r$r& dest_namesrc_namer5r;normalized_dest optim_levelcodein_fpr>s r*rzCArchiveWriter._write_entrys27/ 8Xx s??##BYAA AG$$Y//  ?bgkS(("))"'+t<>  ;"O666#%'"2"29"="= ;"d&;;;$vRavvksvvv%))/::: s??##B-F-F9-F-FQQ Q * * *!"!44X>K"9hMMMD&t,,D##B d(;(;YV^#__ _  # #h%% $zz|| $ $ $ $ $ $ $ $ $ $ $ $ $ $ $8~----=bcc++D&t,,D##B d(;(;Y[c#dd d __??7++g5D##BiH#UU U##B)XPX#YY Ys-GGGFblobc|}t|}|rtj||j}|||t||t |||fS)z Write the binary contents (**blob**) of a small file to the archive and return the corresponding CArchive TOC entry. )level)rr7r4r5r6rint)r out_fprryr;r5 data_offset data_lengths r*rozCArchiveWriter._write_blobsm kkmm $ii  F=T-DEEED TSYY S]]HiXXr@cb|}tj|j}t |d5}|rt d} t j|j} | | } | sn1| | | d| I| | ntj||dddn #1swxYwY|||z |t|||fS)zl Stream copy a large file into the archive and return the corresponding CArchive TOC entry. rki@TN)rrstatst_sizer bytearrayr4 compressobjr6readintorr5flushshutil copyfileobjr) r rrzryr;r5rrr~ tmp_buffer compressornum_reads r*rxzCArchiveWriter._write_files^kkmm gh''/ (D ! ! 2U 2&y11 !-d.EFF M$~~j99H#LL!4!4Z  5J!K!KLLL M  Z--//0000"5&111 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2V[[]][8+s8}}V^`ijjsB2C<<DDc g}|D]}|\}}}}}} | d} t| dz} |j| z} | dzdkr d| dzz } | | z } tj|j| dz|j| z|||||d| } || d|S)NrnrLrmrrcrMr@)rVr7_TOC_ENTRY_LENGTHrr_TOC_ENTRY_FORMATrjoin)r8r%serialized_tocr'rcompressed_lengthrr5r;r9 name_length entry_lengthpadding_lengthserialized_entrys r*rPzCArchiveWriter._serialize_toc s 4 4IT] QK*K8T;;w''Dd))a-K 0;>Lb A%%!#|b'8!9~-  &{%;(9(9(99% 3!((     ! !"2 3 3 3 3xx'''r@N)F)rArBrCrDrUrTrcalcsizerQrrr6r+rbytesrorxrErPrFr@r*rHrHgs7"N$V_^44N!'(9::)")")"VCZCZCZJ Y Y Y Y Y Ykkkk*(([(((r@rHc<eZdZdZdZejeZdZdS) SplashWriterz 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 Tdfd|D}t|d5}|d|jzd} |} |D]A} | ddz} || | t | z } B|} t |} ||d|}t |tr%t |}||nat|d5}|}dddn #1swxYwYt |}||~d }tj |j ||d d ||d d ||d d| | ||| | }| dtj||ddddS#1swxYwYdS)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. ctj|}tr:tjjdkr%|tjjd}|S)Nr^r_)rr1rprrqrr)r!s r*_normalize_filenamez2SplashWriter.__init__.._normalize_filename_sMw''11H ?"'+,,$++BGK>>Or@c&g|] }|SrFrF).0r9rs r* z)SplashWriter.__init__..gs%EEE4((..EEEr@rrrrnrkNc |d}t||kr&td|dt|d|d|S)NrnzLength of the encoded field z (z&) is greater or equal to the limit of z characters!)rVr7rt)value field_namelimit enc_values r* _encode_strz*SplashWriter.__init__.._encode_strss!LL11 y>>U**$8z88s9~~88$)888 ! r@ tcl_libname tk_libnametklibrm)rrrrrVr7 isinstancerrvrr_HEADER_FORMATrrr)r r! name_listrrrimagescriptr$requirements_lenrequirements_offsetr9 script_offset script_len image_offset image_lenimage_fp image_datar header_datars @r*r+zSplashWriter.__init__Ps   FEEE9EEE (D ! !> "R HHUT00 1 1 1 ! "$'')) ! . .{{7++e3 CII-  GGIIMVJ HHV]]7++ , , ,7799L%'' JJ %&&1(!)J111111111111111 OO $$$  ! ! !!+# K;; J b99 E7B// #  K GGAr{ # # # HH[ ! ! !}> "> "> "> "> "> "> "> "> "> "> "> "> "> "> "> "> "> "s7D!HE% H%E) )H,E) -B#HH!$H!N) rArBrCrDrrrrr+rFr@r*rr0sJ4-N$V_^44NW"W"W"W"W"r@r)rDrrrrrRr4PyInstaller.building.utilsrrPyInstaller.compatrrr#PyInstaller.loader.pyimod01_archiverr r r rHrrFr@r*rs9 KKKKKKKKJJJJJJJJJJ]]]]]]]]]]IIIIIIIIXF(F(F(F(F(F(F(F(Rw"w"w"w"w"w"w"w"w"w"r@