�
Cf�c�K � � � d Z ddlZddlZddlZddlZddlZddlmZ ddl m
Z
mZmZm
Z
mZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZ dd lmZ dd
lm Z dZ!dZ"g d
�Z#dZ$g d�Z%dZ&dZ'dZ(dZ) G d� de� Z* G d� de+� Z, G d� de,� Z- G d� de,� Z. G d� de� Z/e0dk( rH e/ejb d � � Z2e2jf ji � Z4 e5e4jm d� � yy# e$ r
dZesd� ZY ��w xY w)!zX Representation of Debian binary package (.deb) files
Debfile Classes
===============
� N)�Path)�Any�BinaryIO�Dict�IO�Iterator�List�Optional�Text�TypeVar�Union�overload�
TYPE_CHECKING)�LiteralFc � � y �N� )�fs �0/usr/lib/python3/dist-packages/debian/debfile.py�<lambda>r 9 s � � )�ArFile�ArError�ArMember)� Changelog)�Deb822zdata.tarzcontrol.tar)�gz�bz2�xz�lzma�zstz
debian-binary)�preinst�postinst�prerm�postrm�config�controlzusr/share/doc/%s/changelog.gzz$usr/share/doc/%s/changelog.Debian.gz�md5sumsc � � e Zd Zy)�DebErrorN��__name__�
__module__�__qualname__r r r r* r* M s � �r r* c � � e Zd ZdZd� Zd� Zed� � Zd� Zdd�Z e
dd�� Ze
dd �� Zdd
�Ze
dd�� Ze
dd�� Z dd
�Zd� Z
d� Zd� Zd� Zy)�DebParta� 'Part' of a .deb binary package.
A .deb package is considered as made of 2 parts: a 'data' part
(corresponding to the possibly compressed 'data.tar' archive embedded
in a .deb) and a 'control' part (the 'control.tar.gz' archive). Each of
them is represented by an instance of this class. Each archive should
be a compressed tar archive although an uncompressed data.tar is permitted;
supported compression formats are: .tar.gz, .tar.bz2, .tar.xz .
When referring to file members of the underlying .tar.gz archive, file
names can be specified in one of 3 formats "file", "./file", "/file". In
all cases the file is considered relative to the root of the archive. For
the control part the preferred mechanism is the first one (as in
deb.control.get_content('control') ); for the data part the preferred
mechanism is the third one (as in deb.data.get_file('/etc/vim/vimrc') ).
c � � || _ d | _ y r )�_DebPart__member�
_DebPart__tgz)�self�members r �__init__zDebPart.__init__c s � ���
���
r c � � � � fd�}� j ��� j j }t j j |� d dd }|t v s|t k( s |t k( rE|dk( r |ddg� }n� j } t j |d�� � _ � j S t d
|z � �� j S # t j t j f$ r}t d |z � �d}~ww xY w)z�Return a TarFile object corresponding to this part of a .deb
package.
Despite the name, this method gives access to various kind of
compressed tar archives, not only gzipped ones.
c �� ��� dd l }dd l�|j | |j |j d�fd��� }|j �j j � � d }|j dk7 r+t
d dj | � �d
|j �d�� �t j |� S # t t
f$ r&}t
ddj | � �d|�d�� �d }~ww xY w)Nr Fc �P �� � j � j � j � S r )�signal�SIGPIPE�SIG_DFL)r: s �r r z9DebPart.tgz.<locals>._custom_decompress.<locals>.<lambda>} s �� ��M�M�&�.�.�&�.�.�A� r )�stdin�stdout�universal_newlines�
preexec_fnzerror while running command '� z' as subprocess: '�'z command 'z' has failed with code ')�
subprocessr: �Popen�PIPE�OSError�
ValueErrorr* �join�communicater2 �read�
returncode�io�BytesIO)�command_listrC �proc�e�datar: r4 s @�r �_custom_decompressz'DebPart.tgz.<locals>._custom_decompressq s� �� �
<�!�� "�'�'� �$�/�/�*�/�/�',� B� (� �� �#�#�D�M�M�$6�$6�$8�9�!�<�D����!�#�� #���� 6���� I� J� J� �:�:�d�#�#�� �Z�(�
<�� #���� 6�� ;� <� <��
<�s �5B4 �4C)�!C$�$C)N� r! �unzstdz--stdoutzr:*)�fileobj�modez#tarfile has returned an error: '%s'z"part '%s' has unexpected extension)r3 r2 �name�os�path�splitext� PART_EXTS� DATA_PART� CTRL_PART�tarfile�open� ReadError�CompressionErrorr* )r4 rR rW � extension�bufferrP s ` r �tgzzDebPart.tgzh s� �� � $�4 �:�:���=�=�%�%�D����(�(��.�q�1�!�"�5�I��I�%���):�d�i�>O� ��%�/��:�0F�G�F�!�]�]�F�N�!(���f�5�!I�D�J�
�z�z�� �C�d�J�K�K��z�z��� �)�)�7�+C�+C�D� N�"�#H�1�#L�M�M��N�s �C �#C=�*C8�8C=c � � t | � j dd� } | j d� r| S | j d� rd| z S d| z S )zw try (not so hard) to obtain a member file name in a form that is
stored in the .tar.gz, i.e. starting with ./ �\�/z./�.)�str�replace�
startswith)�fnames r �__normalize_memberzDebPart.__normalize_member� sO � � �E�
�"�"�4��-�����D�!��L����C� ���;���e�|�r c �j � g }|j d� dd D ]� }|j |� t j j dj |� � }t j |� }| j � j |� }|j � s��|j j d� r(|j j d� }|j }��|j |d< |