'Get an item or attribute of an object but prefer the attribute.
Unlike :meth:`getitem` the attribute *must* be a bytestring.'

def getattr(self, obj, attribute):

    try:
        return getattr(obj, attribute)
    except AttributeError:
        pass
    try:
        return obj[attribute]
    except (TypeError, LookupError, AttributeError):
        return self.undefined(obj=obj, name=attribute)
