aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2019-02-26 20:39:44 -0800
committerOle Trøan <otroan@employees.org>2019-02-28 23:09:17 +0000
commit5fced04ba58a14c370c60c275302519de5e15893 (patch)
tree56faac260da7a970ceef0302cea7ce01a7e0a442
parent5ad273adecb11c82862afe9e8b37d171978545dc (diff)
vpp_papi.py: Change VppEnum from explicit metaclass to metaclass wrapper/decorator.
Change-Id: Iab41bb972e3c7ec005a1a13d5a25f654ae8c3932 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_papi.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py
index 9c4ede90d48..2b73023025b 100644
--- a/src/vpp-api/python/vpp_papi/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi/vpp_papi.py
@@ -21,6 +21,7 @@ import os
import logging
import collections
import struct
+import functools
import json
import threading
import fnmatch
@@ -38,17 +39,23 @@ else:
import queue as queue
+def metaclass(metaclass):
+ @functools.wraps(metaclass)
+ def wrapper(cls):
+ return metaclass(cls.__name__, cls.__bases__, cls.__dict__.copy())
+
+ return wrapper
+
+
class VppEnumType(type):
def __getattr__(cls, name):
t = vpp_get_type(name)
return t.enum
-# Python3
-# class VppEnum(metaclass=VppEnumType):
-# pass
+@metaclass(VppEnumType)
class VppEnum(object):
- __metaclass__ = VppEnumType
+ pass
def vpp_atexit(vpp_weakref):