Example #1
0
def add_multi_constructor(tag_prefix,
                          multi_constructor,
                          Loader=None,
                          constructor=Constructor):
    # type: (Any, Any, Any, Any) -> None
    """
    Add a multi-constructor for the given tag prefix.
    Multi-constructor is called for a node if its tag starts with tag_prefix.
    Multi-constructor accepts a Loader instance, a tag suffix,
    and a node object and produces the corresponding Python object.
    """
    if Loader is None:
        constructor.add_multi_constructor(tag_prefix, multi_constructor)
    else:
        if False and hasattr(Loader, 'add_multi_constructor'):
            Loader.add_multi_constructor(tag_prefix, constructor)
            return
        if issubclass(Loader, BaseLoader):
            BaseConstructor.add_multi_constructor(tag_prefix,
                                                  multi_constructor)
        elif issubclass(Loader, SafeLoader):
            SafeConstructor.add_multi_constructor(tag_prefix,
                                                  multi_constructor)
        elif issubclass(Loader, ruamel.yaml.loader.Loader):
            Constructor.add_multi_constructor(tag_prefix, multi_constructor)
        elif issubclass(Loader, RoundTripLoader):
            RoundTripConstructor.add_multi_constructor(tag_prefix,
                                                       multi_constructor)
        else:
            raise NotImplementedError
Example #2
0
 def __init__(self, stream, version=None, preserve_quotes=None):
     Reader.__init__(self, stream)
     Scanner.__init__(self)
     Parser.__init__(self)
     Composer.__init__(self)
     Constructor.__init__(self)
     Resolver.__init__(self)
Example #3
0
def add_constructor(tag,
                    object_constructor,
                    Loader=None,
                    constructor=Constructor):
    # type: (Any, Any, Any, Any) -> None
    """
    Add an object constructor for the given tag.
    object_onstructor is a function that accepts a Loader instance
    and a node object and produces the corresponding Python object.
    """
    if Loader is None:
        constructor.add_constructor(tag, object_constructor)
    else:
        if hasattr(Loader, 'add_constructor'):
            Loader.add_constructor(tag, object_constructor)
            return
        if issubclass(Loader, BaseLoader):
            BaseConstructor.add_constructor(tag, object_constructor)
        elif issubclass(Loader, SafeLoader):
            SafeConstructor.add_constructor(tag, object_constructor)
        elif issubclass(Loader, Loader):
            Constructor.add_constructor(tag, object_constructor)
        elif issubclass(Loader, RoundTripLoader):
            RoundTripConstructor.add_constructor(tag, object_constructor)
        else:
            raise NotImplementedError
Example #4
0
 def __init__(self, stream, version=None, preserve_quotes=None):
     Reader.__init__(self, stream)
     Scanner.__init__(self)
     Parser.__init__(self)
     Composer.__init__(self)
     Constructor.__init__(self)
     Resolver.__init__(self)
Example #5
0
 def __init__(self, stream, version=None, preserve_quotes=None):
     # type: (StreamTextType, Optional[VersionType], Optional[bool]) -> None
     Reader.__init__(self, stream, loader=self)
     Scanner.__init__(self, loader=self)
     Parser.__init__(self, loader=self)
     Composer.__init__(self, loader=self)
     Constructor.__init__(self, loader=self)
     VersionedResolver.__init__(self, version, loader=self)
Example #6
0
 def __init__(self, stream):
     if hasattr(stream, 'read'):
         stream = stream.read()
     CanonicalScanner.__init__(self, stream)
     CanonicalParser.__init__(self)
     Composer.__init__(self)
     Constructor.__init__(self)
     Resolver.__init__(self)
Example #7
0
 def __init__(self, stream, version=None, preserve_quotes=None):
     CParser.__init__(self, stream)
     Constructor.__init__(self)
     Resolver.__init__(self)
Example #8
0
 def __init__(self, stream, version=None, preserve_quotes=None):
     # type: (StreamTextType, Optional[VersionType], Optional[bool]) -> None
     CParser.__init__(self, stream)
     self._parser = self._composer = self
     Constructor.__init__(self, loader=self)
     Resolver.__init__(self, loadumper=self)
Example #9
0
 def __init__(self, stream, version=None, preserve_quotes=None):
     CParser.__init__(self, stream)
     Constructor.__init__(self)
     Resolver.__init__(self)
Example #10
0
 def from_yaml(cls, constructor: Constructor,
               node: MappingNode) -> "Question":
     value = list(constructor.construct_yaml_map(node))[0]
     return cls(**value)