(cls, attr, attr2)
return formats
Return ``{ext: `attr`, ...}`` dict if ``cls`` has `attr2`.
        If `attr` is '', return ``{ext: cls, ...}`` instead.

        If there are multiple formats for an extension, return a format
        with the lowest priority.
Return ``{ext: `attr`, ...}`` dict if ``cls`` has `attr2`.
        If `attr` is '', return ``{ext: cls, ...}`` instead.
Return { ext : attr ... } dict if cls has attr2 . If attr is return { ext : cls ... } instead .
def _ext_to_attr_if_attr2(cls, attr, attr2):
        """
        Return ``{ext: `attr`, ...}`` dict if ``cls`` has `attr2`.
        If `attr` is '', return ``{ext: cls, ...}`` instead.

        If there are multiple formats for an extension, return a format
        with the lowest priority.
        """
        formats = OrderedDict()
        for format_ in sorted(cls.registry.values(), key=lambda x: x.PRIORITY):
            if not hasattr(format_, attr2):
                continue
            for ext in getattr(format_, 'EXTENSIONS', []):
                # Only adds if not yet registered
                formats.setdefault(ext, getattr(format_, attr, format_))
        return formats
def _ext_to_attr_if_attr2 ( cls , attr , attr2 ) : formats = OrderedDict ( ) for format_ in sorted ( cls . registry . values ( ) , key = lambda x : x . PRIORITY ) : if not hasattr ( format_ , attr2 ) : continue for ext in getattr ( format_ , 'EXTENSIONS' , [ ] ) : # Only adds if not yet registered formats . setdefault ( ext , getattr ( format_ , attr , format_ ) ) return formats