Coverage for an_website/patches/braille.py: 47.059%
17 statements
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-16 19:56 +0000
« prev ^ index » next coverage.py v7.6.4, created at 2024-11-16 19:56 +0000
1# This program is free software: you can redistribute it and/or modify
2# it under the terms of the GNU Affero General Public License as
3# published by the Free Software Foundation, either version 3 of the
4# License, or (at your option) any later version.
5#
6# This program is distributed in the hope that it will be useful,
7# but WITHOUT ANY WARRANTY; without even the implied warranty of
8# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9# GNU Affero General Public License for more details.
10#
11# You should have received a copy of the GNU Affero General Public License
12# along with this program. If not, see <https://www.gnu.org/licenses/>.
13# pylint: disable=missing-function-docstring, unused-argument
14# fmt: off
16"""⠗⡰⠓"""
18from __future__ import annotations
20from codecs import CodecInfo, register
23def encode(data: str, errors: str = "strict") -> tuple[bytes, int]:
24 output = bytearray()
25 for pos, char in enumerate(data):
26 byte = ord(char) - 0x2800
27 if not 0 <= byte <= 255:
28 if errors == "ignore":
29 continue
30 raise UnicodeEncodeError(
31 "braille",
32 char,
33 pos,
34 pos + 1,
35 "ordinal not in range(0x2800, 0x2900)",
36 )
37 output.append(byte)
38 return bytes(output), len(data)
41def decode(data: bytes, errors: str = "strict") -> tuple[str, int]:
42 return "".join(chr(0x2800 + byte) for byte in data), len(data)
45def morb() -> CodecInfo:
46 """⡉⡔⠧⡓⠠⡍⡏⡒⡂⡉⡎⠧⠠⡔⡉⡍⡅"""
47 return CodecInfo(
48 name="braille",
49 encode=encode,
50 decode=decode, # type: ignore[arg-type]
51 )
54register(lambda codec: morb() if codec == "braille" else None)