Skip to content

Commit e175acd

Browse files
committed
Make parameter names snake case
1 parent 81aad82 commit e175acd

File tree

3 files changed

+98
-98
lines changed

3 files changed

+98
-98
lines changed

Lib/compression/zstd/__init__.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -182,28 +182,28 @@ def decompress(data, zstd_dict=None, options=None):
182182
class CParameter(enum.IntEnum):
183183
"""Compression parameters"""
184184

185-
compressionLevel = _zstd._ZSTD_c_compressionLevel
186-
windowLog = _zstd._ZSTD_c_windowLog
187-
hashLog = _zstd._ZSTD_c_hashLog
188-
chainLog = _zstd._ZSTD_c_chainLog
189-
searchLog = _zstd._ZSTD_c_searchLog
190-
minMatch = _zstd._ZSTD_c_minMatch
191-
targetLength = _zstd._ZSTD_c_targetLength
185+
compression_level = _zstd._ZSTD_c_compressionLevel
186+
window_log = _zstd._ZSTD_c_windowLog
187+
hash_log = _zstd._ZSTD_c_hashLog
188+
chain_log = _zstd._ZSTD_c_chainLog
189+
search_log = _zstd._ZSTD_c_searchLog
190+
min_match = _zstd._ZSTD_c_minMatch
191+
target_length = _zstd._ZSTD_c_targetLength
192192
strategy = _zstd._ZSTD_c_strategy
193193

194-
enableLongDistanceMatching = _zstd._ZSTD_c_enableLongDistanceMatching
195-
ldmHashLog = _zstd._ZSTD_c_ldmHashLog
196-
ldmMinMatch = _zstd._ZSTD_c_ldmMinMatch
197-
ldmBucketSizeLog = _zstd._ZSTD_c_ldmBucketSizeLog
198-
ldmHashRateLog = _zstd._ZSTD_c_ldmHashRateLog
194+
enable_long_distance_matching = _zstd._ZSTD_c_enableLongDistanceMatching
195+
ldm_hash_log = _zstd._ZSTD_c_ldmHashLog
196+
ldm_min_match = _zstd._ZSTD_c_ldmMinMatch
197+
ldm_bucket_size_log = _zstd._ZSTD_c_ldmBucketSizeLog
198+
ldm_hash_rate_log = _zstd._ZSTD_c_ldmHashRateLog
199199

200-
contentSizeFlag = _zstd._ZSTD_c_contentSizeFlag
201-
checksumFlag = _zstd._ZSTD_c_checksumFlag
202-
dictIDFlag = _zstd._ZSTD_c_dictIDFlag
200+
content_size_flag = _zstd._ZSTD_c_contentSizeFlag
201+
checksum_flag = _zstd._ZSTD_c_checksumFlag
202+
dict_id_flag = _zstd._ZSTD_c_dictIDFlag
203203

204-
nbWorkers = _zstd._ZSTD_c_nbWorkers
205-
jobSize = _zstd._ZSTD_c_jobSize
206-
overlapLog = _zstd._ZSTD_c_overlapLog
204+
nb_workers = _zstd._ZSTD_c_nbWorkers
205+
job_size = _zstd._ZSTD_c_jobSize
206+
overlap_log = _zstd._ZSTD_c_overlapLog
207207

208208
def bounds(self):
209209
"""Return lower and upper bounds of a compression parameter, both inclusive."""
@@ -213,7 +213,7 @@ def bounds(self):
213213
class DParameter(enum.IntEnum):
214214
"""Decompression parameters"""
215215

216-
windowLogMax = _zstd._ZSTD_d_windowLogMax
216+
window_log_max = _zstd._ZSTD_d_windowLogMax
217217

218218
def bounds(self):
219219
"""Return lower and upper bounds of a decompression parameter, both inclusive."""
@@ -241,4 +241,4 @@ class Strategy(enum.IntEnum):
241241
# Set CParameter/DParameter types for validity check
242242
_zstd._set_parameter_types(CParameter, DParameter)
243243

