Ejemplo n.º 1
0
        internal static PythonModule ReloadBuiltin(PythonModule module)
        {
            Type ty;

            if (module.SystemState.TopPackage.Builtins.TryGetValue(module.ModuleName, out ty))
            {
                if (typeof(CustomFieldIdDict).IsAssignableFrom(ty))
                {
                    CustomFieldIdDict dict = (CustomFieldIdDict)ty.GetConstructor(Type.EmptyTypes).Invoke(new object[0]);
                    //@todo share logic to copy old values in when not already there from reload
                    module.__dict__ = dict;
                    module.Initialize();
                    return(module);
                }
                else
                {
                    ReflectedType type = (ReflectedType)Ops.GetDynamicTypeFromType(ty);
                    type.Initialize();
                    foreach (string attrName in type.GetAttrNames(module))
                    {
                        SymbolId id = SymbolTable.StringToId(attrName);
                        module.__dict__[id] = type.GetAttr(module, null, id);
                    }
                    module.Initialize();
                    return(module);
                }
            }
            throw new NotImplementedException();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes the specified module and returns the user-exposable PythonModule.
        /// </summary>
        private static PythonModule InitializeModule(string fullName, PythonModule pmod)
        {
            // if we have a collision (both a package & namespace)
            // then we could have already exposed the ReflectedPackage
            // out to the user.  Therefore the outer module will alway
            // be the reflected packge module.

            PythonModule rpMod  = pmod.SystemState.TopPackage.TryGetPackage(pmod.SystemState, fullName);
            PythonModule newmod = pmod;

            if (rpMod != null)
            {
                pmod.InnerModule  = rpMod.InnerModule;
                rpMod.InnerModule = pmod;

                pmod.PackageImported = true;

                pmod = rpMod;
            }

            //Put this in modules dict so we won't reload with circular imports
            pmod.SystemState.modules[fullName] = pmod;
            try {
                newmod.InitializeBuiltins();
                newmod.Initialize();
            } catch {
                pmod.SystemState.modules.Remove(fullName);
                throw;
            }


            return(pmod);
        }
Ejemplo n.º 3
0
        internal static PythonModule ReloadBuiltin(PythonModule module)
        {
            Type ty;

            if (module.SystemState.TopPackage.Builtins.TryGetValue(module.ModuleName, out ty)) {
                if (typeof(CustomSymbolDict).IsAssignableFrom(ty)) {
                    CustomSymbolDict dict = (CustomSymbolDict)ty.GetConstructor(Type.EmptyTypes).Invoke(Ops.EMPTY);
                    //@todo share logic to copy old values in when not already there from reload
                    module.__dict__ = dict;
                    module.Initialize();
                    return module;
                } else {
                    ReflectedType type = (ReflectedType)Ops.GetDynamicTypeFromType(ty);
                    type.Initialize();
                    foreach (string attrName in type.GetAttrNames(module)) {
                        SymbolId id = SymbolTable.StringToId(attrName);

                        module.__dict__[id] = type.GetAttr(module, null, id);
                    }
                    module.Initialize();
                    return module;
                }
            }
            throw new NotImplementedException();
        }