vici: Use OrderedDict to handle vici responses in Python library
authorMartin Willi <martin@revosec.ch>
Fri, 27 Feb 2015 13:30:34 +0000 (14:30 +0100)
committerMartin Willi <martin@revosec.ch>
Wed, 18 Mar 2015 12:59:14 +0000 (13:59 +0100)
The default Python dictionaries are unordered, but order is important for some
vici trees (for example the order of authentication rounds).

src/libcharon/plugins/vici/python/vici/protocol.py

index 60b94ed..88e1c34 100644 (file)
@@ -3,6 +3,7 @@ import socket
 import struct
 
 from collections import namedtuple
+from collections import OrderedDict
 
 from .exception import DeserializationException
 
@@ -150,13 +151,13 @@ class Message(object):
                     "Expected end of list at {pos}".format(pos=stream.tell())
                 )
 
-        section = {}
+        section = OrderedDict()
         section_stack = []
         while stream.has_more():
             element_type, = struct.unpack("!B", stream.read(1))
             if element_type == cls.SECTION_START:
                 section_name = decode_named_type(stream)
-                new_section = {}
+                new_section = OrderedDict()
                 section[section_name] = new_section
                 section_stack.append(section)
                 section = new_section