comparison cutils/util/__init__.py @ 188:2784fdcc99e5

Implement basic parsing of treesum output. Including CRC32 checks.
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 15 Jan 2025 14:41:36 +0100
parents f04d4b1c14b3
children 0f4febf646f5
comparison
equal deleted inserted replaced
187:7b41cd8692fc 188:2784fdcc99e5
7 7
8 """ 8 """
9 9
10 __all__ = ["PY2", 10 __all__ = ["PY2",
11 "PY35", 11 "PY35",
12 "n", "b", "u",
12 "normalize_filename", 13 "normalize_filename",
13 "argv2algo", 14 "argv2algo",
14 "algotag2algotype", 15 "algotag2algotype",
15 "get_blake2b", 16 "get_blake2b",
16 "get_blake2b_256", 17 "get_blake2b_256",
17 "get_blake2s", 18 "get_blake2s",
18 "default_algotag", 19 "default_algotag",
19 "fsencode", 20 "fsencode",
21 "interpolate_bytes",
20 ] 22 ]
21 23
22 24
23 import argparse 25 import argparse
24 import hashlib 26 import hashlib
26 import sys 28 import sys
27 29
28 30
29 PY2 = sys.version_info[0] < 3 31 PY2 = sys.version_info[0] < 3
30 PY35 = sys.version_info[:2] >= (3, 5) 32 PY35 = sys.version_info[:2] >= (3, 5)
33
34
35 if PY2:
36
37 def n(s, encoding="ascii"):
38 """Convert `s` to the native string implementation"""
39 if isinstance(s, unicode): # noqa: F821 undefined name 'unicode'
40 return s.encode(encoding)
41 return s
42
43 def b(s, encoding="ascii"):
44 """Convert `s` to bytes"""
45 if isinstance(s, unicode): # noqa: F821 undefined name 'unicode'
46 return s.encode(encoding)
47 return s
48
49 def u(s, encoding="ascii"):
50 """Convert `s` to a unicode string"""
51 if isinstance(s, str):
52 return s.decode(encoding)
53 return s
54
55 else:
56
57 def n(s, encoding="ascii"):
58 """Convert `s` to the native string implementation"""
59 if isinstance(s, (bytes, bytearray)):
60 return s.decode(encoding)
61 return s
62
63 def b(s, encoding="ascii"):
64 """Convert `s` to bytes"""
65 if isinstance(s, str):
66 return s.encode(encoding)
67 return s
68
69 u = n
31 70
32 71
33 def default_algotag(): 72 def default_algotag():
34 """Determine the "best" default algorithm. 73 """Determine the "best" default algorithm.
35 74