244-
zstd_support_multithread = CParameter.nbWorkers.bounds() != (0, 0)
244+
zstd_support_multithread = CParameter.nb_workers.bounds() != (0, 0)

Lib/test/test_zstd/test_core.py

Lines changed: 59 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def setUpModule():
7373
DAT_130K_D = bytes([random.randint(0, 127) for _ in range(130*_1K)])
7474

7575
global DAT_130K_C
76-
DAT_130K_C = compress(DAT_130K_D, options={CParameter.checksumFlag:1})
76+
DAT_130K_C = compress(DAT_130K_D, options={CParameter.checksum_flag:1})
7777

7878
global DECOMPRESSED_DAT
7979
DECOMPRESSED_DAT = b'abcdefg123456' * 1000
@@ -131,7 +131,7 @@ def test_version(self):
131131
self.assertEqual(s, zstd_version)
132132

133133
def test_compressionLevel_values(self):
134-
min, max = CParameter.compressionLevel.bounds()
134+
min, max = CParameter.compression_level.bounds()
135135
self.assertIs(type(COMPRESSION_LEVEL_DEFAULT), int)
136136
self.assertIs(type(min), int)
137137
self.assertIs(type(max), int)
@@ -145,7 +145,7 @@ def test_roundtrip_default(self):
145145

