endec 0.5.1__cp38-cp38-manylinux_2_24_armv7l.whl

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.
endec/__init__.py ADDED
@@ -0,0 +1,5 @@
1
+ from ._endec import encode, decode
2
+ from . import _endec
3
+
4
+ __doc__ = _endec.__doc__
5
+ __all__ = ["encode", "decode"]
endec/_endec.pyi ADDED
@@ -0,0 +1,20 @@
1
+ from typing import Literal
2
+
3
+ EncodeErrorHandler = Literal["strict", "xmlcharrefreplace"]
4
+ DecodeErrorHandler = Literal["strict", "replace"]
5
+ DecodeBomHandler = Literal["evaluate", "evaluateall", "strip", "ignore"]
6
+
7
+ def encode(
8
+ input_str: str,
9
+ /,
10
+ encoding: str = "utf-8",
11
+ errors: EncodeErrorHandler = "strict",
12
+ ) -> bytes: ...
13
+ def decode(
14
+ input_bytes: bytes,
15
+ /,
16
+ encoding: str = "utf-8",
17
+ errors: DecodeErrorHandler = "strict",
18
+ *,
19
+ bom: DecodeBomHandler = "evaluate",
20
+ ) -> str: ...
endec/exceptions.py ADDED
@@ -0,0 +1,44 @@
1
+ from typing import TYPE_CHECKING
2
+
3
+ if TYPE_CHECKING:
4
+ from typing import Optional
5
+
6
+
7
+ class DecodeError(UnicodeError):
8
+ encoding: str
9
+ target: bytes
10
+ reason: "Optional[str]"
11
+
12
+ def __init__(
13
+ self, encoding: str, target: bytes, reason: "Optional[str]" = None, /
14
+ ) -> None:
15
+ self.encoding = encoding
16
+ self.target = target
17
+ self.reason = reason
18
+
19
+ def __str__(self) -> str:
20
+ reason = ""
21
+ if self.reason:
22
+ reason = self.reason + "\n"
23
+
24
+ return reason + f"decoding with '{self.encoding}' codec failed"
25
+
26
+
27
+ class EncodeError(UnicodeError):
28
+ encoding: str
29
+ target: str
30
+ reason: "Optional[str]"
31
+
32
+ def __init__(
33
+ self, encoding: str, target: str, reason: "Optional[str]" = None, /
34
+ ) -> None:
35
+ self.encoding = encoding
36
+ self.target = target
37
+ self.reason = reason
38
+
39
+ def __str__(self) -> str:
40
+ reason = ""
41
+ if self.reason:
42
+ reason = self.reason + "\n"
43
+
44
+ return reason + f"encoding with '{self.encoding}' codec failed"
endec/py.typed ADDED
File without changes
@@ -0,0 +1,125 @@
1
+ Metadata-Version: 2.4
2
+ Name: endec
3
+ Version: 0.5.1
4
+ Classifier: License :: OSI Approved :: MIT License
5
+ Classifier: Intended Audience :: Developers
6
+ Classifier: Natural Language :: English
7
+ Classifier: Programming Language :: Rust
8
+ Classifier: Programming Language :: Python
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3 :: Only
11
+ Classifier: Programming Language :: Python :: 3.8
12
+ Classifier: Programming Language :: Python :: 3.9
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: Implementation :: CPython
19
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
20
+ Classifier: Topic :: Utilities
21
+ License-File: LICENSE
22
+ Summary: Web-compatible encoding and decoding library
23
+ Keywords: encoding_rs,web,codec
24
+ Author-email: Thitat Auareesuksakul <flux@thitat.net>
25
+ Requires-Python: >=3.8
26
+ Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
27
+ Project-URL: Changelog, https://github.com/fluxth/endec/releases
28
+ Project-URL: Homepage, https://github.com/fluxth/endec
29
+ Project-URL: Source, https://github.com/fluxth/endec
30
+
31
+ # endec
32
+
33
+ [![PyPI - Version](https://img.shields.io/pypi/v/endec)](https://pypi.org/project/endec/)
34
+ ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/endec)
35
+ ![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/fluxth/endec/build.yml)
36
+ ![GitHub Workflow Status (with event)](https://img.shields.io/github/actions/workflow/status/fluxth/endec/test.yml?label=tests)
37
+
38
+ Web-compatible **en**coding and **dec**oding library
39
+
40
+ **endec** uses [`encoding_rs`](https://github.com/hsivonen/encoding_rs) (which powers Firefox) under the hood.
41
+
42
+ ## Supported Python versions
43
+
44
+ - CPython 3.8 or higher
45
+ - PyPy 3.11 or higher
46
+
47
+ ## Installation
48
+
49
+ ### Using [uv package manager](https://github.com/astral-sh/uv) (recommended)
50
+
51
+ ```bash
52
+ uv add endec
53
+ ```
54
+
55
+ ### Using [Poetry package manager](https://github.com/python-poetry/poetry)
56
+
57
+ ```bash
58
+ poetry add endec
59
+ ```
60
+
61
+ ### Using pip
62
+
63
+ ```bash
64
+ pip install endec
65
+ ```
66
+
67
+ ## Examples
68
+
69
+ ### Codecs
70
+
71
+ Please refer to [WHATWG Web Encoding Standard](https://encoding.spec.whatwg.org/#concept-encoding-get) for available codecs.
72
+
73
+ ### Encode
74
+
75
+ ```python
76
+ import endec
77
+
78
+ utf8_bytes = endec.encode("こんにちは")
79
+ assert utf8_bytes == b"\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf"
80
+
81
+ iso2022jp_bytes = endec.encode("㊤㊥㊦", "iso-2022-jp")
82
+ assert iso2022jp_bytes == b"\x1b$B-e-f-g\x1b(B"
83
+
84
+ "㊤㊥㊦".encode("iso-2022-jp") # Standard Library `encode`
85
+ # UnicodeEncodeError: 'iso2022_jp' codec can't encode character '\u32a4' in position 0: illegal multibyte sequence
86
+ ```
87
+
88
+ ### Decode
89
+
90
+ ```python
91
+ import endec
92
+
93
+ utf8_str = endec.decode(b"\xe3\x81\x93\xe3\x82\x93\xe3\x81\xab\xe3\x81\xa1\xe3\x81\xaf")
94
+ assert utf8_str == "こんにちは"
95
+
96
+ iso2022jp_str = endec.decode(b"\x1b$B-e-f-g\x1b(B", "iso-2022-jp")
97
+ assert iso2022jp_str == "㊤㊥㊦"
98
+
99
+ b"\x1b$B-e-f-g\x1b(B".decode("iso-2022-jp") # Standard Library `decode`
100
+ # UnicodeDecodeError: 'iso2022_jp' codec can't decode bytes in position 3-4: illegal multibyte sequence
101
+ ```
102
+
103
+ ### Error Handling
104
+
105
+ ```python
106
+ import endec
107
+ from endec.exceptions import EncodeError, DecodeError
108
+
109
+ try:
110
+ invalid_encode = endec.encode("漢字", "ascii")
111
+ except EncodeError as exc:
112
+ # endec.exceptions.EncodeError: encoding with 'windows-1252' codec failed
113
+ raise exc
114
+
115
+ try:
116
+ invalid_decode = endec.decode(b"\x42\xff\x42", "iso-2022-jp")
117
+ except DecodeError as exc:
118
+ # endec.exceptions.DecodeError: decoding with 'ISO-2022-JP' codec failed
119
+ raise exc
120
+ ```
121
+
122
+ ## License
123
+
124
+ This project is licensed under the terms of the [MIT license](https://github.com/fluxth/endec/blob/main/LICENSE).
125
+
@@ -0,0 +1,9 @@
1
+ endec/__init__.py,sha256=QHs4ebnMRPpR5cUVLh4FpZLdlc0ooJBgLgk83mw_iaA,113
2
+ endec/_endec.cpython-38-arm-linux-gnueabihf.so,sha256=HnfP6Ius7b4PLBNbcS5GEth762prgJiDvMw-qnHXPrQ,818864
3
+ endec/_endec.pyi,sha256=93qe9Ra7ZsUiL2vfv-2_Gz2G8PrtKofjioxLOlK7AV8,515
4
+ endec/exceptions.py,sha256=0vllesQZ3btKIArFIPyccwTHfSMxenbYsaQUIH717oY,1060
5
+ endec/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ endec-0.5.1.dist-info/METADATA,sha256=Tq5uuiJAxQzYrSxEZ1G9otxiAYRrSHoge8yux-0atQE,3915
7
+ endec-0.5.1.dist-info/WHEEL,sha256=YYe6mfI2xyIC3sQsNqnXvfIyD2CdxHDniYRT7Fa47zo,107
8
+ endec-0.5.1.dist-info/licenses/LICENSE,sha256=Dix8fgnEM4M0liTQ0rUrcP-Qon1T4G_IHBXFRNiIyxg,1064
9
+ endec-0.5.1.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: maturin (1.11.0)
3
+ Root-Is-Purelib: false
4
+ Tag: cp38-cp38-manylinux_2_24_armv7l
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 fluxth
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+