Commit Graph

7593 Commits

Author SHA1 Message Date
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
Guido van Rossum cbe2dbddda Don't memoize the empty tuple in protocol 0. 2003-01-28 14:40:16 +00:00
Tim Peters d97da80dd5 save_tuple(): So long as the charter is rewriting for clarity, the snaky
control flow had to be simplified.
2003-01-28 05:48:29 +00:00
Tim Peters ff57bff16e save_tuple(): I believe the new code for TUPLE{1,2,3} in proto 2 was
incorrect for recursive tuples.  Tried to repair; seems to work OK, but
there are no checked-in tests for this yet.
2003-01-28 05:34:53 +00:00
Tim Peters 81098ac1c8 Comments. 2003-01-28 05:12:08 +00:00
Tim Peters fdc03462b3 Now that proto2 is defined, replaced XXX blocks with text about it.
Also moved the proto2 opcode descriptors into the sections they fit (like
TUPLE{1,2,3} in the group of tuple-building opcodes; etc).
2003-01-28 04:56:33 +00:00
Guido van Rossum 7d97d31a1b OK, this is really the last one tonight!
NEWFALSE and NEWTRUE.
2003-01-28 04:25:27 +00:00
Guido van Rossum 025bc2fe6c Shouldn't test short tuples with all items equal -- one potential bug
would be that the tuple is reversed on unpickling, and we should catch
that. :-)

Goodnight -- that's it for toniht!
2003-01-28 04:20:02 +00:00
Guido van Rossum 44f0ea5f73 More protocol 2: TUPLE1, TUPLE2, TUPLE3.
Also moved the special case for empty tuples from save() to save_tuple().
2003-01-28 04:14:51 +00:00
Guido van Rossum 9d32bb1708 Rename 'bin' arg to 'proto'. Keep the default at 0 lest the tests
change in meaning.
2003-01-28 03:51:53 +00:00
Tim Peters 3b769835ca save_inst(): Rewrote to have only one branch on self.bin. Also got rid
of my recent XXX comment, taking a (what appears to be vanishingly small)
chance and calling self.memoize() instead.
2003-01-28 03:51:36 +00:00
Guido van Rossum d6c9e63af9 First baby steps towards implementing protocol 2: PROTO, LONG1 and LONG4. 2003-01-28 03:49:52 +00:00
Tim Peters d95c2df3a9 Fixed odd whitespace after "if", which I believe I introduced long ago. 2003-01-28 03:41:54 +00:00
Tim Peters 8fda7bc48d save_int(): Fixed two new off-by-1 glitches. 2003-01-28 03:40:52 +00:00
Guido van Rossum e0b904232f Add a comment explaining that struct.pack() beats marshal.dumps(), but
marshal.loads() beats struct.unpack()!  Possibly because the latter
creates a one-tuple. :-(
2003-01-28 03:17:21 +00:00
Guido van Rossum 5c938d00a1 Got rid of mdumps; I timed it, and struct.pack("<i", x) is more than
40% faster than marshal.dumps(x)[1:]!  (That's not counting the
module attribute lookups, which can be avoided in either case.)
2003-01-28 03:03:08 +00:00
Tim Peters f558da0f90 save_tuple(): Minor rewriting, and added a comment about the subtlety
created by recursive tuples.
2003-01-28 02:09:55 +00:00
Tim Peters 209ad95b00 load_appends(): replaced .append() loop with an .extend(). 2003-01-28 01:44:45 +00:00
Tim Peters c23d18a955 Comments. 2003-01-28 01:41:51 +00:00
Tim Peters 064567e41a save_dict(): Untangled most of the bin-vs-not-bin logic. Also used
iteritems() instead of materializing a (possibly giant) list of the
items.
2003-01-28 01:34:43 +00:00
Tim Peters 21c18f0bf5 save_list(): Rewrote, to untangle the proto 0 from the proto 1 cases.
The code is much easier to follow now, and I bet it's faster too.
2003-01-28 01:15:46 +00:00
Tim Peters 22dc6f4f7a save_list(): removed unused local "d". 2003-01-28 01:07:48 +00:00
Tim Peters 58d7846e68 save_list(): removed unused local "memo". 2003-01-28 01:07:10 +00:00
Tim Peters bd1cdb9227 save_pers(): Switched the order of cases, to get rid of a "not", and to
make the bin-vs-not-bin order consistent with what other routines try to
do (they almost all handle the bin case first).
2003-01-28 01:03:10 +00:00
Tim Peters 518df0dae4 Several routines appeared to inline the guts of memoize(), possibly for
some notion of low-level efficiency.  Undid that, but left one routine
alone:  save_inst() claims it has a reason for not using memoize().
I don't understand that comment, so added an XXX comment there.
2003-01-28 01:00:38 +00:00
Tim Peters b32a8317d7 save(): Fiddled the control flow to put the normal case where it
belongs.  This is a much smaller change than it may appear:  the bulk
of the function merely got unindented by one level.
2003-01-28 00:48:09 +00:00
Tim Peters c9d7c4a656 Added XXX about save()'s special-casing of tuples -- I don't get it. 2003-01-28 00:43:26 +00:00
Tim Peters 22987e3cbd save_bool(): simplified. 2003-01-28 00:26:14 +00:00
Tim Peters cbd0a32d09 Repaired grammar in new comment. 2003-01-28 00:24:43 +00:00