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 218 219 220 221 222 223 224 225 226 227 228 229 230 231
|
# -*- coding: utf-8 -*-
from collections import OrderedDict
from copy import deepcopy
from datetime import datetime, tzinfo
from toml.tz import TomlTz
example_ini = u"""\
[foo]
bar = ěšč
spam = 1
baz = 1.1
[[blah]]
blahblah = True, text4
nothing = None\
"""
example_ini_with_interpolation = u"""\
[foo]
bar = ěšč
spam = 1 [%%(test)s]
baz = 1.1
[[blah]]
blahblah = True, text4
nothing = None\
"""
example_json = u"""\
{
"foo": {
"bar": "ěšč",
"spam": 1,
"baz": 1.1,
"blah": {
"blahblah": [
true,
"text4"
],
"nothing": null
}
}
}"""
example_json5 = u"""\
{foo: {
bar: 'ěšč',
spam: 1,
baz: 1.1,
blah: {
blahblah: [true, "text4",],
nothing: null
}
}}"""
# toml is special, since it e.g. only allows lists to have same types of values
example_toml = u"""\
title = "TOML Example"
[foo]
name = "barů"
dob = 1987-07-05T17:45:00Z
[spam]
spam2 = "spam"
ham = [1, 2, 3]
[spam.spam]
foo = [["bar"]]
"""
example_xml = u"""\
<?xml version="1.0" encoding="utf-8"?>
<foo>
\t<bar>ěšč</bar>
\t<spam>1</spam>
\t<baz>1.1</baz>
\t<blah>
\t\t<blahblah>true</blahblah>
\t\t<blahblah>text4</blahblah>
\t\t<nothing></nothing>
\t</blah>
</foo>"""
example_yaml_map = u"""\
foo:
bar: ěšč
spam: 1
baz: 1.1
blah:
blahblah:
- True
- text4
nothing:"""
# for testing OrderedDict parsing/serializing with PyYAML
# TODO: what about "nothing: null"? it's not there for normal map
example_yaml_omap = u"""\
!!omap
- foo: !!omap
- bar: ěšč
- spam: 1
- baz: 1.1
- blah: !!omap
- blahblah:
- True
- text4
- nothing: null"""
example_as_ordered_dict = OrderedDict(
[(u'foo', OrderedDict([
(u'bar', u'ěšč'),
(u'spam', 1),
(u'baz', 1.1),
(u'blah', OrderedDict([
(u'blahblah', [True, u'text4']),
(u'nothing', None)
]))
]))]
)
example_as_dict = {
u'foo': {
u'bar': u'ěšč',
u'spam': 1,
u'baz': 1.1,
u'blah': {
u'blahblah': [True, u'text4'],
u'nothing': None
}
}
}
toml_example_as_dict = {
u'foo': {
u'dob': datetime(1987, 7, 5, 17, 45, tzinfo=TomlTz('Z')),
u'name': u'barů'},
u'spam': {u'ham': [1, 2, 3],
u'spam': {u'foo': [[u'bar']]},
u'spam2': u'spam'},
u'title': u'TOML Example'
}
# ini loading doesn't yield any ints/floats/NoneTypes/bools, so it's ideal
# to test our custom convertors; for other types, some of these values
# are pre-converted by the used parsers
types_ini = u"""
[x]
a=1
b=1.1
c=None
d=True"""
types_json = u"""
{
"x":
{
"a": 1,
"b": 1.1,
"c": null,
"d": true,
}
}"""
types_json5 = types_json
types_toml = u"""
[x]
a=1
b=1.1
c=1987-07-05T17:45:00Z
d=true
"""
types_yaml = u"""
x:
a: 1
b: 1.1
c: None
d: True
"""
types_xml = u"""\
<?xml version="1.0" encoding="utf-8"?>
<x>
\t<a>1</a>
\t<b>1.1</b>
\t<c>None</c>
\t<d>True</d>
</x>"""
types_as_struct_with_objects = {
'x': {
'a': 1,
'b': 1.1,
'c': None,
'd': True,
}
}
toml_types_as_struct_with_objects = deepcopy(types_as_struct_with_objects)
toml_types_as_struct_with_objects['x']['c'] = datetime(1987, 7, 5, 17, 45, tzinfo=TomlTz('Z'))
types_as_struct_with_strings = {
'x': {
'a': "1",
'b': "1.1",
'c': "None",
'd': "True",
}
}
toml_types_as_struct_with_strings = deepcopy(types_as_struct_with_strings)
toml_types_as_struct_with_strings['x']['c'] = '1987-07-05 17:45:00+00:00'
|