Commit Graph

141 Commits

Author SHA1 Message Date
Ka-Ping Yee 593cd6b843 Clean up the TextIOWrapper code; pick better names; improve documentation. 2008-03-20 10:37:32 +00:00
Ka-Ping Yee dbe28e573e This is r61508 plus additional fixes to the handling of 'limit'
in TextIOWrapper.readline().

All tests now pass for me (except for expected skips on darwin:
bsddb, bsddb3, cProfile, codecmaps_*, curses, gdbm, largefile,
locale, normalization, ossaudiodev, pep277, socketserver,
startfile, timeout, urllib2net, urllibnet, winreg, winsound,
xmlrpc_net, zipfile64, and the -u largefile part of test_io).
2008-03-20 10:34:07 +00:00
Neal Norwitz e2b070558c Revert r61508: it caused test_mailbox to fail on all platforms. 2008-03-18 19:52:05 +00:00
Ka-Ping Yee 30cc83832d In TextIOWrapper:
- Switch from consuming _decoded_text to advancing an offset into it.
  - Fix readline() interaction with seek/tell.
  - Fix readline() handling of 'limit' argument.

Add tests for seek/tell after readline().
2008-03-18 07:01:49 +00:00
Ka-Ping Yee f44c7e8996 Make TextIOWrapper's seek/tell work properly with stateful decoders;
document and rename things to make seek/tell workings a little clearer.

Add a weird decoder for testing TextIOWrapper's seek/tell methods.

Document the getstate/setstate protocol conventions for IncrementalDecoders.
2008-03-18 04:51:32 +00:00
Ka-Ping Yee ddaa7064ee Patch from jbalogh fixes issue #2282 (misnamed seekable() method). 2008-03-17 20:35:15 +00:00
Ka-Ping Yee 7a0d3980ed Remove the "unsafe" flag on peek() -- it is no longer used, because
self._read_buf is an immutable bytes object.
2008-03-17 17:34:48 +00:00
Christian Heimes 3ecfea71ff Merged revisions 60481,60485,60489-60492,60494-60496,60498-60499,60501-60503,60505-60506,60508-60509,60523-60524,60532,60543,60545,60547-60548,60552,60554,60556-60559,60561-60562,60569,60571-60572,60574,60576-60583,60585-60586,60589,60591,60594-60595,60597-60598,60600-60601,60606-60612,60615,60617,60619-60621,60623-60625,60627-60629,60631,60633,60635,60647,60650,60652,60654,60656,60658-60659,60664-60666,60668-60670,60672,60676,60678-60695 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk

........
  r60679 | raymond.hettinger | 2008-02-09 02:18:42 +0100 (Sat, 09 Feb 2008) | 1 line

  Make ABC containers inherit as documented.
........
  r60684 | raymond.hettinger | 2008-02-09 04:34:52 +0100 (Sat, 09 Feb 2008) | 1 line

  Merge with r60683.
........
  r60687 | raymond.hettinger | 2008-02-09 05:37:49 +0100 (Sat, 09 Feb 2008) | 1 line

  Add -3 warnings that set.copy(), dict.copy(), and defaultdict.copy() will go away in Py3.x
........
  r60689 | raymond.hettinger | 2008-02-09 11:04:19 +0100 (Sat, 09 Feb 2008) | 1 line

  Metaclass declaration is inherited
........
  r60691 | raymond.hettinger | 2008-02-09 11:06:20 +0100 (Sat, 09 Feb 2008) | 1 line

  Temporarily disable this test. It's been broken for a week.
........
  r60695 | nick.coghlan | 2008-02-09 16:28:09 +0100 (Sat, 09 Feb 2008) | 1 line

  Issue 2021: Allow NamedTemporaryFile and SpooledTemporaryFile to be used as context managers. (The NamedTemporaryFile fix should be considered for backporting to 2.5)
