Commit Graph

3340 Commits

Author SHA1 Message Date
Skip Montanaro c797ceb545 add open function to bsddb185 module so the file format sniffing can be
restricted to the whichdb module
2003-05-06 20:38:52 +00:00
Martin v. Löwis e941617671 Patch #724588: Check whether the address of hstrerror and inet_pton can
be taken, and define NI_MAX{HOST|SERV} if necessary.
2003-05-03 10:12:45 +00:00
Martin v. Löwis dd6cd65b98 Implement tcl object __cmp__. 2003-05-03 09:45:12 +00:00
Martin v. Löwis c16f3bd8a3 Patch #708495: Port more stuff to OpenVMS. 2003-05-03 09:14:54 +00:00
Raymond Hettinger 7c2bb5bc57 * Added a substantial number of edge case and argument tests for
the itertoolsmodule.
* Taught itertools.repeat(obj, n) to treat negative repeat counts as
  zero.  This behavior matches that for sequences and prevents
  infinite loops.
2003-05-03 05:59:48 +00:00
Raymond Hettinger 341deb74e7 The previous made the stop argument optional.
It is better to be explicit and just allow stop to be None.
2003-05-02 19:44:20 +00:00
Raymond Hettinger 14ef54cd83 SF bug #730685: itertools.islice stop argument is not optional
* itertools.islice() stop argument did not perform as documented.
* beefed-up test suite
2003-05-02 19:04:37 +00:00
Tim Peters e2df5ffa53 SF patch 731504: Typo in datetimemodule.c comment.
s/isofomat/isoformat/, by Steven Taschuk.
2003-05-02 18:39:55 +00:00
Anthony Baxter 0e85f9d6fd Patch 731209: Restore socketmodule's behaviour with dotted quad addresses
to that of Python2.1. Such nnn.nnn.nnn.nnn addresses are just used directly,
not passed to the resolver for a pointless lookup.
2003-05-02 15:40:46 +00:00
Martin v. Löwis 1869ec5cb7 Convert tcl objects to strings in getvar/setvar. Fixes #730506. 2003-05-01 05:47:00 +00:00
Martin v. Löwis fccac2e61a Patch #725942: Always rename emulation functions. 2003-05-01 05:20:46 +00:00
Andrew M. Kuchling c24fe36c57 Allow _sre.c to compile with Python 2.2 2003-04-30 13:09:08 +00:00
Guido van Rossum 24ccca1565 When an unhandled exception happens, report the repr() of the function
that was used to start the thread.  This is useful to track down the
source of the problem when there is no traceback, as can happen when a
daemon thread gets to run after Python is finialized (a new kind of
event, somehow this is now possible due to changes in Py_Finalize()).
2003-04-29 19:44:05 +00:00
Gustavo Niemeyer 572f5233f0 Applying patch #728656, by logistix, fixing opening of nonexistent
bz2 files. Also, included a testcase for this problem.
2003-04-29 14:53:08 +00:00
Gustavo Niemeyer caf1c9dfe7 - Included detailed documentation in _sre.c explaining how, when, and why
to use LASTMARK_SAVE()/LASTMARK_RESTORE(), based on the discussion
  in patch #712900.

- Cleaned up LASTMARK_SAVE()/LASTMARK_RESTORE() usage, based on the
  established rules.

