def filter_from_mapping(self, mapping, backend=None):
def mapping_filter(key_item):<EOL><INDENT>key, item = key_item<EOL>return (<EOL>(mapping is None or item.mapping == mapping or<EOL>(mapping[<NUM_LIT:1>] is None and item.mapping is not None and item.mapping[<NUM_LIT:0>] == mapping[<NUM_LIT:0>])) and<EOL>(backend is None or item.backend == backend)<EOL>)<EOL><DEDENT>items = [item for item in six.iteritems(self) if mapping_filter(item)]<EOL>aliases = collections.OrderedDict(<EOL>sorted(items, key=lambda alias: alias[<NUM_LIT:1>].mapping<EOL>if alias[<NUM_LIT:1>] is not None else (<NUM_LIT:0>, <NUM_LIT:0>))<EOL>)<EOL>return aliases<EOL>
Return mappings that either exactly correspond to the given `mapping`
tuple, or, if the second item of `mapping` is `None`, include mappings
that only match the first item of `mapping` (useful to show all
mappings for a given project).