public void DeleteAttr(ICallerContext context, SymbolId name)
 {
     if (!GetTypeMap().Remove(name))
     {
         throw Ops.AttributeError("namespace {0} has no type/nested namespace {1}", myNamespace, name);
     }
 }
Beispiel #2
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;
            }
        }
Beispiel #3
0
 public object Call(params object[] args)
 {
     if (func == null)
     {
         throw Ops.AttributeError("{0} not defined on instance of {1}", name, pythonType.__name__);
     }
     return(Ops.Call(func, args));
 }
        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));
        }
Beispiel #5
0
 protected virtual void RawDeleteSlot(SymbolId name)
 {
     if (dict.ContainsKey(name))
     {
         dict.Remove(name);
     }
     else
     {
         throw Ops.AttributeError("No attribute {0}.", name);
     }
 }
Beispiel #6
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;
            }
        }
 public object GetAttribute(object instance, object owner)
 {
     if (instance == null)
     {
         return(this);
     }
     if (fget != null)
     {
         return(Ops.Call(fget, instance));
     }
     throw Ops.AttributeError("unreadable attribute");
 }
Beispiel #8
0
 public object Invoke(object self, object arg1, object arg2, object arg3)
 {
     if (func == null)
     {
         throw Ops.AttributeError("{0} not defined on instance of {1}", name, pythonType.__name__);
     }
     if (funcAsFunc != null)
     {
         return(funcAsFunc.Call(self, arg1, arg2, arg3));
     }
     return(Ops.Call(Ops.GetDescriptor(func, self, pythonType), arg1, arg2, arg3));
 }
        /// <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));
        }
Beispiel #10
0
 public object GetAttribute(object instance, object owner)
 {
     if (func == null)
     {
         throw Ops.AttributeError("{0} not defined on instance of {1}", name, pythonType.__name__);
     }
     if (instance != null)
     {
         return(new Method(func, instance, owner));
     }
     else
     {
         return(func);
     }
 }
Beispiel #11
0
        public bool DeleteAttribute(object instance)
        {
            if (fdel != null)
            {
                Ops.Call(fdel, instance);
                return(true);
            }
            else
            {
                if (instance == null)
                {
                    return(false);
                }

                throw Ops.AttributeError("undeletable attribute");
            }
        }
Beispiel #12
0
        public bool SetAttribute(object instance, object value)
        {
            if (fset != null)
            {
                Ops.Call(fset, instance, value);
                return(true);
            }
            else
            {
                if (instance == null)
                {
                    return(false);
                }

                throw Ops.AttributeError("readonly attribute");
            }
        }
Beispiel #13
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);
        }
Beispiel #14
0
 public override object GetAttr(ICallerContext context, object self, SymbolId name)
 {
     if (__getattribute__F.IsObjectMethod())
     {
         object ret;
         if (TryBaseGetAttr(context, (ISuperDynamicObject)self, name, out ret))
         {
             return(ret);
         }
         else
         {
             throw Ops.AttributeError((string)SymbolTable.IdToString(name));
         }
     }
     else
     {
         return(__getattribute__F.Invoke(self, SymbolTable.IdToString(name)));
     }
 }
Beispiel #15
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);
        }
Beispiel #16
0
        public static object GetAttributeMethod(object self, object name)
        {
            string strName = name as string;

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

            ISuperDynamicObject s = self as ISuperDynamicObject;

            if (s != null)
            {
                object ret;
                if (((UserType)s.GetDynamicType()).TryBaseGetAttr(DefaultContext.Default, s, SymbolTable.StringToId(strName), out ret))
                {
                    return(ret);
                }
            }
            throw Ops.AttributeError("no attribute {0}", name); //??? better message
        }
        public override bool TryGetAttr(ICallerContext context, object self, SymbolId name, out object ret)
        {
            Assembly          asm = self as Assembly;
            ReflectedAssembly reflectedAssembly = GetReflectedAssembly(asm);

            if (name == SymbolTable.Dict)
            {
                ret = reflectedAssembly.GetTypeMap();
                return(true);
            }

            if (base.TryGetAttr(context, self, name, out ret))
            {
                return(true);
            }

            if (!reflectedAssembly.TryGetValue(name, out ret))
            {
                throw Ops.AttributeError("assembly {0} has no type {1}", asm.GetName().Name, name);
            }

            return(true);
        }
Beispiel #18
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));
 }