î ¼ê[«Kã$@sSdZddddddddd d d d d ddddddddddddddddddd d!d"d#d$g$Zd%d&lZd%d&lZd%d'lTd%d(lmZmZd%Zd)Zd*Z d+Z d,Z Gd-d„dej ƒZ d.d/d&d0d) d1d&d2d&d3d&d4d&d5d&d6d!„Zed) d&d&d7d"„Zed&d&d8d#„Zd&S)9aSInterface to the liblzma compression library. This module provides a class for reading and writing compressed files, classes for incremental (de)compression, and convenience functions for one-shot (de)compression. These classes and functions support both the XZ and legacy LZMA container formats, as well as raw compressed data streams. Z CHECK_NONEZ CHECK_CRC32Z CHECK_CRC64Z CHECK_SHA256Z CHECK_ID_MAXZ CHECK_UNKNOWNZ FILTER_LZMA1Z FILTER_LZMA2Z FILTER_DELTAZ FILTER_X86Z FILTER_IA64Z FILTER_ARMZFILTER_ARMTHUMBZFILTER_POWERPCZ FILTER_SPARCÚ FORMAT_AUTOÚ FORMAT_XZZ FORMAT_ALONEZ FORMAT_RAWZMF_HC3ZMF_HC4ZMF_BT2ZMF_BT3ZMF_BT4Z MODE_FASTZ MODE_NORMALZPRESET_DEFAULTZPRESET_EXTREMEÚLZMACompressorÚLZMADecompressorÚLZMAFileÚ LZMAErrorÚopenÚcompressÚ decompressZis_check_supportedéN)Ú*)Ú_encode_filter_propertiesÚ_decode_filter_propertieséééi c @sWeZdZdZdddddd7ddddd d „Zd d „Zed d„ƒZdd„Zdd„Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd „Zd!d"d#„Zd!d$d%„Zd8d&d'„Zd9d(d)„Zd:d*d+„Zd;d,d-„Zd.d/„Zd0d1„Zd2d3d4„Zd5d6„ZdS)ˆs     zLZMAFile.closecCs |jtkS)zTrue if this file is closed.)r%r$)r6r9r9r:Úclosed szLZMAFile.closedcCs|jƒ|jjƒS)z3Return the file descriptor for the underlying file.)Ú_check_not_closedr"Úfileno)r6r9r9r:rA¥s zLZMAFile.filenocCs|jƒo|jjƒS)z)Return whether the file supports seeking.)Úreadabler"Úseekable)r6r9r9r:rCªszLZMAFile.seekablecCs|jƒ|jttfkS)z/Return whether the file was opened for reading.)r@r%r)r<)r6r9r9r:rB®s zLZMAFile.readablecCs|jƒ|jtkS)z/Return whether the file was opened for writing.)r@r%r.)r6r9r9r:Úwritable³s zLZMAFile.writablecCs|jrtdƒ‚ndS)NzI/O operation on closed file)r?r()r6r9r9r:r@ºs zLZMAFile._check_not_closedcCs5|jttfkr1|jƒtjdƒ‚ndS)NzFile not open for reading)r%r)r<r@ÚioÚUnsupportedOperation)r6r9r9r:Ú_check_can_read¾s zLZMAFile._check_can_readcCs/|jtkr+|jƒtjdƒ‚ndS)NzFile not open for writing)r%r.r@rErF)r6r9r9r:Ú_check_can_writeÃs zLZMAFile._check_can_writecCsV|jttfkr1|jƒtjdƒ‚n|jjƒsRtjdƒ‚ndS)Nz3Seeking is only supported on files open for readingz3The underlying file object does not support seeking)r%r)r<r@rErFr"rC)r6r9r9r:Ú_check_can_seekÈs  zLZMAFile._check_can_seekc Cs|jtkrdSxú|jt|jƒkr|jjpI|jjt ƒ}|s†|jj rwt|_|j |_ dSt dƒ‚n|jj rît|j|_y|jj|ƒ|_Wqtk rêt|_|j |_ dSYqXn|jj|ƒ|_d|_qWdS)NFzACompressed file ended before the end-of-stream marker was reachedr T)r%r<r-Úlenr,r+Ú unused_datar"rÚ _BUFFER_SIZEÚeofr&r'ÚEOFErrorrr*r r)r6Zrawblockr9r9r:Ú _fill_bufferÒs,          zLZMAFile._fill_bufferTcCsŒ|j|jd…|_d|_g}xJ|jƒrt|rP|j|jƒn|jt|jƒ7_d|_q+W|rˆdj|ƒSdS)Nr r)r,r-rOÚappendr&rJÚjoin)r6Ú return_dataÚblocksr9r9r:Ú _read_allõs  zLZMAFile._read_allcCsC|j|}|t|jƒkrd|j|j|…}||_|jt|ƒ7_|r`|SdS|j|jd…|_d|_g}x|dkr+|jƒr+|t|jƒkrÛ|jd|…}||_n|j}d|_|r|j|ƒn|jt|ƒ7_|t|ƒ8}qW|r?dj|ƒSdS)Nr r)r-rJr,r&rOrPrQ)r6ÚnrRÚendÚdatarSr9r9r:Ú _read_blocks*      zLZMAFile._read_blockcCs.|jƒ|jƒsdS|j|jd…S)z¿Return buffered data without advancing the file position. Always returns at least one byte of data, unless at EOF. The exact number of bytes returned is unspecified. rN)rGrOr,r-)r6Úsizer9r9r:Úpeek!s  z LZMAFile.peekcCsA|jƒ|dkrdS|dkr0|jƒS|j|ƒSdS)z±Read up to size uncompressed bytes from the file. If size is negative or omitted, read until EOF is reached. Returns b"" if the file is already at EOF. r rN)rGrTrX)r6rYr9r9r:r,s     z LZMAFile.readcCsÁ|jƒ|dks;|jt|jƒkr?|jƒ r?dS|dkr€|j|j|j|…}|jt|ƒ7_n(|j|jd…}d|_d|_|jt|ƒ7_|S)z¨Read up to size uncompressed bytes, while trying to avoid making multiple reads from the underlying stream. Returns b"" if the file is at EOF. r rN)rGr-rJr,rOr&)r6rYrWr9r9r:Úread1:s  %    zLZMAFile.read1cCsŒ|jƒ|dkry|jjd|jƒd}|dkry|j|j|…}||_|jt|ƒ7_|Sntjj||ƒS)a Read a line of uncompressed bytes from the file. The terminating newline (if present) is retained. If size is non-negative, no more than size bytes will be read (in which case the line may be incomplete). Returns b'' if already at EOF. r s r) rGr,Úfindr-r&rJrEÚBufferedIOBaseÚreadline)r6rYrVÚliner9r9r:r^Ts    zLZMAFile.readlinecCsK|jƒ|jj|ƒ}|jj|ƒ|jt|ƒ7_t|ƒS)z÷Write a bytes object to the file. Returns the number of uncompressed bytes written, which is always len(data). Note that due to buffering, the file on disk may not reflect the data written until close() is called. )rHr/rr"r r&rJ)r6rWZ compressedr9r9r:r fs  zLZMAFile.writecCsM|jjddƒt|_d|_t|j|_d|_d|_ dS)Nr r) r"Úseekr)r%r&rr*r+r,r-)r6r9r9r:Ú_rewindts    zLZMAFile._rewindr cCsË|jƒ|dkrno|dkr5|j|}nS|dkrs|jdkrc|jddƒn|j|}ntdj|ƒƒ‚||jkr¤|jƒn ||j8}|j|ddƒ|jS)aðChange the file position. The new position is specified by offset, relative to the position indicated by whence. Possible values for whence are: 0: start of stream (default): offset must not be negative 1: current stream position 2: end of stream; offset must not be positive Returns the new file position. Note that seeking is emulated, sp depending on the parameters, this operation may be extremely slow. r rrrRFzInvalid value for whence: {})rIr&r'rTr(rrarX)r6ÚoffsetÚwhencer9r9r:r`|s      z LZMAFile.seekcCs|jƒ|jS)z!Return the current file position.)r@r&)r6r9r9r:Útell¥s z LZMAFile.tellr!r!r!r!r!)Ú__name__Ú __module__Ú __qualname__Ú__doc__r;r>Úpropertyr?rArCrBrDr@rGrHrIrOrTrXrZrr[r^r rar`rdr9r9r9r:r&s0  !V         #   )rrrrrÚencodingÚerrorsÚnewlinec Csåd|kr1d|kr‚td|fƒ‚q‚nQ|dk rLtdƒ‚n|dk rgtdƒ‚n|dk r‚tdƒ‚n|jddƒ} t|| d |d |d |d |ƒ} d|krÝtj| |||ƒS| SdS) a Open an LZMA-compressed file in binary or text mode. filename can be either an actual file name (given as a str or bytes object), in which case the named file is opened, or it can be an existing file object to read from or write to. The mode argument can be "r", "rb" (default), "w", "wb", "x", "xb", "a", or "ab" for binary mode, or "rt", "wt", "xt", or "at" for text mode. The format, check, preset and filters arguments specify the compression settings, as for LZMACompressor, LZMADecompressor and LZMAFile. For binary mode, this function is equivalent to the LZMAFile constructor: LZMAFile(filename, mode, ...). In this case, the encoding, errors and newline arguments must not be provided. For text mode, a LZMAFile object is created, and wrapped in an io.TextIOWrapper instance with the specified encoding, error handling behavior, and line ending(s). ÚtrzInvalid mode: %rNz0Argument 'encoding' not supported in binary modez.Argument 'errors' not supported in binary modez/Argument 'newline' not supported in binary modeÚrrrr)r(ÚreplacerrEÚ TextIOWrapper) r7r8rrrrrjrkrlZlz_modeZ binary_filer9r9r:r«s      cCs,t||||ƒ}|j|ƒ|jƒS)zãCompress a block of data. Refer to LZMACompressor's docstring for a description of the optional arguments *format*, *check*, *preset* and *filters*. For incremental compression, use an LZMACompressor instead. )rrr=)rWrrrrÚcompr9r9r:rÚsc Cs™g}xƒt|||ƒ}y|j|ƒ}Wntk rO|rHPn‚YnX|j|ƒ|jsutdƒ‚n|j}|s Pq q Wdj|ƒS)záDecompress a block of data. Refer to LZMADecompressor's docstring for a description of the optional arguments *format*, *check* and *filters*. For incremental decompression, use an LZMADecompressor instead. zACompressed data ended before the end-of-stream marker was reachedr)rr rrPrMrKrQ)rWrZmemlimitrZresultsZdecompZresr9r9r:r æs     )rhÚ__all__r3rEZ_lzmar r r$r)r<r.rLr]rrrrrr r9r9r9r:Ú s2        ÿ†-