From eaba7badcb3ce04a9db6e4fe8504950cef832f7d Mon Sep 17 00:00:00 2001 From: Anthon van der Neut Date: Thu, 13 Jul 2017 23:32:42 +0200 Subject: added register_class/yaml_object --- constructor.py | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'constructor.py') diff --git a/constructor.py b/constructor.py index fd1926e..c957cd0 100644 --- a/constructor.py +++ b/constructor.py @@ -1278,6 +1278,17 @@ class RoundTripConstructor(SafeConstructor): yield data self.construct_mapping(node, data) + def construct_yaml_object(self, node, cls): + # type: (Any, Any) -> Any + data = cls.__new__(cls) + yield data + if hasattr(data, '__setstate__'): + state = SafeConstructor.construct_mapping(self, node, deep=True) + data.__setstate__(state) + else: + state = SafeConstructor.construct_mapping(self, node) + data.__dict__.update(state) + def construct_yaml_omap(self, node): # type: (Any) -> Any # Note: we do now check for duplicate keys -- cgit v1.2.1