Antoine Pitrou | 2dbc6e6 | 2015-04-11 00:31:01 +0200 | [diff] [blame] | 1 | import _compression |
| 2 | from io import BytesIO, UnsupportedOperation, DEFAULT_BUFFER_SIZE |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 3 | import os |
Nadeem Vawda | 3797065 | 2013-10-28 21:35:23 +0100 | [diff] [blame] | 4 | import pickle |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 5 | import random |
| 6 | import unittest |
| 7 | |
| 8 | from test.support import ( |
| 9 | _4G, TESTFN, import_module, bigmemtest, run_unittest, unlink |
| 10 | ) |
| 11 | |
| 12 | lzma = import_module("lzma") |
| 13 | from lzma import LZMACompressor, LZMADecompressor, LZMAError, LZMAFile |
| 14 | |
| 15 | |
| 16 | class CompressorDecompressorTestCase(unittest.TestCase): |
| 17 | |
| 18 | # Test error cases. |
| 19 | |
| 20 | def test_simple_bad_args(self): |
| 21 | self.assertRaises(TypeError, LZMACompressor, []) |
| 22 | self.assertRaises(TypeError, LZMACompressor, format=3.45) |
| 23 | self.assertRaises(TypeError, LZMACompressor, check="") |
| 24 | self.assertRaises(TypeError, LZMACompressor, preset="asdf") |
| 25 | self.assertRaises(TypeError, LZMACompressor, filters=3) |
| 26 | # Can't specify FORMAT_AUTO when compressing. |
| 27 | self.assertRaises(ValueError, LZMACompressor, format=lzma.FORMAT_AUTO) |
| 28 | # Can't specify a preset and a custom filter chain at the same time. |
| 29 | with self.assertRaises(ValueError): |
| 30 | LZMACompressor(preset=7, filters=[{"id": lzma.FILTER_LZMA2}]) |
| 31 | |
| 32 | self.assertRaises(TypeError, LZMADecompressor, ()) |
| 33 | self.assertRaises(TypeError, LZMADecompressor, memlimit=b"qw") |
| 34 | with self.assertRaises(TypeError): |
| 35 | LZMADecompressor(lzma.FORMAT_RAW, filters="zzz") |
| 36 | # Cannot specify a memory limit with FILTER_RAW. |
| 37 | with self.assertRaises(ValueError): |
| 38 | LZMADecompressor(lzma.FORMAT_RAW, memlimit=0x1000000) |
| 39 | # Can only specify a custom filter chain with FILTER_RAW. |
| 40 | self.assertRaises(ValueError, LZMADecompressor, filters=FILTERS_RAW_1) |
| 41 | with self.assertRaises(ValueError): |
| 42 | LZMADecompressor(format=lzma.FORMAT_XZ, filters=FILTERS_RAW_1) |
| 43 | with self.assertRaises(ValueError): |
| 44 | LZMADecompressor(format=lzma.FORMAT_ALONE, filters=FILTERS_RAW_1) |
| 45 | |
| 46 | lzc = LZMACompressor() |
| 47 | self.assertRaises(TypeError, lzc.compress) |
| 48 | self.assertRaises(TypeError, lzc.compress, b"foo", b"bar") |
| 49 | self.assertRaises(TypeError, lzc.flush, b"blah") |
| 50 | empty = lzc.flush() |
| 51 | self.assertRaises(ValueError, lzc.compress, b"quux") |
| 52 | self.assertRaises(ValueError, lzc.flush) |
| 53 | |
| 54 | lzd = LZMADecompressor() |
| 55 | self.assertRaises(TypeError, lzd.decompress) |
| 56 | self.assertRaises(TypeError, lzd.decompress, b"foo", b"bar") |
| 57 | lzd.decompress(empty) |
| 58 | self.assertRaises(EOFError, lzd.decompress, b"quux") |
| 59 | |
| 60 | def test_bad_filter_spec(self): |
| 61 | self.assertRaises(TypeError, LZMACompressor, filters=[b"wobsite"]) |
| 62 | self.assertRaises(ValueError, LZMACompressor, filters=[{"xyzzy": 3}]) |
| 63 | self.assertRaises(ValueError, LZMACompressor, filters=[{"id": 98765}]) |
| 64 | with self.assertRaises(ValueError): |
| 65 | LZMACompressor(filters=[{"id": lzma.FILTER_LZMA2, "foo": 0}]) |
| 66 | with self.assertRaises(ValueError): |
| 67 | LZMACompressor(filters=[{"id": lzma.FILTER_DELTA, "foo": 0}]) |
| 68 | with self.assertRaises(ValueError): |
| 69 | LZMACompressor(filters=[{"id": lzma.FILTER_X86, "foo": 0}]) |
| 70 | |
| 71 | def test_decompressor_after_eof(self): |
| 72 | lzd = LZMADecompressor() |
| 73 | lzd.decompress(COMPRESSED_XZ) |
| 74 | self.assertRaises(EOFError, lzd.decompress, b"nyan") |
| 75 | |
| 76 | def test_decompressor_memlimit(self): |
| 77 | lzd = LZMADecompressor(memlimit=1024) |
| 78 | self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_XZ) |
| 79 | |
| 80 | lzd = LZMADecompressor(lzma.FORMAT_XZ, memlimit=1024) |
| 81 | self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_XZ) |
| 82 | |
| 83 | lzd = LZMADecompressor(lzma.FORMAT_ALONE, memlimit=1024) |
| 84 | self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_ALONE) |
| 85 | |
| 86 | # Test LZMADecompressor on known-good input data. |
| 87 | |
| 88 | def _test_decompressor(self, lzd, data, check, unused_data=b""): |
| 89 | self.assertFalse(lzd.eof) |
| 90 | out = lzd.decompress(data) |
| 91 | self.assertEqual(out, INPUT) |
| 92 | self.assertEqual(lzd.check, check) |
| 93 | self.assertTrue(lzd.eof) |
| 94 | self.assertEqual(lzd.unused_data, unused_data) |
| 95 | |
| 96 | def test_decompressor_auto(self): |
| 97 | lzd = LZMADecompressor() |
| 98 | self._test_decompressor(lzd, COMPRESSED_XZ, lzma.CHECK_CRC64) |
| 99 | |
| 100 | lzd = LZMADecompressor() |
| 101 | self._test_decompressor(lzd, COMPRESSED_ALONE, lzma.CHECK_NONE) |
| 102 | |
| 103 | def test_decompressor_xz(self): |
| 104 | lzd = LZMADecompressor(lzma.FORMAT_XZ) |
| 105 | self._test_decompressor(lzd, COMPRESSED_XZ, lzma.CHECK_CRC64) |
| 106 | |
| 107 | def test_decompressor_alone(self): |
| 108 | lzd = LZMADecompressor(lzma.FORMAT_ALONE) |
| 109 | self._test_decompressor(lzd, COMPRESSED_ALONE, lzma.CHECK_NONE) |
| 110 | |
| 111 | def test_decompressor_raw_1(self): |
| 112 | lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_1) |
| 113 | self._test_decompressor(lzd, COMPRESSED_RAW_1, lzma.CHECK_NONE) |
| 114 | |
| 115 | def test_decompressor_raw_2(self): |
| 116 | lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_2) |
| 117 | self._test_decompressor(lzd, COMPRESSED_RAW_2, lzma.CHECK_NONE) |
| 118 | |
| 119 | def test_decompressor_raw_3(self): |
| 120 | lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_3) |
| 121 | self._test_decompressor(lzd, COMPRESSED_RAW_3, lzma.CHECK_NONE) |
| 122 | |
| 123 | def test_decompressor_raw_4(self): |
| 124 | lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4) |
| 125 | self._test_decompressor(lzd, COMPRESSED_RAW_4, lzma.CHECK_NONE) |
| 126 | |
| 127 | def test_decompressor_chunks(self): |
| 128 | lzd = LZMADecompressor() |
| 129 | out = [] |
| 130 | for i in range(0, len(COMPRESSED_XZ), 10): |
| 131 | self.assertFalse(lzd.eof) |
| 132 | out.append(lzd.decompress(COMPRESSED_XZ[i:i+10])) |
| 133 | out = b"".join(out) |
| 134 | self.assertEqual(out, INPUT) |
| 135 | self.assertEqual(lzd.check, lzma.CHECK_CRC64) |
| 136 | self.assertTrue(lzd.eof) |
| 137 | self.assertEqual(lzd.unused_data, b"") |
| 138 | |
Antoine Pitrou | 26795ba | 2015-01-17 16:22:18 +0100 | [diff] [blame] | 139 | def test_decompressor_chunks_maxsize(self): |
| 140 | lzd = LZMADecompressor() |
| 141 | max_length = 100 |
| 142 | out = [] |
| 143 | |
| 144 | # Feed first half the input |
| 145 | len_ = len(COMPRESSED_XZ) // 2 |
| 146 | out.append(lzd.decompress(COMPRESSED_XZ[:len_], |
| 147 | max_length=max_length)) |
| 148 | self.assertFalse(lzd.needs_input) |
| 149 | self.assertEqual(len(out[-1]), max_length) |
| 150 | |
| 151 | # Retrieve more data without providing more input |
| 152 | out.append(lzd.decompress(b'', max_length=max_length)) |
| 153 | self.assertFalse(lzd.needs_input) |
| 154 | self.assertEqual(len(out[-1]), max_length) |
| 155 | |
| 156 | # Retrieve more data while providing more input |
| 157 | out.append(lzd.decompress(COMPRESSED_XZ[len_:], |
| 158 | max_length=max_length)) |
| 159 | self.assertLessEqual(len(out[-1]), max_length) |
| 160 | |
| 161 | # Retrieve remaining uncompressed data |
| 162 | while not lzd.eof: |
| 163 | out.append(lzd.decompress(b'', max_length=max_length)) |
| 164 | self.assertLessEqual(len(out[-1]), max_length) |
| 165 | |
| 166 | out = b"".join(out) |
| 167 | self.assertEqual(out, INPUT) |
| 168 | self.assertEqual(lzd.check, lzma.CHECK_CRC64) |
| 169 | self.assertEqual(lzd.unused_data, b"") |
| 170 | |
| 171 | def test_decompressor_inputbuf_1(self): |
| 172 | # Test reusing input buffer after moving existing |
| 173 | # contents to beginning |
| 174 | lzd = LZMADecompressor() |
| 175 | out = [] |
| 176 | |
| 177 | # Create input buffer and fill it |
| 178 | self.assertEqual(lzd.decompress(COMPRESSED_XZ[:100], |
| 179 | max_length=0), b'') |
| 180 | |
| 181 | # Retrieve some results, freeing capacity at beginning |
| 182 | # of input buffer |
| 183 | out.append(lzd.decompress(b'', 2)) |
| 184 | |
| 185 | # Add more data that fits into input buffer after |
| 186 | # moving existing data to beginning |
| 187 | out.append(lzd.decompress(COMPRESSED_XZ[100:105], 15)) |
| 188 | |
| 189 | # Decompress rest of data |
| 190 | out.append(lzd.decompress(COMPRESSED_XZ[105:])) |
| 191 | self.assertEqual(b''.join(out), INPUT) |
| 192 | |
| 193 | def test_decompressor_inputbuf_2(self): |
| 194 | # Test reusing input buffer by appending data at the |
| 195 | # end right away |
| 196 | lzd = LZMADecompressor() |
| 197 | out = [] |
| 198 | |
| 199 | # Create input buffer and empty it |
| 200 | self.assertEqual(lzd.decompress(COMPRESSED_XZ[:200], |
| 201 | max_length=0), b'') |
| 202 | out.append(lzd.decompress(b'')) |
| 203 | |
| 204 | # Fill buffer with new data |
| 205 | out.append(lzd.decompress(COMPRESSED_XZ[200:280], 2)) |
| 206 | |
| 207 | # Append some more data, not enough to require resize |
| 208 | out.append(lzd.decompress(COMPRESSED_XZ[280:300], 2)) |
| 209 | |
| 210 | # Decompress rest of data |
| 211 | out.append(lzd.decompress(COMPRESSED_XZ[300:])) |
| 212 | self.assertEqual(b''.join(out), INPUT) |
| 213 | |
| 214 | def test_decompressor_inputbuf_3(self): |
| 215 | # Test reusing input buffer after extending it |
| 216 | |
| 217 | lzd = LZMADecompressor() |
| 218 | out = [] |
| 219 | |
| 220 | # Create almost full input buffer |
| 221 | out.append(lzd.decompress(COMPRESSED_XZ[:200], 5)) |
| 222 | |
| 223 | # Add even more data to it, requiring resize |
| 224 | out.append(lzd.decompress(COMPRESSED_XZ[200:300], 5)) |
| 225 | |
| 226 | # Decompress rest of data |
| 227 | out.append(lzd.decompress(COMPRESSED_XZ[300:])) |
| 228 | self.assertEqual(b''.join(out), INPUT) |
| 229 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 230 | def test_decompressor_unused_data(self): |
| 231 | lzd = LZMADecompressor() |
| 232 | extra = b"fooblibar" |
| 233 | self._test_decompressor(lzd, COMPRESSED_XZ + extra, lzma.CHECK_CRC64, |
| 234 | unused_data=extra) |
| 235 | |
| 236 | def test_decompressor_bad_input(self): |
| 237 | lzd = LZMADecompressor() |
| 238 | self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_RAW_1) |
| 239 | |
| 240 | lzd = LZMADecompressor(lzma.FORMAT_XZ) |
| 241 | self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_ALONE) |
| 242 | |
| 243 | lzd = LZMADecompressor(lzma.FORMAT_ALONE) |
| 244 | self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_XZ) |
| 245 | |
| 246 | lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_1) |
| 247 | self.assertRaises(LZMAError, lzd.decompress, COMPRESSED_XZ) |
| 248 | |
| 249 | # Test that LZMACompressor->LZMADecompressor preserves the input data. |
| 250 | |
| 251 | def test_roundtrip_xz(self): |
| 252 | lzc = LZMACompressor() |
| 253 | cdata = lzc.compress(INPUT) + lzc.flush() |
| 254 | lzd = LZMADecompressor() |
| 255 | self._test_decompressor(lzd, cdata, lzma.CHECK_CRC64) |
| 256 | |
| 257 | def test_roundtrip_alone(self): |
| 258 | lzc = LZMACompressor(lzma.FORMAT_ALONE) |
| 259 | cdata = lzc.compress(INPUT) + lzc.flush() |
| 260 | lzd = LZMADecompressor() |
| 261 | self._test_decompressor(lzd, cdata, lzma.CHECK_NONE) |
| 262 | |
| 263 | def test_roundtrip_raw(self): |
| 264 | lzc = LZMACompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4) |
| 265 | cdata = lzc.compress(INPUT) + lzc.flush() |
| 266 | lzd = LZMADecompressor(lzma.FORMAT_RAW, filters=FILTERS_RAW_4) |
| 267 | self._test_decompressor(lzd, cdata, lzma.CHECK_NONE) |
| 268 | |
| 269 | def test_roundtrip_chunks(self): |
| 270 | lzc = LZMACompressor() |
| 271 | cdata = [] |
| 272 | for i in range(0, len(INPUT), 10): |
| 273 | cdata.append(lzc.compress(INPUT[i:i+10])) |
| 274 | cdata.append(lzc.flush()) |
| 275 | cdata = b"".join(cdata) |
| 276 | lzd = LZMADecompressor() |
| 277 | self._test_decompressor(lzd, cdata, lzma.CHECK_CRC64) |
| 278 | |
| 279 | # LZMADecompressor intentionally does not handle concatenated streams. |
| 280 | |
| 281 | def test_decompressor_multistream(self): |
| 282 | lzd = LZMADecompressor() |
| 283 | self._test_decompressor(lzd, COMPRESSED_XZ + COMPRESSED_ALONE, |
| 284 | lzma.CHECK_CRC64, unused_data=COMPRESSED_ALONE) |
| 285 | |
| 286 | # Test with inputs larger than 4GiB. |
| 287 | |
| 288 | @bigmemtest(size=_4G + 100, memuse=2) |
| 289 | def test_compressor_bigmem(self, size): |
| 290 | lzc = LZMACompressor() |
| 291 | cdata = lzc.compress(b"x" * size) + lzc.flush() |
| 292 | ddata = lzma.decompress(cdata) |
| 293 | try: |
| 294 | self.assertEqual(len(ddata), size) |
| 295 | self.assertEqual(len(ddata.strip(b"x")), 0) |
| 296 | finally: |
| 297 | ddata = None |
| 298 | |
| 299 | @bigmemtest(size=_4G + 100, memuse=3) |
| 300 | def test_decompressor_bigmem(self, size): |
| 301 | lzd = LZMADecompressor() |
| 302 | blocksize = 10 * 1024 * 1024 |
| 303 | block = random.getrandbits(blocksize * 8).to_bytes(blocksize, "little") |
| 304 | try: |
| 305 | input = block * (size // blocksize + 1) |
| 306 | cdata = lzma.compress(input) |
| 307 | ddata = lzd.decompress(cdata) |
| 308 | self.assertEqual(ddata, input) |
| 309 | finally: |
| 310 | input = cdata = ddata = None |
| 311 | |
Nadeem Vawda | 3797065 | 2013-10-28 21:35:23 +0100 | [diff] [blame] | 312 | # Pickling raises an exception; there's no way to serialize an lzma_stream. |
| 313 | |
| 314 | def test_pickle(self): |
Serhiy Storchaka | bad1257 | 2014-12-15 14:03:42 +0200 | [diff] [blame] | 315 | for proto in range(pickle.HIGHEST_PROTOCOL + 1): |
| 316 | with self.assertRaises(TypeError): |
| 317 | pickle.dumps(LZMACompressor(), proto) |
| 318 | with self.assertRaises(TypeError): |
| 319 | pickle.dumps(LZMADecompressor(), proto) |
Nadeem Vawda | 3797065 | 2013-10-28 21:35:23 +0100 | [diff] [blame] | 320 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 321 | |
| 322 | class CompressDecompressFunctionTestCase(unittest.TestCase): |
| 323 | |
| 324 | # Test error cases: |
| 325 | |
| 326 | def test_bad_args(self): |
| 327 | self.assertRaises(TypeError, lzma.compress) |
| 328 | self.assertRaises(TypeError, lzma.compress, []) |
| 329 | self.assertRaises(TypeError, lzma.compress, b"", format="xz") |
| 330 | self.assertRaises(TypeError, lzma.compress, b"", check="none") |
| 331 | self.assertRaises(TypeError, lzma.compress, b"", preset="blah") |
| 332 | self.assertRaises(TypeError, lzma.compress, b"", filters=1024) |
| 333 | # Can't specify a preset and a custom filter chain at the same time. |
| 334 | with self.assertRaises(ValueError): |
| 335 | lzma.compress(b"", preset=3, filters=[{"id": lzma.FILTER_LZMA2}]) |
| 336 | |
| 337 | self.assertRaises(TypeError, lzma.decompress) |
| 338 | self.assertRaises(TypeError, lzma.decompress, []) |
| 339 | self.assertRaises(TypeError, lzma.decompress, b"", format="lzma") |
| 340 | self.assertRaises(TypeError, lzma.decompress, b"", memlimit=7.3e9) |
| 341 | with self.assertRaises(TypeError): |
| 342 | lzma.decompress(b"", format=lzma.FORMAT_RAW, filters={}) |
| 343 | # Cannot specify a memory limit with FILTER_RAW. |
| 344 | with self.assertRaises(ValueError): |
| 345 | lzma.decompress(b"", format=lzma.FORMAT_RAW, memlimit=0x1000000) |
| 346 | # Can only specify a custom filter chain with FILTER_RAW. |
| 347 | with self.assertRaises(ValueError): |
| 348 | lzma.decompress(b"", filters=FILTERS_RAW_1) |
| 349 | with self.assertRaises(ValueError): |
| 350 | lzma.decompress(b"", format=lzma.FORMAT_XZ, filters=FILTERS_RAW_1) |
| 351 | with self.assertRaises(ValueError): |
| 352 | lzma.decompress( |
| 353 | b"", format=lzma.FORMAT_ALONE, filters=FILTERS_RAW_1) |
| 354 | |
| 355 | def test_decompress_memlimit(self): |
| 356 | with self.assertRaises(LZMAError): |
| 357 | lzma.decompress(COMPRESSED_XZ, memlimit=1024) |
| 358 | with self.assertRaises(LZMAError): |
| 359 | lzma.decompress( |
| 360 | COMPRESSED_XZ, format=lzma.FORMAT_XZ, memlimit=1024) |
| 361 | with self.assertRaises(LZMAError): |
| 362 | lzma.decompress( |
| 363 | COMPRESSED_ALONE, format=lzma.FORMAT_ALONE, memlimit=1024) |
| 364 | |
| 365 | # Test LZMADecompressor on known-good input data. |
| 366 | |
| 367 | def test_decompress_good_input(self): |
| 368 | ddata = lzma.decompress(COMPRESSED_XZ) |
| 369 | self.assertEqual(ddata, INPUT) |
| 370 | |
| 371 | ddata = lzma.decompress(COMPRESSED_ALONE) |
| 372 | self.assertEqual(ddata, INPUT) |
| 373 | |
| 374 | ddata = lzma.decompress(COMPRESSED_XZ, lzma.FORMAT_XZ) |
| 375 | self.assertEqual(ddata, INPUT) |
| 376 | |
| 377 | ddata = lzma.decompress(COMPRESSED_ALONE, lzma.FORMAT_ALONE) |
| 378 | self.assertEqual(ddata, INPUT) |
| 379 | |
| 380 | ddata = lzma.decompress( |
| 381 | COMPRESSED_RAW_1, lzma.FORMAT_RAW, filters=FILTERS_RAW_1) |
| 382 | self.assertEqual(ddata, INPUT) |
| 383 | |
| 384 | ddata = lzma.decompress( |
| 385 | COMPRESSED_RAW_2, lzma.FORMAT_RAW, filters=FILTERS_RAW_2) |
| 386 | self.assertEqual(ddata, INPUT) |
| 387 | |
| 388 | ddata = lzma.decompress( |
| 389 | COMPRESSED_RAW_3, lzma.FORMAT_RAW, filters=FILTERS_RAW_3) |
| 390 | self.assertEqual(ddata, INPUT) |
| 391 | |
| 392 | ddata = lzma.decompress( |
| 393 | COMPRESSED_RAW_4, lzma.FORMAT_RAW, filters=FILTERS_RAW_4) |
| 394 | self.assertEqual(ddata, INPUT) |
| 395 | |
| 396 | def test_decompress_incomplete_input(self): |
| 397 | self.assertRaises(LZMAError, lzma.decompress, COMPRESSED_XZ[:128]) |
| 398 | self.assertRaises(LZMAError, lzma.decompress, COMPRESSED_ALONE[:128]) |
| 399 | self.assertRaises(LZMAError, lzma.decompress, COMPRESSED_RAW_1[:128], |
| 400 | format=lzma.FORMAT_RAW, filters=FILTERS_RAW_1) |
| 401 | self.assertRaises(LZMAError, lzma.decompress, COMPRESSED_RAW_2[:128], |
| 402 | format=lzma.FORMAT_RAW, filters=FILTERS_RAW_2) |
| 403 | self.assertRaises(LZMAError, lzma.decompress, COMPRESSED_RAW_3[:128], |
| 404 | format=lzma.FORMAT_RAW, filters=FILTERS_RAW_3) |
| 405 | self.assertRaises(LZMAError, lzma.decompress, COMPRESSED_RAW_4[:128], |
| 406 | format=lzma.FORMAT_RAW, filters=FILTERS_RAW_4) |
| 407 | |
| 408 | def test_decompress_bad_input(self): |
| 409 | with self.assertRaises(LZMAError): |
Nadeem Vawda | 9c72ebc | 2013-12-04 23:03:49 +0100 | [diff] [blame] | 410 | lzma.decompress(COMPRESSED_BOGUS) |
| 411 | with self.assertRaises(LZMAError): |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 412 | lzma.decompress(COMPRESSED_RAW_1) |
| 413 | with self.assertRaises(LZMAError): |
| 414 | lzma.decompress(COMPRESSED_ALONE, format=lzma.FORMAT_XZ) |
| 415 | with self.assertRaises(LZMAError): |
| 416 | lzma.decompress(COMPRESSED_XZ, format=lzma.FORMAT_ALONE) |
| 417 | with self.assertRaises(LZMAError): |
| 418 | lzma.decompress(COMPRESSED_XZ, format=lzma.FORMAT_RAW, |
| 419 | filters=FILTERS_RAW_1) |
| 420 | |
| 421 | # Test that compress()->decompress() preserves the input data. |
| 422 | |
| 423 | def test_roundtrip(self): |
| 424 | cdata = lzma.compress(INPUT) |
| 425 | ddata = lzma.decompress(cdata) |
| 426 | self.assertEqual(ddata, INPUT) |
| 427 | |
| 428 | cdata = lzma.compress(INPUT, lzma.FORMAT_XZ) |
| 429 | ddata = lzma.decompress(cdata) |
| 430 | self.assertEqual(ddata, INPUT) |
| 431 | |
| 432 | cdata = lzma.compress(INPUT, lzma.FORMAT_ALONE) |
| 433 | ddata = lzma.decompress(cdata) |
| 434 | self.assertEqual(ddata, INPUT) |
| 435 | |
| 436 | cdata = lzma.compress(INPUT, lzma.FORMAT_RAW, filters=FILTERS_RAW_4) |
| 437 | ddata = lzma.decompress(cdata, lzma.FORMAT_RAW, filters=FILTERS_RAW_4) |
| 438 | self.assertEqual(ddata, INPUT) |
| 439 | |
| 440 | # Unlike LZMADecompressor, decompress() *does* handle concatenated streams. |
| 441 | |
| 442 | def test_decompress_multistream(self): |
| 443 | ddata = lzma.decompress(COMPRESSED_XZ + COMPRESSED_ALONE) |
| 444 | self.assertEqual(ddata, INPUT * 2) |
| 445 | |
Nadeem Vawda | 9c72ebc | 2013-12-04 23:03:49 +0100 | [diff] [blame] | 446 | # Test robust handling of non-LZMA data following the compressed stream(s). |
| 447 | |
| 448 | def test_decompress_trailing_junk(self): |
| 449 | ddata = lzma.decompress(COMPRESSED_XZ + COMPRESSED_BOGUS) |
| 450 | self.assertEqual(ddata, INPUT) |
| 451 | |
| 452 | def test_decompress_multistream_trailing_junk(self): |
| 453 | ddata = lzma.decompress(COMPRESSED_XZ * 3 + COMPRESSED_BOGUS) |
| 454 | self.assertEqual(ddata, INPUT * 3) |
| 455 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 456 | |
| 457 | class TempFile: |
| 458 | """Context manager - creates a file, and deletes it on __exit__.""" |
| 459 | |
| 460 | def __init__(self, filename, data=b""): |
| 461 | self.filename = filename |
| 462 | self.data = data |
| 463 | |
| 464 | def __enter__(self): |
| 465 | with open(self.filename, "wb") as f: |
| 466 | f.write(self.data) |
| 467 | |
| 468 | def __exit__(self, *args): |
| 469 | unlink(self.filename) |
| 470 | |
| 471 | |
| 472 | class FileTestCase(unittest.TestCase): |
| 473 | |
| 474 | def test_init(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 475 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 476 | pass |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 477 | with LZMAFile(BytesIO(), "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 478 | pass |
Nadeem Vawda | 42ca982 | 2013-10-19 00:06:19 +0200 | [diff] [blame] | 479 | with LZMAFile(BytesIO(), "x") as f: |
| 480 | pass |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 481 | with LZMAFile(BytesIO(), "a") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 482 | pass |
| 483 | |
| 484 | def test_init_with_filename(self): |
| 485 | with TempFile(TESTFN, COMPRESSED_XZ): |
| 486 | with LZMAFile(TESTFN) as f: |
| 487 | pass |
| 488 | with LZMAFile(TESTFN, "w") as f: |
| 489 | pass |
| 490 | with LZMAFile(TESTFN, "a") as f: |
| 491 | pass |
| 492 | |
Nadeem Vawda | 6cbb20c | 2012-06-04 23:36:24 +0200 | [diff] [blame] | 493 | def test_init_mode(self): |
| 494 | with TempFile(TESTFN): |
| 495 | with LZMAFile(TESTFN, "r"): |
| 496 | pass |
| 497 | with LZMAFile(TESTFN, "rb"): |
| 498 | pass |
| 499 | with LZMAFile(TESTFN, "w"): |
| 500 | pass |
| 501 | with LZMAFile(TESTFN, "wb"): |
| 502 | pass |
| 503 | with LZMAFile(TESTFN, "a"): |
| 504 | pass |
| 505 | with LZMAFile(TESTFN, "ab"): |
| 506 | pass |
| 507 | |
Nadeem Vawda | 42ca982 | 2013-10-19 00:06:19 +0200 | [diff] [blame] | 508 | def test_init_with_x_mode(self): |
| 509 | self.addCleanup(unlink, TESTFN) |
| 510 | for mode in ("x", "xb"): |
| 511 | unlink(TESTFN) |
| 512 | with LZMAFile(TESTFN, mode): |
| 513 | pass |
| 514 | with self.assertRaises(FileExistsError): |
| 515 | with LZMAFile(TESTFN, mode): |
| 516 | pass |
| 517 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 518 | def test_init_bad_mode(self): |
| 519 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 520 | LZMAFile(BytesIO(COMPRESSED_XZ), (3, "x")) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 521 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 522 | LZMAFile(BytesIO(COMPRESSED_XZ), "") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 523 | with self.assertRaises(ValueError): |
Nadeem Vawda | 42ca982 | 2013-10-19 00:06:19 +0200 | [diff] [blame] | 524 | LZMAFile(BytesIO(COMPRESSED_XZ), "xt") |
| 525 | with self.assertRaises(ValueError): |
| 526 | LZMAFile(BytesIO(COMPRESSED_XZ), "x+") |
| 527 | with self.assertRaises(ValueError): |
| 528 | LZMAFile(BytesIO(COMPRESSED_XZ), "rx") |
| 529 | with self.assertRaises(ValueError): |
| 530 | LZMAFile(BytesIO(COMPRESSED_XZ), "wx") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 531 | with self.assertRaises(ValueError): |
Nadeem Vawda | 6cbb20c | 2012-06-04 23:36:24 +0200 | [diff] [blame] | 532 | LZMAFile(BytesIO(COMPRESSED_XZ), "rt") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 533 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 534 | LZMAFile(BytesIO(COMPRESSED_XZ), "r+") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 535 | with self.assertRaises(ValueError): |
Nadeem Vawda | 6cbb20c | 2012-06-04 23:36:24 +0200 | [diff] [blame] | 536 | LZMAFile(BytesIO(COMPRESSED_XZ), "wt") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 537 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 538 | LZMAFile(BytesIO(COMPRESSED_XZ), "w+") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 539 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 540 | LZMAFile(BytesIO(COMPRESSED_XZ), "rw") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 541 | |
| 542 | def test_init_bad_check(self): |
| 543 | with self.assertRaises(TypeError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 544 | LZMAFile(BytesIO(), "w", check=b"asd") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 545 | # CHECK_UNKNOWN and anything above CHECK_ID_MAX should be invalid. |
| 546 | with self.assertRaises(LZMAError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 547 | LZMAFile(BytesIO(), "w", check=lzma.CHECK_UNKNOWN) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 548 | with self.assertRaises(LZMAError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 549 | LZMAFile(BytesIO(), "w", check=lzma.CHECK_ID_MAX + 3) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 550 | # Cannot specify a check with mode="r". |
| 551 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 552 | LZMAFile(BytesIO(COMPRESSED_XZ), check=lzma.CHECK_NONE) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 553 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 554 | LZMAFile(BytesIO(COMPRESSED_XZ), check=lzma.CHECK_CRC32) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 555 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 556 | LZMAFile(BytesIO(COMPRESSED_XZ), check=lzma.CHECK_CRC64) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 557 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 558 | LZMAFile(BytesIO(COMPRESSED_XZ), check=lzma.CHECK_SHA256) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 559 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 560 | LZMAFile(BytesIO(COMPRESSED_XZ), check=lzma.CHECK_UNKNOWN) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 561 | |
| 562 | def test_init_bad_preset(self): |
| 563 | with self.assertRaises(TypeError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 564 | LZMAFile(BytesIO(), "w", preset=4.39) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 565 | with self.assertRaises(LZMAError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 566 | LZMAFile(BytesIO(), "w", preset=10) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 567 | with self.assertRaises(LZMAError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 568 | LZMAFile(BytesIO(), "w", preset=23) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 569 | with self.assertRaises(OverflowError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 570 | LZMAFile(BytesIO(), "w", preset=-1) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 571 | with self.assertRaises(OverflowError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 572 | LZMAFile(BytesIO(), "w", preset=-7) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 573 | with self.assertRaises(TypeError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 574 | LZMAFile(BytesIO(), "w", preset="foo") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 575 | # Cannot specify a preset with mode="r". |
| 576 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 577 | LZMAFile(BytesIO(COMPRESSED_XZ), preset=3) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 578 | |
| 579 | def test_init_bad_filter_spec(self): |
| 580 | with self.assertRaises(TypeError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 581 | LZMAFile(BytesIO(), "w", filters=[b"wobsite"]) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 582 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 583 | LZMAFile(BytesIO(), "w", filters=[{"xyzzy": 3}]) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 584 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 585 | LZMAFile(BytesIO(), "w", filters=[{"id": 98765}]) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 586 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 587 | LZMAFile(BytesIO(), "w", |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 588 | filters=[{"id": lzma.FILTER_LZMA2, "foo": 0}]) |
| 589 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 590 | LZMAFile(BytesIO(), "w", |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 591 | filters=[{"id": lzma.FILTER_DELTA, "foo": 0}]) |
| 592 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 593 | LZMAFile(BytesIO(), "w", |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 594 | filters=[{"id": lzma.FILTER_X86, "foo": 0}]) |
| 595 | |
| 596 | def test_init_with_preset_and_filters(self): |
| 597 | with self.assertRaises(ValueError): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 598 | LZMAFile(BytesIO(), "w", format=lzma.FORMAT_RAW, |
| 599 | preset=6, filters=FILTERS_RAW_1) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 600 | |
| 601 | def test_close(self): |
| 602 | with BytesIO(COMPRESSED_XZ) as src: |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 603 | f = LZMAFile(src) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 604 | f.close() |
| 605 | # LZMAFile.close() should not close the underlying file object. |
| 606 | self.assertFalse(src.closed) |
| 607 | # Try closing an already-closed LZMAFile. |
| 608 | f.close() |
| 609 | self.assertFalse(src.closed) |
| 610 | |
| 611 | # Test with a real file on disk, opened directly by LZMAFile. |
| 612 | with TempFile(TESTFN, COMPRESSED_XZ): |
| 613 | f = LZMAFile(TESTFN) |
| 614 | fp = f._fp |
| 615 | f.close() |
| 616 | # Here, LZMAFile.close() *should* close the underlying file object. |
| 617 | self.assertTrue(fp.closed) |
| 618 | # Try closing an already-closed LZMAFile. |
| 619 | f.close() |
| 620 | |
| 621 | def test_closed(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 622 | f = LZMAFile(BytesIO(COMPRESSED_XZ)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 623 | try: |
| 624 | self.assertFalse(f.closed) |
| 625 | f.read() |
| 626 | self.assertFalse(f.closed) |
| 627 | finally: |
| 628 | f.close() |
| 629 | self.assertTrue(f.closed) |
| 630 | |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 631 | f = LZMAFile(BytesIO(), "w") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 632 | try: |
| 633 | self.assertFalse(f.closed) |
| 634 | finally: |
| 635 | f.close() |
| 636 | self.assertTrue(f.closed) |
| 637 | |
| 638 | def test_fileno(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 639 | f = LZMAFile(BytesIO(COMPRESSED_XZ)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 640 | try: |
| 641 | self.assertRaises(UnsupportedOperation, f.fileno) |
| 642 | finally: |
| 643 | f.close() |
| 644 | self.assertRaises(ValueError, f.fileno) |
| 645 | with TempFile(TESTFN, COMPRESSED_XZ): |
| 646 | f = LZMAFile(TESTFN) |
| 647 | try: |
| 648 | self.assertEqual(f.fileno(), f._fp.fileno()) |
| 649 | self.assertIsInstance(f.fileno(), int) |
| 650 | finally: |
| 651 | f.close() |
| 652 | self.assertRaises(ValueError, f.fileno) |
| 653 | |
| 654 | def test_seekable(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 655 | f = LZMAFile(BytesIO(COMPRESSED_XZ)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 656 | try: |
| 657 | self.assertTrue(f.seekable()) |
| 658 | f.read() |
| 659 | self.assertTrue(f.seekable()) |
| 660 | finally: |
| 661 | f.close() |
| 662 | self.assertRaises(ValueError, f.seekable) |
| 663 | |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 664 | f = LZMAFile(BytesIO(), "w") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 665 | try: |
| 666 | self.assertFalse(f.seekable()) |
| 667 | finally: |
| 668 | f.close() |
| 669 | self.assertRaises(ValueError, f.seekable) |
| 670 | |
Nadeem Vawda | ae557d7 | 2012-02-12 01:51:38 +0200 | [diff] [blame] | 671 | src = BytesIO(COMPRESSED_XZ) |
| 672 | src.seekable = lambda: False |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 673 | f = LZMAFile(src) |
Nadeem Vawda | ae557d7 | 2012-02-12 01:51:38 +0200 | [diff] [blame] | 674 | try: |
| 675 | self.assertFalse(f.seekable()) |
| 676 | finally: |
| 677 | f.close() |
| 678 | self.assertRaises(ValueError, f.seekable) |
| 679 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 680 | def test_readable(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 681 | f = LZMAFile(BytesIO(COMPRESSED_XZ)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 682 | try: |
| 683 | self.assertTrue(f.readable()) |
| 684 | f.read() |
| 685 | self.assertTrue(f.readable()) |
| 686 | finally: |
| 687 | f.close() |
| 688 | self.assertRaises(ValueError, f.readable) |
| 689 | |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 690 | f = LZMAFile(BytesIO(), "w") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 691 | try: |
| 692 | self.assertFalse(f.readable()) |
| 693 | finally: |
| 694 | f.close() |
| 695 | self.assertRaises(ValueError, f.readable) |
| 696 | |
| 697 | def test_writable(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 698 | f = LZMAFile(BytesIO(COMPRESSED_XZ)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 699 | try: |
| 700 | self.assertFalse(f.writable()) |
| 701 | f.read() |
| 702 | self.assertFalse(f.writable()) |
| 703 | finally: |
| 704 | f.close() |
| 705 | self.assertRaises(ValueError, f.writable) |
| 706 | |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 707 | f = LZMAFile(BytesIO(), "w") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 708 | try: |
| 709 | self.assertTrue(f.writable()) |
| 710 | finally: |
| 711 | f.close() |
| 712 | self.assertRaises(ValueError, f.writable) |
| 713 | |
| 714 | def test_read(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 715 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 716 | self.assertEqual(f.read(), INPUT) |
| 717 | self.assertEqual(f.read(), b"") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 718 | with LZMAFile(BytesIO(COMPRESSED_ALONE)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 719 | self.assertEqual(f.read(), INPUT) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 720 | with LZMAFile(BytesIO(COMPRESSED_XZ), format=lzma.FORMAT_XZ) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 721 | self.assertEqual(f.read(), INPUT) |
| 722 | self.assertEqual(f.read(), b"") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 723 | with LZMAFile(BytesIO(COMPRESSED_ALONE), format=lzma.FORMAT_ALONE) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 724 | self.assertEqual(f.read(), INPUT) |
| 725 | self.assertEqual(f.read(), b"") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 726 | with LZMAFile(BytesIO(COMPRESSED_RAW_1), |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 727 | format=lzma.FORMAT_RAW, filters=FILTERS_RAW_1) as f: |
| 728 | self.assertEqual(f.read(), INPUT) |
| 729 | self.assertEqual(f.read(), b"") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 730 | with LZMAFile(BytesIO(COMPRESSED_RAW_2), |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 731 | format=lzma.FORMAT_RAW, filters=FILTERS_RAW_2) as f: |
| 732 | self.assertEqual(f.read(), INPUT) |
| 733 | self.assertEqual(f.read(), b"") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 734 | with LZMAFile(BytesIO(COMPRESSED_RAW_3), |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 735 | format=lzma.FORMAT_RAW, filters=FILTERS_RAW_3) as f: |
| 736 | self.assertEqual(f.read(), INPUT) |
| 737 | self.assertEqual(f.read(), b"") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 738 | with LZMAFile(BytesIO(COMPRESSED_RAW_4), |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 739 | format=lzma.FORMAT_RAW, filters=FILTERS_RAW_4) as f: |
| 740 | self.assertEqual(f.read(), INPUT) |
| 741 | self.assertEqual(f.read(), b"") |
| 742 | |
| 743 | def test_read_0(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 744 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 745 | self.assertEqual(f.read(0), b"") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 746 | with LZMAFile(BytesIO(COMPRESSED_ALONE)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 747 | self.assertEqual(f.read(0), b"") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 748 | with LZMAFile(BytesIO(COMPRESSED_XZ), format=lzma.FORMAT_XZ) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 749 | self.assertEqual(f.read(0), b"") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 750 | with LZMAFile(BytesIO(COMPRESSED_ALONE), format=lzma.FORMAT_ALONE) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 751 | self.assertEqual(f.read(0), b"") |
| 752 | |
| 753 | def test_read_10(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 754 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 755 | chunks = [] |
| 756 | while True: |
| 757 | result = f.read(10) |
| 758 | if not result: |
| 759 | break |
| 760 | self.assertLessEqual(len(result), 10) |
| 761 | chunks.append(result) |
| 762 | self.assertEqual(b"".join(chunks), INPUT) |
| 763 | |
| 764 | def test_read_multistream(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 765 | with LZMAFile(BytesIO(COMPRESSED_XZ * 5)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 766 | self.assertEqual(f.read(), INPUT * 5) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 767 | with LZMAFile(BytesIO(COMPRESSED_XZ + COMPRESSED_ALONE)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 768 | self.assertEqual(f.read(), INPUT * 2) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 769 | with LZMAFile(BytesIO(COMPRESSED_RAW_3 * 4), |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 770 | format=lzma.FORMAT_RAW, filters=FILTERS_RAW_3) as f: |
| 771 | self.assertEqual(f.read(), INPUT * 4) |
| 772 | |
| 773 | def test_read_multistream_buffer_size_aligned(self): |
| 774 | # Test the case where a stream boundary coincides with the end |
| 775 | # of the raw read buffer. |
Antoine Pitrou | 2dbc6e6 | 2015-04-11 00:31:01 +0200 | [diff] [blame] | 776 | saved_buffer_size = _compression.BUFFER_SIZE |
| 777 | _compression.BUFFER_SIZE = len(COMPRESSED_XZ) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 778 | try: |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 779 | with LZMAFile(BytesIO(COMPRESSED_XZ * 5)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 780 | self.assertEqual(f.read(), INPUT * 5) |
| 781 | finally: |
Antoine Pitrou | 2dbc6e6 | 2015-04-11 00:31:01 +0200 | [diff] [blame] | 782 | _compression.BUFFER_SIZE = saved_buffer_size |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 783 | |
Nadeem Vawda | 9c72ebc | 2013-12-04 23:03:49 +0100 | [diff] [blame] | 784 | def test_read_trailing_junk(self): |
| 785 | with LZMAFile(BytesIO(COMPRESSED_XZ + COMPRESSED_BOGUS)) as f: |
| 786 | self.assertEqual(f.read(), INPUT) |
| 787 | |
| 788 | def test_read_multistream_trailing_junk(self): |
| 789 | with LZMAFile(BytesIO(COMPRESSED_XZ * 5 + COMPRESSED_BOGUS)) as f: |
| 790 | self.assertEqual(f.read(), INPUT * 5) |
| 791 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 792 | def test_read_from_file(self): |
| 793 | with TempFile(TESTFN, COMPRESSED_XZ): |
| 794 | with LZMAFile(TESTFN) as f: |
| 795 | self.assertEqual(f.read(), INPUT) |
| 796 | self.assertEqual(f.read(), b"") |
| 797 | |
Nadeem Vawda | 10c8791 | 2012-06-20 01:48:50 +0200 | [diff] [blame] | 798 | def test_read_from_file_with_bytes_filename(self): |
| 799 | try: |
| 800 | bytes_filename = TESTFN.encode("ascii") |
| 801 | except UnicodeEncodeError: |
| 802 | self.skipTest("Temporary file name needs to be ASCII") |
| 803 | with TempFile(TESTFN, COMPRESSED_XZ): |
| 804 | with LZMAFile(bytes_filename) as f: |
| 805 | self.assertEqual(f.read(), INPUT) |
| 806 | self.assertEqual(f.read(), b"") |
| 807 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 808 | def test_read_incomplete(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 809 | with LZMAFile(BytesIO(COMPRESSED_XZ[:128])) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 810 | self.assertRaises(EOFError, f.read) |
| 811 | |
Serhiy Storchaka | 57f9b7a | 2013-01-22 17:07:49 +0200 | [diff] [blame] | 812 | def test_read_truncated(self): |
| 813 | # Drop stream footer: CRC (4 bytes), index size (4 bytes), |
Serhiy Storchaka | 70ea7fa | 2013-02-08 11:24:16 +0200 | [diff] [blame] | 814 | # flags (2 bytes) and magic number (2 bytes). |
Serhiy Storchaka | 57f9b7a | 2013-01-22 17:07:49 +0200 | [diff] [blame] | 815 | truncated = COMPRESSED_XZ[:-12] |
| 816 | with LZMAFile(BytesIO(truncated)) as f: |
| 817 | self.assertRaises(EOFError, f.read) |
| 818 | with LZMAFile(BytesIO(truncated)) as f: |
| 819 | self.assertEqual(f.read(len(INPUT)), INPUT) |
| 820 | self.assertRaises(EOFError, f.read, 1) |
| 821 | # Incomplete 12-byte header. |
| 822 | for i in range(12): |
| 823 | with LZMAFile(BytesIO(truncated[:i])) as f: |
| 824 | self.assertRaises(EOFError, f.read, 1) |
| 825 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 826 | def test_read_bad_args(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 827 | f = LZMAFile(BytesIO(COMPRESSED_XZ)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 828 | f.close() |
| 829 | self.assertRaises(ValueError, f.read) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 830 | with LZMAFile(BytesIO(), "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 831 | self.assertRaises(ValueError, f.read) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 832 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Antoine Pitrou | 2dbc6e6 | 2015-04-11 00:31:01 +0200 | [diff] [blame] | 833 | self.assertRaises(TypeError, f.read, float()) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 834 | |
Nadeem Vawda | 9c72ebc | 2013-12-04 23:03:49 +0100 | [diff] [blame] | 835 | def test_read_bad_data(self): |
| 836 | with LZMAFile(BytesIO(COMPRESSED_BOGUS)) as f: |
| 837 | self.assertRaises(LZMAError, f.read) |
| 838 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 839 | def test_read1(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 840 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 841 | blocks = [] |
| 842 | while True: |
| 843 | result = f.read1() |
| 844 | if not result: |
| 845 | break |
| 846 | blocks.append(result) |
| 847 | self.assertEqual(b"".join(blocks), INPUT) |
| 848 | self.assertEqual(f.read1(), b"") |
| 849 | |
| 850 | def test_read1_0(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 851 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 852 | self.assertEqual(f.read1(0), b"") |
| 853 | |
| 854 | def test_read1_10(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 855 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 856 | blocks = [] |
| 857 | while True: |
| 858 | result = f.read1(10) |
| 859 | if not result: |
| 860 | break |
| 861 | blocks.append(result) |
| 862 | self.assertEqual(b"".join(blocks), INPUT) |
| 863 | self.assertEqual(f.read1(), b"") |
| 864 | |
| 865 | def test_read1_multistream(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 866 | with LZMAFile(BytesIO(COMPRESSED_XZ * 5)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 867 | blocks = [] |
| 868 | while True: |
| 869 | result = f.read1() |
| 870 | if not result: |
| 871 | break |
| 872 | blocks.append(result) |
| 873 | self.assertEqual(b"".join(blocks), INPUT * 5) |
| 874 | self.assertEqual(f.read1(), b"") |
| 875 | |
| 876 | def test_read1_bad_args(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 877 | f = LZMAFile(BytesIO(COMPRESSED_XZ)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 878 | f.close() |
| 879 | self.assertRaises(ValueError, f.read1) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 880 | with LZMAFile(BytesIO(), "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 881 | self.assertRaises(ValueError, f.read1) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 882 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 883 | self.assertRaises(TypeError, f.read1, None) |
| 884 | |
| 885 | def test_peek(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 886 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 887 | result = f.peek() |
| 888 | self.assertGreater(len(result), 0) |
| 889 | self.assertTrue(INPUT.startswith(result)) |
| 890 | self.assertEqual(f.read(), INPUT) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 891 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 892 | result = f.peek(10) |
| 893 | self.assertGreater(len(result), 0) |
| 894 | self.assertTrue(INPUT.startswith(result)) |
| 895 | self.assertEqual(f.read(), INPUT) |
| 896 | |
| 897 | def test_peek_bad_args(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 898 | with LZMAFile(BytesIO(), "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 899 | self.assertRaises(ValueError, f.peek) |
| 900 | |
| 901 | def test_iterator(self): |
| 902 | with BytesIO(INPUT) as f: |
| 903 | lines = f.readlines() |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 904 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 905 | self.assertListEqual(list(iter(f)), lines) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 906 | with LZMAFile(BytesIO(COMPRESSED_ALONE)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 907 | self.assertListEqual(list(iter(f)), lines) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 908 | with LZMAFile(BytesIO(COMPRESSED_XZ), format=lzma.FORMAT_XZ) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 909 | self.assertListEqual(list(iter(f)), lines) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 910 | with LZMAFile(BytesIO(COMPRESSED_ALONE), format=lzma.FORMAT_ALONE) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 911 | self.assertListEqual(list(iter(f)), lines) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 912 | with LZMAFile(BytesIO(COMPRESSED_RAW_2), |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 913 | format=lzma.FORMAT_RAW, filters=FILTERS_RAW_2) as f: |
| 914 | self.assertListEqual(list(iter(f)), lines) |
| 915 | |
| 916 | def test_readline(self): |
| 917 | with BytesIO(INPUT) as f: |
| 918 | lines = f.readlines() |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 919 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 920 | for line in lines: |
| 921 | self.assertEqual(f.readline(), line) |
| 922 | |
| 923 | def test_readlines(self): |
| 924 | with BytesIO(INPUT) as f: |
| 925 | lines = f.readlines() |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 926 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 927 | self.assertListEqual(f.readlines(), lines) |
| 928 | |
Antoine Pitrou | 2dbc6e6 | 2015-04-11 00:31:01 +0200 | [diff] [blame] | 929 | def test_decompress_limited(self): |
| 930 | """Decompressed data buffering should be limited""" |
| 931 | bomb = lzma.compress(bytes(int(2e6)), preset=6) |
| 932 | self.assertLess(len(bomb), _compression.BUFFER_SIZE) |
| 933 | |
| 934 | decomp = LZMAFile(BytesIO(bomb)) |
| 935 | self.assertEqual(bytes(1), decomp.read(1)) |
| 936 | max_decomp = 1 + DEFAULT_BUFFER_SIZE |
| 937 | self.assertLessEqual(decomp._buffer.raw.tell(), max_decomp, |
| 938 | "Excessive amount of data was decompressed") |
| 939 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 940 | def test_write(self): |
| 941 | with BytesIO() as dst: |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 942 | with LZMAFile(dst, "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 943 | f.write(INPUT) |
| 944 | expected = lzma.compress(INPUT) |
| 945 | self.assertEqual(dst.getvalue(), expected) |
| 946 | with BytesIO() as dst: |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 947 | with LZMAFile(dst, "w", format=lzma.FORMAT_XZ) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 948 | f.write(INPUT) |
| 949 | expected = lzma.compress(INPUT, format=lzma.FORMAT_XZ) |
| 950 | self.assertEqual(dst.getvalue(), expected) |
| 951 | with BytesIO() as dst: |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 952 | with LZMAFile(dst, "w", format=lzma.FORMAT_ALONE) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 953 | f.write(INPUT) |
| 954 | expected = lzma.compress(INPUT, format=lzma.FORMAT_ALONE) |
| 955 | self.assertEqual(dst.getvalue(), expected) |
| 956 | with BytesIO() as dst: |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 957 | with LZMAFile(dst, "w", format=lzma.FORMAT_RAW, |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 958 | filters=FILTERS_RAW_2) as f: |
| 959 | f.write(INPUT) |
| 960 | expected = lzma.compress(INPUT, format=lzma.FORMAT_RAW, |
| 961 | filters=FILTERS_RAW_2) |
| 962 | self.assertEqual(dst.getvalue(), expected) |
| 963 | |
| 964 | def test_write_10(self): |
| 965 | with BytesIO() as dst: |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 966 | with LZMAFile(dst, "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 967 | for start in range(0, len(INPUT), 10): |
| 968 | f.write(INPUT[start:start+10]) |
| 969 | expected = lzma.compress(INPUT) |
| 970 | self.assertEqual(dst.getvalue(), expected) |
| 971 | |
| 972 | def test_write_append(self): |
| 973 | part1 = INPUT[:1024] |
| 974 | part2 = INPUT[1024:1536] |
| 975 | part3 = INPUT[1536:] |
| 976 | expected = b"".join(lzma.compress(x) for x in (part1, part2, part3)) |
| 977 | with BytesIO() as dst: |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 978 | with LZMAFile(dst, "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 979 | f.write(part1) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 980 | with LZMAFile(dst, "a") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 981 | f.write(part2) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 982 | with LZMAFile(dst, "a") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 983 | f.write(part3) |
| 984 | self.assertEqual(dst.getvalue(), expected) |
| 985 | |
| 986 | def test_write_to_file(self): |
| 987 | try: |
| 988 | with LZMAFile(TESTFN, "w") as f: |
| 989 | f.write(INPUT) |
| 990 | expected = lzma.compress(INPUT) |
| 991 | with open(TESTFN, "rb") as f: |
| 992 | self.assertEqual(f.read(), expected) |
| 993 | finally: |
| 994 | unlink(TESTFN) |
| 995 | |
Nadeem Vawda | 10c8791 | 2012-06-20 01:48:50 +0200 | [diff] [blame] | 996 | def test_write_to_file_with_bytes_filename(self): |
| 997 | try: |
| 998 | bytes_filename = TESTFN.encode("ascii") |
| 999 | except UnicodeEncodeError: |
| 1000 | self.skipTest("Temporary file name needs to be ASCII") |
| 1001 | try: |
| 1002 | with LZMAFile(bytes_filename, "w") as f: |
| 1003 | f.write(INPUT) |
| 1004 | expected = lzma.compress(INPUT) |
| 1005 | with open(TESTFN, "rb") as f: |
| 1006 | self.assertEqual(f.read(), expected) |
| 1007 | finally: |
| 1008 | unlink(TESTFN) |
| 1009 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1010 | def test_write_append_to_file(self): |
| 1011 | part1 = INPUT[:1024] |
| 1012 | part2 = INPUT[1024:1536] |
| 1013 | part3 = INPUT[1536:] |
| 1014 | expected = b"".join(lzma.compress(x) for x in (part1, part2, part3)) |
| 1015 | try: |
| 1016 | with LZMAFile(TESTFN, "w") as f: |
| 1017 | f.write(part1) |
| 1018 | with LZMAFile(TESTFN, "a") as f: |
| 1019 | f.write(part2) |
| 1020 | with LZMAFile(TESTFN, "a") as f: |
| 1021 | f.write(part3) |
| 1022 | with open(TESTFN, "rb") as f: |
| 1023 | self.assertEqual(f.read(), expected) |
| 1024 | finally: |
| 1025 | unlink(TESTFN) |
| 1026 | |
| 1027 | def test_write_bad_args(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1028 | f = LZMAFile(BytesIO(), "w") |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1029 | f.close() |
| 1030 | self.assertRaises(ValueError, f.write, b"foo") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1031 | with LZMAFile(BytesIO(COMPRESSED_XZ), "r") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1032 | self.assertRaises(ValueError, f.write, b"bar") |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1033 | with LZMAFile(BytesIO(), "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1034 | self.assertRaises(TypeError, f.write, None) |
| 1035 | self.assertRaises(TypeError, f.write, "text") |
| 1036 | self.assertRaises(TypeError, f.write, 789) |
| 1037 | |
| 1038 | def test_writelines(self): |
| 1039 | with BytesIO(INPUT) as f: |
| 1040 | lines = f.readlines() |
| 1041 | with BytesIO() as dst: |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1042 | with LZMAFile(dst, "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1043 | f.writelines(lines) |
| 1044 | expected = lzma.compress(INPUT) |
| 1045 | self.assertEqual(dst.getvalue(), expected) |
| 1046 | |
| 1047 | def test_seek_forward(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1048 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1049 | f.seek(555) |
| 1050 | self.assertEqual(f.read(), INPUT[555:]) |
| 1051 | |
| 1052 | def test_seek_forward_across_streams(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1053 | with LZMAFile(BytesIO(COMPRESSED_XZ * 2)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1054 | f.seek(len(INPUT) + 123) |
| 1055 | self.assertEqual(f.read(), INPUT[123:]) |
| 1056 | |
| 1057 | def test_seek_forward_relative_to_current(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1058 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1059 | f.read(100) |
| 1060 | f.seek(1236, 1) |
| 1061 | self.assertEqual(f.read(), INPUT[1336:]) |
| 1062 | |
| 1063 | def test_seek_forward_relative_to_end(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1064 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1065 | f.seek(-555, 2) |
| 1066 | self.assertEqual(f.read(), INPUT[-555:]) |
| 1067 | |
| 1068 | def test_seek_backward(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1069 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1070 | f.read(1001) |
| 1071 | f.seek(211) |
| 1072 | self.assertEqual(f.read(), INPUT[211:]) |
| 1073 | |
| 1074 | def test_seek_backward_across_streams(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1075 | with LZMAFile(BytesIO(COMPRESSED_XZ * 2)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1076 | f.read(len(INPUT) + 333) |
| 1077 | f.seek(737) |
| 1078 | self.assertEqual(f.read(), INPUT[737:] + INPUT) |
| 1079 | |
| 1080 | def test_seek_backward_relative_to_end(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1081 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1082 | f.seek(-150, 2) |
| 1083 | self.assertEqual(f.read(), INPUT[-150:]) |
| 1084 | |
| 1085 | def test_seek_past_end(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1086 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1087 | f.seek(len(INPUT) + 9001) |
| 1088 | self.assertEqual(f.tell(), len(INPUT)) |
| 1089 | self.assertEqual(f.read(), b"") |
| 1090 | |
| 1091 | def test_seek_past_start(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1092 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1093 | f.seek(-88) |
| 1094 | self.assertEqual(f.tell(), 0) |
| 1095 | self.assertEqual(f.read(), INPUT) |
| 1096 | |
| 1097 | def test_seek_bad_args(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1098 | f = LZMAFile(BytesIO(COMPRESSED_XZ)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1099 | f.close() |
| 1100 | self.assertRaises(ValueError, f.seek, 0) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1101 | with LZMAFile(BytesIO(), "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1102 | self.assertRaises(ValueError, f.seek, 0) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1103 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1104 | self.assertRaises(ValueError, f.seek, 0, 3) |
Antoine Pitrou | 2dbc6e6 | 2015-04-11 00:31:01 +0200 | [diff] [blame] | 1105 | # io.BufferedReader raises TypeError instead of ValueError |
| 1106 | self.assertRaises((TypeError, ValueError), f.seek, 9, ()) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1107 | self.assertRaises(TypeError, f.seek, None) |
| 1108 | self.assertRaises(TypeError, f.seek, b"derp") |
| 1109 | |
| 1110 | def test_tell(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1111 | with LZMAFile(BytesIO(COMPRESSED_XZ)) as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1112 | pos = 0 |
| 1113 | while True: |
| 1114 | self.assertEqual(f.tell(), pos) |
| 1115 | result = f.read(183) |
| 1116 | if not result: |
| 1117 | break |
| 1118 | pos += len(result) |
| 1119 | self.assertEqual(f.tell(), len(INPUT)) |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1120 | with LZMAFile(BytesIO(), "w") as f: |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1121 | for pos in range(0, len(INPUT), 144): |
| 1122 | self.assertEqual(f.tell(), pos) |
| 1123 | f.write(INPUT[pos:pos+144]) |
| 1124 | self.assertEqual(f.tell(), len(INPUT)) |
| 1125 | |
| 1126 | def test_tell_bad_args(self): |
Nadeem Vawda | 33c34da | 2012-06-04 23:34:07 +0200 | [diff] [blame] | 1127 | f = LZMAFile(BytesIO(COMPRESSED_XZ)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1128 | f.close() |
| 1129 | self.assertRaises(ValueError, f.tell) |
| 1130 | |
| 1131 | |
Nadeem Vawda | e860404 | 2012-06-04 23:38:12 +0200 | [diff] [blame] | 1132 | class OpenTestCase(unittest.TestCase): |
| 1133 | |
| 1134 | def test_binary_modes(self): |
| 1135 | with lzma.open(BytesIO(COMPRESSED_XZ), "rb") as f: |
| 1136 | self.assertEqual(f.read(), INPUT) |
| 1137 | with BytesIO() as bio: |
| 1138 | with lzma.open(bio, "wb") as f: |
| 1139 | f.write(INPUT) |
| 1140 | file_data = lzma.decompress(bio.getvalue()) |
| 1141 | self.assertEqual(file_data, INPUT) |
| 1142 | with lzma.open(bio, "ab") as f: |
| 1143 | f.write(INPUT) |
| 1144 | file_data = lzma.decompress(bio.getvalue()) |
| 1145 | self.assertEqual(file_data, INPUT * 2) |
| 1146 | |
| 1147 | def test_text_modes(self): |
| 1148 | uncompressed = INPUT.decode("ascii") |
| 1149 | uncompressed_raw = uncompressed.replace("\n", os.linesep) |
| 1150 | with lzma.open(BytesIO(COMPRESSED_XZ), "rt") as f: |
| 1151 | self.assertEqual(f.read(), uncompressed) |
| 1152 | with BytesIO() as bio: |
| 1153 | with lzma.open(bio, "wt") as f: |
| 1154 | f.write(uncompressed) |
| 1155 | file_data = lzma.decompress(bio.getvalue()).decode("ascii") |
| 1156 | self.assertEqual(file_data, uncompressed_raw) |
| 1157 | with lzma.open(bio, "at") as f: |
| 1158 | f.write(uncompressed) |
| 1159 | file_data = lzma.decompress(bio.getvalue()).decode("ascii") |
| 1160 | self.assertEqual(file_data, uncompressed_raw * 2) |
| 1161 | |
| 1162 | def test_filename(self): |
| 1163 | with TempFile(TESTFN): |
| 1164 | with lzma.open(TESTFN, "wb") as f: |
| 1165 | f.write(INPUT) |
| 1166 | with open(TESTFN, "rb") as f: |
| 1167 | file_data = lzma.decompress(f.read()) |
| 1168 | self.assertEqual(file_data, INPUT) |
| 1169 | with lzma.open(TESTFN, "rb") as f: |
| 1170 | self.assertEqual(f.read(), INPUT) |
| 1171 | with lzma.open(TESTFN, "ab") as f: |
| 1172 | f.write(INPUT) |
| 1173 | with lzma.open(TESTFN, "rb") as f: |
| 1174 | self.assertEqual(f.read(), INPUT * 2) |
| 1175 | |
| 1176 | def test_bad_params(self): |
| 1177 | # Test invalid parameter combinations. |
| 1178 | with self.assertRaises(ValueError): |
| 1179 | lzma.open(TESTFN, "") |
| 1180 | with self.assertRaises(ValueError): |
Nadeem Vawda | e860404 | 2012-06-04 23:38:12 +0200 | [diff] [blame] | 1181 | lzma.open(TESTFN, "rbt") |
| 1182 | with self.assertRaises(ValueError): |
| 1183 | lzma.open(TESTFN, "rb", encoding="utf-8") |
| 1184 | with self.assertRaises(ValueError): |
| 1185 | lzma.open(TESTFN, "rb", errors="ignore") |
| 1186 | with self.assertRaises(ValueError): |
| 1187 | lzma.open(TESTFN, "rb", newline="\n") |
| 1188 | |
| 1189 | def test_format_and_filters(self): |
| 1190 | # Test non-default format and filter chain. |
| 1191 | options = {"format": lzma.FORMAT_RAW, "filters": FILTERS_RAW_1} |
| 1192 | with lzma.open(BytesIO(COMPRESSED_RAW_1), "rb", **options) as f: |
| 1193 | self.assertEqual(f.read(), INPUT) |
| 1194 | with BytesIO() as bio: |
| 1195 | with lzma.open(bio, "wb", **options) as f: |
| 1196 | f.write(INPUT) |
| 1197 | file_data = lzma.decompress(bio.getvalue(), **options) |
| 1198 | self.assertEqual(file_data, INPUT) |
| 1199 | |
| 1200 | def test_encoding(self): |
| 1201 | # Test non-default encoding. |
| 1202 | uncompressed = INPUT.decode("ascii") |
| 1203 | uncompressed_raw = uncompressed.replace("\n", os.linesep) |
| 1204 | with BytesIO() as bio: |
| 1205 | with lzma.open(bio, "wt", encoding="utf-16-le") as f: |
| 1206 | f.write(uncompressed) |
| 1207 | file_data = lzma.decompress(bio.getvalue()).decode("utf-16-le") |
| 1208 | self.assertEqual(file_data, uncompressed_raw) |
| 1209 | bio.seek(0) |
| 1210 | with lzma.open(bio, "rt", encoding="utf-16-le") as f: |
| 1211 | self.assertEqual(f.read(), uncompressed) |
| 1212 | |
| 1213 | def test_encoding_error_handler(self): |
Martin Panter | 46f5072 | 2016-05-26 05:35:26 +0000 | [diff] [blame] | 1214 | # Test with non-default encoding error handler. |
Nadeem Vawda | e860404 | 2012-06-04 23:38:12 +0200 | [diff] [blame] | 1215 | with BytesIO(lzma.compress(b"foo\xffbar")) as bio: |
| 1216 | with lzma.open(bio, "rt", encoding="ascii", errors="ignore") as f: |
| 1217 | self.assertEqual(f.read(), "foobar") |
| 1218 | |
| 1219 | def test_newline(self): |
| 1220 | # Test with explicit newline (universal newline mode disabled). |
| 1221 | text = INPUT.decode("ascii") |
| 1222 | with BytesIO() as bio: |
| 1223 | with lzma.open(bio, "wt", newline="\n") as f: |
| 1224 | f.write(text) |
| 1225 | bio.seek(0) |
| 1226 | with lzma.open(bio, "rt", newline="\r") as f: |
| 1227 | self.assertEqual(f.readlines(), [text]) |
| 1228 | |
Nadeem Vawda | 42ca982 | 2013-10-19 00:06:19 +0200 | [diff] [blame] | 1229 | def test_x_mode(self): |
| 1230 | self.addCleanup(unlink, TESTFN) |
| 1231 | for mode in ("x", "xb", "xt"): |
| 1232 | unlink(TESTFN) |
| 1233 | with lzma.open(TESTFN, mode): |
| 1234 | pass |
| 1235 | with self.assertRaises(FileExistsError): |
| 1236 | with lzma.open(TESTFN, mode): |
| 1237 | pass |
| 1238 | |
Nadeem Vawda | e860404 | 2012-06-04 23:38:12 +0200 | [diff] [blame] | 1239 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1240 | class MiscellaneousTestCase(unittest.TestCase): |
| 1241 | |
| 1242 | def test_is_check_supported(self): |
| 1243 | # CHECK_NONE and CHECK_CRC32 should always be supported, |
| 1244 | # regardless of the options liblzma was compiled with. |
Nadeem Vawda | bc459bb | 2012-05-06 23:01:51 +0200 | [diff] [blame] | 1245 | self.assertTrue(lzma.is_check_supported(lzma.CHECK_NONE)) |
| 1246 | self.assertTrue(lzma.is_check_supported(lzma.CHECK_CRC32)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1247 | |
| 1248 | # The .xz format spec cannot store check IDs above this value. |
Nadeem Vawda | bc459bb | 2012-05-06 23:01:51 +0200 | [diff] [blame] | 1249 | self.assertFalse(lzma.is_check_supported(lzma.CHECK_ID_MAX + 1)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1250 | |
| 1251 | # This value should not be a valid check ID. |
Nadeem Vawda | bc459bb | 2012-05-06 23:01:51 +0200 | [diff] [blame] | 1252 | self.assertFalse(lzma.is_check_supported(lzma.CHECK_UNKNOWN)) |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1253 | |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1254 | def test__encode_filter_properties(self): |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1255 | with self.assertRaises(TypeError): |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1256 | lzma._encode_filter_properties(b"not a dict") |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1257 | with self.assertRaises(ValueError): |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1258 | lzma._encode_filter_properties({"id": 0x100}) |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1259 | with self.assertRaises(ValueError): |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1260 | lzma._encode_filter_properties({"id": lzma.FILTER_LZMA2, "junk": 12}) |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1261 | with self.assertRaises(lzma.LZMAError): |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1262 | lzma._encode_filter_properties({"id": lzma.FILTER_DELTA, |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1263 | "dist": 9001}) |
| 1264 | |
| 1265 | # Test with parameters used by zipfile module. |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1266 | props = lzma._encode_filter_properties({ |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1267 | "id": lzma.FILTER_LZMA1, |
| 1268 | "pb": 2, |
| 1269 | "lp": 0, |
| 1270 | "lc": 3, |
| 1271 | "dict_size": 8 << 20, |
| 1272 | }) |
| 1273 | self.assertEqual(props, b"]\x00\x00\x80\x00") |
| 1274 | |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1275 | def test__decode_filter_properties(self): |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1276 | with self.assertRaises(TypeError): |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1277 | lzma._decode_filter_properties(lzma.FILTER_X86, {"should be": bytes}) |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1278 | with self.assertRaises(lzma.LZMAError): |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1279 | lzma._decode_filter_properties(lzma.FILTER_DELTA, b"too long") |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1280 | |
| 1281 | # Test with parameters used by zipfile module. |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1282 | filterspec = lzma._decode_filter_properties( |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1283 | lzma.FILTER_LZMA1, b"]\x00\x00\x80\x00") |
| 1284 | self.assertEqual(filterspec["id"], lzma.FILTER_LZMA1) |
| 1285 | self.assertEqual(filterspec["pb"], 2) |
| 1286 | self.assertEqual(filterspec["lp"], 0) |
| 1287 | self.assertEqual(filterspec["lc"], 3) |
| 1288 | self.assertEqual(filterspec["dict_size"], 8 << 20) |
| 1289 | |
| 1290 | def test_filter_properties_roundtrip(self): |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1291 | spec1 = lzma._decode_filter_properties( |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1292 | lzma.FILTER_LZMA1, b"]\x00\x00\x80\x00") |
Nadeem Vawda | a425c3d | 2012-06-21 23:36:48 +0200 | [diff] [blame] | 1293 | reencoded = lzma._encode_filter_properties(spec1) |
| 1294 | spec2 = lzma._decode_filter_properties(lzma.FILTER_LZMA1, reencoded) |
Nadeem Vawda | f55b329 | 2012-05-06 23:01:27 +0200 | [diff] [blame] | 1295 | self.assertEqual(spec1, spec2) |
| 1296 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1297 | |
| 1298 | # Test data: |
| 1299 | |
| 1300 | INPUT = b""" |
| 1301 | LAERTES |
| 1302 | |
| 1303 | O, fear me not. |
| 1304 | I stay too long: but here my father comes. |
| 1305 | |
| 1306 | Enter POLONIUS |
| 1307 | |
| 1308 | A double blessing is a double grace, |
| 1309 | Occasion smiles upon a second leave. |
| 1310 | |
| 1311 | LORD POLONIUS |
| 1312 | |
| 1313 | Yet here, Laertes! aboard, aboard, for shame! |
| 1314 | The wind sits in the shoulder of your sail, |
| 1315 | And you are stay'd for. There; my blessing with thee! |
| 1316 | And these few precepts in thy memory |
| 1317 | See thou character. Give thy thoughts no tongue, |
| 1318 | Nor any unproportioned thought his act. |
| 1319 | Be thou familiar, but by no means vulgar. |
| 1320 | Those friends thou hast, and their adoption tried, |
| 1321 | Grapple them to thy soul with hoops of steel; |
| 1322 | But do not dull thy palm with entertainment |
| 1323 | Of each new-hatch'd, unfledged comrade. Beware |
| 1324 | Of entrance to a quarrel, but being in, |
| 1325 | Bear't that the opposed may beware of thee. |
| 1326 | Give every man thy ear, but few thy voice; |
| 1327 | Take each man's censure, but reserve thy judgment. |
| 1328 | Costly thy habit as thy purse can buy, |
| 1329 | But not express'd in fancy; rich, not gaudy; |
| 1330 | For the apparel oft proclaims the man, |
| 1331 | And they in France of the best rank and station |
| 1332 | Are of a most select and generous chief in that. |
| 1333 | Neither a borrower nor a lender be; |
| 1334 | For loan oft loses both itself and friend, |
| 1335 | And borrowing dulls the edge of husbandry. |
| 1336 | This above all: to thine ownself be true, |
| 1337 | And it must follow, as the night the day, |
| 1338 | Thou canst not then be false to any man. |
| 1339 | Farewell: my blessing season this in thee! |
| 1340 | |
| 1341 | LAERTES |
| 1342 | |
| 1343 | Most humbly do I take my leave, my lord. |
| 1344 | |
| 1345 | LORD POLONIUS |
| 1346 | |
| 1347 | The time invites you; go; your servants tend. |
| 1348 | |
| 1349 | LAERTES |
| 1350 | |
| 1351 | Farewell, Ophelia; and remember well |
| 1352 | What I have said to you. |
| 1353 | |
| 1354 | OPHELIA |
| 1355 | |
| 1356 | 'Tis in my memory lock'd, |
| 1357 | And you yourself shall keep the key of it. |
| 1358 | |
| 1359 | LAERTES |
| 1360 | |
| 1361 | Farewell. |
| 1362 | """ |
| 1363 | |
Nadeem Vawda | 9c72ebc | 2013-12-04 23:03:49 +0100 | [diff] [blame] | 1364 | COMPRESSED_BOGUS = b"this is not a valid lzma stream" |
| 1365 | |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1366 | COMPRESSED_XZ = ( |
| 1367 | b"\xfd7zXZ\x00\x00\x04\xe6\xd6\xb4F\x02\x00!\x01\x16\x00\x00\x00t/\xe5\xa3" |
| 1368 | b"\xe0\x07\x80\x03\xdf]\x00\x05\x14\x07bX\x19\xcd\xddn\x98\x15\xe4\xb4\x9d" |
| 1369 | b"o\x1d\xc4\xe5\n\x03\xcc2h\xc7\\\x86\xff\xf8\xe2\xfc\xe7\xd9\xfe6\xb8(" |
| 1370 | b"\xa8wd\xc2\"u.n\x1e\xc3\xf2\x8e\x8d\x8f\x02\x17/\xa6=\xf0\xa2\xdf/M\x89" |
| 1371 | b"\xbe\xde\xa7\x1cz\x18-]\xd5\xef\x13\x8frZ\x15\x80\x8c\xf8\x8do\xfa\x12" |
| 1372 | b"\x9b#z/\xef\xf0\xfaF\x01\x82\xa3M\x8e\xa1t\xca6 BF$\xe5Q\xa4\x98\xee\xde" |
| 1373 | b"l\xe8\x7f\xf0\x9d,bn\x0b\x13\xd4\xa8\x81\xe4N\xc8\x86\x153\xf5x2\xa2O" |
| 1374 | b"\x13@Q\xa1\x00/\xa5\xd0O\x97\xdco\xae\xf7z\xc4\xcdS\xb6t<\x16\xf2\x9cI#" |
| 1375 | b"\x89ud\xc66Y\xd9\xee\xe6\xce\x12]\xe5\xf0\xaa\x96-Pe\xade:\x04\t\x1b\xf7" |
| 1376 | b"\xdb7\n\x86\x1fp\xc8J\xba\xf4\xf0V\xa9\xdc\xf0\x02%G\xf9\xdf=?\x15\x1b" |
| 1377 | b"\xe1(\xce\x82=\xd6I\xac3\x12\x0cR\xb7\xae\r\xb1i\x03\x95\x01\xbd\xbe\xfa" |
| 1378 | b"\x02s\x01P\x9d\x96X\xb12j\xc8L\xa8\x84b\xf6\xc3\xd4c-H\x93oJl\xd0iQ\xe4k" |
| 1379 | b"\x84\x0b\xc1\xb7\xbc\xb1\x17\x88\xb1\xca?@\xf6\x07\xea\xe6x\xf1H12P\x0f" |
| 1380 | b"\x8a\xc9\xeauw\xe3\xbe\xaai\xa9W\xd0\x80\xcd#cb5\x99\xd8]\xa9d\x0c\xbd" |
| 1381 | b"\xa2\xdcWl\xedUG\xbf\x89yF\xf77\x81v\xbd5\x98\xbeh8\x18W\x08\xf0\x1b\x99" |
| 1382 | b"5:\x1a?rD\x96\xa1\x04\x0f\xae\xba\x85\xeb\x9d5@\xf5\x83\xd37\x83\x8ac" |
| 1383 | b"\x06\xd4\x97i\xcdt\x16S\x82k\xf6K\x01vy\x88\x91\x9b6T\xdae\r\xfd]:k\xbal" |
| 1384 | b"\xa9\xbba\xc34\xf9r\xeb}r\xdb\xc7\xdb*\x8f\x03z\xdc8h\xcc\xc9\xd3\xbcl" |
| 1385 | b"\xa5-\xcb\xeaK\xa2\xc5\x15\xc0\xe3\xc1\x86Z\xfb\xebL\xe13\xcf\x9c\xe3" |
| 1386 | b"\x1d\xc9\xed\xc2\x06\xcc\xce!\x92\xe5\xfe\x9c^\xa59w \x9bP\xa3PK\x08d" |
| 1387 | b"\xf9\xe2Z}\xa7\xbf\xed\xeb%$\x0c\x82\xb8/\xb0\x01\xa9&,\xf7qh{Q\x96)\xf2" |
| 1388 | b"q\x96\xc3\x80\xb4\x12\xb0\xba\xe6o\xf4!\xb4[\xd4\x8aw\x10\xf7t\x0c\xb3" |
| 1389 | b"\xd9\xd5\xc3`^\x81\x11??\\\xa4\x99\x85R\xd4\x8e\x83\xc9\x1eX\xbfa\xf1" |
| 1390 | b"\xac\xb0\xea\xea\xd7\xd0\xab\x18\xe2\xf2\xed\xe1\xb7\xc9\x18\xcbS\xe4>" |
| 1391 | b"\xc9\x95H\xe8\xcb\t\r%\xeb\xc7$.o\xf1\xf3R\x17\x1db\xbb\xd8U\xa5^\xccS" |
| 1392 | b"\x16\x01\x87\xf3/\x93\xd1\xf0v\xc0r\xd7\xcc\xa2Gkz\xca\x80\x0e\xfd\xd0" |
| 1393 | b"\x8b\xbb\xd2Ix\xb3\x1ey\xca-0\xe3z^\xd6\xd6\x8f_\xf1\x9dP\x9fi\xa7\xd1" |
| 1394 | b"\xe8\x90\x84\xdc\xbf\xcdky\x8e\xdc\x81\x7f\xa3\xb2+\xbf\x04\xef\xd8\\" |
| 1395 | b"\xc4\xdf\xe1\xb0\x01\xe9\x93\xe3Y\xf1\x1dY\xe8h\x81\xcf\xf1w\xcc\xb4\xef" |
| 1396 | b" \x8b|\x04\xea\x83ej\xbe\x1f\xd4z\x9c`\xd3\x1a\x92A\x06\xe5\x8f\xa9\x13" |
| 1397 | b"\t\x9e=\xfa\x1c\xe5_\x9f%v\x1bo\x11ZO\xd8\xf4\t\xddM\x16-\x04\xfc\x18<\"" |
| 1398 | b"CM\xddg~b\xf6\xef\x8e\x0c\xd0\xde|\xa0'\x8a\x0c\xd6x\xae!J\xa6F\x88\x15u" |
| 1399 | b"\x008\x17\xbc7y\xb3\xd8u\xac_\x85\x8d\xe7\xc1@\x9c\xecqc\xa3#\xad\xf1" |
| 1400 | b"\x935\xb5)_\r\xec3]\x0fo]5\xd0my\x07\x9b\xee\x81\xb5\x0f\xcfK+\x00\xc0" |
| 1401 | b"\xe4b\x10\xe4\x0c\x1a \x9b\xe0\x97t\xf6\xa1\x9e\x850\xba\x0c\x9a\x8d\xc8" |
| 1402 | b"\x8f\x07\xd7\xae\xc8\xf9+i\xdc\xb9k\xb0>f\x19\xb8\r\xa8\xf8\x1f$\xa5{p" |
| 1403 | b"\xc6\x880\xce\xdb\xcf\xca_\x86\xac\x88h6\x8bZ%'\xd0\n\xbf\x0f\x9c\"\xba" |
| 1404 | b"\xe5\x86\x9f\x0f7X=mNX[\xcc\x19FU\xc9\x860\xbc\x90a+* \xae_$\x03\x1e\xd3" |
| 1405 | b"\xcd_\xa0\x9c\xde\xaf46q\xa5\xc9\x92\xd7\xca\xe3`\x9d\x85}\xb4\xff\xb3" |
| 1406 | b"\x83\xfb\xb6\xca\xae`\x0bw\x7f\xfc\xd8\xacVe\x19\xc8\x17\x0bZ\xad\x88" |
| 1407 | b"\xeb#\x97\x03\x13\xb1d\x0f{\x0c\x04w\x07\r\x97\xbd\xd6\xc1\xc3B:\x95\x08" |
| 1408 | b"^\x10V\xaeaH\x02\xd9\xe3\n\\\x01X\xf6\x9c\x8a\x06u#%\xbe*\xa1\x18v\x85" |
| 1409 | b"\xec!\t4\x00\x00\x00\x00Vj?uLU\xf3\xa6\x00\x01\xfb\x07\x81\x0f\x00\x00tw" |
| 1410 | b"\x99P\xb1\xc4g\xfb\x02\x00\x00\x00\x00\x04YZ" |
| 1411 | ) |
| 1412 | |
| 1413 | COMPRESSED_ALONE = ( |
| 1414 | b"]\x00\x00\x80\x00\xff\xff\xff\xff\xff\xff\xff\xff\x00\x05\x14\x07bX\x19" |
| 1415 | b"\xcd\xddn\x98\x15\xe4\xb4\x9do\x1d\xc4\xe5\n\x03\xcc2h\xc7\\\x86\xff\xf8" |
| 1416 | b"\xe2\xfc\xe7\xd9\xfe6\xb8(\xa8wd\xc2\"u.n\x1e\xc3\xf2\x8e\x8d\x8f\x02" |
| 1417 | b"\x17/\xa6=\xf0\xa2\xdf/M\x89\xbe\xde\xa7\x1cz\x18-]\xd5\xef\x13\x8frZ" |
| 1418 | b"\x15\x80\x8c\xf8\x8do\xfa\x12\x9b#z/\xef\xf0\xfaF\x01\x82\xa3M\x8e\xa1t" |
| 1419 | b"\xca6 BF$\xe5Q\xa4\x98\xee\xdel\xe8\x7f\xf0\x9d,bn\x0b\x13\xd4\xa8\x81" |
| 1420 | b"\xe4N\xc8\x86\x153\xf5x2\xa2O\x13@Q\xa1\x00/\xa5\xd0O\x97\xdco\xae\xf7z" |
| 1421 | b"\xc4\xcdS\xb6t<\x16\xf2\x9cI#\x89ud\xc66Y\xd9\xee\xe6\xce\x12]\xe5\xf0" |
| 1422 | b"\xaa\x96-Pe\xade:\x04\t\x1b\xf7\xdb7\n\x86\x1fp\xc8J\xba\xf4\xf0V\xa9" |
| 1423 | b"\xdc\xf0\x02%G\xf9\xdf=?\x15\x1b\xe1(\xce\x82=\xd6I\xac3\x12\x0cR\xb7" |
| 1424 | b"\xae\r\xb1i\x03\x95\x01\xbd\xbe\xfa\x02s\x01P\x9d\x96X\xb12j\xc8L\xa8" |
| 1425 | b"\x84b\xf8\x1epl\xeajr\xd1=\t\x03\xdd\x13\x1b3!E\xf9vV\xdaF\xf3\xd7\xb4" |
| 1426 | b"\x0c\xa9P~\xec\xdeE\xe37\xf6\x1d\xc6\xbb\xddc%\xb6\x0fI\x07\xf0;\xaf\xe7" |
| 1427 | b"\xa0\x8b\xa7Z\x99(\xe9\xe2\xf0o\x18>`\xe1\xaa\xa8\xd9\xa1\xb2}\xe7\x8d" |
| 1428 | b"\x834T\xb6\xef\xc1\xde\xe3\x98\xbcD\x03MA@\xd8\xed\xdc\xc8\x93\x03\x1a" |
| 1429 | b"\x93\x0b\x7f\x94\x12\x0b\x02Sa\x18\xc9\xc5\x9bTJE}\xf6\xc8g\x17#ZV\x01" |
| 1430 | b"\xc9\x9dc\x83\x0e>0\x16\x90S\xb8/\x03y_\x18\xfa(\xd7\x0br\xa2\xb0\xba?" |
| 1431 | b"\x8c\xe6\x83@\x84\xdf\x02:\xc5z\x9e\xa6\x84\xc9\xf5BeyX\x83\x1a\xf1 :\t" |
| 1432 | b"\xf7\x19\xfexD\\&G\xf3\x85Y\xa2J\xf9\x0bv{\x89\xf6\xe7)A\xaf\x04o\x00" |
| 1433 | b"\x075\xd3\xe0\x7f\x97\x98F\x0f?v\x93\xedVtTf\xb5\x97\x83\xed\x19\xd7\x1a" |
| 1434 | b"'k\xd7\xd9\xc5\\Y\xd1\xdc\x07\x15|w\xbc\xacd\x87\x08d\xec\xa7\xf6\x82" |
| 1435 | b"\xfc\xb3\x93\xeb\xb9 \x8d\xbc ,\xb3X\xb0\xd2s\xd7\xd1\xffv\x05\xdf}\xa2" |
| 1436 | b"\x96\xfb%\n\xdf\xa2\x7f\x08.\xa16\n\xe0\x19\x93\x7fh\n\x1c\x8c\x0f \x11" |
| 1437 | b"\xc6Bl\x95\x19U}\xe4s\xb5\x10H\xea\x86pB\xe88\x95\xbe\x8cZ\xdb\xe4\x94A" |
| 1438 | b"\x92\xb9;z\xaa\xa7{\x1c5!\xc0\xaf\xc1A\xf9\xda\xf0$\xb0\x02qg\xc8\xc7/|" |
| 1439 | b"\xafr\x99^\x91\x88\xbf\x03\xd9=\xd7n\xda6{>8\n\xc7:\xa9'\xba.\x0b\xe2" |
| 1440 | b"\xb5\x1d\x0e\n\x9a\x8e\x06\x8f:\xdd\x82'[\xc3\"wD$\xa7w\xecq\x8c,1\x93" |
| 1441 | b"\xd0,\xae2w\x93\x12$Jd\x19mg\x02\x93\x9cA\x95\x9d&\xca8i\x9c\xb0;\xe7NQ" |
| 1442 | b"\x1frh\x8beL;\xb0m\xee\x07Q\x9b\xc6\xd8\x03\xb5\xdeN\xd4\xfe\x98\xd0\xdc" |
| 1443 | b"\x1a[\x04\xde\x1a\xf6\x91j\xf8EOli\x8eB^\x1d\x82\x07\xb2\xb5R]\xb7\xd7" |
| 1444 | b"\xe9\xa6\xc3.\xfb\xf0-\xb4e\x9b\xde\x03\x88\xc6\xc1iN\x0e\x84wbQ\xdf~" |
| 1445 | b"\xe9\xa4\x884\x96kM\xbc)T\xf3\x89\x97\x0f\x143\xe7)\xa0\xb3B\x00\xa8\xaf" |
| 1446 | b"\x82^\xcb\xc7..\xdb\xc7\t\x9dH\xee5\xe9#\xe6NV\x94\xcb$Kk\xe3\x7f\r\xe3t" |
| 1447 | b"\x12\xcf'\xefR\x8b\xf42\xcf-LH\xac\xe5\x1f0~?SO\xeb\xc1E\x1a\x1c]\xf2" |
| 1448 | b"\xc4<\x11\x02\x10Z0a*?\xe4r\xff\xfb\xff\xf6\x14nG\xead^\xd6\xef8\xb6uEI" |
| 1449 | b"\x99\nV\xe2\xb3\x95\x8e\x83\xf6i!\xb5&1F\xb1DP\xf4 SO3D!w\x99_G\x7f+\x90" |
| 1450 | b".\xab\xbb]\x91>\xc9#h;\x0f5J\x91K\xf4^-[\x9e\x8a\\\x94\xca\xaf\xf6\x19" |
| 1451 | b"\xd4\xa1\x9b\xc4\xb8p\xa1\xae\x15\xe9r\x84\xe0\xcar.l []\x8b\xaf+0\xf2g" |
| 1452 | b"\x01aKY\xdfI\xcf,\n\xe8\xf0\xe7V\x80_#\xb2\xf2\xa9\x06\x8c>w\xe2W,\xf4" |
| 1453 | b"\x8c\r\xf963\xf5J\xcc2\x05=kT\xeaUti\xe5_\xce\x1b\xfa\x8dl\x02h\xef\xa8" |
| 1454 | b"\xfbf\x7f\xff\xf0\x19\xeax" |
| 1455 | ) |
| 1456 | |
| 1457 | FILTERS_RAW_1 = [{"id": lzma.FILTER_LZMA2, "preset": 3}] |
| 1458 | COMPRESSED_RAW_1 = ( |
| 1459 | b"\xe0\x07\x80\x03\xfd]\x00\x05\x14\x07bX\x19\xcd\xddn\x96cyq\xa1\xdd\xee" |
| 1460 | b"\xf8\xfam\xe3'\x88\xd3\xff\xe4\x9e \xceQ\x91\xa4\x14I\xf6\xb9\x9dVL8\x15" |
| 1461 | b"_\x0e\x12\xc3\xeb\xbc\xa5\xcd\nW\x1d$=R;\x1d\xf8k8\t\xb1{\xd4\xc5+\x9d" |
| 1462 | b"\x87c\xe5\xef\x98\xb4\xd7S3\xcd\xcc\xd2\xed\xa4\x0em\xe5\xf4\xdd\xd0b" |
| 1463 | b"\xbe4*\xaa\x0b\xc5\x08\x10\x85+\x81.\x17\xaf9\xc9b\xeaZrA\xe20\x7fs\"r" |
| 1464 | b"\xdaG\x81\xde\x90cu\xa5\xdb\xa9.A\x08l\xb0<\xf6\x03\xddOi\xd0\xc5\xb4" |
| 1465 | b"\xec\xecg4t6\"\xa6\xb8o\xb5?\x18^}\xb6}\x03[:\xeb\x03\xa9\n[\x89l\x19g" |
| 1466 | b"\x16\xc82\xed\x0b\xfb\x86n\xa2\x857@\x93\xcd6T\xc3u\xb0\t\xf9\x1b\x918" |
| 1467 | b"\xfc[\x1b\x1e4\xb3\x14\x06PCV\xa8\"\xf5\x81x~\xe9\xb5N\x9cK\x9f\xc6\xc3%" |
| 1468 | b"\xc8k:{6\xe7\xf7\xbd\x05\x02\xb4\xc4\xc3\xd3\xfd\xc3\xa8\\\xfc@\xb1F_" |
| 1469 | b"\xc8\x90\xd9sU\x98\xad8\x05\x07\xde7J\x8bM\xd0\xb3;X\xec\x87\xef\xae\xb3" |
| 1470 | b"eO,\xb1z,d\x11y\xeejlB\x02\x1d\xf28\x1f#\x896\xce\x0b\xf0\xf5\xa9PK\x0f" |
| 1471 | b"\xb3\x13P\xd8\x88\xd2\xa1\x08\x04C?\xdb\x94_\x9a\"\xe9\xe3e\x1d\xde\x9b" |
| 1472 | b"\xa1\xe8>H\x98\x10;\xc5\x03#\xb5\x9d4\x01\xe7\xc5\xba%v\xa49\x97A\xe0\"" |
| 1473 | b"\x8c\xc22\xe3i\xc1\x9d\xab3\xdf\xbe\xfdDm7\x1b\x9d\xab\xb5\x15o:J\x92" |
| 1474 | b"\xdb\x816\x17\xc2O\x99\x1b\x0e\x8d\xf3\tQ\xed\x8e\x95S/\x16M\xb2S\x04" |
| 1475 | b"\x0f\xc3J\xc6\xc7\xe4\xcb\xc5\xf4\xe7d\x14\xe4=^B\xfb\xd3E\xd3\x1e\xcd" |
| 1476 | b"\x91\xa5\xd0G\x8f.\xf6\xf9\x0bb&\xd9\x9f\xc2\xfdj\xa2\x9e\xc4\\\x0e\x1dC" |
| 1477 | b"v\xe8\xd2\x8a?^H\xec\xae\xeb>\xfe\xb8\xab\xd4IqY\x8c\xd4K7\x11\xf4D\xd0W" |
| 1478 | b"\xa5\xbe\xeaO\xbf\xd0\x04\xfdl\x10\xae5\xd4U\x19\x06\xf9{\xaa\xe0\x81" |
| 1479 | b"\x0f\xcf\xa3k{\x95\xbd\x19\xa2\xf8\xe4\xa3\x08O*\xf1\xf1B-\xc7(\x0eR\xfd" |
| 1480 | b"@E\x9f\xd3\x1e:\xfdV\xb7\x04Y\x94\xeb]\x83\xc4\xa5\xd7\xc0gX\x98\xcf\x0f" |
| 1481 | b"\xcd3\x00]n\x17\xec\xbd\xa3Y\x86\xc5\xf3u\xf6*\xbdT\xedA$A\xd9A\xe7\x98" |
| 1482 | b"\xef\x14\x02\x9a\xfdiw\xec\xa0\x87\x11\xd9%\xc5\xeb\x8a=\xae\xc0\xc4\xc6" |
| 1483 | b"D\x80\x8f\xa8\xd1\xbbq\xb2\xc0\xa0\xf5Cqp\xeeL\xe3\xe5\xdc \x84\"\xe9" |
| 1484 | b"\x80t\x83\x05\xba\xf1\xc5~\x93\xc9\xf0\x01c\xceix\x9d\xed\xc5)l\x16)\xd1" |
| 1485 | b"\x03@l\x04\x7f\x87\xa5yn\x1b\x01D\xaa:\xd2\x96\xb4\xb3?\xb0\xf9\xce\x07" |
| 1486 | b"\xeb\x81\x00\xe4\xc3\xf5%_\xae\xd4\xf9\xeb\xe2\rh\xb2#\xd67Q\x16D\x82hn" |
| 1487 | b"\xd1\xa3_?q\xf0\xe2\xac\xf317\x9e\xd0_\x83|\xf1\xca\xb7\x95S\xabW\x12" |
| 1488 | b"\xff\xddt\xf69L\x01\xf2|\xdaW\xda\xees\x98L\x18\xb8_\xe8$\x82\xea\xd6" |
| 1489 | b"\xd1F\xd4\x0b\xcdk\x01vf\x88h\xc3\xae\xb91\xc7Q\x9f\xa5G\xd9\xcc\x1f\xe3" |
| 1490 | b"5\xb1\xdcy\x7fI\x8bcw\x8e\x10rIp\x02:\x19p_\xc8v\xcea\"\xc1\xd9\x91\x03" |
| 1491 | b"\xbfe\xbe\xa6\xb3\xa8\x14\x18\xc3\xabH*m}\xc2\xc1\x9a}>l%\xce\x84\x99" |
| 1492 | b"\xb3d\xaf\xd3\x82\x15\xdf\xc1\xfc5fOg\x9b\xfc\x8e^&\t@\xce\x9f\x06J\xb8" |
| 1493 | b"\xb5\x86\x1d\xda{\x9f\xae\xb0\xff\x02\x81r\x92z\x8cM\xb7ho\xc9^\x9c\xb6" |
| 1494 | b"\x9c\xae\xd1\xc9\xf4\xdfU7\xd6\\!\xea\x0b\x94k\xb9Ud~\x98\xe7\x86\x8az" |
| 1495 | b"\x10;\xe3\x1d\xe5PG\xf8\xa4\x12\x05w\x98^\xc4\xb1\xbb\xfb\xcf\xe0\x7f" |
| 1496 | b"\x033Sf\x0c \xb1\xf6@\x94\xe5\xa3\xb2\xa7\x10\x9a\xc0\x14\xc3s\xb5xRD" |
| 1497 | b"\xf4`W\xd9\xe5\xd3\xcf\x91\rTZ-X\xbe\xbf\xb5\xe2\xee|\x1a\xbf\xfb\x08" |
| 1498 | b"\x91\xe1\xfc\x9a\x18\xa3\x8b\xd6^\x89\xf5[\xef\x87\xd1\x06\x1c7\xd6\xa2" |
| 1499 | b"\t\tQ5/@S\xc05\xd2VhAK\x03VC\r\x9b\x93\xd6M\xf1xO\xaaO\xed\xb9<\x0c\xdae" |
| 1500 | b"*\xd0\x07Hk6\x9fG+\xa1)\xcd\x9cl\x87\xdb\xe1\xe7\xefK}\x875\xab\xa0\x19u" |
| 1501 | b"\xf6*F\xb32\x00\x00\x00" |
| 1502 | ) |
| 1503 | |
| 1504 | FILTERS_RAW_2 = [{"id": lzma.FILTER_DELTA, "dist": 2}, |
| 1505 | {"id": lzma.FILTER_LZMA2, |
| 1506 | "preset": lzma.PRESET_DEFAULT | lzma.PRESET_EXTREME}] |
| 1507 | COMPRESSED_RAW_2 = ( |
| 1508 | b"\xe0\x07\x80\x05\x91]\x00\x05\x14\x06-\xd4\xa8d?\xef\xbe\xafH\xee\x042" |
| 1509 | b"\xcb.\xb5g\x8f\xfb\x14\xab\xa5\x9f\x025z\xa4\xdd\xd8\t[}W\xf8\x0c\x1dmH" |
| 1510 | b"\xfa\x05\xfcg\xba\xe5\x01Q\x0b\x83R\xb6A\x885\xc0\xba\xee\n\x1cv~\xde:o" |
| 1511 | b"\x06:J\xa7\x11Cc\xea\xf7\xe5*o\xf7\x83\\l\xbdE\x19\x1f\r\xa8\x10\xb42" |
| 1512 | b"\x0caU{\xd7\xb8w\xdc\xbe\x1b\xfc8\xb4\xcc\xd38\\\xf6\x13\xf6\xe7\x98\xfa" |
| 1513 | b"\xc7[\x17_9\x86%\xa8\xf8\xaa\xb8\x8dfs#\x1e=\xed<\x92\x10\\t\xff\x86\xfb" |
| 1514 | b"=\x9e7\x18\x1dft\\\xb5\x01\x95Q\xc5\x19\xb38\xe0\xd4\xaa\x07\xc3\x7f\xd8" |
| 1515 | b"\xa2\x00>-\xd3\x8e\xa1#\xfa\x83ArAm\xdbJ~\x93\xa3B\x82\xe0\xc7\xcc(\x08`" |
| 1516 | b"WK\xad\x1b\x94kaj\x04 \xde\xfc\xe1\xed\xb0\x82\x91\xefS\x84%\x86\xfbi" |
| 1517 | b"\x99X\xf1B\xe7\x90;E\xfde\x98\xda\xca\xd6T\xb4bg\xa4\n\x9aj\xd1\x83\x9e]" |
| 1518 | b"\"\x7fM\xb5\x0fr\xd2\\\xa5j~P\x10GH\xbfN*Z\x10.\x81\tpE\x8a\x08\xbe1\xbd" |
| 1519 | b"\xcd\xa9\xe1\x8d\x1f\x04\xf9\x0eH\xb9\xae\xd6\xc3\xc1\xa5\xa9\x95P\xdc~" |
| 1520 | b"\xff\x01\x930\xa9\x04\xf6\x03\xfe\xb5JK\xc3]\xdd9\xb1\xd3\xd7F\xf5\xd1" |
| 1521 | b"\x1e\xa0\x1c_\xed[\x0c\xae\xd4\x8b\x946\xeb\xbf\xbb\xe3$kS{\xb5\x80,f:Sj" |
| 1522 | b"\x0f\x08z\x1c\xf5\xe8\xe6\xae\x98\xb0Q~r\x0f\xb0\x05?\xb6\x90\x19\x02&" |
| 1523 | b"\xcb\x80\t\xc4\xea\x9c|x\xce\x10\x9c\xc5|\xcbdhh+\x0c'\xc5\x81\xc33\xb5" |
| 1524 | b"\x14q\xd6\xc5\xe3`Z#\xdc\x8a\xab\xdd\xea\x08\xc2I\xe7\x02l{\xec\x196\x06" |
| 1525 | b"\x91\x8d\xdc\xd5\xb3x\xe1hz%\xd1\xf8\xa5\xdd\x98!\x8c\x1c\xc1\x17RUa\xbb" |
| 1526 | b"\x95\x0f\xe4X\xea1\x0c\xf1=R\xbe\xc60\xe3\xa4\x9a\x90bd\x97$]B\x01\xdd" |
| 1527 | b"\x1f\xe3h2c\x1e\xa0L`4\xc6x\xa3Z\x8a\r\x14]T^\xd8\x89\x1b\x92\r;\xedY" |
| 1528 | b"\x0c\xef\x8d9z\xf3o\xb6)f\xa9]$n\rp\x93\xd0\x10\xa4\x08\xb8\xb2\x8b\xb6" |
| 1529 | b"\x8f\x80\xae;\xdcQ\xf1\xfa\x9a\x06\x8e\xa5\x0e\x8cK\x9c @\xaa:UcX\n!\xc6" |
| 1530 | b"\x02\x12\xcb\x1b\"=\x16.\x1f\x176\xf2g=\xe1Wn\xe9\xe1\xd4\xf1O\xad\x15" |
| 1531 | b"\x86\xe9\xa3T\xaf\xa9\xd7D\xb5\xd1W3pnt\x11\xc7VOj\xb7M\xc4i\xa1\xf1$3" |
| 1532 | b"\xbb\xdc\x8af\xb0\xc5Y\r\xd1\xfb\xf2\xe7K\xe6\xc5hwO\xfe\x8c2^&\x07\xd5" |
| 1533 | b"\x1fV\x19\xfd\r\x14\xd2i=yZ\xe6o\xaf\xc6\xb6\x92\x9d\xc4\r\xb3\xafw\xac%" |
| 1534 | b"\xcfc\x1a\xf1`]\xf2\x1a\x9e\x808\xedm\xedQ\xb2\xfe\xe4h`[q\xae\xe0\x0f" |
| 1535 | b"\xba0g\xb6\"N\xc3\xfb\xcfR\x11\xc5\x18)(\xc40\\\xa3\x02\xd9G!\xce\x1b" |
| 1536 | b"\xc1\x96x\xb5\xc8z\x1f\x01\xb4\xaf\xde\xc2\xcd\x07\xe7H\xb3y\xa8M\n\\A\t" |
| 1537 | b"ar\xddM\x8b\x9a\xea\x84\x9b!\xf1\x8d\xb1\xf1~\x1e\r\xa5H\xba\xf1\x84o" |
| 1538 | b"\xda\x87\x01h\xe9\xa2\xbe\xbeqN\x9d\x84\x0b!WG\xda\xa1\xa5A\xb7\xc7`j" |
| 1539 | b"\x15\xf2\xe9\xdd?\x015B\xd2~E\x06\x11\xe0\x91!\x05^\x80\xdd\xa8y\x15}" |
| 1540 | b"\xa1)\xb1)\x81\x18\xf4\xf4\xf8\xc0\xefD\xe3\xdb2f\x1e\x12\xabu\xc9\x97" |
| 1541 | b"\xcd\x1e\xa7\x0c\x02x4_6\x03\xc4$t\xf39\x94\x1d=\xcb\xbfv\\\xf5\xa3\x1d" |
| 1542 | b"\x9d8jk\x95\x13)ff\xf9n\xc4\xa9\xe3\x01\xb8\xda\xfb\xab\xdfM\x99\xfb\x05" |
| 1543 | b"\xe0\xe9\xb0I\xf4E\xab\xe2\x15\xa3\x035\xe7\xdeT\xee\x82p\xb4\x88\xd3" |
| 1544 | b"\x893\x9c/\xc0\xd6\x8fou;\xf6\x95PR\xa9\xb2\xc1\xefFj\xe2\xa7$\xf7h\xf1" |
| 1545 | b"\xdfK(\xc9c\xba7\xe8\xe3)\xdd\xb2,\x83\xfb\x84\x18.y\x18Qi\x88\xf8`h-" |
| 1546 | b"\xef\xd5\xed\x8c\t\xd8\xc3^\x0f\x00\xb7\xd0[!\xafM\x9b\xd7.\x07\xd8\xfb" |
| 1547 | b"\xd9\xe2-S+\xaa8,\xa0\x03\x1b \xea\xa8\x00\xc3\xab~\xd0$e\xa5\x7f\xf7" |
| 1548 | b"\x95P]\x12\x19i\xd9\x7fo\x0c\xd8g^\rE\xa5\x80\x18\xc5\x01\x80\xaek`\xff~" |
| 1549 | b"\xb6y\xe7+\xe5\x11^D\xa7\x85\x18\"!\xd6\xd2\xa7\xf4\x1eT\xdb\x02\xe15" |
| 1550 | b"\x02Y\xbc\x174Z\xe7\x9cH\x1c\xbf\x0f\xc6\xe9f]\xcf\x8cx\xbc\xe5\x15\x94" |
| 1551 | b"\xfc3\xbc\xa7TUH\xf1\x84\x1b\xf7\xa9y\xc07\x84\xf8X\xd8\xef\xfc \x1c\xd8" |
| 1552 | b"( /\xf2\xb7\xec\xc1\\\x8c\xf6\x95\xa1\x03J\x83vP8\xe1\xe3\xbb~\xc24kA" |
| 1553 | b"\x98y\xa1\xf2P\xe9\x9d\xc9J\xf8N\x99\xb4\xceaO\xde\x16\x1e\xc2\x19\xa7" |
| 1554 | b"\x03\xd2\xe0\x8f:\x15\xf3\x84\x9e\xee\xe6e\xb8\x02q\xc7AC\x1emw\xfd\t" |
| 1555 | b"\x9a\x1eu\xc1\xa9\xcaCwUP\x00\xa5\xf78L4w!\x91L2 \x87\xd0\xf2\x06\x81j" |
| 1556 | b"\x80;\x03V\x06\x87\x92\xcb\x90lv@E\x8d\x8d\xa5\xa6\xe7Z[\xdf\xd6E\x03`>" |
| 1557 | b"\x8f\xde\xa1bZ\x84\xd0\xa9`\x05\x0e{\x80;\xe3\xbef\x8d\x1d\xebk1.\xe3" |
| 1558 | b"\xe9N\x15\xf7\xd4(\xfa\xbb\x15\xbdu\xf7\x7f\x86\xae!\x03L\x1d\xb5\xc1" |
| 1559 | b"\xb9\x11\xdb\xd0\x93\xe4\x02\xe1\xd2\xcbBjc_\xe8}d\xdb\xc3\xa0Y\xbe\xc9/" |
| 1560 | b"\x95\x01\xa3,\xe6bl@\x01\xdbp\xc2\xce\x14\x168\xc2q\xe3uH\x89X\xa4\xa9" |
| 1561 | b"\x19\x1d\xc1}\x7fOX\x19\x9f\xdd\xbe\x85\x83\xff\x96\x1ee\x82O`CF=K\xeb$I" |
| 1562 | b"\x17_\xefX\x8bJ'v\xde\x1f+\xd9.v\xf8Tv\x17\xf2\x9f5\x19\xe1\xb9\x91\xa8S" |
| 1563 | b"\x86\xbd\x1a\"(\xa5x\x8dC\x03X\x81\x91\xa8\x11\xc4pS\x13\xbc\xf2'J\xae!" |
| 1564 | b"\xef\xef\x84G\t\x8d\xc4\x10\x132\x00oS\x9e\xe0\xe4d\x8f\xb8y\xac\xa6\x9f" |
| 1565 | b",\xb8f\x87\r\xdf\x9eE\x0f\xe1\xd0\\L\x00\xb2\xe1h\x84\xef}\x98\xa8\x11" |
| 1566 | b"\xccW#\\\x83\x7fo\xbbz\x8f\x00" |
| 1567 | ) |
| 1568 | |
| 1569 | FILTERS_RAW_3 = [{"id": lzma.FILTER_IA64, "start_offset": 0x100}, |
| 1570 | {"id": lzma.FILTER_LZMA2}] |
| 1571 | COMPRESSED_RAW_3 = ( |
| 1572 | b"\xe0\x07\x80\x03\xdf]\x00\x05\x14\x07bX\x19\xcd\xddn\x98\x15\xe4\xb4\x9d" |
| 1573 | b"o\x1d\xc4\xe5\n\x03\xcc2h\xc7\\\x86\xff\xf8\xe2\xfc\xe7\xd9\xfe6\xb8(" |
| 1574 | b"\xa8wd\xc2\"u.n\x1e\xc3\xf2\x8e\x8d\x8f\x02\x17/\xa6=\xf0\xa2\xdf/M\x89" |
| 1575 | b"\xbe\xde\xa7\x1cz\x18-]\xd5\xef\x13\x8frZ\x15\x80\x8c\xf8\x8do\xfa\x12" |
| 1576 | b"\x9b#z/\xef\xf0\xfaF\x01\x82\xa3M\x8e\xa1t\xca6 BF$\xe5Q\xa4\x98\xee\xde" |
| 1577 | b"l\xe8\x7f\xf0\x9d,bn\x0b\x13\xd4\xa8\x81\xe4N\xc8\x86\x153\xf5x2\xa2O" |
| 1578 | b"\x13@Q\xa1\x00/\xa5\xd0O\x97\xdco\xae\xf7z\xc4\xcdS\xb6t<\x16\xf2\x9cI#" |
| 1579 | b"\x89ud\xc66Y\xd9\xee\xe6\xce\x12]\xe5\xf0\xaa\x96-Pe\xade:\x04\t\x1b\xf7" |
| 1580 | b"\xdb7\n\x86\x1fp\xc8J\xba\xf4\xf0V\xa9\xdc\xf0\x02%G\xf9\xdf=?\x15\x1b" |
| 1581 | b"\xe1(\xce\x82=\xd6I\xac3\x12\x0cR\xb7\xae\r\xb1i\x03\x95\x01\xbd\xbe\xfa" |
| 1582 | b"\x02s\x01P\x9d\x96X\xb12j\xc8L\xa8\x84b\xf6\xc3\xd4c-H\x93oJl\xd0iQ\xe4k" |
| 1583 | b"\x84\x0b\xc1\xb7\xbc\xb1\x17\x88\xb1\xca?@\xf6\x07\xea\xe6x\xf1H12P\x0f" |
| 1584 | b"\x8a\xc9\xeauw\xe3\xbe\xaai\xa9W\xd0\x80\xcd#cb5\x99\xd8]\xa9d\x0c\xbd" |
| 1585 | b"\xa2\xdcWl\xedUG\xbf\x89yF\xf77\x81v\xbd5\x98\xbeh8\x18W\x08\xf0\x1b\x99" |
| 1586 | b"5:\x1a?rD\x96\xa1\x04\x0f\xae\xba\x85\xeb\x9d5@\xf5\x83\xd37\x83\x8ac" |
| 1587 | b"\x06\xd4\x97i\xcdt\x16S\x82k\xf6K\x01vy\x88\x91\x9b6T\xdae\r\xfd]:k\xbal" |
| 1588 | b"\xa9\xbba\xc34\xf9r\xeb}r\xdb\xc7\xdb*\x8f\x03z\xdc8h\xcc\xc9\xd3\xbcl" |
| 1589 | b"\xa5-\xcb\xeaK\xa2\xc5\x15\xc0\xe3\xc1\x86Z\xfb\xebL\xe13\xcf\x9c\xe3" |
| 1590 | b"\x1d\xc9\xed\xc2\x06\xcc\xce!\x92\xe5\xfe\x9c^\xa59w \x9bP\xa3PK\x08d" |
| 1591 | b"\xf9\xe2Z}\xa7\xbf\xed\xeb%$\x0c\x82\xb8/\xb0\x01\xa9&,\xf7qh{Q\x96)\xf2" |
| 1592 | b"q\x96\xc3\x80\xb4\x12\xb0\xba\xe6o\xf4!\xb4[\xd4\x8aw\x10\xf7t\x0c\xb3" |
| 1593 | b"\xd9\xd5\xc3`^\x81\x11??\\\xa4\x99\x85R\xd4\x8e\x83\xc9\x1eX\xbfa\xf1" |
| 1594 | b"\xac\xb0\xea\xea\xd7\xd0\xab\x18\xe2\xf2\xed\xe1\xb7\xc9\x18\xcbS\xe4>" |
| 1595 | b"\xc9\x95H\xe8\xcb\t\r%\xeb\xc7$.o\xf1\xf3R\x17\x1db\xbb\xd8U\xa5^\xccS" |
| 1596 | b"\x16\x01\x87\xf3/\x93\xd1\xf0v\xc0r\xd7\xcc\xa2Gkz\xca\x80\x0e\xfd\xd0" |
| 1597 | b"\x8b\xbb\xd2Ix\xb3\x1ey\xca-0\xe3z^\xd6\xd6\x8f_\xf1\x9dP\x9fi\xa7\xd1" |
| 1598 | b"\xe8\x90\x84\xdc\xbf\xcdky\x8e\xdc\x81\x7f\xa3\xb2+\xbf\x04\xef\xd8\\" |
| 1599 | b"\xc4\xdf\xe1\xb0\x01\xe9\x93\xe3Y\xf1\x1dY\xe8h\x81\xcf\xf1w\xcc\xb4\xef" |
| 1600 | b" \x8b|\x04\xea\x83ej\xbe\x1f\xd4z\x9c`\xd3\x1a\x92A\x06\xe5\x8f\xa9\x13" |
| 1601 | b"\t\x9e=\xfa\x1c\xe5_\x9f%v\x1bo\x11ZO\xd8\xf4\t\xddM\x16-\x04\xfc\x18<\"" |
| 1602 | b"CM\xddg~b\xf6\xef\x8e\x0c\xd0\xde|\xa0'\x8a\x0c\xd6x\xae!J\xa6F\x88\x15u" |
| 1603 | b"\x008\x17\xbc7y\xb3\xd8u\xac_\x85\x8d\xe7\xc1@\x9c\xecqc\xa3#\xad\xf1" |
| 1604 | b"\x935\xb5)_\r\xec3]\x0fo]5\xd0my\x07\x9b\xee\x81\xb5\x0f\xcfK+\x00\xc0" |
| 1605 | b"\xe4b\x10\xe4\x0c\x1a \x9b\xe0\x97t\xf6\xa1\x9e\x850\xba\x0c\x9a\x8d\xc8" |
| 1606 | b"\x8f\x07\xd7\xae\xc8\xf9+i\xdc\xb9k\xb0>f\x19\xb8\r\xa8\xf8\x1f$\xa5{p" |
| 1607 | b"\xc6\x880\xce\xdb\xcf\xca_\x86\xac\x88h6\x8bZ%'\xd0\n\xbf\x0f\x9c\"\xba" |
| 1608 | b"\xe5\x86\x9f\x0f7X=mNX[\xcc\x19FU\xc9\x860\xbc\x90a+* \xae_$\x03\x1e\xd3" |
| 1609 | b"\xcd_\xa0\x9c\xde\xaf46q\xa5\xc9\x92\xd7\xca\xe3`\x9d\x85}\xb4\xff\xb3" |
| 1610 | b"\x83\xfb\xb6\xca\xae`\x0bw\x7f\xfc\xd8\xacVe\x19\xc8\x17\x0bZ\xad\x88" |
| 1611 | b"\xeb#\x97\x03\x13\xb1d\x0f{\x0c\x04w\x07\r\x97\xbd\xd6\xc1\xc3B:\x95\x08" |
| 1612 | b"^\x10V\xaeaH\x02\xd9\xe3\n\\\x01X\xf6\x9c\x8a\x06u#%\xbe*\xa1\x18v\x85" |
| 1613 | b"\xec!\t4\x00\x00\x00" |
| 1614 | ) |
| 1615 | |
| 1616 | FILTERS_RAW_4 = [{"id": lzma.FILTER_DELTA, "dist": 4}, |
| 1617 | {"id": lzma.FILTER_X86, "start_offset": 0x40}, |
| 1618 | {"id": lzma.FILTER_LZMA2, "preset": 4, "lc": 2}] |
| 1619 | COMPRESSED_RAW_4 = ( |
| 1620 | b"\xe0\x07\x80\x06\x0e\\\x00\x05\x14\x07bW\xaah\xdd\x10\xdc'\xd6\x90,\xc6v" |
| 1621 | b"Jq \x14l\xb7\x83xB\x0b\x97f=&fx\xba\n>Tn\xbf\x8f\xfb\x1dF\xca\xc3v_\xca?" |
| 1622 | b"\xfbV<\x92#\xd4w\xa6\x8a\xeb\xf6\x03\xc0\x01\x94\xd8\x9e\x13\x12\x98\xd1" |
| 1623 | b"*\xfa]c\xe8\x1e~\xaf\xb5]Eg\xfb\x9e\x01\"8\xb2\x90\x06=~\xe9\x91W\xcd" |
| 1624 | b"\xecD\x12\xc7\xfa\xe1\x91\x06\xc7\x99\xb9\xe3\x901\x87\x19u\x0f\x869\xff" |
| 1625 | b"\xc1\xb0hw|\xb0\xdcl\xcck\xb16o7\x85\xee{Y_b\xbf\xbc$\xf3=\x8d\x8bw\xe5Z" |
| 1626 | b"\x08@\xc4kmE\xad\xfb\xf6*\xd8\xad\xa1\xfb\xc5{\xdej,)\x1emB\x1f<\xaeca" |
| 1627 | b"\x80(\xee\x07 \xdf\xe9\xf8\xeb\x0e-\x97\x86\x90c\xf9\xea'B\xf7`\xd7\xb0" |
| 1628 | b"\x92\xbd\xa0\x82]\xbd\x0e\x0eB\x19\xdc\x96\xc6\x19\xd86D\xf0\xd5\x831" |
| 1629 | b"\x03\xb7\x1c\xf7&5\x1a\x8f PZ&j\xf8\x98\x1bo\xcc\x86\x9bS\xd3\xa5\xcdu" |
| 1630 | b"\xf9$\xcc\x97o\xe5V~\xfb\x97\xb5\x0b\x17\x9c\xfdxW\x10\xfep4\x80\xdaHDY" |
| 1631 | b"\xfa)\xfet\xb5\"\xd4\xd3F\x81\xf4\x13\x1f\xec\xdf\xa5\x13\xfc\"\x91x\xb7" |
| 1632 | b"\x99\xce\xc8\x92\n\xeb[\x10l*Y\xd8\xb1@\x06\xc8o\x8d7r\xebu\xfd5\x0e\x7f" |
| 1633 | b"\xf1$U{\t}\x1fQ\xcfxN\x9d\x9fXX\xe9`\x83\xc1\x06\xf4\x87v-f\x11\xdb/\\" |
| 1634 | b"\x06\xff\xd7)B\xf3g\x06\x88#2\x1eB244\x7f4q\t\xc893?mPX\x95\xa6a\xfb)d" |
| 1635 | b"\x9b\xfc\x98\x9aj\x04\xae\x9b\x9d\x19w\xba\xf92\xfaA\x11\\\x17\x97C3\xa4" |
| 1636 | b"\xbc!\x88\xcdo[\xec:\x030\x91.\x85\xe0@\\4\x16\x12\x9d\xcaJv\x97\xb04" |
| 1637 | b"\xack\xcbkf\xa3ss\xfc\x16^\x8ce\x85a\xa5=&\xecr\xb3p\xd1E\xd5\x80y\xc7" |
| 1638 | b"\xda\xf6\xfek\xbcT\xbfH\xee\x15o\xc5\x8c\x830\xec\x1d\x01\xae\x0c-e\\" |
| 1639 | b"\x91\x90\x94\xb2\xf8\x88\x91\xe8\x0b\xae\xa7>\x98\xf6\x9ck\xd2\xc6\x08" |
| 1640 | b"\xe6\xab\t\x98\xf2!\xa0\x8c^\xacqA\x99<\x1cEG\x97\xc8\xf1\xb6\xb9\x82" |
| 1641 | b"\x8d\xf7\x08s\x98a\xff\xe3\xcc\x92\x0e\xd2\xb6U\xd7\xd9\x86\x7fa\xe5\x1c" |
| 1642 | b"\x8dTG@\t\x1e\x0e7*\xfc\xde\xbc]6N\xf7\xf1\x84\x9e\x9f\xcf\xe9\x1e\xb5'" |
| 1643 | b"\xf4<\xdf\x99sq\xd0\x9d\xbd\x99\x0b\xb4%p4\xbf{\xbb\x8a\xd2\x0b\xbc=M" |
| 1644 | b"\x94H:\xf5\xa8\xd6\xa4\xc90\xc2D\xb9\xd3\xa8\xb0S\x87 `\xa2\xeb\xf3W\xce" |
| 1645 | b" 7\xf9N#\r\xe6\xbe\t\x9d\xe7\x811\xf9\x10\xc1\xc2\x14\xf6\xfc\xcba\xb7" |
| 1646 | b"\xb1\x7f\x95l\xe4\tjA\xec:\x10\xe5\xfe\xc2\\=D\xe2\x0c\x0b3]\xf7\xc1\xf7" |
| 1647 | b"\xbceZ\xb1A\xea\x16\xe5\xfddgFQ\xed\xaf\x04\xa3\xd3\xf8\xa2q\x19B\xd4r" |
| 1648 | b"\xc5\x0c\x9a\x14\x94\xea\x91\xc4o\xe4\xbb\xb4\x99\xf4@\xd1\xe6\x0c\xe3" |
| 1649 | b"\xc6d\xa0Q\n\xf2/\xd8\xb8S5\x8a\x18:\xb5g\xac\x95D\xce\x17\x07\xd4z\xda" |
| 1650 | b"\x90\xe65\x07\x19H!\t\xfdu\x16\x8e\x0eR\x19\xf4\x8cl\x0c\xf9Q\xf1\x80" |
| 1651 | b"\xe3\xbf\xd7O\xf8\x8c\x18\x0b\x9c\xf1\x1fb\xe1\tR\xb2\xf1\xe1A\xea \xcf-" |
| 1652 | b"IGE\xf1\x14\x98$\x83\x15\xc9\xd8j\xbf\x19\x0f\xd5\xd1\xaa\xb3\xf3\xa5I2s" |
| 1653 | b"\x8d\x145\xca\xd5\xd93\x9c\xb8D0\xe6\xaa%\xd0\xc0P}JO^h\x8e\x08\xadlV." |
| 1654 | b"\x18\x88\x13\x05o\xb0\x07\xeaw\xe0\xb6\xa4\xd5*\xe4r\xef\x07G+\xc1\xbei[" |
| 1655 | b"w\xe8\xab@_\xef\x15y\xe5\x12\xc9W\x1b.\xad\x85-\xc2\xf7\xe3mU6g\x8eSA" |
| 1656 | b"\x01(\xd3\xdb\x16\x13=\xde\x92\xf9,D\xb8\x8a\xb2\xb4\xc9\xc3\xefnE\xe8\\" |
| 1657 | b"\xa6\xe2Y\xd2\xcf\xcb\x8c\xb6\xd5\xe9\x1d\x1e\x9a\x8b~\xe2\xa6\rE\x84uV" |
| 1658 | b"\xed\xc6\x99\xddm<\x10[\x0fu\x1f\xc1\x1d1\n\xcfw\xb2%!\xf0[\xce\x87\x83B" |
| 1659 | b"\x08\xaa,\x08%d\xcef\x94\"\xd9g.\xc83\xcbXY+4\xec\x85qA\n\x1d=9\xf0*\xb1" |
| 1660 | b"\x1f/\xf3s\xd61b\x7f@\xfb\x9d\xe3FQ\\\xbd\x82\x1e\x00\xf3\xce\xd3\xe1" |
| 1661 | b"\xca,E\xfd7[\xab\xb6\xb7\xac!mA}\xbd\x9d3R5\x9cF\xabH\xeb\x92)cc\x13\xd0" |
| 1662 | b"\xbd\xee\xe9n{\x1dIJB\xa5\xeb\x11\xe8`w&`\x8b}@Oxe\t\x8a\x07\x02\x95\xf2" |
| 1663 | b"\xed\xda|\xb1e\xbe\xaa\xbbg\x19@\xe1Y\x878\x84\x0f\x8c\xe3\xc98\xf2\x9e" |
| 1664 | b"\xd5N\xb5J\xef\xab!\xe2\x8dq\xe1\xe5q\xc5\xee\x11W\xb7\xe4k*\x027\xa0" |
| 1665 | b"\xa3J\xf4\xd8m\xd0q\x94\xcb\x07\n:\xb6`.\xe4\x9c\x15+\xc0)\xde\x80X\xd4" |
| 1666 | b"\xcfQm\x01\xc2cP\x1cA\x85'\xc9\xac\x8b\xe6\xb2)\xe6\x84t\x1c\x92\xe4Z" |
| 1667 | b"\x1cR\xb0\x9e\x96\xd1\xfb\x1c\xa6\x8b\xcb`\x10\x12]\xf2gR\x9bFT\xe0\xc8H" |
| 1668 | b"S\xfb\xac<\x04\xc7\xc1\xe8\xedP\xf4\x16\xdb\xc0\xd7e\xc2\x17J^\x1f\xab" |
| 1669 | b"\xff[\x08\x19\xb4\xf5\xfb\x19\xb4\x04\xe5c~']\xcb\xc2A\xec\x90\xd0\xed" |
| 1670 | b"\x06,\xc5K{\x86\x03\xb1\xcdMx\xdeQ\x8c3\xf9\x8a\xea=\x89\xaba\xd2\xc89a" |
| 1671 | b"\xd72\xf0\xc3\x19\x8a\xdfs\xd4\xfd\xbb\x81b\xeaE\"\xd8\xf4d\x0cD\xf7IJ!" |
| 1672 | b"\xe5d\xbbG\xe9\xcam\xaa\x0f_r\x95\x91NBq\xcaP\xce\xa7\xa9\xb5\x10\x94eP!" |
| 1673 | b"|\x856\xcd\xbfIir\xb8e\x9bjP\x97q\xabwS7\x1a\x0ehM\xe7\xca\x86?\xdeP}y~" |
| 1674 | b"\x0f\x95I\xfc\x13\xe1<Q\x1b\x868\x1d\x11\xdf\x94\xf4\x82>r\xa9k\x88\xcb" |
| 1675 | b"\xfd\xc3v\xe2\xb9\x8a\x02\x8eq\x92I\xf8\xf6\xf1\x03s\x9b\xb8\xe3\"\xe3" |
| 1676 | b"\xa9\xa5>D\xb8\x96;\xe7\x92\xd133\xe8\xdd'e\xc9.\xdc;\x17\x1f\xf5H\x13q" |
| 1677 | b"\xa4W\x0c\xdb~\x98\x01\xeb\xdf\xe32\x13\x0f\xddx\n6\xa0\t\x10\xb6\xbb" |
| 1678 | b"\xb0\xc3\x18\xb6;\x9fj[\xd9\xd5\xc9\x06\x8a\x87\xcd\xe5\xee\xfc\x9c-%@" |
| 1679 | b"\xee\xe0\xeb\xd2\xe3\xe8\xfb\xc0\x122\\\xc7\xaf\xc2\xa1Oth\xb3\x8f\x82" |
| 1680 | b"\xb3\x18\xa8\x07\xd5\xee_\xbe\xe0\x1cA\x1e_\r\x9a\xb0\x17W&\xa2D\x91\x94" |
| 1681 | b"\x1a\xb2\xef\xf2\xdc\x85;X\xb0,\xeb>-7S\xe5\xca\x07)\x1fp\x7f\xcaQBL\xca" |
| 1682 | b"\xf3\xb9d\xfc\xb5su\xb0\xc8\x95\x90\xeb*)\xa0v\xe4\x9a{FW\xf4l\xde\xcdj" |
| 1683 | b"\x00" |
| 1684 | ) |
| 1685 | |
| 1686 | |
| 1687 | def test_main(): |
| 1688 | run_unittest( |
| 1689 | CompressorDecompressorTestCase, |
| 1690 | CompressDecompressFunctionTestCase, |
| 1691 | FileTestCase, |
Nadeem Vawda | e860404 | 2012-06-04 23:38:12 +0200 | [diff] [blame] | 1692 | OpenTestCase, |
Nadeem Vawda | 3ff069e | 2011-11-30 00:25:06 +0200 | [diff] [blame] | 1693 | MiscellaneousTestCase, |
| 1694 | ) |
| 1695 | |
| 1696 | if __name__ == "__main__": |
| 1697 | test_main() |