Tim Peters [Thu, 13 Sep 2001 21:49:44 +0000 (21:49 +0000)]
Get rid of builtin_open() entirely (the C code and docstring, not the
builtin function); Guido pointed out that it could be just another
name in the __builtin__ dict for the file constructor now.
Tim Peters [Thu, 13 Sep 2001 21:01:29 +0000 (21:01 +0000)]
Now that file objects are subclassable, you can get at the file constructor
just by doing type(f) where f is any file object. This left a hole in
restricted execution mode that rexec.py can't plug by itself (although it
can plug part of it; the rest is plugged in fileobject.c now).
Tim Peters [Thu, 13 Sep 2001 19:18:27 +0000 (19:18 +0000)]
type_call(): Change in policy. The keyword args (if any) are now passed
on to the tp_new slot (if non-NULL), as well as to the tp_init slot (if
any). A sane type implementing both tp_new and tp_init should probably
pay attention to the arguments in only one of them.
Fred Drake [Thu, 13 Sep 2001 16:56:43 +0000 (16:56 +0000)]
Admit that we'll never add the args for a "call" event to the profile
and trace functions; this now declares that None will be passed for the
"call" event.
This closes SF bug/suggestion #460315.
SF bug #461073: mailbox __iter__ bug, by Andrew Dalke.
Andrew quite correctly notices that the next() method isn't quite what
we need, since it returns None upon end instead of raising
StopIteration. His fix is easy enough, using iter(self.next, None)
instead.
build_class(): one more (hopefully the last) step on the way to
backwards compatibility. When using the class of the first base as
the metaclass, use its __class__ attribute in preference over its
ob_type slot. This ensures that we can still use classic classes as
metaclasse, as shown in the original "Metaclasses" essay. This also
makes all the examples in Demo/metaclasses/ work again (maybe these
should be turned into a test suite?).
Tim Peters [Wed, 12 Sep 2001 19:12:49 +0000 (19:12 +0000)]
Again perhaps the end of [#460020] bug or feature: unicode() and subclasses.
Inhibited complex unary plus optimization when applied to a complex subtype.
Added PyComplex_CheckExact macro. Some comments and minor code fiddling.
Tim Peters [Wed, 12 Sep 2001 07:54:51 +0000 (07:54 +0000)]
If interning an instance of a string subclass, intern a real string object
with the same value instead. This ensures that a string (or string
subclass) object's ob_sinterned pointer is always a str (or NULL), and
that the dict of interned strings only has strs as keys.
Tim Peters [Wed, 12 Sep 2001 05:18:58 +0000 (05:18 +0000)]
str_subtype_new, unicode_subtype_new:
+ These were leaving the hash fields at 0, which all string and unicode
routines believe is a legitimate hash code. As a result, hash() applied
to str and unicode subclass instances always returned 0, which in turn
confused dict operations, etc.
+ Changed local names "new"; no point to antagonizing C++ compilers.
Tim Peters [Wed, 12 Sep 2001 02:18:30 +0000 (02:18 +0000)]
More bug 460020: lots of string optimizations inhibited for string
subclasses, all "the usual" ones (slicing etc), plus replace, translate,
ljust, rjust, center and strip. I don't know how to be sure they've all
been caught.
Question: Should we complain if someone tries to intern an instance of
a string subclass? I hate to slow any code on those paths.
Tim Peters [Tue, 11 Sep 2001 21:44:14 +0000 (21:44 +0000)]
More bug 460020. When I is a subclass of int, disable the +I(whatever),
I(0) << whatever, I(0) >> whatever, I(whatever) << 0 and I(whatever) >> 0
optimizations.
Jack Jansen [Tue, 11 Sep 2001 21:25:10 +0000 (21:25 +0000)]
These modules now live under the Carbon package.
Added a few new toolbox modules.
Noted machine dependencies for some modules.
Moved waste to undoc.tex.
Fred Drake [Tue, 11 Sep 2001 19:56:51 +0000 (19:56 +0000)]
Document clearly that the only way to retrieve the return code from the
child processes is to use the Popen3 and Popen4 classes.
This fixes SF bug #460512.
Add login() method and SMTPAuthenticationError exception. SF patch
#460112 by Gerhard Haering.
(With slight layout changes to conform to docstrings guidelines and to
prevent a line longer than 78 characters. Also fixed some docstrings
that Gerhard didn't touch.)
Restore the comparisons that I initially put in the test but that Tim
XXX'ed out. Turns out that after fixing the constructors, the
comparisons in fact succeed. E.g. int(hexint(12345)) returns an int
with value 12345.
Jack Jansen [Tue, 11 Sep 2001 13:08:10 +0000 (13:08 +0000)]
Mods by Donovan Preston (with changes by me to make them "go with the flow")
that will detect an __main__.py or __rawmain__.py in the application bundle.
This file is then exectued as the main script. We now have applets in
MachO Python!!!
The difference between __main__ and __rawmain__ is that the former gets a
complete simulated argv (so you can drop files on the applet and the script
sees them in sys.argv) while the latter skips the argv simulation and the
<option>key dialog. This keeps the AppleEvent that started the app intact,
as well as the funny "-psn_xxxx" argv[1] argument, so the script can do
with these what it wants.
Tim Peters [Tue, 11 Sep 2001 03:07:38 +0000 (03:07 +0000)]
Possibly the end of SF [#460020] bug or feature: unicode() and subclasses.
Changed unicode(i) to return a true Unicode object when i is an instance of
a unicode subclass. Added PyUnicode_CheckExact macro.
Tim Peters [Tue, 11 Sep 2001 01:52:02 +0000 (01:52 +0000)]
Added another test of str() applied to a string subclass instance,
involving embedded null bytes, since it's possible to screw that up w/o
screwing up cases w/o embedded nulls.
Tim Peters [Tue, 11 Sep 2001 01:41:59 +0000 (01:41 +0000)]
More on SF bug [#460020] bug or feature: unicode() and subclasses.
Repaired str(i) to return a genuine string when i is an instance of a str
subclass. New PyString_CheckExact() macro.
Tim Peters [Mon, 10 Sep 2001 23:37:46 +0000 (23:37 +0000)]
More on SF bug [#460020] bug or feature: unicode() and subclasses.
tuple(i) repaired to return a true tuple when i is an instance of a
tuple subclass.
Added PyTuple_CheckExact macro.
PySequence_Tuple(): if a tuple-like object isn't exactly a tuple, it's
not safe to return the object as-is -- make a new tuple of it instead.
Jack Jansen [Mon, 10 Sep 2001 22:00:39 +0000 (22:00 +0000)]
Replaced PyMac_FullPath by PyMac_FullPathname, which has an extra 'length'
parameter for the return string (as unix pathnames are not limited
by the 255 char pstring limit).
Implemented the function for MachO-Python, where it returns unix pathnames.
Tim Peters [Mon, 10 Sep 2001 21:28:20 +0000 (21:28 +0000)]
More for SF bug [#460020] bug or feature: unicode() and subclasses
Repair float constructor to return a true float when passed a subclass
instance. New PyFloat_CheckExact macro.
Tim Peters [Mon, 10 Sep 2001 20:52:51 +0000 (20:52 +0000)]
SF bug #460020: bug or feature: unicode() and subclasses.
Given an immutable type M, and an instance I of a subclass of M, the
constructor call M(I) was just returning I as-is; but it should return a
new instance of M. This fixes it for M in {int, long}. Strings, floats
and tuples remain to be done.
Added new macros PyInt_CheckExact and PyLong_CheckExact, to more easily
distinguish between "is" and "is a" (i.e., only an int passes
PyInt_CheckExact, while any sublass of int passes PyInt_Check).
Added private API function _PyLong_Copy.
Subtlety on Windows: if we change test_largefile.py to use a file
> 4GB, it still fails. A debug session suggests this is because
fseek(fp, 0, 2) refuses to seek to the end of the file when the file
is > 4GB, because it uses the SetFilePointer() in 32-bit mode.
But it only fails when we seek relative to the end of the file,
because in the other seek modes only calls to fgetpos() and fsetpos()
are made, which use Get/SetFilePointer() in 64-bit mode. Solution:
#ifdef MS_WInDOWS, replace the call to fseek(fp, ...) with a call to
_lseeki64(fileno(fp), ...). Make sure to call fflush(fp) first.
(XXX Could also replace the entire branch with a call to _lseeki64().
Would that be more efficient? Certainly less generated code.)
(XXX This needs more testing. I can't actually test that it works for
files >4GB on my Win98 machine, because the filesystem here won't let
me create files >=4GB at all. Tim should test this on his Win2K
machine.)
Fredrik Lundh [Mon, 10 Sep 2001 19:45:02 +0000 (19:45 +0000)]
sync with pythonware codebase: much faster import (doesn't import
xmllib unless needed), merged docstring patches, added overridable
Transport.getparser to simplify plugging in different parsers.
PyObject_Dir():
- use PyModule_Check() instead of PyObject_TypeCheck(), now we can.
- don't assert that the __dict__ gotten out of a module is always
a dictionary; check its type, and raise an exception if it's not.
Move the global variables 'size' and 'name' to the top -- these are
"module parameters", and used in the Windows test (which crashed
because size was undefined -- sigh).
If on Windows, we require the 'largefile' resource.
If not on Windows, we use a test that actually writes a byte beyond
the 2BG limit -- seeking alone is not sufficient, since on some
systems (e.g. Linux with glibc 2.2) the sytem call interface supports
large seek offsets but not all filesystem implementations do.
Note that on Windows, we do not use the write test: on Win2K, that
test can take a minute trying to zero all those blocks on disk, and on
Windows our code always supports large seek offsets (but again, not
all filesystems do). This may mean that on Win95, or on certain other
backward filesystems, test_largefile will *fail*.
Jeremy Hylton [Mon, 10 Sep 2001 01:54:43 +0000 (01:54 +0000)]
Fix core dump in PyArg_ParseTuple() with Unicode arguments.
Reported by Fredrik Lundh on python-dev.
The conversimple() code that handles Unicode arguments and converts
them to the default encoding now calls converterr() with the original
Unicode argument instead of the NULL returned by the failed encoding
attempt.
This time (I hope) I've fixed largefile
support on Linux (and Solaris, I expect) for real.
The necessary symbols are defined once and for all,
under the assumption that they won't harm elsewhere.
Tim Peters [Sun, 9 Sep 2001 06:12:01 +0000 (06:12 +0000)]
Teach regrtest how to pass on doctest failure msgs. This is done via a
horridly inefficient hack in regrtest's Compare class, but it's about as
clean as can be: regrtest has to set up the Compare instance before
importing a test module, and by the time the module *is* imported it's too
late to change that decision. The good news is that the more tests we
convert to unittest and doctest, the less the inefficiency here matters.
Even now there are few tests with large expected-output files (the new
cost here is a Python-level call per .write() when there's an expected-
output file).
Jack Jansen [Sun, 9 Sep 2001 00:35:19 +0000 (00:35 +0000)]
Minimal module to decode AppleSingle files (the way resource files are
stored in the CVS repository). It can either decode resource/data forks
in the standard Mac way or decode only the resource fork but store
the result in the data fork (the MacOSX preferred way). Finder info
and all other stuff is ignored.
Tim Peters [Sat, 8 Sep 2001 04:00:12 +0000 (04:00 +0000)]
Generalize operator.indexOf (PySequence_Index) to work with any
iterable object. I'm not sure how that got overlooked before!
Got rid of the internal _PySequence_IterContains, introduced a new
internal _PySequence_IterSearch, and rewrote all the iteration-based
"count of", "index of", and "is the object in it or not?" routines to
just call the new function. I suppose it's slower this way, but the
code duplication was getting depressing.
Tim Peters [Sat, 8 Sep 2001 03:37:56 +0000 (03:37 +0000)]
It appears that unittest was changed to stop hoarding raw exception data,
saving instead a traceback string, but test_support's run_unittest was
still peeking into unittest internals and trying to pick apart unittest's
errors and failures vectors as if they contained exc_info() tuples instead
of strings.
Whatever, when a unittest-based test failed, test_support blew up. I'm
not sure this is the right way to fix it; it simply gets me unstuck.
PyClass_New(): put the extended Don Beaudry hook back in. When one of
the base classes is not a classic class, and its class (the metaclass)
is callable, call the metaclass to do the deed.
One effect of this is that, when mixing classic and new-style classes
amongst the bases of a class, it doesn't matter whether the first base
class is a classic class or not: you will always get the error
"TypeError: metatype conflict among bases". (Formerly, with a classic
class first, you'd get "TypeError: PyClass_New: base must be a class".)
Another effect is that multiple inheritance from ExtensionClass.Base,
with a classic class as the first class, transfers control to the
ExtensionClass.Base class. This is what we need for SF #443239 (and
also for running Zope under 2.2a4, before ExtensionClass is replaced).
PySequence_Check(), PyMapping_Check(): only return true if the
corresponding "getitem" operation (sq_item or mp_subscript) is
implemented. I realize that "sequence-ness" and "mapping-ness" are
poorly defined (and the tests may still be wrong for user-defined
instances, which always have both slots filled), but I believe that a
sequence that doesn't support its getitem operation should not be
considered a sequence. All other operations are optional though.
For example, the ZODB BTree tests crashed because PySequence_Check()
returned true for a dictionary! (In 2.2, the dictionary type has a
tp_as_sequence pointer, but the only field filled is sq_contains, so
you can write "if key in dict".) With this fix, all standalone ZODB
tests succeed.