Edit File by line
/home/barbar84/www/wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../usr/lib64/python3....
File: _compression.py
"""Internal classes used by the gzip, lzma and bz2 modules"""
[0] Fix | Delete
[1] Fix | Delete
import io
[2] Fix | Delete
[3] Fix | Delete
[4] Fix | Delete
BUFFER_SIZE = io.DEFAULT_BUFFER_SIZE # Compressed data read chunk size
[5] Fix | Delete
[6] Fix | Delete
[7] Fix | Delete
class BaseStream(io.BufferedIOBase):
[8] Fix | Delete
"""Mode-checking helper functions."""
[9] Fix | Delete
[10] Fix | Delete
def _check_not_closed(self):
[11] Fix | Delete
if self.closed:
[12] Fix | Delete
raise ValueError("I/O operation on closed file")
[13] Fix | Delete
[14] Fix | Delete
def _check_can_read(self):
[15] Fix | Delete
if not self.readable():
[16] Fix | Delete
raise io.UnsupportedOperation("File not open for reading")
[17] Fix | Delete
[18] Fix | Delete
def _check_can_write(self):
[19] Fix | Delete
if not self.writable():
[20] Fix | Delete
raise io.UnsupportedOperation("File not open for writing")
[21] Fix | Delete
[22] Fix | Delete
def _check_can_seek(self):
[23] Fix | Delete
if not self.readable():
[24] Fix | Delete
raise io.UnsupportedOperation("Seeking is only supported "
[25] Fix | Delete
"on files open for reading")
[26] Fix | Delete
if not self.seekable():
[27] Fix | Delete
raise io.UnsupportedOperation("The underlying file object "
[28] Fix | Delete
"does not support seeking")
[29] Fix | Delete
[30] Fix | Delete
[31] Fix | Delete
class DecompressReader(io.RawIOBase):
[32] Fix | Delete
"""Adapts the decompressor API to a RawIOBase reader API"""
[33] Fix | Delete
[34] Fix | Delete
def readable(self):
[35] Fix | Delete
return True
[36] Fix | Delete
[37] Fix | Delete
def __init__(self, fp, decomp_factory, trailing_error=(), **decomp_args):
[38] Fix | Delete
self._fp = fp
[39] Fix | Delete
self._eof = False
[40] Fix | Delete
self._pos = 0 # Current offset in decompressed stream
[41] Fix | Delete
[42] Fix | Delete
# Set to size of decompressed stream once it is known, for SEEK_END
[43] Fix | Delete
self._size = -1
[44] Fix | Delete
[45] Fix | Delete
# Save the decompressor factory and arguments.
[46] Fix | Delete
# If the file contains multiple compressed streams, each
[47] Fix | Delete
# stream will need a separate decompressor object. A new decompressor
[48] Fix | Delete
# object is also needed when implementing a backwards seek().
[49] Fix | Delete
self._decomp_factory = decomp_factory
[50] Fix | Delete
self._decomp_args = decomp_args
[51] Fix | Delete
self._decompressor = self._decomp_factory(**self._decomp_args)
[52] Fix | Delete
[53] Fix | Delete
# Exception class to catch from decompressor signifying invalid
[54] Fix | Delete
# trailing data to ignore
[55] Fix | Delete
self._trailing_error = trailing_error
[56] Fix | Delete
[57] Fix | Delete
def close(self):
[58] Fix | Delete
self._decompressor = None
[59] Fix | Delete
return super().close()
[60] Fix | Delete
[61] Fix | Delete
def seekable(self):
[62] Fix | Delete
return self._fp.seekable()
[63] Fix | Delete
[64] Fix | Delete
def readinto(self, b):
[65] Fix | Delete
with memoryview(b) as view, view.cast("B") as byte_view:
[66] Fix | Delete
data = self.read(len(byte_view))
[67] Fix | Delete
byte_view[:len(data)] = data
[68] Fix | Delete
return len(data)
[69] Fix | Delete
[70] Fix | Delete
def read(self, size=-1):
[71] Fix | Delete
if size < 0:
[72] Fix | Delete
return self.readall()
[73] Fix | Delete
[74] Fix | Delete
if not size or self._eof:
[75] Fix | Delete
return b""
[76] Fix | Delete
data = None # Default if EOF is encountered
[77] Fix | Delete
# Depending on the input data, our call to the decompressor may not
[78] Fix | Delete
# return any data. In this case, try again after reading another block.
[79] Fix | Delete
while True:
[80] Fix | Delete
if self._decompressor.eof:
[81] Fix | Delete
rawblock = (self._decompressor.unused_data or
[82] Fix | Delete
self._fp.read(BUFFER_SIZE))
[83] Fix | Delete
if not rawblock:
[84] Fix | Delete
break
[85] Fix | Delete
# Continue to next stream.
[86] Fix | Delete
self._decompressor = self._decomp_factory(
[87] Fix | Delete
**self._decomp_args)
[88] Fix | Delete
try:
[89] Fix | Delete
data = self._decompressor.decompress(rawblock, size)
[90] Fix | Delete
except self._trailing_error:
[91] Fix | Delete
# Trailing data isn't a valid compressed stream; ignore it.
[92] Fix | Delete
break
[93] Fix | Delete
else:
[94] Fix | Delete
if self._decompressor.needs_input:
[95] Fix | Delete
rawblock = self._fp.read(BUFFER_SIZE)
[96] Fix | Delete
if not rawblock:
[97] Fix | Delete
raise EOFError("Compressed file ended before the "
[98] Fix | Delete
"end-of-stream marker was reached")
[99] Fix | Delete
else:
[100] Fix | Delete
rawblock = b""
[101] Fix | Delete
data = self._decompressor.decompress(rawblock, size)
[102] Fix | Delete
if data:
[103] Fix | Delete
break
[104] Fix | Delete
if not data:
[105] Fix | Delete
self._eof = True
[106] Fix | Delete
self._size = self._pos
[107] Fix | Delete
return b""
[108] Fix | Delete
self._pos += len(data)
[109] Fix | Delete
return data
[110] Fix | Delete
[111] Fix | Delete
# Rewind the file to the beginning of the data stream.
[112] Fix | Delete
def _rewind(self):
[113] Fix | Delete
self._fp.seek(0)
[114] Fix | Delete
self._eof = False
[115] Fix | Delete
self._pos = 0
[116] Fix | Delete
self._decompressor = self._decomp_factory(**self._decomp_args)
[117] Fix | Delete
[118] Fix | Delete
def seek(self, offset, whence=io.SEEK_SET):
[119] Fix | Delete
# Recalculate offset as an absolute file position.
[120] Fix | Delete
if whence == io.SEEK_SET:
[121] Fix | Delete
pass
[122] Fix | Delete
elif whence == io.SEEK_CUR:
[123] Fix | Delete
offset = self._pos + offset
[124] Fix | Delete
elif whence == io.SEEK_END:
[125] Fix | Delete
# Seeking relative to EOF - we need to know the file's size.
[126] Fix | Delete
if self._size < 0:
[127] Fix | Delete
while self.read(io.DEFAULT_BUFFER_SIZE):
[128] Fix | Delete
pass
[129] Fix | Delete
offset = self._size + offset
[130] Fix | Delete
else:
[131] Fix | Delete
raise ValueError("Invalid value for whence: {}".format(whence))
[132] Fix | Delete
[133] Fix | Delete
# Make it so that offset is the number of bytes to skip forward.
[134] Fix | Delete
if offset < self._pos:
[135] Fix | Delete
self._rewind()
[136] Fix | Delete
else:
[137] Fix | Delete
offset -= self._pos
[138] Fix | Delete
[139] Fix | Delete
# Read and discard data until we reach the desired position.
[140] Fix | Delete
while offset > 0:
[141] Fix | Delete
data = self.read(min(io.DEFAULT_BUFFER_SIZE, offset))
[142] Fix | Delete
if not data:
[143] Fix | Delete
break
[144] Fix | Delete
offset -= len(data)
[145] Fix | Delete
[146] Fix | Delete
return self._pos
[147] Fix | Delete
[148] Fix | Delete
def tell(self):
[149] Fix | Delete
"""Return the current file position."""
[150] Fix | Delete
return self._pos
[151] Fix | Delete
[152] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function