146146
def test_roundtrip_level(self):
147147
raw_dat = THIS_FILE_BYTES[: len(THIS_FILE_BYTES) // 6]
148-
level_min, level_max = CParameter.compressionLevel.bounds()
148+
level_min, level_max = CParameter.compression_level.bounds()
149149

150150
for level in range(max(-20, level_min), level_max + 1):
151151
dat1 = compress(raw_dat, level)
@@ -201,7 +201,7 @@ def test_simple_compress_bad_args(self):
201201
ZstdCompressor(options={2**31: 100})
202202

203203
with self.assertRaises(ZstdError):
204-
ZstdCompressor(options={CParameter.windowLog: 100})
204+
ZstdCompressor(options={CParameter.window_log: 100})
205205
with self.assertRaises(ZstdError):
206206
ZstdCompressor(options={3333: 100})
207207

@@ -227,65 +227,65 @@ def test_simple_compress_bad_args(self):
227227
zc.flush(zc.FLUSH_FRAME)
228228

229229
def test_compress_parameters(self):
230-
d = {CParameter.compressionLevel : 10,
231-
232-
CParameter.windowLog : 12,
233-
CParameter.hashLog : 10,
234-
CParameter.chainLog : 12,
235-
CParameter.searchLog : 12,
236-
CParameter.minMatch : 4,
237-
CParameter.targetLength : 12,
230+
d = {CParameter.compression_level : 10,
231+
232+
CParameter.window_log : 12,
233+
CParameter.hash_log : 10,
234+
CParameter.chain_log : 12,
235+
CParameter.search_log : 12,
236+
CParameter.min_match : 4,
237+
CParameter.target_length : 12,
238238
CParameter.strategy : Strategy.lazy,
239239

240-
CParameter.enableLongDistanceMatching : 1,
241-
CParameter.ldmHashLog : 12,
242-
CParameter.ldmMinMatch : 11,
243-
CParameter.ldmBucketSizeLog : 5,
244-
CParameter.ldmHashRateLog : 12,
240+
CParameter.enable_long_distance_matching : 1,
241+
CParameter.ldm_hash_log : 12,
242+
CParameter.ldm_min_match : 11,
243+
CParameter.ldm_bucket_size_log : 5,
244+
CParameter.ldm_hash_rate_log : 12,
245245

246-
CParameter.contentSizeFlag : 1,
247-
CParameter.checksumFlag : 1,
248-
CParameter.dictIDFlag : 0,
246+
CParameter.content_size_flag : 1,
247+
CParameter.checksum_flag : 1,
248+
CParameter.dict_id_flag : 0,
249249

250-
CParameter.nbWorkers : 2 if zstd_support_multithread else 0,
251-
CParameter.jobSize : 5*_1M if zstd_support_multithread else 0,
252-
CParameter.overlapLog : 9 if zstd_support_multithread else 0,
250+
CParameter.nb_workers : 2 if zstd_support_multithread else 0,
251+
CParameter.job_size : 5*_1M if zstd_support_multithread else 0,
252+
CParameter.overlap_log : 9 if zstd_support_multithread else 0,
253253
}
254254
ZstdCompressor(options=d)
255255

256256
# larger than signed int, ValueError
257257
d1 = d.copy()
258-
d1[CParameter.ldmBucketSizeLog] = 2**31
258+
d1[CParameter.ldm_bucket_size_log] = 2**31
259259
self.assertRaises(ValueError, ZstdCompressor, d1)
260260

261261
# clamp compressionLevel
262-
level_min, level_max = CParameter.compressionLevel.bounds()
262+
level_min, level_max = CParameter.compression_level.bounds()
263263
compress(b'', level_max+1)
264264
compress(b'', level_min-1)
265265

266-
compress(b'', {CParameter.compressionLevel:level_max+1})
267-
compress(b'', {CParameter.compressionLevel:level_min-1})
266+
compress(b'', {CParameter.compression_level:level_max+1})
267+
compress(b'', {CParameter.compression_level:level_min-1})
268268

269269
# zstd lib doesn't support MT compression
270270
if not zstd_support_multithread:
271271
with self.assertRaises(ZstdError):
272-
ZstdCompressor({CParameter.nbWorkers:4})
272+
ZstdCompressor({CParameter.nb_workers:4})
273273
with self.assertRaises(ZstdError):
274-
ZstdCompressor({CParameter.jobSize:4})
274+
ZstdCompressor({CParameter.job_size:4})
275275
with self.assertRaises(ZstdError):
276-
ZstdCompressor({CParameter.overlapLog:4})
276+
ZstdCompressor({CParameter.overlap_log:4})
277277

278278
# out of bounds error msg
279-
option = {CParameter.windowLog:100}
279+
option = {CParameter.window_log:100}
280280
with self.assertRaisesRegex(ZstdError,
281-
(r'Error when setting zstd compression parameter "windowLog", '
281+
(r'Error when setting zstd compression parameter "window_log", '
282282
r'it should \d+ <= value <= \d+, provided value is 100\. '
283283
r'\(zstd v\d\.\d\.\d, (?:32|64)-bit build\)')):
284284
compress(b'', option)
285285

286286
def test_unknown_compression_parameter(self):
287287
KEY = 100001234
288-
option = {CParameter.compressionLevel: 10,
288+
option = {CParameter.compression_level: 10,
289289
KEY: 200000000}
290290
pattern = r'Zstd compression parameter.*?"unknown parameter \(key %d\)"' \
291291
% KEY
@@ -298,8 +298,8 @@ def test_zstd_multithread_compress(self):
298298
size = 40*_1M
299299
b = THIS_FILE_BYTES * (size // len(THIS_FILE_BYTES))
300300

301-
options = {CParameter.compressionLevel : 4,
302-
CParameter.nbWorkers : 2}
301+
options = {CParameter.compression_level : 4,
302+
CParameter.nb_workers : 2}
303303

304304
# compress()
305305
dat1 = compress(b, options=options)
@@ -388,7 +388,7 @@ def test_simple_decompress_bad_args(self):
388388
ZstdDecompressor(options={2**31 : 100})
389389

390390
with self.assertRaises(ZstdError):
391-
ZstdDecompressor(options={DParameter.windowLogMax:100})
391+
ZstdDecompressor(options={DParameter.window_log_max:100})
392392
with self.assertRaises(ZstdError):
393393
ZstdDecompressor(options={3333 : 100})
394394

@@ -400,25 +400,25 @@ def test_simple_decompress_bad_args(self):
400400
lzd.decompress(empty)
401401

402402
def test_decompress_parameters(self):
403-
d = {DParameter.windowLogMax : 15}
403+
d = {DParameter.window_log_max : 15}
404404
ZstdDecompressor(options=d)
405405

406406
# larger than signed int, ValueError
407407
d1 = d.copy()
408-
d1[DParameter.windowLogMax] = 2**31
408+
d1[DParameter.window_log_max] = 2**31
409409
self.assertRaises(ValueError, ZstdDecompressor, None, d1)
410410

411411
# out of bounds error msg
412-
options = {DParameter.windowLogMax:100}
412+
options = {DParameter.window_log_max:100}
413413
with self.assertRaisesRegex(ZstdError,
414-
(r'Error when setting zstd decompression parameter "windowLogMax", '
414+
(r'Error when setting zstd decompression parameter "window_log_max", '
415415
r'it should \d+ <= value <= \d+, provided value is 100\. '
416416
r'\(zstd v\d\.\d\.\d, (?:32|64)-bit build\)')):
417417
decompress(b'', options=options)
418418

419419
def test_unknown_decompression_parameter(self):
420420
KEY = 100001234
421-
options = {DParameter.windowLogMax: DParameter.windowLogMax.bounds()[1],
421+
options = {DParameter.window_log_max: DParameter.window_log_max.bounds()[1],
422422
KEY: 200000000}
423423
pattern = r'Zstd decompression parameter.*?"unknown parameter \(key %d\)"' \
424424
% KEY
@@ -517,7 +517,7 @@ def test_decompressor_arg(self):
517517

518518
ZstdDecompressor()
519519
ZstdDecompressor(zd, {})
520-
ZstdDecompressor(zstd_dict=zd, options={DParameter.windowLogMax:25})
520+
ZstdDecompressor(zstd_dict=zd, options={DParameter.window_log_max:25})
521521

522522
def test_decompressor_1(self):
523523
# empty
@@ -662,7 +662,7 @@ class DecompressorFlagsTestCase(unittest.TestCase):
662662

663663
@classmethod
664664
def setUpClass(cls):
665-
options = {CParameter.checksumFlag:1}
665+
options = {CParameter.checksum_flag:1}
666666
c = ZstdCompressor(options)
667667

668668
cls.DECOMPRESSED_42 = b'a'*42
@@ -1294,9 +1294,9 @@ def test_as_digested_dict(self):
12941294
zd.as_undigested_dict = b'1234'
12951295

12961296
def test_advanced_compression_parameters(self):
1297-
options = {CParameter.compressionLevel: 6,
1298-
CParameter.windowLog: 20,
1299-
CParameter.enableLongDistanceMatching: 1}
1297+
options = {CParameter.compression_level: 6,
1298+
CParameter.window_log: 20,
1299+
CParameter.enable_long_distance_matching: 1}
13001300

13011301
# automatically select
13021302
dat = compress(SAMPLES[0], options=options, zstd_dict=TRAINED_DICT)
@@ -1327,14 +1327,14 @@ def test_init(self):
13271327

13281328
with ZstdFile(io.BytesIO(), "w", level=12) as f:
13291329
pass
1330-
with ZstdFile(io.BytesIO(), "w", options={CParameter.checksumFlag:1}) as f:
1330+
with ZstdFile(io.BytesIO(), "w", options={CParameter.checksum_flag:1}) as f:
13311331
pass
13321332
with ZstdFile(io.BytesIO(), "w", options={}) as f:
13331333
pass
13341334
with ZstdFile(io.BytesIO(), "w", level=20, zstd_dict=TRAINED_DICT) as f:
13351335
pass
13361336

1337-
with ZstdFile(io.BytesIO(), "r", options={DParameter.windowLogMax:25}) as f:
1337+
with ZstdFile(io.BytesIO(), "r", options={DParameter.window_log_max:25}) as f:
13381338
pass
13391339
with ZstdFile(io.BytesIO(), "r", options={}, zstd_dict=TRAINED_DICT) as f:
13401340
pass
@@ -1421,9 +1421,9 @@ def test_init_bad_mode(self):
14211421
ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB), "rw")
14221422

14231423
with self.assertRaisesRegex(TypeError, r"NOT be CParameter"):
1424-
ZstdFile(io.BytesIO(), 'rb', options={CParameter.compressionLevel:5})
1424+
ZstdFile(io.BytesIO(), 'rb', options={CParameter.compression_level:5})
14251425
with self.assertRaisesRegex(TypeError, r"NOT be DParameter"):
1426-
ZstdFile(io.BytesIO(), 'wb', options={DParameter.windowLogMax:21})
1426+
ZstdFile(io.BytesIO(), 'wb', options={DParameter.window_log_max:21})
14271427

14281428
with self.assertRaises(TypeError):
14291429
ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB), "r", level=12)
@@ -1435,14 +1435,14 @@ def test_init_bad_check(self):
14351435
with self.assertRaises(ZstdError):
14361436
ZstdFile(io.BytesIO(), "w", options={999:9999})
14371437
with self.assertRaises(ZstdError):
1438-
ZstdFile(io.BytesIO(), "w", options={CParameter.windowLog:99})
1438+
ZstdFile(io.BytesIO(), "w", options={CParameter.window_log:99})
14391439

14401440
with self.assertRaises(TypeError):
14411441
ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB), "r", options=33)
14421442

14431443
with self.assertRaises(ValueError):
14441444
ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB),
1445-
options={DParameter.windowLogMax:2**31})
1445+
options={DParameter.window_log_max:2**31})
14461446

