48 Commits

Author SHA1 Message Date
Tim Peters
a6c0c202f5 Mechanical whitespace normalization. 2006-03-23 19:07:46 +00:00
Walter Dörwald
a4b4dc328f Backport revision 42872:
If size is specified, try to read at least size characters.
This is a alternative version of patch #1379332.
2006-03-06 22:44:03 +00:00
Martin v. Löwis
91926ad477 Patch #1268314: Cache lines in StreamReader.readlines for performance. 2005-09-18 08:45:35 +00:00
Walter Dörwald
81e2d6b60a Backport checkin:
SF bug #1235646: codecs.StreamRecoder.next() now reencodes the data it reads
from the input stream, so that the output is a byte string in the correct
encoding instead of a unicode string.
2005-09-01 12:03:14 +00:00
Martin v. Löwis
674c1882fe Return complete lines from codec stream readers
even if there is an exception in later lines, resulting in
correct line numbers for decoding errors in source code. Fixes #1178484.
2005-08-24 07:38:36 +00:00
Walter Dörwald
ba72589680 Backport checkin:
Make attributes and local variables in the StreamReader str objects instead
of unicode objects, so that codecs that do a str->str decoding won't promote
the result to unicode. This fixes SF bug #1241507.
2005-07-20 22:52:09 +00:00
Walter Dörwald
4d3fec604d Backport checkin (and the appropriate fix to the test):
If the data read from the bytestream in readline() ends in a '\r' read one more
byte, even if the user has passed a size parameter. This extra byte shouldn't
cause a buffer overflow in the tokenizer. The original plan was to return a line
ending in '\r', which might be recognizable as a complete line and skip any '\n'
that was read afterwards. Unfortunately this didn't work, as the tokenizer only
recognizes '\n' as line ends, which in turn lead to joined lines and
SyntaxErrors, so this special treatment of a split '\r\n' has been dropped. (It
can only happen with a temporarily exhausted bytestream now anyway.)
Fixes parts of SF bugs #1163244 and #1175396.
2005-04-21 21:53:43 +00:00
Walter Dörwald
67e4ecd451 Backport checkin:
Fix for SF bug #1175396: readline() will now read one more character, if
the last character read is "\r" (and size is None, i.e. we're allowed to
call read() multiple times), so that we can return the correct line ending
(this additional character might be a "\n").

If the stream is temporarily exhausted, we might return the wrong line ending
(if the last character read is "\r" and the next one (after the byte stream
provides more data) is "\n", but at least the atcr member ensures that we
get the correct number of lines (i.e. this "\n" will not be treated as
another line ending).
2005-04-04 21:56:28 +00:00
Walter Dörwald
2a20d4bd31 Backport checkin:
Add default value for "whence" argument.
2005-03-14 19:26:47 +00:00
Walter Dörwald
96aeafbfbc Backport checkin:
Reset internal buffers when seek() is called. This fixes SF bug #1156259.
2005-03-14 19:20:19 +00:00
Martin v. Löwis
ad80c6bb2a Build with --disable-unicode again. Fixes #1158607. 2005-03-08 15:05:18 +00:00
Walter Dörwald
55d3a19643 Backport checkin:
Fix and test for SF bug #1098990: codec readline() splits lines apart.
2005-01-10 12:26:00 +00:00
Walter Dörwald
d0e18e48d2 Backport checkin:
The changes to the stateful codecs in 2.4 resulted in StreamReader.readline()
trying to return a complete line even if a size parameter was given (see
http://www.python.org/sf/1076985). This leads to buffer overflows with long
source lines under Windows if e.g. cp1252 is used as the source encoding.
This patch reverts the behaviour of readline() to something that behaves more
like Python 2.3: If a size parameter is given, read() is called only once.

As a side effect of this, readline() now supports all types of linebreaks
supported by unicode.splitlines().

Note that the tokenizer is still broken and it's possible to provoke segfaults
(see http://www.python.org/sf/1089395).
2004-12-21 22:35:24 +00:00
Hye-Shik Chang
af5c7cff56 SF #1048865: Fix a trivial typo that breaks StreamReader.readlines() 2004-10-17 23:51:21 +00:00
Walter Dörwald
69652035bc SF patch #998993: The UTF-8 and the UTF-16 stateful decoders now support
decoding incomplete input (when the input stream is temporarily exhausted).
codecs.StreamReader now implements buffering, which enables proper
readline support for the UTF-16 decoders. codecs.StreamReader.read()
has a new argument chars which specifies the number of characters to
return. codecs.StreamReader.readline() and codecs.StreamReader.readlines()
have a new argument keepends. Trailing "\n"s will be stripped from the lines
if keepends is false. Added C APIs PyUnicode_DecodeUTF8Stateful and
PyUnicode_DecodeUTF16Stateful.
2004-09-07 20:24:22 +00:00
Marc-André Lemburg
d594849c42 Ignore sizehint argument. Fixes SF #844561. 2004-02-26 15:22:17 +00:00
Walter Dörwald
7f3ed74643 Fix typos. 2003-02-02 23:08:27 +00:00
Neal Norwitz
6ec0a8ab93 sys was already imported, remove second import 2002-12-30 23:36:02 +00:00
Marc-André Lemburg
b28de0d79f Patch to make _codecs a builtin module. This is necessary since
Python 2.3 will support source code encodings which rely on the
builtin codecs being available to the parser.

Remove struct dependency from codecs.py
2002-12-12 17:37:50 +00:00
Walter Dörwald
7f82f7955e Add missing documentation for the PEP 293 functionality to
the codecs docstrings.
2002-11-19 21:42:53 +00:00
Walter Dörwald
4dbf192f2b Add next() and __iter__() methods to StreamReader, StreamReaderWriter
and StreamRecoder.

This closes SF bug #634246.
2002-11-06 16:53:44 +00:00
Walter Dörwald
3aeb632c31 PEP 293 implemention (from SF patch http://www.python.org/sf/432401) 2002-09-02 13:14:32 +00:00
Walter Dörwald
474458da48 Add constants BOM_UTF8, BOM_UTF16, BOM_UTF16_LE, BOM_UTF16_BE,
BOM_UTF32, BOM_UTF32_LE and BOM_UTF32_BE that represent the Byte
Order Mark in UTF-8, UTF-16 and UTF-32 encodings for little and
big endian systems.

The old names BOM32_* and BOM64_* were off by a factor of 2.

This closes SF bug http://www.python.org/sf/555360
2002-06-04 15:16:29 +00:00
Raymond Hettinger
54f0222547 SF 563203. Replaced 'has_key()' with 'in'. 2002-06-01 14:18:47 +00:00
Martin v. Löwis
b786e61b1c Set default value for readlines.sizehint to None. Change needed for 2.2.1
as well.
2002-03-05 15:46:38 +00:00