public static object __new__(CodeContext context, PythonType type, [NotNull] IReversible o) { return(o.__reversed__()); }
public void __init__(PythonType type) { __init__(type, null); }
public static PythonModule /*!*/ __new__(CodeContext /*!*/ context, PythonType /*!*/ cls, [ParamDictionary] IDictionary <object, object> kwDict0, params object[] /*!*/ args\u00F8) { return(__new__(context, cls, args\u00F8)); }
public void DeleteCustomMember(CodeContext context, string name) { PythonType.DeleteMember(context, this, name); }
internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) { value = __get__(context, instance, owner); return(true); }
internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) { value = instance == null ? (object)this : new Method(this, instance, owner); return(true); }
public void SetMember(CodeContext context, string name, object value) { PythonType.SetMember(context, this, name, value); }
internal static ExtensionMethodSet AddExtensions(ExtensionMethodSet extensionMethodSet, object[] extensions) { var res = extensionMethodSet; var newTypes = new HashSet <Type>(); var newAssms = new HashSet <Assembly>(); var newNspaces = new HashSet <NamespaceTracker>(); foreach (object o in extensions) { PythonType type = o as PythonType; if (type != null) { if (res._types != null && res._types.Contains(type)) { continue; } newTypes.Add(type.UnderlyingSystemType); } Assembly asm = o as Assembly; if (asm != null) { if (res._assemblies != null && res._assemblies.Contains(asm)) { continue; } foreach (var method in ReflectionUtils.GetVisibleExtensionMethods(asm)) { if (newTypes.Contains(method.DeclaringType) || (res._types != null && res._types.Contains(method.DeclaringType))) { continue; } newTypes.Add(method.DeclaringType); } } NamespaceTracker ns = o as NamespaceTracker; if (ns != null) { if (res._namespaces != null && res._namespaces.Contains(ns)) { continue; } foreach (var packageAsm in ns.PackageAssemblies) { foreach (var method in ReflectionUtils.GetVisibleExtensionMethods(packageAsm)) { if (newTypes.Contains(method.DeclaringType) || (res._types != null && res._types.Contains(method.DeclaringType))) { continue; } newTypes.Add(method.DeclaringType); } } } } if (newTypes.Count > 0) { if (res._types != null) { newTypes.UnionWith(res._types); } if (res._namespaces != null) { newNspaces.UnionWith(res._namespaces); } if (res._assemblies != null) { newAssms.UnionWith(res._assemblies); } return(new ExtensionMethodSet(newTypes, newNspaces, newAssms)); } return(res); }
internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value) { owner = CheckGetArgs(context, instance, owner); value = new Method(_func, owner, DynamicHelpers.GetPythonType(owner)); return(true); }
public static ExtensionMethodSet AddType(PythonContext context, ExtensionMethodSet /*!*/ existingSet, PythonType /*!*/ type) { Assert.NotNull(existingSet, type); lock (existingSet) { AssemblyLoadInfo assemblyLoadInfo; if (existingSet._loadedAssemblies.TryGetValue(type.UnderlyingSystemType.Assembly, out assemblyLoadInfo)) { if (assemblyLoadInfo.IsFullAssemblyLoaded || (assemblyLoadInfo.Types != null && assemblyLoadInfo.Types.Contains(type)) || (assemblyLoadInfo.Namespaces != null && assemblyLoadInfo.Namespaces.Contains(type.UnderlyingSystemType.Namespace))) { // type is already in this set. return(existingSet); } } var dict = NewInfoOrCopy(existingSet); if (!dict.TryGetValue(type.UnderlyingSystemType.Assembly, out assemblyLoadInfo)) { dict[type.UnderlyingSystemType.Assembly] = assemblyLoadInfo = new AssemblyLoadInfo(type.UnderlyingSystemType.Assembly); } if (assemblyLoadInfo.Types == null) { assemblyLoadInfo.Types = new HashSet <PythonType>(); } assemblyLoadInfo.Types.Add(type); return(context.UniqifyExtensions(new ExtensionMethodSet(dict))); } }
public override ICollection <MemberDoc> GetMembers(object value) { List <MemberDoc> res = new List <MemberDoc>(); PythonModule mod = value as PythonModule; if (mod != null) { foreach (var kvp in mod.__dict__) { AddMember(res, kvp, false); } return(res); } NamespaceTracker ns = value as NamespaceTracker; if (ns != null) { foreach (var v in ns) { AddMember( res, new KeyValuePair <object, object>( v.Key, Importer.MemberTrackerToPython(_context.SharedClsContext, v.Value) ), false ); } } else { PythonType pt = value as PythonType; if (pt != null) { foreach (PythonType type in pt.ResolutionOrder) { foreach (var member in type.GetMemberDictionary(_context.SharedContext)) { AddMember(res, member, true); } } } else { pt = DynamicHelpers.GetPythonType(value); foreach (var member in pt.GetMemberDictionary(_context.SharedContext)) { AddMember(res, member, true); } } IPythonObject ipo = value as IPythonObject; if (ipo != null && ipo.Dict != null) { foreach (var member in ipo.Dict) { AddMember(res, member, false); } } } return(res.ToArray()); }
public static object __new__(CodeContext context, [NotNull] PythonType cls, [NotNull] string @string) { throw PythonOps.TypeError("string argument without an encoding"); }
public static object fromkeys(CodeContext context, PythonType cls, object seq) { return(fromkeys(context, cls, seq, null)); }
private static object fromkeysAny(CodeContext /*!*/ context, PythonType cls, object o, object value) { PythonDictionary pyDict; object dict; if (cls == TypeCache.Dict) { string str; ICollection ic = o as ICollection; // creating our own dict, try and get the ideal size and add w/o locks if (ic != null) { pyDict = new PythonDictionary(new CommonDictionaryStorage(ic.Count)); } else if ((str = o as string) != null) { pyDict = new PythonDictionary(str.Length); } else { pyDict = new PythonDictionary(); } IEnumerator i = PythonOps.GetEnumerator(o); while (i.MoveNext()) { pyDict._storage.AddNoLock(i.Current, value); } return(pyDict); } else { // call the user type constructor dict = MakeDict(context, cls); pyDict = dict as PythonDictionary; } if (pyDict != null) { // then store all the keys with their associated value IEnumerator i = PythonOps.GetEnumerator(o); while (i.MoveNext()) { pyDict[i.Current] = value; } } else { // slow path, cls.__new__ returned a user defined dictionary instead of a PythonDictionary. PythonContext pc = PythonContext.GetContext(context); IEnumerator i = PythonOps.GetEnumerator(o); while (i.MoveNext()) { pc.SetIndex(dict, i.Current, value); } } return(dict); }