def guess_id(which, attr='id'):
    """Guess the id of an object.

    If `which` is an integer, it is returned unchanged.  If it is a dict
    or a browse_record the attribute/key given by `attr` is look up and
    return.  If not found an AttibuteError is raised.  Any other type is a
    TypeError.

    """
    from xoeuf.odoo.osv.orm import browse_record
    from xoutil.future.collections import Mapping
    if isinstance(which, int):
        return which
    elif isinstance(which, (Mapping, browse_record)):
        from xoutil.objects import smart_getter
        get = smart_getter(which, strict=True)
        return get(attr)
    else:
        raise TypeError('Object %r of invalid type' % which)
