本文整理汇总了C#中IronPython.Runtime.PythonContext类的典型用法代码示例。如果您正苦于以下问题:C# PythonContext类的具体用法?C# PythonContext怎么用?C# PythonContext使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PythonContext类属于IronPython.Runtime命名空间,在下文中一共展示了PythonContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: _FileIO
public _FileIO(CodeContext/*!*/ context, int fd, [DefaultParameterValue("r")]string mode, [DefaultParameterValue(true)]bool closefd) {
if (fd < 0) {
throw PythonOps.ValueError("fd must be >= 0");
}
PythonContext pc = PythonContext.GetContext(context);
_FileIO file = (_FileIO)pc.FileManager.GetObjectFromId(pc, fd);
Console.WriteLine(file);
_context = pc;
switch (mode) {
case "r": _mode = "rb"; break;
case "w": _mode = "wb"; break;
case "a": _mode = "w"; break;
case "r+":
case "+r": _mode = "rb+"; break;
case "w+":
case "+w": _mode = "rb+"; break;
case "a+":
case "+a": _mode = "r+"; break;
default:
BadMode(mode);
break;
}
_readStream = file._readStream;
_writeStream = file._writeStream;
_closefd = closefd;
}
示例2: CodeContext
public CodeContext(Scope scope, PythonContext languageContext, CodeContext parent) {
Assert.NotNull(languageContext);
_languageContext = languageContext;
_scope = scope;
_parent = parent;
}
示例3: PerformModuleReload
public static void PerformModuleReload(PythonContext/*!*/ context, PythonDictionary/*!*/ dict) {
var socket = context.GetBuiltinModule("socket");
var socketError = PythonSocket.GetSocketError(context, socket.__dict__);
context.EnsureModuleException("SSLError", socketError, dict, "SSLError", "ssl");
}
示例4: PerformModuleReload
public static void PerformModuleReload(PythonContext context, PythonDictionary dict) {
if (!context.HasModuleState(_zip_directory_cache_key))
context.SetModuleState(_zip_directory_cache_key, new PythonDictionary());
dict["_zip_directory_cache"] = context.GetModuleState(_zip_directory_cache_key);
InitModuleExceptions(context, dict);
}
示例5: PerformModuleReload
public static void PerformModuleReload(PythonContext/*!*/ context, IDictionary/*!*/ dict) {
if (ucd_5_2_0 == null) {
// This is a lie. The version of Unicode depends on the .NET version as well as the OS. The
// version of the database stored internally is 5.2, so just say that.
Interlocked.CompareExchange(ref ucd_5_2_0, new UCD("5.2.0"), null);
}
}
示例6: PerformModuleReload
public static void PerformModuleReload(PythonContext context, IAttributesCollection dict) {
Scope scope = Importer.ImportModule(context.SharedContext, context.SharedContext.GlobalScope.Dict, "itertools", false, -1) as Scope;
if (scope != null) {
dict[SymbolTable.StringToId("map")] = scope.LookupName(context, SymbolTable.StringToId("imap"));
dict[SymbolTable.StringToId("filter")] = scope.LookupName(context, SymbolTable.StringToId("ifilter"));
dict[SymbolTable.StringToId("zip")] = scope.LookupName(context, SymbolTable.StringToId("izip"));
}
}
示例7: 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);
}
示例8: PerformModuleReload
public static void PerformModuleReload(PythonContext context, IAttributesCollection dict) {
PythonModule scope = Importer.ImportModule(context.SharedContext, context.SharedContext.GlobalDict, "itertools", false, -1) as PythonModule;
if (scope != null) {
dict[SymbolTable.StringToId("map")] = scope.__dict__["imap"];
dict[SymbolTable.StringToId("filter")] = scope.__dict__["ifilter"];
dict[SymbolTable.StringToId("zip")] = scope.__dict__["izip"];
}
}
示例9: MakeSignalState
private static PythonSignalState MakeSignalState(PythonContext context) {
if (Environment.OSVersion.Platform == PlatformID.Unix
|| Environment.OSVersion.Platform == PlatformID.MacOSX) {
return MakePosixSignalState(context);
} else {
return MakeNtSignalState(context);
}
}
示例10: PerformModuleReload
public static void PerformModuleReload(PythonContext context, PythonDictionary dict) {
PythonModule scope = Importer.ImportModule(context.SharedContext, context.SharedContext.GlobalDict, "itertools", false, -1) as PythonModule;
if (scope != null) {
dict["map"] = scope.__dict__["imap"];
dict["filter"] = scope.__dict__["ifilter"];
dict["zip"] = scope.__dict__["izip"];
}
}
示例11: ModuleContext
/// <summary>
/// Creates a new ModuleContext for the specified module.
/// </summary>
public ModuleContext(PythonModule/*!*/ module, PythonContext/*!*/ creatingContext) {
ContractUtils.RequiresNotNull(module, "module");
ContractUtils.RequiresNotNull(creatingContext, "creatingContext");
_globals = module.__dict__;
_pyContext = creatingContext;
_globalContext = new CodeContext(_globals, this);
_module = module;
}
示例12: StaticGlobalAllocator
public StaticGlobalAllocator(PythonContext/*!*/ context, string name) {
_typeGen = Snippets.Shared.DefineType(name, typeof(object), false, false);
_codeContextField = _typeGen.AddStaticField(typeof(CodeContext), "__global_context");
_codeContext = CreateFieldBuilderExpression(_codeContextField);
_scope = new Scope(new PythonDictionary(new GlobalDictionaryStorage(_globalVals)));
_context = new CodeContext(_scope, context);
}
示例13: PerformModuleReload
public static void PerformModuleReload(PythonContext/*!*/ context, IAttributesCollection/*!*/ dict) {
context.EnsureModuleException("PickleError", dict, "PickleError", "cPickle");
context.EnsureModuleException("PicklingError", dict, "PicklingError", "cPickle");
context.EnsureModuleException("UnpicklingError", dict, "UnpicklingError", "cPickle");
context.EnsureModuleException("UnpickleableError", dict, "UnpickleableError", "cPickle");
context.EnsureModuleException("BadPickleGet", dict, "BadPickleGet", "cPickle");
dict[Symbols.Builtins] = context.BuiltinModuleInstance;
dict[SymbolTable.StringToId("compatible_formats")] = PythonOps.MakeList("1.0", "1.1", "1.2", "1.3", "2.0");
}
示例14: PerformModuleReload
public static void PerformModuleReload(PythonContext/*!*/ context, PythonDictionary/*!*/ dict) {
context.EnsureModuleException("PickleError", dict, "PickleError", "cPickle");
context.EnsureModuleException("PicklingError", dict, "PicklingError", "cPickle");
context.EnsureModuleException("UnpicklingError", dict, "UnpicklingError", "cPickle");
context.EnsureModuleException("UnpickleableError", dict, "UnpickleableError", "cPickle");
context.EnsureModuleException("BadPickleGet", dict, "BadPickleGet", "cPickle");
dict["__builtins__"] = context.BuiltinModuleInstance;
dict["compatible_formats"] = PythonOps.MakeList("1.0", "1.1", "1.2", "1.3", "2.0");
}
示例15: InitModuleExceptions
private static void InitModuleExceptions(PythonContext context,
PythonDictionary dict)
{
ZipImportError = context.EnsureModuleException(
"zipimport.ZipImportError",
PythonExceptions.ImportError,
typeof(PythonExceptions.BaseException),
dict, "ZipImportError", "zipimport",
msg => new ImportException(msg));
}