本文整理汇总了C#中PythonDictionary类的典型用法代码示例。如果您正苦于以下问题:C# PythonDictionary类的具体用法?C# PythonDictionary怎么用?C# PythonDictionary使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
PythonDictionary类属于命名空间,在下文中一共展示了PythonDictionary类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: IronPythonUpdateProcessor
/// <summary>APIの設定を用いてインスタンスを初期化します。 </summary>
/// <param name="api">IronPython用APIの何らかの実装</param>
/// <param name="setting">更新処理の設定</param>
/// <param name="dictionary">キャラに対応するグローバル変数用にディクショナリ</param>
public IronPythonUpdateProcessor(IScriptApi api, IScriptUpdateSetting setting, PythonDictionary dictionary)
{
_setting = setting;
var engine = Python.CreateEngine();
//名前参照にexeのディレクトリとキャラのディレクトリを追加
var paths = engine.GetSearchPaths();
paths.Add(Environment.CurrentDirectory);
paths.Add(DirectoryNames.GetCharacterScriptDirectory(api.CharacterName));
engine.SetSearchPaths(paths);
//可視領域を限界まで広く取るためビルトインスコープにぶち込んでおく
ScriptScope builtin = engine.GetBuiltinModule();
builtin.SetVariable(IronPythonCommonVariableNames.ApiVariableName, api);
builtin.SetVariable(IronPythonCommonVariableNames.ApiGlobalDictionaryName, dictionary);
string path = Path.Combine(DirectoryNames.GetCharacterScriptDirectory(api.CharacterName), UpdateScriptName);
//高スピードで読むので先にコンパイル
try
{
_updateCode = engine.CreateScriptSourceFromFile(path).Compile();
IsValid = true;
}
catch (Exception)
{
IsValid = false;
}
}
示例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: Py_InitModule4
Py_InitModule4(string name, IntPtr methodsPtr, string doc, IntPtr selfPtr, int apiver)
{
name = this.FixImportName(name);
PythonDictionary methodTable = new PythonDictionary();
PythonModule module = new PythonModule();
this.AddModule(name, module);
this.CreateModulesContaining(name);
PythonDictionary __dict__ = module.Get__dict__();
__dict__["__doc__"] = doc;
__dict__["__name__"] = name;
string __file__ = this.importFiles.Peek();
__dict__["__file__"] = __file__;
List __path__ = new List();
if (__file__ != null)
{
__path__.append(Path.GetDirectoryName(__file__));
}
__dict__["__path__"] = __path__;
__dict__["_dispatcher"] = new Dispatcher(this, methodTable, selfPtr);
StringBuilder moduleCode = new StringBuilder();
moduleCode.Append(CodeSnippets.USEFUL_IMPORTS);
CallableBuilder.GenerateFunctions(moduleCode, methodsPtr, methodTable);
this.ExecInModule(moduleCode.ToString(), module);
return this.Store(module);
}
示例5: Argument
public Argument(PythonBoss pyBoss, long address, PythonDictionary spec, Process process, int depth, Arguments parent, string namePrefix)
{
Address = address;
this.process = process;
_pyBoss = pyBoss;
_parent = parent;
NamePrefix = namePrefix;
// Parse the spec for this argument
// stackspec: [{"name": "socket",
// "size": 4,
// "type": None,
// "fuzz": NOFUZZ,
// "type_args": None},]
Fuzz = (bool)spec.get("fuzz");
Name = (string)spec.get("name");
_argumentType = (object)spec.get("type");
if ( spec.ContainsKey("type_args") )
{
_typeArgs = spec.get("type_args");
}
// Validate required fields
if (Name == null)
throw new Exception("ERROR: Argument specification must include 'name' attribute. Failed when parsing name prefix '" + namePrefix + "'.");
else if (Fuzz == null)
throw new Exception("ERROR: Argument specification must include 'fuzz' attribute. Failed when parsing type '" + namePrefix + Name + "'.");
else if (spec.get("size") == null)
throw new Exception("ERROR: Argument specification must include 'size' attribute. Failed when parsing type '" + namePrefix + Name + "'.");
if (spec.get("size") is string)
{
object sizeArgument = null;
if (parent.TryGetMemberSearchUp((string)spec.get("size"), out sizeArgument))
Size = ((Argument)sizeArgument).ToInt();
else
throw new Exception("ERROR: Unable to load size for type '" + Name + "' from parent member named '" + (string)spec.get("size") + "'. Please make sure this field exists in the parent.");
}
else if (spec.get("size") is int)
{
Size = (int)spec.get("size");
}
else
{
throw new Exception("ERROR: Unable to load size for type '" + Name + "'. The size must be of type 'int' or type 'string'. Size is type: '" + spec.get("size").ToString() + "'" );
}
// Read the data
try
{
Data = MemoryFunctions.ReadMemory(process.ProcessDotNet, address, (uint)Size);
}
catch (Exception e)
{
Data = null;
}
PointerTarget = null;
}
示例6: PythonModule
public PythonModule() {
_dict = new PythonDictionary();
if (GetType() != typeof(PythonModule) && this is IPythonObject) {
// we should share the user dict w/ our dict.
((IPythonObject)this).ReplaceDict(_dict);
}
}
示例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)) {
SetFields(fields);
}
// TODO: _anonymous_
}
示例8: Initialize
/// <summary>フィールド初期化を行います。</summary>
private void Initialize()
{
var chatWindowPosition = new ChatWindowPositionModel(
_mainWindow,
_setting.ChatWindowLayout,
_relocator
);
_chatWindow = new ChatWindowModel(chatWindowPosition);
var voiceOperator = new VoiceOperator(_setting.Voice);
voiceOperator.LipSynchRequested += (_, e) => _lipSyncher = e.LipSyncher;
var scriptRequestor = new SimpleScriptRequestor();
var api = new ScriptApi(
_mainWindow, _character, voiceOperator, _chatWindow, scriptRequestor,
_setting,
_setting.ScriptApi,
_characterName
);
var dict = new PythonDictionary();
_updateProcessor = new IronPythonUpdateProcessor(api, _setting.ScriptUpdate, dict);
var ironPythonReader = new IronPythonMainScriptReader(api, dict);
_scriptStateManager = new ScriptStateManager(ironPythonReader, _setting.ScriptRoutine, _characterName);
scriptRequestor.ScriptRequested += (_, e) => _scriptStateManager.Request(
e.ScriptName,
e.Priority
);
}
示例9: 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();
}
示例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);
}
}
示例11: MapRoute
public static void MapRoute(string name, string url, PythonDictionary defaults) {
var defaultValues = new RouteValueDictionary();
foreach (var kvp in defaults) {
defaultValues.Add(Convert.ToString(kvp.Key, CultureInfo.InvariantCulture), kvp.Value);
}
RouteTable.Routes.Add(name, new Route(url, defaultValues, new MvcRouteHandler())) ;
}
示例12: 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"];
}
}
示例13: 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");
}
示例14: create_node
public Tree create_node(int left, int top, int width, int height, PythonDictionary tags)
{
BoundingBox bb = new BoundingBox(left, top, width, height);
Dictionary<string, object> cTags = new Dictionary<string,object>();
foreach(string key in tags.Keys)
cTags[key] = tags[key];
return Tree.FromBoundingBox(bb, cTags);
}
示例15: GenerateFunctions
GenerateFunctions(StringBuilder code, IntPtr methods, PythonDictionary methodTable)
{
GenerateCallablesFromMethodDefs(
code, methods, methodTable, "",
CodeSnippets.OLDARGS_FUNCTION_TEMPLATE,
CodeSnippets.NOARGS_FUNCTION_TEMPLATE,
CodeSnippets.OBJARG_FUNCTION_TEMPLATE,
CodeSnippets.VARARGS_FUNCTION_TEMPLATE,
CodeSnippets.VARARGS_KWARGS_FUNCTION_TEMPLATE);
}