Ticket #143: test4.py
| File test4.py, 476 bytes (added by berlin_lev@…, 4 years ago) |
|---|
| Line | |
|---|---|
| 1 | |
| 2 | import yaml |
| 3 | import re |
| 4 | |
| 5 | s = """ |
| 6 | good: foo |
| 7 | bad: | |
| 8 | foo""" |
| 9 | |
| 10 | |
| 11 | class Test(yaml.YAMLObject): |
| 12 | yaml_tag = '!test' |
| 13 | pattern = re.compile(r'foo') |
| 14 | yaml.add_implicit_resolver('!test', pattern) |
| 15 | |
| 16 | def __init__(self, s): |
| 17 | self.s = s |
| 18 | def __repr__(self): |
| 19 | return 'Test(%s)' % self.s |
| 20 | |
| 21 | @classmethod |
| 22 | def from_yaml(cls, loader, node): |
| 23 | value = loader.construct_scalar(node) |
| 24 | return cls(value) |
| 25 | |
| 26 | print yaml.load(s) |
