Exemplo n.º 1
0
 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):
         node.value.append(self.compose_node(node, index))
         index += 1
     end_event = self.parser.get_event()
     if node.flow_style is True and end_event.comment is not None:
         if node.comment is not None:
             nprint(
                 'Warning: unexpected end_event commment in sequence '
                 'node {}'.format(node.flow_style)
             )
         node.comment = end_event.comment
     node.end_mark = end_event.end_mark
     self.check_end_doc_comment(end_event, node)
     return node
Exemplo n.º 2
0
 def emit(self, event):
     if dbg(DBG_EVENT):
         nprint(event)
     self.events.append(event)
     while not self.need_more_events():
         self.event = self.events.pop(0)
         self.state()
         self.event = None
Exemplo n.º 3
0
 def emit(self, event):
     if dbg(DBG_EVENT):
         nprint(event)
     self.events.append(event)
     while not self.need_more_events():
         self.event = self.events.pop(0)
         self.state()
         self.event = None
Exemplo n.º 4
0
 def serialize(self, node):
     if dbg(DBG_NODE):
         nprint('Serializing nodes')
         node.dump()
     if self.closed is None:
         raise SerializerError("serializer is not opened")
     elif self.closed:
         raise SerializerError("serializer is closed")
     self.emit(DocumentStartEvent(explicit=self.use_explicit_start,
                                  version=self.use_version,
                                  tags=self.use_tags))
     self.anchor_node(node)
     self.serialize_node(node, None, None)
     self.emit(DocumentEndEvent(explicit=self.use_explicit_end))
     self.serialized_nodes = {}
     self.anchors = {}
     self.last_anchor_id = 0
Exemplo n.º 5
0
 def serialize(self, node):
     if dbg(DBG_NODE):
         nprint('Serializing nodes')
         node.dump()
     if self.closed is None:
         raise SerializerError("serializer is not opened")
     elif self.closed:
         raise SerializerError("serializer is closed")
     self.emit(
         DocumentStartEvent(explicit=self.use_explicit_start,
                            version=self.use_version,
                            tags=self.use_tags))
     self.anchor_node(node)
     self.serialize_node(node, None, None)
     self.emit(DocumentEndEvent(explicit=self.use_explicit_end))
     self.serialized_nodes = {}
     self.anchors = {}
     self.last_anchor_id = 0