Commit Graph

7621 Commits

Author SHA1 Message Date
Tim Peters 31f119ebdb 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.
2003-02-03 16:20:13 +00:00
Guido van Rossum 7aa56c9a7f 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.
2003-02-03 15:25:01 +00:00
Andrew M. Kuchling 8ca202e395 Bug #676273: Rewrite paragraph in module docstring 2003-02-03 15:21:15 +00:00
Fred Drake 9a0db07c2f 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.
2003-02-03 15:19:30 +00:00
Greg Ward 4c6c9c42fb Add __all__ (suggested by Raymond Hettinger).
Rename 'whitespace' global to '_whitespace' -- it's not part of the
public interface.
2003-02-03 14:46:57 +00:00
Walter Dörwald 7a2d7a74fc Remove test_b1 and test_b2 from the list of tests
that are no real tests, because test_b1 and
test_b2 no longer exist. (Spotted by Raymond Hettinger)
2003-02-03 11:54:39 +00:00
Just van Rossum ca3fec7162 patch #664131, fix config command on OSX and Linux 2003-02-03 11:43:54 +00:00
Michael W. Hudson 35a92ce9da Fix bug
[ 676342 ] after using pdb readline does not work correctly

using Michael Stone's patch so the completer functionality of
cmd is only setup between preloop and postloop.
2003-02-03 11:04:27 +00:00
Gregory P. Smith bc2adef898 fix for use on python 2.1 2003-02-03 04:19:40 +00:00
Guido van Rossum 49992f9d25 cPickle now implements enough of protocol 2 to enable all
cross-pickling tests.
2003-02-03 01:32:33 +00:00
Walter Dörwald 7f3ed74643 Fix typos. 2003-02-02 23:08:27 +00:00
Jack Jansen cc94764c67 Getting rid of macfs usage and almost all FSSpecs. Untested on MacOS9. 2003-02-02 23:03:50 +00:00
Tim Peters 1d63c9f151 cPickle support for TUPLE[123]. Incidentally plugged several undetected
overflow holes in Pdata_grow().
2003-02-02 20:29:39 +00:00
Just van Rossum 9af6968b90 jeez, now I know why I shouldn't even _want_ to learn sh. 2003-02-02 18:56:37 +00:00
Tim Peters 3c67d795ef Implemented proto 2 NEWTRUE and NEWFALSE in cPickle. 2003-02-02 17:59:11 +00:00
Tim Peters 70b02d79f9 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.
2003-02-02 17:26:40 +00:00
Tim Peters 4190fb8429 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.
2003-02-02 16:09:05 +00:00
Raymond Hettinger 1ecfb73c26 One more use of ifilter() 2003-02-02 16:07:53 +00:00
Raymond Hettinger a3a53180c0 SF patch #678899: Save time and memory by using itertools in sets module. 2003-02-02 14:27:19 +00:00
Tim Peters bf2674be0e 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.
2003-02-02 07:51:32 +00:00
Tim Peters ee1a53cbb1 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).
2003-02-02 02:57:53 +00:00
Tim Peters 5bd2a79b22 The C pickle now knows how to deal with a proto= argument. Assorted
code cleanups, and purged more references to text-vs-binary modes.
2003-02-01 16:45:06 +00:00
Just van Rossum a212c5c37f removed bizarre construct, no idea why it was there... 2003-02-01 10:29:45 +00:00
Just van Rossum 2aa09566c5 icon support by Robin Dunn, closes patch #678218 2003-02-01 08:34:46 +00:00
Tim Peters b57f8f02ba 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!).
2003-02-01 02:54:15 +00:00
Raymond Hettinger 874d9bcbe5 Neaten ref count test. 2003-02-01 02:33:45 +00:00
Tim Peters 1f1b2d2e68 Removed all uses of the out-of-favor __safe_for_unpickling__ magic
attr, and copy_reg.safe_constructors.
2003-02-01 02:16:37 +00:00
Raymond Hettinger 96ef8115dd Move itertools module from the sandbox and into production. 2003-02-01 00:10:11 +00:00
Tim Peters 96940c971c 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.
2003-01-31 21:55:33 +00:00
Thomas Heller 9582794c17 Pass the preprocessor options also to the resource compiler
when compiling .RC files.

