File: disallowed-yaml.md

package info (click to toggle)
python-strictyaml 1.7.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,708 kB
  • sloc: python: 12,836; sh: 48; makefile: 3
file content (217 lines) | stat: -rw-r--r-- 3,498 bytes parent folder | download
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
---
title: Disallowed YAML
---


StrictYAML parses an opinionated subset of the YAML
specification which refuses to parse features which
are otherwise valid in standard YAML.

For an explanation as to why these features are stripped
out of StrictYAML, see the FAQ.

Disallowed YAML features raise Disallowed exceptions
while syntactically invalid YAML raises ScannerError
or ComposerError.

Every error inherits from YAMLError.




```python
from strictyaml import Map, Int, Any, load
from strictyaml import TagTokenDisallowed, FlowMappingDisallowed, AnchorTokenDisallowed

schema = Map({"x": Map({"a": Any(), "b": Any(), "c": Any()})})

```



Tag tokens:

```yaml
x:
  a: !!str yes
  b: !!str 3.5
  c: !!str yes

```


```python
load(yaml_snippet, schema, label="disallowed")
```


```python
strictyaml.exceptions.TagTokenDisallowed:
While scanning
  in "disallowed", line 2, column 11:
      a: !!str yes
              ^ (line: 2)
Found disallowed tag tokens (do not specify types in markup)
  in "disallowed", line 2, column 6:
      a: !!str yes
         ^ (line: 2)
```




Flow style sequence:

```yaml
[a, b]: [x, y]

```


```python
load(yaml_snippet, schema, label="disallowed")
```


```python
strictyaml.exceptions.FlowMappingDisallowed:
While scanning
  in "disallowed", line 1, column 1:
    [a, b]: [x, y]
    ^ (line: 1)
Found ugly disallowed JSONesque flow mapping (surround with ' and ' to make text appear literally)
  in "disallowed", line 1, column 2:
    [a, b]: [x, y]
     ^ (line: 1)
```




Flow style mapping:

```yaml
x: { a: 1, b: 2, c: 3 }

```


```python
load(yaml_snippet, schema, label="disallowed")
```


```python
strictyaml.exceptions.FlowMappingDisallowed:
While scanning
  in "disallowed", line 1, column 4:
    x: { a: 1, b: 2, c: 3 }
       ^ (line: 1)
Found ugly disallowed JSONesque flow mapping (surround with ' and ' to make text appear literally)
  in "disallowed", line 1, column 5:
    x: { a: 1, b: 2, c: 3 }
        ^ (line: 1)
```




Node anchors and references:

```yaml
x: 
  a: &node1 3.5
  b: 1
  c: *node1

```


```python
load(yaml_snippet, schema, label="disallowed")
```


```python
strictyaml.exceptions.AnchorTokenDisallowed:
While scanning
  in "disallowed", line 2, column 6:
      a: &node1 3.5
         ^ (line: 2)
Found confusing disallowed anchor token (surround with ' and ' to make text appear literally)
  in "disallowed", line 2, column 12:
      a: &node1 3.5
               ^ (line: 2)
```




Syntactically invalid YAML:

```yaml
- invalid
string

```


```python
load(yaml_snippet, schema, label="disallowed")
```


```python
strictyaml.ruamel.scanner.ScannerError:
while scanning a simple key
  in "disallowed", line 2, column 1:
    string
    ^ (line: 2)
could not find expected ':'
  in "disallowed", line 3, column 1:
    
    ^ (line: 3)
```




Mixed space indentation:

```yaml
item:
  two space indent: 2
item two:
    four space indent: 2

```


```python
load(yaml_snippet, label="disallowed")
```


```python
strictyaml.exceptions.InconsistentIndentationDisallowed:
While parsing
  in "disallowed", line 4, column 5:
        four space indent: 2
        ^ (line: 4)
Found mapping with indentation inconsistent with previous mapping
  in "disallowed", line 5, column 1:
    
    ^ (line: 5)
```







!!! note "Executable specification"

    Documentation automatically generated from 
    <a href="https://github.com/crdoconnor/strictyaml/blob/master/hitch/story/disallow.story">disallow.story
    storytests.