Skip to content

Commit 4f6be48

Browse files
committed
Applied some minor improvements
1 parent 5aaec70 commit 4f6be48

File tree

12 files changed

+48
-27
lines changed

12 files changed

+48
-27
lines changed

.github/workflows/python-package.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
python -m pip install --upgrade pip
3232
python -m pip install pytest pytest-cov coverage
3333
pip install -r requirements.txt
34+
pip install tinyscript>=1.31
3435
pip install .
3536
- name: Test ${{ env.package }} with pytest
3637
run: |
@@ -45,7 +46,7 @@ jobs:
4546
- name: Set up Python ${{ matrix.python-version }}
4647
uses: actions/setup-python@v4
4748
with:
48-
python-version: "3.12"
49+
python-version: "3.13"
4950
- name: Install ${{ env.package }}
5051
run: |
5152
python -m pip install --upgrade pip

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
markdown2>=2.5.4
21
legacycrypt; python_version >= '3.13'
2+
markdown2>=2.5.4

src/codext/VERSION.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.15.9
1+
1.15.10

src/codext/__common__.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import os
77
import random
88
import re
9-
import sre_parse
109
import sys
1110
from encodings.aliases import aliases as ALIASES
1211
from functools import reduce, update_wrapper, wraps
@@ -37,8 +36,12 @@
3736
from importlib import reload
3837
except ImportError:
3938
pass
39+
try:
40+
import re._parser as sre_parse
41+
except ImportError:
42+
import sre_parse
4043

41-
# from Python 3.11, it seems that 'sre_parse' is not bound to 're' anymore
44+
# from Python 3.11, 'sre_parse' is bound as '_parser' ; monkey-patch it for backward-compatibility
4245
re.sre_parse = sre_parse
4346

4447

@@ -870,10 +873,9 @@ def _handle_error(token, position, output="", eename=None):
870873
:param output: output, as decoded up to the position of the error
871874
"""
872875
if errors == "strict":
873-
msg = "'%s' codec can't %scode %s '%s' in %s %d"
874-
token = ensure_str(token)
875-
token = token[:7] + "..." if len(token) > 10 else token
876-
err = getattr(builtins, exc)(msg % (eename or ename, ["en", "de"][decode], kind, token, item, position))
876+
token = f"{token[:7]}..." if len(token := ensure_str(token)) > 10 else token
877+
err = getattr(builtins, exc)(f"'{eename or ename}' codec can't {['en','de'][decode]}code {kind} '{token}' "
878+
f"in {item} {position}")
877879
err.output = output
878880
err.__cause__ = err
879881
raise err
@@ -1264,8 +1266,8 @@ def __guess(prev_input, input, stop_func, depth, max_depth, min_depth, encodings
12641266
if not stop and (show or debug) and found not in result:
12651267
s = repr(input)
12661268
s = s[2:-1] if s.startswith("b'") and s.endswith("'") else s
1267-
s = "[+] {', '.join(found)}: {s}"
1268-
print(s if len(s) <= 80 else s[:77] + "...")
1269+
s = f"[+] {', '.join(found)}: {s}"
1270+
print(s if len(s) <= 80 else f"{s[:77]}...")
12691271
result[found] = input
12701272
if depth >= max_depth or len(result) > 0 and stop:
12711273
return
@@ -1275,7 +1277,7 @@ def __guess(prev_input, input, stop_func, depth, max_depth, min_depth, encodings
12751277
if len(result) > 0 and stop:
12761278
return
12771279
if debug:
1278-
print(f"[*] Depth %0{len(str(max_depth))}d/%d: {encoding}" % (depth+1, max_depth))
1280+
print(f"[*] Depth {depth+1:0{len(str(max_depth))}}/{max_depth}: {encoding}")
12791281
__guess(input, new_input, stop_func, depth+1, max_depth, min_depth, encodings, result, found + (encoding, ),
12801282
stop, show, scoring_heuristic, extended, debug)
12811283

src/codext/hashing/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
# -*- coding: UTF-8 -*-
2-
from .blake import *
3-
from .checksums import *
4-
from .crypt import *
5-
from .md import *
6-
from .sha import *
7-
from .shake import *
8-
1+
# -*- coding: UTF-8 -*-
2+
from .blake import *
3+
from .checksums import *
4+
from .crypt import *
5+
from .md import *
6+
from .mmh3 import *
7+
from .sha import *
8+
from .shake import *
9+

src/codext/hashing/blake.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
"""Case Codecs - string hashing with blake.
2+
"""Blake2 Codecs - string hashing with blake.
33
44
These are codecs for hashing strings, for use with other codecs in encoding chains.
55

src/codext/hashing/checksums.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
"""Case Codecs - string common checksums.
2+
"""Checksum Codecs - string common checksums.
33
44
These are codecs for hashing strings, for use with other codecs in encoding chains.
55

src/codext/hashing/crypt.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
"""Case Codecs - string hashing with Unix's Crypt.
2+
"""Crypt Hashing Codec - string hashing with Unix's Crypt.
33
44
These are codecs for hashing strings, for use with other codecs in encoding chains.
55

src/codext/hashing/md.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# -*- coding: UTF-8 -*-
2-
"""Case Codecs - string hashing with Message Digest (MD).
2+
"""MD Hashing Codecs - string hashing with Message Digest (MD).
33
44
These are codecs for hashing strings, for use with other codecs in encoding chains.
55
@@ -56,4 +56,3 @@ def md2(data):
5656
add("md5", lambda s, error="strict": (hashlib.new("md5", b(s)).hexdigest(), len(s)), guess=None)
5757
if "md4" in hashlib.algorithms_available:
5858
add("md4", lambda s, error="strict": (hashlib.new("md4", b(s)).hexdigest(), len(s)), guess=None)
59-

src/codext/hashing/mmh3.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# -*- coding: UTF-8 -*-
2+
"""MMH3 Codecs - string hashing with MurmurHash3.
3+
4+
These are codecs for hashing strings, for use with other codecs in encoding chains.
5+
6+
These codecs:
7+
- transform strings from str to str
8+
- transform strings from bytes to bytes
9+
- transform file content from str to bytes (write)
10+
"""
11+
from ..__common__ import *
12+
13+
14+
if "mmh3_32" in hashlib.algorithms_available:
15+
add("mmh3_32", lambda s, error="strict": (hashlib.mmh3_32(b(s)).hexdigest(), len(s)), guess=None)
16+
if "mmh3_128" in hashlib.algorithms_available:
17+
add("mmh3_128", lambda s, error="strict": (hashlib.mmh3_128(b(s)).hexdigest(), len(s)), guess=None)
18+

0 commit comments

Comments
 (0)