-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_yaml.py
More file actions
36 lines (31 loc) · 870 Bytes
/
test_yaml.py
File metadata and controls
36 lines (31 loc) · 870 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import sys
from ruamel.yaml import YAML
from ruamel.yaml.compat import StringIO
def strip_python_tags(s):
result = []
for line in s.splitlines():
idx = line.find("!")
if idx > -1:
line = line[:idx]
result.append(line)
return '\n'.join(result)
class Kid(object):
def __init__(self, name):
self.name = name
class Person(object):
population = 0
def __init__(self, first, last):
self.first = first
self.last = last
self.kids = []
self.kids['foo'] = Kid("Henry")
# self.kids.append(Kid("Alice"))
# self.kids.append(Kid("Sally"))
self.population += 1
a = Person('first', 'last')
yaml = YAML()
yaml.encoding = None
yaml.typ = "safe"
yaml.register_class(Person)
yaml.register_class(Kid)
yaml.dump(a, sys.stdout, transform=strip_python_tags)