vpp_papi: Adjust aenum import for python3.
[vpp.git] / src / vpp-api / python / vpp_papi / vpp_serializer.py
index 418c024..1e59e36 100644 (file)
 
 import struct
 import collections
-from enum import IntEnum
+import sys
+
+if sys.version_info <= (3, 4):
+    from aenum import IntEnum
+else:
+    from enum import IntEnum
+
+if sys.version_info <= (3, 6):
+    from aenum import IntFlag
+else:
+    from enum import IntFlag
+
 import logging
 from . import vpp_format
 import ipaddress
-import sys
+
 import socket
 
 #
@@ -30,9 +41,10 @@ import socket
 logger = logging.getLogger(__name__)
 
 if sys.version[0] == '2':
-    check = lambda d: type(d) is dict
+    def check(d): type(d) is dict
 else:
-    check = lambda d: type(d) is dict or type(d) is bytes
+    def check(d): type(d) is dict or type(d) is bytes
+
 
 def conversion_required(data, field_type):
     if check(data):
@@ -101,7 +113,7 @@ class String(object):
             return b'', 0
         p = BaseTypes('u8', length)
         x, size = p.unpack(data, offset + length_field_size)
-        x2 = x.split(b'\0',1)[0]
+        x2 = x.split(b'\0', 1)[0]
         return (x2.decode('utf8'), size + length_field_size)
 
 
@@ -275,7 +287,7 @@ class VPPEnumType(object):
                 continue
             ename, evalue = f
             e_hash[ename] = evalue
-        self.enum = IntEnum(name, e_hash)
+        self.enum = IntFlag(name, e_hash)
         types[name] = self
 
     def __getattr__(self, name):