def yaml_events(self, value, show_comments, show_choices): """Create a mapping event list, based on the values given.""" if value is None: value = dict() events = list() events.append(yaml.MappingStartEvent(anchor=None, tag=None, implicit=True)) if show_comments: comment = self._sub_elem.make_comment( show_choices=show_choices, show_name=False) events.append(yaml.CommentEvent(value=comment)) if value: for key, val in value.items(): # Add the mapping key. events.append(yaml.ScalarEvent(value=key, anchor=None, tag=None, implicit=(True, True))) # Add the mapping value. events.extend( self._sub_elem.yaml_events( val, show_comments, show_choices)) events.append(yaml.MappingEndEvent()) return events
def yaml_events(self, value, show_comments, show_choices): """Create the events for a ListElem.""" events = list() events.append(yaml.SequenceStartEvent( anchor=None, tag=None, implicit=True, flow_style=False, )) if show_comments and ( (not isinstance(self._sub_elem, ScalarElem) or self._sub_elem.help_text)): comment = self._sub_elem.make_comment( show_choices=show_choices, recursive=True, ) events.append(yaml.CommentEvent(value=comment)) if not value: value = self.type() # Value is expected to be a list of items at this point. for val in value: events.extend( self._sub_elem.yaml_events( value=val, show_comments=False, show_choices=show_choices)) events.append(yaml.SequenceEndEvent()) return events
def yaml_events(self, value, show_comments, show_choices): if value is None: value = dict() events = list() events.append(yaml.MappingStartEvent(anchor=None, tag=None, implicit=True)) for key, elem in self.config_elems.items(): if elem.hidden: continue # Don't output anything for Derived Elements if isinstance(elem, DerivedElem): continue val = value.get(key, None) if show_comments: comment = elem.make_comment(show_choices=show_choices) events.append(yaml.CommentEvent(value=comment)) # Add the mapping key events.append(yaml.ScalarEvent(value=key, anchor=None, tag=None, implicit=(True, True))) # Add the mapping value events.extend(elem.yaml_events(val, show_comments, show_choices)) events.append(yaml.MappingEndEvent()) return events
def yaml_events(self, value, show_comments, show_choices, comment_width=80): events = list() events.append( yaml.SequenceStartEvent( anchor=None, tag=None, implicit=True, flow_style=False, )) if show_comments: comment = self._sub_elem.make_comment(width=comment_width, show_choices=show_choices, show_name=False) events.append(yaml.CommentEvent(value=comment)) if value is not None: # Value is expected to be a list of items at this point. for v in value: events.extend( self._sub_elem.yaml_events(v, show_comments, show_choices, comment_width=comment_width)) else: events.extend( self._sub_elem.yaml_events(None, show_comments, show_choices, comment_width=comment_width)) events.append(yaml.SequenceEndEvent()) return events