Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Core, WebHost: lazy-load worlds in unpickler, WebHost and WebHostLib #2156

Merged
merged 7 commits into from
Sep 20, 2023
6 changes: 5 additions & 1 deletion Utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,13 @@ def get_unique_identifier():


class RestrictedUnpickler(pickle.Unpickler):
generic_properties_module: Optional[object]

def __init__(self, *args, **kwargs):
super(RestrictedUnpickler, self).__init__(*args, **kwargs)
self.options_module = importlib.import_module("Options")
self.net_utils_module = importlib.import_module("NetUtils")
self.generic_properties_module = importlib.import_module("worlds.generic")
self.generic_properties_module = None

def find_class(self, module, name):
if module == "builtins" and name in safe_builtins:
Expand All @@ -373,6 +375,8 @@ def find_class(self, module, name):
return getattr(self.net_utils_module, name)
# Options and Plando are unpickled by WebHost -> Generate
if module == "worlds.generic" and name in {"PlandoItem", "PlandoConnection"}:
if not self.generic_properties_module:
self.generic_properties_module = importlib.import_module("worlds.generic")
return getattr(self.generic_properties_module, name)
# pep 8 specifies that modules should have "all-lowercase names" (options, not Options)
if module.lower().endswith("options"):
Expand Down