当前位置: 首页>>代码示例>>C#>>正文


C# PythonTuple类代码示例

本文整理汇总了C#中PythonTuple的典型用法代码示例。如果您正苦于以下问题:C# PythonTuple类的具体用法?C# PythonTuple怎么用?C# PythonTuple使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


PythonTuple类属于命名空间,在下文中一共展示了PythonTuple类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: _CFuncPtr

            // __nonzero__ 

            /// <summary>
            /// Creates a new CFuncPtr object from a tuple.  The 1st element of the
            /// tuple is the ordinal or function name.  The second is an object with
            /// a _handle property.  The _handle property is the handle of the module
            /// from which the function will be loaded.
            /// </summary>
            public _CFuncPtr(PythonTuple args) {
                if (args == null) {
                    throw PythonOps.TypeError("expected sequence, got None");
                } else if (args.Count != 2) {
                    throw PythonOps.TypeError("argument 1 must be a sequence of length 2, not {0}", args.Count);
                }

                object nameOrOrdinal = args[0];
                object dll = args[1];
                IntPtr intPtrHandle = GetHandleFromObject(dll, "the _handle attribute of the second element must be an integer");

                string funcName = args[0] as string;
                if (funcName != null) {
                    _addr = NativeFunctions.GetProcAddress(intPtrHandle, funcName);
                } else {
                    _addr = NativeFunctions.GetProcAddress(intPtrHandle, new IntPtr((int)nameOrOrdinal));
                }

                if (_addr == IntPtr.Zero) {
                    if (CallingConvention == CallingConvention.StdCall && funcName != null) {
                        // apply std call name mangling - prepend a _, append @bytes where 
                        // bytes is the number of bytes of the argument list.
                        string mangled = "_" + funcName + "@";
                        for (int i = 0; i < 128 && _addr == IntPtr.Zero; i += 4) {
                            _addr = NativeFunctions.GetProcAddress(intPtrHandle, mangled + i);
                        }
                    }

                    if (_addr == IntPtr.Zero) {
                        throw PythonOps.AttributeError("function {0} is not defined", args[0]);
                    }
                }

                _id = Interlocked.Increment(ref _curId);
            }
开发者ID:techarch,项目名称:ironruby,代码行数:43,代码来源:CFuncPtr.cs

示例2: PythonTime

        static PythonTime() {

            // altzone, timezone are offsets from UTC in seconds, so they always fit in the
            // -13*3600 to 13*3600 range and are safe to cast to ints
#if FEATURE_TIMEZONE
            DaylightTime dayTime = TimeZone.CurrentTimeZone.GetDaylightChanges(DateTime.Now.Year);
            daylight = (dayTime.Start == dayTime.End && dayTime.Start == DateTime.MinValue && dayTime.Delta.Ticks == 0) ? 0 : 1;

            tzname = PythonTuple.MakeTuple(TimeZone.CurrentTimeZone.StandardName, TimeZone.CurrentTimeZone.DaylightName);
            altzone = (int)-TimeZone.CurrentTimeZone.GetUtcOffset(DateTime.Now).TotalSeconds;
            timezone = altzone;
            if (daylight != 0) {
                // GetUtcOffset includes adjustments for timezones.  If we're in daylight saving time then
                // we need to adjust timezone so it is the correct time.  Otherwise we need to adjust altzone
                if (TimeZone.CurrentTimeZone.IsDaylightSavingTime(DateTime.Now)) {
                    timezone += (int)dayTime.Delta.TotalSeconds;
                } else {
                    altzone -= (int)dayTime.Delta.TotalSeconds;
                }
            }
#else
            daylight = TimeZoneInfo.Local.SupportsDaylightSavingTime ? 1 : 0;
            tzname = PythonTuple.MakeTuple(TimeZoneInfo.Local.StandardName, TimeZoneInfo.Local.DaylightName);
            timezone = (int)-TimeZoneInfo.Local.BaseUtcOffset.TotalSeconds;
            altzone = (int)-TimeZoneInfo.Local.GetUtcOffset(DateTime.Now).TotalSeconds;
#endif
        }
开发者ID:kashano,项目名称:main,代码行数:27,代码来源:time.cs

