Skip to content

Commit

Permalink
fix: 🐛 read_text encoding in Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
ZhaoQi99 committed Mar 26, 2024
1 parent 0b6e0c2 commit e839539
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions pyencrypt/encrypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ def generate_so_file(cipher_key: str, d: int, n: int, base_dir: Optional[Path] =
need_import_files = ['ntt.py', 'aes.py', 'decrypt.py', 'license.py']
for file in need_import_files:
file_path = path / file
decrypt_source_ls.append(REMOVE_SELF_IMPORT.sub('', file_path.read_text()))
decrypt_source_ls.append(REMOVE_SELF_IMPORT.sub('', file_path.read_text(encoding="utf-8")))

loader_source_path = path / 'loader.py'
loader_source = REMOVE_SELF_IMPORT.sub('', loader_source_path.read_text()).replace(
"__private_key = ''", f"__private_key = '{private_key}'", 1
).replace("__cipher_key = ''", f"__cipher_key = '{cipher_key}'", 1).replace(
'license = None', f'license = {license}', 1
loader_source = (
REMOVE_SELF_IMPORT.sub("", loader_source_path.read_text(encoding="utf-8"))
.replace("__private_key = ''", f"__private_key = '{private_key}'", 1)
.replace("__cipher_key = ''", f"__cipher_key = '{cipher_key}'", 1)
.replace("license = None", f"license = {license}", 1)
)

if base_dir is None:
Expand All @@ -81,7 +81,7 @@ def generate_so_file(cipher_key: str, d: int, n: int, base_dir: Optional[Path] =
loader_origin_file_path.touch(exist_ok=True)
loader_origin_file_path.write_text(f"{decrypt_source}\n{loader_source}")

loader_file_path.write_text(python_minifier.minify(loader_origin_file_path.read_text()))
loader_file_path.write_text(python_minifier.minify(loader_origin_file_path.read_text(encoding="utf-8")))

from setuptools import setup # isort:skip
from Cython.Build import cythonize
Expand Down

0 comments on commit e839539

Please sign in to comment.