Ë
    CfÙc°K  ã                   ó  — d Z ddlZddlZddlZddlZddlZddlmZ 	 ddl	m
Z
mZmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZmZmZ dd	lmZ dd
lm Z  dZ!dZ"g d¢Z#dZ$g d¢Z%dZ&dZ'dZ(dZ) G d„ de«      Z* G d„ de+«      Z, G d„ de,«      Z- G d„ de,«      Z. G d„ de«      Z/e0dk(  rH e/ejb                  d   ¬ «      Z2e2jf                  ji                  «       Z4 e5e4jm                  d«      «       yy# e$ r
 dZesd„ ZY Œ¿w xY 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)ÚDeb822zdata.tarzcontrol.tar)ÚgzÚbz2ÚxzÚlzmaÚzstzdebian-binary)ÚpreinstÚpostinstÚprermÚpostrmÚconfigÚcontrolzusr/share/doc/%s/changelog.gzz$usr/share/doc/%s/changelog.Debian.gzÚmd5sumsc                   ó   — e Zd Zy)ÚDebErrorN©Ú__name__Ú
__module__Ú__qualname__r   r   r   r*   r*   M   s   „ Ør   r*   c                   óº   — e Zd ZdZd„ Zd„ Zed„ «       Zd„ Zdd„Z	e
dd„«       Ze
dd	„«       Zdd
„Ze
	 	 	 dd„«       Ze
	 	 dd„«       Z	 	 	 dd„Zd„ Zd„ Zd„ Zd„ Zy)Ú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__zDebPart.__init__c   s   € àˆŒØˆ�
r   c                 ó   ‡ — ˆ fd„}‰ j                   €¨‰ j                  j                  }t        j                  j                  |«      d   dd }|t        v s|t        k(  s	|t        k(  rE|dk(  r |ddg«      }n‰ j                  }	 t        j                  |d¬«      ‰ _         ‰ j                   S t        d
|z  «      ‚‰ j                   S # t        j                  t        j                  f$ r}t        d	|z  «      ‚d}~ww xY 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                 óØ  •‡— 	 dd l }dd lŠ|j                  | |j                  |j                  dˆfd„¬«      }|j                  ‰j                  j                  «       «      d   }|j                  dk7  r+t        d	dj                  | «      ›d
|j                  ›d�«      ‚t        j                  |«      S # t        t
        f$ r&}t        ddj                  | «      ›d|›d�«      ‚d }~ww xY 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_fnzerror 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 Â4C)Ã!C$Ã$C)Né   r!   Úunzstdz--stdoutzr:*)Ú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   ÚtgzzDebPart.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Ã8C=c                 ó”   — t        | «      j                  dd«      } | j                  d«      r| S | j                  d«      rd| 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_memberzDebPart.__normalize_memberž   sO   € ô �E“
×"Ñ" 4¨Ó-ˆà×Ñ˜DÔ!ØˆLà×Ñ˜CÔ Ø˜‘;ÐØ�e‰|Ðr   c                 ój  — 	 g }|j                  d«      dd D ]Ø  }|j                  |«       t        j                  j	                  dj                  |«      «      }t        j                  |«      }| j                  «       j                  |«      }|j                  «       sŒ‡|j                  j                  d«      r(|j                  j                  d«      }|j                  }ŒÊ|j                  |d<   ŒÚ 	 t        j                  t        j                  j	                  «      «      S # t        $ r Y yw xY w)zÏ walk the path following symlinks

        returns:
            resolved_path, info

        if the path is not found even after following symlinks within the
        archive, then None is returned.
        rg   rS   Néÿÿÿÿ)ÚsplitÚappendrX   rY   ÚnormpathrH   r0   Ú_DebPart__normalize_memberrd   Ú	getmemberÚissymÚlinknamerk   ÚKeyError)r4   rY   Úresolved_path_partsÚpathpartÚcurrpathÚtinfos         r   Ú__resolve_symlinkszDebPart.__resolve_symlinks®   s  € ð	Ø"$ÐØ ŸJ™J s›O¨A¨BÐ/ò A�Ø#×*Ñ*¨8Ô4ÜŸ7™7×+Ñ+¨C¯H©HÐ5HÓ,IÓJ�Ü"×5Ñ5°hÓ?�ØŸ™›
