[Bug #676292] BaseHTTPServer incorrectly parses protocol; fix by Andrew Dalke
* Treat major, minor numbers of HTTP version as separate integers
* Fix errors if version string is "HTTP/1.2.3" or even simply "BLAH".
* send_error() checks if 'self.command' is a
HEAD. However, if there's an error parsing the first line of the
HTTP request the self.command wasn't set yet; force
self.command to be initialized to None.
Tim Peters [Mon, 3 Feb 2003 16:20:13 +0000 (16:20 +0000)]
Proper testing of proto 2 in part requires checking that the new opcodes
are actually getting generated. Add helpered method
ensure_opcode_in_pickle to do a correct job checking for that. Changed
test_long1(), test_long4(), and test_short_tuples() to use it.
_PyLong_Sign(): remove an assert that needed a variable ndigits that
wasn't used outside the assert (and hence caused a compiler warning
about an unused variable in NDEBUG mode). The assert wasn't very
useful any more.
_PyLong_NumBits(): moved the calculation of ndigits after asserting
that v != NULL.
test_float_overflow(): make shuge (added last week) a little less
huge. On older Linux systems, the C library's strtod() apparently
gives up before seeing the end of the string when it sees so many
digits that it thinks the result must be Infinity. (It is wrong, BTW
-- there could be an "e-10000" hiding behind 10,000 digits.) The
shorter shuge still tests what it's testing, without relying on
strtod() doing a super job.
Fred Drake [Mon, 3 Feb 2003 15:19:30 +0000 (15:19 +0000)]
test_support.requires(): Instead of raising TestSkipped, raise a new
exception, ResourceDenied. This is used to distinguish between tests that
are skipped for other reasons (platform support, missing data, etc.) from
those that are skipped because a "resource" has not been enabled. This
prevents those tests from being reported as unexpected skips for the
platform; those should only be considered unexpected skips if the resource
were enabled.
Skip Montanaro [Mon, 3 Feb 2003 05:13:24 +0000 (05:13 +0000)]
* Add description of PyInt_FromString.
* Correct description of PyFloat_FromString. While ignored, the pend
argument still has to be given.
* Typo in PyLong_FromString.
Skip Montanaro [Mon, 3 Feb 2003 03:56:36 +0000 (03:56 +0000)]
Add PyFloat_FromString. Left the char **pend argument out of the
description since while there, it is useless and ignored, according to Tim's
commen. (PyInt_FromString is also not described, but PyLong_FromString is.
Is the former deprecated?)
Tim Peters [Sun, 2 Feb 2003 18:29:33 +0000 (18:29 +0000)]
Massive edits. If p is a pointer to a struct, and p->f is a pointer to
a function, then
p->f(arg1, arg2, ...)
is semantically the same as
(*p->f)(arg1, arg2, ...)
Changed all instances of the latter into the former. Given how often
the code embeds this kind of expression in an if test, the unnecessary
parens and dereferening operator were a real drag on readability.
Tim Peters [Sun, 2 Feb 2003 17:26:40 +0000 (17:26 +0000)]
Beefed up the tests by putting in more "for proto in protocols:" outer
loops. Renamed DATA and BINDATA to DATA0 and DATA1. Included
disassemblies, but noted why we can't test them. Added XXX comment to
cPickle about a mysterious comment, where pickle and cPickle diverge
in how they number PUT indices.
Tim Peters [Sun, 2 Feb 2003 16:14:23 +0000 (16:14 +0000)]
dump(): Fixed a stupid bug in new code. It wasn't possible for the bug
to have an effect before protocol 3 is invented, so no test can be
written for this (yet).
Tim Peters [Sun, 2 Feb 2003 16:09:05 +0000 (16:09 +0000)]
Add cPickle support for PROTO. Duplicated PROTO/LONG1/LONG4 code in
the hitherto unknown (to me) noload() cPickle function, which is (a)
something we don't test at all, and (b) pickle.py doesn't have.
Tim Peters [Sun, 2 Feb 2003 07:51:32 +0000 (07:51 +0000)]
long(string, base) now takes time linear in len(string) when base is a
power of 2. Enabled the tail end of test_long() in pickletester.py
because it no longer takes forever when run from test_pickle.py.
Tim Peters [Sun, 2 Feb 2003 02:57:53 +0000 (02:57 +0000)]
cPickle.c: Full support for the new LONG1 and LONG4. Added comments.
Assorted code cleanups; e.g., sizeof(char) is 1 by definition, so there's
no need to do things like multiply by sizeof(char) in hairy malloc
arguments. Fixed an undetected-overflow bug in readline_file().
longobject.c: Fixed a really stupid bug in the new _PyLong_NumBits.
pickle.py: Fixed stupid bug in save_long(): When proto is 2, it
wrote LONG1 or LONG4, but forgot to return then -- it went on to
append the proto 1 LONG opcode too.
Fixed equally stupid cancelling bugs in load_long1() and
load_long4(): they *returned* the unpickled long instead of pushing
it on the stack. The return values were ignored. Tests passed
before only because save_long() pickled the long twice.
Fixed bugs in encode_long().
Noted that decode_long() is quadratic-time despite our hopes,
because long(string, 16) is still quadratic-time in len(string).
It's hex() that's linear-time. I don't know a way to make decode_long()
linear-time in Python, short of maybe transforming the 256's-complement
bytes into marshal's funky internal format, and letting marshal decode
that. It would be more valuable to make long(string, 16) linear time.
pickletester.py: Added a global "protocols" vector so tests can try
all the protocols in a sane way. Changed test_ints() and test_unicode()
to do so. Added a new test_long(), but the tail end of it is disabled
because it "takes forever" under pickle.py (but runs very quickly under
cPickle: cPickle proto 2 for longs is linear-time).
Tim Peters [Sat, 1 Feb 2003 04:40:04 +0000 (04:40 +0000)]
New functions alloc_{time,datetime}. Got rid of all setstate-like
functions. Reworked {time,datetime}_new() to do what their corresponding
setstates used to do in their state-tuple-input paths, but directly,
without constructing an object with throwaway state first. Tightened
the "is this a state tuple input?" paths to check the presumed state
string-length too, and to raise an exception if the optional second state
element isn't a tzinfo instance (IOW, check these paths for type errors
as carefully as the normal paths).
Tim Peters [Sat, 1 Feb 2003 02:54:15 +0000 (02:54 +0000)]
There's no good reason for datetime objects to expose __getstate__()
anymore either, so don't. This also allows to get rid of obscure code
making __getnewargs__ identical to __getstate__ (hmm ... hope there
wasn't more to this than I realize!).
Tim Peters [Fri, 31 Jan 2003 22:27:17 +0000 (22:27 +0000)]
The various datetime object __setstate__() methods are no longer public
(pickling no longer needs them, and immutable objects shouldn't have
visible __setstate__() methods regardless). Rearranged the code to
put the internal setstate functions in the constructor sections.
Repaired the timedelta reduce() method, which was still producing
stuff that required a public timedelta.__setstate__() when unpickling.
Tim Peters [Fri, 31 Jan 2003 21:55:33 +0000 (21:55 +0000)]
Changed the tests to stop using __setstate__(). __setstate__() no
longer needs to be public, and shoudn't be public because all datetime
objects are immutable. The Python implementation has changed
accordingly, but still need to change the C implementation.
Guido van Rossum [Fri, 31 Jan 2003 18:53:21 +0000 (18:53 +0000)]
Another extension to reduce(). It can return a 4- or 5-tuple now.
The 4th item can be None or an iterator yielding list items, which are
used to append() or extend() the object. The 5th item can be None or
an iterator yielding a dict's (key, value) pairs, which are stuffed
into the object using __setitem__.
Also (as a separate, though related, feature) add "batching" for list
and dict items. If you pickled a dict or list with a million items in
the past, it would push a million items onto the stack. It now pushes
only 1000 items at a time on the stack, using repeated APPENDS or
SETITEMS opcodes. (For lists, I hope that using many short extend()
calls doesn't exhibit quadratic behavior.)
Jeremy Hylton [Fri, 31 Jan 2003 18:33:18 +0000 (18:33 +0000)]
Provide __module__ attributes for functions defined in C and Python.
__module__ is the string name of the module the function was defined
in, just like __module__ of classes. In some cases, particularly for
C functions, the __module__ may be None.
Change PyCFunction_New() from a function to a macro, but keep an
unused copy of the function around so that we don't change the binary
API.
Change pickle's save_global() to use whichmodule() if __module__ is
None, but add the __module__ logic to whichmodule() since it might be
used outside of pickle.
Guido van Rossum [Fri, 31 Jan 2003 18:13:18 +0000 (18:13 +0000)]
SF patch 676472 by Geoff Talvola, reviewed by Ben Laurie.
Geoff writes:
This is yet another patch to _ssl.c that sets the
underlying BIO to non-blocking if the socket being
wrapped is non-blocking. It also correctly loops when
SSL_connect, SSL_write, or SSL_read indicates that it
needs to read or write more bytes.
This seems to fix bug #673797 which was not fixed by my
previous patch.
Walter Dörwald [Fri, 31 Jan 2003 17:19:08 +0000 (17:19 +0000)]
Change the treatment of positions returned by PEP293
error handers in the Unicode codecs: Negative
positions are treated as being relative to the end of
the input and out of bounds positions result in an
IndexError.
Also update the PEP and include an explanation of
this in the documentation for codecs.register_error.
Fixes a small bug in iconv_codecs: if the position
from the callback is negative *add* it to the size
instead of substracting it.
Guido van Rossum [Fri, 31 Jan 2003 17:17:49 +0000 (17:17 +0000)]
Pass the object to save_reduce(), so the memoize() call can go into
save_reduce(), before the state is pickled. This makes it possible
for an object to be referenced from its own (mutable) state.
Tim Peters [Fri, 31 Jan 2003 15:52:05 +0000 (15:52 +0000)]
_PyLong_NumBits(): The definition of this was too specific to the quirky
needs of pickling longs. Backed off to a definition that's much easier
to understand. The pickler will have to work a little harder, but other
uses are more likely to be correct <0.5 wink>.
_PyLong_Sign(): New teensy function to characterize a long, as to <0, ==0,
or >0.
Kurt B. Kaiser [Fri, 31 Jan 2003 05:06:43 +0000 (05:06 +0000)]
M PyShell.py
M rpc.py
SF Bug 676398 Doesn't handle non-built-in exceptions
1. Move exception formatting to the subprocess; allows subclassing of
exceptions, including subclasses created in the shell without
introducing excessive complexity in the RPC mechanism.
2. Provide access to linecache from subprocess to support this.
Guido van Rossum [Thu, 30 Jan 2003 22:06:23 +0000 (22:06 +0000)]
Change the approach to pickling to use __reduce__ everywhere. Most
classes have a __reduce__ that returns (self.__class__,
self.__getstate__()). tzinfo.__reduce__() is a bit smarter, calling
__getinitargs__ and __getstate__ if they exist, and falling back to
__dict__ if it exists and isn't empty.