コード例 #1
0
        protected virtual void Dispose(bool disposing)
        {
            if (isclosed)
            {
                return;
            }

            if (disposing)
            {
                Flush();
                stream.Close();
            }

            isclosed = true;
            PythonFileManager.Remove(this);
        }
コード例 #2
0
 public int GetFileNumber()
 {
     ThrowIfClosed();
     return(PythonFileManager.GetIdFromFile(this));
 }
コード例 #3
0
        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);
        }