a
´i¯3 ã @ s¤ d Z g d¢ZddlZddlZddlZddlT ddlmZmZ ddlZdZ dZ
dZG dd „ d ejƒZ
dddddddddœd
d„Zedddfdd„Zeddfdd„ZdS )aS Interface 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.
)$Ú
CHECK_NONEÚCHECK_CRC32ÚCHECK_CRC64ÚCHECK_SHA256ÚCHECK_ID_MAXÚ
CHECK_UNKNOWNÚFILTER_LZMA1ÚFILTER_LZMA2ÚFILTER_DELTAÚ
FILTER_X86ÚFILTER_IA64Ú
FILTER_ARMÚFILTER_ARMTHUMBÚFILTER_POWERPCÚFILTER_SPARCÚFORMAT_AUTOÚ FORMAT_XZÚFORMAT_ALONEÚ
FORMAT_RAWÚMF_HC3ÚMF_HC4ÚMF_BT2ÚMF_BT3ÚMF_BT4Ú MODE_FASTÚMODE_NORMALÚPRESET_DEFAULTÚPRESET_EXTREMEÚLZMACompressorÚLZMADecompressorÚLZMAFileÚ LZMAErrorÚopenÚcompressÚ
decompressÚis_check_supportedé N)Ú*)Ú_encode_filter_propertiesÚ_decode_filter_propertiesé é c @ s e Zd ZdZd"dddddœdd„Zdd „ Zed
d„ ƒZdd
„ Zdd„ Z dd„ Z
dd„ Zd#dd„Zd$dd„Z
d%dd„Zd&dd„Zdd„ Zejfdd„Zd d!„ ZdS )'r a@ A file object providing transparent LZMA (de)compression.
An LZMAFile can act as a wrapper for an existing file object, or
refer directly to a named file on disk.
Note that LZMAFile provides a *binary* file interface - data read
is returned as bytes, and data to be written must be given as bytes.
NÚréÿÿÿÿ©ÚformatÚcheckÚpresetÚfiltersc C s& d| _ d| _t| _|dv rL|dkr*tdƒ‚|dur:tdƒ‚|du rFt}t}n@|dv r~|du r`t}t}t ||||d�| _
d | _ntd
|¡ƒ‚t
|tttjfƒrÊd|vr®|d7 }t ||¡| _ d| _|| _n*t|d
ƒsÞt|dƒrì|| _ || _ntdƒ‚| jtk�r"tj| j tt||d�}t |¡| _dS )aø Open an LZMA-compressed file in binary mode.
filename can be either an actual file name (given as a str,
bytes, or PathLike object), in which case the named file is
opened, or it can be an existing file object to read from or
write to.
mode can be "r" for reading (default), "w" for (over)writing,
"x" for creating exclusively, or "a" for appending. These can
equivalently be given as "rb", "wb", "xb" and "ab" respectively.
format specifies the container format to use for the file.
If mode is "r", this defaults to FORMAT_AUTO. Otherwise, the
default is FORMAT_XZ.
check specifies the integrity check to use. This argument can
only be used when opening a file for writing. For FORMAT_XZ,
the default is CHECK_CRC64. FORMAT_ALONE and FORMAT_RAW do not
support integrity checks - for these formats, check must be
omitted, or be CHECK_NONE.
When opening a file for reading, the *preset* argument is not
meaningful, and should be omitted. The *filters* argument should
also be omitted, except when format is FORMAT_RAW (in which case
it is required).
When opening a file for writing, the settings used by the
compressor can be specified either as a preset compression
level (with the *preset* argument), or in detail as a custom
filter chain (with the *filters* argument). For FORMAT_XZ and
FORMAT_ALONE, the default is to use the PRESET_DEFAULT preset
level. For FORMAT_RAW, the caller must always specify a filter
chain; the raw compressor does not support preset compression
levels.
preset (if provided) should be an integer in the range 0-9,
optionally OR-ed with the constant PRESET_EXTREME.
filters (if provided) should be a sequence of dicts. Each dict
should have an entry for "id" indicating ID of the filter, plus
additional entries for options to the filter.
NF)r+ Úrbr, zACannot specify an integrity check when opening a file for readingzICannot specify a preset compression level when opening a file for reading)ÚwÚwbÚaÚabÚxÚxbr- r% zInvalid mode: {!r}ÚbTÚreadÚwritez6filename must be a str, bytes, file or PathLike object)Útrailing_errorr. r1 )Ú_fpÚ_closefpÚ_MODE_CLOSEDÚ_modeÚ
ValueErrorr Ú
_MODE_READr Ú_MODE_WRITEr Ú_compressorÚ_posr. Ú
isinstanceÚstrÚbytesÚosÚPathLikeÚbuiltinsr! ÚhasattrÚ TypeErrorÚ_compressionÚDecompressReaderr r ÚioÚBufferedReaderÚ_buffer) ÚselfÚfilenameÚmoder. r/ r0 r1 Ú mode_codeÚraw© rX ú/usr/lib64/python3.9/lzma.pyÚ__init__1 sF ,ÿ
ÿzLZMAFile.__init__c C sÐ | j tkrdS z~| j tkr,| j ¡ d| _n"| j tkrN| j | j ¡ ¡ d| _W z&| j
rb| j ¡ W d| _d| _
t| _ qÌd| _d| _
t| _ 0 n>z&| j
r | j ¡ W d| _d| _
t| _ nd| _d| _
t| _ 0 0 dS )z«Flush and close the file.
May be called more than once without error. Once the file is
closed, any other operation on it will raise a ValueError.
NF)r@ r? rB rR ÚcloserC r= r; rD Úflushr> ©rS rX rX rY r[ † s6
þ
úþzLZMAFile.closec C s
| j tkS )zTrue if this file is closed.)r@ r? r] rX rX rY Úclosedž s zLZMAFile.closedc C s | ¡ | j ¡ S )z3Return the file descriptor for the underlying file.)Ú_check_not_closedr= Úfilenor] rX rX rY r` £ s zLZMAFile.filenoc C s | ¡ o| j ¡ S )z)Return whether the file supports seeking.)ÚreadablerR Úseekabler] rX rX rY rb ¨ s zLZMAFile.seekablec C s | ¡ | jtkS )z/Return whether the file was opened for reading.)r_ r@ rB r] rX rX rY ra ¬ s zLZMAFile.readablec C s | ¡ | jtkS )z/Return whether the file was opened for writing.)r_ r@ rC r] rX rX rY Úwritable± s zLZMAFile.writablec C s | ¡ | j |¡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.
)Ú_check_can_readrR Úpeek©rS ÚsizerX rX rY re ¶ s z
LZMAFile.peekc C s | ¡ | j |¡S )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.
)rd rR r: rf rX rX rY r: Á s z
LZMAFile.readc C s" | ¡ |dk rtj}| j |¡S )zêRead up to size uncompressed bytes, while trying to avoid
making multiple reads from the underlying stream. Reads up to a
buffer's worth of data if size is negative.
Returns b"" if the file is at EOF.
r% )rd rP ÚDEFAULT_BUFFER_SIZErR Úread1rf rX rX rY ri Ê s zLZMAFile.read1c C s | ¡ | j |¡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.
)rd rR Úreadlinerf rX rX rY rj Ö s zLZMAFile.readlinec C sX | ¡ t|ttfƒr t|ƒ}nt|ƒ}|j}| j |¡}| j
|¡ | j|7 _|S )a Write a bytes object to the file.
Returns the number of uncompressed bytes written, which is
always the length of data in bytes. Note that due to buffering,
the file on disk may not reflect the data written until close()
is called.
)Ú_check_can_writerF rH Ú bytearrayÚlenÚ
memoryviewÚnbytesrD r" r= r; rE )rS ÚdataÚlengthÚ
compressedrX rX rY r; à s
zLZMAFile.writec C s | ¡ | j ||¡S )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, so depending on the parameters,
this operation may be extremely slow.
)Ú_check_can_seekrR Úseek)rS ÚoffsetÚwhencerX rX rY rt õ s z
LZMAFile.seekc C s" | ¡ | jtkr| j ¡ S | jS )z!Return the current file position.)r_ r@ rB rR ÚtellrE r] rX rX rY rw s
z
LZMAFile.tell)Nr+ )r, )r, )r, )r, )Ú__name__Ú
__module__Ú__qualname__Ú__doc__rZ r[ Úpropertyr^ r` rb ra rc re r: ri rj r; rP ÚSEEK_SETrt rw rX rX rX rY r &