×,Ñ,¨XÓ6�ð —;‘;•=Ø—~‘~×0Ñ0°Ô5à.3¯n©n×.BÑ.BÀ3Ó.GÐ+Ø#(§>¡>™ð 38·.±.Ð+¨BÒ/ñ%Aô0 ×)Ñ)¬"¯'©'×*:Ñ*:¸8Ó*DÓEÐEøô	 ò 	áð	ús   ‚BD& ÂAD& Ä&	D2Ä1D2c                 ó¨   — t         j                  |«      }| j                  «       j                  «       }||v ry|r| j	                  |«      }|duS ||v S )zmCheck if this part contains a given file name.

        Symlinks within the archive can be followed.
        TN)r0   rs   rd   ÚgetnamesÚ_DebPart__resolve_symlinks)r4   rl   Úfollow_symlinksÚnamesÚ
fname_reals        r   Úhas_filezDebPart.has_fileÔ   sZ   € ô ×*Ñ*¨5Ó1ˆà—‘“
×#Ñ#Ó%ˆØ�E‰>ØáØ×0Ñ0°Ó7ˆJØ TÐ)Ð)à˜ˆ~Ðr   Nc                  ó   — y r   r   ©r4   rl   ÚencodingÚerrorsr€   s        r   Úget_filezDebPart.get_fileæ   ó   € ð 	r   c                  ó   — y r   r   r…   s        r   rˆ   zDebPart.get_fileë   r‰   r   c                 ó2  — t         j                  |«      }|r | j                  |«      }|€t        d«      ‚|}	 | j	                  «       j                  |«      }|€t        d«      ‚|�t        j                  |||¬«      S |S # t        $ r t        d«      ‚w xY w)a  Return a file object corresponding to a given file name.

        If encoding is given, then the file object will return Unicode data;
        otherwise, it will return binary data.

        If follow_symlinks is True, then symlinks within the archive will be
        followed.
        zFile not found inside package©r†   r‡   )	r0   rs   r   r*   rd   Úextractfilerw   rL   ÚTextIOWrapper)r4   rl   r†   r‡   r€   r‚   Úfobjs          r   rˆ   zDebPart.get_fileð   s©   € ô ×*Ñ*¨5Ó1ˆáØ×0Ñ0°Ó7ˆJØÐ!ÜÐ>Ó?Ð?ØˆEð	<Ø—8‘8“:×)Ñ)¨%Ó0ˆDð ˆ<ÜÐ:Ó;Ð;àÐÜ×#Ñ# D°8ÀFÔKÐKàˆøô ò 	<ÜÐ:Ó;Ð;ð	<ús   ¹B ÂBc                  ó   — y r   r   r…   s        r   Úget_contentzDebPart.get_content  ó   € ð 	r   c                  ó   — y r   r   r…   s        r   r‘   zDebPart.get_content  r’   r   c                 óŠ   — | j                  t        |«      |||¬«      }d}|r |j                  «       }|j                  «        |S )a5  Return the string content of a given file, or None (e.g. for
        directories).

        If encoding is given, then the content will be a Unicode object;
        otherwise, it will contain binary data.

        If follow_symlinks is True, then symlinks within the archive will be
        followed.
        )r†   r‡   r€   N)rˆ   ri   rJ   Úclose)r4   rl   r†   r‡   r€   r   Úcontents          r   r‘   zDebPart.get_content$  sI   € ð  �M‰MÜ�‹JØ fØ+ð ó 
