How to use the srsly.ruamel_yaml.constructor.SafeConstructor function in srsly

To help you get started, we’ve selected a few srsly examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github explosion / srsly / srsly / ruamel_yaml / loader.py View on Github external
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)
        SafeConstructor.__init__(self, loader=self)
        VersionedResolver.__init__(self, version, loader=self)
github explosion / srsly / srsly / ruamel_yaml / constructor.py View on Github external
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:set", SafeConstructor.construct_yaml_set
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:str", SafeConstructor.construct_yaml_str
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:seq", SafeConstructor.construct_yaml_seq
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:map", SafeConstructor.construct_yaml_map
)

SafeConstructor.add_constructor(None, SafeConstructor.construct_undefined)

if PY2:

    class classobj:
        pass


class Constructor(SafeConstructor):
    def construct_python_str(self, node):
        raise ValueError("Unsafe constructor not implemented in this library")

    def construct_python_unicode(self, node):
        raise ValueError("Unsafe constructor not implemented in this library")
github explosion / srsly / srsly / ruamel_yaml / constructor.py View on Github external
else:
            state = self.construct_mapping(node)
            data.__dict__.update(state)

    def construct_undefined(self, node):
        # type: (Any) -> None
        raise ConstructorError(
            None,
            None,
            "could not determine a constructor for the tag %r" % utf8(node.tag),
            node.start_mark,
        )


SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:null", SafeConstructor.construct_yaml_null
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:bool", SafeConstructor.construct_yaml_bool
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:int", SafeConstructor.construct_yaml_int
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:float", SafeConstructor.construct_yaml_float
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:binary", SafeConstructor.construct_yaml_binary
github explosion / srsly / srsly / ruamel_yaml / constructor.py View on Github external
def construct_undefined(self, node):
        # type: (Any) -> None
        raise ConstructorError(
            None,
            None,
            "could not determine a constructor for the tag %r" % utf8(node.tag),
            node.start_mark,
        )


SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:null", SafeConstructor.construct_yaml_null
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:bool", SafeConstructor.construct_yaml_bool
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:int", SafeConstructor.construct_yaml_int
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:float", SafeConstructor.construct_yaml_float
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:binary", SafeConstructor.construct_yaml_binary
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:timestamp", SafeConstructor.construct_yaml_timestamp
github explosion / srsly / srsly / ruamel_yaml / constructor.py View on Github external
match = None
        if match is None:
            raise ConstructorError(
                None,
                None,
                'failed to construct timestamp from "{}"'.format(node.value),
                node.start_mark,
            )
        values = match.groupdict()
        if not values["hour"]:
            return SafeConstructor.construct_yaml_timestamp(self, node, values)
        for part in ["t", "tz_sign", "tz_hour", "tz_minute"]:
            if values[part]:
                break
        else:
            return SafeConstructor.construct_yaml_timestamp(self, node, values)
        year = int(values["year"])
        month = int(values["month"])
        day = int(values["day"])
        hour = int(values["hour"])
        minute = int(values["minute"])
        second = int(values["second"])
        fraction = 0
        if values["fraction"]:
            fraction_s = values["fraction"][:6]
            while len(fraction_s) < 6:
                fraction_s += "0"
            fraction = int(fraction_s)
            if len(values["fraction"]) > 6 and int(values["fraction"][6]) > 4:
                fraction += 1
        delta = None
        if values["tz_sign"]:
github explosion / srsly / srsly / ruamel_yaml / constructor.py View on Github external
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:pairs", SafeConstructor.construct_yaml_pairs
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:set", SafeConstructor.construct_yaml_set
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:str", SafeConstructor.construct_yaml_str
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:seq", SafeConstructor.construct_yaml_seq
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:map", SafeConstructor.construct_yaml_map
)

SafeConstructor.add_constructor(None, SafeConstructor.construct_undefined)

if PY2:

    class classobj:
        pass


class Constructor(SafeConstructor):
    def construct_python_str(self, node):
github explosion / srsly / srsly / ruamel_yaml / constructor.py View on Github external
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)
github explosion / srsly / srsly / ruamel_yaml / constructor.py View on Github external
None,
            "could not determine a constructor for the tag %r" % utf8(node.tag),
            node.start_mark,
        )


SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:null", SafeConstructor.construct_yaml_null
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:bool", SafeConstructor.construct_yaml_bool
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:int", SafeConstructor.construct_yaml_int
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:float", SafeConstructor.construct_yaml_float
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:binary", SafeConstructor.construct_yaml_binary
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:timestamp", SafeConstructor.construct_yaml_timestamp
)

SafeConstructor.add_constructor(
    u"tag:yaml.org,2002:omap", SafeConstructor.construct_yaml_omap
github explosion / srsly / srsly / ruamel_yaml / loader.py View on Github external
__all__ = ["BaseLoader", "SafeLoader", "Loader", "RoundTripLoader"]


class BaseLoader(Reader, Scanner, Parser, Composer, BaseConstructor, VersionedResolver):
    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)
        BaseConstructor.__init__(self, loader=self)
        VersionedResolver.__init__(self, version, loader=self)


class SafeLoader(Reader, Scanner, Parser, Composer, SafeConstructor, VersionedResolver):
    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)
        SafeConstructor.__init__(self, loader=self)
        VersionedResolver.__init__(self, version, loader=self)


class Loader(Reader, Scanner, Parser, Composer, Constructor, VersionedResolver):
    def __init__(self, stream, version=None, preserve_quotes=None):
        raise ValueError("Unsafe loader not implemented in this library.")


class RoundTripLoader(