コード例 #1
0
        internal PythonFile(Stream stream, Encoding encoding, string mode, bool weakMapping)
        {
            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";
            }

            if (weakMapping)
                PythonFileManager.AddToWeakMapping(this);
        }
コード例 #2
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);
        }