示例3: StructType

            public StructType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection members)
                : base(context, name, bases, members) {

                foreach (PythonType pt in ResolutionOrder) {
                    StructType st = pt as StructType;
                    if (st != this && st != null) {
                        st.EnsureFinal();
                    }

                    UnionType ut = pt as UnionType;
                    if (ut != null) {
                        ut.EnsureFinal();
                    }
                }

                object pack;
                if (members.TryGetValue(SymbolTable.StringToId("_pack_"), out pack)) {
                    if (!(pack is int) || ((int)pack < 0)) {
                        throw PythonOps.ValueError("pack must be a non-negative integer");
                    }
                    _pack = (int)pack;
                }

                object fields;
                if (members.TryGetValue(SymbolTable.StringToId("_fields_"), out fields)) {
                    SetFields(fields);
                }

                // TODO: _anonymous_
            }
开发者ID:joshholmes,项目名称:ironruby,代码行数:30,代码来源:StructType.cs

示例4: Import

        /// <summary>
        /// Gateway into importing ... called from Ops.  Performs the initial import of
        /// a module and returns the module.
        /// </summary>
        public static object Import(CodeContext/*!*/ context, string fullName, PythonTuple from, int level) {
            PythonContext pc = PythonContext.GetContext(context);

            if (level == -1) {
                // no specific level provided, call the 4 param version so legacy code continues to work
                return pc.OldImportSite.Target(
                    pc.OldImportSite,
                    context,
                    FindImportFunction(context),
                    fullName,
                    Builtin.globals(context),
                    context.Dict,
                    from
                );
            }

            // relative import or absolute import, in other words:
            //
            // from . import xyz
            // or 
            // from __future__ import absolute_import

            return pc.ImportSite.Target(
                pc.ImportSite,
                context,
                FindImportFunction(context),
                fullName,
                Builtin.globals(context),
                context.Dict,
                from,
                level
            );
        }
开发者ID:jxnmaomao,项目名称:ironruby,代码行数:37,代码来源:Importer.cs

示例5: load_module

        public static object load_module(CodeContext/*!*/ context, string name, PythonFile file, string filename, PythonTuple/*!*/ description) {
            if (description == null) {
                throw PythonOps.TypeError("load_module() argument 4 must be 3-item sequence, not None");
            }
            if (description.__len__() != 3) {
                throw PythonOps.TypeError("load_module() argument 4 must be sequence of length 3, not {0}", description.__len__());
            }

            PythonContext pythonContext = PythonContext.GetContext(context);

            // already loaded? do reload()
            PythonModule module = pythonContext.GetModuleByName(name);
            if (module != null) {
                Importer.ReloadModule(context, module.Scope);
                return module.Scope;
            }

            int type = PythonContext.GetContext(context).ConvertToInt32(description[2]);
            switch (type) {
                case PythonSource:
                    return LoadPythonSource(pythonContext, name, file, filename);
                case CBuiltin:
                    return LoadBuiltinModule(context, name);
                case PackageDirectory:
                    return LoadPackageDirectory(pythonContext, name, filename);
                default:
                    throw PythonOps.TypeError("don't know how to import {0}, (type code {1}", name, type);
            }
        }
开发者ID:jcteague,项目名称:ironruby,代码行数:29,代码来源:imp.cs

示例6: GetNewType

        public static Type GetNewType(string typeName, PythonTuple bases, IAttributesCollection dict) {
            if (bases == null) bases = PythonTuple.EMPTY;
            // we're really only interested in the "correct" base type pulled out of bases
            // and any slot information contained in dict
            // other info might be used for future optimizations

            NewTypeInfo typeInfo = GetTypeInfo(typeName, bases, GetSlots(dict));

            if (typeInfo.BaseType.IsValueType)
                throw PythonOps.TypeError("cannot derive from {0} because it is a value type", typeInfo.BaseType.FullName);
            if (typeInfo.BaseType.IsSealed)
                throw PythonOps.TypeError("cannot derive from {0} because it is sealed", typeInfo.BaseType.FullName);

            Type ret = _newTypes.GetOrCreateValue(typeInfo,
                delegate() {
                    if (typeInfo.InterfaceTypes.Count == 0 && typeInfo.Slots == null) {
                        // types that the have DynamicBaseType attribute can be used as NewType's directly, no 
                        // need to create a new type unless we're adding interfaces or slots...
                        object[] attrs = typeInfo.BaseType.GetCustomAttributes(typeof(DynamicBaseTypeAttribute), false);
                        if (attrs.Length > 0) {
                            return typeInfo.BaseType;
                        }
                    }

                    // creation code                    
                    return GetTypeMaker(bases, typeInfo).CreateNewType();
                });
            
            OptimizedScriptCode.InitializeFields(ret, true);

            return ret;
        }
