Ejemplo n.º 1
0
        public void DeleteAttr(ICallerContext context, SymbolId name)
        {
            switch (name.Id)
            {
            case SymbolTable.ClassId: throw Ops.TypeError("__class__ must be set to class");

            case SymbolTable.DictId: throw Ops.TypeError("__dict__ must be set to a dictionary");

            default:
                if (name == SymbolTable.Unassign)
                {
                    // removing finalizer
                    if (HasFinalizer() && !__class__.HasFinalizer)
                    {
                        ClearFinalizer();
                    }
                }

                if (!__dict__.Remove(name))
                {
                    throw Ops.AttributeError("{0} is not a valid attribute", SymbolTable.IdToString(name));
                }
                break;
            }
        }
Ejemplo n.º 2
0
 protected virtual void RawDeleteSlot(SymbolId name)
 {
     if (dict.ContainsKey(name))
     {
         dict.Remove(name);
     }
     else
     {
         throw Ops.AttributeError("No attribute {0}.", name);
     }
 }
Ejemplo n.º 3
0
        public void DeleteAttr(ICallerContext context, SymbolId name)
        {
            if (!__dict__.Remove(name))
            {
                throw Ops.AttributeError("{0} is not a valid attribute", name);
            }

            if (name == SymbolTable.Unassign)
            {
                hasFinalizer = false;
            }
        }
Ejemplo n.º 4
0
        private object setdefaultencodingImpl(object name)
        {
            if (name == null)
            {
                throw Ops.TypeError("name cannot be None");
            }
            string strName = name as string;

            if (strName == null)
            {
                throw Ops.TypeError("name must be a string");
            }

            Encoding enc;

            if (!StringOps.TryGetEncoding(this, strName, out enc))
            {
                throw Ops.LookupError("'{0}' does not match any available encodings", strName);
            }

            DefaultEncoding = enc;
            __dict__.Remove(SymbolTable.SetDefaultEncoding);
            return(null);
        }
Ejemplo n.º 5
0
        public void BaseDelAttr(ICallerContext context, ISuperDynamicObject self, SymbolId name)
        {
            object slot;

            if (!TryLookupSlot(context, name, out slot))
            {
                IAttributesDictionary d = GetInitializedDict((ISuperDynamicObject)self); //!!! forces dict init
                if (d.ContainsKey(name))
                {
                    d.Remove(name);
                    return;
                }
                else
                {
                    throw Ops.AttributeError("no slot named {0} on {1}", SymbolTable.IdToString(name), this.__name__);
                }
            }
            Ops.DelDescriptor(slot, self);
        }
Ejemplo n.º 6
0
        public void DeleteAttr(ICallerContext context, SymbolId name)
        {
            if (name == SymbolTable.Dict)
            {
                throw Ops.TypeError(name.ToString() + " may not be deleted");
            }

            if (dict == null || !dict.ContainsKey(name))
            {
                // We check for SymbolTable.Module as the user code can modify it
                if (name == SymbolTable.Module)
                {
                    throw Ops.TypeError(name.ToString() + " may not be deleted");
                }

                throw Ops.AttributeError("no attribute {0}", name);
            }

            dict.Remove(name);
        }
Ejemplo n.º 7
0
        public bool TryGetAttr(ICallerContext context, SymbolId name, out object value)
        {
            // We lazily load types on demand.  We try to avoid having to iterate
            // all the types in the assembly on each re-load.
            // If a type is in our dictionary we check a 2ndary dictionary which contains
            //      the number of assemblies we knew about when we reflected over it.  If
            //      this number is less than our current number of assemblies the type is good
            //      as it is to hand out.  If the # of assemblies has changed we need to check
            //      all of our loaded assemblies, and hand out all available types (in case there
            //      are collisions).
            // If we fail to find a name in our dictionary then we will only iterate all of the types
            // if we don't have the full assembly loaded.  This is controllved via our assemblyTypeLoadIndex.



            if (__dict__.TryGetValue(name, out value))
            {
                int level;
                if (!loadLevels.TryGetValue(name, out level) || level >= packageAssemblies.Count)
                {
                    return(true);
                }
            }

            if (assemblyTypeLoadIndex != packageAssemblies.Count)
            {
                value = null;
                string typeName = fullName + "." + SymbolTable.IdToString(name);

                bool fRemovedOld = false;

                // try and find the type name...
                for (int i = 0; i < packageAssemblies.Count; i++)
                {
                    string arityName = typeName + '`';
                    Type[] allTypes  = packageAssemblies[i].GetTypes();

                    for (int j = 0; j < allTypes.Length; j++)
                    {
                        Type t      = allTypes[j];
                        int  nested = t.FullName.IndexOf('+');
                        if (nested != -1)
                        {
                            continue;
                        }

                        object [] attrs = t.GetCustomAttributes(typeof(PythonTypeAttribute), false);
                        if ((attrs.Length > 0 && ((PythonTypeAttribute)attrs[0]).name == typeName) ||
                            t.FullName == typeName ||
                            String.Compare(t.FullName, 0, arityName, 0, arityName.Length) == 0)
                        {
                            if (!fRemovedOld)
                            {
                                // remove the old entry, we replace it w/ the values
                                // we get from the full iteration now.
                                if (__dict__.ContainsKey(name))
                                {
                                    __dict__.Remove(name);
                                }

                                fRemovedOld = true;
                            }
                            ComObject.AddType(t.GUID, t);

                            SaveType(t);
                            value = Ops.GetDynamicTypeFromType(t);
                        }
                    }
                    loadLevels[name] = packageAssemblies.Count;
                }

                if (value != null)
                {
                    return(true);
                }
            }

            // could have been a namespace, try the dictionary one last time...
            if (__dict__.TryGetValue(name, out value))
            {
                return(true);
            }

            value = null;
            return(false);
        }
Ejemplo n.º 8
0
        internal bool DeleteAttrWithCustomDict(ICallerContext context, ICustomAttributes self, IAttributesDictionary selfDict, SymbolId name)
        {
            Debug.Assert(IsInstanceOfType(self));

            if (name == SymbolTable.Dict)
                throw Ops.AttributeErrorForReadonlyAttribute(__name__.ToString(), name);

            object value;
            if (selfDict.TryGetValue(name, out value)) {
                if (value == Uninitialized.instance) return false;

                selfDict.Remove(name);
                return true;
            }

            object dummy;
            if (TryLookupSlot(context, name, out dummy)) {
                selfDict[name] = Uninitialized.instance;
                return true;
            } else {
                return selfDict.Remove(name);
            }
        }
Ejemplo n.º 9
0
 public void DeleteAttr(ICallerContext context, SymbolId name)
 {
     __dict__.Remove(name);
 }