File tree Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Expand file tree Collapse file tree 1 file changed +52
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env python3
2
+
3
+ import sys
4
+ sys .path .insert (0 , 'lib' )
5
+
6
+ from yaml import *
7
+
8
+ ldr = SafeLoader ()
9
+
10
+ def dice_constructor1 (loader , node ):
11
+ value = loader .construct_scalar (node )
12
+ a , b = map (int , value .split ('d' ))
13
+ return [a ,b ]
14
+
15
+ def dice_constructor2 (loader , node ):
16
+ value = loader .construct_scalar (node )
17
+ a , b = map (int , value .split ('d' ))
18
+ return [b ,a ]
19
+
20
+ s = """
21
+ - !dice 3d4
22
+ """
23
+
24
+
25
+
26
+ add_constructor ('!dice' , dice_constructor1 , SafeLoader )
27
+
28
+ print ()
29
+ data = load (s , SafeLoader )
30
+ print ('1) SafeLoader -> %s' % data )
31
+ data = load (s , ldr )
32
+ print ('1) Instance -> %s' % data )
33
+
34
+
35
+
36
+ ldr .add_constructor ('!dice' , dice_constructor2 )
37
+
38
+ print ()
39
+ data = load (s , SafeLoader )
40
+ print ('2) SafeLoader -> %s' % data )
41
+ data = load (s , ldr )
42
+ print ('2) Instance -> %s' % data )
43
+
44
+
45
+
46
+ ldr .add_constructor ('!dice' , None )
47
+
48
+ print ()
49
+ data = load (s , SafeLoader )
50
+ print ('3) SafeLoader -> %s' % data )
51
+ data = load (s , ldr )
52
+ print ('3) Instance -> %s' % data )
You can’t perform that action at this time.
0 commit comments