internal static SourceUnit TryFindSourceFile(PythonContext /*!*/ context, string /*!*/ name) { PythonList paths; if (!context.TryGetSystemPath(out paths)) { return(null); } foreach (object dirObj in paths) { string directory = dirObj as string; if (directory == null) { continue; // skip invalid entries } string candidatePath = null; LanguageContext candidateLanguage = null; foreach (string extension in context.DomainManager.Configuration.GetFileExtensions()) { string fullPath; try { fullPath = context.DomainManager.Platform.CombinePaths(directory, name + extension); } catch (ArgumentException) { // skip invalid paths continue; } if (context.DomainManager.Platform.FileExists(fullPath)) { if (candidatePath != null) { throw PythonOps.ImportError(String.Format("Found multiple modules of the same name '{0}': '{1}' and '{2}'", name, candidatePath, fullPath)); } candidatePath = fullPath; candidateLanguage = context.DomainManager.GetLanguageByExtension(extension); } } if (candidatePath != null) { return(candidateLanguage.CreateFileUnit(candidatePath)); } } return(null); }