character-encoding-utils 0.0.7__tar.gz → 0.0.9__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.
Files changed (20) hide show
  1. character_encoding_utils-0.0.9/.github/workflows/publish.yml +29 -0
  2. character_encoding_utils-0.0.9/.github/workflows/test.yml +25 -0
  3. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/PKG-INFO +2 -2
  4. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/pyproject.toml +1 -1
  5. character_encoding_utils-0.0.9/requirements.txt +1 -0
  6. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/src/character_encoding_utils/big5.py +21 -9
  7. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/src/character_encoding_utils/gb2312.py +21 -9
  8. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/src/character_encoding_utils/ksx1001.py +22 -10
  9. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/src/character_encoding_utils/shiftjis.py +19 -7
  10. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/tests/test_big5.py +2 -2
  11. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/tests/test_gb2312.py +2 -2
  12. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/tests/test_ksx1001.py +2 -2
  13. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/tests/test_shiftjis.py +4 -4
  14. character_encoding_utils-0.0.7/.github/workflows/publish.yml +0 -29
  15. character_encoding_utils-0.0.7/.github/workflows/test.yml +0 -24
  16. character_encoding_utils-0.0.7/requirements.txt +0 -1
  17. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/.gitignore +0 -0
  18. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/LICENSE +0 -0
  19. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/README.md +0 -0
  20. {character_encoding_utils-0.0.7 → character_encoding_utils-0.0.9}/src/character_encoding_utils/__init__.py +0 -0
@@ -0,0 +1,29 @@
1
+ name: Publish
2
+
3
+ on:
4
+ release:
5
+ types: [published]
6
+
7
+ jobs:
8
+ publish:
9
+ environment:
10
+ name: pypi
11
+ url: https://pypi.org/project/character-encoding-utils/
12
+ permissions:
13
+ id-token: write
14
+ runs-on: ubuntu-latest
15
+ steps:
16
+ - name: Checkout
17
+ uses: actions/checkout@v4
18
+ - name: Setup Python
19
+ uses: actions/setup-python@v5
20
+ with:
21
+ python-version: "3.x"
22
+ - name: Install dependencies
23
+ run: |
24
+ python -m pip install pip --upgrade
25
+ python -m pip install build
26
+ - name: Build
27
+ run: python -m build
28
+ - name: Publish
29
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,25 @@
1
+ name: Test
2
+
3
+ on: [push, pull_request]
4
+
5
+ jobs:
6
+ test:
7
+ strategy:
8
+ matrix:
9
+ os: [ubuntu-latest, macos-latest, windows-latest]
10
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
11
+ fail-fast: false
12
+ runs-on: ${{ matrix.os }}
13
+ steps:
14
+ - name: Checkout
15
+ uses: actions/checkout@v4
16
+ - name: Setup Python
17
+ uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - name: Install dependencies
21
+ run: |
22
+ python -m pip install pip --upgrade
23
+ python -m pip install -r requirements.txt
24
+ - name: Test
25
+ run: python -m pytest
@@ -1,6 +1,6 @@
1
- Metadata-Version: 2.3
1
+ Metadata-Version: 2.4
2
2
  Name: character-encoding-utils
3
- Version: 0.0.7
3
+ Version: 0.0.9
4
4
  Summary: Some character encoding utils.
5
5
  Project-URL: homepage, https://github.com/TakWolf/character-encoding-utils
6
6
  Project-URL: source, https://github.com/TakWolf/character-encoding-utils
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
4
4
 
5
5
  [project]
6
6
  name = "character-encoding-utils"
7
- version = "0.0.7"
7
+ version = "0.0.9"
8
8
  description = "Some character encoding utils."
9
9
  readme = "README.md"
10
10
  license = { text = "MIT License" }
@@ -0,0 +1 @@
1
+ pytest==8.3.4
@@ -4,23 +4,35 @@ class Big5Exception(Exception):
4
4
 
5
5
 
6
6
  class Big5EncodeError(Big5Exception):
7
+ obj: str
8
+ position: int
9
+ reason: str
10
+
7
11
  def __init__(self, obj: str, position: int, reason: str):
8
- super().__init__(f"'big5' codec can't encode character '\\u{ord(obj):x}' in position {position}: {reason}")
9
- self.object = obj
12
+ self.obj = obj
10
13
  self.position = position
11
14
  self.reason = reason
12
15
 
16
+ def __str__(self) -> str:
17
+ return f"'big5' codec can't encode character '\\u{ord(self.obj):x}' in position {self.position}: {self.reason}"
18
+
13
19
 
14
20
  class Big5DecodeError(Big5Exception):
21
+ obj: bytes
22
+ position: int
23
+ reason: str
24
+
15
25
  def __init__(self, obj: bytes, position: int, reason: str):
