40 lines
1015 B
Python
40 lines
1015 B
Python
from pathlib import Path
|
|
|
|
def patch_flask_frozen():
|
|
try:
|
|
import flask_frozen
|
|
except ImportError:
|
|
print("flask_frozen is not installed.")
|
|
|
|
return
|
|
|
|
init_path = Path(flask_frozen.__file__).parent / "__init__.py"
|
|
|
|
if not init_path.exists():
|
|
print("Could not find flask_frozen __init__.py")
|
|
|
|
return
|
|
|
|
with open(init_path, "r") as f:
|
|
lines = f.readlines()
|
|
|
|
changed = False
|
|
|
|
for i, line in enumerate(lines):
|
|
if "url_encoding = self.app.url_map.charset" in line:
|
|
indent = line[: len(line) - len(line.lstrip())]
|
|
lines[i] = f"{indent}url_encoding = getattr(self.app.url_map, 'charset', 'utf-8') # patched\n"
|
|
changed = True
|
|
|
|
if changed:
|
|
with open(init_path, "w") as f:
|
|
f.writelines(lines)
|
|
print("✅ flask_frozen patched successfully.")
|
|
else:
|
|
print("⚠️ Patch already applied or target line not found.")
|
|
|
|
|
|
if __name__ == "__main__":
|
|
patch_flask_frozen()
|
|
|