some fields of Rename and StrEditor patch now support MultipleSafeEval

This commit is contained in:
Faraphel 2022-08-16 21:50:28 +02:00
parent 8edf1d60d2
commit d3ca353ecd
2 changed files with 9 additions and 6 deletions

View file

@ -4,6 +4,7 @@ from source.mkw.Patch.PatchOperation import AbstractPatchOperation
if TYPE_CHECKING:
from source.mkw.Patch import Patch
from source import TemplateMultipleSafeEval
class Rename(AbstractPatchOperation):
@ -13,8 +14,8 @@ class Rename(AbstractPatchOperation):
type = "rename"
def __init__(self, name: str):
def __init__(self, name: "TemplateMultipleSafeEval"):
self.name = name
def patch(self, patch: "Patch", file_name: str, file_content: IO) -> (str, IO):
return self.name, file_content
return patch.mod_config.multiple_safe_eval(self.name)(), file_content

View file

@ -8,6 +8,7 @@ from source.wt import wstrt
if TYPE_CHECKING:
from source.mkw.Patch import Patch
from source import TemplateMultipleSafeEval
class StrEditor(AbstractPatchOperation):
@ -17,7 +18,8 @@ class StrEditor(AbstractPatchOperation):
type = "str-edit"
def __init__(self, region: int = None, https: str = None, domain: str = None, sections: list[str] = None):
def __init__(self, region: "TemplateMultipleSafeEval" = None, https: "TemplateMultipleSafeEval" = None,
domain: "TemplateMultipleSafeEval" = None, sections: list[str] = None):
self.region = region
self.https = https
self.domain = domain
@ -37,9 +39,9 @@ class StrEditor(AbstractPatchOperation):
patch_content = BytesIO(
wstrt.patch_data(
file_content.read(),
region=self.region,
https=self.https,
domain=self.domain,
region=patch.mod_config.multiple_safe_eval(self.region)(),
https=patch.mod_config.multiple_safe_eval(self.https)(),
domain=patch.mod_config.multiple_safe_eval(self.domain)(),
sections=checked_sections
)
)