protected virtual void Dispose(bool disposing) { if (isclosed) { return; } if (disposing) { Flush(); stream.Close(); } isclosed = true; PythonFileManager.Remove(this); }
public int GetFileNumber() { ThrowIfClosed(); return(PythonFileManager.GetIdFromFile(this)); }
internal PythonFile(Stream stream, Encoding encoding, string mode) { this.stream = stream; this.mode = mode; PythonFileMode filemode = MapFileMode(mode); if (stream.CanRead) { switch (filemode) { case PythonFileMode.Binary: reader = new PythonBinaryReader(stream); break; case PythonFileMode.TextCrLf: reader = new PythonTextCRLFReader(stream, encoding); break; case PythonFileMode.TextCr: reader = new PythonTextCRReader(stream, encoding); break; case PythonFileMode.TextLf: reader = new PythonTextLFReader(stream, encoding); break; case PythonFileMode.UniversalNewline: reader = new PythonUniversalReader(stream, encoding); break; } } if (stream.CanWrite) { switch (filemode) { case PythonFileMode.Binary: writer = new PythonBinaryWriter(stream); break; case PythonFileMode.TextCrLf: writer = new PythonTextCRLFWriter(stream, encoding); break; case PythonFileMode.TextCr: writer = new PythonTextCRWriter(stream, encoding); break; case PythonFileMode.TextLf: writer = new PythonTextLFWriter(stream, encoding); break; } } FileStream fs = stream as FileStream; if (fs != null) { this.name = fs.Name; } else { this.name = "nul"; } PythonFileManager.AddToMapping(this); }