File: vdf.rst

package info (click to toggle)
python-steamodd 5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 304 kB
  • sloc: python: 2,224; makefile: 162
file content (51 lines) | stat: -rw-r--r-- 1,203 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
==============
VDF serializer
==============

|VDF|_ is format similar to JSON or YAML, used by Valve to store data. This
module mimics built-in :code:`json` module and provides functions for
serialization and deserialization of :code:`VDF` files.

.. autofunction:: steam.vdf.dump

.. code:: python

    >>> with open('dump.vdf', 'w') as file:
    ...     vdf.dump({u"key": u"value", u"list": [1, 2, 3]}, file)

    → cat dump.vdf
    "list"
    {
    "1" "1"
    "2" "1"
    "3" "1"
    }

    "key" "value"

.. autofunction:: steam.vdf.dumps

.. code:: python

    >>> vdf_obj = vdf.dumps({"key": "value", "list": [1, 2, 3]})
    >>> vdf_obj.decode('utf-16')
    u'\n  "list"\n  {\n    "1" "1"\n    "2" "1"\n    "3" "1"\n  }\n\n  "key" "value"\n'

.. autofunction:: steam.vdf.load

.. code:: python

    >>> with open('dump.vdf', 'r') as file:
    ...     vdf.load(file)
    ...
    {u'list': {u'1': u'1', u'3': u'1', u'2': u'1'}, u'key': u'value'}

.. autofunction:: steam.vdf.loads

.. code:: python

    >>> vdf.loads('"list" { "a" "1" "b" "2" "c" "3" }')
    {u'list': {u'a': u'1', u'c': u'3', u'b': u'2'}}

.. |VDF| replace:: :code:`VDF`
.. _VDF: https://wiki.teamfortress.com/wiki/WebAPI/VDF