@@ -144,67 +144,61 @@ def __repr__(self):
144
144
return "<_MultiCall %s, kwargs=%r>" % (status , self .caller_kwargs )
145
145
146
146
147
- class _MultiCall (object ):
148
- """Execute a call into multiple python functions/methods.
149
- """
150
- def __init__ (self , hook_impls , kwargs , specopts = {}, hook = None ):
151
- self .hook = hook
152
- self .hook_impls = hook_impls
153
- self .caller_kwargs = kwargs # come from _HookCaller.__call__()
154
- self .specopts = hook .spec_opts if hook else specopts
147
+ def _legacymulticall (hook_impls , caller_kwargs , specopts = {}, hook = None ):
148
+ return _LegacyMultiCall (
149
+ hook_impls , caller_kwargs , specopts = specopts , hook = hook ).execute ()
155
150
156
- def execute (self ):
157
- __tracebackhide__ = True
158
- caller_kwargs = self .caller_kwargs
159
- self .results = results = []
160
- firstresult = self .specopts .get ("firstresult" )
161
- excinfo = None
162
- try : # run impl and wrapper setup functions in a loop
163
- teardowns = []
164
- try :
165
- for hook_impl in reversed (self .hook_impls ):
166
- try :
167
- args = [caller_kwargs [argname ] for argname in hook_impl .argnames ]
168
- # args = operator.itemgetter(hookimpl.argnames)(caller_kwargs)
169
- except KeyError :
170
- for argname in hook_impl .argnames :
171
- if argname not in caller_kwargs :
172
- raise HookCallError (
173
- "hook call must provide argument %r" % (argname ,))
174
-
175
- if hook_impl .hookwrapper :
176
- try :
177
- gen = hook_impl .function (* args )
178
- next (gen ) # first yield
179
- teardowns .append (gen )
180
- except StopIteration :
181
- _raise_wrapfail (gen , "did not yield" )
182
- else :
183
- res = hook_impl .function (* args )
184
- if res is not None :
185
- results .append (res )
186
- if firstresult : # halt further impl calls
187
- break
188
- except BaseException :
189
- excinfo = sys .exc_info ()
190
- finally :
191
- if firstresult : # first result hooks return a single value
192
- outcome = _Result (results [0 ] if results else None , excinfo )
193
- else :
194
- outcome = _Result (results , excinfo )
195
-
196
- # run all wrapper post-yield blocks
197
- for gen in reversed (teardowns ):
151
+
152
+ def _multicall (hook_impls , caller_kwargs , specopts = {}, hook = None ):
153
+ """Execute a call into multiple python functions/methods and return the
154
+ result(s).
155
+
156
+ ``caller_kwargs`` comes from _HookCaller.__call__().
157
+ """
158
+ __tracebackhide__ = True
159
+ specopts = hook .spec_opts if hook else specopts
160
+ results = []
161
+ firstresult = specopts .get ("firstresult" )
162
+ excinfo = None
163
+ try : # run impl and wrapper setup functions in a loop
164
+ teardowns = []
165
+ try :
166
+ for hook_impl in reversed (hook_impls ):
198
167
try :
199
- gen .send (outcome )
200
- _raise_wrapfail (gen , "has second yield" )
201
- except StopIteration :
202
- pass
168
+ args = [caller_kwargs [argname ] for argname in hook_impl .argnames ]
169
+ except KeyError :
170
+ for argname in hook_impl .argnames :
171
+ if argname not in caller_kwargs :
172
+ raise HookCallError (
173
+ "hook call must provide argument %r" % (argname ,))
174
+
175
+ if hook_impl .hookwrapper :
176
+ try :
177
+ gen = hook_impl .function (* args )
178
+ next (gen ) # first yield
179
+ teardowns .append (gen )
180
+ except StopIteration :
181
+ _raise_wrapfail (gen , "did not yield" )
182
+ else :
183
+ res = hook_impl .function (* args )
184
+ if res is not None :
185
+ results .append (res )
186
+ if firstresult : # halt further impl calls
187
+ break
188
+ except BaseException :
189
+ excinfo = sys .exc_info ()
190
+ finally :
191
+ if firstresult : # first result hooks return a single value
192
+ outcome = _Result (results [0 ] if results else None , excinfo )
193
+ else :
194
+ outcome = _Result (results , excinfo )
203
195
204
- return outcome .get_result ()
196
+ # run all wrapper post-yield blocks
197
+ for gen in reversed (teardowns ):
198
+ try :
199
+ gen .send (outcome )
200
+ _raise_wrapfail (gen , "has second yield" )
201
+ except StopIteration :
202
+ pass
205
203
206
- def __repr__ (self ):
207
- status = "%d meths" % (len (self .hook_impls ),)
208
- if hasattr (self , "results" ):
209
- status = ("%d results, " % len (self .results )) + status
210
- return "<_MultiCall %s, kwargs=%r>" % (status , self .caller_kwargs )
204
+ return outcome .get_result ()
0 commit comments