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
        private static PythonModule MakePythonModule(PythonModule importer, string name, ReflectedType type)
        {
            type.Initialize();
            FieldIdDict dict = new FieldIdDict();

            //!!! need a GetAttrIds
            foreach (string attrName in type.GetAttrNames(DefaultContext.Default))
            {
                dict[SymbolTable.StringToId(attrName)] = type.GetAttr(DefaultContext.Default, null, SymbolTable.StringToId(attrName));
            }
            PythonModule ret = new PythonModule(name, dict, importer.SystemState);

            importer.SystemState.modules[name] = ret;
            return(ret);
        }