7 __all__ = [
'BaseResolver',
'Resolver']
19 DEFAULT_SCALAR_TAG =
u'tag:yaml.org,2002:str'
20 DEFAULT_SEQUENCE_TAG =
u'tag:yaml.org,2002:seq'
21 DEFAULT_MAPPING_TAG =
u'tag:yaml.org,2002:map'
23 yaml_implicit_resolvers = {}
24 yaml_path_resolvers = {}
31 if not 'yaml_implicit_resolvers' in cls.__dict__:
32 cls.yaml_implicit_resolvers = cls.yaml_implicit_resolvers.copy()
36 cls.yaml_implicit_resolvers.setdefault(ch, []).append((tag, regexp))
37 add_implicit_resolver = classmethod(add_implicit_resolver)
52 if not 'yaml_path_resolvers' in cls.__dict__:
53 cls.yaml_path_resolvers = cls.yaml_path_resolvers.copy()
56 if isinstance(element, (list, tuple)):
58 node_check, index_check = element
59 elif len(element) == 1:
60 node_check = element[0]
68 node_check = ScalarNode
69 elif node_check
is list:
70 node_check = SequenceNode
71 elif node_check
is dict:
72 node_check = MappingNode
73 elif node_check
not in [ScalarNode, SequenceNode, MappingNode] \
74 and not isinstance(node_check, basestring) \
75 and node_check
is not None:
77 if not isinstance(index_check, (basestring, int)) \
78 and index_check
is not None:
79 raise ResolverError(
"Invalid index checker: %s" % index_check)
80 new_path.append((node_check, index_check))
87 elif kind
not in [ScalarNode, SequenceNode, MappingNode] \
90 cls.yaml_path_resolvers[tuple(new_path), kind] = tag
91 add_path_resolver = classmethod(add_path_resolver)
102 current_node, current_index):
103 if len(path) > depth:
104 prefix_paths.append((path, kind))
112 prefix_paths.append((path, kind))
113 self.resolver_exact_paths.append(exact_paths)
114 self.resolver_prefix_paths.append(prefix_paths)
119 self.resolver_exact_paths.pop()
120 self.resolver_prefix_paths.pop()
123 current_node, current_index):
124 node_check, index_check = path[depth-1]
125 if isinstance(node_check, basestring):
126 if current_node.tag != node_check:
128 elif node_check
is not None:
129 if not isinstance(current_node, node_check):
131 if index_check
is True and current_index
is not None:
133 if (index_check
is False or index_check
is None) \
134 and current_index
is None:
136 if isinstance(index_check, basestring):
137 if not (isinstance(current_index, ScalarNode)
138 and index_check == current_index.value):
140 elif isinstance(index_check, int)
and not isinstance(index_check, bool):
141 if index_check != current_index:
146 if kind
is ScalarNode
and implicit[0]:
148 resolvers = self.yaml_implicit_resolvers.get(
u'', [])
150 resolvers = self.yaml_implicit_resolvers.get(value[0], [])
151 resolvers += self.yaml_implicit_resolvers.get(
None, [])
152 for tag, regexp
in resolvers:
153 if regexp.match(value):
155 implicit = implicit[1]
158 if kind
in exact_paths:
159 return exact_paths[kind]
160 if None in exact_paths:
161 return exact_paths[
None]
162 if kind
is ScalarNode:
164 elif kind
is SequenceNode:
166 elif kind
is MappingNode:
172 Resolver.add_implicit_resolver(
173 u'tag:yaml.org,2002:bool',
174 re.compile(
ur'''^(?:yes|Yes|YES|no|No|NO
175 |true|True|TRUE|false|False|FALSE
176 |on|On|ON|off|Off|OFF)$''', re.X),
179 Resolver.add_implicit_resolver(
180 u'tag:yaml.org,2002:float',
181 re.compile(
ur'''^(?:[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*(?:[eE][-+][0-9]+)?
182 |[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*
183 |[-+]?\.(?:inf|Inf|INF)
184 |\.(?:nan|NaN|NAN))$''', re.X),
185 list(
u'-+0123456789.'))
187 Resolver.add_implicit_resolver(
188 u'tag:yaml.org,2002:int',
189 re.compile(
ur'''^(?:[-+]?0b[0-1_]+
191 |[-+]?(?:0|[1-9][0-9_]*)
192 |[-+]?0x[0-9a-fA-F_]+
193 |[-+]?[1-9][0-9_]*(?::[0-5]?[0-9])+)$''', re.X),
194 list(
u'-+0123456789'))
196 Resolver.add_implicit_resolver(
197 u'tag:yaml.org,2002:merge',
198 re.compile(
ur'^(?:<<)$'),
201 Resolver.add_implicit_resolver(
202 u'tag:yaml.org,2002:null',
203 re.compile(
ur'''^(?: ~
206 [
u'~',
u'n',
u'N',
u''])
208 Resolver.add_implicit_resolver(
209 u'tag:yaml.org,2002:timestamp',
210 re.compile(
ur'''^(?:[0-9][0-9][0-9][0-9]-[0-9][0-9]-[0-9][0-9]
211 |[0-9][0-9][0-9][0-9] -[0-9][0-9]? -[0-9][0-9]?
212 (?:[Tt]|[ \t]+)[0-9][0-9]?
213 :[0-9][0-9] :[0-9][0-9] (?:\.[0-9]*)?
214 (?:[ \t]*(?:Z|[-+][0-9][0-9]?(?::[0-9][0-9])?))?)$''', re.X),
217 Resolver.add_implicit_resolver(
218 u'tag:yaml.org,2002:value',
219 re.compile(
ur'^(?:=)$'),
224 Resolver.add_implicit_resolver(
225 u'tag:yaml.org,2002:yaml',
226 re.compile(
ur'^(?:!|&|\*)$'),
string DEFAULT_SCALAR_TAG
Fstring::size_type len(Fstring const &s)
Length.
dictionary yaml_path_resolvers
string DEFAULT_SEQUENCE_TAG
def check_resolver_prefix
string DEFAULT_MAPPING_TAG
tuple add_implicit_resolver