开发者ID:octavioh,项目名称:ironruby,代码行数:32,代码来源:NewTypeMaker.cs

示例7: StructType

            private static readonly Field[] _emptyFields = new Field[0]; // fields were never initialized before a type was created

            public StructType(CodeContext/*!*/ context, string name, PythonTuple bases, PythonDictionary members)
                : base(context, name, bases, members) {

                foreach (PythonType pt in ResolutionOrder) {
                    StructType st = pt as StructType;
                    if (st != this && st != null) {
                        st.EnsureFinal();
                    }

                    UnionType ut = pt as UnionType;
                    if (ut != null) {
                        ut.EnsureFinal();
                    }
                }

                object pack;
                if (members.TryGetValue("_pack_", out pack)) {
                    if (!(pack is int) || ((int)pack < 0)) {
                        throw PythonOps.ValueError("pack must be a non-negative integer");
                    }
                    _pack = (int)pack;
                }

                object fields;
                if (members.TryGetValue("_fields_", out fields)) {
                    // When we support alternate endianness this should change to:
                    //__setattr__(context, "_fields_", fields);
                    SetFields(fields);
                }

                // TODO: _anonymous_
            }
开发者ID:TerabyteX,项目名称:ironpython3,代码行数:34,代码来源:StructType.cs

示例8: PythonFunction

        /// <summary>
        /// Python ctor - maps to function.__new__
        /// 
        /// y = func(x.__code__, globals(), 'foo', None, (a, ))
        /// </summary>
        public PythonFunction(CodeContext context, FunctionCode code, PythonDictionary globals, string name, PythonTuple defaults, PythonTuple closure) {
            if (closure != null && closure.__len__() != 0) {
                throw new NotImplementedException("non empty closure argument is not supported");
            }

            if (globals == context.GlobalDict) {
                _module = context.Module.GetName();
                _context = context;
            } else {
                _module = null;
                _context = new CodeContext(new PythonDictionary(), new ModuleContext(globals, DefaultContext.DefaultPythonContext));
            }

            _defaults = defaults == null ? ArrayUtils.EmptyObjects : defaults.ToArray();
            _code = code;
            _name = name;
            _doc = code._initialDoc;
            Closure = null;

            var scopeStatement = _code.PythonCode;
            if (scopeStatement.IsClosure) {
                throw new NotImplementedException("code containing closures is not supported");
            }
            scopeStatement.RewriteBody(FunctionDefinition.ArbitraryGlobalsVisitorInstance);

            _compat = CalculatedCachedCompat();
        }
开发者ID:CookieEaters,项目名称:FireHTTP,代码行数:32,代码来源:PythonFunction.cs

示例9: GetNewType

        public static Type/*!*/ GetNewType(string/*!*/ typeName, PythonTuple/*!*/ bases) {
            Assert.NotNull(typeName, bases);

            NewTypeInfo typeInfo = NewTypeInfo.GetTypeInfo(typeName, bases);

            if (typeInfo.BaseType.IsValueType) {
                throw PythonOps.TypeError("cannot derive from {0} because it is a value type", typeInfo.BaseType.FullName);
            } else if (typeInfo.BaseType.IsSealed) {
                throw PythonOps.TypeError("cannot derive from {0} because it is sealed", typeInfo.BaseType.FullName);
            }

            Type ret = _newTypes.GetOrCreateValue(typeInfo,
                () => {
                    if (typeInfo.InterfaceTypes.Count == 0) {
                        // types that the have DynamicBaseType attribute can be used as NewType's directly, no 
                        // need to create a new type unless we're adding interfaces
                        object[] attrs = typeInfo.BaseType.GetCustomAttributes(typeof(DynamicBaseTypeAttribute), false);
                        if (attrs.Length > 0) {
                            return typeInfo.BaseType;
                        }
                    }

                    // creation code                    
                    return new NewTypeMaker(typeInfo).CreateNewType();
                });
            
            return ret;
        }
开发者ID:Hank923,项目名称:ironruby,代码行数:28,代码来源:NewTypeMaker.cs

