overrides: accept Gst.Structure in Caps.__new__
authorMathieu Duponchelle <mathieu@centricular.com>
Thu, 15 Feb 2018 19:08:38 +0000 (20:08 +0100)
committerMathieu Duponchelle <mathieu@centricular.com>
Thu, 15 Feb 2018 19:23:34 +0000 (20:23 +0100)
Also rename misleading parameter (*kwargs -> *args)

https://bugzilla.gnome.org/show_bug.cgi?id=793493

gi/overrides/Gst.py

index fce3d1b..a3fc9d1 100644 (file)
@@ -70,15 +70,24 @@ class Caps(Gst.Caps):
     def __nonzero__(self):
         return not self.is_empty()
 
-    def __new__(cls, *kwargs):
-        if not kwargs:
+    def __new__(cls, *args):
+        if not args:
             return Caps.new_empty()
-        elif len(kwargs) > 1:
+        elif len(args) > 1:
             raise TypeError("wrong arguments when creating GstCaps object")
-        elif isinstance(kwargs[0], str):
-            return Caps.from_string(kwargs[0])
-        elif isinstance(kwargs[0], Caps):
-            return kwargs[0].copy()
+        elif isinstance(args[0], str):
+            return Caps.from_string(args[0])
+        elif isinstance(args[0], Caps):
+            return args[0].copy()
+        elif isinstance(args[0], Structure):
+            res = Caps.new_empty()
+            res.append_structure(args[0])
+            return res
+        elif isinstance(args[0], (list, tuple)):
+            res = Caps.new_empty()
+            for e in args[0]:
+                res.append_structure(e)
+            return res
 
         raise TypeError("wrong arguments when creating GstCaps object")