........
2008-02-09 20:51:34 +00:00
Alexandre Vassalotti a38f73b1bb Fix issue1753: TextIOWrapper.write writes utf BOM for every string.
Patch by Erick Tryzelaar, with slight modifications by me.
2008-01-07 18:30:48 +00:00
Alexandre Vassalotti c3d7fe0dbe Fix the reset() method of IncrementalNewlineDecoder to
also reset self.seennl.
2007-12-28 01:24:22 +00:00
Christian Heimes a33eb06e3b Added descriptor for builtins.open.__doc__
Before the change help(open) didn't return anything helpful but the doc string of io.OpenWrapper. Now it shows the user the documentation of io.open.
2007-12-08 17:47:40 +00:00
Guido van Rossum f64db9f6db Fix the rest of issue 1400, by introducing a proper implementation of
line buffering.  The TextIOWrapper class no longer calls isatty() on
every write() call.
2007-12-06 01:04:26 +00:00
Guido van Rossum e7fc50f2d0 Add an errors parameter to open() and TextIOWrapper() to specify error handling. 2007-12-03 22:54:21 +00:00
Georg Brandl 1a3284ed69 #1535: rename __builtin__ module to builtins. 2007-12-02 09:40:06 +00:00
Guido van Rossum 254348e201 Rename buffer -> bytearray. 2007-11-21 19:29:53 +00:00
Amaury Forgeot d'Arc a2d1d7e3b2 Oops, I missed this one again (test_univnewlines fails):
Some incremental decoders return multiple characters, even when fed with
only one more byte. In this case the tell() state must subtract the
number of extra characters.
2007-11-19 21:14:47 +00:00
Amaury Forgeot d'Arc 1ff9910f59 Issue1395: Universal mode used to duplicate newlines when using read(1).
"Universal newline" is now an incremental decoder wrapping the initial one,
with its own additional buffer (if '\r' is seen at the end of the input).

A decoder allows the tell() funtion to record the state of the translation.
This also simplifies the readline() process.

Now test_netrc passes on Windows, as well as many new tests in test_io.py
2007-11-19 20:34:10 +00:00
Christian Heimes 3ab4f651b9 seek() has to accept any int-like number 2007-11-09 01:27:29 +00:00
Christian Heimes 8e42a0a0e0 Fixed bug #1081: file.seek allows float arguments 2007-11-08 18:04:45 +00:00
Christian Heimes 8bd14fb398 Fixed #1403 where compileall and py_compile choked on an encoding header in a py file. Both modules need more unit tests. 2007-11-08 16:34:32 +00:00
Guido van Rossum 98297ee781 Merging the py3k-pep3137 branch back into the py3k branch.
No detailed change log; just check out the change log for the py3k-pep3137
branch.  The most obvious changes:

  - str8 renamed to bytes (PyString at the C level);
  - bytes renamed to buffer (PyBytes at the C level);
  - PyString and PyUnicode are no longer compatible.

I.e. we now have an immutable bytes type and a mutable bytes type.