ˆð
 ˆÙØ—f‘f“hˆGØ�G‰GŒIØˆr   c                 óP   — t        | j                  «       j                  «       «      S r   )Úiterrd   r~   ©r4   s    r   Ú__iter__zDebPart.__iter__A  s   € ä�D—H‘H“J×'Ñ'Ó)Ó*Ð*r   c                 ó$   — | j                  |«      S r   )rƒ   ©r4   rl   s     r   Ú__contains__zDebPart.__contains__E  s   € à�}‰}˜UÓ#Ð#r   c                 ó$   — | j                  |«      S r   )r‘   rœ   s     r   Ú__getitem__zDebPart.__getitem__I  s   € à×Ñ Ó&Ð&r   c                 ó8   — | j                   j                  «        y r   )r2   r•   r™   s    r   r•   zDebPart.closeM  s   € à�‰×ÑÕr   )F)NNF)NF)r,   r-   r.   Ú__doc__r6   rd   Ústaticmethodrs   r   rƒ   r   rˆ   r‘   rš   r�   rŸ   r•   r   r   r   r0   r0   Q   s¿   „ ñò"ò
4ðl ñó ðò$FóLð$ òó ðð òó ðóð@ ð "ØØ$)ò	ó ðð ð  Ø$)ò	ó ðð "ØØ$)ó	ò:+ò$ò'ór   r0   c                   ó   — e Zd Zy)ÚDebDataNr+   r   r   r   r¤   r¤   R  s   „ àr   r¤   c                   óD   — e Zd Zd„ Zd„ Zedd„«       Zedd„«       Zdd„Zy)	Ú
DebControlc                 óv   — i }t         D ]-  }| j                  |«      sŒ| j                  |«      }|€Œ)|||<   Œ/ |S )zo Return a dictionary of maintainer scripts (postinst, prerm, ...)
        mapping script names to script text. )ÚMAINT_SCRIPTSrƒ   r‘   )r4   Úscriptsrl   rQ   s       r   r©   zDebControl.scriptsY  sJ   € ð
 ˆÜ"ò 	*ˆEØ�}‰}˜UÕ#Ø×'Ñ'¨Ó.�ØÑ#Ø%)�G˜E’Nð		*ð ˆr   c                 ó>   — t        | j                  t        «      «      S )z¶ Return the debian/control as a Deb822 (a Debian-specific dict-like
        class) object.

        For a string representation of debian/control try
        .get_content('control') )r   r‘   ÚCONTROL_FILEr™   s    r   Ú
debcontrolzDebControl.debcontrolg  s   € ô �d×&Ñ&¤|Ó4Ó5Ð5r   Nc                  ó   — y r   r   ©r4   r†   r‡   s      r   r(   zDebControl.md5sumsq  r‰   r   c                  ó   — y r   r   r®   s      r   r(   zDebControl.md5sumsv  r‰   r   c                 óx  — | j                  t        «      st        dt        z  «      ‚| j                  t        ||¬«      }i }d}|€d}|j	                  «       D ]O  }|j                  |«      j                  dd«      \  }}t        |t        «      r|j                  «       ||<   ŒK|||<   ŒQ |j                  «        |S )aó   Return a dictionary mapping filenames (of the data part) to
        md5sums. Fails if the control part does not contain a 'md5sum' file.

        Keys of the returned dictionary are the left-hand side values of lines
        in the md5sums member of control.tar.gz, usually file names relative to
        the file system root (without heading '/' or './').

        The returned keys are Unicode objects if an encoding is specified,
        otherwise binary. The returned values are always Unicode.z('%s' file not found, can't list MD5 sumsrŒ   z
Ns   
rS   )rƒ   ÚMD5_FILEr*   rˆ   Ú	readlinesÚrstriprp   Ú
isinstanceÚbytesÚdecoder•   )	r4   r†   r‡   Úmd5_fileÚsumsÚnewlineÚlineÚmd5rl   s	            r   r(   zDebControl.md5sums{  s¼   € ð �}‰}œXÔ&ÜØ:¼XÑEóGð Gð —=‘=¤°HÀV�=ÓLˆØˆàˆØÐØˆGà×&Ñ&Ó(ò 	"ˆDàŸ™ WÓ-×3Ñ3°D¸!Ó<‰JˆC�Ü˜#œuÔ%Ø!Ÿj™j›l��U’à!��U’ð	"ð 	�‰ÔØˆr   ©NNr   )r,   r-   r.   r©   r¬   r   r(   r   r   r   r¦   r¦   W  s9   „ òò6ð òó ðð òó ðôr   r¦   c                   óž   — e Zd ZdZdd„Zd„ Zed„ «       Zed„ «       Zed„ «       Z	d„ Z
d	„ Zedd
„«       Zedd„«       Zdd„Zd„ Zd„ Zd„ Zd„ Zy)ÚDebFileaÚ  Representation of a .deb file (a Debian binary package)

    DebFile objects have the following (read-only) properties:
        - version       debian .deb file format version (not related with the
                        contained package version), 2.0 at the time of writing
                        for all .deb packages in the Debian archive
        - data          DebPart object corresponding to the data.tar.gz (or
                        other compressed or uncompressed tar) archive contained
                        in the .deb file
        - control       DebPart object corresponding to the control.tar.gz (or
                        other compressed tar) archive contained in the .deb
                        file
    Nc                 ó&  ‡— t        j                  | |||«       t        | j                  «       «      Šˆfd„}t        ‰vrt        dt        z  «      ‚i | _        t        | j                   |t        «      «      «      | j                  t        <   t        | j                   |t        «      «      «      | j                  t        <   d | _        | j                  t        «      }|j                  «       j                  «       | _        |j!                  «        y )Nc                 ó$  •— t         D �cg c]	  }| ›d|›�‘Œ }}| t        t        fv r|j                  | «       ‰j	                  t        |«      «      }|st        d|z  «      ‚t        |«      dkD  rt        d|z  «      ‚t        |«      d   S c c}w )Nrh   z9missing required part in given .deb (expected one of: %s)rS   z>too many parts in given .deb (was looking for only one of: %s)r   )	r[   r\   r]   rq   ÚintersectionÚsetr*   ÚlenÚlist)ÚbasenameÚextÚ
