constructor.py 25 KB

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