From 29a587086f68053e75700ccb56924a5cf3faaf19 Mon Sep 17 00:00:00 2001 From: Aaron Liang <76561968+AaronL725@users.noreply.github.com> Date: Wed, 15 Jul 2026 01:47:13 +0800 Subject: [PATCH] fix: preserve modularization shared state compatibility --- tools/fix_modularization_shared_state.py | 49 ++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tools/fix_modularization_shared_state.py diff --git a/tools/fix_modularization_shared_state.py b/tools/fix_modularization_shared_state.py new file mode 100644 index 0000000..32d6b04 --- /dev/null +++ b/tools/fix_modularization_shared_state.py @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +from pathlib import Path + +path = Path(__file__).resolve().with_name("apply_full_safe_modularization.py") +text = path.read_text(encoding="utf-8") + +old_import = '''import_block = '''\\nimport functools\\nimport app_config as _app_config\\n''' +new_import = '''import_block = '''\\nimport functools\\nimport types\\nimport app_config as _app_config\\n''' +if old_import not in text: + raise RuntimeError("main import block anchor not found") +text = text.replace(old_import, new_import, 1) + +old_getattr = '''def __getattr__(name): + if name in {{"browser", "page", "browser_proxy_bridge", "browser_started_with_proxy", "cf_clearance"}}: + return getattr(_registration_browser, name) + raise AttributeError(name) +''' +new_getattr = '''def __getattr__(name): + if name in {{"browser", "page", "browser_proxy_bridge", "browser_started_with_proxy", "cf_clearance"}}: + return getattr(_registration_browser, name) + if name in {{"_cf_domain_index", "_cloudmail_domain_index"}}: + return getattr(_mail_service, name) + raise AttributeError(name) + + +class _CompatibilityModule(types.ModuleType): + def __setattr__(self, name, value): + if name == "config": + if value is not _app_config.config: + if not isinstance(value, dict): + raise TypeError("config must be a dict") + _app_config.config.clear() + _app_config.config.update(value) + value = _app_config.config + elif name in {{"_cf_domain_index", "_cloudmail_domain_index"}}: + setattr(_mail_service, name, int(value)) + self.__dict__.pop(name, None) + return + super().__setattr__(name, value) + + +sys.modules[__name__].__class__ = _CompatibilityModule +''' +if old_getattr not in text: + raise RuntimeError("compatibility getattr anchor not found") +text = text.replace(old_getattr, new_getattr, 1) + +path.write_text(text, encoding="utf-8") +print("shared state compatibility patch applied")