16
- if len(obj) <= 1:
17
- super().__init__(f"'big5' codec can't decode byte 0x{obj[0]:x} in position {position}: {reason}")
18
- else:
19
- super().__init__(f"'big5' codec can't decode bytes in position {position}-{position + len(obj) - 1}: {reason}")
20
- self.object = obj
26
+ self.obj = obj
21
27
  self.position = position
22
28
  self.reason = reason
23
29
 
30
+ def __str__(self) -> str:
31
+ if len(self.obj) <= 1:
32
+ return f"'big5' codec can't decode byte 0x{self.obj[0]:x} in position {self.position}: {self.reason}"
33
+ else:
34
+ return f"'big5' codec can't decode bytes in position {self.position}-{self.position + len(self.obj) - 1}: {self.reason}"
35
+
24
36
 
25
37
  def encode(cs: str) -> bytes:
26
38
  bs = bytearray()
@@ -102,9 +114,9 @@ def query_code(c: str) -> int:
102
114
  try:
103
115
  bs = encode(c)
104
116
  except Big5EncodeError as e:
105
- raise Big5Exception(f"'{c}' is not a 'big5' character") from e
117
+ raise Big5Exception(f"'\\u{ord(c):x}' is not a 'big5' character") from e
106
118
  if len(bs) == 1:
107
- raise Big5Exception(f"'{c}' is a ascii character")
119
+ raise Big5Exception(f"'\\u{ord(c):x}' is a ascii character")
108
120
  code = int(f'{bs[0]:02x}{bs[1]:02x}', 16)
109
121
  return code
110
122
 
@@ -7,23 +7,35 @@ class GB2312Exception(Exception):
7
7
 
8
8
 
9
9
  class GB2312EncodeError(GB2312Exception):
10
+ obj: str
11
+ position: int
12
+ reason: str
13
+
10
14
  def __init__(self, obj: str, position: int, reason: str):
11
- super().__init__(f"'gb2312' codec can't encode character '\\u{ord(obj):x}' in position {position}: {reason}")
12
- self.object = obj
15
+ self.obj = obj
13
16
  self.position = position
14
17
  self.reason = reason
15
18
 
19
+ def __str__(self) -> str:
20
+ return f"'gb2312' codec can't encode character '\\u{ord(self.obj):x}' in position {self.position}: {self.reason}"
21
+
16
22
 
17
23
  class GB2312DecodeError(GB2312Exception):
24
+ obj: bytes
25
+ position: int
26
+ reason: str
27
+
18
28
  def __init__(self, obj: bytes, position: int, reason: str):
19
- if len(obj) <= 1:
20
- super().__init__(f"'gb2312' codec can't decode byte 0x{obj[0]:x} in position {position}: {reason}")
21
- else:
22
- super().__init__(f"'gb2312' codec can't decode bytes in position {position}-{position + len(obj) - 1}: {reason}")
23
- self.object = obj
29
+ self.obj = obj
24
30
  self.position = position
25
31
  self.reason = reason
26
32
 
33
+ def __str__(self) -> str:
34
+ if len(self.obj) <= 1:
35
+ return f"'gb2312' codec can't decode byte 0x{self.obj[0]:x} in position {self.position}: {self.reason}"
36
+ else:
37
+ return f"'gb2312' codec can't decode bytes in position {self.position}-{self.position + len(self.obj) - 1}: {self.reason}"
38
+
27
39
 
28
40
  def encode(cs: str) -> bytes:
29
41
  bs = bytearray()
@@ -64,9 +76,9 @@ def query_coord(c: str) -> tuple[int, int]:
64
76
  try:
65
77
  bs = encode(c)
66
78
  except GB2312EncodeError as e:
67
- raise GB2312Exception(f"'{c}' is not a 'gb2312' character") from e
79
+ raise GB2312Exception(f"'\\u{ord(c):x}' is not a 'gb2312' character") from e
68
80
  if len(bs) == 1:
69
- raise GB2312Exception(f"'{c}' is a ascii character")
81
+ raise GB2312Exception(f"'\\u{ord(c):x}' is a ascii character")
70
82
  row = bs[0] - _EUC_OFFSET
71
83
  col = bs[1] - _EUC_OFFSET
72
84
  return row, col
@@ -7,23 +7,35 @@ class KSX1001Exception(Exception):
7
7
 
8
8
 
9
9
  class KSX1001EncodeError(KSX1001Exception):
10
+ obj: str
11
+ position: int
12
+ reason: str
13
+
10
14
  def __init__(self, obj: str, position: int, reason: str):
11
- super().__init__(f"'ksx1001' codec can't encode character '\\u{ord(obj):x}' in position {position}: {reason}")
12
- self.object = obj
15
+ self.obj = obj
13
16
  self.position = position
14
17
  self.reason = reason
15
18
 