14471447
with self.assertRaises(ZstdError):
14481448
ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB),
@@ -1605,7 +1605,7 @@ def test_read_0(self):
16051605
self.assertEqual(f.read(0), b"")
16061606
self.assertEqual(f.read(), DECOMPRESSED_100_PLUS_32KB)
16071607
with ZstdFile(io.BytesIO(COMPRESSED_100_PLUS_32KB),
1608-
options={DParameter.windowLogMax:20}) as f:
1608+
options={DParameter.window_log_max:20}) as f:
16091609
self.assertEqual(f.read(0), b"")
16101610

16111611
# empty file
@@ -1820,16 +1820,16 @@ def test_write(self):
18201820
self.assertEqual(dst.getvalue(), expected)
18211821

18221822
with io.BytesIO() as dst:
1823-
with ZstdFile(dst, "w", options={CParameter.checksumFlag:1}) as f:
1823+
with ZstdFile(dst, "w", options={CParameter.checksum_flag:1}) as f:
18241824
f.write(raw_data)
18251825

1826-
comp = ZstdCompressor({CParameter.checksumFlag:1})
1826+
comp = ZstdCompressor({CParameter.checksum_flag:1})
18271827
expected = comp.compress(raw_data) + comp.flush()
18281828
self.assertEqual(dst.getvalue(), expected)
18291829

18301830
with io.BytesIO() as dst:
1831-
options = {CParameter.compressionLevel:-5,
1832-
CParameter.checksumFlag:1}
1831+
options = {CParameter.compression_level:-5,
1832+
CParameter.checksum_flag:1}
18331833
with ZstdFile(dst, "w",
18341834
options=options) as f:
18351835
f.write(raw_data)
@@ -2288,11 +2288,11 @@ def test_bad_params(self):
22882288
os.remove(TESTFN)
22892289

22902290
def test_option(self):
2291-
options = {DParameter.windowLogMax:25}
2291+
options = {DParameter.window_log_max:25}
22922292
with open(io.BytesIO(COMPRESSED_100_PLUS_32KB), "rb", options=options) as f:
22932293
self.assertEqual(f.read(), DECOMPRESSED_100_PLUS_32KB)
22942294

2295-
options = {CParameter.compressionLevel:12}
2295+
options = {CParameter.compression_level:12}
22962296
with io.BytesIO() as bio:
22972297
with open(bio, "wb", options=options) as f:
22982298
f.write(DECOMPRESSED_100_PLUS_32KB)

0 commit comments

Comments
 (0)