From Robin Dunn, fixes SF # 669198.
2003-01-31 20:40:15 +00:00
Guido van Rossum cf356fd865 Add extension management to __all__. 2003-01-31 20:34:07 +00:00
Guido van Rossum 7eff63abce Change the default protocol back to 0.
Add a feature suggested by Tim: a negative protocol value means to use
the largest protocol value supported.
2003-01-31 19:42:31 +00:00
Guido van Rossum 25cb7dfb0f 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.)
2003-01-31 18:53:21 +00:00
Jeremy Hylton 4f0dcc9a9a 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.
2003-01-31 18:33:18 +00:00
Michael W. Hudson 01eb85cc03 I believe this fixes
[ 669692 ] pdb user_call breakage

What an odd interface!  I guess I should have read the docstring, though.
2003-01-31 17:48:29 +00:00
Walter Dörwald 2e0b18af30 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.

From SF patch #677429.
2003-01-31 17:19:08 +00:00
Guido van Rossum f7f4517fae 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.
2003-01-31 17:17:49 +00:00
Guido van Rossum d053b4b416 Add a magical feature to save_reduce so that __reduce__ can cause
NEWOBJ to be generated.
2003-01-31 16:51:45 +00:00
Tim Peters 4b23f2b44b It's Official: for LONG1/LONG4, a "byte count" of 0 is taken as a
shortcut meaning 0L.  This allows LONG1 to encode 0L in two bytes
total.
2003-01-31 16:43:39 +00:00
Guido van Rossum c1265bd9a6 Make StringIO its own iterator, similar to real files.
(This should also be done to cStringIO.)
2003-01-31 16:04:15 +00:00
Kurt B. Kaiser 8cd0def10d 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.
2003-01-31 05:06:43 +00:00
Neal Norwitz d17406830c Fix typo 2003-01-31 04:04:23 +00:00
Tim Peters 91149821d3 Linear-time implementations of {encode,decode}_long. 2003-01-31 03:43:58 +00:00
Barry Warsaw 1a17704ff1 typo in comment 2003-01-31 03:30:09 +00:00
Neil Schemenauer 1e6ada0533 Give people who run "pydoc re" a clue. 2003-01-31 00:35:58 +00:00
Guido van Rossum 177e41a117 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.
2003-01-30 22:06:23 +00:00
Tim Peters e14295cf5f pickle.py has a few doctest'ed internal functions, so run their tests. 2003-01-30 21:27:37 +00:00
Walter Dörwald b4ff1113ca Check whether the choosen encoding requires byte swapping
for this iconv() implementation in the init function.

For encoding: use a byteswapped version of the input if
neccessary.

For decoding: byteswap every piece returned by iconv()
if neccessary (but not those pieces returned from the
callback)

Comment out test_sane() in the test script, because
whether this works depends on whether byte swapping
is neccessary or not (an on Py_UNICODE_SIZE)
2003-01-30 19:55:28 +00:00
Tim Peters 2b93c4c708 Updated the INST/OBJ docs, to say they really are (almost) identical
in 2.3.
2003-01-30 16:35:08 +00:00
Tim Peters d01c1e91c4 load_inst(), load_obj(): Put the bulk of these into a common new
_instantiate() method.
2003-01-30 15:41:46 +00:00
Tim Peters 43277d64eb dis(): Simplified stack emulation a bit. 2003-01-30 15:02:12 +00:00
Guido van Rossum 9b40e804c7 There was a subtle big in save_newobj(): it used self.save_global(t)
on the type instead of self.save(t).  This defeated the purpose of
NEWOBJ, because it didn't generate a BINGET opcode when t was already
memoized; but moreover, it would generate multiple BINPUT opcodes for
the same type!  pickletools.dis() doesn't like this.

How I found this?  I was playing with picklesize.py in the datetime
sandbox, and noticed that protocol 2 pickles for multiple objects were
in fact larger than protocol 1 pickles!  That was suspicious, so I
decided to disassemble one of the pickles.

