@classmethod def add_implicit_resolver(cls, tag, regexp, first): ifnot'yaml_implicit_resolvers'in cls.__dict__:
implicit_resolvers = {} for key in cls.yaml_implicit_resolvers:
implicit_resolvers[key] = cls.yaml_implicit_resolvers[key][:]
cls.yaml_implicit_resolvers = implicit_resolvers if first isNone:
first = [None] for ch in first:
cls.yaml_implicit_resolvers.setdefault(ch, []).append((tag, regexp))
@classmethod def add_path_resolver(cls, tag, path, kind=None): # Note: `add_path_resolver` is experimental. The API could be changed. # `new_path` is a pattern that is matched against the path from the # root to the node that is being considered. `node_path` elements are # tuples `(node_check, index_check)`. `node_check` is a node class: # `ScalarNode`, `SequenceNode`, `MappingNode` or `None`. `None` # matches any kind of a node. `index_check` could be `None`, a boolean # value, a string value, or a number. `None` and `False` match against # any _value_ of sequence and mapping nodes. `True` matches against # any _key_ of a mapping node. A string `index_check` matches against # a mapping value that corresponds to a scalar key which content is # equal to the `index_check` value. An integer `index_check` matches # against a sequence value with the index equal to `index_check`. ifnot'yaml_path_resolvers'in cls.__dict__:
cls.yaml_path_resolvers = cls.yaml_path_resolvers.copy()
new_path = [] for element in path: if isinstance(element, (list, tuple)): if len(element) == 2:
node_check, index_check = element elif len(element) == 1:
node_check = element[0]
index_check = True else: raise ResolverError("Invalid path element: %s" % element) else:
node_check = None
index_check = element if node_check is str:
node_check = ScalarNode elif node_check is list:
node_check = SequenceNode elif node_check is dict:
node_check = MappingNode elif node_check notin [ScalarNode, SequenceNode, MappingNode] \ andnot isinstance(node_check, str) \ and node_check isnotNone: raise ResolverError("Invalid node checker: %s" % node_check) ifnot isinstance(index_check, (str, int)) \ and index_check isnotNone: raise ResolverError("Invalid index checker: %s" % index_check)
new_path.append((node_check, index_check)) if kind is str:
kind = ScalarNode elif kind is list:
kind = SequenceNode elif kind is dict:
kind = MappingNode elif kind notin [ScalarNode, SequenceNode, MappingNode] \ and kind isnotNone: raise ResolverError("Invalid node kind: %s" % kind)
cls.yaml_path_resolvers[tuple(new_path), kind] = tag
def descend_resolver(self, current_node, current_index): ifnot self.yaml_path_resolvers: return
exact_paths = {}
prefix_paths = [] if current_node:
depth = len(self.resolver_prefix_paths) for path, kind in self.resolver_prefix_paths[-1]: if self.check_resolver_prefix(depth, path, kind,
current_node, current_index): if len(path) > depth:
prefix_paths.append((path, kind)) else:
exact_paths[kind] = self.yaml_path_resolvers[path, kind] else: for path, kind in self.yaml_path_resolvers: ifnot path:
exact_paths[kind] = self.yaml_path_resolvers[path, kind] else:
prefix_paths.append((path, kind))
self.resolver_exact_paths.append(exact_paths)
self.resolver_prefix_paths.append(prefix_paths)
def check_resolver_prefix(self, depth, path, kind,
current_node, current_index):
node_check, index_check = path[depth-1] if isinstance(node_check, str): if current_node.tag != node_check: return elif node_check isnotNone: ifnot isinstance(current_node, node_check): return if index_check isTrueand current_index isnotNone: return if (index_check isFalseor index_check isNone) \ and current_index isNone: return if isinstance(index_check, str): ifnot (isinstance(current_index, ScalarNode) and index_check == current_index.value): return elif isinstance(index_check, int) andnot isinstance(index_check, bool): if index_check != current_index: return returnTrue
def resolve(self, kind, value, implicit): if kind is ScalarNode and implicit[0]: if value == '':
resolvers = self.yaml_implicit_resolvers.get('', []) else:
resolvers = self.yaml_implicit_resolvers.get(value[0], [])
wildcard_resolvers = self.yaml_implicit_resolvers.get(None, []) for tag, regexp in resolvers + wildcard_resolvers: if regexp.match(value): return tag
implicit = implicit[1] if self.yaml_path_resolvers:
exact_paths = self.resolver_exact_paths[-1] if kind in exact_paths: return exact_paths[kind] ifNonein exact_paths: return exact_paths[None] if kind is ScalarNode: return self.DEFAULT_SCALAR_TAG elif kind is SequenceNode: return self.DEFAULT_SEQUENCE_TAG elif kind is MappingNode: return self.DEFAULT_MAPPING_TAG
# The following resolver is only for documentation purposes. It cannot work # because plain scalars cannot start with '!', '&', or '*'.
Resolver.add_implicit_resolver( 'tag:yaml.org,2002:yaml',
re.compile(r'^(?:!|&|\*)$'),
list('!&*'))
Messung V0.5
¤ Dauer der Verarbeitung: 0.16 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.