(obj, key)
Get the attribute referenced by 'key'. The key is used
    to build the name of an attribute, or attribute accessor method.

    The following attributes and accesors are tried (in this order):

    - Accessor 'getKey'
    - Accesoor 'get_key'
    - Accessor or attribute 'key'
    - Accessor or attribute 'isKey'
    - Attribute '_key'

    If none of these exist, raise KeyError
Get the attribute referenced by 'key'. The key is used
    to build the name of an attribute, or attribute accessor method.
Get the attribute referenced by key . The key is used to build the name of an attribute or attribute accessor method .
def getKey(obj, key):
    """
    Get the attribute referenced by 'key'. The key is used
    to build the name of an attribute, or attribute accessor method.

    The following attributes and accesors are tried (in this order):

    - Accessor 'getKey'
    - Accesoor 'get_key'
    - Accessor or attribute 'key'
    - Accessor or attribute 'isKey'
    - Attribute '_key'

    If none of these exist, raise KeyError
    """
    if obj is None:
        return None
    if isinstance(obj, (objc.objc_object, objc.objc_class)):
        return obj.valueForKey_(key)

    # check for dict-like objects
    getitem = getattr(obj, '__getitem__', None)
    if getitem is not None:
        try:
            return getitem(key)
        except (KeyError, IndexError, TypeError):
            pass

    # check for array-like objects
    if isinstance(obj, (collections_abc.Sequence, collections_abc.Set)) and not isinstance(obj, (basestring, collections_abc.Mapping)):
        def maybe_get(obj, key):
            try:
                return getKey(obj, key)
            except KeyError:
                return _null
        return [maybe_get(obj, key) for obj in iter(obj)]

    try:
        m = getattr(obj, "get" + keyCaps(key))
    except AttributeError:
        pass
    else:
        return m()

    try:
        m = getattr(obj, "get_" + key)
    except AttributeError:
        pass
    else:
        return m()

    for keyName in (key, "is" + keyCaps(key)):
        try:
            m = getattr(obj, keyName)
        except AttributeError:
            continue

        if isinstance(m, types.MethodType) and m.__self__ is obj:
            return m()

        elif isinstance(m, types.BuiltinMethodType):
            # Can't access the bound self of methods of builtin classes :-(
            return m()

        elif isinstance(m, objc.selector) and m.self is obj:
            return m()

        else:
            return m

    try:
        return getattr(obj, "_" + key)
    except AttributeError:
        raise KeyError("Key %s does not exist" % (key,))
def getKey ( obj , key ) : if obj is None : return None if isinstance ( obj , ( objc . objc_object , objc . objc_class ) ) : return obj . valueForKey_ ( key ) # check for dict-like objects getitem = getattr ( obj , '__getitem__' , None ) if getitem is not None : try : return getitem ( key ) except ( KeyError , IndexError , TypeError ) : pass # check for array-like objects if isinstance ( obj , ( collections_abc . Sequence , collections_abc . Set ) ) and not isinstance ( obj , ( basestring , collections_abc . Mapping ) ) : def maybe_get ( obj , key ) : try : return getKey ( obj , key ) except KeyError : return _null return [ maybe_get ( obj , key ) for obj in iter ( obj ) ] try : m = getattr ( obj , "get" + keyCaps ( key ) ) except AttributeError : pass else : return m ( ) try : m = getattr ( obj , "get_" + key ) except AttributeError : pass else : return m ( ) for keyName in ( key , "is" + keyCaps ( key ) ) : try : m = getattr ( obj , keyName ) except AttributeError : continue if isinstance ( m , types . MethodType ) and m . __self__ is obj : return m ( ) elif isinstance ( m , types . BuiltinMethodType ) : # Can't access the bound self of methods of builtin classes :-( return m ( ) elif isinstance ( m , objc . selector ) and m . self is obj : return m ( ) else : return m try : return getattr ( obj , "_" + key ) except AttributeError : raise KeyError ( "Key %s does not exist" % ( key , ) )