The behavior of PyString was modified quite a bit, to make it more
bytes-like.  Some changes are still on the to-do list.
2007-11-06 21:34:58 +00:00
Georg Brandl 316414e435 Fix typo. 2007-10-30 17:42:20 +00:00
Guido van Rossum 2dced8b602 Patch 1329 (partial) by Christian Heimes.
Add a closefd flag to open() which can be set to False to prevent closing
the file descriptor when close() is called or when the object is destroyed.
Useful to ensure that sys.std{in,out,err} keep their file descriptors open
when Python is uninitialized.  (This was always a feature in 2.x, it just
wasn't implemented in 3.0 yet.)
2007-10-30 17:27:30 +00:00
Guido van Rossum 57233cb3f9 Patch 1330 by Christian Heimes (with some TLC applied by myself).
Move most of the messiness with truncate() on Windows into _fileio.c.
Still keep the flush() call in io.py though.
2007-10-26 17:19:33 +00:00
Guido van Rossum 79b79eeab2 Patch # 1323 by Amaury Forgeot d'Arc.
This patch corrects a problem in test_file.py on Windows:
f.truncate() seeks to the truncation point, but does not empty the
buffers. In the test, f.tell() returns -1...
2007-10-25 23:21:03 +00:00
Guido van Rossum ce3a72aec6 Patch 1267 by Christian Heimes.
Move the initialization of sys.std{in,out,err} and __builtin__.open
to C code.
This solves the problem that "python -S" wouldn't work.
2007-10-19 23:16:50 +00:00
Guido van Rossum 3172c5d263 Patch# 1258 by Christian Heimes: kill basestring.
I like this because it makes the code shorter! :-)
2007-10-16 18:12:55 +00:00
Brett Cannon 7648ba83f2 Make the docstring for io.open() a raw string so that the explanation for the
'newline' argument is not a jumbled mess of newlines.
2007-10-15 20:52:41 +00:00
Brett Cannon 041683df42 Remove self-referential import. 2007-10-11 23:08:53 +00:00
Guido van Rossum e86254e256 In rseponse to bug# 1029, force the newline default for StringIO to "\n",
so that even on Windows, after s.write("x\n"), s.getvalue() == "x\n".
2007-08-29 18:31:16 +00:00
Guido van Rossum dcce8391d1 Insist that the argument to TextIOWrapper.write() is a basestring
instance.  This was effectively already the case, but the error
reporting was lousy.
2007-08-29 18:10:08 +00:00
Guido van Rossum a74184eb1d Commit strict str/bytes distinction.
From now on, trying to write str to a binary stream
is an error (I'm still working on the reverse).
There are still (at least) two failing tests:
- test_asynchat
- test_urllib2_localnet
but I'm sure these will be fixed by someone.
2007-08-29 04:05:57 +00:00
Guido van Rossum 5abbf750a2 Changes to io.py and socket.py by Christian Heimes.
- Replace all asserts by ValuleErrors or TypeErrors as appropriate.
- Add _checkReadable, _checkWritable methods; these check self.closed too.
- Add a test that everything exported by io.py exists, and is either
  an exception or an IOBase instance (except for the open function).
- Default buffering to 1 if isatty() (I had to tweak this to enforce
  the *default* bit -- GvR).
2007-08-27 17:39:33 +00:00
Guido van Rossum b7f136e73e Make IOBase (and hence all other classes in io.py) use ABCMeta as its metaclass,
so you can use their class .register() method to register virtual subclasses.
2007-08-22 18:14:10 +00:00
Guido van Rossum 8358db22fa New I/O code from Tony Lownds implement newline feature correctly,
and implements .newlines attribute in a 2.x-compatible fashion.
2007-08-18 21:39:55 +00:00
Neal Norwitz 1e50a9f7cc Fix test_wsgiref that used StringIO and a BufferedReader rather than
real files.  This code assumed that fileno() would succeed which wasn't
the case.
2007-08-11 18:37:05 +00:00
Martin v. Löwis d78d3b4541 Fall back to ascii if the locale module cannot be loaded. 2007-08-11 15:36:45 +00:00
Martin v. Löwis d1cd4d4176 Set sys.stdout.encoding properly.
Always set LC_CTYPE on interpreter startup.
Add device_encoding function.
2007-08-11 14:02:14 +00:00
Guido van Rossum 34d1928766 SF patch# 1770008 by Christian Heimes (plus some extras).
Completely get rid of StringIO.py and cStringIO.c.

I had to fix a few tests and modules beyond what Christian did, and
invent a few conventions.  E.g. in elementtree, I chose to
write/return Unicode strings whe no encoding is given, but bytes when
an explicit encoding is given.  Also mimetools was made to always
assume binary files.
2007-08-09 01:03:29 +00:00
Jeremy Hylton 5accbdb812 Make sure socket.close() doesn't interfere with socket.makefile().
If a makefile()-generated object is open and its parent socket is
closed, the parent socket should remain open until the child is
closed, too.  The code to support this is moderately complex and
requires one extra slots in the socket object.

This change fixes httplib so that several urllib2net test cases pass
again.

Add SocketCloser class to socket.py, which encapsulates the
refcounting logic for sockets after makefile() has been called.

Move SocketIO class from io module to socket module.  It's only use is
to implement the raw I/O methods on top of a socket to support
makefile().

Add unittests to test_socket to cover various patterns of close and
makefile.
2007-08-03 20:40:09 +00:00
Guido van Rossum 3e1f85eb5d Fix the minidom test.
In order to do this, I added an optional encoding argument to io.StringIO.
The toprettyxml() function returns bytes when you specify an encoding now.
2007-07-27 18:03:11 +00:00
Guido van Rossum 67feb09d06 Delete redundant read() and close() methods from SocketIO class. 2007-07-27 04:38:24 +00:00
Guido van Rossum 33e7a8e813 Make close() (all versions) ignore IOError from flush().
This makes test_resource.py pass, and I think it's the right thing
to do: if you're closing a file after encountering an I/O error
there's nothing you can do about it.  If you want the error, you
can call flush() yourself.
2007-07-22 20:38:07 +00:00
Guido van Rossum b972a78e17 SF patch# 1757683 by Alexandre Vassalotti. Add support for
seeking/writing beyond EOF to io.BytesIO.
2007-07-21 00:25:15 +00:00
Guido van Rossum 469734b996 Set closed flag *after* calling flush(). 2007-07-10 12:00:45 +00:00
Guido van Rossum 4b5386f398 Add proper tests for closed files to various I/O operations,
restoring a disabled test.
This was necessary to make test_pickle.py pass.
2007-07-10 09:12:49 +00:00
Guido van Rossum 7165cb1a48 Made test_file pass. This meant adding support for read(-1) and read()
to even the most basic file object (I also added readall() which may
be a better API).  Also, not all the tests requiring specific failure
modes could be saved.  And there were the usual str/bytes issues.
I made sure test_io.py still passes (io.py is now most thoroughly
tested by combining test_file.py and test_io.py).
2007-07-10 06:54:34 +00:00
Guido van Rossum 2bf7138bb7 Make test_socket work.
Don't exclude test_socket from the tests to run.
2007-06-08 00:07:57 +00:00
Guido van Rossum 48fc58ad31 Accellerate binary readline() a bit. 2007-06-07 23:45:37 +00:00
Guido van Rossum 9cbfffd1a6 tokenizer.c: make coding markup work again.
io.open() now takes all positional parameters (so we can conveniently
call it from C code).

test_tarfile.py no longer uses u"..." literals, but is otherwise still
badly broken.

This is a checkpoint; some more stuff now breaks.
2007-06-07 00:54:15 +00:00
Walter Dörwald 865b003de0 Remove debug print. 2007-05-29 19:18:28 +00:00
Walter Dörwald a327000bdd Fix typo. 2007-05-29 19:13:29 +00:00
Guido van Rossum 859b5ec240 Add isatty() to TextIOWrapper. 2007-05-27 09:14:51 +00:00
Guido van Rossum fc3436becd Add an encoding property to TextIOBase instances.
Add sys.__std{in,out,err}__.
Make test_sys pass.
2007-05-24 17:58:06 +00:00
Guido van Rossum fa0054aa73 Make test_subprocess work. Fix universal newlines in io.py. 2007-05-24 04:05:35 +00:00
Guido van Rossum c2f93dc2e4 Remove native popen() and fdopen(), replacing them with subprocess calls.
Fix a path to an assert in fileio_read().
Some misc tweaks.
2007-05-24 00:50:02 +00:00
Guido van Rossum 7d0a8264ff Sockets facelift. APIs that could return binary data (e.g. aton() and
recv()) now return bytes, not str or str8.  The socket.py code is
redone; it now subclasses _socket.socket and instead of having its own
_fileobject for makefile(), it uses io.SocketIO.  Some stuff in io.py
was moved around to make this work.  (I really need to rethink my
policy regarding readline() and read(-1) on raw files; and readline()
on buffered files ought to use peeking().  Later.)
2007-05-21 23:13:11 +00:00
Guido van Rossum 024da5c257 Make all the multibyte codec tests pass.
Changes to io.py, necessary to make this work:
- Redid io.StringIO as a TextIOWrapper on top of a BytesIO instance.
- Got rid of _MemoryIOMixin, folding it into BytesIO instead.
- The read() functions that take -1 to mean "eveything" now also take None.
- Added readline() support to BufferedIOBase. :-(
2007-05-17 23:59:11 +00:00
Walter Dörwald e35553e24c Fix io.StringIO for wide Python builds. 2007-05-16 12:53:48 +00:00
Walter Dörwald 9d2ac22721 Fix io.StringIO: String are stored encoded (using "unicode-internal" as the
encoding) which makes the buffer mutable. Strings are encoded on the way in
and decoded on the way out.

Use io.StringIO in test_codecs.py.

Fix the base64_codec test in test_codecs.py.
2007-05-16 12:47:53 +00:00
Guido van Rossum a5c313dc4d Add to an XXX comment. 2007-05-09 23:41:10 +00:00
Guido van Rossum 2b08b38dea Fix a few places where a str instead of a bytes object was used. 2007-05-08 20:18:39 +00:00
Georg Brandl a18af4e7a2 PEP 3114: rename .next() to .__next__() and add next() builtin. 2007-04-21 15:47:16 +00:00
Guido van Rossum d76e7796c9 Instead of pickling the whole decoder, use the new getstate/setstate API. 2007-04-17 02:38:04 +00:00
Guido van Rossum 13633bb8c5 Support name and mode attributes on all file types.
Don't read more than one line when reading text from a tty device.
Add peek() and read1() methods.
Return str instead of unicode when return ASCII characters in text mode.
2007-04-13 18:42:35 +00:00
Guido van Rossum dc0b1a1069 Make a few more tests pass with the new I/O library.
Fix the truncate() semantics -- it should not affect the current position.
Switch wave.py/chunk.py to struct.unpack_from() to support bytes.
Don't use writelines() on binary files (test_fileinput.py).
2007-04-12 22:55:07 +00:00
Guido van Rossum d410395ea7 Make sure that writing an array instance returns the number of bytes,
not the number of array elements.
2007-04-12 05:44:49 +00:00
Guido van Rossum aa43ed95cd TextIO improvement:
- 25% speed increse in tell();
- f.seek(0, 1) now maps to f.seek(f.tell(), 0) instead of to f.tell().
2007-04-12 05:24:24 +00:00
Guido van Rossum b9c4c3e455 Speed up next() by disabling snapshot updating then. 2007-04-11 16:07:50 +00:00
Guido van Rossum cba608cadb More efficient implementation of tell(); _read_chunk() doesn't have to
call self.buffer.tell().
2007-04-11 14:19:59 +00:00
Guido van Rossum 0dd32e246c Real pickling for bytes.
Restore complex pickling.
Use cPickle in io.py.
2007-04-11 05:40:58 +00:00
Guido van Rossum 9b76da6a8f Checkpoint so I can continue to work on this at a different box.
There is somewhat working (but slow) code supporting seek/tell for text files,
but extensive testing exposes a bug I can't nail down.
2007-04-11 01:09:03 +00:00
Guido van Rossum 8742977b33 truncate() returns the new size and position.
write() returns the number of bytes/characters written/buffered.
FileIO.close() calls self.flush().
Implement readinto() for buffered readers.
Tests th check all these.
Test proper behavior of __enter__/__exit__.
2007-04-10 21:06:59 +00:00
Guido van Rossum 53807dabf0 Implement long positioning (Unix only, probably).
Etc., etc.
2007-04-10 19:01:47 +00:00
Guido van Rossum cce92b27d6 BufferedIOBase and TextIOBase should derive from IOBase, not from RawIOBase! 2007-04-10 14:41:39 +00:00
Guido van Rossum 141f767d46 More cleanup. Renamed BlockingIO to BlockingIOError.
Removed unused _PyFileIO class.
Changed inheritance structure.
TODO: do the same kinds of things to TextIO.
2007-04-10 00:22:16 +00:00
Guido van Rossum 4f0db6e4a1 Cleanup.
Add closed attribute.
Support int argument to open() -- wrapping a file descriptor.
For b/w compat, support readline(n).
Support readlines() and readlines(n).
Flush on __del__.
Added some XXX comments.
2007-04-08 23:59:06 +00:00
Guido van Rossum 9be5597abf Add some backwards compatibility stuff.
This now appears to work when io.open is substituted for the real open
in fileinput.py -- at least the latter's unit tests pass.
2007-04-07 02:59:27 +00:00
Guido van Rossum 76c5d4d72d Checkpoint.
Some cleanup of test_io.py and io.py.
Added seeking to buffered reader and writer, but no tests yet.
2007-04-06 19:10:29 +00:00
Guido van Rossum 186685905c Get rid of duplicate definition of BufferedIOBase. 2007-04-06 18:11:47 +00:00
Guido van Rossum 78892e4613 Added a working Text I/O layer, by Mark Russell.
This is essentially a checkpoint.
2007-04-06 17:31:18 +00:00
Guido van Rossum ef17c16b36 Bug 1679498: remove unused instance variables _readable, _writable and
_seekable.
2007-03-18 03:42:15 +00:00
Guido van Rossum bb09b21250 Bug 1679498: unset variable 'bs'. 2007-03-18 03:36:28 +00:00
Guido van Rossum c819dea40d Add some XXX comments and fix BufferedReader signature. 2007-03-15 18:59:31 +00:00
Guido van Rossum a9e2024b84 Check in Daniel Stutzbach's _fileio.c and test_fileio.py
(see SF#1671314) with small tweaks.
The io module now uses this instead of its own implementation
of the FileIO class, if it can import _fileio.
2007-03-08 00:43:48 +00:00
Guido van Rossum 00efeadbcf Change the specs for readinto() -- it should *not* shorten the buffer to
the amount of data read.
2007-03-07 05:23:25 +00:00
Guido van Rossum 01a2752d19 New version from Mike Verdone (sat in my inbox since 2/27).
I cleaned up whitespace but otherwise didn't change it.

This will need work to reflect the tentative decision to drop nonblocking I/O
support from the buffering layers.
2007-03-07 01:00:12 +00:00
Guido van Rossum 68bbcd2a71 Mike Verdone's checkpoint, cleaned up.
Also implemented Neal's suggestion (add fileno() to SocketIO)
and some unrelated changes, e.g. remove Google copyright
and make BytesIO a subclass of BufferedIOBase.
2007-02-27 17:19:33 +00:00
Guido van Rossum 17e43e582c Added some comments and docstrings. More is needed. 2007-02-27 15:45:13 +00:00
Neal Norwitz 8b41c3dc28 Add some XXX comments for Guido to look at. 2007-02-27 06:26:14 +00:00
Guido van Rossum 28524c7f10 Checkpoint for new I/O library. 2007-02-27 05:47:44 +00:00