예제 #1
0
        public object GetCustomMember(CodeContext context, string name)
        {
            // first find where we are in the mro...
            PythonType mroType = _selfClass as PythonType;

            object value;

            if (mroType != null)   // can be null if the user does super.__new__
            {
                IList <PythonType> mro = mroType.ResolutionOrder;

                int  lookupType;
                bool foundThis = false;
                for (lookupType = 0; lookupType < mro.Count; lookupType++)
                {
                    if (mro[lookupType] == _thisClass)
                    {
                        foundThis = true;
                        break;
                    }
                }

                if (!foundThis)
                {
                    // __self__ is not a subclass of __thisclass__, we need to
                    // search __thisclass__'s mro and return a method from one
                    // of it's bases.
                    lookupType = 0;
                    mro        = _thisClass.ResolutionOrder;
                }

                // if we're super on a class then we have no self.
                object self = _self == _selfClass ? null : _self;

                // then skip our class, and lookup in everything
                // above us until we get a hit.
                lookupType++;
                while (lookupType < mro.Count)
                {
                    if (TryLookupInBase(context, mro[lookupType], name, self, out value))
                    {
                        return(value);
                    }

                    lookupType++;
                }
            }

            if (PythonType.TryGetBoundMember(context, this, name, out value))
            {
                return(value);
            }

            return(OperationFailed.Value);
        }