diff --git a/implementations/python/preserves/schema.py b/implementations/python/preserves/schema.py index 5baae6b..08576ce 100644 --- a/implementations/python/preserves/schema.py +++ b/implementations/python/preserves/schema.py @@ -376,32 +376,36 @@ class Compiler: c._set_schema(self.root, module_path, n, d, None, None) ns[n] = c +def load_schema_file(filename): + c = Compiler() + c.load(filename) + return c.root + # a decorator def extend(cls): return lambda f: setattr(cls, f.__name__, f) -if __name__ == '__main__': - c = Compiler() - schema_bin_filename = pathlib.Path(__file__).parent / '../../../schema/schema.bin' - c.load(schema_bin_filename) - with open(schema_bin_filename, 'rb') as f: - x = Decoder(f.read()).next() - print(c.root.schema.Schema.decode(x)) +__metaschema_filename = pathlib.Path(__file__).parent / '../../../schema/schema.bin' +meta = load_schema_file(__metaschema_filename).schema - @extend(c.root.schema.Schema) +if __name__ == '__main__': + with open(__metaschema_filename, 'rb') as f: + x = Decoder(f.read()).next() + print(meta.Schema.decode(x)) + + @extend(meta.Schema) def f(self, x): return ['yay', self.embeddedType, x] - print(c.root.schema.Schema.decode(x).f(123)) + print(meta.Schema.decode(x).f(123)) print(f) print() - d = Compiler() path_bin_filename = pathlib.Path(__file__).parent / '../../../path/path.bin' - d.load(path_bin_filename) + path = load_schema_file(path_bin_filename).path with open(path_bin_filename, 'rb') as f: x = Decoder(f.read()).next() - print(c.root.schema.Schema.decode(x)) - print(c.root.schema.Schema.decode(x) == c.root.schema.Schema.decode(x)) + print(meta.Schema.decode(x)) + print(meta.Schema.decode(x) == meta.Schema.decode(x)) print() - print(d.root) + print(path)