示例#1
0
 bool IAttributesDictionary.TryGetValue(SymbolId key, out object value)
 {
     return(TryGetValue(SymbolTable.IdToString(key), out value));
 }
示例#2
0
 bool IAttributesDictionary.ContainsKey(SymbolId key)
 {
     return(ContainsKey(SymbolTable.IdToString(key)));
 }
示例#3
0
 bool IAttributesDictionary.Remove(SymbolId key)
 {
     return(Remove(SymbolTable.IdToString(key)));
 }
示例#4
0
 bool IAttributesCollection.Remove(SymbolId name)
 {
     return(((IDictionary <object, object>) this).Remove(SymbolTable.IdToString(name)));
 }
示例#5
0
        /* IAttributesDictionary is implemented on our built-in
         * dictionaries to allow users to assign dictionaries into
         * classes.  These dictionaries will resolve their key via
         * the field table, but only get used when the user does
         * explicit dictionary assignment.
         *
         */

        #region IAttributesDictionary Members

        void IAttributesDictionary.Add(SymbolId key, object value)
        {
            Add(SymbolTable.IdToString(key), value);
        }
示例#6
0
        /* IAttributesDictionary is implemented on our built-in
         * dictionaries to allow users to assign dictionaries into
         * classes.  These dictionaries will resolve their key via
         * the field table, but only get used when the user does
         * explicit dictionary assignment.
         *
         */

        #region IAttributesCollection Members

        void IAttributesCollection.Add(SymbolId name, object value)
        {
            this[SymbolTable.IdToString(name)] = value;
        }
示例#7
0
 bool IAttributesCollection.ContainsKey(SymbolId name)
 {
     return(__contains__(SymbolTable.IdToString(name)));
 }
示例#8
0
        public void DeleteAttr(ICallerContext context, SymbolId name)
        {
            object dummy;

            if (TypeCache.SystemState.TryGetAttr(context, this, name, out dummy))
            {
                try {
                    TypeCache.SystemState.SetAttr(context, this, name, new Uninitialized((string)SymbolTable.IdToString(name)));
                } catch {
                    throw new NotImplementedException("deleting from sys");
                }
            }
            else
            {
                __dict__.Remove(name);
            }
        }
        public override ICollection <MemberDoc> GetMembers(object value)
        {
            List <MemberDoc> res = new List <MemberDoc>();

            PythonModule mod = value as PythonModule;

            if (mod != null)
            {
                foreach (var kvp in mod.__dict__)
                {
                    AddMember(res, kvp, false);
                }
                return(res);
            }

            NamespaceTracker ns = value as NamespaceTracker;

            if (ns != null)
            {
                foreach (var v in ns.SymbolAttributes)
                {
                    AddMember(
                        res,
                        new KeyValuePair <object, object>(
                            SymbolTable.IdToString(v.Key),
                            Importer.MemberTrackerToPython(_context.SharedClsContext, v.Value)
                            ),
                        false
                        );
                }
            }
            else
            {
                OldInstance oi = value as OldInstance;
                if (oi != null)
                {
                    foreach (var member in oi.Dictionary)
                    {
                        AddMember(res, member, false);
                    }

                    AddOldClassMembers(res, oi._class);
                }
                else
                {
                    PythonType pt = value as PythonType;
                    if (pt != null)
                    {
                        foreach (PythonType type in pt.ResolutionOrder)
                        {
                            foreach (var member in type.GetMemberDictionary(_context.SharedContext))
                            {
                                AddMember(res, member, true);
                            }
                        }
                    }
                    else
                    {
                        OldClass oc = value as OldClass;
                        if (oc != null)
                        {
                            AddOldClassMembers(res, oc);
                        }
                        else
                        {
                            pt = DynamicHelpers.GetPythonType(value);
                            foreach (var member in pt.GetMemberDictionary(_context.SharedContext))
                            {
                                AddMember(res, member, true);
                            }
                        }
                    }

                    IPythonObject ipo = value as IPythonObject;
                    if (ipo != null && ipo.Dict != null)
                    {
                        foreach (var member in ipo.Dict)
                        {
                            AddMember(res, member, false);
                        }
                    }
                }
            }

            return(res.ToArray());
        }
示例#10
0
        /// <summary>
        /// You can't actually set anything on NoneType, we just override this to get the correct error.
        /// </summary>
        public override void SetAttr(ICallerContext context, object self, SymbolId name, object value)
        {
            for (int i = 0; i < noneAttrs.Length; i++)
            {
                if (noneAttrs[i] == name)
                {
                    throw Ops.AttributeError("'NoneType' object attribute '{0}' is read-only", SymbolTable.IdToString(name));
                }
            }

            throw Ops.AttributeError("'NoneType' object has no attribute '{0}'", SymbolTable.IdToString(name));
        }
示例#11
0
 public virtual void SetAttr(ICallerContext context, object self, SymbolId name, object value)
 {
     throw Ops.AttributeError("'{0}' object has no attribute '{1}'", this.__name__, SymbolTable.IdToString(name));
 }
示例#12
0
        public virtual object GetAttr(ICallerContext context, object self, SymbolId name)
        {
            object ret;

            if (TryGetAttr(context, self, name, out ret))
            {
                return(ret);
            }
            throw Ops.AttributeError("'{0}' object has no attribute '{1}'", this.__name__, SymbolTable.IdToString(name));
        }