332 """return an instance of the most specific object according |
332 """return an instance of the most specific object according |
333 to parameters |
333 to parameters |
334 |
334 |
335 raise NoSelectableObject if not object apply |
335 raise NoSelectableObject if not object apply |
336 """ |
336 """ |
337 score, winner = 0, None |
337 score, winners = 0, [] |
338 for vobject in vobjects: |
338 for vobject in vobjects: |
339 vobjectscore = vobject.__select__(*args, **kwargs) |
339 vobjectscore = vobject.__select__(*args, **kwargs) |
340 if vobjectscore > score: |
340 if vobjectscore > score: |
341 score, winner = vobjectscore, vobject |
341 score, winners = vobjectscore, [vobject] |
342 if winner is None: |
342 elif vobjectscore > 0 and vobjectscore == score: |
|
343 winners.append(vobject) |
|
344 if not winners: |
343 raise NoSelectableObject('args: %s\nkwargs: %s %s' |
345 raise NoSelectableObject('args: %s\nkwargs: %s %s' |
344 % (args, kwargs.keys(), [repr(v) for v in vobjects])) |
346 % (args, kwargs.keys(), [repr(v) for v in vobjects])) |
|
347 if len(winners) > 1: |
|
348 if self.config.mode == 'installed': |
|
349 self.error('select ambiguity, args: %s\nkwargs: %s %s', |
|
350 args, kwargs.keys(), [repr(v) for v in winners]) |
|
351 else: |
|
352 raise Exception('select ambiguity, args: %s\nkwargs: %s %s' |
|
353 % (args, kwargs.keys(), [repr(v) for v in winners])) |
|
354 winner = winners[0] |
345 # return the result of the .selected method of the vobject |
355 # return the result of the .selected method of the vobject |
346 return winner.selected(*args, **kwargs) |
356 return winner.selected(*args, **kwargs) |
347 |
357 |
348 def possible_objects(self, registry, *args, **kwargs): |
358 def possible_objects(self, registry, *args, **kwargs): |
349 """return an iterator on possible objects in a registry for this result set |
359 """return an iterator on possible objects in a registry for this result set |