Exemplo n.º 1
0
        private bool TryLookupInBase(CodeContext context, PythonType pt, string name, object self, out object value)
        {
            PythonTypeSlot dts;

            if (pt.OldClass == null)
            {
                // new-style class, or reflected type, lookup slot
                if (pt.TryLookupSlot(context, name, out dts) &&
                    dts.TryGetValue(context, self, DescriptorContext, out value))
                {
                    return(true);
                }
            }
            else
            {
                // old-style class, lookup attribute
                OldClass dt = pt.OldClass;

                if (PythonOps.TryGetBoundAttr(context, dt, name, out value))
                {
                    value = OldClass.GetOldStyleDescriptor(context, value, self, DescriptorContext);
                    return(true);
                }
            }
            value = null;
            return(false);
        }
Exemplo n.º 2
0
        private bool TryLookupInBase(CodeContext context, PythonType pt, string name, object self, out object value)
        {
            PythonTypeSlot dts;

            // new-style class, or reflected type, lookup slot
            if (pt.TryLookupSlot(context, name, out dts) &&
                dts.TryGetValue(context, self, DescriptorContext, out value))
            {
                return(true);
            }
            value = null;
            return(false);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Looks up a __xyz__ method in slots only (because we should never lookup
        /// in instance members for these)
        /// </summary>
        internal static bool TryLookupSpecialMethod(ICallerContext context, object self, SymbolId symbol, out object ret)
        {
            IDynamicObject ido = self as IDynamicObject;

            if (ido != null)
            {
                PythonType pt = (PythonType)ido.GetDynamicType();

                if (pt.TryLookupSlot(context, symbol, out ret))
                {
                    ret = Ops.GetDescriptor(ret, self, pt);
                    return(true);
                }
            }
            ret = null;
            return(false);
        }
Exemplo n.º 4
0
        internal static bool TryGetValueVirtual(CodeContext context, PythonDictionary self, object key, ref object DefaultGetItem, out object value)
        {
            IPythonObject sdo = self as IPythonObject;

            if (sdo != null)
            {
                Debug.Assert(sdo != null);
                PythonType     myType = sdo.PythonType;
                object         ret;
                PythonTypeSlot dts;

                if (DefaultGetItem == null)
                {
                    // lazy init our cached DefaultGetItem
                    TypeCache.Dict.TryLookupSlot(context, "__getitem__", out dts);
                    bool res = dts.TryGetValue(context, self, TypeCache.Dict, out DefaultGetItem);
                    Debug.Assert(res);
                }

                // check and see if it's overridden
                if (myType.TryLookupSlot(context, "__getitem__", out dts))
                {
                    dts.TryGetValue(context, self, myType, out ret);

                    if (ret != DefaultGetItem)
                    {
                        // subtype of dict that has overridden __getitem__
                        // we need to call the user's versions, and handle
                        // any exceptions.
                        try {
                            value = self[key];
                            return(true);
                        } catch (KeyNotFoundException) {
                            value = null;
                            return(false);
                        }
                    }
                }
            }

            value = null;
            return(false);
        }