Fix lookup scoping multi-match ordering

When look-up is occurring the possible provider
ordering is used instead of the scope returned provider
ordering. This causes incorrect matches when look-up
argument names that are produced by multiple providers (at
the same scope level) all providing the same requirement
name.

The scope order should be enforced as the de-facto order
and not the order that the storage unit finds (which is
hash based and varies depending on hash ordering).

Closes-Bug: #1425326

Change-Id: I15f1ee5515758bdc470c0f7dd7a2f616923e5628
This commit is contained in:
Joshua Harlow
2015-02-24 16:19:04 -08:00
committed by Joshua Harlow
parent 7f9e44d501
commit 0a97fb96b5
6 changed files with 101 additions and 9 deletions

View File

@@ -196,6 +196,37 @@ def parse_uri(uri):
return netutils.urlsplit(uri)
def look_for(haystack, needles, extractor=None):
"""Find items in haystack and returns matches found (in haystack order).
Given a list of items (the haystack) and a list of items to look for (the
needles) this will look for the needles in the haystack and returns
the found needles (if any). The ordering of the returned needles is in the
order they are located in the haystack.
Example input and output:
>>> from taskflow.utils import misc
>>> hay = [3, 2, 1]
>>> misc.look_for(hay, [1, 2])
[2, 1]
"""
if not haystack:
return []
if extractor is None:
extractor = lambda v: v
matches = []
for i, v in enumerate(needles):
try:
matches.append((haystack.index(extractor(v)), i))
except ValueError:
pass
if not matches:
return []
else:
return [needles[i] for (_hay_i, i) in sorted(matches)]
def clamp(value, minimum, maximum, on_clamped=None):
"""Clamps a value to ensure its >= minimum and <= maximum."""
if minimum > maximum: