MCPcopy Create free account
hub / github.com/TimMcCool/scratchattach / Meta

Class Meta

scratchattach/editor/meta.py:52–117  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

50
51
52class Meta(base.JSONSerializable):
53 def __init__(self, semver: str = "3.0.0", vm: str = DEFAULT_VM, agent: str = DEFAULT_AGENT,
54 platform: Optional[PlatformMeta] = None):
55 """
56 Represents metadata of the project
57 https://en.scratch-wiki.info/wiki/Scratch_File_Format#Metadata
58 """
59 if platform is None and META_SET_PLATFORM:
60 platform = DEFAULT_PLATFORM.dcopy()
61
62 self.semver = semver
63 self.vm = vm
64 self.agent = agent
65 self.platform = platform
66
67 if not self.vm_is_valid:
68 raise ValueError(
69 f"{vm!r} does not match pattern '^([0-9]+\\.[0-9]+\\.[0-9]+)($|-)' - maybe try '0.0.0'?")
70
71 def __repr__(self):
72 data = f"{self.semver} : {self.vm} : {self.agent}"
73 if self.platform:
74 data += f": {self.platform}"
75
76 return f"Meta<{data}>"
77
78 @property
79 def vm_is_valid(self):
80 """
81 Check whether the vm value is valid using a regex
82 regex pattern from TurboWarp ↓↓↓↓
83 """
84 return re.match("^([0-9]+\\.[0-9]+\\.[0-9]+)($|-)", self.vm) is not None
85
86 def to_json(self):
87 _json: dict[str, str | dict[str, str]] = {
88 "semver": self.semver,
89 "vm": self.vm,
90 "agent": self.agent
91 }
92
93 if self.platform:
94 _json["platform"] = self.platform.to_json()
95 return _json
96
97 @staticmethod
98 def from_json(data: dict[str, str | dict[str, str]] | None):
99 if data is None:
100 data = {"semver": "3.0.0"}
101
102 semver = data["semver"]
103 vm = data.get("vm")
104 agent = data.get("agent")
105 platform = PlatformMeta.from_json(data.get("platform"))
106
107 if EDIT_META or vm is None:
108 vm = DEFAULT_VM
109

Callers 1

from_jsonMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected