)uycK:dZddlZddlZddlZddlZddlZddlmZ ddl m Z m Z m Z m Z mZmZmZmZmZmZmZmZddlmZn#e$r dZesdZYnwxYwddlmZmZmZdd lmZdd lm Z d Z!d Z"gd Z#dZ$gdZ%dZ&dZ'dZ(dZ)GddeZ*Gdde+Z,Gdde,Z-Gdde,Z.GddeZ/e0dkrPe/ej1d Z2e2j34Z4e5e46ddSdS)!zX Representation of Debian binary package (.deb) files Debfile Classes =============== N)Path) AnyBinaryIODictIOIteratorListOptionalTextTypeVarUnionoverload TYPE_CHECKING)LiteralFcdSN)fs 0/usr/lib/python3/dist-packages/debian/debfile.pyr9sT)ArFileArErrorArMember) Changelog)Deb822zdata.tarz control.tar)gzbz2xzlzmazstz debian-binary)preinstpostinstprermpostrmconfigcontrolzusr/share/doc/%s/changelog.gzz$usr/share/doc/%s/changelog.Debian.gzmd5sumsceZdZdS)DebErrorN__name__ __module__ __qualname__rrrr*r*MsDrr*ceZdZdZdZdZedZdZddZ e dd Z e dd Z dd Z e dd Z e dd Z ddZ dZ dZdZdZdS)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|_dSr)_DebPart__member _DebPart__tgz)selfmembers r__init__zDebPart.__init__cs  rcfd}j׉jj}tj|ddd}|t vs|tks |tkrm|dkr|ddg}nj} tj |d_nG#tj tj f$r}td |zd}~wwxYwtd |zjS) zReturn 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 ddl}ddl|||j|jdfd}nB#tt f$r.}t dd|d|dd}~wwxYw|j d}|j dkr.t d d|d |j dtj |S) NrFcDjjSr)signalSIGPIPESIG_DFL)r:srrz9DebPart.tgz.._custom_decompress..}sMM&.&.AAr)stdinstdoutuniversal_newlines preexec_fnzerror while running command ' z' as subprocess: ''z command 'z' has failed with code ') subprocessr:PopenPIPEOSError ValueErrorr*join communicater2read returncodeioBytesIO) command_listrCprocedatar:r4s @r_custom_decompressz'DebPart.tgz.._custom_decompressqs> <!!!! "'' $/*/', B B B B (Z( < < <h # 6 6 6 6 ;<<< <##DM$6$6$8$899!O>O%%//:0FGGFF!]FN!(f5!I!I!IDJJ)7+CDNNN"#H1#LMMMNCdJKKKzsBC9C  Cct|dd}|dr|S|drd|zSd|zS)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./.)strreplace startswith)fnames r__normalize_memberzDebPart.__normalize_membersdE ""4--   D ! ! L   C  ; e|rc g}|dddD]}||tjd|}t |}| |}| rF|j dr"|j d}|j }|j |d<n#t$rYdSwxYwt tj|S)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. rgrSN)splitappendrXrYnormpathrHr0_DebPart__normalize_memberrd getmemberissymlinknamerkKeyError)r4rYresolved_path_partspathpartcurrpathtinfos r__resolve_symlinkszDebPart.__resolve_symlinkss@ "$  JJsOOABB/ A A#**84447++CHH5H,I,IJJ"55h?? ,,X66;;== A~0055 A.3n.B.B3.G.G+#(>38.+B/% A(   44 ))"'*:*:8*D*DEEEsDD DDFct|}|}||vrdS|r||}|duS||vS)zmCheck if this part contains a given file name. Symlinks within the archive can be followed. TN)r0rsrdgetnames_DebPart__resolve_symlinks)r4rlfollow_symlinksnames fname_reals rhas_filezDebPart.has_filesn **511 ##%% E>>4  *0077JT) )~rNcdSrrr4rlencodingerrorsrs rget_filezDebPart.get_file  rcdSrrrs rrzDebPart.get_filerrcnt|}|r(||}|td|} ||}n#t $rtdwxYw|td|tj|||S|S)aReturn 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. NzFile not found inside packagerr) r0rsrr*rd extractfilerwrL TextIOWrapper)r4rlrrrrfobjs rrzDebPart.get_files**511  0077J!>???E <88::))%00DD < < <:;; ; < <:;; ;  #D8FKKK K s 'A..BcdSrrrs r get_contentzDebPart.get_content  rcdSrrrs rrzDebPart.get_contentrrc|t||||}d}|r(|}||S)a5Return 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. )rrrN)rrirJclose)r4rlrrrrcontents rrzDebPart.get_content$s[ MM JJf+      ffhhG GGIIIrcht|Sr)iterrdr~r4s r__iter__zDebPart.__iter__As$DHHJJ''))***rc,||Sr)rr4rls r __contains__zDebPart.__contains__Es}}U###rc,||Sr)rrs r __getitem__zDebPart.__getitem__Is&&&rc8|jdSr)r2rrs rrz DebPart.closeMs r)F)NNF)NF)r,r-r.__doc__r6rd staticmethodrsrrrrrrrrrrrrr0r0Qs" 444l  \ $F$F$FL$   X    X @"$)    X  $)    X "$) :+++$$$'''rr0ceZdZdS)DebDataNr+rrrrrRsDrrcReZdZdZdZeddZeddZddZdS) DebControlci}tD]3}||r||}||||<4|S)zo Return a dictionary of maintainer scripts (postinst, prerm, ...) mapping script names to script text. ) MAINT_SCRIPTSrr)r4scriptsrlrQs rrzDebControl.scriptsYsT " * *E}}U## *''..#%)GENrcPt|tS)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') )rr CONTROL_FILErs r debcontrolzDebControl.debcontrolgs d&&|44555rNcdSrrr4rrs rr(zDebControl.md5sumsqrrcdSrrrs rr(zDebControl.md5sumsvrrc|tstdtz|t||}i}d}|d}|D]`}||dd\}}t|tr| ||<[|||<a| |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 sumsrz Ns rS) rMD5_FILEr*r readlinesrstriprp isinstancebytesdecoder) r4rrmd5_filesumsnewlinelinemd5rls rr(zDebControl.md5sums{s}}X&& G:XEGG G==HV=LL  G&&(( " "DW--33D!<zBDebFile.__init__..compressed_part_name..s$IIIXXXss3IIIrz9missing required part in given .deb (expected one of: %s)rSz>too many parts in given .deb (was looking for only one of: %s)r) r[r\r]rq intersectionsetr*lenlist)r candidatesparts actual_namess` rcompressed_part_namez.DebFile.__init__..compressed_part_namesIIIIyIIIJIy111!!(+++ --c*oo>>E ;-/9:;;;5zzA~~9;EFGGG;;q> !rz4missing required part in given .deb (expected: '%s'))rr6rr~ INFO_PARTr*_DebFile__partsrrtr]rr\_DebFile__pkgnamerJstrip_DebFile__versionr)r4filenamerVrUrrrs @rr6zDebFile.__init__s&hg6664==??++  " " " " "& L ( ($&/011 1 ",T^^  + +.-.-#.#. Y")$..  + ++-+-#.#. Y NN9 % %))  rcD|d|_dS)Npackage)rrrs r__updatePkgNamezDebFile.__updatePkgNames**95rc|jSr)rrs rversionzDebFile.versions ~rc&|jtSr)rr\rs rrQz DebFile.data|I&&rc&|jtSr)rr]rs rr'zDebFile.controlrrc4|jS)z See .control.debcontrol() )r'rrs rrzDebFile.debcontrols|&&(((rc4|jS)z See .control.scripts() )r'rrs rrzDebFile.scriptss|##%%%rcdSrrrs rr(zDebFile.md5sumsrrcdSrrrs rr(zDebFile.md5sumsrrc:|j||S)z See .control.md5sums() r)r'r(rs rr(zDebFile.md5sumss|##Xf#EEErc||j|t|jzt|jzfD]} |j|d}n#t $rY,wxYwtj|5}| }dddn #1swxYwYt|cSdS)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__updatePkgNameCHANGELOG_DEBIANCHANGELOG_NATIVErQrr*gzipGzipFilerJr)r4rlfhr raw_changelogs r changelogzDebFile.changelogs > !  " " "&7&79 , ,E Y''t'DD    r*** *b "  * * * * * * * * * * * * * * *]++ + + +ts#A A'&A'?B  B$ 'B$ cj|j|jdSr)r'rrQrs rrz DebFile.closes.  rc|Srrrs r __enter__zDebFile.__enter__s rc.|dSr)r)r4exc_typeexc_valexc_tbs r__exit__zDebFile.__exit__!s r)NrNrr)r,r-r.rr6rpropertyrrQr'rrrr(rrrrrrrrrsE  &&&&P666X''X'''X' ))) &&&    X    X FFFF * rr__main__rS)r)7rrrLr^sysos.pathrXpathlibrtypingrrrrrr r r r r rrtyping_extensionsr ImportError debian.arfilerrrdebian.changelogr debian.deb822rr\r]r[rrrrrrr*objectr0rrrr,argvdebr'rdprintrtrrrrs.  "                            """M "">"4333333333&&&&&&    . . .  DDD  29      w   ~~~~~f~~~B     g   CCCCCCCCLFFFFFfFFFR z '38A; ' ' 'C +//  C E#-- " "#####s"A AA