Example #1
0
        //===================================================================
        // Preloads all currently-known names for the module namespace. This
        // can be called multiple times, to add names from assemblies that
        // may have been loaded since the last call to the method.
        //===================================================================

        public void LoadNames()
        {
            ManagedType m = null;

            foreach (string name in AssemblyManager.GetNames(_namespace))
            {
                this.cache.TryGetValue(name, out m);
                if (m == null)
                {
                    ManagedType attr = this.GetAttribute(name, true);
                    if (Runtime.wrap_exceptions)
                    {
                        if (attr is ExceptionClassObject)
                        {
                            ExceptionClassObject c = attr as ExceptionClassObject;
                            if (c != null)
                            {
                                IntPtr p = attr.pyHandle;
                                IntPtr r = Exceptions.GetExceptionClassWrapper(p);
                                Runtime.PyDict_SetItemString(dict, name, r);
                                Runtime.Incref(r);
                            }
                        }
                    }
                }
            }
        }
Example #2
0
        //====================================================================
        // ModuleObject __getattribute__ implementation. Module attributes
        // are always either classes or sub-modules representing subordinate
        // namespaces. CLR modules implement a lazy pattern - the sub-modules
        // and classes are created when accessed and cached for future use.
        //====================================================================

        public static IntPtr tp_getattro(IntPtr ob, IntPtr key)
        {
            ModuleObject self = (ModuleObject)GetManagedObject(ob);

            if (!Runtime.PyString_Check(key))
            {
                Exceptions.SetError(Exceptions.TypeError, "string expected");
                return(IntPtr.Zero);
            }

            IntPtr op = Runtime.PyDict_GetItem(self.dict, key);

            if (op != IntPtr.Zero)
            {
                Runtime.Incref(op);
                return(op);
            }

            string name = Runtime.GetManagedString(key);

            if (name == "__dict__")
            {
                Runtime.Incref(self.dict);
                return(self.dict);
            }

            ManagedType attr = self.GetAttribute(name, true);

            if (attr == null)
            {
                Exceptions.SetError(Exceptions.AttributeError, name);
                return(IntPtr.Zero);
            }

            // XXX - hack required to recognize exception types. These types
            // may need to be wrapped in old-style class wrappers in versions
            // of Python where new-style classes cannot be used as exceptions.

            if (Runtime.wrap_exceptions)
            {
                if (attr is ExceptionClassObject)
                {
                    ExceptionClassObject c = attr as ExceptionClassObject;
                    if (c != null)
                    {
                        IntPtr p = attr.pyHandle;
                        IntPtr r = Exceptions.GetExceptionClassWrapper(p);
                        Runtime.PyDict_SetItemString(self.dict, name, r);
                        Runtime.Incref(r);
                        return(r);
                    }
                }
            }

            Runtime.Incref(attr.pyHandle);
            return(attr.pyHandle);
        }
Example #3
0
        //===================================================================
        // Preloads all currently-known names for the module namespace. This
        // can be called multiple times, to add names from assemblies that
        // may have been loaded since the last call to the method.
        //===================================================================

        public void LoadNames()
        {
            foreach (string name in AssemblyManager.GetNames(_namespace))
            {
                if (!this.cache.ContainsKey(name))
                {
                    ManagedType attr = this.GetAttribute(name);
                    if (Runtime.wrap_exceptions)
                    {
                        if (attr is ClassBase)
                        {
                            ClassBase c = attr as ClassBase;
                            if (c.is_exception)
                            {
                                IntPtr p = attr.pyHandle;
                                IntPtr r = Exceptions.GetExceptionClassWrapper(p);
                                Runtime.PyDict_SetItemString(dict, name, r);
                                Runtime.Incref(r);
                            }
                        }
                    }
                }
            }
        }