示例10: UnionType

            public UnionType(CodeContext/*!*/ context, string name, PythonTuple bases, PythonDictionary members)
                : base(context, name, bases, members) {

                object fields;
                if (members.TryGetValue("_fields_", out fields)) {
                    SetFields(fields);
                }
            }
开发者ID:TerabyteX,项目名称:ironpython3,代码行数:8,代码来源:UnionType.cs

示例11: UnionType

            public UnionType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection members)
                : base(context, name, bases, members) {

                object fields;
                if (members.TryGetValue(SymbolTable.StringToId("_fields_"), out fields)) {
                    SetFields(fields);
                }
            }
开发者ID:xerxesb,项目名称:ironruby,代码行数:8,代码来源:UnionType.cs

示例12: FormatString

        /// <summary>
        /// Runs the formatting operation on the given format and keyword arguments
        /// </summary>
        public static string/*!*/ FormatString(PythonContext/*!*/ context, string/*!*/ format, PythonTuple/*!*/ args, IAttributesCollection/*!*/ kwArgs) {
            ContractUtils.RequiresNotNull(context, "context");
            ContractUtils.RequiresNotNull(format, "format");
            ContractUtils.RequiresNotNull(args, "args");
            ContractUtils.RequiresNotNull(kwArgs, "kwArgs");

            return Formatter.FormatString(context, format, args, kwArgs);
        }
开发者ID:joshholmes,项目名称:ironruby,代码行数:11,代码来源:NewStringFormatter.cs

示例13: PointerType

            public PointerType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection members)
                : base(context, name, bases, members) {

                object type;
                if (members.TryGetValue(SymbolTable.StringToId("_type_"), out type) && !(type is INativeType)) {
                    throw PythonOps.TypeError("_type_ must be a type");
                }
                _type = (INativeType)type;
            }
开发者ID:joshholmes,项目名称:ironruby,代码行数:9,代码来源:PointerType.cs

示例14: validateRouteInfo

        private static void validateRouteInfo(PythonTuple routeInfo)
        {
            if (routeInfo.Count != EXPECTED_TUPLE_LENGTH) {
                throw new RouteMappingException();
            }

            if (routeInfo.Contains(null)) {
                throw new RouteMappingException();
            }
        }
开发者ID:mdrubin,项目名称:codevoyeur-samples,代码行数:10,代码来源:RouteManager.cs

示例15: ArrayType

            public ArrayType(CodeContext/*!*/ context, string name, PythonTuple bases, IAttributesCollection dict)
                : base(context, name, bases, dict) {
                object len;
                int iLen;
                if (!dict.TryGetValue(SymbolTable.StringToId("_length_"), out len) || !(len is int) || (iLen = (int)len) < 0) {
                    throw PythonOps.AttributeError("arrays must have _length_ attribute and it must be a positive integer");
                }

                object type;
                if (!dict.TryGetValue(SymbolTable.StringToId("_type_"), out type)) {
                    throw PythonOps.AttributeError("class must define a '_type_' attribute");
                }

                _length = iLen;
                _type = (INativeType)type;

                if (_type is SimpleType) {
                    SimpleType st = (SimpleType)_type;
                    if (st._type == SimpleTypeKind.Char) {
                        // TODO: (c_int * 2).value isn't working
                        SetCustomMember(context,
                            SymbolTable.StringToId("value"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetCharArrayValue")),
                                NameType.Property | NameType.Python
                            )
                        );

                        SetCustomMember(context,
                            SymbolTable.StringToId("raw"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayRaw")),
                                NameType.Property | NameType.Python
                            )
                        );
                    } else if (st._type == SimpleTypeKind.WChar) {
                        SetCustomMember(context,
                            SymbolTable.StringToId("value"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayValue")),
                                NameType.Property | NameType.Python
                            )
                        );

                        SetCustomMember(context,
                            SymbolTable.StringToId("raw"),
                            new ReflectedExtensionProperty(
                                new ExtensionPropertyInfo(this, typeof(CTypes).GetMethod("GetWCharArrayRaw")),
                                NameType.Property | NameType.Python
                            )
                        );
                    }
                }
            }
开发者ID:techarch,项目名称:ironruby,代码行数:54,代码来源:ArrayType.cs


注:本文中的PythonTuple类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。