8000 tiny polish · libvips/pyvips@d19a20d · GitHub
[go: up one dir, main page]

Skip to content

Commit d19a20d

Browse files
committed
tiny polish
1 parent f35b0a5 commit d19a20d

File tree

1 file changed

+21
-22
lines changed

1 file changed

+21
-22
lines changed

pyvips/voperation.py

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,6 @@
2222
_OPERATION_DEPRECATED = 8
2323

2424

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-
4125
class Introspect(object):
4226
"""Build introspection data for operations.
4327
@@ -156,6 +140,22 @@ def get(cls, operation_name):
156140
return cls._introspect_cache[operation_name]
157141

158142

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+
159159
class Operation(pyvips.VipsObject):
160160
"""Call libvips operations.
161161
@@ -216,10 +216,6 @@ def call(operation_name, *args, **kwargs):
216216
# logger.debug('VipsOperation.call: args = %s, kwargs =%s',
217217
# args, kwargs)
218218

219-
# pull out the special string_options kwarg
220-
string_options = kwargs.pop('string_options', '')
221-
222-
op = Operation.new_from_name(operation_name)
223219
intro = Introspect.get(operation_name)
224220

225221
if len(intro.required_input) != len(args):
@@ -228,14 +224,17 @@ def call(operation_name, *args, **kwargs):
228224
len(intro.required_input),
229225
len(args)))
230226

227+
op = Operation.new_from_name(operation_name)
228+
231229
# set any string options before any args so they can't be
232230
# overridden
231+
string_options = kwargs.pop('string_options', '')
233232
if not op.set_string(string_options):
234233
raise Error('unable to call {0}'.format(operation_name))
235234

236235
# the first image argument is the thing we expand constants to
237236
# 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
239238
match_image = _find_inside(lambda x: isinstance(x, pyvips.Image),
240239
args)
241240

@@ -257,7 +256,7 @@ def add_reference(x):
257256
_find_inside(add_reference, value)
258257
op.set(name, intro.details[name]['flags'], match_image, value)
259258

260-
# set any kwargs
259+
# set any optional args
261260
for name in kwargs:
262261
value = kwargs[name]
263262
details = intro.details[name]

0 commit comments

Comments
 (0)
0