class MarkedYAMLError(YAMLError):
    def __init__(
        self,
        context=None,
        context_mark=None,
        problem=None,
        problem_mark=None,
        note=None,
        warn=None,
    ):
        # type: (Any, Any, Any, Any, Any, Any) -> None
        self.context = context
        self.context_mark = context_mark
        self.problem = problem
        self.problem_mark = problem_mark
        self.note = note
        # warn is ignored

    def __str__(self):
        # type: () -> Any
        lines = []  # type: List[str]
        if self.context is not None:
            lines.append(self.context)
        if self.context_mark is not None and (
            self.problem is None
            or self.problem_mark is None
            or self.context_mark.name != self.problem_mark.name
            or self.context_mark.line != self.problem_mark.line
            or self.context_mark.column != self.problem_mark.column
        ):
            lines.append(str(self.context_mark))
        if self.problem is not None:
            lines.append(self.problem)
        if self.problem_mark is not None:
            lines.append(str(self.problem_mark))
        if self.note is not None and self.note:
            note = textwrap.dedent(self.note)
            lines.append(note)
        return "\n".join(lines) class ReusedAnchorWarning(YAMLWarning):
    pass _DEFAULT_YAML_VERSION = (1, 2)
PY2 = sys.version_info[0] == 2
PY3 = sys.version_info[0] == 3
    MAXSIZE = sys.maxsize
UNICODE_SIZE = 4 if sys.maxunicode > 65535 else 2
DBG_TOKEN = 1
DBG_EVENT = 2
DBG_NODE = 4
class ordereddict(OrderedDict):  # type: ignore
    class ObjectCounter(object):
class Nprint(object):
class MutableSliceableSequence(MutableSequence):  # type: ignore
        def insert(self, pos, key, value):
    def utf8(s):
    def to_str(s):
    def to_unicode(s):
    def utf8(s):
    def to_str(s):
    def to_unicode(s):
def with_metaclass(meta, *bases):
        def __init__(self):
        def __call__(self, k):
        def dump(self):
def dbg(val=None):
    def __init__(self, file_name=None):
    def __call__(self, *args, **kw):
    def set_max_print(self, i):
def check_namespace_char(ch):
def check_anchorname_char(ch):
def version_tnf(t1, t2=None):
    def __getitem__(self, index):
    def __setitem__(self, index, value):
    def __delitem__(self, index):
    def __getsingleitem__(self, index):
    def __setsingleitem__(self, index, value):
    def __delsingleitem__(self, index): class StreamStartEvent(Event):
    __slots__ = ('encoding',)

    def __init__(self, start_mark=None, end_mark=None, encoding=None, comment=None):
        # type: (Any, Any, Any, Any) -> None
        Event.__init__(self, start_mark, end_mark, comment)
        self.encoding = encoding class StreamEndEvent(Event):
    __slots__ = () class MappingStartEvent(CollectionStartEvent):
    __slots__ = () class MappingEndEvent(CollectionEndEvent):
    __slots__ = () class SequenceStartEvent(CollectionStartEvent):
    __slots__ = () class SequenceEndEvent(CollectionEndEvent):
    __slots__ = () class AliasEvent(NodeEvent):
    __slots__ = () class ScalarEvent(NodeEvent):
    __slots__ = 'tag', 'implicit', 'value', 'style'

    def __init__(
        self,
        anchor,
        tag,
        implicit,
        value,
        start_mark=None,
        end_mark=None,
        style=None,
        comment=None,
    ):
        # type: (Any, Any, Any, Any, Any, Any, Any, Any) -> None
        NodeEvent.__init__(self, anchor, start_mark, end_mark, comment)
        self.tag = tag
        self.implicit = implicit
        self.value = value
        self.style = style class MappingNode(CollectionNode):
    __slots__ = ('merge',)
    id = 'mapping'

    def __init__(
        self,
        tag,
        value,
        start_mark=None,
        end_mark=None,
        flow_style=None,
        comment=None,
        anchor=None,
    ):
        # type: (Any, Any, Any, Any, Any, Any, Any) -> None
        CollectionNode.__init__(
            self, tag, value, start_mark, end_mark, flow_style, comment, anchor
        )
        self.merge = None class ScalarNode(Node):
    """
    styles:
      ? -> set() ? key, no value
      " -> double quoted
      ' -> single quoted
      | -> literal style
      > -> folding style
    """

    __slots__ = ('style',)
    id = 'scalar'

    def __init__(
        self, tag, value, start_mark=None, end_mark=None, style=None, comment=None, anchor=None
    ):
        # type: (Any, Any, Any, Any, Any, Any, Any) -> None
        Node.__init__(self, tag, value, start_mark, end_mark, comment=comment, anchor=anchor)
        self.style = style class SequenceNode(CollectionNode):
    __slots__ = ()
    id = 'sequence'
