overrides: accept Gst.Structure in Caps.__new__

Also rename misleading parameter (*kwargs -> *args)

https://bugzilla.gnome.org/show_bug.cgi?id=793493
This commit is contained in:
Mathieu Duponchelle 2018-02-15 20:08:38 +01:00
parent 429b58ed29
commit 8a807cc1be

View 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")