def getownattr(cls, attrib_name):
    """
    Return the value of `cls.<attrib_name>` if it is defined in the class (and not inherited).
    If the attribute is not present or is inherited, an `AttributeError` is raised.

    >>> class A(object):
    ...     a = 1
    >>>
    >>> class B(A):
    ...     pass
    >>>
    >>> getownattr(A, 'a')
    1
    >>> getownattr(A, 'unknown')
    Traceback (most recent call last):
        ...
    AttributeError: type object 'A' has no attribute 'unknown'
    >>> getownattr(B, 'a')
    Traceback (most recent call last):
        ...
    AttributeError: type object 'B' has no directly defined attribute 'a'

    """
    attr = getattr(cls, attrib_name)

    for base_cls in cls.__mro__[1:]:
        a = getattr(base_cls, attrib_name, None)
        if attr is a:
            raise AttributeError("type object %r has no directly defined attribute %r" % (cls.__name__, attrib_name))

    return attr