� ��^i8E�� �ddlmZddlZddlZddlZddlZddlZddlmZm Z m Z ddl m Z ddl mZmZmZmZmZmZeje��Zd���Zejd��Zd Zd �ZeZGd �d e��ZdS) �)�BytesION�)� sysconfig�detect_encoding�ZipFile)�finder)� FileOperator�get_export_entry� convert_path�get_executable� get_platform�in_venva� s^#!.*pythonw?[0-9.]*([ ].*)?$z�# -*- coding: utf-8 -*- import re import sys from %(module)s import %(import_name)s if __name__ == '__main__': sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0]) sys.exit(%(func)s()) c���d|vrj|�d��r;|�dd��\}}d|vr|�d��s|�d|�d�}n|�d��sd|z}|S)N� z /usr/bin/env r�"z "z"%s")� startswith�split)� executable�env� _executables ��/builddir/build/BUILDROOT/alt-python311-pip-21.3.1-4.el8.x86_64/opt/alt/python311/lib/python3.11/site-packages/pip/_vendor/distlib/scripts.py�enquote_executabler3s��� �j��� � � �� 1� 1� 1�)�/�/��Q�7�7� �C���k�!�!�+�*@�*@��*E�*E�!�*-�#�#�{�{�{�;� ���(�(��-�-� 1�#�j�0� � ��c�6�eZdZdZeZdZ dd�Zd�Ze j � d��rd�Z d �Z d �Zdd �Zd �ZeZd�Zd�ZdZd�Zdd�Zd�Zed���Zejd���Zejdksejdkrejdkrd�Zdd�Z dd�Z!dS)� ScriptMakerz_ A class to copy or create scripts from source scripts or callable specifications. NTFc��||_||_||_d|_d|_t jdkpt jdkot jdk|_td��|_ |pt|��|_ t jdkpt jdkot jdk|_ tj|_dS)NF�posix�java)��X.Y�nt)� source_dir� target_dir� add_launchers�force�clobber�os�name�_name�set_mode�set�variantsr �_fileop�_is_nt�sys� version_info)�selfr"r#r$�dry_run�fileops r�__init__zScriptMaker.__init__Ns���$���$���*����� ��� ���G�+�F���F�1B�2E�13��W�1D� � ��K�(�(�� ��6��g�!6�!6�� ��g��o�4� �G�v� � 2�"�(�d�"2� � ��,����rc���|�dd��r_|jrXtj�|��\}}|�dd��}tj�||��}|S)N�guiF�python�pythonw)�getr.r'�pathr�replace�join)r1r�options�dn�fns r�_get_alternate_executablez%ScriptMaker._get_alternate_executable_sf�� �;�;�u�e� $� $� .��� .��W�]�]�:�.�.�F�B�����H�i�0�0�B�����b�"�-�-�J��rrc��� t|��5}|�d��dkcddd��S#1swxYwYdS#ttf$rt�d|��YdSwxYw)zl Determine if the specified executable is a script (contains a #! line) �z#!NzFailed to open %sF)�open�read�OSError�IOError�logger�warning)r1r�fps r� _is_shellzScriptMaker._is_shellgs���  ��*�%�%�.���7�7�1�:�:��-�.�.�.�.�.�.�.�.�.�.�.�.����.�.�.�.�.�.���W�%� � � ����2�J�?�?�?��u�u� ���s,�A�7� A�;�A�;�A�,A4�3A4c���|�|��r*ddl}|jj�d��dkr|Sn)|����d��r|Sd|zS)Nrzos.name�Linuxz jython.exez/usr/bin/env %s)rJr�lang�System� getProperty�lower�endswith)r1rrs r�_fix_jython_executablez"ScriptMaker._fix_jython_executabless|���~�~�j�)�)� "�� � � ��9�#�/�/� �:�:�g�E�E�%�%�F��!�!�#�#�,�,�\�:�:� "�!�!�$�z�1� 1rc���tjdkrd}nAt|��t|��zdz}tjdkrd}nd}d|vo||k}|r d|z|zd z}nd }|d |z|zd zz }|d z }|S)a Build a shebang line. In the simple case (on Windows, or a shebang line which is not too long or contains spaces) use a simple formulation for the shebang. Otherwise, use /bin/sh as the executable, with a contrived shebang which allows the script to run either under Python or sh, using suitable quoting. Thanks to Harald Nordgren for his input. See also: http://www.in-ulm.de/~mascheck/various/shebang/#length https://hg.mozilla.org/mozilla-central/file/tip/mach rT��darwini�� s#!� s #!/bin/sh s '''exec' s "$0" "$@" s' ''')r'r(�lenr/�platform)r1r� post_interp�simple_shebang�shebang_length�max_shebang_length�results r�_build_shebangzScriptMaker._build_shebangs��� �7�g� � �!�N�N�!��_�_�s�;�/?�/?�?�!�C�N��|�x�'�'�%(�"�"�%(�"�#�:�5�E�-�1C�C� � � ��Z�'�+�5��=�F�F�#�F� �l�Z�/�+�=��O� O�F� �h� �F�� rrc���d}|jr |j}d}�n:tj��st��}�nt ��rHt j�tjd��dtj d��z��}n�t j�tj d��dtj d���tj d������}t j� |��sGt j�tj d��dtj d��z��}|r|� ||��}tj �d ��r|�|��}|rt!|��}|�d ��}tj d kr d |vr d |vr|dz }|�||��} |�d ��n #t($rt+d|z���wxYw|d kr; |�|��n$#t($rt+d|�d|�d����wxYw|S)NTF�scriptszpython%s�EXE�BINDIRr7�VERSIONr�utf-8�cliz -X:Framesz -X:FullFramess -X:Framesz,The shebang (%r) is not decodable from utf-8z The shebang (z-) is not decodable from the script encoding (�))rr�is_python_buildr rr'r:r<�get_path�get_config_var�isfiler@r/rZrrRr�encoder`�decode�UnicodeDecodeError� ValueError)r1�encodingr[r=�enquoter�shebangs r� _get_shebangzScriptMaker._get_shebang�s����� �?� P���J��G�G��*�,�,� P�'�)�)�J�J� �Y�Y� P�����i�&8��&C�&C�&��)A�%�)H�)H�H�J�J�J�J������(��2�2�2�(�7� �B�B�B�(�7��>�>�>�@�A�A�J��7�>�>�*�-�-� P� �W�\�\�)�*B�8�*L�*L� *�i�.F�u�.M�.M� N�P�P� � � M��7�7� �G�L�L�J� �<� "� "�6� *� *� A��4�4�Z�@�@�J� � 8�+�J�7�7�J� �&�&�w�/�/� � �L�E� !� !�k��&D�&D��{�2�2� �=� (�K��%�%�j�+�>�>��  J� �N�N�7� #� #� #� #��!� J� J� J��>��H�J�J� J� J���� �w� � � K����x�(�(�(�(��%� K� K� K� �j�7>�w�w����J�K�K�K� K�����s�5H � H(�2I�!I)c��|jt|j|j�d��d|j���zS)N�.r)�module� import_name�func)�script_template�dict�prefix�suffixr)r1�entrys r�_get_script_textzScriptMaker._get_script_text�sD���#�d�%�,�7<�|�7I�7I�#�7N�7N�q�7Q�05� �'>�'>�'>�>� >rc�T�tj�|��}|j|zS�N)r'r:�basename�manifest)r1�exename�bases r� get_manifestzScriptMaker.get_manifest�s$���w����(�(���}�t�#�#rc��|jo|j}tj�d��}|�|��s||z }|s||z}n�|dkr|�d��}n|�d��}t��} t| d��5} | � d|��ddd��n #1swxYwY| � ��} ||z| z}|D�]} tj � |j | ��} |�r.tj �| ��\}}|�d��r|} d| z} |j�| |���nx#t$$r�t&�d��d | z}tj �|��rtj|��tj| |��|j�| |��t&�d �� tj|��n#t$$rYnwxYwYn�wxYw|jr| �d |z��s| �d |��} tj �| ��r$|jst&�d | �����|j�| |��|jr|j�| g��|�| ����dS) Nrf�py�t�wz __main__.pyz.pyz%s.exez:Failed to write executable - trying to use .deleteme logicz %s.deletemez0Able to replace executable using .deleteme logicrvzSkipping existing file %s)r$r.r'�lineseprmrQ� _get_launcherrr�writestr�getvaluer:r<r#�splitextrr-�write_binary_file� ExceptionrGrH�exists�remove�rename�debugr&r*�set_executable_mode�append)r1�namesrs� script_bytes� filenames�ext� use_launcherr��launcher�stream�zf�zip_datar(�outname�n�e�dfnames r� _write_scriptzScriptMaker._write_script�sa���)�9�d�k� ��*�#�#�G�,�,������(�(� � �w� �G�� 9�"�\�1�L�L��d�{�{��-�-�c�2�2����-�-�c�2�2���Y�Y�F����%�%� 9��� � �M�<�8�8�8� 9� 9� 9� 9� 9� 9� 9� 9� 9� 9� 9���� 9� 9� 9� 9����(�(�H�#�g�-��8�L��! &�! &�D��g�l�l�4�?�D�9�9�G�� @��w�'�'��0�0���1��<�<��&�&� ��G�"�W�,����L�2�2�7�L�I�I�I�I�� �����N�N�$9�:�:�:�*�W�4�F��w�~�~�f�-�-�*�� �&�)�)�)��I�g�v�.�.�.��L�2�2�7�L�I�I�I��L�L�"3�4�4�4��� �&�)�)�)�)��$���������������� �;�7�w�'7�'7��c� �'B�'B�7�)0���#�#�6�G��7�>�>�'�*�*��4�<���N�N�#>��H�H�H��� �.�.�w� �E�E�E��=�@��L�4�4�g�Y�?�?�?� � � �W� %� %� %� %�C! &�! &sI�C�C� C�E2�2B&I�H.�-I�. H;�8I�:H;�;I�I�-c�<�t��}d|jvr|�|��d|jvr$|�|�|jd����d|jvr9|�|�|j�|jd�d|jd����|S)Nr�Xrr rvr)r+r,�addr0�variant_separator)r1r(r_s r�get_script_filenamesz ScriptMaker.get_script_filenames$s������� ��� � � �J�J�t� � � � �$�-� � � �J�J���t�'8��';�';�<� =� =� =� �D�M� !� !� �J�J�d�d�D�,B�,B�&*�&7��&:�&:�&:�D� %srspythonwr�r�) r'r:r<r"r r#r�r%r-�newerrGr�rC�readlinerH� FIRST_LINE_RE�matchr;�grouprFr2�close� copy_filer*r�r��infor�seekrtr�rD)r1r�r��adjustr��f� first_liner�r[rq�linesrsr�r�s r� _copy_scriptzScriptMaker._copy_script?s���������d�o�|�F�/C�/C�D�D���'�,�,�t����0@�0@��0H�0H�I�I���z� �$�,�"4�"4�V�W�"E�"E� � �L�L�6�� ?� ?� ?� �F�  4��V�T�"�"�A� �����J�� ����?��H�H�H���!�'�'� �(:�(:�7�E�(J�(J�K�K�E�� 4���#�k�k�!�n�n�3�� ���� � � ��<� ���A�A�A� ����� �� ���� � � � �L� "� "�6�7� 3� 3� 3��}� <�� �0�0�'��;�;�;� � � �W� %� %� %� %� %� �K�K�8�&��� )� )� )��<�'� K�"1�!�*�"=�"=���%����q� � � ��+�+�H�k�B�B����+�+��C�C��C��G�$�$�W�-�-���"�"�A�3�������9�c�J�J�J�� ���� � � � � � � s�7E�E�Ec��|jjSr��r-r2)r1s rr2zScriptMaker.dry_runrs ���|�#�#rc��||j_dSr�r�)r1�values rr2zScriptMaker.dry_runvs��$�� ���rr!c�@�tjd��dkrd}nd}t��dkrdnd}|�|�|�d�}t�d d ��d }t |���|��}|sd |�d |��}t|���|jS)N�P��64�32z win-arm64z-armrz.exervrrzUnable to find resource z in package ) �struct�calcsizer �__name__�rsplitr�findrp�bytes)r1�kind�bits�platform_suffixr(�distlib_package�resource�msgs rr�zScriptMaker._get_launcher~s�����s�#�#�q�(�(������(4���+�(E�(E�f�f�2�O�#'�4������?�D�'�o�o�c�1�5�5�a�8�O��o�.�.�3�3�D�9�9�H�� &� &�EI�T�T�&��(�� ��o�o�%��>� !rc��g}t|��}|�|�||��n|�|||���|S)a� Make a script. :param specification: The specification, which is either a valid export entry specification (to make a script from a callable) or a filename (to make a script by copying from a source location). :param options: A dictionary of options controlling script generation. :return: A list of all absolute pathnames written to. Nr�)r r�r�)r1� specificationr=r�r~s r�makezScriptMaker.make�sU��� � ��/�/�� �=� � � �m�Y� 7� 7� 7� 7� � � �e�Y�� � @� @� @��rc�f�g}|D]+}|�|�||�����,|S)z� Take a list of specifications and make scripts from them, :param specifications: A list of specifications. :return: A list of all absolute pathnames written to, )�extendr�)r1�specificationsr=r�r�s r� make_multiplezScriptMaker.make_multiple�sE�� � �+� @� @�M� � � �T�Y�Y�}�g�>�>� ?� ?� ?� ?��r)TFN)rNr�)"r�� __module__� __qualname__�__doc__�SCRIPT_TEMPLATErzrr4r@r/rZrrJrRr`rtr�_DEFAULT_MANIFESTr�r�r�r�r�r�r��propertyr2�setterr'r(r)r�r�r��rrrrEs���������&�O��J�=A�'+�-�-�-�-�"��� �|���v�&�&�2� � � � 2� 2� 2����>C�C�C�C�J>�>�>� !�H�$�$�$�2&�2&�2&�h�� � � �I�I�I�I� 1�1�1�f�$�$��X�$� �^�%�%��^�%� �w�$���2�7�f�,�,���T�1A�1A� "� "� "�&����& � � � � � rr) �ior�loggingr'�rer�r/�compatrrr� resourcesr�utilr r r r r r� getLoggerr�rG�stripr��compiler�r�r�_enquote_executable�objectrr�rr�r�s_������������ � � � � � � � � � � � � � � � �7�7�7�7�7�7�7�7�7�7�������:�:�:�:�:�:�:�:�:�:�:�:�:�:�:�:� �� �8� $� $��� �u�w�w�!�&�� �=�>�>� ��� � � � )��h�h�h�h�h�&�h�h�h�h�hr