22
22
_OPERATION_DEPRECATED = 8
23
23
24
24
25
- # search an array with a predicate, recursing into subarrays as we see them
26
- # used to find the match_image for an operation
27
- def _find_inside (pred , thing ):
28
- if pred (thing ):
29
- return thing
30
-
31
- if isinstance (thing , list ) or isinstance (thing , tuple ):
32
- for x in thing :
33
- result = _find_inside (pred , x )
34
-
35
- if result is not None :
36
- return result
37
-
38
- return None
39
-
40
-
41
25
class Introspect (object ):
42
26
"""Build introspection data for operations.
43
27
@@ -156,6 +140,22 @@ def get(cls, operation_name):
156
140
return cls ._introspect_cache [operation_name ]
157
141
158
142
143
+ # search an array with a predicate, recursing into subarrays as we see them
144
+ # used to find the match_image for an operation
145
+ def _find_inside (pred , thing ):
146
+ if pred (thing ):
147
+ return thing
148
+
149
+ if isinstance (thing , list ) or isinstance (thing , tuple ):
150
+ for x in thing :
151
+ result = _find_inside (pred , x )
152
+
153
+ if result is not None :
154
+ return result
155
+
156
+ return None
157
+
158
+
159
159
class Operation (pyvips .VipsObject ):
160
160
"""Call libvips operations.
161
161
@@ -216,10 +216,6 @@ def call(operation_name, *args, **kwargs):
216
216
# logger.debug('VipsOperation.call: args = %s, kwargs =%s',
217
217
# args, kwargs)
218
218
219
- # pull out the special string_options kwarg
220
- string_options = kwargs .pop ('string_options' , '' )
221
-
222
- op = Operation .new_from_name (operation_name )
223
219
intro = Introspect .get (operation_name )
224
220
225
221
if len (intro .required_input ) != len (args ):
@@ -228,14 +224,17 @@ def call(operation_name, *args, **kwargs):
228
224
len (intro .required_input ),
229
225
len (args )))
230
226
227
+ op = Operation .new_from_name (operation_name )
228
+
231
229
# set any string options before any args so they can't be
232
230
# overridden
231
+ string_options = kwargs .pop ('string_options' , '' )
233
232
if not op .set_string (string_options ):
234
233
raise Error ('unable to call {0}' .format (operation_name ))
235
234
236
235
# the first image argument is the thing we expand constants to
237
236
# match ... look inside tables for images, since we may be passing
238
- # an array of image as a single param
237
+ # an array of images as a single param
239
238
match_image = _find_inside (lambda x : isinstance (x , pyvips .Image ),
240
239
args )
241
240
@@ -257,7 +256,7 @@ def add_reference(x):
257
256
_find_inside (add_reference , value )
258
257
op .set (name , intro .details [name ]['flags' ], match_image , value )
259
258
260
- # set any kwargs
259
+ # set any optional args
261
260
for name in kwargs :
262
261
value = kwargs [name ]
263
262
details = intro .details [name ]
0 commit comments