Mercurial > repos > shellac > sam_consensus_v3
annotate env/lib/python3.9/site-packages/ruamel/yaml/comments.py @ 0:4f3585e2f14b draft default tip
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
| author | shellac | 
|---|---|
| date | Mon, 22 Mar 2021 18:12:50 +0000 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 0 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1 # coding: utf-8 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 2 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 3 from __future__ import absolute_import, print_function | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 4 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 5 """ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 6 stuff to deal with comments and formatting on dict/list/ordereddict/set | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 7 these are not really related, formatting could be factored out as | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 8 a separate base | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 9 """ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 10 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 11 import sys | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 12 import copy | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 13 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 14 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 15 from ruamel.yaml.compat import ordereddict # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 16 from ruamel.yaml.compat import PY2, string_types, MutableSliceableSequence | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 17 from ruamel.yaml.scalarstring import ScalarString | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 18 from ruamel.yaml.anchor import Anchor | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 19 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 20 if PY2: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 21 from collections import MutableSet, Sized, Set, Mapping | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 22 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 23 from collections.abc import MutableSet, Sized, Set, Mapping | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 24 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 25 if False: # MYPY | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 26 from typing import Any, Dict, Optional, List, Union, Optional, Iterator # NOQA | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 27 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 28 # fmt: off | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 29 __all__ = ['CommentedSeq', 'CommentedKeySeq', | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 30 'CommentedMap', 'CommentedOrderedMap', | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 31 'CommentedSet', 'comment_attrib', 'merge_attrib'] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 32 # fmt: on | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 33 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 34 comment_attrib = '_yaml_comment' | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 35 format_attrib = '_yaml_format' | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 36 line_col_attrib = '_yaml_line_col' | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 37 merge_attrib = '_yaml_merge' | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 38 tag_attrib = '_yaml_tag' | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 39 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 40 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 41 class Comment(object): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 42 # sys.getsize tested the Comment objects, __slots__ makes them bigger | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 43 # and adding self.end did not matter | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 44 __slots__ = 'comment', '_items', '_end', '_start' | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 45 attrib = comment_attrib | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 46 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 47 def __init__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 48 # type: () -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 49 self.comment = None # [post, [pre]] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 50 # map key (mapping/omap/dict) or index (sequence/list) to a list of | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 51 # dict: post_key, pre_key, post_value, pre_value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 52 # list: pre item, post item | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 53 self._items = {} # type: Dict[Any, Any] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 54 # self._start = [] # should not put these on first item | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 55 self._end = [] # type: List[Any] # end of document comments | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 56 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 57 def __str__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 58 # type: () -> str | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 59 if bool(self._end): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 60 end = ',\n end=' + str(self._end) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 61 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 62 end = "" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 63 return 'Comment(comment={0},\n items={1}{2})'.format(self.comment, self._items, end) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 64 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 65 @property | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 66 def items(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 67 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 68 return self._items | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 69 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 70 @property | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 71 def end(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 72 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 73 return self._end | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 74 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 75 @end.setter | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 76 def end(self, value): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 77 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 78 self._end = value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 79 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 80 @property | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 81 def start(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 82 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 83 return self._start | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 84 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 85 @start.setter | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 86 def start(self, value): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 87 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 88 self._start = value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 89 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 90 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 91 # to distinguish key from None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 92 def NoComment(): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 93 # type: () -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 94 pass | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 95 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 96 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 97 class Format(object): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 98 __slots__ = ('_flow_style',) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 99 attrib = format_attrib | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 100 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 101 def __init__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 102 # type: () -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 103 self._flow_style = None # type: Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 104 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 105 def set_flow_style(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 106 # type: () -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 107 self._flow_style = True | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 108 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 109 def set_block_style(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 110 # type: () -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 111 self._flow_style = False | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 112 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 113 def flow_style(self, default=None): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 114 # type: (Optional[Any]) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 115 """if default (the flow_style) is None, the flow style tacked on to | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 116 the object explicitly will be taken. If that is None as well the | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 117 default flow style rules the format down the line, or the type | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 118 of the constituent values (simple -> flow, map/list -> block)""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 119 if self._flow_style is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 120 return default | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 121 return self._flow_style | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 122 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 123 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 124 class LineCol(object): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 125 attrib = line_col_attrib | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 126 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 127 def __init__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 128 # type: () -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 129 self.line = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 130 self.col = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 131 self.data = None # type: Optional[Dict[Any, Any]] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 132 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 133 def add_kv_line_col(self, key, data): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 134 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 135 if self.data is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 136 self.data = {} | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 137 self.data[key] = data | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 138 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 139 def key(self, k): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 140 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 141 return self._kv(k, 0, 1) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 142 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 143 def value(self, k): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 144 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 145 return self._kv(k, 2, 3) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 146 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 147 def _kv(self, k, x0, x1): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 148 # type: (Any, Any, Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 149 if self.data is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 150 return None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 151 data = self.data[k] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 152 return data[x0], data[x1] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 153 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 154 def item(self, idx): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 155 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 156 if self.data is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 157 return None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 158 return self.data[idx][0], self.data[idx][1] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 159 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 160 def add_idx_line_col(self, key, data): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 161 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 162 if self.data is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 163 self.data = {} | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 164 self.data[key] = data | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 165 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 166 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 167 class Tag(object): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 168 """store tag information for roundtripping""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 169 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 170 __slots__ = ('value',) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 171 attrib = tag_attrib | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 172 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 173 def __init__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 174 # type: () -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 175 self.value = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 176 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 177 def __repr__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 178 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 179 return '{0.__class__.__name__}({0.value!r})'.format(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 180 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 181 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 182 class CommentedBase(object): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 183 @property | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 184 def ca(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 185 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 186 if not hasattr(self, Comment.attrib): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 187 setattr(self, Comment.attrib, Comment()) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 188 return getattr(self, Comment.attrib) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 189 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 190 def yaml_end_comment_extend(self, comment, clear=False): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 191 # type: (Any, bool) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 192 if comment is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 193 return | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 194 if clear or self.ca.end is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 195 self.ca.end = [] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 196 self.ca.end.extend(comment) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 197 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 198 def yaml_key_comment_extend(self, key, comment, clear=False): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 199 # type: (Any, Any, bool) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 200 r = self.ca._items.setdefault(key, [None, None, None, None]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 201 if clear or r[1] is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 202 if comment[1] is not None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 203 assert isinstance(comment[1], list) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 204 r[1] = comment[1] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 205 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 206 r[1].extend(comment[0]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 207 r[0] = comment[0] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 208 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 209 def yaml_value_comment_extend(self, key, comment, clear=False): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 210 # type: (Any, Any, bool) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 211 r = self.ca._items.setdefault(key, [None, None, None, None]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 212 if clear or r[3] is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 213 if comment[1] is not None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 214 assert isinstance(comment[1], list) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 215 r[3] = comment[1] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 216 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 217 r[3].extend(comment[0]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 218 r[2] = comment[0] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 219 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 220 def yaml_set_start_comment(self, comment, indent=0): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 221 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 222 """overwrites any preceding comment lines on an object | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 223 expects comment to be without `#` and possible have multiple lines | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 224 """ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 225 from .error import CommentMark | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 226 from .tokens import CommentToken | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 227 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 228 pre_comments = self._yaml_get_pre_comment() | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 229 if comment[-1] == '\n': | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 230 comment = comment[:-1] # strip final newline if there | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 231 start_mark = CommentMark(indent) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 232 for com in comment.split('\n'): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 233 pre_comments.append(CommentToken('# ' + com + '\n', start_mark, None)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 234 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 235 def yaml_set_comment_before_after_key( | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 236 self, key, before=None, indent=0, after=None, after_indent=None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 237 ): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 238 # type: (Any, Any, Any, Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 239 """ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 240 expects comment (before/after) to be without `#` and possible have multiple lines | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 241 """ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 242 from ruamel.yaml.error import CommentMark | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 243 from ruamel.yaml.tokens import CommentToken | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 244 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 245 def comment_token(s, mark): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 246 # type: (Any, Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 247 # handle empty lines as having no comment | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 248 return CommentToken(('# ' if s else "") + s + '\n', mark, None) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 249 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 250 if after_indent is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 251 after_indent = indent + 2 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 252 if before and (len(before) > 1) and before[-1] == '\n': | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 253 before = before[:-1] # strip final newline if there | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 254 if after and after[-1] == '\n': | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 255 after = after[:-1] # strip final newline if there | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 256 start_mark = CommentMark(indent) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 257 c = self.ca.items.setdefault(key, [None, [], None, None]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 258 if before == '\n': | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 259 c[1].append(comment_token("", start_mark)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 260 elif before: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 261 for com in before.split('\n'): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 262 c[1].append(comment_token(com, start_mark)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 263 if after: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 264 start_mark = CommentMark(after_indent) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 265 if c[3] is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 266 c[3] = [] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 267 for com in after.split('\n'): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 268 c[3].append(comment_token(com, start_mark)) # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 269 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 270 @property | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 271 def fa(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 272 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 273 """format attribute | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 274 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 275 set_flow_style()/set_block_style()""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 276 if not hasattr(self, Format.attrib): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 277 setattr(self, Format.attrib, Format()) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 278 return getattr(self, Format.attrib) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 279 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 280 def yaml_add_eol_comment(self, comment, key=NoComment, column=None): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 281 # type: (Any, Optional[Any], Optional[Any]) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 282 """ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 283 there is a problem as eol comments should start with ' #' | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 284 (but at the beginning of the line the space doesn't have to be before | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 285 the #. The column index is for the # mark | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 286 """ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 287 from .tokens import CommentToken | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 288 from .error import CommentMark | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 289 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 290 if column is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 291 try: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 292 column = self._yaml_get_column(key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 293 except AttributeError: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 294 column = 0 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 295 if comment[0] != '#': | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 296 comment = '# ' + comment | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 297 if column is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 298 if comment[0] == '#': | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 299 comment = ' ' + comment | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 300 column = 0 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 301 start_mark = CommentMark(column) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 302 ct = [CommentToken(comment, start_mark, None), None] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 303 self._yaml_add_eol_comment(ct, key=key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 304 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 305 @property | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 306 def lc(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 307 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 308 if not hasattr(self, LineCol.attrib): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 309 setattr(self, LineCol.attrib, LineCol()) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 310 return getattr(self, LineCol.attrib) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 311 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 312 def _yaml_set_line_col(self, line, col): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 313 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 314 self.lc.line = line | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 315 self.lc.col = col | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 316 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 317 def _yaml_set_kv_line_col(self, key, data): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 318 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 319 self.lc.add_kv_line_col(key, data) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 320 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 321 def _yaml_set_idx_line_col(self, key, data): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 322 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 323 self.lc.add_idx_line_col(key, data) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 324 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 325 @property | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 326 def anchor(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 327 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 328 if not hasattr(self, Anchor.attrib): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 329 setattr(self, Anchor.attrib, Anchor()) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 330 return getattr(self, Anchor.attrib) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 331 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 332 def yaml_anchor(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 333 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 334 if not hasattr(self, Anchor.attrib): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 335 return None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 336 return self.anchor | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 337 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 338 def yaml_set_anchor(self, value, always_dump=False): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 339 # type: (Any, bool) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 340 self.anchor.value = value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 341 self.anchor.always_dump = always_dump | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 342 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 343 @property | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 344 def tag(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 345 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 346 if not hasattr(self, Tag.attrib): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 347 setattr(self, Tag.attrib, Tag()) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 348 return getattr(self, Tag.attrib) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 349 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 350 def yaml_set_tag(self, value): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 351 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 352 self.tag.value = value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 353 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 354 def copy_attributes(self, t, memo=None): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 355 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 356 # fmt: off | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 357 for a in [Comment.attrib, Format.attrib, LineCol.attrib, Anchor.attrib, | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 358 Tag.attrib, merge_attrib]: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 359 if hasattr(self, a): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 360 if memo is not None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 361 setattr(t, a, copy.deepcopy(getattr(self, a, memo))) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 362 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 363 setattr(t, a, getattr(self, a)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 364 # fmt: on | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 365 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 366 def _yaml_add_eol_comment(self, comment, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 367 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 368 raise NotImplementedError | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 369 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 370 def _yaml_get_pre_comment(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 371 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 372 raise NotImplementedError | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 373 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 374 def _yaml_get_column(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 375 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 376 raise NotImplementedError | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 377 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 378 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 379 class CommentedSeq(MutableSliceableSequence, list, CommentedBase): # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 380 __slots__ = (Comment.attrib, '_lst') | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 381 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 382 def __init__(self, *args, **kw): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 383 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 384 list.__init__(self, *args, **kw) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 385 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 386 def __getsingleitem__(self, idx): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 387 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 388 return list.__getitem__(self, idx) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 389 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 390 def __setsingleitem__(self, idx, value): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 391 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 392 # try to preserve the scalarstring type if setting an existing key to a new value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 393 if idx < len(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 394 if ( | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 395 isinstance(value, string_types) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 396 and not isinstance(value, ScalarString) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 397 and isinstance(self[idx], ScalarString) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 398 ): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 399 value = type(self[idx])(value) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 400 list.__setitem__(self, idx, value) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 401 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 402 def __delsingleitem__(self, idx=None): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 403 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 404 list.__delitem__(self, idx) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 405 self.ca.items.pop(idx, None) # might not be there -> default value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 406 for list_index in sorted(self.ca.items): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 407 if list_index < idx: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 408 continue | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 409 self.ca.items[list_index - 1] = self.ca.items.pop(list_index) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 410 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 411 def __len__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 412 # type: () -> int | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 413 return list.__len__(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 414 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 415 def insert(self, idx, val): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 416 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 417 """the comments after the insertion have to move forward""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 418 list.insert(self, idx, val) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 419 for list_index in sorted(self.ca.items, reverse=True): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 420 if list_index < idx: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 421 break | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 422 self.ca.items[list_index + 1] = self.ca.items.pop(list_index) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 423 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 424 def extend(self, val): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 425 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 426 list.extend(self, val) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 427 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 428 def __eq__(self, other): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 429 # type: (Any) -> bool | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 430 return list.__eq__(self, other) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 431 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 432 def _yaml_add_comment(self, comment, key=NoComment): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 433 # type: (Any, Optional[Any]) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 434 if key is not NoComment: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 435 self.yaml_key_comment_extend(key, comment) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 436 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 437 self.ca.comment = comment | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 438 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 439 def _yaml_add_eol_comment(self, comment, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 440 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 441 self._yaml_add_comment(comment, key=key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 442 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 443 def _yaml_get_columnX(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 444 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 445 return self.ca.items[key][0].start_mark.column | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 446 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 447 def _yaml_get_column(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 448 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 449 column = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 450 sel_idx = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 451 pre, post = key - 1, key + 1 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 452 if pre in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 453 sel_idx = pre | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 454 elif post in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 455 sel_idx = post | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 456 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 457 # self.ca.items is not ordered | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 458 for row_idx, _k1 in enumerate(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 459 if row_idx >= key: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 460 break | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 461 if row_idx not in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 462 continue | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 463 sel_idx = row_idx | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 464 if sel_idx is not None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 465 column = self._yaml_get_columnX(sel_idx) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 466 return column | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 467 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 468 def _yaml_get_pre_comment(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 469 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 470 pre_comments = [] # type: List[Any] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 471 if self.ca.comment is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 472 self.ca.comment = [None, pre_comments] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 473 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 474 self.ca.comment[1] = pre_comments | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 475 return pre_comments | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 476 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 477 def __deepcopy__(self, memo): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 478 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 479 res = self.__class__() | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 480 memo[id(self)] = res | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 481 for k in self: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 482 res.append(copy.deepcopy(k, memo)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 483 self.copy_attributes(res, memo=memo) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 484 return res | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 485 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 486 def __add__(self, other): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 487 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 488 return list.__add__(self, other) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 489 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 490 def sort(self, key=None, reverse=False): # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 491 # type: (Any, bool) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 492 if key is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 493 tmp_lst = sorted(zip(self, range(len(self))), reverse=reverse) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 494 list.__init__(self, [x[0] for x in tmp_lst]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 495 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 496 tmp_lst = sorted( | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 497 zip(map(key, list.__iter__(self)), range(len(self))), reverse=reverse | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 498 ) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 499 list.__init__(self, [list.__getitem__(self, x[1]) for x in tmp_lst]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 500 itm = self.ca.items | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 501 self.ca._items = {} | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 502 for idx, x in enumerate(tmp_lst): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 503 old_index = x[1] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 504 if old_index in itm: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 505 self.ca.items[idx] = itm[old_index] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 506 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 507 def __repr__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 508 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 509 return list.__repr__(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 510 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 511 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 512 class CommentedKeySeq(tuple, CommentedBase): # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 513 """This primarily exists to be able to roundtrip keys that are sequences""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 514 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 515 def _yaml_add_comment(self, comment, key=NoComment): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 516 # type: (Any, Optional[Any]) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 517 if key is not NoComment: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 518 self.yaml_key_comment_extend(key, comment) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 519 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 520 self.ca.comment = comment | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 521 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 522 def _yaml_add_eol_comment(self, comment, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 523 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 524 self._yaml_add_comment(comment, key=key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 525 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 526 def _yaml_get_columnX(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 527 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 528 return self.ca.items[key][0].start_mark.column | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 529 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 530 def _yaml_get_column(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 531 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 532 column = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 533 sel_idx = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 534 pre, post = key - 1, key + 1 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 535 if pre in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 536 sel_idx = pre | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 537 elif post in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 538 sel_idx = post | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 539 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 540 # self.ca.items is not ordered | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 541 for row_idx, _k1 in enumerate(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 542 if row_idx >= key: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 543 break | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 544 if row_idx not in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 545 continue | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 546 sel_idx = row_idx | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 547 if sel_idx is not None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 548 column = self._yaml_get_columnX(sel_idx) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 549 return column | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 550 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 551 def _yaml_get_pre_comment(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 552 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 553 pre_comments = [] # type: List[Any] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 554 if self.ca.comment is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 555 self.ca.comment = [None, pre_comments] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 556 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 557 self.ca.comment[1] = pre_comments | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 558 return pre_comments | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 559 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 560 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 561 class CommentedMapView(Sized): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 562 __slots__ = ('_mapping',) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 563 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 564 def __init__(self, mapping): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 565 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 566 self._mapping = mapping | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 567 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 568 def __len__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 569 # type: () -> int | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 570 count = len(self._mapping) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 571 return count | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 572 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 573 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 574 class CommentedMapKeysView(CommentedMapView, Set): # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 575 __slots__ = () | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 576 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 577 @classmethod | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 578 def _from_iterable(self, it): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 579 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 580 return set(it) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 581 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 582 def __contains__(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 583 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 584 return key in self._mapping | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 585 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 586 def __iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 587 # type: () -> Any # yield from self._mapping # not in py27, pypy | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 588 # for x in self._mapping._keys(): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 589 for x in self._mapping: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 590 yield x | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 591 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 592 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 593 class CommentedMapItemsView(CommentedMapView, Set): # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 594 __slots__ = () | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 595 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 596 @classmethod | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 597 def _from_iterable(self, it): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 598 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 599 return set(it) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 600 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 601 def __contains__(self, item): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 602 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 603 key, value = item | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 604 try: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 605 v = self._mapping[key] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 606 except KeyError: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 607 return False | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 608 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 609 return v == value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 610 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 611 def __iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 612 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 613 for key in self._mapping._keys(): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 614 yield (key, self._mapping[key]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 615 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 616 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 617 class CommentedMapValuesView(CommentedMapView): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 618 __slots__ = () | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 619 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 620 def __contains__(self, value): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 621 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 622 for key in self._mapping: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 623 if value == self._mapping[key]: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 624 return True | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 625 return False | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 626 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 627 def __iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 628 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 629 for key in self._mapping._keys(): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 630 yield self._mapping[key] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 631 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 632 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 633 class CommentedMap(ordereddict, CommentedBase): # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 634 __slots__ = (Comment.attrib, '_ok', '_ref') | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 635 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 636 def __init__(self, *args, **kw): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 637 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 638 self._ok = set() # type: MutableSet[Any] # own keys | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 639 self._ref = [] # type: List[CommentedMap] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 640 ordereddict.__init__(self, *args, **kw) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 641 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 642 def _yaml_add_comment(self, comment, key=NoComment, value=NoComment): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 643 # type: (Any, Optional[Any], Optional[Any]) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 644 """values is set to key to indicate a value attachment of comment""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 645 if key is not NoComment: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 646 self.yaml_key_comment_extend(key, comment) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 647 return | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 648 if value is not NoComment: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 649 self.yaml_value_comment_extend(value, comment) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 650 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 651 self.ca.comment = comment | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 652 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 653 def _yaml_add_eol_comment(self, comment, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 654 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 655 """add on the value line, with value specified by the key""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 656 self._yaml_add_comment(comment, value=key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 657 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 658 def _yaml_get_columnX(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 659 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 660 return self.ca.items[key][2].start_mark.column | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 661 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 662 def _yaml_get_column(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 663 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 664 column = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 665 sel_idx = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 666 pre, post, last = None, None, None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 667 for x in self: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 668 if pre is not None and x != key: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 669 post = x | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 670 break | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 671 if x == key: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 672 pre = last | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 673 last = x | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 674 if pre in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 675 sel_idx = pre | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 676 elif post in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 677 sel_idx = post | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 678 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 679 # self.ca.items is not ordered | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 680 for k1 in self: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 681 if k1 >= key: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 682 break | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 683 if k1 not in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 684 continue | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 685 sel_idx = k1 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 686 if sel_idx is not None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 687 column = self._yaml_get_columnX(sel_idx) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 688 return column | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 689 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 690 def _yaml_get_pre_comment(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 691 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 692 pre_comments = [] # type: List[Any] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 693 if self.ca.comment is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 694 self.ca.comment = [None, pre_comments] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 695 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 696 self.ca.comment[1] = pre_comments | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 697 return pre_comments | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 698 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 699 def update(self, vals): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 700 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 701 try: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 702 ordereddict.update(self, vals) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 703 except TypeError: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 704 # probably a dict that is used | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 705 for x in vals: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 706 self[x] = vals[x] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 707 try: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 708 self._ok.update(vals.keys()) # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 709 except AttributeError: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 710 # assume a list/tuple of two element lists/tuples | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 711 for x in vals: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 712 self._ok.add(x[0]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 713 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 714 def insert(self, pos, key, value, comment=None): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 715 # type: (Any, Any, Any, Optional[Any]) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 716 """insert key value into given position | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 717 attach comment if provided | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 718 """ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 719 ordereddict.insert(self, pos, key, value) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 720 self._ok.add(key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 721 if comment is not None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 722 self.yaml_add_eol_comment(comment, key=key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 723 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 724 def mlget(self, key, default=None, list_ok=False): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 725 # type: (Any, Any, Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 726 """multi-level get that expects dicts within dicts""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 727 if not isinstance(key, list): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 728 return self.get(key, default) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 729 # assume that the key is a list of recursively accessible dicts | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 730 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 731 def get_one_level(key_list, level, d): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 732 # type: (Any, Any, Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 733 if not list_ok: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 734 assert isinstance(d, dict) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 735 if level >= len(key_list): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 736 if level > len(key_list): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 737 raise IndexError | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 738 return d[key_list[level - 1]] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 739 return get_one_level(key_list, level + 1, d[key_list[level - 1]]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 740 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 741 try: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 742 return get_one_level(key, 1, self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 743 except KeyError: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 744 return default | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 745 except (TypeError, IndexError): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 746 if not list_ok: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 747 raise | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 748 return default | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 749 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 750 def __getitem__(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 751 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 752 try: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 753 return ordereddict.__getitem__(self, key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 754 except KeyError: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 755 for merged in getattr(self, merge_attrib, []): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 756 if key in merged[1]: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 757 return merged[1][key] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 758 raise | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 759 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 760 def __setitem__(self, key, value): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 761 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 762 # try to preserve the scalarstring type if setting an existing key to a new value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 763 if key in self: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 764 if ( | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 765 isinstance(value, string_types) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 766 and not isinstance(value, ScalarString) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 767 and isinstance(self[key], ScalarString) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 768 ): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 769 value = type(self[key])(value) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 770 ordereddict.__setitem__(self, key, value) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 771 self._ok.add(key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 772 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 773 def _unmerged_contains(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 774 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 775 if key in self._ok: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 776 return True | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 777 return None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 778 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 779 def __contains__(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 780 # type: (Any) -> bool | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 781 return bool(ordereddict.__contains__(self, key)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 782 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 783 def get(self, key, default=None): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 784 # type: (Any, Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 785 try: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 786 return self.__getitem__(key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 787 except: # NOQA | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 788 return default | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 789 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 790 def __repr__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 791 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 792 return ordereddict.__repr__(self).replace('CommentedMap', 'ordereddict') | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 793 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 794 def non_merged_items(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 795 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 796 for x in ordereddict.__iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 797 if x in self._ok: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 798 yield x, ordereddict.__getitem__(self, x) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 799 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 800 def __delitem__(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 801 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 802 # for merged in getattr(self, merge_attrib, []): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 803 # if key in merged[1]: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 804 # value = merged[1][key] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 805 # break | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 806 # else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 807 # # not found in merged in stuff | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 808 # ordereddict.__delitem__(self, key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 809 # for referer in self._ref: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 810 # referer.update_key_value(key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 811 # return | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 812 # | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 813 # ordereddict.__setitem__(self, key, value) # merge might have different value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 814 # self._ok.discard(key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 815 self._ok.discard(key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 816 ordereddict.__delitem__(self, key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 817 for referer in self._ref: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 818 referer.update_key_value(key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 819 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 820 def __iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 821 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 822 for x in ordereddict.__iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 823 yield x | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 824 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 825 def _keys(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 826 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 827 for x in ordereddict.__iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 828 yield x | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 829 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 830 def __len__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 831 # type: () -> int | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 832 return int(ordereddict.__len__(self)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 833 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 834 def __eq__(self, other): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 835 # type: (Any) -> bool | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 836 return bool(dict(self) == other) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 837 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 838 if PY2: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 839 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 840 def keys(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 841 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 842 return list(self._keys()) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 843 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 844 def iterkeys(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 845 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 846 return self._keys() | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 847 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 848 def viewkeys(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 849 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 850 return CommentedMapKeysView(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 851 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 852 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 853 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 854 def keys(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 855 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 856 return CommentedMapKeysView(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 857 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 858 if PY2: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 859 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 860 def _values(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 861 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 862 for x in ordereddict.__iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 863 yield ordereddict.__getitem__(self, x) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 864 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 865 def values(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 866 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 867 return list(self._values()) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 868 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 869 def itervalues(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 870 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 871 return self._values() | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 872 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 873 def viewvalues(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 874 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 875 return CommentedMapValuesView(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 876 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 877 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 878 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 879 def values(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 880 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 881 return CommentedMapValuesView(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 882 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 883 def _items(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 884 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 885 for x in ordereddict.__iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 886 yield x, ordereddict.__getitem__(self, x) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 887 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 888 if PY2: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 889 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 890 def items(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 891 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 892 return list(self._items()) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 893 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 894 def iteritems(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 895 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 896 return self._items() | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 897 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 898 def viewitems(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 899 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 900 return CommentedMapItemsView(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 901 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 902 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 903 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 904 def items(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 905 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 906 return CommentedMapItemsView(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 907 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 908 @property | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 909 def merge(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 910 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 911 if not hasattr(self, merge_attrib): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 912 setattr(self, merge_attrib, []) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 913 return getattr(self, merge_attrib) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 914 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 915 def copy(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 916 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 917 x = type(self)() # update doesn't work | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 918 for k, v in self._items(): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 919 x[k] = v | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 920 self.copy_attributes(x) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 921 return x | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 922 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 923 def add_referent(self, cm): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 924 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 925 if cm not in self._ref: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 926 self._ref.append(cm) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 927 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 928 def add_yaml_merge(self, value): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 929 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 930 for v in value: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 931 v[1].add_referent(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 932 for k, v in v[1].items(): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 933 if ordereddict.__contains__(self, k): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 934 continue | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 935 ordereddict.__setitem__(self, k, v) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 936 self.merge.extend(value) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 937 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 938 def update_key_value(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 939 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 940 if key in self._ok: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 941 return | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 942 for v in self.merge: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 943 if key in v[1]: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 944 ordereddict.__setitem__(self, key, v[1][key]) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 945 return | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 946 ordereddict.__delitem__(self, key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 947 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 948 def __deepcopy__(self, memo): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 949 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 950 res = self.__class__() | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 951 memo[id(self)] = res | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 952 for k in self: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 953 res[k] = copy.deepcopy(self[k], memo) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 954 self.copy_attributes(res, memo=memo) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 955 return res | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 956 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 957 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 958 # based on brownie mappings | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 959 @classmethod # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 960 def raise_immutable(cls, *args, **kwargs): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 961 # type: (Any, *Any, **Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 962 raise TypeError('{} objects are immutable'.format(cls.__name__)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 963 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 964 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 965 class CommentedKeyMap(CommentedBase, Mapping): # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 966 __slots__ = Comment.attrib, '_od' | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 967 """This primarily exists to be able to roundtrip keys that are mappings""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 968 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 969 def __init__(self, *args, **kw): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 970 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 971 if hasattr(self, '_od'): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 972 raise_immutable(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 973 try: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 974 self._od = ordereddict(*args, **kw) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 975 except TypeError: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 976 if PY2: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 977 self._od = ordereddict(args[0].items()) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 978 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 979 raise | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 980 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 981 __delitem__ = __setitem__ = clear = pop = popitem = setdefault = update = raise_immutable | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 982 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 983 # need to implement __getitem__, __iter__ and __len__ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 984 def __getitem__(self, index): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 985 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 986 return self._od[index] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 987 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 988 def __iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 989 # type: () -> Iterator[Any] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 990 for x in self._od.__iter__(): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 991 yield x | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 992 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 993 def __len__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 994 # type: () -> int | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 995 return len(self._od) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 996 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 997 def __hash__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 998 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 999 return hash(tuple(self.items())) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1000 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1001 def __repr__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1002 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1003 if not hasattr(self, merge_attrib): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1004 return self._od.__repr__() | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1005 return 'ordereddict(' + repr(list(self._od.items())) + ')' | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1006 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1007 @classmethod | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1008 def fromkeys(keys, v=None): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1009 # type: (Any, Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1010 return CommentedKeyMap(dict.fromkeys(keys, v)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1011 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1012 def _yaml_add_comment(self, comment, key=NoComment): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1013 # type: (Any, Optional[Any]) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1014 if key is not NoComment: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1015 self.yaml_key_comment_extend(key, comment) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1016 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1017 self.ca.comment = comment | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1018 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1019 def _yaml_add_eol_comment(self, comment, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1020 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1021 self._yaml_add_comment(comment, key=key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1022 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1023 def _yaml_get_columnX(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1024 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1025 return self.ca.items[key][0].start_mark.column | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1026 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1027 def _yaml_get_column(self, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1028 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1029 column = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1030 sel_idx = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1031 pre, post = key - 1, key + 1 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1032 if pre in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1033 sel_idx = pre | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1034 elif post in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1035 sel_idx = post | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1036 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1037 # self.ca.items is not ordered | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1038 for row_idx, _k1 in enumerate(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1039 if row_idx >= key: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1040 break | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1041 if row_idx not in self.ca.items: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1042 continue | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1043 sel_idx = row_idx | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1044 if sel_idx is not None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1045 column = self._yaml_get_columnX(sel_idx) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1046 return column | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1047 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1048 def _yaml_get_pre_comment(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1049 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1050 pre_comments = [] # type: List[Any] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1051 if self.ca.comment is None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1052 self.ca.comment = [None, pre_comments] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1053 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1054 self.ca.comment[1] = pre_comments | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1055 return pre_comments | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1056 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1057 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1058 class CommentedOrderedMap(CommentedMap): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1059 __slots__ = (Comment.attrib,) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1060 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1061 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1062 class CommentedSet(MutableSet, CommentedBase): # type: ignore # NOQA | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1063 __slots__ = Comment.attrib, 'odict' | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1064 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1065 def __init__(self, values=None): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1066 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1067 self.odict = ordereddict() | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1068 MutableSet.__init__(self) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1069 if values is not None: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1070 self |= values # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1071 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1072 def _yaml_add_comment(self, comment, key=NoComment, value=NoComment): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1073 # type: (Any, Optional[Any], Optional[Any]) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1074 """values is set to key to indicate a value attachment of comment""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1075 if key is not NoComment: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1076 self.yaml_key_comment_extend(key, comment) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1077 return | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1078 if value is not NoComment: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1079 self.yaml_value_comment_extend(value, comment) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1080 else: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1081 self.ca.comment = comment | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1082 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1083 def _yaml_add_eol_comment(self, comment, key): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1084 # type: (Any, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1085 """add on the value line, with value specified by the key""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1086 self._yaml_add_comment(comment, value=key) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1087 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1088 def add(self, value): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1089 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1090 """Add an element.""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1091 self.odict[value] = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1092 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1093 def discard(self, value): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1094 # type: (Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1095 """Remove an element. Do not raise an exception if absent.""" | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1096 del self.odict[value] | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1097 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1098 def __contains__(self, x): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1099 # type: (Any) -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1100 return x in self.odict | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1101 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1102 def __iter__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1103 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1104 for x in self.odict: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1105 yield x | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1106 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1107 def __len__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1108 # type: () -> int | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1109 return len(self.odict) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1110 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1111 def __repr__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1112 # type: () -> str | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1113 return 'set({0!r})'.format(self.odict.keys()) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1114 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1115 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1116 class TaggedScalar(CommentedBase): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1117 # the value and style attributes are set during roundtrip construction | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1118 def __init__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1119 # type: () -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1120 self.value = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1121 self.style = None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1122 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1123 def __str__(self): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1124 # type: () -> Any | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1125 return self.value | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1126 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1127 | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1128 def dump_comments(d, name="", sep='.', out=sys.stdout): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1129 # type: (Any, str, str, Any) -> None | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1130 """ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1131 recursively dump comments, all but the toplevel preceded by the path | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1132 in dotted form x.0.a | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1133 """ | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1134 if isinstance(d, dict) and hasattr(d, 'ca'): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1135 if name: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1136 sys.stdout.write('{}\n'.format(name)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1137 out.write('{}\n'.format(d.ca)) # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1138 for k in d: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1139 dump_comments(d[k], name=(name + sep + k) if name else k, sep=sep, out=out) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1140 elif isinstance(d, list) and hasattr(d, 'ca'): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1141 if name: | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1142 sys.stdout.write('{}\n'.format(name)) | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1143 out.write('{}\n'.format(d.ca)) # type: ignore | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1144 for idx, k in enumerate(d): | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1145 dump_comments( | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1146 k, name=(name + sep + str(idx)) if name else str(idx), sep=sep, out=out | 
| 
4f3585e2f14b
"planemo upload commit 60cee0fc7c0cda8592644e1aad72851dec82c959"
 shellac parents: diff
changeset | 1147 ) | 
