Coverage for an_website / patches / braille.py: 43.750%

16 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-04-24 17:35 +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 

15 

16"""⠗⡰⠓""" 

17 

18 

19from codecs import CodecInfo, register 

20 

21 

22def encode(data: str, errors: str = "strict") -> tuple[bytes, int]: 

23 output = bytearray() 

24 for pos, char in enumerate(data): 

25 byte = ord(char) - 0x2800 

26 if not 0 <= byte <= 255: 

27 if errors == "ignore": 

28 continue 

29 raise UnicodeEncodeError( 

30 "braille", 

31 char, 

32 pos, 

33 pos + 1, 

34 "ordinal not in range(0x2800, 0x2900)", 

35 ) 

36 output.append(byte) 

37 return bytes(output), len(data) 

38 

39 

40def decode(data: bytes, errors: str = "strict") -> tuple[str, int]: 

41 return "".join(chr(0x2800 + byte) for byte in data), len(data) 

42 

43 

44def morb() -> CodecInfo: 

45 """⡉⡔⠧⡓⠠⡍⡏⡒⡂⡉⡎⠧⠠⡔⡉⡍⡅""" 

46 return CodecInfo( 

47 name="braille", 

48 encode=encode, 

49 decode=decode, # type: ignore[arg-type] 

50 ) 

51 

52 

53register(lambda codec: morb() if codec == "braille" else None)