File: xmlbackend_and_dict-_and_list_field.py

package info (click to toggle)
python-gpyconf 0.2-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 416 kB
  • ctags: 590
  • sloc: python: 1,980; makefile: 87; sh: 4
file content (44 lines) | stat: -rw-r--r-- 858 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
# coding: utf-8
from gpyconf import Configuration, fields
from gpyconf.backends._xml import XMLBackend

class Conf(Configuration):
    backend = XMLBackend

    a = fields.DictField()
    b = fields.DictField(keys={'a_dict' : dict, 'a_list' : list, 'a_int' : int})

    c = fields.ListField()
    d = fields.ListField(item_type=dict)

c = Conf()
c.a = c_a = {
    'aasdasd' : (1,2,3),
    'asd' : u'baaaräää',
    # this can't work in XML:
    # 5: 'elf',
    # 4 : 42.4222
}

c.c = c_c = ['a', 'b', {'foo' : 'bar'}, {'baz': 1, 'peng': 2}]

c.d = c_d = [{'a': 1, 'b':2},  {'c':3, 'd':'foo'}]

c.b = c_b = {
    'a_dict' : c.a,
    'a_list' : c.c,
    'a_int' : 42
}

c.save()

#from xml.dom.minidom import parse
#print parse(c.backend_instance.file).toprettyxml()

del c

c = Conf()
assert c.a == c_a
assert c.b == c_b
assert c.c == c_c
assert c.d == c_d