Пример #1
0
 public static object __new__(CodeContext context, PythonType type, [NotNull] IReversible o)
 {
     return(o.__reversed__());
 }
Пример #2
0
 public void __init__(PythonType type)
 {
     __init__(type, null);
 }
Пример #3
0
 public static PythonModule /*!*/ __new__(CodeContext /*!*/ context, PythonType /*!*/ cls, [ParamDictionary] IDictionary <object, object> kwDict0, params object[] /*!*/ args\u00F8)
 {
     return(__new__(context, cls, args\u00F8));
 }
Пример #4
0
 public void DeleteCustomMember(CodeContext context, string name)
 {
     PythonType.DeleteMember(context, this, name);
 }
Пример #5
0
 internal override bool TryGetValue(CodeContext context, object instance, PythonType owner, out object value)
 {
     value = __get__(context, instance, owner);
     return(true);
 }
Пример #6
0
 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);
 }
Пример #7
0
 public void SetMember(CodeContext context, string name, object value)
 {
     PythonType.SetMember(context, this, name, value);
 }
Пример #8
0
        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);
        }
Пример #9
0
 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);
 }
Пример #10
0
        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());
        }
Пример #12
0
 public static object __new__(CodeContext context, [NotNull] PythonType cls, [NotNull] string @string)
 {
     throw PythonOps.TypeError("string argument without an encoding");
 }
Пример #13
0
 public static object fromkeys(CodeContext context, PythonType cls, object seq)
 {
     return(fromkeys(context, cls, seq, null));
 }
Пример #14
0
        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);
        }