This really needs a unit test, but I'm exhausted.  I'll be late for
work as it is. :-(
2003-01-30 06:37:41 +00:00
Guido van Rossum 4fba220f4a Slight code rearrangement to avoid testing getstate twice. 2003-01-30 05:41:19 +00:00
Guido van Rossum 45486176ea In save_newobj(), if an object's __getnewargs__ and __getstate__ are
the same function, don't save the state or write a BUILD opcode.  This
is so that a type (e.g. datetime :-) can support protocol 2 using
__getnewargs__ while also supporting protocol 0 and 1 using
__getstate__.  (Without this, the state would be pickled twice with
protocol 2, unless __getstate__ is defined to return None, which
breaks protocol 0 and 1.)
2003-01-30 05:39:04 +00:00
Raymond Hettinger 0e449234bf SF patch 672098: Three __contains__ implementations
Contributed by Jp Calderone.
2003-01-30 00:56:33 +00:00
Guido van Rossum ba884f3d22 Use %c rather than chr() to turn some ints into chars. 2003-01-29 20:14:23 +00:00
Tim Peters c1c2b3e0e2 dis(): This had a problem with proto 0 pickles, in that POP sometimes
popped a MARK, but without stack emulation the disassembler couldn't
know that, and subsequent indentation got hosed.

Now the disassembler does do enough stack emulation to catch this.  While
I was at it, also added lots of sanity checks for other stack operations,
and correct use of the memo.  This goes (I think) a long way toward being
a "pickle verifier" now too.
2003-01-29 20:12:21 +00:00
Guido van Rossum 5d9113d8be Implement appropriate __getnewargs__ for all immutable subclassable builtin
types.  The special handling for these can now be removed from save_newobj().
Add some testing for this.

Also add support for setting the 'fast' flag on the Python Pickler class,
which suppresses use of the memo.
2003-01-29 17:58:45 +00:00
Guido van Rossum d3590f937f Only log a message and chmod() when the mode isn't already what we
want it to be.  Log both the old and new mode.
2003-01-29 16:58:31 +00:00
Jack Jansen 6afc5e02fa - The mac-specific tests should also be run on darwin.
- Added test_aepack to the mac/darwin specific tests.
2003-01-29 16:24:16 +00:00
Skip Montanaro 5445594e20 minor grammar tweaks 2003-01-29 15:41:33 +00:00
Michael W. Hudson 5e83b7a9cc Teach the parsermodule about floor division. Fixes
[ 676521 ] parser module validation failure

bugfix candidate.
2003-01-29 14:20:23 +00:00
Jack Jansen 090da4b626 Moved aepack test code to the test suite. 2003-01-29 10:41:18 +00:00
Jack Jansen 0502d89b49 Some objects could have uninitialized attributes. Fixed. 2003-01-29 10:39:19 +00:00
Jack Jansen cbdffcee62 test_macfs found an error on the first day of its existence: round trips for date values to FSSpec.{Get,Set}Dates didn't work in MacPython-OS9. Fixed. 2003-01-29 09:56:56 +00:00
Guido van Rossum ecb1104342 Document the demise of all pretenses of safety, and the difference
between cPickle and pickle.py regarding __safe_for_unpickling__ before
Python 2.3.
2003-01-29 06:24:30 +00:00
Guido van Rossum 586c9e813c Declare Protocol 2 as implemented. 2003-01-29 06:16:12 +00:00
Guido van Rossum 255f3ee0a5 Support for extension codes. (By accident I checked in the tests first.) 2003-01-29 06:14:11 +00:00
Guido van Rossum 0322d0ff13 Test all three EXT opcodes, and move these tests into
TempAbstractPickleTests, because they don't work with cPickle yet.
2003-01-29 06:12:46 +00:00
Tim Peters 2c60f7a136 Whitespace normalization. 2003-01-29 03:49:43 +00:00
Tim Peters c0c12b5707 pickle: Comment repair.
pickletools:  Import decode_long from pickle instead of duplicating it.
2003-01-29 00:56:17 +00:00
Tim Peters ecd79eb7db Expect test_macostools and test_macfs to get skipped whenever
sys.platform != mac.  Likewise expect test_win{reg,sound} to get skipped
on non-win32 platforms.
2003-01-29 00:35:32 +00:00
Jack Jansen addc5859db Test aliases too. 2003-01-28 23:54:05 +00:00
Jack Jansen 2b88dec606 Converted to not use macfs whenever possible. 2003-01-28 23:53:40 +00:00
Tim Peters 47a6b13988 Temporary hacks to arrange that the pickle tests relying on protocol 2
only get run by test_pickle.py now (& not by test_cpickle.py).  This
should be undone when protocol 2 is implemented in cPickle too.
test_cpickle should pass again.
2003-01-28 22:34:11 +00:00
Guido van Rossum 4e2491dbb1 Add a comment about how some built-in types should grow a
__getnewargs__ method.
2003-01-28 22:31:25 +00:00
Guido van Rossum b26a97aa50 Get rid of __safe_for_unpickling__ and safe_constructors.
Also tidied up a few lines, got rid of apply(), added a comment.
2003-01-28 22:29:13 +00:00
Tim Peters dcaa24e503 Renamed "bin" arguments to "proto". Note that this test currently
fails, for reasons unrelated to this patch.
2003-01-28 22:26:28 +00:00
Guido van Rossum c8d6ef5cd6 Add a test for a list subclass with a __dict__ as well as slots. 2003-01-28 22:02:31 +00:00
Guido van Rossum ac5b5d2e8b Instead of bad hacks trying to worm around the inherited
object.__reduce__, do a getattr() on the class so we can explicitly
test for it.  The reduce()-calling code becomes a bit more regular as
a result.

Also add support slots: if an object has slots, the default state is
(dict, slots) where dict is the __dict__ or None, and slots is a dict
mapping slot names to slot values.  We do a best-effort approach to
find slot names, assuming the __slots__ fields of classes aren't
modified after class definition time to misrepresent the actual list
of slots defined by a class.
2003-01-28 22:01:16 +00:00
Jack Jansen 28827e2406 Don't import Nav. It isn't needed, and importing it doesn't work in a
non-windowing Python.
2003-01-28 21:40:36 +00:00
Jack Jansen 10882f6fcb Finally created the first two tests for MacPython modules: macfs and
macostools.
2003-01-28 21:39:28 +00:00
Guido van Rossum fe8d84d5ae Comment out a test that was anticipating SF patch 661536 -- but that
isn't checked in yet. :-(
2003-01-28 20:39:49 +00:00
Guido van Rossum 3d8c01b31c The default __reduce__ on the base object type obscured any
possibility of calling save_reduce().  Add a special hack for this.
The tests for this are much simpler now (no __getstate__ or
__getnewargs__ needed).
2003-01-28 19:48:18 +00:00
Neal Norwitz abcb0c03ad Fix SF bug# 676155, RuntimeWarning with tp_compare
Check return value of PyLong_AsDouble(), it can return an error.
2003-01-28 19:21:24 +00:00
Guido van Rossum 54fb192508 Move the NEWOBJ-generating code to a separate function, and invoke it
after checking for __reduce__.
2003-01-28 18:22:35 +00:00
Guido van Rossum 533dbcf250 Some experimental support for generating NEWOBJ with proto=2, and
fixed a bug in load_newobj().
2003-01-28 17:55:05 +00:00
Guido van Rossum 53b39d2e70 Verify treatment of unary minus on negative numbers SF bug #660455. 2003-01-28 17:48:21 +00:00
Barry Warsaw f71de3e9a0 Everything worked in both the distutils distro and in Python 2.3cvs,
so merge from the bsddb-bsddb3-schizo-branch back to the trunk.
2003-01-28 17:20:44 +00:00
Tim Peters a6ae9a2128 save_empty_tuple(): Comment on why we can't get rid of this. 2003-01-28 16:58:41 +00:00
Tim Peters 82ca59e002 save_dict(): Added a comment about the control flow NealN missed. 2003-01-28 16:47:59 +00:00
Tim Peters 13a25fb8e6 _is_string_secure(): This method is no longer used; removed it. (It
was used before string-escape codecs were added to the core.)
2003-01-28 16:42:22 +00:00
Guido van Rossum bc64e22ed6 Made save() fit on a page, while adding comments. (I moved some type
checks to save_reduce(), which can also be called from a subclass.)

Also tweaked some more comments.
2003-01-28 16:34:19 +00:00
Tim Peters ad5a771fae Got rid of the _quotes global. Used only once, and is trivial. 2003-01-28 16:23:33 +00:00
Tim Peters 55762f5f80 Use raw-mode docstring whenever there's an escape code in an example --
they're easier to read this way.
2003-01-28 16:01:25 +00:00
Guido van Rossum 03e35327f2 _dis_test should be a raw string now that it contains \x escapes. 2003-01-28 15:37:13 +00:00
Tim Peters d0f7c86a20 dis(): Not all opcodes are printable anymore, so print the repr
of the opcode character instead (but stripping the quotes).

Added a proto 2 test section for the canonical recursive-tuple case.
Note that since pickle's save_tuple() takes different paths depending on
tuple length now, beefier tests are really needed (but not in pickletools);
the "short tuple" case tried here was actually broken yesterday, and it's
subtle stuff so needs to be tested.
2003-01-28 15:27:57 +00:00
Guido van Rossum 1be3175992 Add a few comments. Change the way the protocol is checked (it must
be one of 0, 1 or 2).

I should note that the previous checkin also added NEWOBJ support to
the unpickler -- but there's nothing yet that generates this.
2003-01-28 15:19:53 +00:00
Guido van Rossum 3a41c61dd4 Rename all variables 'object' to 'obj' to avoid conflicts with the
type 'object'.  Also minor docstring tweakage, and rearranged a few
lines in save().
2003-01-28 15:10:22 +00:00
Guido van Rossum 570283584a Fix one disassembly output now that empty tuples are no longer
memoized in text mode.  Fixed some variable names in the disassembler
doctest.
2003-01-28 15:09:10 +00:00