示例#1
0
        private static string GetFullPathAndValidateCase(LanguageContext /*!*/ context, string path, bool isDir)
        {
#if !SILVERLIGHT
            // check for a match in the case of the filename, unfortunately we can't do this
            // in Silverlight becauase there's no way to get the original filename.

            PlatformAdaptationLayer pal = context.DomainManager.Platform;
            string dir = pal.GetDirectoryName(path);
            if (!pal.DirectoryExists(dir))
            {
                return(null);
            }

            try {
                string   file  = pal.GetFileName(path);
                string[] files = pal.GetFileSystemEntries(dir, file, !isDir, isDir);

                if (files.Length != 1 || pal.GetFileName(files[0]) != file)
                {
                    return(null);
                }

                return(pal.GetFullPath(files[0]));
            } catch (IOException) {
                return(null);
            }
#else
            return(path);
#endif
        }
示例#2
0
        private static string GetFullPathAndValidateCase(LanguageContext /*!*/ context, string path, bool isDir)
        {
            // Check for a match in the case of the filename.
            PlatformAdaptationLayer pal = context.DomainManager.Platform;
            string dir = pal.GetDirectoryName(path);

            if (!pal.DirectoryExists(dir))
            {
                return(null);
            }

            try {
                string   file  = pal.GetFileName(path);
                string[] files = pal.GetFileSystemEntries(dir, file, !isDir, isDir);

                if (files.Length != 1 || pal.GetFileName(files[0]) != file)
                {
                    return(null);
                }

                return(pal.GetFullPath(files[0]));
            } catch (IOException) {
                return(null);
            }
        }
示例#3
0
        internal static PythonModule TryImportSourceFile(PythonContext /*!*/ context, string /*!*/ name)
        {
            var sourceUnit = TryFindSourceFile(context, name);
            PlatformAdaptationLayer pal = context.DomainManager.Platform;

            if (sourceUnit == null ||
                GetFullPathAndValidateCase(context, pal.CombinePaths(pal.GetDirectoryName(sourceUnit.Path), name + pal.GetExtension(sourceUnit.Path)), false) == null)
            {
                return(null);
            }

            var scope = ExecuteSourceUnit(context, sourceUnit);

            if (sourceUnit.LanguageContext != context)
            {
                // foreign language, we should publish in sys.modules too
                context.SystemStateModules[name] = scope;
            }
            PythonOps.ScopeSetMember(context.SharedContext, sourceUnit.LanguageContext.DomainManager.Globals, name, scope);
            return(scope);
        }