[vlc-devel] commit: python-ctypes: accomodate both old and new message exception getter (Olivier Aubert )

git version control git at videolan.org
Fri Aug 28 16:36:27 CEST 2009


vlc | branch: master | Olivier Aubert <olivier.aubert at liris.cnrs.fr> | Fri Aug 28 16:34:49 2009 +0200| [4b8fd6429bf873795a33a73b381e5e29003a8d28] | committer: Olivier Aubert 

python-ctypes: accomodate both old and new message exception getter

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=4b8fd6429bf873795a33a73b381e5e29003a8d28
---

 bindings/python-ctypes/header.py |   49 +++++++++++++++++++++++++++----------
 1 files changed, 36 insertions(+), 13 deletions(-)

diff --git a/bindings/python-ctypes/header.py b/bindings/python-ctypes/header.py
index 4f4c870..83b370f 100755
--- a/bindings/python-ctypes/header.py
+++ b/bindings/python-ctypes/header.py
@@ -91,19 +91,42 @@ class LibVLCException(Exception):
     pass
 
 # From libvlc_structures.h
-class VLCException(ctypes.Structure):
-    """libvlc exception.
-    """
-    _fields_= [
-                ('raised', ctypes.c_int),
-                ('code', ctypes.c_int),
-                ('message', ctypes.c_char_p),
-                ]
-    def init(self):
-        libvlc_exception_init(self)
 
-    def clear(self):
-        libvlc_exception_clear(self)
+# This is version-dependent, depending on the presence of libvlc_exception_get_message.
+
+if hasattr(dll, 'libvlc_exception_get_message'):
+    # New-style message passing
+    class VLCException(ctypes.Structure):
+        """libvlc exception.
+        """
+        _fields_= [
+                    ('raised', ctypes.c_int),
+                    ]
+
+        @property
+        def message(self):
+            return dll.libvlc_exception_get_message()
+
+        def init(self):
+            libvlc_exception_init(self)
+
+        def clear(self):
+            libvlc_exception_clear(self)
+else:
+    # Old-style exceptions
+    class VLCException(ctypes.Structure):
+        """libvlc exception.
+        """
+        _fields_= [
+                    ('raised', ctypes.c_int),
+                    ('code', ctypes.c_int),
+                    ('message', ctypes.c_char_p),
+                    ]
+        def init(self):
+            libvlc_exception_init(self)
+
+        def clear(self):
+            libvlc_exception_clear(self)
 
 class PlaylistItem(ctypes.Structure):
     _fields_= [




More information about the vlc-devel mailing list