hexconv 0.2.3__tar.gz → 0.2.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hexconv-0.2.3/src/hexconv.egg-info → hexconv-0.2.4}/PKG-INFO +50 -13
- {hexconv-0.2.3 → hexconv-0.2.4}/README.md +49 -12
- {hexconv-0.2.3 → hexconv-0.2.4}/pyproject.toml +1 -1
- {hexconv-0.2.3 → hexconv-0.2.4/src/hexconv.egg-info}/PKG-INFO +50 -13
- {hexconv-0.2.3 → hexconv-0.2.4}/tests/test_hexconv.py +1 -0
- {hexconv-0.2.3 → hexconv-0.2.4}/LICENSE +0 -0
- {hexconv-0.2.3 → hexconv-0.2.4}/MANIFEST.in +0 -0
- {hexconv-0.2.3 → hexconv-0.2.4}/setup.cfg +0 -0
- {hexconv-0.2.3 → hexconv-0.2.4}/src/hexconv/__init__.py +0 -0
- {hexconv-0.2.3 → hexconv-0.2.4}/src/hexconv/_core.py +0 -0
- {hexconv-0.2.3 → hexconv-0.2.4}/src/hexconv/py.typed +0 -0
- {hexconv-0.2.3 → hexconv-0.2.4}/src/hexconv.egg-info/SOURCES.txt +0 -0
- {hexconv-0.2.3 → hexconv-0.2.4}/src/hexconv.egg-info/dependency_links.txt +0 -0
- {hexconv-0.2.3 → hexconv-0.2.4}/src/hexconv.egg-info/requires.txt +0 -0
- {hexconv-0.2.3 → hexconv-0.2.4}/src/hexconv.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hexconv
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Pythonic conversion toolkit for bytes, hex, integers, arrays, binary strings, base64, and text.
|
|
5
5
|
Author: hexconv contributors
|
|
6
6
|
License-Expression: MIT
|
|
@@ -41,33 +41,67 @@ It is built around ergonomic one-liners and composable format objects.
|
|
|
41
41
|
pip install hexconv
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## Fast compose
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
The intended interface is small pieces snapped together:
|
|
47
|
+
`source format >> optional transforms >> target format`.
|
|
47
48
|
|
|
48
49
|
```python
|
|
49
50
|
import hexconv as hx
|
|
50
51
|
|
|
51
|
-
hx.
|
|
52
|
+
to_bytes = hx.Hex() >> hx.Bytes()
|
|
53
|
+
to_bytes("de ad be ef")
|
|
52
54
|
# b'\xde\xad\xbe\xef'
|
|
53
55
|
|
|
54
|
-
hx.
|
|
55
|
-
|
|
56
|
+
spaced_hex = hx.Bytes() >> hx.Hex(sep=" ")
|
|
57
|
+
spaced_hex(b"\xde\xad\xbe\xef")
|
|
58
|
+
# 'de ad be ef'
|
|
56
59
|
|
|
57
|
-
hx.
|
|
58
|
-
|
|
60
|
+
words = hx.Hex(sep=" ") >> hx.Chunk(2) >> hx.IntArray(width=2)
|
|
61
|
+
words("12 34 56 78")
|
|
62
|
+
# [4660, 22136]
|
|
59
63
|
|
|
60
|
-
hx.
|
|
61
|
-
|
|
64
|
+
text_to_urlsafe = hx.Text() >> hx.Base64(urlsafe=True, padding=False)
|
|
65
|
+
text_to_urlsafe("data")
|
|
66
|
+
# 'ZGF0YQ'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Hex input accepts common separators, so spaced or copied hex usually does not
|
|
70
|
+
need manual cleanup before conversion. `Hex(sep=" ")` is also how you emit
|
|
71
|
+
space-separated hex.
|
|
72
|
+
|
|
73
|
+
## Quick tour
|
|
74
|
+
|
|
75
|
+
Use direct helpers when you want one obvious conversion across many
|
|
76
|
+
representations:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
hx.from_hex("de ad be ef").bytes
|
|
80
|
+
# b'\xde\xad\xbe\xef'
|
|
62
81
|
|
|
63
82
|
hx.from_text("data").to_hex_array(prefix=True)
|
|
64
83
|
# ['0x64', '0x61', '0x74', '0x61']
|
|
65
84
|
|
|
66
|
-
hx.from_int(0xdeadbeef).
|
|
85
|
+
hx.from_int(0xdeadbeef).bytes
|
|
67
86
|
# b'\xde\xad\xbe\xef'
|
|
68
87
|
|
|
69
88
|
hx.from_int_array([0x1234, 0x5678], width=2).to_hex_array(width=2)
|
|
70
89
|
# ['1234', '5678']
|
|
90
|
+
|
|
91
|
+
hx.from_binary("01100100 01100001 01110100 01100001").text
|
|
92
|
+
# 'data'
|
|
93
|
+
|
|
94
|
+
hx.from_base64("ZGF0YQ==").text
|
|
95
|
+
# 'data'
|
|
96
|
+
|
|
97
|
+
hx.from_escaped(r"\xde\xad").hex
|
|
98
|
+
# 'dead'
|
|
99
|
+
|
|
100
|
+
hx.from_struct((0x1234, 0x5678), fmt=">HH").hex
|
|
101
|
+
# '12345678'
|
|
102
|
+
|
|
103
|
+
hx.from_bits("101", pad=True).hex
|
|
104
|
+
# '05'
|
|
71
105
|
```
|
|
72
106
|
|
|
73
107
|
Use `from_auto` when you want a quick best-effort parse:
|
|
@@ -88,7 +122,7 @@ hx.from_auto([0xde, 0xad, 0xbe, 0xef]).to(hx.Hex(prefix=True))
|
|
|
88
122
|
`hexconv` is built around small format objects. A format can parse directly:
|
|
89
123
|
|
|
90
124
|
```python
|
|
91
|
-
hx.Hex()("
|
|
125
|
+
hx.Hex()("de ad be ef").bytes
|
|
92
126
|
# b'\xde\xad\xbe\xef'
|
|
93
127
|
|
|
94
128
|
hx.Text()("data").hex
|
|
@@ -98,7 +132,7 @@ hx.Int(width=4, endian="little")(0x12345678).hex
|
|
|
98
132
|
# '78563412'
|
|
99
133
|
```
|
|
100
134
|
|
|
101
|
-
Formats compose with
|
|
135
|
+
Formats compose with `>>`, so reusable converters are normal Python objects:
|
|
102
136
|
|
|
103
137
|
```python
|
|
104
138
|
to_text = hx.HexArray() >> hx.Text()
|
|
@@ -148,6 +182,9 @@ Use `convert` when you want an explicit source and target in one expression:
|
|
|
148
182
|
hx.convert("de ad be ef", hx.Hex(sep=" "), hx.Bytes())
|
|
149
183
|
# b'\xde\xad\xbe\xef'
|
|
150
184
|
|
|
185
|
+
hx.convert(b"\xde\xad\xbe\xef", hx.Bytes(), hx.Hex(sep=" "))
|
|
186
|
+
# 'de ad be ef'
|
|
187
|
+
|
|
151
188
|
hx.convert("data", hx.Text(), hx.Hex(prefix=True))
|
|
152
189
|
# '0x64617461'
|
|
153
190
|
|
|
@@ -12,33 +12,67 @@ It is built around ergonomic one-liners and composable format objects.
|
|
|
12
12
|
pip install hexconv
|
|
13
13
|
```
|
|
14
14
|
|
|
15
|
-
##
|
|
15
|
+
## Fast compose
|
|
16
16
|
|
|
17
|
-
|
|
17
|
+
The intended interface is small pieces snapped together:
|
|
18
|
+
`source format >> optional transforms >> target format`.
|
|
18
19
|
|
|
19
20
|
```python
|
|
20
21
|
import hexconv as hx
|
|
21
22
|
|
|
22
|
-
hx.
|
|
23
|
+
to_bytes = hx.Hex() >> hx.Bytes()
|
|
24
|
+
to_bytes("de ad be ef")
|
|
23
25
|
# b'\xde\xad\xbe\xef'
|
|
24
26
|
|
|
25
|
-
hx.
|
|
26
|
-
|
|
27
|
+
spaced_hex = hx.Bytes() >> hx.Hex(sep=" ")
|
|
28
|
+
spaced_hex(b"\xde\xad\xbe\xef")
|
|
29
|
+
# 'de ad be ef'
|
|
27
30
|
|
|
28
|
-
hx.
|
|
29
|
-
|
|
31
|
+
words = hx.Hex(sep=" ") >> hx.Chunk(2) >> hx.IntArray(width=2)
|
|
32
|
+
words("12 34 56 78")
|
|
33
|
+
# [4660, 22136]
|
|
30
34
|
|
|
31
|
-
hx.
|
|
32
|
-
|
|
35
|
+
text_to_urlsafe = hx.Text() >> hx.Base64(urlsafe=True, padding=False)
|
|
36
|
+
text_to_urlsafe("data")
|
|
37
|
+
# 'ZGF0YQ'
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Hex input accepts common separators, so spaced or copied hex usually does not
|
|
41
|
+
need manual cleanup before conversion. `Hex(sep=" ")` is also how you emit
|
|
42
|
+
space-separated hex.
|
|
43
|
+
|
|
44
|
+
## Quick tour
|
|
45
|
+
|
|
46
|
+
Use direct helpers when you want one obvious conversion across many
|
|
47
|
+
representations:
|
|
48
|
+
|
|
49
|
+
```python
|
|
50
|
+
hx.from_hex("de ad be ef").bytes
|
|
51
|
+
# b'\xde\xad\xbe\xef'
|
|
33
52
|
|
|
34
53
|
hx.from_text("data").to_hex_array(prefix=True)
|
|
35
54
|
# ['0x64', '0x61', '0x74', '0x61']
|
|
36
55
|
|
|
37
|
-
hx.from_int(0xdeadbeef).
|
|
56
|
+
hx.from_int(0xdeadbeef).bytes
|
|
38
57
|
# b'\xde\xad\xbe\xef'
|
|
39
58
|
|
|
40
59
|
hx.from_int_array([0x1234, 0x5678], width=2).to_hex_array(width=2)
|
|
41
60
|
# ['1234', '5678']
|
|
61
|
+
|
|
62
|
+
hx.from_binary("01100100 01100001 01110100 01100001").text
|
|
63
|
+
# 'data'
|
|
64
|
+
|
|
65
|
+
hx.from_base64("ZGF0YQ==").text
|
|
66
|
+
# 'data'
|
|
67
|
+
|
|
68
|
+
hx.from_escaped(r"\xde\xad").hex
|
|
69
|
+
# 'dead'
|
|
70
|
+
|
|
71
|
+
hx.from_struct((0x1234, 0x5678), fmt=">HH").hex
|
|
72
|
+
# '12345678'
|
|
73
|
+
|
|
74
|
+
hx.from_bits("101", pad=True).hex
|
|
75
|
+
# '05'
|
|
42
76
|
```
|
|
43
77
|
|
|
44
78
|
Use `from_auto` when you want a quick best-effort parse:
|
|
@@ -59,7 +93,7 @@ hx.from_auto([0xde, 0xad, 0xbe, 0xef]).to(hx.Hex(prefix=True))
|
|
|
59
93
|
`hexconv` is built around small format objects. A format can parse directly:
|
|
60
94
|
|
|
61
95
|
```python
|
|
62
|
-
hx.Hex()("
|
|
96
|
+
hx.Hex()("de ad be ef").bytes
|
|
63
97
|
# b'\xde\xad\xbe\xef'
|
|
64
98
|
|
|
65
99
|
hx.Text()("data").hex
|
|
@@ -69,7 +103,7 @@ hx.Int(width=4, endian="little")(0x12345678).hex
|
|
|
69
103
|
# '78563412'
|
|
70
104
|
```
|
|
71
105
|
|
|
72
|
-
Formats compose with
|
|
106
|
+
Formats compose with `>>`, so reusable converters are normal Python objects:
|
|
73
107
|
|
|
74
108
|
```python
|
|
75
109
|
to_text = hx.HexArray() >> hx.Text()
|
|
@@ -119,6 +153,9 @@ Use `convert` when you want an explicit source and target in one expression:
|
|
|
119
153
|
hx.convert("de ad be ef", hx.Hex(sep=" "), hx.Bytes())
|
|
120
154
|
# b'\xde\xad\xbe\xef'
|
|
121
155
|
|
|
156
|
+
hx.convert(b"\xde\xad\xbe\xef", hx.Bytes(), hx.Hex(sep=" "))
|
|
157
|
+
# 'de ad be ef'
|
|
158
|
+
|
|
122
159
|
hx.convert("data", hx.Text(), hx.Hex(prefix=True))
|
|
123
160
|
# '0x64617461'
|
|
124
161
|
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "hexconv"
|
|
7
|
-
version = "0.2.
|
|
7
|
+
version = "0.2.4"
|
|
8
8
|
description = "Pythonic conversion toolkit for bytes, hex, integers, arrays, binary strings, base64, and text."
|
|
9
9
|
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
10
|
requires-python = ">=3.10"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hexconv
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.4
|
|
4
4
|
Summary: Pythonic conversion toolkit for bytes, hex, integers, arrays, binary strings, base64, and text.
|
|
5
5
|
Author: hexconv contributors
|
|
6
6
|
License-Expression: MIT
|
|
@@ -41,33 +41,67 @@ It is built around ergonomic one-liners and composable format objects.
|
|
|
41
41
|
pip install hexconv
|
|
42
42
|
```
|
|
43
43
|
|
|
44
|
-
##
|
|
44
|
+
## Fast compose
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
The intended interface is small pieces snapped together:
|
|
47
|
+
`source format >> optional transforms >> target format`.
|
|
47
48
|
|
|
48
49
|
```python
|
|
49
50
|
import hexconv as hx
|
|
50
51
|
|
|
51
|
-
hx.
|
|
52
|
+
to_bytes = hx.Hex() >> hx.Bytes()
|
|
53
|
+
to_bytes("de ad be ef")
|
|
52
54
|
# b'\xde\xad\xbe\xef'
|
|
53
55
|
|
|
54
|
-
hx.
|
|
55
|
-
|
|
56
|
+
spaced_hex = hx.Bytes() >> hx.Hex(sep=" ")
|
|
57
|
+
spaced_hex(b"\xde\xad\xbe\xef")
|
|
58
|
+
# 'de ad be ef'
|
|
56
59
|
|
|
57
|
-
hx.
|
|
58
|
-
|
|
60
|
+
words = hx.Hex(sep=" ") >> hx.Chunk(2) >> hx.IntArray(width=2)
|
|
61
|
+
words("12 34 56 78")
|
|
62
|
+
# [4660, 22136]
|
|
59
63
|
|
|
60
|
-
hx.
|
|
61
|
-
|
|
64
|
+
text_to_urlsafe = hx.Text() >> hx.Base64(urlsafe=True, padding=False)
|
|
65
|
+
text_to_urlsafe("data")
|
|
66
|
+
# 'ZGF0YQ'
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
Hex input accepts common separators, so spaced or copied hex usually does not
|
|
70
|
+
need manual cleanup before conversion. `Hex(sep=" ")` is also how you emit
|
|
71
|
+
space-separated hex.
|
|
72
|
+
|
|
73
|
+
## Quick tour
|
|
74
|
+
|
|
75
|
+
Use direct helpers when you want one obvious conversion across many
|
|
76
|
+
representations:
|
|
77
|
+
|
|
78
|
+
```python
|
|
79
|
+
hx.from_hex("de ad be ef").bytes
|
|
80
|
+
# b'\xde\xad\xbe\xef'
|
|
62
81
|
|
|
63
82
|
hx.from_text("data").to_hex_array(prefix=True)
|
|
64
83
|
# ['0x64', '0x61', '0x74', '0x61']
|
|
65
84
|
|
|
66
|
-
hx.from_int(0xdeadbeef).
|
|
85
|
+
hx.from_int(0xdeadbeef).bytes
|
|
67
86
|
# b'\xde\xad\xbe\xef'
|
|
68
87
|
|
|
69
88
|
hx.from_int_array([0x1234, 0x5678], width=2).to_hex_array(width=2)
|
|
70
89
|
# ['1234', '5678']
|
|
90
|
+
|
|
91
|
+
hx.from_binary("01100100 01100001 01110100 01100001").text
|
|
92
|
+
# 'data'
|
|
93
|
+
|
|
94
|
+
hx.from_base64("ZGF0YQ==").text
|
|
95
|
+
# 'data'
|
|
96
|
+
|
|
97
|
+
hx.from_escaped(r"\xde\xad").hex
|
|
98
|
+
# 'dead'
|
|
99
|
+
|
|
100
|
+
hx.from_struct((0x1234, 0x5678), fmt=">HH").hex
|
|
101
|
+
# '12345678'
|
|
102
|
+
|
|
103
|
+
hx.from_bits("101", pad=True).hex
|
|
104
|
+
# '05'
|
|
71
105
|
```
|
|
72
106
|
|
|
73
107
|
Use `from_auto` when you want a quick best-effort parse:
|
|
@@ -88,7 +122,7 @@ hx.from_auto([0xde, 0xad, 0xbe, 0xef]).to(hx.Hex(prefix=True))
|
|
|
88
122
|
`hexconv` is built around small format objects. A format can parse directly:
|
|
89
123
|
|
|
90
124
|
```python
|
|
91
|
-
hx.Hex()("
|
|
125
|
+
hx.Hex()("de ad be ef").bytes
|
|
92
126
|
# b'\xde\xad\xbe\xef'
|
|
93
127
|
|
|
94
128
|
hx.Text()("data").hex
|
|
@@ -98,7 +132,7 @@ hx.Int(width=4, endian="little")(0x12345678).hex
|
|
|
98
132
|
# '78563412'
|
|
99
133
|
```
|
|
100
134
|
|
|
101
|
-
Formats compose with
|
|
135
|
+
Formats compose with `>>`, so reusable converters are normal Python objects:
|
|
102
136
|
|
|
103
137
|
```python
|
|
104
138
|
to_text = hx.HexArray() >> hx.Text()
|
|
@@ -148,6 +182,9 @@ Use `convert` when you want an explicit source and target in one expression:
|
|
|
148
182
|
hx.convert("de ad be ef", hx.Hex(sep=" "), hx.Bytes())
|
|
149
183
|
# b'\xde\xad\xbe\xef'
|
|
150
184
|
|
|
185
|
+
hx.convert(b"\xde\xad\xbe\xef", hx.Bytes(), hx.Hex(sep=" "))
|
|
186
|
+
# 'de ad be ef'
|
|
187
|
+
|
|
151
188
|
hx.convert("data", hx.Text(), hx.Hex(prefix=True))
|
|
152
189
|
# '0x64617461'
|
|
153
190
|
|
|
@@ -46,6 +46,7 @@ def test_converter_class_matches_proposed_usage():
|
|
|
46
46
|
def test_convert_one_shot():
|
|
47
47
|
assert hx.convert("data", from_=hx.Text, to=hx.HexString) == "64617461"
|
|
48
48
|
assert hx.convert("de ad be ef", hx.Hex(sep=" "), hx.Bytes()) == b"\xde\xad\xbe\xef"
|
|
49
|
+
assert hx.convert(b"\xde\xad\xbe\xef", hx.Bytes(), hx.Hex(sep=" ")) == "de ad be ef"
|
|
49
50
|
assert hx.convert("data", hx.Text(), hx.Hex(prefix=True)) == "0x64617461"
|
|
50
51
|
|
|
51
52
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|