19
+ def __str__(self) -> str:
20
+ return f"'ksx1001' codec can't encode character '\\u{ord(self.obj):x}' in position {self.position}: {self.reason}"
21
+
16
22
 
17
23
  class KSX1001DecodeError(KSX1001Exception):
24
+ obj: bytes
25
+ position: int
26
+ reason: str
27
+
18
28
  def __init__(self, obj: bytes, position: int, reason: str):
19
- if len(obj) <= 1:
20
- super().__init__(f"'ksx1001' codec can't decode byte 0x{obj[0]:x} in position {position}: {reason}")
21
- else:
22
- super().__init__(f"'ksx1001' codec can't decode bytes in position {position}-{position + len(obj) - 1}: {reason}")
23
- self.object = obj
29
+ self.obj = obj
24
30
  self.position = position
25
31
  self.reason = reason
26
32
 
33
+ def __str__(self) -> str:
34
+ if len(self.obj) <= 1:
35
+ return f"'ksx1001' codec can't decode byte 0x{self.obj[0]:x} in position {self.position}: {self.reason}"
36
+ else:
37
+ return f"'ksx1001' codec can't decode bytes in position {self.position}-{self.position + len(self.obj) - 1}: {self.reason}"
38
+
27
39
 
28
40
  def encode(cs: str) -> bytes:
29
41
  bs = bytearray()
@@ -78,11 +90,11 @@ def query_coord(c: str) -> tuple[int, int]:
78
90
  try:
79
91
  bs = encode(c)
80
92
  except KSX1001EncodeError as e:
81
- raise KSX1001Exception(f"'{c}' is not a 'ksx1001' character") from e
93
+ raise KSX1001Exception(f"'\\u{ord(c):x}' is not a 'ksx1001' character") from e
82
94
  if len(bs) == 1:
83
- raise KSX1001Exception(f"'{c}' is a ascii character")
95
+ raise KSX1001Exception(f"'\\u{ord(c):x}' is a ascii character")
84
96
  elif bs.startswith(b'\xa4\xd4') and len(bs) > 2:
85
- raise KSX1001Exception(f"'{c}' is not a 'ksx1001' character")
97
+ raise KSX1001Exception(f"'\\u{ord(c):x}' is not a 'ksx1001' character")
86
98
  row = bs[0] - _EUC_OFFSET
87
99
  col = bs[1] - _EUC_OFFSET
88
100
  return row, col
@@ -6,23 +6,35 @@ class ShiftJISException(Exception):
6
6
 
7
7
 
8
8
  class ShiftJISEncodeError(ShiftJISException):
9
+ obj: str
10
+ position: int
11
+ reason: str
12
+
9
13
  def __init__(self, obj: str, position: int, reason: str):
10
- super().__init__(f"'shift-jis' codec can't encode character '\\u{ord(obj):x}' in position {position}: {reason}")
11
- self.object = obj
14
+ self.obj = obj
12
15
  self.position = position
13
16
  self.reason = reason
14
17
 
18
+ def __str__(self) -> str:
19
+ return f"'shift-jis' codec can't encode character '\\u{ord(self.obj):x}' in position {self.position}: {self.reason}"
20
+
15
21
 
16
22
  class ShiftJISDecodeError(ShiftJISException):
23
+ obj: bytes
24
+ position: int
25
+ reason: str
26
+
17
27
  def __init__(self, obj: bytes, position: int, reason: str):
18
- if len(obj) <= 1:
19
- super().__init__(f"'shift-jis' codec can't decode byte 0x{obj[0]:x} in position {position}: {reason}")
20
- else:
21
- super().__init__(f"'shift-jis' codec can't decode bytes in position {position}-{position + len(obj) - 1}: {reason}")
22
- self.object = obj
28
+ self.obj = obj
23
29
  self.position = position
24
30
  self.reason = reason
25
31
 
32
+ def __str__(self) -> str:
33
+ if len(self.obj) <= 1:
34
+ return f"'shift-jis' codec can't decode byte 0x{self.obj[0]:x} in position {self.position}: {self.reason}"
35
+ else:
36
+ return f"'shift-jis' codec can't decode bytes in position {self.position}-{self.position + len(self.obj) - 1}: {self.reason}"
37
+
26
38
 
27
39
  def encode(cs: str) -> bytes:
28
40
  bs = bytearray()
@@ -10,13 +10,13 @@ def test_codec():
10
10
 
11
11
  with pytest.raises(Big5EncodeError) as info:
12
12
  big5.encode('abc가')
13
- assert info.value.object == '가'
13
+ assert info.value.obj == '가'
14
14
  assert info.value.position == 3
15
15
  assert info.value.reason == 'illegal multibyte sequence'
16
16
 
17
17
  with pytest.raises(Big5DecodeError) as info:
18
18
  big5.decode(b'abc\xa4\xa4\xb0')
