constructor.py 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  1. # SPDX-License-Identifier: MIT
  2. __all__ = ['BaseConstructor', 'SafeConstructor', 'Constructor',
  3. 'ConstructorError']
  4. from .error import *
  5. from .nodes import *
  6. import collections, datetime, base64, binascii, re, sys, types
  7. class ConstructorError(MarkedYAMLError):
  8. pass
  9. class BaseConstructor:
  10. yaml_constructors = {}
  11. yaml_multi_constructors = {}
  12. def __init__(self):
  13. self.constructed_objects = {}
  14. self.recursive_objects = {}
  15. self.state_generators = []
  16. self.deep_construct = False
  17. def check_data(self):
  18. # If there are more documents available?
  19. return self.check_node()
  20. def get_data(self):
  21. # Construct and return the next document.
  22. if self.check_node():
  23. return self.construct_document(self.get_node())
  24. def get_single_data(self):
  25. # Ensure that the stream contains a single document and construct it.
  26. node = self.get_single_node()
  27. if node is not None:
  28. return self.construct_document(node)
  29. return None
  30. def construct_document(self, node):
  31. data = self.construct_object(node)
  32. while self.state_generators:
  33. state_generators = self.state_generators
  34. self.state_generators = []
  35. for generator in state_generators:
  36. for dummy in generator:
  37. pass
  38. self.constructed_objects = {}
  39. self.recursive_objects = {}
  40. self.deep_construct = False
  41. return data
  42. def construct_object(self, node, deep=False):
  43. if node in self.constructed_objects:
  44. return self.constructed_objects[node]
  45. if deep:
  46. old_deep = self.deep_construct
  47. self.deep_construct = True
  48. if node in self.recursive_objects:
  49. raise ConstructorError(None, None,
  50. "found unconstructable recursive node", node.start_mark)
  51. self.recursive_objects[node] = None
  52. constructor = None
  53. tag_suffix = None
  54. if node.tag in self.yaml_constructors:
  55. constructor = self.yaml_constructors[node.tag]
  56. else:
  57. for tag_prefix in self.yaml_multi_constructors:
  58. if node.tag.startswith(tag_prefix):
  59. tag_suffix = node.tag[len(tag_prefix):]
  60. constructor = self.yaml_multi_constructors[tag_prefix]
  61. break
  62. else:
  63. if None in self.yaml_multi_constructors:
  64. tag_suffix = node.tag
  65. constructor = self.yaml_multi_constructors[None]
  66. elif None in self.yaml_constructors:
  67. constructor = self.yaml_constructors[None]
  68. elif isinstance(node, ScalarNode):
  69. constructor = self.__class__.construct_scalar
  70. elif isinstance(node, SequenceNode):
  71. constructor = self.__class__.construct_sequence
  72. elif isinstance(node, MappingNode):
  73. constructor = self.__class__.construct_mapping
  74. if tag_suffix is None:
  75. data = constructor(self, node)
  76. else:
  77. data = constructor(self, tag_suffix, node)
  78. if isinstance(data, types.GeneratorType):
  79. generator = data
  80. data = next(generator)
  81. if self.deep_construct:
  82. for dummy in generator:
  83. pass
  84. else:
  85. self.state_generators.append(generator)
  86. self.constructed_objects[node] = data
  87. del self.recursive_objects[node]
  88. if deep:
  89. self.deep_construct = old_deep
  90. return data
  91. def construct_scalar(self, node):
  92. if not isinstance(node, ScalarNode):
  93. raise ConstructorError(None, None,
  94. "expected a scalar node, but found %s" % node.id,
  95. node.start_mark)
  96. return node.value
  97. def construct_sequence(self, node, deep=False):
  98. if not isinstance(node, SequenceNode):
  99. raise ConstructorError(None, None,
  100. "expected a sequence node, but found %s" % node.id,
  101. node.start_mark)
  102. return [self.construct_object(child, deep=deep)
  103. for child in node.value]
  104. def construct_mapping(self, node, deep=False):
  105. if not isinstance(node, MappingNode):
  106. raise ConstructorError(None, None,
  107. "expected a mapping node, but found %s" % node.id,
  108. node.start_mark)
  109. mapping = {}
  110. for key_node, value_node in node.value:
  111. key = self.construct_object(key_node, deep=deep)
  112. if not isinstance(key, collections.Hashable):
  113. raise ConstructorError("while constructing a mapping", node.start_mark,
  114. "found unhashable key", key_node.start_mark)
  115. value = self.construct_object(value_node, deep=deep)
  116. mapping[key] = value
  117. return mapping
  118. def construct_pairs(self, node, deep=False):
  119. if not isinstance(node, MappingNode):
  120. raise ConstructorError(None, None,
  121. "expected a mapping node, but found %s" % node.id,
  122. node.start_mark)
  123. pairs = []
  124. for key_node, value_node in node.value:
  125. key = self.construct_object(key_node, deep=deep)
  126. value = self.construct_object(value_node, deep=deep)
  127. pairs.append((key, value))
  128. return pairs
  129. @classmethod
  130. def add_constructor(cls, tag, constructor):
  131. if not 'yaml_constructors' in cls.__dict__:
  132. cls.yaml_constructors = cls.yaml_constructors.copy()
  133. cls.yaml_constructors[tag] = constructor
  134. @classmethod
  135. def add_multi_constructor(cls, tag_prefix, multi_constructor):
  136. if not 'yaml_multi_constructors' in cls.__dict__:
  137. cls.yaml_multi_constructors = cls.yaml_multi_constructors.copy()
  138. cls.yaml_multi_constructors[tag_prefix] = multi_constructor
  139. class SafeConstructor(BaseConstructor):
  140. def construct_scalar(self, node):
  141. if isinstance(node, MappingNode):
  142. for key_node, value_node in node.value:
  143. if key_node.tag == 'tag:yaml.org,2002:value':
  144. return self.construct_scalar(value_node)
  145. return super().construct_scalar(node)
  146. def flatten_mapping(self, node):
  147. merge = []
  148. index = 0
  149. while index < len(node.value):
  150. key_node, value_node = node.value[index]
  151. if key_node.tag == 'tag:yaml.org,2002:merge':
  152. del node.value[index]
  153. if isinstance(value_node, MappingNode):
  154. self.flatten_mapping(value_node)
  155. merge.extend(value_node.value)
  156. elif isinstance(value_node, SequenceNode):
  157. submerge = []
  158. for subnode in value_node.value:
  159. if not isinstance(subnode, MappingNode):
  160. raise ConstructorError("while constructing a mapping",
  161. node.start_mark,
  162. "expected a mapping for merging, but found %s"
  163. % subnode.id, subnode.start_mark)
  164. self.flatten_mapping(subnode)
  165. submerge.append(subnode.value)
  166. submerge.reverse()
  167. for value in submerge:
  168. merge.extend(value)
  169. else:
  170. raise ConstructorError("while constructing a mapping", node.start_mark,
  171. "expected a mapping or list of mappings for merging, but found %s"
  172. % value_node.id, value_node.start_mark)
  173. elif key_node.tag == 'tag:yaml.org,2002:value':
  174. key_node.tag = 'tag:yaml.org,2002:str'
  175. index += 1
  176. else:
  177. index += 1
  178. if merge:
  179. node.value = merge + node.value
  180. def construct_mapping(self, node, deep=False):
  181. if isinstance(node, MappingNode):
  182. self.flatten_mapping(node)
  183. return super().construct_mapping(node, deep=deep)
  184. def construct_yaml_null(self, node):
  185. self.construct_scalar(node)
  186. return None
  187. bool_values = {
  188. 'yes': True,
  189. 'no': False,
  190. 'true': True,
  191. 'false': False,
  192. 'on': True,
  193. 'off': False,
  194. }
  195. def construct_yaml_bool(self, node):
  196. value = self.construct_scalar(node)
  197. return self.bool_values[value.lower()]
  198. def construct_yaml_int(self, node):
  199. value = self.construct_scalar(node)
  200. value = value.replace('_', '')
  201. sign = +1
  202. if value[0] == '-':
  203. sign = -1
  204. if value[0] in '+-':
  205. value = value[1:]
  206. if value == '0':
  207. return 0
  208. elif value.startswith('0b'):
  209. return sign*int(value[2:], 2)
  210. elif value.startswith('0x'):
  211. return sign*int(value[2:], 16)
  212. elif value[0] == '0':
  213. return sign*int(value, 8)
  214. elif ':' in value:
  215. digits = [int(part) for part in value.split(':')]
  216. digits.reverse()
  217. base = 1
  218. value = 0
  219. for digit in digits:
  220. value += digit*base
  221. base *= 60
  222. return sign*value
  223. else:
  224. return sign*int(value)
  225. inf_value = 1e300
  226. while inf_value != inf_value*inf_value:
  227. inf_value *= inf_value
  228. nan_value = -inf_value/inf_value # Trying to make a quiet NaN (like C99).
  229. def construct_yaml_float(self, node):
  230. value = self.construct_scalar(node)
  231. value = value.replace('_', '').lower()
  232. sign = +1
  233. if value[0] == '-':
  234. sign = -1
  235. if value[0] in '+-':
  236. value = value[1:]
  237. if value == '.inf':
  238. return sign*self.inf_value
  239. elif value == '.nan':
  240. return self.nan_value
  241. elif ':' in value:
  242. digits = [float(part) for part in value.split(':')]
  243. digits.reverse()
  244. base = 1
  245. value = 0.0
  246. for digit in digits:
  247. value += digit*base
  248. base *= 60
  249. return sign*value
  250. else:
  251. return sign*float(value)
  252. def construct_yaml_binary(self, node):
  253. try:
  254. value = self.construct_scalar(node).encode('ascii')
  255. except UnicodeEncodeError as exc:
  256. raise ConstructorError(None, None,
  257. "failed to convert base64 data into ascii: %s" % exc,
  258. node.start_mark)
  259. try:
  260. if hasattr(base64, 'decodebytes'):
  261. return base64.decodebytes(value)
  262. else:
  263. return base64.decodestring(value)
  264. except binascii.Error as exc:
  265. raise ConstructorError(None, None,
  266. "failed to decode base64 data: %s" % exc, node.start_mark)
  267. timestamp_regexp = re.compile(
  268. r'''^(?P<year>[0-9][0-9][0-9][0-9])
  269. -(?P<month>[0-9][0-9]?)
  270. -(?P<day>[0-9][0-9]?)
  271. (?:(?:[Tt]|[ \t]+)
  272. (?P<hour>[0-9][0-9]?)
  273. :(?P<minute>[0-9][0-9])
  274. :(?P<second>[0-9][0-9])
  275. (?:\.(?P<fraction>[0-9]*))?
  276. (?:[ \t]*(?P<tz>Z|(?P<tz_sign>[-+])(?P<tz_hour>[0-9][0-9]?)
  277. (?::(?P<tz_minute>[0-9][0-9]))?))?)?$''', re.X)
  278. def construct_yaml_timestamp(self, node):
  279. value = self.construct_scalar(node)
  280. match = self.timestamp_regexp.match(node.value)
  281. values = match.groupdict()
  282. year = int(values['year'])
  283. month = int(values['month'])
  284. day = int(values['day'])
  285. if not values['hour']:
  286. return datetime.date(year, month, day)
  287. hour = int(values['hour'])
  288. minute = int(values['minute'])
  289. second = int(values['second'])
  290. fraction = 0
  291. if values['fraction']:
  292. fraction = values['fraction'][:6]
  293. while len(fraction) < 6:
  294. fraction += '0'
  295. fraction = int(fraction)
  296. delta = None
  297. if values['tz_sign']:
  298. tz_hour = int(values['tz_hour'])
  299. tz_minute = int(values['tz_minute'] or 0)
  300. delta = datetime.timedelta(hours=tz_hour, minutes=tz_minute)
  301. if values['tz_sign'] == '-':
  302. delta = -delta
  303. data = datetime.datetime(year, month, day, hour, minute, second, fraction)
  304. if delta:
  305. data -= delta
  306. return data
  307. def construct_yaml_omap(self, node):
  308. # Note: we do not check for duplicate keys, because it's too
  309. # CPU-expensive.
  310. omap = []
  311. yield omap
  312. if not isinstance(node, SequenceNode):
  313. raise ConstructorError("while constructing an ordered map", node.start_mark,
  314. "expected a sequence, but found %s" % node.id, node.start_mark)
  315. for subnode in node.value:
  316. if not isinstance(subnode, MappingNode):
  317. raise ConstructorError("while constructing an ordered map", node.start_mark,
  318. "expected a mapping of length 1, but found %s" % subnode.id,
  319. subnode.start_mark)
  320. if len(subnode.value) != 1:
  321. raise ConstructorError("while constructing an ordered map", node.start_mark,
  322. "expected a single mapping item, but found %d items" % len(subnode.value),
  323. subnode.start_mark)
  324. key_node, value_node = subnode.value[0]
  325. key = self.construct_object(key_node)
  326. value = self.construct_object(value_node)
  327. omap.append((key, value))
  328. def construct_yaml_pairs(self, node):
  329. # Note: the same code as `construct_yaml_omap`.
  330. pairs = []
  331. yield pairs
  332. if not isinstance(node, SequenceNode):
  333. raise ConstructorError("while constructing pairs", node.start_mark,
  334. "expected a sequence, but found %s" % node.id, node.start_mark)
  335. for subnode in node.value:
  336. if not isinstance(subnode, MappingNode):
  337. raise ConstructorError("while constructing pairs", node.start_mark,
  338. "expected a mapping of length 1, but found %s" % subnode.id,
  339. subnode.start_mark)
  340. if len(subnode.value) != 1:
  341. raise ConstructorError("while constructing pairs", node.start_mark,
  342. "expected a single mapping item, but found %d items" % len(subnode.value),
  343. subnode.start_mark)
  344. key_node, value_node = subnode.value[0]
  345. key = self.construct_object(key_node)
  346. value = self.construct_object(value_node)
  347. pairs.append((key, value))
  348. def construct_yaml_set(self, node):
  349. data = set()
  350. yield data
  351. value = self.construct_mapping(node)
  352. data.update(value)
  353. def construct_yaml_str(self, node):
  354. return self.construct_scalar(node)
  355. def construct_yaml_seq(self, node):
  356. data = []
  357. yield data
  358. data.extend(self.construct_sequence(node))
  359. def construct_yaml_map(self, node):
  360. data = {}
  361. yield data
  362. value = self.construct_mapping(node)
  363. data.update(value)
  364. def construct_yaml_object(self, node, cls):
  365. data = cls.__new__(cls)
  366. yield data
  367. if hasattr(data, '__setstate__'):
  368. state = self.construct_mapping(node, deep=True)
  369. data.__setstate__(state)
  370. else:
  371. state = self.construct_mapping(node)
  372. data.__dict__.update(state)
  373. def construct_undefined(self, node):
  374. raise ConstructorError(None, None,
  375. "could not determine a constructor for the tag %r" % node.tag,
  376. node.start_mark)
  377. SafeConstructor.add_constructor(
  378. 'tag:yaml.org,2002:null',
  379. SafeConstructor.construct_yaml_null)
  380. SafeConstructor.add_constructor(
  381. 'tag:yaml.org,2002:bool',
  382. SafeConstructor.construct_yaml_bool)
  383. SafeConstructor.add_constructor(
  384. 'tag:yaml.org,2002:int',
  385. SafeConstructor.construct_yaml_int)
  386. SafeConstructor.add_constructor(
  387. 'tag:yaml.org,2002:float',
  388. SafeConstructor.construct_yaml_float)
  389. SafeConstructor.add_constructor(
  390. 'tag:yaml.org,2002:binary',
  391. SafeConstructor.construct_yaml_binary)
  392. SafeConstructor.add_constructor(
  393. 'tag:yaml.org,2002:timestamp',
  394. SafeConstructor.construct_yaml_timestamp)
  395. SafeConstructor.add_constructor(
  396. 'tag:yaml.org,2002:omap',
  397. SafeConstructor.construct_yaml_omap)
  398. SafeConstructor.add_constructor(
  399. 'tag:yaml.org,2002:pairs',
  400. SafeConstructor.construct_yaml_pairs)
  401. SafeConstructor.add_constructor(
  402. 'tag:yaml.org,2002:set',
  403. SafeConstructor.construct_yaml_set)
  404. SafeConstructor.add_constructor(
  405. 'tag:yaml.org,2002:str',
  406. SafeConstructor.construct_yaml_str)
  407. SafeConstructor.add_constructor(
  408. 'tag:yaml.org,2002:seq',
  409. SafeConstructor.construct_yaml_seq)
  410. SafeConstructor.add_constructor(
  411. 'tag:yaml.org,2002:map',
  412. SafeConstructor.construct_yaml_map)
  413. SafeConstructor.add_constructor(None,
  414. SafeConstructor.construct_undefined)
  415. class Constructor(SafeConstructor):
  416. def construct_python_str(self, node):
  417. return self.construct_scalar(node)
  418. def construct_python_unicode(self, node):
  419. return self.construct_scalar(node)
  420. def construct_python_bytes(self, node):
  421. try:
  422. value = self.construct_scalar(node).encode('ascii')
  423. except UnicodeEncodeError as exc:
  424. raise ConstructorError(None, None,
  425. "failed to convert base64 data into ascii: %s" % exc,
  426. node.start_mark)
  427. try:
  428. if hasattr(base64, 'decodebytes'):
  429. return base64.decodebytes(value)
  430. else:
  431. return base64.decodestring(value)
  432. except binascii.Error as exc:
  433. raise ConstructorError(None, None,
  434. "failed to decode base64 data: %s" % exc, node.start_mark)
  435. def construct_python_long(self, node):
  436. return self.construct_yaml_int(node)
  437. def construct_python_complex(self, node):
  438. return complex(self.construct_scalar(node))
  439. def construct_python_tuple(self, node):
  440. return tuple(self.construct_sequence(node))
  441. def find_python_module(self, name, mark):
  442. if not name:
  443. raise ConstructorError("while constructing a Python module", mark,
  444. "expected non-empty name appended to the tag", mark)
  445. try:
  446. __import__(name)
  447. except ImportError as exc:
  448. raise ConstructorError("while constructing a Python module", mark,
  449. "cannot find module %r (%s)" % (name, exc), mark)
  450. return sys.modules[name]
  451. def find_python_name(self, name, mark):
  452. if not name:
  453. raise ConstructorError("while constructing a Python object", mark,
  454. "expected non-empty name appended to the tag", mark)
  455. if '.' in name:
  456. module_name, object_name = name.rsplit('.', 1)
  457. else:
  458. module_name = 'builtins'
  459. object_name = name
  460. try:
  461. __import__(module_name)
  462. except ImportError as exc:
  463. raise ConstructorError("while constructing a Python object", mark,
  464. "cannot find module %r (%s)" % (module_name, exc), mark)
  465. module = sys.modules[module_name]
  466. if not hasattr(module, object_name):
  467. raise ConstructorError("while constructing a Python object", mark,
  468. "cannot find %r in the module %r"
  469. % (object_name, module.__name__), mark)
  470. return getattr(module, object_name)
  471. def construct_python_name(self, suffix, node):
  472. value = self.construct_scalar(node)
  473. if value:
  474. raise ConstructorError("while constructing a Python name", node.start_mark,
  475. "expected the empty value, but found %r" % value, node.start_mark)
  476. return self.find_python_name(suffix, node.start_mark)
  477. def construct_python_module(self, suffix, node):
  478. value = self.construct_scalar(node)
  479. if value:
  480. raise ConstructorError("while constructing a Python module", node.start_mark,
  481. "expected the empty value, but found %r" % value, node.start_mark)
  482. return self.find_python_module(suffix, node.start_mark)
  483. def make_python_instance(self, suffix, node,
  484. args=None, kwds=None, newobj=False):
  485. if not args:
  486. args = []
  487. if not kwds:
  488. kwds = {}
  489. cls = self.find_python_name(suffix, node.start_mark)
  490. if newobj and isinstance(cls, type):
  491. return cls.__new__(cls, *args, **kwds)
  492. else:
  493. return cls(*args, **kwds)
  494. def set_python_instance_state(self, instance, state):
  495. if hasattr(instance, '__setstate__'):
  496. instance.__setstate__(state)
  497. else:
  498. slotstate = {}
  499. if isinstance(state, tuple) and len(state) == 2:
  500. state, slotstate = state
  501. if hasattr(instance, '__dict__'):
  502. instance.__dict__.update(state)
  503. elif state:
  504. slotstate.update(state)
  505. for key, value in slotstate.items():
  506. setattr(object, key, value)
  507. def construct_python_object(self, suffix, node):
  508. # Format:
  509. # !!python/object:module.name { ... state ... }
  510. instance = self.make_python_instance(suffix, node, newobj=True)
  511. yield instance
  512. deep = hasattr(instance, '__setstate__')
  513. state = self.construct_mapping(node, deep=deep)
  514. self.set_python_instance_state(instance, state)
  515. def construct_python_object_apply(self, suffix, node, newobj=False):
  516. # Format:
  517. # !!python/object/apply # (or !!python/object/new)
  518. # args: [ ... arguments ... ]
  519. # kwds: { ... keywords ... }
  520. # state: ... state ...
  521. # listitems: [ ... listitems ... ]
  522. # dictitems: { ... dictitems ... }
  523. # or short format:
  524. # !!python/object/apply [ ... arguments ... ]
  525. # The difference between !!python/object/apply and !!python/object/new
  526. # is how an object is created, check make_python_instance for details.
  527. if isinstance(node, SequenceNode):
  528. args = self.construct_sequence(node, deep=True)
  529. kwds = {}
  530. state = {}
  531. listitems = []
  532. dictitems = {}
  533. else:
  534. value = self.construct_mapping(node, deep=True)
  535. args = value.get('args', [])
  536. kwds = value.get('kwds', {})
  537. state = value.get('state', {})
  538. listitems = value.get('listitems', [])
  539. dictitems = value.get('dictitems', {})
  540. instance = self.make_python_instance(suffix, node, args, kwds, newobj)
  541. if state:
  542. self.set_python_instance_state(instance, state)
  543. if listitems:
  544. instance.extend(listitems)
  545. if dictitems:
  546. for key in dictitems:
  547. instance[key] = dictitems[key]
  548. return instance
  549. def construct_python_object_new(self, suffix, node):
  550. return self.construct_python_object_apply(suffix, node, newobj=True)
  551. Constructor.add_constructor(
  552. 'tag:yaml.org,2002:python/none',
  553. Constructor.construct_yaml_null)
  554. Constructor.add_constructor(
  555. 'tag:yaml.org,2002:python/bool',
  556. Constructor.construct_yaml_bool)
  557. Constructor.add_constructor(
  558. 'tag:yaml.org,2002:python/str',
  559. Constructor.construct_python_str)
  560. Constructor.add_constructor(
  561. 'tag:yaml.org,2002:python/unicode',
  562. Constructor.construct_python_unicode)
  563. Constructor.add_constructor(
  564. 'tag:yaml.org,2002:python/bytes',
  565. Constructor.construct_python_bytes)
  566. Constructor.add_constructor(
  567. 'tag:yaml.org,2002:python/int',
  568. Constructor.construct_yaml_int)
  569. Constructor.add_constructor(
  570. 'tag:yaml.org,2002:python/long',
  571. Constructor.construct_python_long)
  572. Constructor.add_constructor(
  573. 'tag:yaml.org,2002:python/float',
  574. Constructor.construct_yaml_float)
  575. Constructor.add_constructor(
  576. 'tag:yaml.org,2002:python/complex',
  577. Constructor.construct_python_complex)
  578. Constructor.add_constructor(
  579. 'tag:yaml.org,2002:python/list',
  580. Constructor.construct_yaml_seq)
  581. Constructor.add_constructor(
  582. 'tag:yaml.org,2002:python/tuple',
  583. Constructor.construct_python_tuple)
  584. Constructor.add_constructor(
  585. 'tag:yaml.org,2002:python/dict',
  586. Constructor.construct_yaml_map)
  587. Constructor.add_multi_constructor(
  588. 'tag:yaml.org,2002:python/name:',
  589. Constructor.construct_python_name)
  590. Constructor.add_multi_constructor(
  591. 'tag:yaml.org,2002:python/module:',
  592. Constructor.construct_python_module)
  593. Constructor.add_multi_constructor(
  594. 'tag:yaml.org,2002:python/object:',
  595. Constructor.construct_python_object)
  596. Constructor.add_multi_constructor(
  597. 'tag:yaml.org,2002:python/object/apply:',
  598. Constructor.construct_python_object_apply)
  599. Constructor.add_multi_constructor(
  600. 'tag:yaml.org,2002:python/object/new:',
  601. Constructor.construct_python_object_new)