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
This commit is contained in:
parent
fc4e6adff5
commit
487a067d10
|
@ -3,7 +3,7 @@ from dataclasses import dataclass
|
||||||
from schema import And, Schema
|
from schema import And, Schema
|
||||||
|
|
||||||
from Options import Toggle, Choice, DefaultOnToggle, Range, PerGameCommonOptions, StartInventoryPool, OptionDict
|
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):
|
class ShuffleDoors(Choice):
|
||||||
|
|
|
@ -78,13 +78,16 @@ def get_progressive_item_id(name: str):
|
||||||
def load_static_data_from_file():
|
def load_static_data_from_file():
|
||||||
global PAINTING_ENTRANCES, PAINTING_EXITS
|
global PAINTING_ENTRANCES, PAINTING_EXITS
|
||||||
|
|
||||||
|
from . import datatypes
|
||||||
|
from Utils import safe_builtins
|
||||||
|
|
||||||
class RenameUnpickler(pickle.Unpickler):
|
class RenameUnpickler(pickle.Unpickler):
|
||||||
def find_class(self, module, name):
|
def find_class(self, module, name):
|
||||||
renamed_module = module
|
if module in ("worlds.lingo.datatypes", "datatypes"):
|
||||||
if module == "datatypes":
|
return getattr(datatypes, name)
|
||||||
renamed_module = "worlds.lingo.datatypes"
|
elif module == "builtins" and name in safe_builtins:
|
||||||
|
return getattr(safe_builtins, name)
|
||||||
return super(RenameUnpickler, self).find_class(renamed_module, name)
|
raise pickle.UnpicklingError(f"global '{module}.{name}' is forbidden")
|
||||||
|
|
||||||
file = pkgutil.get_data(__name__, os.path.join("data", "generated.dat"))
|
file = pkgutil.get_data(__name__, os.path.join("data", "generated.dat"))
|
||||||
pickdata = RenameUnpickler(BytesIO(file)).load()
|
pickdata = RenameUnpickler(BytesIO(file)).load()
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
import os
|
import os
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from worlds.lingo.static_logic import HASHES
|
from ..static_logic import HASHES
|
||||||
from worlds.lingo.utils.pickle_static_data import hash_file
|
from ..utils.pickle_static_data import hash_file
|
||||||
|
|
||||||
|
|
||||||
class TestDatafile(unittest.TestCase):
|
class TestDatafile(unittest.TestCase):
|
||||||
|
|
Loading…
Reference in New Issue