0001class NoDefault: pass
0002
0003def getlogoattr(obj, attr, default=NoDefault):
0004 if hasattr(obj, attr):
0005 return getattr(obj, attr)
0006 to_do = [obj] + mro(obj)
0007 for o in to_do:
0008 result = _findattr(o, attr)
0009 if result is not None:
0010 return getattr(obj, result)
0011 if default is NoDefault:
0012 raise AttributeError(
0013 "Attribute %s not found in %r" % (attr, obj))
0014 else:
0015 return default
0016
0017def _findattr(obj, attr):
0018 for name, value in obj.__dict__.items():
0019 if name.lower() == attr.lower():
0020 return name
0021 if hasattr(value, 'aliases'):
0022 for alias in value.aliases:
0023 if alias.lower() == attr.lower():
0024 return name
0025 return None
0026
0027def _enumattr(obj):
0028 result = {}
0029 for o in [obj] + mro(obj):
0030 for name, value in o.__dict__.items():
0031 result[name] = None
0032 for alias in getattr(value, 'aliases', ()):
0033 result[alias] = None
0034 return sorted(result.keys())
0035
0036def mro(obj):
0037 if hasattr(obj, '__mro__'):
0038 return obj.__mro__
0039 if not hasattr(obj, '__bases__'):
0040 obj = obj.__class__
0041 result = [obj]
0042 for base in obj.__bases__:
0043 result.extend(mro(base))
0044 return result
0045
0046def update_logo_attrs(obj):
0047 if hasattr(obj, '_logo_attrs'):
0048 return
0049 attrs = {}
0050 to_do = [obj] + mro(obj)
0051 for o in to_do:
0052 if hasattr(o, '_logo_attrs'):
0053 attrs.update(o._logo_attrs)
0054 break
0055 for name, value in o.__dict__.iteritems():
0056 if getattr(value, 'logo_expose', False):
0057 if name.lower() != name:
0058 attrs[name.lower()] = name
0059 if hasattr(value, 'aliases'):
0060 for alias in value.aliases:
0061 attrs[alias] = name
0062 obj._logo_attrs = attrs