summaryrefslogtreecommitdiffstats
path: root/src/vpp-api
diff options
context:
space:
mode:
Diffstat (limited to 'src/vpp-api')
-rw-r--r--src/vpp-api/python/setup.py2
-rw-r--r--src/vpp-api/python/vpp_papi.py18
2 files changed, 17 insertions, 3 deletions
diff --git a/src/vpp-api/python/setup.py b/src/vpp-api/python/setup.py
index 626dddeeda2..abda43de606 100644
--- a/src/vpp-api/python/setup.py
+++ b/src/vpp-api/python/setup.py
@@ -26,7 +26,7 @@ setup (name = 'vpp_papi',
python_requires='>=2.7, >=3.3',
license = 'Apache-2.0',
test_suite = 'tests',
- install_requires=['cffi >= 1.10'],
+ install_requires=['cffi >= 1.6'],
py_modules=['vpp_papi'],
long_description = '''VPP Python language binding.''',
zip_safe = True,
diff --git a/src/vpp-api/python/vpp_papi.py b/src/vpp-api/python/vpp_papi.py
index 67ac22a4d32..e7e1707c435 100644
--- a/src/vpp-api/python/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi.py
@@ -25,6 +25,7 @@ import threading
import glob
import atexit
from cffi import FFI
+import cffi
if sys.version[0] == '2':
import Queue as queue
@@ -54,7 +55,6 @@ void vac_set_error_handler(vac_error_callback_t);
# Barfs on failure, no need to check success.
vpp_api = ffi.dlopen('libvppapiclient.so')
-
def vpp_atexit(self):
"""Clean up VPP connection on shutdown."""
if self.connected:
@@ -166,6 +166,14 @@ class VPP():
# Register error handler
vpp_api.vac_set_error_handler(vac_error_handler)
+ # Support legacy CFFI
+ # from_buffer supported from 1.8.0
+ (major, minor, patch) = [int(s) for s in cffi.__version__.split('.', 3)]
+ if major >= 1 and minor >= 8:
+ self._write = self._write_new_cffi
+ else:
+ self._write = self._write_legacy_cffi
+
class ContextId(object):
"""Thread-safe provider of unique context IDs."""
def __init__(self):
@@ -469,12 +477,18 @@ class VPP():
self.logger.debug(
'No such message type or failed CRC checksum: %s', n)
- def _write(self, buf):
+ def _write_new_cffi(self, buf):
"""Send a binary-packed message to VPP."""
if not self.connected:
raise IOError(1, 'Not connected')
return vpp_api.vac_write(ffi.from_buffer(buf), len(buf))
+ def _write_legacy_cffi(self, buf):
+ """Send a binary-packed message to VPP."""
+ if not self.connected:
+ raise IOError(1, 'Not connected')
+ return vpp_api.vac_write(str(buf), len(buf))
+
def _read(self):
if not self.connected:
raise IOError(1, 'Not connected')