19
- assert info.value.object == b'\xb0'
19
+ assert info.value.obj == b'\xb0'
20
20
  assert info.value.position == 5
21
21
  assert info.value.reason == 'incomplete multibyte sequence'
22
22
 
@@ -10,13 +10,13 @@ def test_codec():
10
10
 
11
11
  with pytest.raises(GB2312EncodeError) as info:
12
12
  gb2312.encode('abc가')
13
- assert info.value.object == '가'
13
+ assert info.value.obj == '가'
14
14
  assert info.value.position == 3
15
15
  assert info.value.reason == 'illegal multibyte sequence'
16
16
 
17
17
  with pytest.raises(GB2312DecodeError) as info:
18
18
  gb2312.decode(b'abc\xd6\xd0\xb9')
19
- assert info.value.object == b'\xb9'
19
+ assert info.value.obj == b'\xb9'
20
20
  assert info.value.position == 5
21
21
  assert info.value.reason == 'incomplete multibyte sequence'
22
22
 
@@ -10,13 +10,13 @@ def test_codec():
10
10
 
11
11
  with pytest.raises(KSX1001EncodeError) as info:
12
12
  ksx1001.encode('abc😈')
13
- assert info.value.object == '😈'
13
+ assert info.value.obj == '😈'
14
14
  assert info.value.position == 3
15
15
  assert info.value.reason == 'illegal multibyte sequence'
16
16
 
17
17
  with pytest.raises(KSX1001DecodeError) as info:
18
18
  ksx1001.decode(b'abc\xb0\xa1\xc3')
19
- assert info.value.object == b'\xc3'
19
+ assert info.value.obj == b'\xc3'
20
20
  assert info.value.position == 5
21
21
  assert info.value.reason == 'incomplete multibyte sequence'
22
22
 
@@ -10,26 +10,26 @@ def test_codec():
10
10
 
11
11
  with pytest.raises(ShiftJISEncodeError) as info:
12
12
  shiftjis.encode('abc가')
13
- assert info.value.object == '가'
13
+ assert info.value.obj == '가'
14
14
  assert info.value.position == 3
15
15
  assert info.value.reason == 'illegal multibyte sequence'
16
16
 
17
17
  with pytest.raises(ShiftJISDecodeError) as info:
18
18
  shiftjis.decode(b'abc\x93\xfa\x96')
19
- assert info.value.object == b'\x96'
19
+ assert info.value.obj == b'\x96'
20
20
  assert info.value.position == 5
21
21
  assert info.value.reason == 'incomplete multibyte sequence'
22
22
 
23
23
  with pytest.raises(ShiftJISEncodeError) as info:
24
24
  shiftjis.encode('\\')
25
- assert info.value.object == '\\'
25
+ assert info.value.obj == '\\'
26
26
  assert info.value.position == 0
27
27
  assert '\\' in info.value.reason
28
28
  assert '¥' in info.value.reason
29
29
 
30
30
  with pytest.raises(ShiftJISEncodeError) as info:
31
31
  shiftjis.encode('~')
32
- assert info.value.object == '~'
32
+ assert info.value.obj == '~'
33
33
  assert info.value.position == 0
34
34
  assert '~' in info.value.reason
35
35
  assert '‾' in info.value.reason
@@ -1,29 +0,0 @@
1
- name: Publish
2
-
3
- on:
4
- release:
5
- types: [published]
6
-
7
- jobs:
8
- publish:
9
- runs-on: ubuntu-latest
10
- environment:
11
- name: pypi
12
- url: https://pypi.org/project/character-encoding-utils/
13
- permissions:
14
- id-token: write
15
- steps:
16
- - name: Checkout
17
- uses: actions/checkout@v4
18
- - name: Setup Python
19
- uses: actions/setup-python@v5
20
- with:
21
- python-version: '3.x'
22
- - name: Install dependencies
23
- run: |
24
- python -m pip install pip --upgrade
25
- python -m pip install build
26
- - name: Build
27
- run: python -m build
28
- - name: Publish
29
- uses: pypa/gh-action-pypi-publish@release/v1
@@ -1,24 +0,0 @@
1
- name: Test
2
-
3
- on: [push, pull_request]
4
-
5
- jobs:
6
- test:
7
- runs-on: ubuntu-latest
8
- strategy:
9
- fail-fast: false
10
- matrix:
11
- python-version: ["3.10", "3.11", "3.12"]
12
- steps:
13
- - name: Checkout
14
- uses: actions/checkout@v4
15
- - name: Setup Python
16
- uses: actions/setup-python@v5
17
- with:
18
- python-version: ${{ matrix.python-version }}
19
- - name: Install dependencies
20
- run: |
21
- python -m pip install pip --upgrade
22
- python -m pip install -r requirements.txt
23
- - name: Test
24
- run: python -m pytest
@@ -1 +0,0 @@
1
- pytest==8.2.0