import warnings
from .error import MarkedYAMLError, ReusedAnchorWarning
from .compat import utf8, nprint, nprintf  # NOQA
from .events import (
    StreamStartEvent,
    StreamEndEvent,
    MappingStartEvent,
    MappingEndEvent,
    SequenceStartEvent,
    SequenceEndEvent,
    AliasEvent,
    ScalarEvent,
)
from .nodes import MappingNode, ScalarNode, SequenceNode
    from typing import Any, Dict, Optional, List  # NOQA
    def get_node(self):
        # type: () -> Any
        # Get the root node of the next document.
        if not self.parser.check_event(StreamEndEvent):
            return self.compose_document()

    def get_single_node(self):
        # type: () -> Any
        # Drop the STREAM-START event.
        self.parser.get_event()

        # Compose a document if the stream is not empty.
        document = None  # type: Any
        if not self.parser.check_event(StreamEndEvent):
            document = self.compose_document()

        # Ensure that the stream contains no more documents.
        if not self.parser.check_event(StreamEndEvent):
            event = self.parser.get_event()
            raise ComposerError(
                "expected a single document in the stream",
                document.start_mark,
                "but found another document",
                event.start_mark,
            )

        # Drop the STREAM-END event.
        self.parser.get_event()

        return document

    def compose_document(self):
        # type: (Any) -> Any
        # Drop the DOCUMENT-START event.
        self.parser.get_event()

        # Compose the root node.
        node = self.compose_node(None, None)

        # Drop the DOCUMENT-END event.
        self.parser.get_event()

        self.anchors = {}
        return node

    def compose_node(self, parent, index):
        # type: (Any, Any) -> Any
        if self.parser.check_event(AliasEvent):
            event = self.parser.get_event()
            alias = event.anchor
            if alias not in self.anchors:
                raise ComposerError(
                    None,
                    None,
                    "found undefined alias %r" % utf8(alias),
                    event.start_mark,
                )
            return self.anchors[alias]
        event = self.parser.peek_event()
        anchor = event.anchor
        if anchor is not None:  # have an anchor
            if anchor in self.anchors:
                # raise ComposerError(
                #     "found duplicate anchor %r; first occurrence"
                #     % utf8(anchor), self.anchors[anchor].start_mark,
                #     "second occurrence", event.start_mark)
                ws = (
                    "\nfound duplicate anchor {!r}\nfirst occurrence {}\nsecond occurrence "
                    "{}".format(
                        (anchor), self.anchors[anchor].start_mark, event.start_mark
                    )
                )
                warnings.warn(ws, ReusedAnchorWarning)
        self.resolver.descend_resolver(parent, index)
        if self.parser.check_event(ScalarEvent):
            node = self.compose_scalar_node(anchor)
        elif self.parser.check_event(SequenceStartEvent):
            node = self.compose_sequence_node(anchor)
        elif self.parser.check_event(MappingStartEvent):
            node = self.compose_mapping_node(anchor)
        self.resolver.ascend_resolver()
        return node

    def compose_scalar_node(self, anchor):
        # type: (Any) -> Any
        event = self.parser.get_event()
        tag = event.tag
        if tag is None or tag == u"!":
            tag = self.resolver.resolve(ScalarNode, event.value, event.implicit)
        node = ScalarNode(
            tag,
            event.value,
            event.start_mark,
            event.end_mark,
            style=event.style,
            comment=event.comment,
            anchor=anchor,
        )
        if anchor is not None:
            self.anchors[anchor] = node
        return node

    def compose_sequence_node(self, anchor):
        # type: (Any) -> Any
        start_event = self.parser.get_event()
        tag = start_event.tag
        if tag is None or tag == u"!":
            tag = self.resolver.resolve(SequenceNode, None, start_event.implicit)
        node = SequenceNode(
            tag,
            [],
            start_event.start_mark,
            None,
            flow_style=start_event.flow_style,
            comment=start_event.comment,
            anchor=anchor,
        )
        if anchor is not None:
            self.anchors[anchor] = node
        index = 0

        while not self.parser.check_event(SequenceEndEvent):