From 8a976a1e7353d4a69dcd094216ef261634d5b710 Mon Sep 17 00:00:00 2001 From: John Cupitt Date: Wed, 3 Sep 2014 17:54:36 +0100 Subject: [PATCH] auto un-VipsBlob-ification --- python/vips8/vips.py | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/python/vips8/vips.py b/python/vips8/vips.py index 067b705b..d4d77d8e 100644 --- a/python/vips8/vips.py +++ b/python/vips8/vips.py @@ -68,7 +68,7 @@ class Argument: # blob-ize if GObject.type_is_a(self.prop.value_type, vips_type_blob): - if not isinstance(gi.repository.Vips.Blob, value): + if not isinstance(value, Vips.Blob): value = Vips.Blob.new(None, value) logging.debug('assigning %s' % self.prop.value_type) @@ -76,9 +76,17 @@ class Argument: self.op.props.__setattr__(self.name, value) def get_value(self): - x = self.op.props.__getattribute__(self.name) + value = self.op.props.__getattribute__(self.name) - return x + logging.debug('read out %s from %s' % (value, self.name)) + + # turn VipsBlobs into strings + # FIXME ... this will involve a copy, we should use + # buffer() instead + if isinstance(value, Vips.Blob): + value = value.get() + + return value def _call_base(name, required, optional, self = None, option_string = None): logging.debug('_call_base name=%s, required=%s optional=%s' % @@ -151,24 +159,28 @@ def _call_base(name, required, optional, self = None, option_string = None): if op2 == None: raise Error('Error calling operator %s.' % name) - # find all required output args ... just need the names + # rescan args, op2 has changed + args = [Argument(op2, x) for x in op2.props] + args.sort(lambda a, b: a.priority - b.priority) + + # find all required output args # we can't check assigned here (since we captured the value before the call) # but the getattr will test that for us anyway - required_output = [x.name for x in args if x.flags & enm.OUTPUT and + required_output = [x for x in args if x.flags & enm.OUTPUT and x.flags & enm.REQUIRED] # gather output args out = [] for x in required_output: - out.append(op2.props.__getattribute__(x)) + out.append(x.get_value()) - # find all optional output args ... just need the names + # find all optional output args optional_output = [x.name for x in args if x.flags & enm.OUTPUT and not x.flags & enm.REQUIRED] for x in optional.keys(): if x in optional_output: - out.append(op2.props.__getattribute__(x)) + out.append(x.get_value()) if len(out) == 1: out = out[0] @@ -176,7 +188,7 @@ def _call_base(name, required, optional, self = None, option_string = None): # unref everything now we have refs to all outputs we want op2.unref_outputs() - logging.debug('success, out = %s' % out) + logging.debug('success') return out