| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -393,7 +393,6 @@ struct _Py_global_strings { | |||
| 393 | 393 | STRUCT_FOR_ID(deterministic) | |
| 394 | 394 | STRUCT_FOR_ID(device) | |
| 395 | 395 | STRUCT_FOR_ID(dict) | |
| 396 | - STRUCT_FOR_ID(dict_content) | ||
| 397 | 396 | STRUCT_FOR_ID(dictcomp) | |
| 398 | 397 | STRUCT_FOR_ID(difference_update) | |
| 399 | 398 | STRUCT_FOR_ID(digest) | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -288,8 +288,8 @@ def test_unknown_compression_parameter(self): | |||
| 288 | 288 | KEY = 100001234 | |
| 289 | 289 | option = {CompressionParameter.compression_level: 10, | |
| 290 | 290 | KEY: 200000000} | |
| 291 | - pattern = r'Zstd compression parameter.*?"unknown parameter \(key %d\)"' \ | ||
| 292 | - % KEY | ||
| 291 | + pattern = (r'Invalid zstd compression parameter.*?' | ||
| 292 | + fr'"unknown parameter \(key {KEY}\)"') | ||
| 293 | 293 | with self.assertRaisesRegex(ZstdError, pattern): | |
| 294 | 294 | ZstdCompressor(options=option) | |
| 295 | 295 | ||
@@ -420,8 +420,8 @@ def test_unknown_decompression_parameter(self): | |||
| 420 | 420 | KEY = 100001234 | |
| 421 | 421 | options = {DecompressionParameter.window_log_max: DecompressionParameter.window_log_max.bounds()[1], | |
| 422 | 422 | KEY: 200000000} | |
| 423 | - pattern = r'Zstd decompression parameter.*?"unknown parameter \(key %d\)"' \ | ||
| 424 | - % KEY | ||
| 423 | + pattern = (r'Invalid zstd decompression parameter.*?' | ||
| 424 | + fr'"unknown parameter \(key {KEY}\)"') | ||
| 425 | 425 | with self.assertRaisesRegex(ZstdError, pattern): | |
| 426 | 426 | ZstdDecompressor(options=options) | |
| 427 | 427 | ||
@@ -507,7 +507,7 @@ def test_decompress_epilogue_flags(self): | |||
| 507 | 507 | self.assertFalse(d.needs_input) | |
| 508 | 508 | ||
| 509 | 509 | def test_decompressor_arg(self): | |
| 510 | - zd = ZstdDict(b'12345678', True) | ||
| 510 | + zd = ZstdDict(b'12345678', is_raw=True) | ||
| 511 | 511 | ||
| 512 | 512 | with self.assertRaises(TypeError): | |
| 513 | 513 | d = ZstdDecompressor(zstd_dict={}) | |
@@ -1021,6 +1021,10 @@ def test_decompressor_skippable(self): | |||
| 1021 | 1021 | class ZstdDictTestCase(unittest.TestCase): | |
| 1022 | 1022 | ||
| 1023 | 1023 | def test_is_raw(self): | |
| 1024 | + # must be passed as a keyword argument | ||
| 1025 | + with self.assertRaises(TypeError): | ||
| 1026 | + ZstdDict(bytes(8), True) | ||
| 1027 | + | ||
| 1024 | 1028 | # content < 8 | |
| 1025 | 1029 | b = b'1234567' | |
| 1026 | 1030 | with self.assertRaises(ValueError): | |
@@ -1068,9 +1072,9 @@ def test_invalid_dict(self): | |||
| 1068 | 1072 | ||
| 1069 | 1073 | # corrupted | |
| 1070 | 1074 | zd = ZstdDict(dict_content, is_raw=False) | |
| 1071 | - with self.assertRaisesRegex(ZstdError, r'ZSTD_CDict.*?corrupted'): | ||
| 1075 | + with self.assertRaisesRegex(ZstdError, r'ZSTD_CDict.*?content\.$'): | ||
| 1072 | 1076 | ZstdCompressor(zstd_dict=zd.as_digested_dict) | |
| 1073 | - with self.assertRaisesRegex(ZstdError, r'ZSTD_DDict.*?corrupted'): | ||
| 1077 | + with self.assertRaisesRegex(ZstdError, r'ZSTD_DDict.*?content\.$'): | ||
| 1074 | 1078 | ZstdDecompressor(zd) | |
| 1075 | 1079 | ||
| 1076 | 1080 | # wrong type | |
@@ -1096,7 +1100,7 @@ def test_train_dict(self): | |||
| 1096 | 1100 | ||
| 1097 | 1101 | ||
| 1098 | 1102 | TRAINED_DICT = train_dict(SAMPLES, DICT_SIZE1) | |
| 1099 | - ZstdDict(TRAINED_DICT.dict_content, False) | ||
| 1103 | + ZstdDict(TRAINED_DICT.dict_content, is_raw=False) | ||
| 1100 | 1104 | ||
| 1101 | 1105 | self.assertNotEqual(TRAINED_DICT.dict_id, 0) | |
| 1102 | 1106 | self.assertGreater(len(TRAINED_DICT.dict_content), 0) | |
@@ -1250,7 +1254,7 @@ def _nbytes(dat): | |||
| 1250 | 1254 | def test_as_prefix(self): | |
| 1251 | 1255 | # V1 | |
| 1252 | 1256 | V1 = THIS_FILE_BYTES | |
| 1253 | - zd = ZstdDict(V1, True) | ||
| 1257 | + zd = ZstdDict(V1, is_raw=True) | ||
| 1254 | 1258 | ||
| 1255 | 1259 | # V2 | |
| 1256 | 1260 | mid = len(V1) // 2 | |
@@ -1266,7 +1270,7 @@ def test_as_prefix(self): | |||
| 1266 | 1270 | self.assertEqual(decompress(dat, zd.as_prefix), V2) | |
| 1267 | 1271 | ||
| 1268 | 1272 | # use wrong prefix | |
| 1269 | - zd2 = ZstdDict(SAMPLES[0], True) | ||
| 1273 | + zd2 = ZstdDict(SAMPLES[0], is_raw=True) | ||
| 1270 | 1274 | try: | |
| 1271 | 1275 | decompressed = decompress(dat, zd2.as_prefix) | |
| 1272 | 1276 | except ZstdError: # expected | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,4 @@ | |||
| 1 | - /* | ||
| 2 | - Low level interface to Meta's zstd library for use in the compression.zstd | ||
| 3 | - Python module. | ||
| 4 | - */ | ||
| 1 | + /* Low level interface to the Zstandard algorthm & the zstd library. */ | ||
| 5 | 2 | ||
| 6 | 3 | #ifndef Py_BUILD_CORE_BUILTIN | |
| 7 | 4 | # define Py_BUILD_CORE_MODULE 1 | |
@@ -34,17 +31,17 @@ set_zstd_error(const _zstd_state* const state, | |||
| 34 | 31 | switch (type) | |
| 35 | 32 | { | |
| 36 | 33 | case ERR_DECOMPRESS: | |
| 37 | - msg = "Unable to decompress zstd data: %s"; | ||
| 34 | + msg = "Unable to decompress Zstandard data: %s"; | ||
| 38 | 35 | break; | |
| 39 | 36 | case ERR_COMPRESS: | |
| 40 | - msg = "Unable to compress zstd data: %s"; | ||
| 37 | + msg = "Unable to compress Zstandard data: %s"; | ||
| 41 | 38 | break; | |
| 42 | 39 | ||
| 43 | 40 | case ERR_LOAD_D_DICT: | |
| 44 | - msg = "Unable to load zstd dictionary or prefix for decompression: %s"; | ||
| 41 | + msg = "Unable to load Zstandard dictionary or prefix for decompression: %s"; | ||
| 45 | 42 | break; | |
| 46 | 43 | case ERR_LOAD_C_DICT: | |
| 47 | - msg = "Unable to load zstd dictionary or prefix for compression: %s"; | ||
| 44 | + msg = "Unable to load Zstandard dictionary or prefix for compression: %s"; | ||
| 48 | 45 | break; | |
| 49 | 46 | ||
| 50 | 47 | case ERR_GET_C_BOUNDS: | |
@@ -58,10 +55,10 @@ set_zstd_error(const _zstd_state* const state, | |||
| 58 | 55 | break; | |
| 59 | 56 | ||
| 60 | 57 | case ERR_TRAIN_DICT: | |
| 61 | - msg = "Unable to train zstd dictionary: %s"; | ||
| 58 | + msg = "Unable to train the Zstandard dictionary: %s"; | ||
| 62 | 59 | break; | |
| 63 | 60 | case ERR_FINALIZE_DICT: | |
| 64 | - msg = "Unable to finalize zstd dictionary: %s"; | ||
| 61 | + msg = "Unable to finalize the Zstandard dictionary: %s"; | ||
| 65 | 62 | break; | |
| 66 | 63 | ||
| 67 | 64 | default: | |
@@ -152,7 +149,7 @@ set_parameter_error(const _zstd_state* const state, int is_compress, | |||
| 152 | 149 | } | |
| 153 | 150 | if (ZSTD_isError(bounds.error)) { | |
| 154 | 151 | PyErr_Format(state->ZstdError, | |
| 155 | - "Zstd %s parameter \"%s\" is invalid.", | ||
| 152 | + "Invalid zstd %s parameter \"%s\".", | ||
| 156 | 153 | type, name); | |
| 157 | 154 | return; | |
| 158 | 155 | } | |
@@ -187,13 +184,13 @@ _zstd.train_dict | |||
| 187 | 184 | The size of the dictionary. | |
| 188 | 185 | / | |
| 189 | 186 | ||
| 190 | - Internal function, train a zstd dictionary on sample data. | ||
| 187 | + Train a Zstandard dictionary on sample data. | ||
| 191 | 188 | [clinic start generated code]*/ | |
| 192 | 189 | ||
| 193 | 190 | static PyObject * | |
| 194 | 191 | _zstd_train_dict_impl(PyObject *module, PyBytesObject *samples_bytes, | |
| 195 | 192 | PyObject *samples_sizes, Py_ssize_t dict_size) | |
| 196 | - /*[clinic end generated code: output=8e87fe43935e8f77 input=70fcd8937f2528b6]*/ | ||
| 193 | + /*[clinic end generated code: output=8e87fe43935e8f77 input=d20dedb21c72cb62]*/ | ||
| 197 | 194 | { | |
| 198 | 195 | // TODO(emmatyping): The preamble and suffix to this function and _finalize_dict | |
| 199 | 196 | // are pretty similar. We should see if we can refactor them to share that code. | |
@@ -258,7 +255,7 @@ _zstd_train_dict_impl(PyObject *module, PyBytesObject *samples_bytes, | |||
| 258 | 255 | chunk_sizes, (uint32_t)chunks_number); | |
| 259 | 256 | Py_END_ALLOW_THREADS | |
| 260 | 257 | ||
| 261 | - /* Check zstd dict error */ | ||
| 258 | + /* Check Zstandard dict error */ | ||
| 262 | 259 | if (ZDICT_isError(zstd_ret)) { | |
| 263 | 260 | _zstd_state* const mod_state = get_zstd_state(module); | |
| 264 | 261 | set_zstd_error(mod_state, ERR_TRAIN_DICT, zstd_ret); | |
@@ -292,18 +289,18 @@ _zstd.finalize_dict | |||
| 292 | 289 | dict_size: Py_ssize_t | |
| 293 | 290 | The size of the dictionary. | |
| 294 | 291 | compression_level: int | |
| 295 | - Optimize for a specific zstd compression level, 0 means default. | ||
| 292 | + Optimize for a specific Zstandard compression level, 0 means default. | ||
| 296 | 293 | / | |
| 297 | 294 | ||
| 298 | - Internal function, finalize a zstd dictionary. | ||
| 295 | + Finalize a Zstandard dictionary. | ||
| 299 | 296 | [clinic start generated code]*/ | |
| 300 | 297 | ||
| 301 | 298 | static PyObject * | |
| 302 | 299 | _zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes, | |
| 303 | 300 | PyBytesObject *samples_bytes, | |
| 304 | 301 | PyObject *samples_sizes, Py_ssize_t dict_size, | |
| 305 | 302 | int compression_level) | |
| 306 | - /*[clinic end generated code: output=f91821ba5ae85bda input=130d1508adb55ba1]*/ | ||
| 303 | + /*[clinic end generated code: output=f91821ba5ae85bda input=3c7e2480aa08fb56]*/ | ||
| 307 | 304 | { | |
| 308 | 305 | Py_ssize_t chunks_number; | |
| 309 | 306 | size_t *chunk_sizes = NULL; | |
@@ -360,7 +357,7 @@ _zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes, | |||
| 360 | 357 | ||
| 361 | 358 | /* Parameters */ | |
| 362 | 359 | ||
| 363 | - /* Optimize for a specific zstd compression level, 0 means default. */ | ||
| 360 | + /* Optimize for a specific Zstandard compression level, 0 means default. */ | ||
| 364 | 361 | params.compressionLevel = compression_level; | |
| 365 | 362 | /* Write log to stderr, 0 = none. */ | |
| 366 | 363 | params.notificationLevel = 0; | |
@@ -376,7 +373,7 @@ _zstd_finalize_dict_impl(PyObject *module, PyBytesObject *custom_dict_bytes, | |||
| 376 | 373 | (uint32_t)chunks_number, params); | |
| 377 | 374 | Py_END_ALLOW_THREADS | |
| 378 | 375 | ||
| 379 | - /* Check zstd dict error */ | ||
| 376 | + /* Check Zstandard dict error */ | ||
| 380 | 377 | if (ZDICT_isError(zstd_ret)) { | |
| 381 | 378 | _zstd_state* const mod_state = get_zstd_state(module); | |
| 382 | 379 | set_zstd_error(mod_state, ERR_FINALIZE_DICT, zstd_ret); | |
@@ -407,12 +404,12 @@ _zstd.get_param_bounds | |||
| 407 | 404 | is_compress: bool | |
| 408 | 405 | True for CompressionParameter, False for DecompressionParameter. | |
| 409 | 406 | ||
| 410 | - Internal function, get CompressionParameter/DecompressionParameter bounds. | ||
| 407 | + Get CompressionParameter/DecompressionParameter bounds. | ||
| 411 | 408 | [clinic start generated code]*/ | |
| 412 | 409 | ||
| 413 | 410 | static PyObject * | |
| 414 | 411 | _zstd_get_param_bounds_impl(PyObject *module, int parameter, int is_compress) | |
| 415 | - /*[clinic end generated code: output=4acf5a876f0620ca input=84e669591e487008]*/ | ||
| 412 | + /*[clinic end generated code: output=4acf5a876f0620ca input=45742ef0a3531b65]*/ | ||
| 416 | 413 | { | |
| 417 | 414 | ZSTD_bounds bound; | |
| 418 | 415 | if (is_compress) { | |
@@ -442,24 +439,22 @@ _zstd.get_frame_size | |||
| 442 | 439 | A bytes-like object, it should start from the beginning of a frame, | |
| 443 | 440 | and contains at least one complete frame. | |
| 444 | 441 | ||
| 445 | - Get the size of a zstd frame, including frame header and 4-byte checksum if it has one. | ||
| 446 | - | ||
| 447 | - It will iterate all blocks' headers within a frame, to accumulate the frame size. | ||
| 442 | + Get the size of a Zstandard frame, including the header and optional checksum. | ||
| 448 | 443 | [clinic start generated code]*/ | |
| 449 | 444 | ||
| 450 | 445 | static PyObject * | |
| 451 | 446 | _zstd_get_frame_size_impl(PyObject *module, Py_buffer *frame_buffer) | |
| 452 | - /*[clinic end generated code: output=a7384c2f8780f442 input=7d3ad24311893bf3]*/ | ||
| 447 | + /*[clinic end generated code: output=a7384c2f8780f442 input=3b9f73f8c8129d38]*/ | ||
| 453 | 448 | { | |
| 454 | 449 | size_t frame_size; | |
| 455 | 450 | ||
| 456 | 451 | frame_size = ZSTD_findFrameCompressedSize(frame_buffer->buf, frame_buffer->len); | |
| 457 | 452 | if (ZSTD_isError(frame_size)) { | |
| 458 | 453 | _zstd_state* const mod_state = get_zstd_state(module); | |
| 459 | 454 | PyErr_Format(mod_state->ZstdError, | |
| 460 | - "Error when finding the compressed size of a zstd frame. " | ||
| 461 | - "Make sure the frame_buffer argument starts from the " | ||
| 462 | - "beginning of a frame, and its length not less than this " | ||
| 455 | + "Error when finding the compressed size of a Zstandard frame. " | ||
| 456 | + "Ensure the frame_buffer argument starts from the " | ||
| 457 | + "beginning of a frame, and its length is not less than this " | ||
| 463 | 458 | "complete frame. Zstd error message: %s.", | |
| 464 | 459 | ZSTD_getErrorName(frame_size)); | |
| 465 | 460 | return NULL; | |
@@ -472,14 +467,14 @@ _zstd_get_frame_size_impl(PyObject *module, Py_buffer *frame_buffer) | |||
| 472 | 467 | _zstd.get_frame_info | |
| 473 | 468 | ||
| 474 | 469 | frame_buffer: Py_buffer | |
| 475 | - A bytes-like object, containing the header of a zstd frame. | ||
| 470 | + A bytes-like object, containing the header of a Zstandard frame. | ||
| 476 | 471 | ||
| 477 | - Internal function, get zstd frame infomation from a frame header. | ||
| 472 | + Get Zstandard frame infomation from a frame header. | ||
| 478 | 473 | [clinic start generated code]*/ | |
| 479 | 474 | ||
| 480 | 475 | static PyObject * | |
| 481 | 476 | _zstd_get_frame_info_impl(PyObject *module, Py_buffer *frame_buffer) | |
| 482 | - /*[clinic end generated code: output=56e033cf48001929 input=1816f14656b6aa22]*/ | ||
| 477 | + /*[clinic end generated code: output=56e033cf48001929 input=94b240583ae22ca5]*/ | ||
| 483 | 478 | { | |
| 484 | 479 | uint64_t decompressed_size; | |
| 485 | 480 | uint32_t dict_id; | |
@@ -494,9 +489,9 @@ _zstd_get_frame_info_impl(PyObject *module, Py_buffer *frame_buffer) | |||
| 494 | 489 | _zstd_state* const mod_state = get_zstd_state(module); | |
| 495 | 490 | PyErr_SetString(mod_state->ZstdError, | |
| 496 | 491 | "Error when getting information from the header of " | |
| 497 | - "a zstd frame. Make sure the frame_buffer argument " | ||
| 492 | + "a Zstandard frame. Ensure the frame_buffer argument " | ||
| 498 | 493 | "starts from the beginning of a frame, and its length " | |
| 499 | - "not less than the frame header (6~18 bytes)."); | ||
| 494 | + "is not less than the frame header (6~18 bytes)."); | ||
| 500 | 495 | return NULL; | |
| 501 | 496 | } | |
| 502 | 497 | ||
@@ -518,13 +513,13 @@ _zstd.set_parameter_types | |||
| 518 | 513 | d_parameter_type: object(subclass_of='&PyType_Type') | |
| 519 | 514 | DecompressionParameter IntEnum type object | |
| 520 | 515 | ||
| 521 | - Internal function, set CompressionParameter/DecompressionParameter types for validity check. | ||
| 516 | + Set CompressionParameter and DecompressionParameter types for validity check. | ||
| 522 | 517 | [clinic start generated code]*/ | |
| 523 | 518 | ||
| 524 | 519 | static PyObject * | |
| 525 | 520 | _zstd_set_parameter_types_impl(PyObject *module, PyObject *c_parameter_type, | |
| 526 | 521 | PyObject *d_parameter_type) | |
| 527 | - /*[clinic end generated code: output=f3313b1294f19502 input=30402523871b8280]*/ | ||
| 522 | + /*[clinic end generated code: output=f3313b1294f19502 input=75d7a953580fae5f]*/ | ||
| 528 | 523 | { | |
| 529 | 524 | _zstd_state* const mod_state = get_zstd_state(module); | |
| 530 | 525 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,4 @@ | |||
| 1 | - /* | ||
| 2 | - Low level interface to Meta's zstd library for use in the compression.zstd | ||
| 3 | - Python module. | ||
| 4 | - */ | ||
| 1 | + /* Low level interface to the Zstandard algorthm & the zstd library. */ | ||
| 5 | 2 | ||
| 6 | 3 | /* Declarations shared between different parts of the _zstd module*/ | |
| 7 | 4 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,7 +1,4 @@ | |||
| 1 | - /* | ||
| 2 | - Low level interface to Meta's zstd library for use in the compression.zstd | ||
| 3 | - Python module. | ||
| 4 | - */ | ||
| 1 | + /* Low level interface to the Zstandard algorthm & the zstd library. */ | ||
| 5 | 2 | ||
| 6 | 3 | #ifndef ZSTD_BUFFER_H | |
| 7 | 4 | #define ZSTD_BUFFER_H | |
| Back | FazBrowse Home | New Git URL |
0 commit comments