Ticket #154: libyaml_custom_class_broken.py

File libyaml_custom_class_broken.py, 675 bytes (added by smichalske@…, 5 years ago)
Line 
1import yaml
2from pprint import pprint
3
4class Monster(yaml.YAMLObject):
5    yaml_tag = u'!Monster'
6    def __init__(self, name, hp, ac, attacks):
7        self.name = name
8        self.hp = hp
9        self.ac = ac
10        self.attacks = attacks
11    def __repr__(self):
12        return "%s(name=%r, hp=%r, ac=%r, attacks=%r)" % (
13            self.__class__.__name__, self.name, self.hp, self.ac, self.attacks)
14
15works = yaml.load("""
16--- !Monster
17name: Cave spider
18hp: [2,6]    # 2d6
19ac: 16
20attacks: [BITE, HURT]
21""")
22
23pprint( works )
24print "\n\n\n"
25
26breaks = yaml.load("""
27--- !Monster
28name: Cave spider
29hp: [2,6]    # 2d6
30ac: 16
31attacks: [BITE, HURT]
32""", Loader=yaml.CLoader)
33