public static void PerformModuleReload(PythonContext /*!*/ context, PythonDictionary /*!*/ dict) { if (!dict.ContainsKey("References")) { dict["References"] = context.ReferencedAssemblies; } }
public Bytes get_data(CodeContext /*!*/ context, string path) { if (path.Length >= MAXPATHLEN) { throw MakeError(context, "path too long"); } path = path.Replace(_archive, string.Empty).TrimStart(Path.DirectorySeparatorChar); if (!__files.ContainsKey(path)) { throw PythonOps.IOError(path); } var data = GetData(context, _archive, __files[path] as PythonTuple); return(Bytes.Make(data)); }
public string get_data(CodeContext /*!*/ context, string path) { if (path.Length >= MAXPATHLEN) { throw MakeError("path too long"); } path = path.Replace(_archive, string.Empty).TrimStart(Path.DirectorySeparatorChar); if (!__files.ContainsKey(path)) { throw PythonOps.IOError(path); } var data = GetData(_archive, __files[path] as PythonTuple); return(PythonAsciiEncoding.Instance.GetString(data, 0, data.Length)); }
public zipimporter(CodeContext /*!*/ context, object pathObj, [ParamDictionary] IDictionary <object, object> kwArgs) { PlatformAdaptationLayer pal = context.LanguageContext.DomainManager.Platform; string prefix, input, path; if (pathObj == null) { throw PythonOps.TypeError("must be string, not None"); } if (!(pathObj is string)) { throw PythonOps.TypeError("must be string, not {0}", pathObj.GetType()); } if (kwArgs.Count > 0) { throw PythonOps.TypeError("zipimporter() does not take keyword arguments"); } path = pathObj as string; if (path.Length == 0) { throw MakeError(context, "archive path is empty"); } if (path.Length > MAXPATHLEN) { throw MakeError(context, "archive path too long"); } string buf = path.Replace(Path.AltDirectorySeparatorChar, Path.DirectorySeparatorChar); input = buf; path = string.Empty; prefix = string.Empty; try { while (!string.IsNullOrEmpty(buf)) { if (pal.FileExists(buf)) { path = buf; break; } buf = Path.GetDirectoryName(buf); } } catch { throw MakeError(context, "not a Zip file"); } if (!string.IsNullOrEmpty(path)) { PythonDictionary zip_directory_cache = context.LanguageContext.GetModuleState( _zip_directory_cache_key) as PythonDictionary; if (zip_directory_cache != null && zip_directory_cache.ContainsKey(path)) { _files = zip_directory_cache[path] as PythonDictionary; } else { _files = ReadDirectory(context, path); zip_directory_cache.Add(path, _files); } } else { throw MakeError(context, "not a Zip file"); } _prefix = input.Replace(path, string.Empty); // add trailing SEP if (!string.IsNullOrEmpty(_prefix) && !_prefix.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) { _prefix = _prefix.Substring(1); _prefix += Path.DirectorySeparatorChar; } _archive = path; }