- Moved the upper part of the just commited patch (relative to bug #725106)
  to outside the for() loop of BRANCH OP. There's no need to mark_save()
  in every loop iteration.
2003-04-27 14:42:54 +00:00
Gustavo Niemeyer 3646ab98af Fix for part of the problem mentioned in #725149 by Greg Chapman.
This problem is related to a wrong behavior from mark_save/restore(),
which don't restore the mark_stack_base before restoring the marks.
Greg's suggestion was to change the asserts, which happen to be
the only recursive ops that can continue the loop, but the problem would
happen to any operation with the same behavior. So, rather than
hardcoding this into asserts, I have changed mark_save/restore() to
always restore the stackbase before restoring the marks.

Both solutions should fix these two cases, presented by Greg:

>>> re.match('(a)(?:(?=(b)*)c)*', 'abb').groups()
('b', None)
>>> re.match('(a)((?!(b)*))*', 'abb').groups()
('b', None, None)

The rest of the bug and patch in #725149 must be discussed further.
2003-04-27 13:25:21 +00:00
Gustavo Niemeyer c34f2555bd Applied patch #725106, by Greg Chapman, fixing capturing groups
within repeats of alternatives. The only change to the original
patch was to convert the tests to the new test_re.py file.

This patch fixes cases like:

>>> re.match('((a)|b)*', 'abc').groups()
('b', '')

Which is wrong (it's impossible to match the empty string),
and incompatible with other regex systems, like the following
examples show:

% perl -e '"abc" =~ /^((a)|b)*/; print "$1 $2\n";'
b a

% echo "abc" | sed -r -e "s/^((a)|b)*/\1 \2|/"
b a|c
2003-04-27 12:34:14 +00:00
Gustavo Niemeyer c23fb77477 Applying patch #726869 by Andrew I MacIntyre, reducing in _sre.c the
recursion limit for certain setups of FreeBSD and OS/2.
2003-04-27 06:58:54 +00:00
Gustavo Niemeyer 7628f1ffff Applying patch by Neal Norwitz:
[#727759] get bzip2 to build on Solaris 8 (old bzip library)
2003-04-27 06:25:24 +00:00
Guido van Rossum 47dfa4a89a Patch by Jp Calderone:
- The socket module now provides the functions inet_pton and inet_ntop
  for converting between string and packed representation of IP addresses.
  See SF patch #658327.

This still needs a bit of work in the doc area, because it is not
available on all platforms (especially not on Windows).
2003-04-25 05:48:32 +00:00
Thomas Heller 3457e4bd80 New support functions for test_getargs2.
Theres now a separate function for each of the format codes
b, B, H, I, k, i, l, L, K.
2003-04-24 16:14:27 +00:00
Raymond Hettinger 352f9477da SF patch 695710: fix bug 678519: cStringIO self iterator
(requested by GvR. patch contributed by Michael Stone)
2003-04-24 15:50:11 +00:00
Barry Warsaw c74e4a5351 Added a comment about backward compatibility requirements and a link
to the PyBSDDB project at SourceForge.
2003-04-24 14:28:08 +00:00
Andrew M. Kuchling 360088f206 [Patch #679505] Trigger DeprecationWarning on importing the rotor module 2003-04-24 13:17:13 +00:00
Raymond Hettinger 84fc9aa6ce SF 686323: Minor array module enhancements
Allows use of tuples for the initializer.
2003-04-24 10:41:55 +00:00
Raymond Hettinger 88ba1e39ec SF Patch 685051: fix for 680789: reprs in arraymodule
(contributed by logistix; substantially reworked by rhettinger).

To create a representation of non-string arrays, array_repr() was
starting with a base Python string object and repeatedly using +=
to concatenate the representation of individual objects.

Logistix had the idea to convert to an intermediate tuple form and
then join it all at once.  I took advantage of existing tools and
formed a list with array_tolist() and got its representation through
PyObject_Repr(v) which already has a fast implementation for lists.
2003-04-23 17:27:00 +00:00
Tim Peters 11b2306960 Enable os.fsync() for Windows, mapping it to MS's _commit() there. The
docs here are best-guess:  the MS docs I could find weren't clear, and
some even claimed _commit() has no effect on Win32 systems (which is
easily shown to be false just by trying it).
2003-04-23 02:39:17 +00:00
Raymond Hettinger 9a9c436036 PyObject_IsTrue() can return an error condition.
Adding code to handle it properly.
2003-04-23 00:14:18 +00:00
Mark Hammond a69d409f05 Update to the new PyGILState APIs to simplify and correct thread-state
management.  Old code still #ifdef'd out - I may remove this in a sec,
but for now, let's get it in and things passing the tests again!
2003-04-22 23:13:27 +00:00
Gustavo Niemeyer 3c9068bbec Made MAX_UNTIL/MIN_UNTIL code more coherent about mark protection,
accordingly to further discussions with Greg Chapman in patch #712900.
2003-04-22 15:39:09 +00:00
Neal Norwitz 699cbb7676 Get test_capi & test_getargs2 to pass on alphas
* UINT_MAX -> ULONG_MAX since we are dealing with longs
  * ParseTuple needs &int for 'i' and &long for 'l'
    There may be a better way to do this, but this works.
2003-04-22 01:28:57 +00:00
Andrew MacIntyre baf25b06a6 apply Mark Hammond's PEP 311 changes to the EMX ripoff of the Windows
popen[234]() code
2003-04-21 14:22:36 +00:00
Andrew MacIntyre 75e0145bb5 - DosSetExtLIBPATH objects to a NULL pointer, but a pointer to a NULL
string does what is expected (ie unset [BEGIN|END]LIBPATH)

- set the size of the DosQuerySysInfo buffer correctly; it was safe,
  but incorrect (allowing a 1 element overrun)
2003-04-21 14:19:51 +00:00
Gustavo Niemeyer be733ee7fb More work on bug #672491 and patch #712900.
I've applied a modified version of Greg Chapman's patch. I've included
the fixes without introducing the reorganization mentioned, for the sake
of stability. Also, the second fix mentioned in the patch don't fix the
mentioned problem anymore, because of the change introduced by patch
#720991 (by Greg as well). The new fix wasn't complicated though, and is
included as well.

As a note. It seems that there are other places that require the
"protection" of LASTMARK_SAVE()/LASTMARK_RESTORE(), and are just waiting
for someone to find how to break them. Particularly, I belive that every
recursion of SRE_MATCH() should be protected by these macros. I won't
do that right now since I'm not completely sure about this, and we don't
have much time for testing until the next release.
2003-04-20 07:35:44 +00:00
Gustavo Niemeyer 1aca359e89 - Fixed bug #672491. This change restores the behavior of lastindex/lastgroup
to be compliant with previous python versions, by backing out the changes
  made in revision 2.84 which affected this. The bugfix for backtracking is
  still maintained.
2003-04-20 00:45:13 +00:00
Mark Hammond 8d98d2cb95 New PyGILState_ API - implements pep 311, from patch 684256. 2003-04-19 15:41:53 +00:00
Martin v. Löwis 78e2f06cc6 Fully support 32-bit codes. Enable BIGCHARSET in UCS-4 builds. 2003-04-19 12:56:08 +00:00
Martin v. Löwis 2548c730c1 Implement IDNA (Internationalized Domain Names in Applications). 2003-04-18 10:39:54 +00:00
Thomas Heller a4ea603b05 SF # 595026: support for masks in getargs.c.
New functions:
  unsigned long PyInt_AsUnsignedLongMask(PyObject *);
  unsigned PY_LONG_LONG) PyInt_AsUnsignedLongLongMask(PyObject *);
  unsigned long PyLong_AsUnsignedLongMask(PyObject *);
  unsigned PY_LONG_LONG) PyLong_AsUnsignedLongLongMask(PyObject *);

New and changed format codes:

b unsigned char 0..UCHAR_MAX
B unsigned char none **
h unsigned short 0..USHRT_MAX
H unsigned short none **
i int INT_MIN..INT_MAX
I * unsigned int 0..UINT_MAX
l long LONG_MIN..LONG_MAX
k * unsigned long none
L long long LLONG_MIN..LLONG_MAX
K * unsigned long long none

Notes:

* New format codes.

** Changed from previous "range-and-a-half" to "none"; the
range-and-a-half checking wasn't particularly useful.

New test test_getargs2.py, to verify all this.
2003-04-17 18:55:45 +00:00
Guido van Rossum e13ddc9ec8 - New C API PyGC_Collect(), same as calling gc.collect().
- Call this in Py_Finalize().
- Expand the Misc/NEWS text on PY_LONG_LONG.
2003-04-17 17:29:22 +00:00
Martin v. Löwis 6f29ff319b Support UCS-4 Tcl for UCS-4 Python builds. Fixes #719880. 2003-04-16 20:34:55 +00:00
Raymond Hettinger 954bcf5fe0 Minor source formatting fixes. 2003-04-16 18:40:04 +00:00
Martin v. Löwis ee24e9cad0 Use object interface for global vars. Fixes #721171.
Also move complete processing of get/set/delvar calls to target thread.
2003-04-15 20:33:20 +00:00
Guido van Rossum 8b7a9a38c6 The date class is now properly subclassable. (SF bug #720908)
(This is only the tip of the iceberg; the time and datetime classes
need the same treatment.)
2003-04-14 22:01:58 +00:00
Guido van Rossum 41c99e7f96 SF patch #720991 by Gary Herron:
A small fix for bug #545855 and Greg Chapman's
addition of op code SRE_OP_MIN_REPEAT_ONE for
eliminating recursion on simple uses of pattern '*?' on a
long string.
2003-04-14 17:59:34 +00:00
Andrew M. Kuchling dff694bb9d Fix docstring typo 2003-04-14 15:31:27 +00:00
Jeremy Hylton 42a8aedb29 Make readers and writers participate in garbage collection.
Fix memory leak in dialect_init().
2003-04-14 02:20:55 +00:00
Tim Peters 38fc837fa9 Must declare vrbls at the tops of blocks in C89 (wouldn't compile). 2003-04-13 03:25:15 +00:00
Skip Montanaro 7b01a83488 use PyModule_Add{Int,String}Constant() where appropriate
(thanks to Neal Norwitz for the code review, BTW)
2003-04-12 19:23:46 +00:00
Skip Montanaro 577c7a763d tighten up string checks
make csv_{get,unregister}_dialect METH_O functions to avoid PyArg_ParseTuple
2003-04-12 19:17:14 +00:00
Skip Montanaro 860fc0b1d5 add writerows docstring
conditionally exclude Unicode functions
2003-04-12 18:57:52 +00:00
Skip Montanaro 98f16e0074 typo 2003-04-11 23:10:13 +00:00
Skip Montanaro dfa35fa3b6 typo 2003-04-11 21:40:01 +00:00
Skip Montanaro 3bc093b717 zap commented out bit of code 2003-04-11 19:33:55 +00:00
Raymond Hettinger 502168a86e SF patch #718867: Fix reference leak for time.strptime
(contributed by Brett Cannon)
2003-04-10 16:03:22 +00:00
Jeremy Hylton 7b5ce7f25a Make Unpickler objects colletable.
Bugfix candidate.
2003-04-09 21:25:30 +00:00
Jeremy Hylton 4cf6319cd2 Make Picklers collectable.
Bug fix candidate.
2003-04-09 21:05:12 +00:00
Guido van Rossum 69c2b88392 Fix two crashes on Windows:
- CHECK_VALID() was checking the wrong value for a closed fd
- fseek(&_iob[fileno], ...) doesn't work for fileno >= 20
2003-04-09 19:31:02 +00:00
Guido van Rossum fc29646a2e Don't use (PyObject *)PyObject_Type(x). It is a leaky and verbose way
of saying x->ob_type.
2003-04-09 17:53:22 +00:00
Just van Rossum 547eb42d75 tentative fix for #712322: modification time stamp checking failed
when DST began.
2003-04-08 20:07:15 +00:00
Tim Peters 730f5535ba s/referrents/referents/g. Gotta love that referrers remains rife with rs. 2003-04-08 17:17:17 +00:00
Tim Peters 0f81ab6d88 Finished implementing gc.get_referrents(): dealt with error and end
cases, wrote docs, added a test.
2003-04-08 16:39:48 +00:00
Tim Peters fb2ab4d5ae Comment repair; no semantic changes. 2003-04-07 22:41:24 +00:00
Tim Peters f6b8045ca5 Reworked has_finalizer() to use the new _PyObject_Lookup() instead
of PyObject_HasAttr(); the former promises never to execute
arbitrary Python code.  Undid many of the changes recently made to
worm around the worst consequences of that PyObject_HasAttr() could
execute arbitrary Python code.

Compatibility is hard to discuss, because the dangerous cases are
so perverse, and much of this appears to rely on implementation
accidents.

To start with, using hasattr() to check for __del__ wasn't only
dangerous, in some cases it was wrong:  if an instance of an old-
style class didn't have "__del__" in its instance dict or in any
base class dict, but a getattr hook said __del__ existed, then
hasattr() said "yes, this object has a __del__".  But
instance_dealloc() ignores the possibility of getattr hooks when
looking for a __del__, so while object.__del__ succeeds, no
__del__ method is called when the object is deleted.  gc was
therefore incorrect in believing that the object had a finalizer.

The new method doesn't suffer that problem (like instance_dealloc(),
_PyObject_Lookup() doesn't believe __del__ exists in that case), but
does suffer a somewhat opposite-- and even more obscure --oddity:
if an instance of an old-style class doesn't have "__del__" in its
instance dict, and a base class does have "__del__" in its dict,
and the first base class with a "__del__" associates it with a
descriptor (an object with a __get__ method), *and* if that
descriptor raises an exception when __get__ is called, then
(a) the current method believes the instance does have a __del__,
but (b) hasattr() does not believe the instance has a __del__.

While these disagree, I believe the new method is "more correct":
because the descriptor *will* be called when the object is
destructed, it can execute arbitrary Python code at the time the
object is destructed, and that's really what gc means by "has a
finalizer":  not specifically a __del__ method, but more generally
the possibility of executing arbitrary Python code at object
destruction time.  Code in a descriptor's __get__() executed at
destruction time can be just as problematic as code in a
__del__() executed then.

So I believe the new method is better on all counts.

Bugfix candidate, but it's unclear to me how all this differs in
the 2.2 branch (e.g., new-style and old-style classes already
took different gc paths in 2.3 before this last round of patches,
but don't in the 2.2 branch).
2003-04-07 19:21:15 +00:00
Tim Peters 1155887a74 initgc(): Rewrote to use the PyModule_AddXYZ API; cuts code size. 2003-04-06 23:30:52 +00:00
Tim Peters 259272b7a0 handle_finalizers(): Rewrote to call append_objects() and gc_list_merge()
instead of looping.  Smaller and clearer.  Faster, too, when we're not
appending to gc.garbage:  gc_list_merge() takes constant time, regardless
of the lists' sizes.

append_objects():  Moved up to live with the other list manipulation
utilities.
2003-04-06 19:41:39 +00:00
Tim Peters 50c61d5a6c Switched from METH_VARARGS to METH_NOARGS for the 7 module functions that
take no arguments; cuts generated code size.
2003-04-06 01:50:50 +00:00
Tim Peters bf384c256e Reworked move_finalizer_reachable() to create two distinct lists:
externally unreachable objects with finalizers, and externally unreachable
objects without finalizers reachable from such objects.  This allows us
to call has_finalizer() at most once per object, and so limit the pain of
nasty getattr hooks.  This fixes the failing "boom 2" example Jeremy
posted (a non-printing variant of which is now part of test_gc), via never
triggering the nasty part of its __getattr__ method.
2003-04-06 00:11:39 +00:00
Tim Peters f6ae7a43eb move_finalizers(): Rewrote. It's not necessary for this routine
to special-case classic classes, or to worry about refcounts;
has_finalizer() deleted the current object iff the first entry in
the unreachable list has changed.  I don't believe it was correct
to check for ob_refcnt == 1, either:  the dealloc routine would get
called by Py_DECREF then, but there's nothing to stop the dealloc
routine from ressurecting the object, and then gc would remain at
the head of the unreachable list despite that its refcount temporarily
fell to 0 (and that would lead to an infinite loop in move_finalizers()).

I'm still worried about has_finalizer() resurrecting other objects
in the unreachable list:  what's to stop them from getting collected?
2003-04-05 18:40:50 +00:00
Tim Peters 86b993b6cf New comments. Rewrote has_finalizer() as a sequence of ifs instead of
squashed-together conditional operators; makes it much easier to step
thru in the debugger, and to set a breakpoint on the only dangerous
path.
2003-04-05 17:35:54 +00:00
Tim Peters 93ad66dea9 Fixed new seemingly random segfaults, by moving the initialization of
delstr from initgc() into collect().  initgc() isn't called unless the
user explicitly imports gc, so can be used only for initialization of
user-visible module features; delstr needs to be initialized for proper
internal operation, whether or not gc is explicitly imported.

Bugfix candidate?  I don't know whether the new bug was backported to
2.2 already.
2003-04-05 17:15:44 +00:00
Jeremy Hylton ce136e985a Fix Tim's boom example.
move_finalizers() moves every object from unreachable to collectable
or finalizers, unless the object is deallocated first.
2003-04-04 19:59:06 +00:00
Greg Ward 76ffb1918d Use fcntl() to put the audio device *back* into blocking mode after
opening it in non-blocking mode.  Both Guido and David Hammerton have
reported that this fixes their problems with ossaudiodev -- hooray!
2003-04-04 01:47:42 +00:00
Jeremy Hylton 059b094e29 Add get_referrents() helper function. 2003-04-03 16:29:13 +00:00
Jeremy Hylton 5bd378bfca Add get_referrents() helper function. 2003-04-03 16:28:38 +00:00
Martin v. Löwis 7fb697b5d2 Revert Patch #670715: iconv support. 2003-04-03 04:49:12 +00:00
Barry Warsaw 1baa982c31 init_bsddb(): Added a few symbols that Greg forgot. 2003-03-31 19:51:29 +00:00
Neal Norwitz ddb4f62650 SF patch #667548, Add some audio constants by Michael Pruett
Also remove a few unused variables.  Built on IRIX 6.5.
2003-03-30 21:49:18 +00:00
Neal Norwitz 1ac3e39913 Get build working with pre-C99 compilers 2003-03-30 20:51:29 +00:00
Martin v. Löwis f26d63b3e1 Patch #650412: Check whether the address of flock and getpagesize
can be taken, and use _SC_PAGE_SIZE if getpagesize is not available.
2003-03-30 17:23:49 +00:00
Martin v. Löwis 852ba7eb2a Patch #672053: Return a result from Py_Main, instead of exiting. 2003-03-30 17:09:58 +00:00
Martin v. Löwis e98922fb80 Patch #695250: Suppress COPYRIGHT if site.py is not read. Fixes #672614.
Will backport to 2.2.
2003-03-30 17:00:39 +00:00
Martin v. Löwis a965649386 Wrap thread stuff in WITH_THREAD. Fixes #704641. 2003-03-30 08:44:58 +00:00
Martin v. Löwis 52ae6f67d9 Fake bool API for Python 2.2. 2003-03-30 08:26:04 +00:00
Martin v. Löwis b9a0f91218 Rename LONG_LONG to PY_LONG_LONG. Fixes #710285. 2003-03-29 10:06:18 +00:00
Gregory P. Smith 6e5c1792d9 4.1.5 2003-03-27 17:25:10 +00:00
Gregory P. Smith fe11d3e0d4 Adds support for the DBEnv->set_timeout() method. 2003-03-27 17:23:29 +00:00
Skip Montanaro a16b21fb0a add comment about 2.2 compatibility
dump empty TODO comment
2003-03-23 14:32:54 +00:00
Neal Norwitz 29fd2baf82 Make private function and data static. 2003-03-23 13:21:03 +00:00
Neal Norwitz 2deaddb0d6 Get rid of warning on IRIX 2003-03-21 03:08:31 +00:00
Neal Norwitz b59798b157 Add support for os.openpty() on AIX which uses /dev/ptc instead of /dev/ptmx. 2003-03-21 01:43:31 +00:00
Tim Peters ef4b7ed42b Squash compiler wng about signed-vs-unsigned mismatch. 2003-03-21 01:35:28 +00:00
Skip Montanaro 2497982bbb add _csv build line 2003-03-20 23:37:24 +00:00
Skip Montanaro b4a0417e91 new CSV file processing module - see PEP 305 2003-03-20 23:29:12 +00:00
Tim Peters 9905b943f7 New private API functions _PyFloat_{Pack,Unpack}(4,8}. This is a
refactoring to get all the duplicates of this delicate code out of the
cPickle and struct modules.
2003-03-20 20:53:32 +00:00
Tim Peters d50ade68ec SF bug 705836: struct.pack of floats in non-native endian order
pack_float, pack_double, save_float:  All the routines for creating
IEEE-format packed representations of floats and doubles simply ignored
that rounding can (in rare cases) propagate out of a long string of
1 bits.  At worst, the end-off carry can (by mistake) interfere with
the exponent value, and then unpacking yields a result wrong by a factor
of 2.  In less severe cases, it can end up losing more low-order bits
than intended, or fail to catch overflow *caused* by rounding.

Bugfix candidate, but I already backported this to 2.2.

In 2.3, this code remains in severe need of refactoring.
2003-03-20 18:32:13 +00:00
Raymond Hettinger 1da1dbf458 Renamed PyObject_GenericGetIter to PyObject_SelfIter
to more accurately describe what the function does.

Suggested by Thomas Wouters.
2003-03-17 19:46:11 +00:00
Jack Jansen 7b59b42a38 Added a define EXTRAMACHDEPPATH which can be used to add sys.path items
for specific platforms. Use this to add plat-mac and
plat-mac/lib-scriptpackages on MacOSX. Also tested for not having adverse
effects on Linux, and I think this code isn't used on Windows anyway.

Fixes #661521.
2003-03-17 15:44:10 +00:00
Thomas Wouters 9e1c192525 binascii_a2b_base64: Properly return an empty string if the input was all
invalid, rather than returning a string of random garbage of the
    estimated result length. Closes SF patch #703471 by Hye-Shik Chang.

Will backport to 2.2-maint (consider it done.)
2003-03-17 11:24:29 +00:00
Raymond Hettinger e0cce8f8f0 Created PyObject_GenericGetIter().
Factors out the common case of returning self.
2003-03-17 08:35:49 +00:00
Raymond Hettinger 0153826964 Created PyObject_GenericGetIter().
Factors out the common case of returning self.
2003-03-17 08:24:35 +00:00
Guido van Rossum d11b62edd0 - New function time.tzset() provides access to the C library tzet()
function, if supported.  (SF patch #675422, by Stuart Bishop.)
2003-03-14 21:51:36 +00:00
Michael W. Hudson 43ed43bfc1 Take out my (long since disabled) POSIX signal mask handling code.
I'm not going to have the time or energy to get this working x-platform
-- anyone who does is welcome to the code!
2003-03-13 13:56:53 +00:00
Greg Ward 5c49ef2116 Open with O_NONBLOCK to avoid hanging on open(). 2003-03-11 16:53:13 +00:00
Greg Ward 0b6dfb808c <sys/soundcard.h> seems to exist on both Linux and FreeBSD, so include
it instead of the OS-specific <linux/soundcard.h> or <machine/soundcard.h>.

Mixers devices have an ioctl-only interface, no read/write -- so the
flags passed to open() don't really matter.  Thus, drop the 'mode'
parameter to openmixer() (ie. second arg to newossmixerobject()) and
always open mixers with O_RDWR.
2003-03-10 03:17:06 +00:00
Jack Jansen fbd861bbd3 An #endif was missing in Just's patch. Added. 2003-03-05 16:00:15 +00:00
Just van Rossum 2ac79ef9e3 removing one Mac hack and add another:
- The applet logic has been replaced to bundlebuilder's bootstrap script
- Due to Apple being extremely string about argv[0], we need a way to
  specify the actual executable name for use with sys.executable. See
  the comment embedded in the code.
2003-03-05 15:46:54 +00:00
Martin v. Löwis 73d538b9c6 Always initialize Py_FileSystemDefaultEncoding on Unix in Py_Initialize,
and not as a side effect of setlocale. Expose it as sys.getfilesystemencoding.
Adjust test case.
2003-03-05 15:13:47 +00:00
Martin v. Löwis 7a924e6eb2 Patch #696645: Remove VMS code with uncertain authorship. 2003-03-05 14:15:21 +00:00
Just van Rossum 6a42183967 os.listdir(): Fall back to the original byte string if conversion to unicode
fails, as discussed in patch #683592.
2003-03-04 19:30:44 +00:00
Neal Norwitz 12e2217501 Fix SF #692416, don't crash interpreter for _tkinter.deletefilehandler
in addition to createfilehandler and creaetetimerhandler.
2003-03-03 21:16:39 +00:00
Just van Rossum 2fe07fda2d plugged leak noted by nnorwitz: the 'et' format returns allocated memory 2003-03-03 19:07:13 +00:00
Just van Rossum 96b1c903f5 Patch #683592 revisited, after discussions with MvL:
- Implement the behavior as specified in PEP 277, meaning os.listdir()
  will only return unicode strings if it is _called_ with a unicode
  argument.
- And then return only unicode, don't attempt to convert to ASCII.
- Don't switch on Py_FileSystemDefaultEncoding, but simply use the
  default encoding if Py_FileSystemDefaultEncoding is NULL. This means
  os.listdir() can now raise UnicodeDecodeError if the default encoding
  can't represent the directory entry. (This seems better than silcencing
  the error and fall back to a byte string.)
- Attempted to decribe the above in Doc/lib/libos.tex.
- Reworded the Misc/NEWS items to reflect the current situation.

This checkin also fixes bug #696261, which was due to os.listdir() not
using Py_FileSystemDefaultEncoding, like all file system calls are
supposed to.
2003-03-03 17:32:15 +00:00
Michael W. Hudson f008998668 Fix bug
[ 555817 ] Flawed fcntl.ioctl implementation.

with my patch that allows for an array to be mutated when passed
as the buffer argument to ioctl() (details complicated by
backwards compatibility considerations -- read the docs!).
2003-03-03 12:29:42 +00:00
Martin v. Löwis 7f13489bdf Don't crash on _tkinter.createfilehandler in non-threaded Tcl;
disable this function in threaded Tcl. Likewise for creaetetimerhandler.
Fixes #692416.
2003-03-03 10:40:01 +00:00
Neal Norwitz d9efdc5b5a get_completer() takes no args 2003-03-01 15:19:41 +00:00
Raymond Hettinger d1a283be26 Several of the tools can make direct calls the inner iterators. 2003-03-01 01:48:24 +00:00
Neal Norwitz 3f5fcc8acc Fix SF bug #690012 (among others), iconv_codec stops build
Change setup.py to catch all exceptions.
  - Rename module if the exception was an ImportError
  - Only warn if the exception was any other error

Revert _iconv_codec to raising a RuntimeError.
2003-02-28 17:21:39 +00:00
Just van Rossum f4ecc751b1 use proper constant instead of comment (noted by nnorwitz) 2003-02-28 08:54:01 +00:00
Neal Norwitz e9c571f968 Fix SF bug #694816, remove comparison of unsigned value < 0 2003-02-28 03:14:37 +00:00
Just van Rossum 46c9784f68 Patch #683592: unicode support for os.listdir()
os.listdir() may now return unicode strings on platforms that set
Py_FileSystemDefaultEncoding.
2003-02-25 21:42:15 +00:00
Walter Dörwald dd8766a65b Change the test encoding from "ISO8859-1" to "ISO-8859-1"
(see SF bug #690309) and raise ImportErrors instead of
RuntimeErrors, so building Python continues even
if importing iconv_codecs fails.

This is a temporary fix until we get proper configure
support for "broken" iconv implementations.
2003-02-24 20:17:32 +00:00
Neal Norwitz 937ca98e34 SF patch #687598, array.append is sloooow
This improves speed by about 5.6% for me.
2003-02-24 02:08:42 +00:00
Raymond Hettinger 61fe64d5de User requested changes to the itertools module.
Subsumed times() into repeat().
Added cycle() and chain().
2003-02-23 04:40:07 +00:00
Walter Dörwald e9b851a5e9 Use 'ISO8859-1' instead of 'ASCII' when testing whether byteswapping
is required for the chosen internal encoding in the init function,
as this seems to have a better chance of working under Irix and
Solaris.

Also change the test character from '\x01' to '0'.

This might fix SF bug #690309.
2003-02-21 18:18:49 +00:00
Neal Norwitz c355f0cae9 flex_complete looks like a private (but callback) function, so make it static 2003-02-21 00:30:18 +00:00
Guido van Rossum b76bdf8ef7 The connect timeout code wasn't working on Windows.
Rather than trying to second-guess the various error returns
of a second connect(), use select() to determine whether the
socket becomes writable (which means connected).
2003-02-19 17:50:16 +00:00
Guido van Rossum 6297a7a9fb - PyEval_GetFrame() is now declared to return a PyFrameObject *
instead of a plain PyObject *.  (SF patch #686601 by Ben Laurie.)
2003-02-19 15:53:17 +00:00
Mark Hammond 05107b6af7 os.mkdir() would crash with a Unicode filename and mode param. 2003-02-19 04:08:27 +00:00
Guido van Rossum b289b87a37 Use __reduce_ex__. 2003-02-19 01:45:13 +00:00
Tim Peters b9ce7cd8b8 save_global(): Trying to resolve module.name can fail for two
reasons:  importing module can fail, or the attribute lookup
module.name can fail.  We were giving the same error msg for
both cases, making it needlessly hard to guess what went wrong.
These cases give different error msgs now.
2003-02-18 20:50:45 +00:00
Guido van Rossum 55dc26cbc7 Fold some long lines.
Change fatal errors during module initialization into RuntimeErrors.
2003-02-18 16:11:11 +00:00
Neal Norwitz 0c0aad948a Fix 64-bit problem, ParseTuple("i") needs C ints; ("l") needs C longs.
Use "l" as that *probably* makes more sense (at least to me it does :-)
And the test passes on the alpha.
2003-02-18 03:37:49 +00:00
Neal Norwitz e241ce830a Added test_posix (hopefully it works on Windows).
Remove PyArg_ParseTuple() for methods which take no args,
use METH_NOARGS instead
2003-02-17 18:17:05 +00:00
Neal Norwitz 5c1ba53f8c Use correct function name to PyArg_ParseTuple("is_package").
Fix off-by-1 error in normalize_line_endings():
  when *p == '\0' the NUL was copied into q and q was auto-incremented,
  the loop was broken out of,
  then a newline was appended followed by a NUL.
  So the function, in effect, was strcpy() but added two extra chars
  which was caught by obmalloc in debug mode, since there was only
  room for 1 additional newline.

Get test working under regrtest (added test_main).
2003-02-17 18:05:20 +00:00
Neal Norwitz 0ae4c4a823 Make 2 module variables static. Assuming this is correct. 2003-02-15 15:07:17 +00:00
Tim Peters 080c88b912 cPickle.c, load_build(): Taught cPickle how to pick apart
the optional proto 2 slot state.

pickle.py, load_build():  CAUTION:  Noted that cPickle's
load_build and pickle's load_build really don't do the same
things with the state, and didn't before this patch either.
cPickle never tries to do .update(), and has no backoff if
instance.__dict__ can't be retrieved.  There are no tests
that can tell the difference, and part of what cPickle's
load_build() did looked accidental to me, so I don't know
what the true intent is here.

pickletester.py, test_pickle.py:  Got rid of the hack for
exempting cPickle from running some of the proto 2 tests.

dictobject.c, PyDict_Next():  documented intended use.
2003-02-15 03:01:11 +00:00
Tim Peters 71fcda5ba7 cPickle produces NEWOBJ appropriately now. It still doesn't know
how to unpickle the new slot-full state tuples.
2003-02-14 23:05:28 +00:00
Tim Peters 92c8bb3abf Minor assorted cleanups; no semantic changes. 2003-02-13 23:00:26 +00:00
Tim Peters aae53d47d6 The version of PyImport_Import() in cPickle is no longer needed (an edited
version was moved into import.c long ago), so squashed the duplication.
2003-02-13 22:17:05 +00:00
Tim Peters 5aa3da6495 save(): Reformat tail end just for clarity. 2003-02-13 21:03:57 +00:00
Guido van Rossum 729765079e Another dummy type.
Curious: Str didn't need me to put something in tp_new, but Null did.
Why the difference?
2003-02-13 18:44:57 +00:00
Tim Peters eab7db3cee Taught cPickle how to read pickles containing NEWOBJ. This won't get
exercised by the test suite before cPickle knows how to create NEWOBJ
too.  For now, it was just tried once by hand (via loading a NEWOBJ
pickle created by pickle.py).
2003-02-13 18:24:14 +00:00
Tim Peters 8587b3c073 Added a HIGHEST_PROTOCOL module attribute to pickle and cPickle. 2003-02-13 15:44:41 +00:00
Andrew M. Kuchling fe62bc917d Conditionalize another constant 2003-02-13 13:27:07 +00:00
Tim Peters 1df9fdd4d5 socket_inet_aton(): ip_addr was left undefined before use in the
!HAVE_INET_ATON case.  Repaired that, and tried to repair what looked
like out-of-date comments.
2003-02-13 03:13:40 +00:00
Neal Norwitz 88f115b0d4 Ummm, try to get it right this time 2003-02-13 02:15:42 +00:00
Neal Norwitz 10b214c2fd Use configure to check for inet_aton. 2003-02-13 02:11:10 +00:00
Guido van Rossum ad05cdfa1f Addressing SF bug #643005, implement socket.inet_aton() using
inet_aton() rather than inet_addr() -- the latter is obsolete because
it has a problem: "255.255.255.255" is a valid address but
indistinguishable from an error.

(I'm not sure if inet_aton() exists everywhere -- in case it doesn't,
I've left the old code in with an #ifdef.)
2003-02-12 23:08:22 +00:00
Tim Peters 90975f1ff9 Minor cleanup of new batch-list/dict code. 2003-02-12 05:28:58 +00:00
Neal Norwitz ec74f2fda7 Add more missing PyErr_NoMemory() after failled memory allocs 2003-02-11 23:05:40 +00:00
Tim Peters 42f08ac1e3 Implemented batching for dicts in cPickle. This is after two failed
attempts to merge the C list-batch and dict-batch code -- they worked, but
it was a godawful mess to read.
2003-02-11 22:43:24 +00:00
Guido van Rossum 9eb67ea2af Add Str, a subclass of str. 2003-02-11 21:19:11 +00:00
Tim Peters 1092d64002 Implemented list batching in cPickle. 2003-02-11 21:06:20 +00:00
Gustavo Niemeyer a33d0aa693 Unparenting BZ2File, as discussed in SF patch #661796.
* Modules/bz2module.c
  (BZ2FileObject): Now the structure includes a pointer to a file object,
   instead of "inheriting" one. Also, some members were copied from the
   PyFileObject structure to avoid dealing with the internals of that
   structure from outside fileobject.c.

  (Util_GetLine,Util_DropReadAhead,Util_ReadAhead,Util_ReadAheadGetLineSkip,
   BZ2File_write,BZ2File_writelines,BZ2File_init,BZ2File_dealloc,
   BZ2Comp_dealloc,BZ2Decomp_dealloc):
   	These functions were adapted to the change above.

  (BZ2File_seek,BZ2File_close): Use PyObject_CallMethod instead of
   getting the function attribute locally.

  (BZ2File_notsup): Removed, since it's not necessary anymore to overload
   truncate(), and readinto() with dummy functions.

  (BZ2File_methods): Added xreadlines() as an alias to BZ2File_getiter,
   and removed truncate() and readinto().

  (BZ2File_get_newlines,BZ2File_get_closed,BZ2File_get_mode,BZ2File_get_name,
   BZ2File_getset):
   	Implemented getters for "newlines", "mode", and "name".

  (BZ2File_members): Implemented "softspace" member.

  (BZ2File_init): Reworked to create a file instance instead of initializing
   itself as a file subclass. Also, pass "name" object untouched to the
   file constructor, and use PyObject_CallFunction instead of building the
   argument tuple locally.

  (BZ2File_Type): Set tp_new to PyType_GenericNew, tp_members to
   BZ2File_members, and tp_getset to BZ2File_getset.

  (initbz2): Do not set BZ2File_Type.tp_base nor BZ2File_Type.tp_new.


* Doc/lib/libbz2.tex
  Do not mention that BZ2File inherits from the file type.
2003-02-11 18:46:20 +00:00
Tim Peters 5f322d3dfd SF bug 684667: Modules/selectmodule.c returns NULL without exception set.
select_select() didn't set an exception in the SELECT_USES_HEAP case when
malloc() returned NULL.
2003-02-11 17:18:58 +00:00
Jason Tishler 0c10015a6e Patch #676839: Cygwin _iconv_codec module patch
The attached patch enables the _iconv_codec
module to build cleanly under Cygwin.
2003-02-10 20:48:35 +00:00
Jason Tishler 8437570ec2 Patch #676837: Cygwin array module patch
The attached patch enables the array module
to build cleanly under Cygwin again.
2003-02-10 20:45:47 +00:00
Neal Norwitz 4adc9abc32 Fix memory leak of newstr when putenv() fails 2003-02-10 03:10:43 +00:00
Neal Norwitz e4b5500e54 Remove duplicate code introduced by fixing bug #678518 2003-02-10 01:08:50 +00:00
Guido van Rossum d58f3fce3d Remove unused variable. 2003-02-09 17:19:18 +00:00
Raymond Hettinger 60eca9331a C Code:
* Removed the ifilter flag wart by splitting it into two simpler functions.
* Fixed comment tabbing in C code.
* Factored module start-up code into a loop.

Documentation:
* Re-wrote introduction.
* Addede examples for quantifiers.
* Simplified python equivalent for islice().
* Documented split of ifilter().

Sets.py:
* Replace old ifilter() usage with new.
2003-02-09 06:40:58 +00:00
Michael W. Hudson df1252dec9 Apply logistix's patch from
[ 678518 ] Another parsermodule validation error
2003-02-08 18:05:10 +00:00
Tim Peters aa7d849c7a timedelta comparison and datetime addition: as the Python implementation
of datetime does, accept instances of subclasses too.
2003-02-08 03:28:59 +00:00
Tim Peters 07534a607b Comparison for timedelta, time, date and datetime objects: __eq__ and
__ne__ no longer complain if they don't know how to compare to the other
thing.  If no meaningful way to compare is known, saying "not equal" is
sensible.  This allows things like

    if adatetime in some_sequence:
and
    somedict[adatetime] = whatever

to work as expected even if some_sequence contains non-datetime objects,
or somedict non-datetime keys, because they only call __eq__.

It still complains (raises TypeError) for mixed-type comparisons in
contexts that require a total ordering, such as list.sort(), use as a
key in a BTree-based data structure, and cmp().
2003-02-07 22:50:28 +00:00
Neal Norwitz 4d933fe392 SF patch #682514, mmapmodule.c write fix for LP64 executables
Make length an int so we get the right value from
PyArg_ParseTuple(args, "s#", &str, &length)

Will backport.
2003-02-07 19:44:56 +00:00
Raymond Hettinger f0c00241ae * Eliminated tuple re-use in imap(). Doing it correctly made the code
too hard to read.
* Simplified previous changes to izip() to make it easier to read.
2003-02-07 07:26:25 +00:00
Raymond Hettinger 2012f174ea SF bug #681003: itertools issues
* Fixed typo in exception message for times()
* Filled in missing times_traverse()
* Document reasons that imap() did not adopt a None fill-in feature
* Document that count(sys.maxint) will wrap-around on overflow
* Add overflow test to islice()
* Check that starmap()'s argument returns a tuple
* Verify that imap()'s tuple re-use is safe
* Make a similar tuple re-use (with safety check) for izip()
2003-02-07 05:32:58 +00:00
Fred Drake dab8b0ad99 Integrate the patch from expat.h 1.51; needed for some C compilers.
Closes SF bug #680797.
2003-02-07 02:15:56 +00:00
Tim Peters 6288e230d8 More typo repair. 2003-02-05 03:53:10 +00:00
Tim Peters 679201467b Typo repair. 2003-02-05 03:46:17 +00:00
Tim Peters 3e667d5452 cPickle: exempt two_tuple from GC -- it's a speed hack, and doesn't
guarantee to keep valid pointers in its slots.

tests:  Moved ExtensionSaver from test_copy_reg into pickletester, and
use it both places.  Once extension codes get assigned, it won't be
safe to overwrite them willy nilly in test suites, and ExtensionSaver
does a thorough job of undoing any possible damage.

Beefed up the EXT[124] tests a bit, to check the smallest and largest
codes in each opcode's range too.
2003-02-04 21:47:44 +00:00
Tim Peters 731098b3ff cPickle now generates proto 2 EXT[124] when appropriate.
Moved such EXT tests as currently exist from TempAbstractPickleTests to
AbstractPickleTests, so that test_cpickle runs them too.
2003-02-04 20:56:09 +00:00
Neal Norwitz 7fe16e79f5 Remove forward static reference since it is not required 2003-02-04 20:46:50 +00:00
Neal Norwitz ce3d34dde7 Whitespace normalization 2003-02-04 20:45:17 +00:00
Marc-André Lemburg 29273c87da Fix for [ 543344 ] Interpreter crashes when recoding; suggested
by Michael Stone (mbrierst).

Python 2.1.4, 2.2.2 candidate.
2003-02-04 19:35:03 +00:00
Walter Dörwald bda1c86daf Use size_t instead of int for various variables to prevent
signed/unsigned comparison warnings on the call to iconv().

Fix comment typos.

From SF patch #680146.
2003-02-04 18:02:28 +00:00
Tim Peters fa05ce3c1d Typo in comment. 2003-02-04 05:20:32 +00:00
Tim Peters 2d62965734 cPickle can load pickles using proto 2 EXT[124] now, but can't yet
generate these opcodes.
2003-02-04 05:06:17 +00:00
Guido van Rossum d4b920c8bd Rename the extension registry variables to have leading underscores --
this clarifies that they are part of an internal API (albeit shared
between pickle.py, copy_reg.py and cPickle.c).

I'd like to do the same for copy_reg.dispatch_table, but worry that it
might be used by existing code.  This risk doesn't exist for the
extension registry.
2003-02-04 01:54:49 +00:00
Tim Peters 0dd23aa539 Typo repair. 2003-02-04 00:30:46 +00:00
Tim Peters 5b7da39f23 Brought some module variables into synch with pickle.py's current values.
Imported the extension-registry dicts from copy_reg.py, in preparation for
tackling EXT[124].
2003-02-04 00:21:07 +00:00
Tim Peters 0c7c48e02c load_counted_long(): Changed a ValueError to an UnpicklingError, just
because it seems more consistent with the rest of the code.

cPickle_PyMapping_HasKey():  This extern function isn't used anywhere in
Python or Zope, so got rid of it.
2003-02-03 22:07:24 +00:00
Guido van Rossum 7d9ea5013f - Thanks to Scott David Daniels, a subtle bug in how the zlib
extension implemented flush() was fixed.  Scott also rewrite the
  zlib test suite using the unittest module.  (SF bug #640230 and
  patch #678531.)

Backport candidate I think.
2003-02-03 20:45:52 +00:00
Tim Peters e0a3907904 PDATA_PUSH and PDATA_APPEND. documented, and reformatted for better
readability.

load_bool():  Now that I know the intended difference between _PUSH and
_APPEND, used the right one.

Pdata_grow():  Squashed out a redundant overflow test.
2003-02-03 15:45:56 +00:00
Gregory P. Smith 3ed7b03224 version 4.1.4 (4.1.3 just released) 2003-02-03 04:28:26 +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
Tim Peters 0bc93f5c8b 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.
2003-02-02 18:29:33 +00:00
Tim Peters ac5687a515 Minor cleanup, mostly adding horizontal whitespace, and breaking apart
embedded assignments, for readability.
2003-02-02 18:08:34 +00:00
Tim Peters 3c67d795ef Implemented proto 2 NEWTRUE and NEWFALSE in cPickle. 2003-02-02 17:59:11 +00:00
Neal Norwitz d156c2d782 Get ossaudiodev to compile on freebsd 4.7 2003-02-02 17:59:06 +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
Neal Norwitz 529baf2b57 Fix compiler warning 2003-02-02 17:08:33 +00:00
Tim Peters 87482ea055 dump(): Added asserts that self->proto is sane. 2003-02-02 16:16:30 +00:00
Tim Peters 9b1e03ff4b 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).
2003-02-02 16:14:23 +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
Fred Drake 06dd8cf5e4 Fix memory leak: free memory storing the content model passed to the
ElementDeclHandler by Expat.
Fixes SF bug #676990.
2003-02-02 03:54:17 +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
Tim Peters 040e033796 Removed needless include of errno.h. 2003-02-01 06:30:12 +00:00
Tim Peters 64c04d1df3 The module docstring had an RCS ID from 1999 embedded in it. Enough
already <wink>.
2003-02-01 06:27:59 +00:00
Tim Peters cba30e2c96 Trimmed trailing whitespace. 2003-02-01 06:24:36 +00:00
Tim Peters 797ec24e87 Added #defines for proto 2 opcodes; gave the Pickler a proto member;
removed woefully inadequate opcode docs and pointed to pickletools.py
instead.
2003-02-01 06:22:36 +00:00
Tim Peters 70533e28ad 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).
2003-02-01 04:40:04 +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
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
Tim Peters 371935fc06 All over: changed comments to reflect pickling is straightforward now,
not the maze it was.
2003-02-01 01:52:50 +00:00
Tim Peters 8a60c2238b delta_setstate(): This waS no longer referenced, so nukeit.
delta_reduce():  Simplified.
2003-02-01 01:47:29 +00:00
Raymond Hettinger 96ef8115dd Move itertools module from the sandbox and into production. 2003-02-01 00:10:11 +00:00
Tim Peters 506be287aa 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.
2003-01-31 22:27:17 +00:00
Guido van Rossum 8e0ad0cb0b Ignore the state returned by __reduce__ if it is Py_None. 2003-01-31 21:10:31 +00:00
Guido van Rossum 8f24cdc0d5 SF patch #678257 by Geoff Talvola.
In sendall(), do an internal select before each send() call, instead
of only for the first one.
2003-01-31 18:15:58 +00:00
Guido van Rossum 4f707ac8b1 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.
2003-01-31 18:13:18 +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
Walter Dörwald 757246c189 Initialize swappedinput to silence the compiler warning about
uninitialized variables.
2003-01-31 16:26:50 +00:00
Tim Peters 5b8132ffa3 _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.
2003-01-31 15:52:05 +00:00
Tim Peters abc7cd27ff Backward branches are disgusting, at least when a forward branch
is just as easy.
2003-01-31 01:37:35 +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
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
Michael W. Hudson 0e986a312f I was in this module anyway, so I did some janitorial things.
METH_NOARGS functions are still called with two arguments, one NULL,
so put that back into the function definitions (I didn't know this
until recently).

Make get_history_length() METH_NOARGS.
2003-01-30 14:17:16 +00:00
Michael W. Hudson 796df156cd Add the get_completer() function based on Michael Stone's patch in
[ 676342 ] after using pdb readline does not work correctly

which is required to fix that bug.  So maaybe a bugfix candidate.
2003-01-30 10:12:51 +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
Tim Peters baefd9e552 Added new private API function _PyLong_NumBits. This will be used at the
start for the C implemention of new pickle LONG1 and LONG4 opcodes (the
linear-time way to pickle a long is to call _PyLong_AsByteArray, but
the caller has no idea how big an array to allocate, and correct
calculation is a bit subtle).
2003-01-28 20:37:45 +00:00
Barry Warsaw 7871154c2e Bump the version number 2003-01-28 17:30:46 +00:00
Fred Drake 4faea015f7 Update to the final version released as Expat 1.95.6 (maintaining
Martin's integration changes).
2003-01-28 06:42:40 +00:00
Guido van Rossum 99d4abf8a2 Support socket timeout in SSL, by Geoff Talvola.
(SF patch #675750, to fix SF bug #675552.)
2003-01-27 22:22:50 +00:00
Martin v. Löwis 7a565f0b9b Fix reference counting of iconvcodec_Type. Fixes #670715.
Remove GC code; the base type does not need GC.
2003-01-27 11:39:04 +00:00
Neal Norwitz 57c115c8ad Get rid of compiler warnings on Redhat 2003-01-26 16:26:20 +00:00
Martin v. Löwis 727fe66f27 Add _iconv_codec to Setup.dist. Use PyModule_ functions. 2003-01-26 11:48:20 +00:00
Martin v. Löwis 9789aefa61 Patch #670715: Universal Unicode Codec for POSIX iconv. 2003-01-26 11:30:36 +00:00
Martin v. Löwis c35d199404 Undo inclusion of Python.h. Remove HAVE_MEMCPY section.
Update Windows command line.
2003-01-26 08:40:50 +00:00
Martin v. Löwis 94ac339d21 Uncomment usage of expat_config.h 2003-01-25 22:48:51 +00:00
Martin v. Löwis fc03a94aac Incorporate Expat 1.95.6. 2003-01-25 22:41:29 +00:00
Tim Peters 8d81a012ef date and datetime comparison: when we don't know how to
compare against "the other" argument, we raise TypeError,
in order to prevent comparison from falling back to the
default (and worse than useless, in this case) comparison
by object address.

That's fine so far as it goes, but leaves no way for
another date/datetime object to make itself comparable
to our objects.  For example, it leaves Marc-Andre no way
to teach mxDateTime dates how to compare against Python
dates.

Discussion on Python-Dev raised a number of impractical
ideas, and the simple one implemented here:  when we don't
know how to compare against "the other" argument, we raise
TypeError *unless* the other object has a timetuple attr.
In that case, we return NotImplemented instead, and Python
will give the other object a shot at handling the
comparison then.

Note that comparisons of time and timedelta objects still
suffer the original problem, though.
2003-01-24 22:36:34 +00:00
Tim Peters 8bb5ad2e56 Updated the astimezone() proof to recover from all the last week's
changes (and there were a lot of relevant changes!).
2003-01-24 02:44:45 +00:00
Neal Norwitz 2fbe5378f9 Fix typo 2003-01-23 21:09:05 +00:00
Tim Peters 2a44a8d332 SF bug 660872: datetimetz constructors behave counterintuitively (2.3a1).
This gives much the same treatment to datetime.fromtimestamp(stamp, tz) as
the last batch of checkins gave to datetime.now(tz):  do "the obvious"
thing with the tz argument instead of a senseless thing.
2003-01-23 20:53:10 +00:00
Tim Peters 10cadce41e Reimplemented datetime.now() to be useful. 2003-01-23 19:58:02 +00:00
Tim Peters b1049e8eca fromutc(): Repair incorrect failure return, as noted by NealN. Thanks! 2003-01-23 17:20:36 +00:00
Tim Peters 52dcce24e2 Bringing the code and test suite into line with doc and NEWS changes
checked in two days agao:

Refactoring of, and new rules for, dt.astimezone(tz).

dt must be aware now, and tz.utcoffset() and tz.dst() must not return None.
The old dt.astimezone(None) no longer works to change an aware datetime
into a naive datetime; use dt.replace(tzinfo=None) instead.

The tzinfo base class now supplies a new fromutc(self, dt) method, and
datetime.astimezone(tz) invokes tz.fromutc().  The default implementation
of fromutc() reproduces the same results as the old astimezone()
implementation, but tzinfo subclasses can override fromutc() if the
default implementation isn't strong enough to get the correct results
in all cases (for example, this may be necessary if a tzinfo subclass
models a time zone whose "standard offset" (wrt UTC) changed in some
year(s), or in some variations of double-daylight time -- the creativity
of time zone politics can't be captured in a single default implementation).
2003-01-23 16:36:11 +00:00
Martin v. Löwis 70c3dda2fb Convert booleans to integers in IntVar.set. Fixes #671741.
Return booleans from _tkinter.getboolean.
Convert booleans to Tcl booleans in AsObj.
2003-01-22 09:17:38 +00:00
Martin v. Löwis cd9a8b6bcf Avoid usage of PyDoc_STR in 2.2 compatibility code. 2003-01-21 21:52:57 +00:00
Martin v. Löwis c847f4040d Conditionalize features not found in PyXML 1.95.2. 2003-01-21 11:09:21 +00:00
Martin v. Löwis 069dde2be3 Merge with PyXML 1.71:
60: Added support for the SkippedEntityHandler, new in Expat 1.95.4.
61: Added support for namespace prefixes, which can be enabled by setting the
    "namespace_prefixes" attribute on the parser object.
65: Disable profiling changes for Python 2.0 and 2.1.
66: Update pyexpat to export the Expat 1.95.5 XML_GetFeatureList()
    information, and tighten up a type declaration now that Expat is using
    an incomplete type rather than a void * for the XML_Parser type.
67: Clarified a comment.
    Added support for XML_UseForeignDTD(), new in Expat 1.95.5.
68: Refactor to avoid partial duplication of the code to construct an
    ExpatError instance, and actually conform to the API for the exception
    instance as well.
69: Remove some spurious trailing whitespace.
    Add a special external-entity-ref handler that gets installed once a
    handler has raised a Python exception; this can cancel actual parsing
    earlier if there's an external entity reference in the input data
    after the the Python excpetion has been raised.
70: Untabify APPEND.
71: Backport PyMODINIT_FUNC for 2.2 and earlier.
2003-01-21 10:58:18 +00:00
Tim Peters 327098a613 New rule for tzinfo subclasses handling both standard and daylight time:
When daylight time ends, an hour repeats on the local clock (for example,
in US Eastern, the clock jumps from 1:59 back to 1:00 again).  Times in
the repeated hour are ambiguous.  A tzinfo subclass that wants to play
with astimezone() needs to treat times in the repeated hour as being
standard time.  astimezone() previously required that such times be
treated as daylight time.  There seems no killer argument either way,
but Guido wants the standard-time version, and it does seem easier the
new way to code both American (local-time based) and European (UTC-based)
switch rules, and the astimezone() implementation is simpler.
2003-01-20 22:54:38 +00:00
Neal Norwitz fa56e2dc40 SF # 669553, fix memory (ref) leaks
Will backport.
2003-01-19 15:40:09 +00:00
Tim Peters 513a1cd103 Windows flavor of floatsleep(): folded long lines, introduced a temp
var for clarity.
2003-01-19 04:54:58 +00:00
Raymond Hettinger 9543b34006 SF patch #670423: Add missing identity tests to operator.c 2003-01-18 23:22:20 +00:00
Tim Peters 8b19a93b87 When time.localtime() is passed a tick count the platform C localtime()
function can't handle, don't raise IOError -- that doesn't make sense.
Raise ValueError instead.

Bugfix candidate.
2003-01-17 20:08:54 +00:00
Gregory P. Smith b6c9f78074 bugfix: do not double-close DB cursor during deallocation when the
underlying DB has already been closed (and thus all of its cursors).
        This fixes a potential segfault.
        SF pybsddb bug id 667343
bugfix: close the DB object when raising an exception due to an error
        during DB.open.  This prevents an exception when closing the
        environment about not all databases being closed.
        SF pybsddb bug id 667340
2003-01-17 08:42:50 +00:00