private PythonType CheckGetArgs(CodeContext context, object instance, PythonType owner) { if (owner == null) { if (instance == null) { throw PythonOps.TypeError("__get__(None, None) is invalid"); } owner = DynamicHelpers.GetPythonType(instance); } else { if (!owner.IsSubclassOf(DynamicHelpers.GetPythonTypeFromType(_func.DeclaringType))) { throw PythonOps.TypeError("descriptor {0} for type {1} doesn't apply to type {2}", PythonOps.Repr(context, _func.Name), PythonOps.Repr(context, DynamicHelpers.GetPythonTypeFromType(_func.DeclaringType).Name), PythonOps.Repr(context, owner.Name)); } } if (instance != null) { BuiltinMethodDescriptor.CheckSelfWorker(context, instance, _func); } return(owner); }
/// <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 = ""; } }
public override bool Equals(object obj) { BuiltinMethodDescriptor bmf = obj as BuiltinMethodDescriptor; if (bmf == null) { return(false); } return(template.Equals(bmf.template)); }
private static BuiltinFunction GetNextFunctionTemplate() { BuiltinMethodDescriptor bimd = (BuiltinMethodDescriptor)TypeCache.Generator.GetAttr( DefaultContext.Default, null, SymbolTable.GeneratorNext); BuiltinFunction unOpt = bimd.template; BuiltinFunction res = Compiler.ReflectOptimizer.MakeFunction(unOpt); if (res == null) { return(unOpt); // optimization is disabled... } return(res); }
public override ICollection <OverloadDoc> GetOverloads(object value) { BuiltinFunction bf = value as BuiltinFunction; if (bf != null) { return(GetBuiltinFunctionOverloads(bf)); } BuiltinMethodDescriptor bmd = value as BuiltinMethodDescriptor; if (bmd != null) { return(GetBuiltinFunctionOverloads(bmd.Template)); } PythonFunction pf = value as PythonFunction; if (pf != null) { return(new[] { new OverloadDoc( pf.__name__, pf.__doc__ as string, GetParameterDocs(pf) ) }); } Method method = value as Method; if (method != null) { return(GetOverloads(method.__func__)); } Delegate dlg = value as Delegate; if (dlg != null) { return(new[] { DocBuilder.GetOverloadDoc(dlg.GetType().GetMethod("Invoke"), dlg.GetType().Name, 0, false) }); } return(new OverloadDoc[0]); }