candidatesÚpartsÚactual_namess       €r   Úcompressed_part_namez.DebFile.__init__.<locals>.compressed_part_name²  s§   ø€ ä?HÖI¸¢X©sÒ3ÐIˆJÐIàœI¤yÐ1Ñ1Ø×!Ñ! (Ô+Ø ×-Ñ-¬c°*«oÓ>ˆEÙÜð-Ø/9ñ:ó;ð ;ô �5‹z˜AŠ~Üð9Ø;EñFóGð Gô ˜“;˜q‘>Ð!ùò Js   ŠBz4missing required part in given .deb (expected: '%s'))r   r6   rÂ   r~   Ú	INFO_PARTr*   Ú_DebFile__partsr¦   rt   r]   r¤   r\   Ú_DebFile__pkgnamerJ   ÚstripÚ_DebFile__versionr•   )r4   ÚfilenamerV   rU   rÊ   r   rÉ   s         @r   r6   zDebFile.__init__­  sÕ   ø€ ä�‰˜˜h¨¨gÔ6Ü˜4Ÿ=™=›?Ó+ˆô	"ô& ˜LÑ(Üð$Ü&/ñ0ó1ð 1ð ˆŒÜ",¨T¯^©^Ù ¤Ó+ó.-ó #.ˆ�‰”YÑä")¨$¯.©.Ù ¤Ó+ó+-ó #.ˆ�‰”YÑàˆŒà�N‰Nœ9Ó%ˆØŸ™›Ÿ™Ó)ˆŒØ	�‰�	r   c                 ó4   — | j                  «       d   | _        y )NÚpackage)r¬   rÍ   r™   s    r   Ú__updatePkgNamezDebFile.__updatePkgNameÕ  s   € àŸ™Ó*¨9Ñ5ˆ�r   c                 ó   — | j                   S r   )rÏ   r™   s    r   ÚversionzDebFile.versionÙ  s   € ð �~‰~Ðr   c                 ó(   — | j                   t           S r   )rÌ   r\   r™   s    r   rQ   zDebFile.dataÞ  ó   € ð �|‰|œIÑ&Ð&r   c                 ó(   — | j                   t           S r   )rÌ   r]   r™   s    r   r'   zDebFile.controlã  r×   r   c                 ó6   — | j                   j                  «       S )z See .control.debcontrol() )r'   r¬   r™   s    r   r¬   zDebFile.debcontrolê  s   € ð �|‰|×&Ñ&Ó(Ð(r   c                 ó6   — | j                   j                  «       S )z See .control.scripts() )r'   r©   r™   s    r   r©   zDebFile.scriptsï  s   € ð �|‰|×#Ñ#Ó%Ð%r   c                  ó   — y r   r   r®   s      r   r(   zDebFile.md5sumsô  r‰   r   c                  ó   — y r   r   r®   s      r   r(   zDebFile.md5sumsù  r‰   r   c                 ó<   — | j                   j                  ||¬«      S )z See .control.md5sums() rŒ   )r'   r(   r®   s      r   r(   zDebFile.md5sumsþ  s   € ð �|‰|×#Ñ#¨X¸fÐ#ÓEÐEr   c                 óz  — | j                   €| j                  «        t        | j                   z  t        | j                   z  fD ][  }	 | j                  j                  |d¬«      }t        j                  |¬«      5 }|j                  «       }ddd«       t        «      c S  y# t        $ r Y Œjw xY w# 1 sw Y   Œ'xY w)z† Return a Changelog object for the changelog.Debian.gz of the
        present .deb package. Return None if no changelog can be found. NT)r€   )rU   )rÍ   Ú_DebFile__updatePkgNameÚCHANGELOG_DEBIANÚCHANGELOG_NATIVErQ   rˆ   r*   ÚgzipÚGzipFilerJ   r   )r4   rl   Úfhr   Úraw_changelogs        r   Ú	changelogzDebFile.changelog  sµ   € ð
 �>‰>Ð!Ø× Ñ Ô"ä&¨¯©Ñ7Ü&¨¯©Ñ7ð9ò 		,ˆEðØ—Y‘Y×'Ñ'¨¸tÐ'ÓD�ô —‘ rÔ*ð *¨bØ "§¡£	�÷*ä˜]Ó+Ò+ð		,ð øô ò Ùðú÷*ð *ús   ÁB"Á:B1Â"	B.Â-B.Â1B:	c                 ól   — | j                   j                  «        | j                  j                  «        y r   )r'   r•   rQ   r™   s    r   r•   zDebFile.close  s    € à�‰×ÑÔØ�	‰	�‰Õr   c                 ó   — | S r   r   r™   s    r   Ú	__enter__zDebFile.__enter__  s   € àˆr   c                 ó$   — | j                  «        y r   )r•   )r4   Úexc_typeÚexc_valÚexc_tbs       r   Ú__exit__zDebFile.__exit__!  s   € à�
