FTc@sddkZddkZddkZddkZddkZddkiZ ddk Z ddkZddk i i ZddkZddkiZddkZddkZddkZddkZddkZddkZddkZddkZdeifdYZdefdYZdefdYZdefd YZd efd YZ d efd YZ!defdYZ"defdYZ#dS(iNt ArchiveErrorscBseZdZRS(s.Base exception class for archive class errors.(t__name__t __module__t__doc__(((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR0stInvalidArchiveIndexcBs eZdZdZdZRS(sUsed to indicate that the specified index is in a format not supported or recognized by this version of the pkg(5) ArchiveIndex class.cCsti|||_dS(N(Rt__init__t_InvalidArchiveIndex__name(tselftarc_name((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR9s cCstd|iS(Ns>%s is not in a supported or recognizable archive index format.(t_R(R((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyt__str__=s (RRRRR (((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR4s t ArchiveIndexcBsheZdZd ZdZd ZdZdd dZdZ e dZ dZ dZ d ZRS( sClass representing a pkg(5) archive table of contents and a set of interfaces to populate and retrieve entries. Entries in this file are written in the following format: NULNULNULNULNULNL is a string containing the pathname of the file in the archive. It can be up to 65,535 bytes in length. is an unsigned long long integer containing the relative offset in bytes of the first header block for the file in the archive. The offset is relative to the end of the last block of the first file in the archive. is an unsigned long long integer containing the size of the file's entry in bytes in the archive (including archive headers and trailers for the entry). is an unsigned long long integer containing the size of the file in bytes in the archive. is a single character representing the type of the file in the archive. Possible values are: 0 Regular File 1 Hard Link 2 Symbolic Link 5 Directory or subdirectoryis%s%d%d%d%c trcCstii|pt|djo |i}n||ijot|nt|_ ||_ |d|_ y"t i i|i |i |_Wn2tj o&}|iont|nX||_dS(sUOpen a pkg(5) archive table of contents file. 'name' should be the absolute path of the file to use when reading or writing index data. 'mode' indicates whether the index is being used for reading or writing, and can be 'r' or 'w'. Appending to or updating a table of contents file is not supported. 'version' is an optional integer value specifying the version of the index to be read or written. If not specified, the current version is assumed. tbN(tostpathtisabstAssertionErrortNonetCURRENT_VERSIONtCOMPATIBLE_VERSIONSRtFalset_ArchiveIndex__closedt_ArchiveIndex__namet_ArchiveIndex__modetpkgtpkggzipt PkgGzipFilet_ArchiveIndex__filetIOErrorterrnotversion(RtnametmodeRte((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyRes       cCs1|p|p|o|in |idS(sContext handler that ensures archive is automatically closed in a non-error condition scenario. This enables 'with' usage. N(t_ArchiveIndex__close_fhtclose(Rtexc_typet exc_valuetexc_tb((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyt__exit__scCs|iS(s,The absolute path of the archive index file.(R(R((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pytpathnamescCs*|ii|i|||||fdS(sQAdd an entry for the given archive file to the table of contents.N(Rtwritet ENTRY_FORMAT(RR toffsett entry_sizetsizettypeflag((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pytaddsccs|iidd}yx|iD]}|ddjo2|djo |}q#|d7}||7}q#n|djo |}n|idd\}}}|t|fVd}q#WWnVtj ot|in6tj o)}|i ont|inXdS(smReturns a generator that yields tuples of the form (name, offset) for each file in the index.iits iN( RtseekRtsplittlongt ValueErrorRRRR(RtltlineR R,tignoredR"((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pytoffsetss,        cCs@|iodS|io|iid|_nt|_dS(sgClose the index. No further operations can be performed using this object once closed.N(RRR$RtTrue(R((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR$s     N(i(RRRRRRRR+RR(tpropertyR)R0R9R$(((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR Bs%   tInvalidArchivecBs eZdZdZdZRS(sUsed to indicate that the specified archive is in a format not supported or recognized by this version of the pkg(5) Archive class. cCsti|||_dS(N(RRR(RR((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyRs cCstd|iS(Ns/Archive %s is missing, unsupported, or corrupt.(R R(R((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR s (RRRRR (((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR<s tCorruptArchiveFilescBs eZdZdZdZRS(s_Used to indicate that the specified file(s) could not be found in the archive. cCs#ti|||_||_dS(N(RRRtfiles(RRR>((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyRs  cCs+tdh|id6di|id6S(NscPackage archive %(arc_name)s contains corrupt entries for the requested package file(s): %(files)s.Rs R>(R RtjoinR>(R((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR s  (RRRRR (((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR=s tUnknownArchiveFilescBs eZdZdZdZRS(s_Used to indicate that the specified file(s) could not be found in the archive. cCs#ti|||_||_dS(N(RRRR>(RRR>((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyRs  cCs+tdh|id6di|id6S(NsWPackage archive %(arc_name)s does not contain the requested package file(s): %(files)s.Rs R>(R RR?R>(R((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR s  (RRRRR (((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR@s tUnknownPackageManifestcBs eZdZdZdZRS(snUsed to indicate that a manifest for the specified package could not be found in the archive. cCs#ti|||_||_dS(N(RRRtpfmri(RRRB((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyRs  cCstd|iS(NsKNo package manifest for package '%(pfmri)s' exists in archive %(arc_name)s.(R t__dict__(R((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyR s (RRRRR (((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyRAs tArchivecBsLeZdZdZdZdZeiZdZ dZ dZ dZ dZdZdddZdZdZd Zd Zdd Zddd Zddd ZdZdZddZddZddZddZdZdZddZe dZ!dZ"dZ#dZ$ddZ%e&dZ'RS( szClass representing a pkg(5) archive and a set of interfaces to populate it and retrieve data from it. This class stores package data in pax archives in version 4 repository format. Encoding the structure of a repository into the archive is necessary to enable easy composition of package archive contents with existing repositories and to enable consumers to access the contents of a package archive the same as they would a repository. This class can be used to access or extract the contents of almost any tar archive, except for those that are compressed. s pkg5.index.s.gzspkg5.index.%s.gziR cs&tii|pt|_t_|_ti _ d _ h_ |d}|d7}d|jpd|jptd|jptd|jo1tiii pt| ptnyti|d_WnStj oG}|ititifjotinti|nXd_ti_fd }ti|y.tiid |d id t i!_"WnEtj o}ti|n#t#j otinXh_$d|jofi"i%}|ptin|o|_$d S|i&i'i( p|i&i)i* od S|i&_+|i,i-dd}|i'dpd Sy#t.|i/ddd_0Wn(t1t2fj otinXi0i3jotini4\} } | i5y/i"i6|di dtii7| WnHt i8j otin%tj o}ti|nXi"i9} ySt:| d ddi;_<x.i<i=D]\} } | | i$| j o#ti?| tiq"tj o}ti|q"Xnd|joh_ fd}|i"_@i+i;_+i4\} } | i5t:| d |_<d_AtB_CiD_0iEdddnd S(s'pathname' is the absolute path of the archive file to create or read from. 'mode' is a string used to indicate whether the archive is being opened for reading or writing, which is indicated by 'r' and 'w' respectively. An archive opened for writing may not be used for any extraction operations, and must not already exist. 'archive_index', if supplied is the dictionary returned by self.get_index(), allowing multiple Archive objects to be open, sharing the same index object, for efficient use of memory. Using an existing archive_index requires mode='r'. R t:R twtaiiics&ipinidS(N(t_Archive__closedt_Archive__close_fht_Archive__cleanup((R(s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyt arc_cleanup]s  R!tfileobjtformatNtcommenttspkg5.archive.version.t.iiRtfilenameRcstiii||}|iotii|_n!|i otii |_n|i djodi |i dn|o|i|} ntii||} |i| d||ii|q>WdS(s1Private helper function for adding package files.ReiN(RR0RRR?tfile( RRRtfile_dirthashestfpathtrepotfhashthash_dirt hash_fnametsrc((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyt__add_publisher_filesDs"c Cs|i od|ijpt|pt|o| pt|p|pt|ip|i|_ntii|}|id|t i i |i }t i i d|i}t i i |d}xK||fD]=} | |ijo'|i|d| |ii| qqWt i i ||i} t i i | } | |ijo'|i|d| |ii| n|i|d| t i i |d} x!|iD]} | ipqnti| \}}}|pqnt|g}| idjox'| idtD]}|i|q/W|oU|ii|id }|p2|i|i|i|i<}|ptqqn|pqn|i|| |d |d |qWd S( sPrivate helper function that queues a package for addition to the archive. 'mpath' is the absolute path of the package manifest file. 'fpath' is an optional directory containing the package files stored by hash. 'repo' is an optional Repository object to use to retrieve the data for the package to be added to the archive. 'fpath' or 'repo' must be provided. RFR)RfRReRt signaturetleast_preferredRRN(RHRhRRRfRtmanifesttManifestt set_contentRRtdirnameRgR?RR0t get_dir_patht gen_actionst has_payloadtdigesttget_least_preferred_hashRR tget_chain_certsR:RlRRt get_publishert_Archive__add_publisher_files(RRBtmpathRRtmRRtpub_dirtpkg_dirtdRetman_dirRRGt pref_hattrthvalthfunctpayloadstctpub((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyt __add_packagegs^"      cCsm|o|o|ptt|totii|}n|ipt|i||d|dS(sKQueues the specified package for addition to the archive. The archive will be created and the package added to it when the close() method is called. The package contents must not change after this method is called while the archive is open. 'pfmri' is the FMRI string or object identifying the package to add. 'mpath' is the absolute path of the package manifest file. 'fpath' is the directory containing the package files stored by hash. RN(Rt isinstancet basestringRtfmritPkgFmriRft_Archive__add_package(RRBRR((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyt add_packages cCso|o|ptt|totii|}n|ipt|i||i|d|dS(sAQueues the specified package in a repository for addition to the archive. The archive will be created and the package added to it when the close() method is called. The package contents must not change after this method is called while the archive is open. 'pfmri' is the FMRI string or object identifying the package to add. 'repo' is the Repository object to use to retrieve the data for the package to be added to the archive. RN( RRRRRRRfRR(RRBR((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pytadd_repo_packages cCs|ig}|iD])}| p|i|jo ||qq~}|pt|i|gn|p|di}ntiid|tii}tii|dtii}tii||} ||i jo|i |} | otii| |} tii | pt|i| gny5t i i tii| |tii||Wqtj o} ti| qXn|i| |d|dSxE|iD]:} | i|o$d|i |<|i| |d|SqWt iidt}tii|dtii}x|iD]} | i|o| idd jo| idd \}}}ti|}ti|}t iid |d|d |}|i| }t ii d |}|i!d|i"dt|i#|d|q>q>W|i$} | |_%t&|_'|i(|i)| |i |}tiid|d|d |}|i ||d|qWdS(sExtract one or more package files from the archive. 'hashes' is a list of the files to extract named by their hash. 'path' is the absolute path of the directory to extract the files to. It will be created automatically if it does not exist. 'pub' is the prefix (name) of the publisher that the package files are associated with. If not provided, the first file named after the given hash found in the archive will be used. (This will be noticeably slower depending on the size of the archive.) R RiRQNRf(RHRhRRRRRRR?RRtdiscardR@Rg(RRRRR RRRe((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pytextract_package_filesSs6"         ROcCs|i od|ijpt|o|ptt|totii|}n|ipt|p|i }nt i i d|id|i }y|i ||d|Wn%tj ot|i|nXdS(sExtract a package manifest from the archive. 'pfmri' is the FMRI string or object identifying the package manifest to extract. 'path' is the absolute path of the directory to extract the manifest to. It will be created automatically if it does not exist. 'filename' is an optional name to use for the extracted file. If not provided, the default behaviour is to create a directory named after the package stem in 'path' and a file named after the version in that directory; both components will be URI encoded. R RfRRQN(RHRhRRRRRRRfRRRR?RR@RARg(RRBRRQRe((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pytextract_package_manifests"c CsN|i od|ijpt|ii|d}|i}|dj o|ii|||_ yt i i |}WnHt i j ot|in%tj o}ti|nX|i|jot|iqn*|iot|i|gn|}y |ii|d|d|Wnotj ot|i|gnIt i j ot|in%tj o}ti|nXt|t i pdSyb|p |i}ntii||}ti|i|ijot|i|gnWn$tj o}ti|nXdS(sExtract a member from the archive. 'src' is the pathname of the archive file to extract. 'path' is the absolute path of the directory to extract the file to. 'filename' is an optional string indicating the name to use for the extracted file. If not provided, the full member name in the archive will be used. R RRQN(RHRhRRRRRVRpR2R,R|tTarInfot fromtarfileRR<RgRqRtRuR R@RtKeyErrorRRRR?tstattst_sizeR.R=( RRRRQR,RRR"tdest((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyRsJ "       cCs|i od|ijpt|ii|d}|i}|dj o[|ii|||_ yt i i |}Wqt i j ot|iqXn*|iot|i|gn|}y|i|SWn(tj ot|i|gnXdS(sReturns an archive member as a file object. If the matching member is a regular file, a file-like object will be returned. If it is a link, a file-like object is constructed from the link's target. In all other cases, None will be returned. The file-like object is read-only and provides methods: read(), readline(), readlines(), seek() and tell(). The returned object must be closed before the archive is, and must not be used after the archive is closed. 'src' is the pathname of the archive file to return. R N(RHRhRRRRRVRpR2R,R|RRRR<RgR@t extractfileR(RRR,RR((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyRs" "    cCsA|i od|ijpt|ip|in|iS(sReturns the index, and extract_offsets from an Archive opened in read-only mode, allowing additional Archive objects to reuse the index, in a memory-efficient manner.R (RHRhRRR(R((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pyt get_index!s" c Cs|i od|ijpt|ip|in|pgtiid|d |}x/|iD]$}|i|o|i |SqgWt |i |gn|i tiid|d|d |S(sReturns the first package file matching the given hash as a file-like object. The file-like object is read-only and provides methods: read(), readline(), readlines(), seek() and tell(). The returned object must be closed before the archive is, and must not be used after the archive is closed. 'fhash' is the hash name of the file to return. 'pub' is the prefix (name) of the publisher that the package files are associated with. If not provided, the first file named after the given hash found in the archive will be used. (This will be noticeably slower depending on the size of the archive.) R RiRf( RHRhRRRRRR?RRR@Rg(RRRRR ((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pytget_package_file,s"  cCs|i od|ijpt|ptt|totii|}n|iptt i i d|id|i }y|i |}Wn%tj ot|i|nX|o|Stiid|}|id|idt|S(sReturns a package manifest from the archive. 'pfmri' is the FMRI string or object identifying the package manifest to extract. 'raw' is an optional boolean indicating whether the raw content of the Manifest should be returned. If True, a file-like object containing the content of the manifest. If False, a Manifest object will be returned. R RfRRBRR(RHRhRRRRRRRfRRR?RRR@RARgRRRRR:(RRBtrawReRR((s-/usr/lib/python2.6/vendor-packages/pkg/p5p.pytget_package_manifestOs "cCs<|io|iiS|ih|_x|iD]}|iddjo|ido|idd\}}tii d|d}y|i |}Wn(t j ot i ii|}nMXt iid|}t|djpt|dd}|pt||i|s4