public bool Remove(string key) { key = PythonInterop.EscapeArgument(key, EscapeFlags.Quotes); PythonInterop.Eval($"del {Instance.PyName}[{key}]"); Keys.Remove(key); return(!ContainsKey(key)); }
public static void Add(IList <ListItem> items) { var list = PyVariableManager.NewVariable(); string listCode = "["; for (int i = 0; i < items.Count; i++) { listCode += string.Format("({0},{1},{2})", PythonInterop.EscapeArgument(items[i].Url), items[i].Instance.PyName, items[i].IsFolder ); if (i + 1 < items.Count) { listCode += ","; } } listCode += "]"; PyVariable listVar = PyVariableManager.NewVariable(flags: PyVariableFlags.Object); listVar.Value = listCode; PythonInterop.CallFunction( new PythonFunction(PyModule.XbmcPlugin, "addDirectoryItems"), new List <object> { KodiBridge.RunningAddon.Handle, listVar, items.Count } ); }
public string ToPythonCode() { return(string.Format("({0},{1},{2})", PythonInterop.EscapeArgument(Url), Instance.PyName, IsFolder )); }
public PyVariable GetVariable(string name) { string pyName = PythonInterop.EscapeArgument(name); return(new PyVariable( evalCode: $"{Instance.PyName}[{pyName}]", basename: name )); }
public string this[string key] { get { return(Instance.CallFunction("get", new List <object>() { key })); } set { string pyVal = PythonInterop.EscapeArgument(value); GetVariable(key).EvalAssign(pyVal); } }
public static string ToPythonCode <TKey, TValue>(this IDictionary <TKey, TValue> dict) { StringBuilder sb = new StringBuilder("{"); foreach (TKey key in dict.Keys) { sb.Append(string.Format("{0}:{1}", PythonInterop.EscapeArgument(key), PythonInterop.EscapeArgument(dict[key]) )); sb.Append(","); } sb.Length--; //remove last ',' sb.Append("}"); return(sb.ToString()); }
public static string ToPythonCode(this ICollection <string> array) { StringBuilder sb = new StringBuilder("["); var iter = array.GetEnumerator(); while (iter.MoveNext()) { string value = PythonInterop.EscapeArgument(iter.Current.ToString()); sb.Append(value + ","); } sb.Length--; sb.Append("]"); return(sb.ToString()); }