Commit Graph

78 Commits

Author SHA1 Message Date
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