public override Stream OpenInputFileStream(string path)
 {
     if (IsRelativePath(path))
     {
         if (OnOpenInputFileStream != null)
         {
             OnOpenInputFileStream(path);
         }
         return(getDirectory().GetFile(path.Substring(2)).OpenRead());
     }
     else
     {
         return(innerPal.OpenInputFileStream(path));
     }
 }
 public override Stream OpenInputFileStream(string path)
 {
     if (IsRelativePath(path))
     {
         path = RemoveDotSlash(path);
         var file = getDirectory().GetFile(path);
         if (OnOpenInputFileStream != null)
         {
             OnOpenInputFileStream(file.FullPath);
         }
         return(file.OpenRead());
     }
     else
     {
         return(innerPal.OpenInputFileStream(path));
     }
 }
Esempio n. 3
0
 private static Stream OpenFile(CodeContext /*!*/ context, PlatformAdaptationLayer pal, string name, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
 {
     try {
         return(pal.OpenInputFileStream(name, fileMode, fileAccess, fileShare));
     } catch (UnauthorizedAccessException e) {
         throw PythonFile.ToIoException(context, name, e);
     } catch (IOException e) {
         PythonFile.AddFilename(context, name, e);
         throw;
     }
 }
Esempio n. 4
0
 private static Stream OpenFile(CodeContext /*!*/ context, PlatformAdaptationLayer pal, string name, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
 {
     try {
         return(pal.OpenInputFileStream(name, fileMode, fileAccess, fileShare));
     } catch (UnauthorizedAccessException) {
         throw PythonOps.OSError(13, "Permission denied", name);
     } catch (IOException e) {
         AddFilename(context, name, e);
         throw;
     }
 }
Esempio n. 5
0
 private static Stream OpenFile(CodeContext /*!*/ context, PlatformAdaptationLayer pal, string name, FileMode fileMode, FileAccess fileAccess, FileShare fileShare)
 {
     if (string.IsNullOrWhiteSpace(name))
     {
         throw PythonOps.OSError(2, "No such file or directory", filename: name);
     }
     try {
         return(pal.OpenInputFileStream(name, fileMode, fileAccess, fileShare));
     } catch (UnauthorizedAccessException) {
         throw PythonOps.OSError(13, "Permission denied", name);
     } catch (FileNotFoundException) {
         throw PythonOps.OSError(2, "No such file or directory", name);
     } catch (IOException e) {
         AddFilename(context, name, e);
         throw;
     }
 }
Esempio n. 6
0
        private static PythonTuple FindModulePath(CodeContext /*!*/ context, string name, List path)
        {
            Debug.Assert(path != null);

            if (name == null)
            {
                throw PythonOps.TypeError("find_module() argument 1 must be string, not None");
            }

            PlatformAdaptationLayer pal = context.LanguageContext.DomainManager.Platform;

            foreach (object d in path)
            {
                string dir = d as string;
                if (dir == null)
                {
                    continue;               // skip invalid entries
                }
                string pathName = Path.Combine(dir, name);
                if (pal.DirectoryExists(pathName))
                {
                    if (pal.FileExists(Path.Combine(pathName, "__init__.py")))
                    {
                        return(PythonTuple.MakeTuple(null, pathName, PythonTuple.MakeTuple("", "", PackageDirectory)));
                    }
                }

                string fileName = pathName + ".py";
                if (pal.FileExists(fileName))
                {
                    Stream     fs = pal.OpenInputFileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                    PythonFile pf = PythonFile.Create(context, fs, fileName, "U");
                    return(PythonTuple.MakeTuple(pf, fileName, PythonTuple.MakeTuple(".py", "U", PythonSource)));
                }
            }
            throw PythonOps.ImportError("No module named {0}", name);
        }
Esempio n. 7
0
 internal Stream GetStream(string path)
 {
     return(_pal.OpenInputFileStream(path));
 }