‰
�r   )NÚrNr¼   r   )r,   r-   r.   r¡   r6   rß   ÚpropertyrÕ   rQ   r'   r¬   r©   r   r(   ræ   r•   ré   rî   r   r   r   r¾   r¾   �  sš   „ ñó&òP6ð ñó ðð ñ'ó ð'ð ñ'ó ð'ò)ò
&ð
 òó ðð òó ðóFò
ò*ò
ór   r¾   Ú__main__rS   )rÐ   )7r¡   râ   rL   r^   ÚsysÚos.pathrX   Úpathlibr   Útypingr   r   r   r   r   r	   r
   r   r   r   r   r   Útyping_extensionsr   ÚImportErrorÚdebian.arfiler   r   r   Údebian.changelogr   Údebian.deb822r   r\   r]   r[   rË   r¨   r«   rá   rà   r±   r*   Úobjectr0   r¤   r¦   r¾   r,   ÚargvÚdebr'   rd   Úprintrt   r   r   r   ú<module>rÿ      s$  ðñó. Û 	Û Û 
Û Ý ð"÷÷ ÷ ó õ÷ 4Ñ 3Ý &Ý  ð €	Ø€	Ú.€	Ø€	ÚD€à€Ø2Ð Ø9Ð Ø€ô	ˆwô 	ô~ˆfô ~ôB	ˆgô 	ô
C�ô CôLFˆfô FðR ˆzÒÙ
˜3Ÿ8™8 A™;Ô
'€CØ
�+‰+�/‰/Ó
€CÙ	ˆ#�-‰-˜	Ó
"Õ#ð øði ò "à€Máñ "ˆùð"ús   ž"C1 Ã1D Ã?D 