Ejemplo n.º 1
0
        public List GetAttrNames(ICallerContext context)
        {
            List list;

            if (dict == null)
            {
                list = List.Make();
            }
            else
            {
                list = List.Make(dict);
            }
            list.AddNoLock(SymbolTable.Module.ToString());

            List reflectedAttrs = GetDynamicType().GetAttrNames(context, this);

            foreach (object o in reflectedAttrs)
            {
                if (list.Contains(o))
                {
                    continue;
                }
                list.AddNoLock(o);
            }
            return(list);
        }
Ejemplo n.º 2
0
        public List GetAttrNames(ICallerContext context)
        {
            FieldIdDict attrs = new FieldIdDict(__dict__);

            OldClass.RecurseAttrHierarchy(this.__class__, attrs);
            return(List.Make(attrs));
        }
Ejemplo n.º 3
0
        internal List GetAttrNames(ICallerContext context)
        {
            Initialize(context);

            List list = List.Make();

            if (HaveInterfaces)
            {
                foreach (DynamicType type in interfaces)
                {
                    List names = type.GetAttrNames(context, obj);
                    foreach (object o in names)
                    {
                        if (!list.Contains(o))
                        {
                            list.AddNoLock(o);
                        }
                    }
                }
            }
            else
            {
                //return GetDynamicType().GetAttrNames(context, this);
            }
            return(list);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Performs sys's initialization
        /// It is in it's own function so we can do reload(sys). On reload(sys), most of the attributes need to be
        /// reset. The following are left as they are - argv, exc_type, modules, path, path_hooks, path_importer_cache, ps1, ps2.
        /// </summary>
        public void Initialize()
        {
            if (__dict__ == null)
            {
                __dict__ = new FieldIdDict();

                // These fields do not get reset on "reload(sys)"
                argv      = Ops.MakeList();
                modules   = new Dict();
                path      = List.Make();
                ps1       = Ops.ToPython(">>> ");
                ps2       = Ops.ToPython("... ");
                __stdin__ = new PythonFile(Console.OpenStandardInput(),
                                           Console.InputEncoding,
                                           "<stdin>",
                                           "r");
                __stdout__ = new PythonFile(Options.UnbufferedStdOutAndError ? Console.OpenStandardOutput(0) : Console.OpenStandardOutput(),
                                            Console.OutputEncoding,
                                            "<stdout>",
                                            "w");
                __stderr__ = new PythonFile(Options.UnbufferedStdOutAndError ? Console.OpenStandardError(0) : Console.OpenStandardError(),
                                            Console.OutputEncoding,
                                            "<stderr>",
                                            "w");
            }

            __dict__[SymbolTable.Name] = "sys";

            stdin  = __stdin__;
            stdout = __stdout__;
            stderr = __stderr__;

            // removed from dictionary after the first call to set it.
            MethodInfo mi = typeof(SystemState).GetMethod("setdefaultencodingImpl",
                                                          System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

            BuiltinMethodDescriptor descr = (BuiltinMethodDescriptor) new ReflectedMethod("setdefaultencoding", mi, FunctionType.PythonVisible | FunctionType.Method).GetDescriptor();

            __dict__[SymbolTable.SetDefaultEncoding] = descr.GetAttribute(this, this);

            DefaultEncoding = Encoding.ASCII;
            byteorder       = BitConverter.IsLittleEndian ? "little" : "big";
            copyright       = "Copyright (c) Microsoft Corporation. All rights reserved.";
            hexversion      = 0x02040000;
            maxint          = Int32.MaxValue;
            maxunicode      = (int)ushort.MaxValue;
            platform        = Ops.ToPython("cli");
            version_info    = Tuple.MakeTuple(2, 4);
            // !!! These fields do need to be reset on "reload(sys)". However, the initial value is specified by the
            // engine elsewhere. For now, we initialize them just once to some default value
            if (version == null)
            {
                version     = IronPython.Hosting.PythonEngine.VersionString;
                warnoptions = List.Make();
                executable  = "";
            }
        }
Ejemplo n.º 5
0
        public virtual List GetAttrNames(ICallerContext context)
        {
            Initialize();

            Dictionary <object, object> names = new Dictionary <object, object>();

            if ((context.ContextFlags & CallerContextFlags.ShowCls) == 0)
            {
                foreach (KeyValuePair <object, object> kvp in dict)
                {
                    IContextAwareMember icaa = kvp.Value as IContextAwareMember;
                    if (icaa == null || icaa.IsVisible(context))
                    {
                        string strKey = kvp.Key as string;
                        if (strKey == null)
                        {
                            continue;
                        }

                        names[strKey] = strKey;
                    }
                }
            }
            else
            {
                foreach (object key in dict.Keys)
                {
                    names[key] = null;
                }
            }

            foreach (DynamicType dt in BaseClasses)
            {
                if (dt != TypeCache.Object)
                {
                    foreach (string name in Ops.GetAttrNames(context, dt))
                    {
                        if (name[0] == '_' && name[1] != '_')
                        {
                            continue;
                        }

                        names[name] = name;
                    }
                }
            }

            names["__class__"] = "__class__";
            return(List.Make(names.Keys));
        }
Ejemplo n.º 6
0
        public static List Keys(IDictionary <object, object> self)
        {
            List l = List.Make(self.Keys);

            for (int i = 0; i < l.Count; i++)
            {
                if (l[i] == nullObject)
                {
                    l[i] = DictOps.ObjToNull(l[i]);
                    break;
                }
            }
            return(l);
        }
Ejemplo n.º 7
0
        public List GetAttrNames(ICallerContext context)
        {
            List ret = TypeCache.Method.GetAttrNames(context, this);

            ret = List.Make(ret);
            if (!ret.Contains(SymbolTable.Module.ToString()))
            {
                ret.AddNoLock(SymbolTable.Module.ToString());
            }

            // Check the func
            foreach (KeyValuePair <object, object> kvp in ((PythonFunction)func).dict)
            {
                if (!ret.Contains(kvp.Key))
                {
                    ret.AddNoLock(kvp.Key);
                }
            }

            return(ret);
        }
Ejemplo n.º 8
0
        public List GetAttrNames(ICallerContext context)
        {
            List ret;

            if ((context.ContextFlags & CallerContextFlags.ShowCls) == 0)
            {
                ret = new List();
                foreach (KeyValuePair <object, object> kvp in __dict__)
                {
                    IContextAwareMember icaa = kvp.Value as IContextAwareMember;
                    if (icaa == null || icaa.IsVisible(context))
                    {
                        ret.AddNoLock(kvp.Key);
                    }
                }
            }
            else
            {
                ret = List.Make(__dict__.Keys);
            }

            ret.AddNoLock("__dict__");
            if (packageImported)
            {
                foreach (object o in innerMod.GetAttrNames(context))
                {
                    if (o is string && (string)o == "__dict__")
                    {
                        continue;
                    }
                    if (!((IDictionary <object, object>)__dict__).ContainsKey(o))
                    {
                        ret.AddNoLock(o);
                    }
                }
            }
            return(ret);
        }
Ejemplo n.º 9
0
 public static List Values(IDictionary <object, object> self)
 {
     return(List.Make(self.Values));
 }