From 392fe65313a94ebfd7e0f70c8f7c3c7365bcff1c Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 29 Apr 2024 13:38:29 -0500 Subject: Lingo: Fix world load on frozen 3.8 (#3220) * Lingo: Fix world load on frozen 3.8 * Fixed absolute imports in unit test * Made unpickling safer --- options.py | 2 +- static_logic.py | 13 ++++++++----- test/TestDatafile.py | 4 ++-- 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/options.py b/options.py index 05fb4ed..65f2726 100644 --- a/options.py +++ b/options.py @@ -3,7 +3,7 @@ from dataclasses import dataclass from schema import And, Schema from Options import Toggle, Choice, DefaultOnToggle, Range, PerGameCommonOptions, StartInventoryPool, OptionDict -from worlds.lingo.items import TRAP_ITEMS +from .items import TRAP_ITEMS class ShuffleDoors(Choice): diff --git a/static_logic.py b/static_logic.py index c7ee001..ff820dd 100644 --- a/static_logic.py +++ b/static_logic.py @@ -78,13 +78,16 @@ def get_progressive_item_id(name: str): def load_static_data_from_file(): global PAINTING_ENTRANCES, PAINTING_EXITS + from . import datatypes + from Utils import safe_builtins + class RenameUnpickler(pickle.Unpickler): def find_class(self, module, name): - renamed_module = module - if module == "datatypes": - renamed_module = "worlds.lingo.datatypes" - - return super(RenameUnpickler, self).find_class(renamed_module, name) + if module in ("worlds.lingo.datatypes", "datatypes"): + return getattr(datatypes, name) + elif module == "builtins" and name in safe_builtins: + return getattr(safe_builtins, name) + raise pickle.UnpicklingError(f"global '{module}.{name}' is forbidden") file = pkgutil.get_data(__name__, os.path.join("data", "generated.dat")) pickdata = RenameUnpickler(BytesIO(file)).load() diff --git a/test/TestDatafile.py b/test/TestDatafile.py index 9f4e9da..60acb3e 100644 --- a/test/TestDatafile.py +++ b/test/TestDatafile.py @@ -1,8 +1,8 @@ import os import unittest -from worlds.lingo.static_logic import HASHES -from worlds.lingo.utils.pickle_static_data import hash_file +from ..static_logic import HASHES +from ..utils.pickle_static_data import hash_file class TestDatafile(unittest.TestCase): -- cgit 1.4.1