Commit Graph

5342 Commits

Author SHA1 Message Date
Guido van Rossum 0eb2a6e974 It turned out not so difficult to support old-style numbers (those
without the Py_TPFLAGS_CHECKTYPES flag) in the wrappers.  This
required a few changes in test_descr.py to cope with the fact that the
complex type has __int__, __long__ and __float__ methods that always
raise an exception.
2001-10-09 11:07:24 +00:00
Martin v. Löwis 6ec9a36faf Patch #468647: Fix exception propagation in asyncore. 2001-10-09 10:10:33 +00:00
Tim Peters cce092d046 A brand new implementation of Profile.calibrate(). This measures an
actual run of the profiler, instead of timing a simplified simulation of
part of what the profiler does.  It computes a constant about 60% higher
on my Win98SE box than the old method, and the new constant appears much
more realistic.  Deleted the undocumented simple(), instrumented(), and
profiler_simulation() methods (which existed only to support the previous
calibration method).
2001-10-09 05:31:56 +00:00
Fred Drake 168beada91 Added tests that check getboolean() with the newly allowed values from
SF patch #467580.
2001-10-08 17:13:12 +00:00
Guido van Rossum 4570455813 Change all occurrences of verify(x == y) into vereq(x, y), since when
this type of test fails, vereq() does a better job of reporting than
verify().

Change vereq(x, y) to use "not x == y" rather than "x != y" -- it
makes a difference is some overloading tests.
2001-10-08 16:35:45 +00:00
Tim Peters 281084f798 Put the deprecated .ignore() method back where it was. 2001-10-08 06:28:18 +00:00
Tim Peters 7d01685738 Widespread random code cleanup.
Most of this code was old enough to vote.  Examples of cleanups:

+ Backslashes were used for line continuation even inside unclosed
  bracket structures, from back in the days that was still needed.

+ There was no use of % formats, and e.g. the old fpformat module was
  still used to format floats "by hand" in conjunction with rjust().

+ There was even use of a do-nothing .ignore() method to tack on to the
  end of a chain of method calls, else way back when Python would print
  the non-None result (as it does now in an interactive session -- it
  *used* to do that in batch mode too).

+ Perhaps controversial (although I can't imagine why for real <wink>),
  used augmented assignment where helpful.  Stuff like

      self.total_calls = self.total_calls + other.total_calls

  is just plain harder to follow than

      self.total_calls += other.total_calls
2001-10-08 06:13:19 +00:00
Steven M. Gava 1f733baa04 merged port binding error message patch 2001-10-07 11:44:49 +00:00
Steven M. Gava 4eb286874f merged win spawn patch 2001-10-07 11:26:48 +00:00
Steven M. Gava 898a365c27 merged status bar packing patch 2001-10-07 11:10:44 +00:00
Martin v. Löwis 322c0d187d Only close sockets if they have been created. Reported by Blake Winton. 2001-10-07 08:53:32 +00:00
Tim Peters fb163784ab Typo repair in comment. 2001-10-07 08:49:02 +00:00
Tim Peters 8d061ed75b Guido points out that the comments for self.cur[2] were subtly but
seriously wrong.  This started out by just fixing the docs, but then it
occurred to me that the doc confusion propagated into misleading vrbl names
too, so I also renamed those to match reality.  As a result, INO the time
computations are much easier to understand now (within the limitations of
vast quantities of 3-character names <wink>).
2001-10-07 08:35:44 +00:00
Tim Peters db1ed2aec3 At Guido's request, changed the code that's conceptually asserting stuff
to use assert stmts (was raising unexpected kinds of exceptions).
2001-10-07 04:30:53 +00:00
Tim Peters 6e22149cb6 Repair some longstanding comment errors:
+ The last index in the timing tuple is 4, not 5 (noted by Guido).

+ The poorly named trace_dispatch_i works with float return values too.
2001-10-07 04:02:36 +00:00
Tim Peters 0a1fc4e389 Remove code and docs for the OldProfile and HotProfile classes: code
hasn't worked in years, docs were wrong, and they aren't interesting
anymore regardless.
2001-10-07 03:12:08 +00:00
Tim Peters df5cfd884d The fix to profile semantics broke the miserable but advertised way to
derive Profile subclasses.  This patch repairs that, restoring
negative tuple indices.  Yuck?  You bet.
2001-10-05 23:15:10 +00:00
Fred Drake e029242d5c ReferenceError is now built-in, so pick it up from the right place.
It still needs to be here to preserve the API.
2001-10-05 21:54:09 +00:00
Guido van Rossum 39c785108f Martijn Pieters convinced me that when readline() strips the trailing
newline from a multifile part, it should also strip a trailing \r\n.
2001-10-05 21:22:21 +00:00
Guido van Rossum 9475a2310d Enable GC for new-style instances. This touches lots of files, since
many types were subclassable but had a xxx_dealloc function that
called PyObject_DEL(self) directly instead of deferring to
self->ob_type->tp_free(self).  It is permissible to set tp_free in the
type object directly to _PyObject_Del, for non-GC types, or to
_PyObject_GC_Del, for GC types.  Still, PyObject_DEL was a tad faster,
so I'm fearing that our pystone rating is going down again.  I'm not
sure if doing something like

void xxx_dealloc(PyObject *self)
{
	if (PyXxxCheckExact(self))
		PyObject_DEL(self);
	else
		self->ob_type->tp_free(self);
}

is any faster than always calling the else branch, so I haven't
attempted that -- however those types whose own dealloc is fancier
(int, float, unicode) do use this pattern.
2001-10-05 20:51:39 +00:00
Thomas Heller be63884d50 With Andrew's blessing: distutils version number is now 1.0.3. 2001-10-05 20:43:09 +00:00
Thomas Heller e138f369e6 Explicitely list the metadata attributes to show
in the gui.
Updated to include the new exe-file.
2001-10-05 20:40:48 +00:00
Barry Warsaw 4a8e9f4e42 SMTPServer.__init__(): Print the start information on the DEBUGSTREAM
so that it can be suppressed.
2001-10-05 17:10:31 +00:00
Fred Drake 4e7cdb57f9 Non-failing test for SF bug #467059. 2001-10-04 20:05:10 +00:00
Guido van Rossum fb06f75c5a Apply modified SF patch 467580: ConfigParser.getboolean(): FALSE, TRUE.
This patch allows ConfigParser.getboolean() to interpret TRUE,
    FALSE, YES, NO, ON and OFF instead just '0' and '1'.

    While just allowing '0' and '1' sounds more correct users often
    demand to use more descriptive directives in configuration
    files. Instead of forcing every programmer do brew his own
    solution a system should include the batteries for this.

[My modification to the patch is a slight rewording of the docstring
and use of lowercase instead of uppercase templates.  The code is
still case sensitive. GvR.]
2001-10-04 19:58:46 +00:00
Fred Drake 266410355f run_suite(): If testclass is not available, provide an even more general
error message.
run_unittest():  Provide the testclass to run_suite() so it can construct
                 the error message.
This closes SF bug #467763.
2001-10-04 19:46:07 +00:00
Barry Warsaw d1de6eacf2 TestIterators: Tim Peters suggests a more succinct spelling of
"listify an iterator".
2001-10-04 18:18:37 +00:00
Barry Warsaw c4496f886b More test data for test_email.py 2001-10-04 17:59:42 +00:00
Barry Warsaw 08a534d476 test_header_splitter(), test_body_line_iterator(): Move the test data
into tests/data/msg_*.txt files.
2001-10-04 17:58:50 +00:00
Barry Warsaw e968ead1dd Give me back my page breaks. 2001-10-04 17:05:11 +00:00
Barry Warsaw 0e8427e4f2 Script arguments localhost:localport and remotehost:remoteport are now
optional, and default to `localhost' and ports 8025 and 25
respectively.

SMTPChannel.__init__(): Calculate __fqdn using socket.getfqdn()
instead of gethostby*() and friends.  This allows us to run this
script even if we don't have access to dns (assuming the localhost is
configured properly).

Also, restore my precious page breaks.  Hands off, oh Whitespace
Normalizer!
2001-10-04 16:27:04 +00:00
Fred Drake 7c0a93d966 Updated to reflect the rationalized profiler event reporting. 2001-10-04 14:49:46 +00:00
Tim Peters c59fb2d230 This test relied on hard tab characters, so failed after whitespace
normalization.  Now uses \t in strings instead of hard tabs.
2001-10-04 06:26:17 +00:00
Tim Peters 4fb1fe8bd2 class_docstrings(): The new-style class tests should use new-style
classes (sheesh!).
2001-10-04 05:48:13 +00:00
Tim Peters 527e64fd68 Whitespace normalization. 2001-10-04 05:36:56 +00:00
Tim Peters 2f93e28a19 SF bug [#467331] ClassType.__doc__ always None.
For a dynamically constructed type object, fill in the tp_doc slot with
a copy of the argument dict's "__doc__" value, provided the latter exists
and is a string.
NOTE:  I don't know what to do if it's a Unicode string, so in that case
tp_doc is left NULL (which shows up as Py_None if you do Class.__doc__).
Note that tp_doc holds a char*, not a general PyObject*.
2001-10-04 05:27:00 +00:00
Guido van Rossum f137f75ab8 Hopefully fix the profiler right. Add a test suite that checks that
it deals correctly with some anomalous cases; according to this test
suite I've fixed it right.

The anomalous cases had to do with 'exception' events: these aren't
generated when they would be most helpful, and the profiler has to
work hard to recover the right information.  The problems occur when C
code (such as hasattr(), which is used as the example here) calls back
into Python code and clears an exception raised by that Python code.
Consider this example:

    def foo():
        hasattr(obj, "bar")

Where obj is an instance from a class like this:

    class C:
        def __getattr__(self, name):
            raise AttributeError

The profiler sees the following sequence of events:

    call (foo)
    call (__getattr__)
    exception (in __getattr__)
    return (from foo)

Previously, the profiler would assume the return event returned from
__getattr__. An if statement checking for this condition and raising
an exception was commented out...  This version does the right thing.
2001-10-04 00:58:24 +00:00
Fred Drake 0099ba73de Add some more test cases to be sure we do the right thing in various cases. 2001-10-03 21:15:32 +00:00
Fred Drake a0bc9993e7 Undo previous patch; it did not quite work out. 2001-10-03 21:12:32 +00:00
Andrew M. Kuchling 4602c1b702 Set .addr in a few more places (patch approved by Sam Rushing) 2001-10-03 17:07:25 +00:00
Guido van Rossum 4a5a2bc2b6 dynamics(): add a dummy __getattr__ method to the C class so that the
test for modifying __getattr__ works, now that slot_tp_getattr_hook
zaps the slot if there's no hook.  Added an XXX comment with a ref
back to slot_tp_getattr_hook.
2001-10-03 13:59:54 +00:00
Skip Montanaro ae3b1258e4 remove empty __del__ method from BaseRequestHandler to avoid cyclic garbage
loss for no reason.
2001-10-03 12:21:23 +00:00
Tim Peters 1b0e5490c5 Made the classmethod docstring test a bit less trivial. 2001-10-03 04:15:28 +00:00
Tim Peters 17111f3b24 SF bug [#467336] doctest failures w/ new-style classes.
Taught doctest about static methods, class methods, and property docstrings
in new-style classes.  As for inspect.py/pydoc.py before it, the new stuff
needed didn't really fit into the old architecture (but was less of a
strain to force-fit here).
New-style class docstrings still aren't found, but that's the subject
of a different bug and I want to fix that right instead of hacking around
it in doctest.
2001-10-03 04:08:26 +00:00
Tim Peters 4a9ac4a83c SF patch [#466616] Exclude imported items from doctest.
Another installment; the new functionality wasn't actually enabled in
normal use, only in the strained use checked by the test case.
2001-10-02 22:47:08 +00:00
Guido van Rossum 048eb75c2d Add Garbage Collection support to new-style classes (not yet to their
instances).

Also added GC support to various auxiliary types: super, property,
descriptors, wrappers, dictproxy.  (Only type objects have a tp_clear
field; the other types are.)

One change was necessary to the GC infrastructure.  We have statically
allocated type objects that don't have a GC header (and can't easily
be given one) and heap-allocated type objects that do have a GC
header.  Giving these different metatypes would be really ugly: I
tried, and I had to modify pickle.py, cPickle.c, copy.py, add a new
invent a new name for the new metatype and make it a built-in, change
affected tests...  In short, a mess.  So instead, we add a new type
slot tp_is_gc, which is a simple Boolean function that determines
whether a particular instance has GC headers or not.  This slot is
only relevant for types that have the (new) GC flag bit set.  If the
tp_is_gc slot is NULL (by far the most common case), all instances of
the type are deemed to have GC headers.  This slot is called by the
PyObject_IS_GC() macro (which is only used twice, both times in
gcmodule.c).

I also changed the extern declarations for a bunch of GC-related
functions (_PyObject_GC_Del etc.): these always exist but objimpl.h
only declared them when WITH_CYCLE_GC was defined, but I needed to be
able to reference them without #ifdefs.  (When WITH_CYCLE_GC is not
defined, they do the same as their non-GC counterparts anyway.)
2001-10-02 21:24:57 +00:00
Guido van Rossum fe1fd0e6e9 pickles():
- The test for deepcopy() in pickles() was indented wrongly, so it got
  run twice (one for binary pickle mode, one for text pickle mode; but
  the test doesn't depend on the pickle mode).

- In verbose mode, show which subtest (pickle/cPickle/deepcopy, text/bin).
2001-10-02 19:58:32 +00:00
Guido van Rossum c907bd89de The error reporting here was a bit sparse. In verbose mode, the code
in run_test() referenced two non-existent variables, and in
non-verbose mode, the tests didn't report the actual number, when it
differed from the expected number.  Fixed this.

Also added an extra call to gc.collect() at the start of test_all().
This will be needed when I check in the changes to add GC to new-style
classes.
2001-10-02 19:49:47 +00:00
Guido van Rossum b855134a0d Under certain conditions (sometimes triggered by the test suite),
"from xml.parsers import expat" succeeds but the imported expat module
is an empty shell.  Make sure we don't be fooled by that.
2001-10-02 18:33:11 +00:00
Guido van Rossum e37e96df06 Correct the URL for the license (only used when the LICENSE[.txt] file
is not found).  Being fancy: insert the first 3 characters of
sys.version in the URL.
2001-10-02 18:27:09 +00:00
Tim Peters 7402f791a4 SF patch [#466616] Exclude imported items from doctest,
from Tim Hochberg.  Also mucho fiddling to change the way doctest
determines whether a thing is a function, module or class.  Under 2.2,
this really requires the functions in inspect.py (e.g., types.ClassType
is close to meaningless now, if not outright misleading).
2001-10-02 03:53:41 +00:00
Fredrik Lundh 1538c23dec restored 1.5.2 compatibility
added local escape method (made the dumps method some 50-80% faster)
minor tweaks to the unmarshalling code
2001-10-01 19:42:03 +00:00
Skip Montanaro fbacaf7298 approximately double dump performance by moving import of cgi.escape back to
top level.
2001-10-01 17:50:29 +00:00
Skip Montanaro 419abdaff2 simple dumps/loads test case for xmlrpclib 2001-10-01 17:47:44 +00:00
Martin v. Löwis c04f7a794e Undo last checkin, since it duplicated the code. 2001-10-01 17:02:49 +00:00
Guido van Rossum d1d584f4e8 SF patch #462628 (Travers Naran) NNTPLib supports saving BODY to a file.
I modified nntplib so the body method can accept an
  optional second parameter pointing to a filehandle or
  filename (string). This way, really long body
  articles can be stored to disk instead of kept in
  memory. The way I made the modification should make
  it easy to extend this functionality to other extended
  return methods.
2001-10-01 13:46:55 +00:00
Martin v. Löwis 2fa69d7984 Patch #426880: Implement Listbox itemcget and itemconfigure. 2001-10-01 10:09:31 +00:00
Martin v. Löwis 16dc7f44b1 Patch #462190, patch #464070: Support quoted printable in the binascii module.
Decode and encode underscores for header style encoding. Fixes bug #463996.
2001-09-30 20:32:11 +00:00
Martin v. Löwis 5f12d755a8 Properly detect recursive structures. Adopted from patch #465298. 2001-09-30 20:15:41 +00:00
Fred Drake d157237d51 For Python 2.2, do not use __getattr__(), only use computed properties.
This is probably a little bit faster, but mostly is just cleaner code.
The old-style support is still used for Python versions < 2.2 so this
source file can be shared with PyXML.
2001-09-29 04:58:32 +00:00
Fred Drake 787fd8cdeb _dispatch(): Do no re-define the resolve_dotted_atttribute() function
every time this gets called; move it out as a global helper function.
    Simplify the call to the _dispatch() method of the registered instance.
2001-09-29 04:54:33 +00:00
Guido van Rossum 751c4c864c Add a few ``__dynamic__ = 0'' lines in classes that need to preserve
staticness when __dynamic__ = 1 becomes the default:

- Some classes which are used to test the difference between static
  and dynamic.

- Subclasses of complex: complex uses old-style numbers and the slot
  wrappers used by dynamic classes only support new-style numbers.
  (Ideally, the complex type should be fixed, but that looks like a
  labor-intensive job.)
2001-09-29 00:40:25 +00:00
Guido van Rossum 4bb1e36eec It's a fact: for binary operators, *under certain circumstances*,
__rop__ now takes precendence over __op__.  Those circumstances are:

  - Both arguments are new-style classes
  - Both arguments are new-style numbers
  - Their implementation slots for tp_op differ
  - Their types differ
  - The right argument's type is a subtype of the left argument's type

Also did this for the ternary operator (pow) -- only the binary case
is dealt with properly though, since __rpow__ is not supported anyway.
2001-09-28 23:49:48 +00:00
Fred Drake 946f7b1b24 Update the xml.dom.minidom tests to cover the DOM-compliant parts of the
NodeList interface.
2001-09-28 20:31:50 +00:00
Fred Drake 575712eaca Tighten up the new NodeList implementation.
Clean up a little; do not create an alias that is only used once, or store
attributes with constant values in an instance.
2001-09-28 20:25:45 +00:00
Fred Drake 88a56857f6 Remove an infelicitous space. 2001-09-28 20:16:30 +00:00
Tim Peters 9390cc15da regrtest's -g option stopped working, during the changes to improve
error-reporting for the classic compare-expected-output tests.
Curiously, the bug consisted of not simplifying the logic enough!
2001-09-28 20:14:46 +00:00
Fred Drake b2ad1c8b4d Reflect recent refinements of the regression testing framework. 2001-09-28 20:05:25 +00:00
Fred Drake 746fe0fae5 Clean up circular references in the Weak*Dictionary classes; this avoids
depending on the cycle detector code in the library implementation.
This is a *slightly* different patch than SF patch #417795, but takes
the same approach.  (This version avoids calling the __len__() method of
the dict in the remove() functions.)
This closes SF patch #417795.
2001-09-28 19:01:26 +00:00
Guido van Rossum 8b9def3aac Add complex to the dispatch tables, to avoid going through the whole
rigmarole of __reduce__.
2001-09-28 18:16:13 +00:00
Guido van Rossum 6cef6d5d62 Changes to copy() and deepcopy() in copy.py to support __reduce__ as a
fallback for objects that are neither supported by our dispatch table
nor have a __copy__ or __deepcopy__ method.

Changes to _reduce() in copy_reg.py to support reducing objects that
don't have a __dict__ -- copy.copy(complex()) now invokes _reduce().

Add tests for copy.copy() and copy.deepcopy() to test_regrtest.py.
2001-09-28 18:13:29 +00:00
Fred Drake 3ac6a09eed For Python 2.2 and newer, actually support the full NodeList interface by
subclassing list to add the length and item() attributes.
2001-09-28 04:33:06 +00:00
Fred Drake 5a28bfbbc7 Change the sense of a test in how the profiler interprets exception events.
This should fix a bug in how time is allocated during exception propogation
(esp. in the presence of finally clauses).
2001-09-27 16:28:42 +00:00
Andrew M. Kuchling 264e8186d5 Fix comment typo 2001-09-27 04:18:36 +00:00
Tim Peters 8ac8be5988 docroutine() (both instances): Docstrings for class methods weren't
getting displayed, due to a special case here whose purpose I didn't
understand.  So just disabled the doc suppression here.

Another special case here skips the docs when picking apart a method
and finding that the im_func is also in the class __dict__ under
the same name.  That one I understood.  It has a curious consequence,
though, wrt inherited properties:  a static class copies inherited stuff
into the inheriting class's dict, and that affects whether or not this
special case triggers.  The upshoot is that pydoc doesn't show the
function docstrings of getter/setter/deleter functions of inherited
properties in the property section when the class is static, but does
when the class is dynamic (bring up Lib/test/pydocfodder.py under
GUI pydoc to see this).
2001-09-27 04:08:16 +00:00
Tim Peters 351e362d89 List class attrs in MRO order of defining class instead of by alphabetic
order of defining class's name.
2001-09-27 03:29:51 +00:00
Tim Peters 3ffeae130b Removed no-longer-true comment about pydoc working under all versions of
Python since 1.5 (virtually everything I changed over the last week relies
on "modern" features, particularly nested scopes).
2001-09-26 22:39:22 +00:00
Tim Peters c86f6ca2b6 Display a class's method resolution order, if it's non-trivial. "Trivial"
here means it has no more than one base class to rummage through (in which
cases there's no potential confusion about resolution order).
2001-09-26 21:31:51 +00:00
Fred Drake 39cd603fc8 More test cases, including something that simulates what the profiler
probably *should* be doing.
2001-09-26 21:00:33 +00:00
Tim Peters 38a50f9065 A file just to look at (using pydoc). 2001-09-26 20:31:52 +00:00
Jeremy Hylton ede049b2d3 Add tests for new PyErr_NormalizeException() behavior
Add raise_exception() to the _testcapi module.  It isn't a test, but
the C API exists only to support test_exceptions.  raise_exception()
takes two arguments -- an exception class and an integer specifying
how many arguments it should be called with.

test_exceptions uses BadException() to test the interpreter's behavior
when there is a problem instantiating the exception.  test_capi1()
calls it with too many arguments.  test_capi2() causes an exception to
be raised in the Python code of the constructor.
2001-09-26 20:01:13 +00:00
Jeremy Hylton 4f38c1e664 Don't export generators future info 2001-09-26 19:54:08 +00:00
Thomas Wouters 80d373cbd0 Test case for SF bugs #463359 and #462937, added to test_grammar for lack of
a better place. Excessively fragile code, but at least it breaks when
something in this area changes!
2001-09-26 12:43:39 +00:00
Barry Warsaw 65279d0242 Update the tests for the current incarnation of the email package, and
added some new tests of message/delivery-status content type messages.
2001-09-26 05:47:08 +00:00
Barry Warsaw 0e416cd88e More test messages for test_email.py 2001-09-26 05:45:17 +00:00
Barry Warsaw 66971fbca5 _parsebody(): Use get_boundary() and get_type().
Also, add a clause to the big-if to handle message/delivery-status
    content types.  These create a message with subparts that are
    Message instances, which best represent the header blocks of this
    content type.
2001-09-26 05:44:09 +00:00
Barry Warsaw beb5945c65 has_key(): Implement in terms of get().
get_type(): Use a compiled regular expression, which can be shared.

_get_params_preserve(): A helper method which extracts the header's
    parameter list preserving value quoting.  I'm not sure that this
    needs to be a public method.  It's necessary because we want
    get_param() and friends to return the unquoted parameter value,
    however we want the quote-preserved form for set_boundary().

get_params(), get_param(), set_boundary(): Implement in terms of
    _get_params_preserve().

walk(): Yield ourself first, then recurse over our subparts (if any).
2001-09-26 05:41:51 +00:00
Barry Warsaw 76fac8ed0e __init__(): Arguments major renamed to maintype and minor renamed to
subtype for consistency with the rest of the package.
2001-09-26 05:36:36 +00:00
Barry Warsaw 57758e3a02 Updated docstrings. Also,
typed_subpart_iterator(): Arguments major renamed to maintype and
    minor renamed to subtype for consistency with the rest of the
    package.
2001-09-26 05:35:47 +00:00
Barry Warsaw 3dd978dfff Image.py and class Image => MIMEImage.py and MIMEImage
Text.py and class Text => MIMEText.py and MIMEText

MessageRFC822.py and class MessageRFC822 => MIMEMessage.py and MIMEMessage

These are renamed so as to be more consistent; these are MIME specific
derived classes for when creating the object model out of whole cloth.
2001-09-26 05:34:30 +00:00
Barry Warsaw b384e01796 In class Generator:
_handle_text(): If the payload is None, then just return (i.e. don't
	write anything).  Subparts of message/delivery-status types
	will have this property since they are just blocks of headers.

	Also, when raising the TypeError, include the type of the
	payload in the error message.

    _handle_multipart(), _handle_message(): When creating a clone of self,
	pass in our _mangle_from_ and maxheaderlen flags so the clone
	has the same behavior.

    _handle_message_delivery_status(): New method to do the proper
	printing of message/delivery-status type messages.  These have
	to be handled differently than other message/* types because
	their payloads are subparts containing just blocks of headers.

In class DecodedGenerator:

    _dispatch(): Skip over multipart/* messages since we don't care
        about them, and don't want the non-text format to appear in
        the printed results.
2001-09-26 05:32:41 +00:00
Barry Warsaw 6f70c41923 cosmetic 2001-09-26 05:26:22 +00:00
Tim Peters 26991a7f77 SF [#463737] Add types.CallableIterType
Rather than add umpteen new obscure internal Iter types, got rid of all of
them.  See the new comment.
2001-09-25 22:02:03 +00:00
Barry Warsaw 45653503ec test_iterator(): Don't do a type comparison to see if it's an
iterator, just test to make sure it has the two required iterator
protocol methods __iter__() and next() -- actually just test
hasattr-ness.
2001-09-25 21:40:04 +00:00
Fred Drake cc91ac09ef Factor out the protect-from-exceptions helpers and make capture_events()
use it.  This simplifies the individual tests a little.

Added some new tests related to exception handling.
2001-09-25 20:48:14 +00:00
Tim Peters 8dee809410 Guido points out that sys.__stdout__ is a bit bucket under IDLE. So keep
the local save/modify/restore of sys.stdout, but add machinery so that
regrtest can tell test_support the value of sys.stdout at the time
regrtest.main() started, and test_support can pass that out later to anyone
who needs a "visible" stdout.
2001-09-25 20:05:11 +00:00
Guido van Rossum 698acf98fd _reconstructor(): there's no need for tricks with assignment to
__class__.  The __new__ protocol is up to this.  (Thanks to Tim for
pointing this out.)
2001-09-25 19:46:05 +00:00
Tim Peters d48004f4f0 test_support should be imported directly, not via test.test_support. 2001-09-25 19:29:35 +00:00
Tim Peters 342ca75d95 Get rid of the increasingly convoluted global tricks w/ sys.stdout, in
favor of local save/modify/restore.  The test suite should run fine again.
2001-09-25 19:13:20 +00:00
Guido van Rossum 3926a63d05 - Provisional support for pickling new-style objects. (*)
- Made cls.__module__ writable.

- Ensure that obj.__dict__ is returned as {}, not None, even upon first
  reference; it simply springs into life when you ask for it.

(*) The pickling support is provisional for the following reasons:

- It doesn't support classes with __slots__.

- It relies on additional support in copy_reg.py: the C method
  __reduce__, defined in the object class, really calls calling
  copy_reg._reduce(obj).  Eventually the Python code in copy_reg.py
  needs to be migrated to C, but I'd like to experiment with the
  Python implementation first.  The _reduce() code also relies on an
  additional helper function, _reconstructor(), defined in
  copy_reg.py; this should also be reimplemented in C.
2001-09-25 16:25:58 +00:00
Guido van Rossum ad39aba2f6 Set sys.save_stdout (to sys.stdout), so doctest-using tests can be run
standalone.
2001-09-25 16:21:39 +00:00
Tim Peters f33532cfef + Display property functions in the same order they're specified to
property() (get, set, del; not set, get, del).

+ Change "Data defined/inherited in ..." header lines to
  "Data and non-method functions defined/inherited in ...".  Things like
  the value of __class__, and __new__, and class vrbls like the i in
      class C:
          i = int
  show up in this section too.  I don't think it's worth a separate
  section to distinguish them from non-callable attrs, and there's no
  obvious reliable way to distinguish callable from non-callable attrs
  anyway.
2001-09-25 06:30:51 +00:00
Guido van Rossum a4cb78874c Change repr() of a new-style class to say <class 'ClassName'> rather
than <type 'ClassName'>.  Exception: if it's a built-in type or an
extension type, continue to call it <type 'ClassName>.  Call me a
wimp, but I don't want to break more user code than necessary.
2001-09-25 03:56:29 +00:00
Guido van Rossum 5c294fb0e6 Make __class__ assignment possible, when the object structures are the
same.  I hope the test for structural equivalence is stringent enough.
It only allows the assignment if the old and new types:

- have the same basic size
- have the same item size
- have the same dict offset
- have the same weaklist offset
- have the same GC flag bit
- have a common base that is the same except for maybe the dict and
  weaklist (which may have been added separately at the same offsets
  in both types)
2001-09-25 03:43:42 +00:00
Tim Peters 2306d246e8 + Got rid of all instances of <small>. Under IE5, GUI-mode pydoc has
always been close to useless, because the <small>-ified docstrings
  were too small to read, even after cranking up my default font size
  just for pydoc.  Now it reads fine under my defaults (as does most
  of the web <0.5 wink>).  If it's thought important to play tricks
  with font size, tough, then someone should rework pydoc to use style
  sheets, and (more) predictable percentage-of-default size controls.

+ Tried to ensure that all <dt> and <dd> tags are closed.  I've read (but
  don't know) that some browsers get confused if they're not, and esp.
  when style sheets are in use too.
2001-09-25 03:18:32 +00:00
Tim Peters 3e767d19e0 GUI mode now displays useful stuff for properties. This is usually better
than text mode, since here we can hyperlink from the getter etc methods
back to their definitions.
2001-09-25 00:01:06 +00:00
Tim Peters f4aad8eb28 + Text-mode (but not yet GUI mode) pydoc now produces useful stuff for
properties:  the docstring (if any) is displayed, and the getter, setter
  and deleter (if any) functions are named.  All that is shown indented
  after the property name.

+ Text-mode pydoc class display now draws a horizontal line between
  class attribute groups (similar to GUI mode -- while visually more
  intrusive in text mode, it's still an improvement).
2001-09-24 22:40:47 +00:00
Tim Peters 66c1a525e0 Make properties discoverable from Python:
- property() now takes 4 keyword arguments:  fget, fset, fdel, doc.
  Note that the real purpose of the 'f' prefix is to make fdel fit in
  ('del' is a keyword, so can't used as a keyword argument name).

- These map to visible readonly attributes 'fget', 'fset', 'fdel',
  and '__doc__' in the property object.

- fget/fset/fdel weren't discoverable from Python before.

- __doc__ is new, and allows to associate a docstring with a property.
2001-09-24 21:17:50 +00:00
Fred Drake 30c4849169 Added several new tests to check the behavior with respect to doctype
declarations and weird markup that we used to accept & ignore that recent
versions raised an exception for; the original behavior has been restored
and augmented (the user can decide what to do if they care; the default is
to ignore it as done in early versions).
2001-09-24 20:22:09 +00:00
Fred Drake e822049efc Adapt to use the test_main() approach. 2001-09-24 20:19:08 +00:00
Fred Drake a3bae3369c Re-factor the SGMLParser class to use the new markupbase.ParserBase class.
Use a new internal method, error(), consistently to raise parse errors;
the new base class also uses this.
Adjust the parse_comment() method to return the new offset into the buffer
instead of the number of characters scanned; this was the only helper
method that did it this way, so we have better consistency now.  Required
to share the new base class.
This fixes SF bug #448482 and #453706.
2001-09-24 20:15:51 +00:00
Fred Drake bfc8fea1e0 Re-factor the HTMLParser class to use the new markupbase.ParserBase class.
Use a new internal method, error(), consistently to raise parse errors;
the new base class also uses this.
2001-09-24 20:10:28 +00:00
Fred Drake 1cffd5ccff Be consistent about the string module. 2001-09-24 20:04:29 +00:00
Fred Drake 68f8a8061d New base class for the SGMLParser and HTMLParser classes from the sgmllib
and HTMLParser modules (and indirectly for the htmllib.HTMLParser class).

This has all the support for scanning over DOCTYPE declarations; it warrants
having a base class since this is a fair amount of tedious code (since it's
fairly strict), and should be in a separate module to avoid compiling many
REs that are not used (which would happen if this were placed in either then
sgmllib or HTMLParser module).
2001-09-24 20:01:28 +00:00
Guido van Rossum 3d45d8f12e Another comparison patch-up: comparing a type with a dynamic metatype
to one with a static metatype raised an obscure error.
2001-09-24 18:47:40 +00:00
Fred Drake 2d879017b3 Add more tests showing the relationship between exceptions raised & caught
and the information provided to the profiler.  This stuff is a mess!
2001-09-24 18:44:11 +00:00
Guido van Rossum 2205642fe0 Do the same thing to complex that I did to str: the rich comparison
function returns NotImplemented when comparing objects whose
tp_richcompare slot is not itself.
2001-09-24 17:52:04 +00:00
Marc-André Lemburg e47df7a211 StringIO patch #462596: let's [c]StringIO accept read buffers on
input to .write() too.
2001-09-24 17:34:52 +00:00
Guido van Rossum bb77e6801e Change string comparison so that it applies even when one (or both)
arguments are subclasses of str, as long as they don't override rich
comparison.
2001-09-24 16:51:54 +00:00
Guido van Rossum ff0e6d6ef5 Fix the baffler that Tim reported: sometimes the repr() of an object
looks like <X object at ...>, sometimes it says <X instance at ...>.
Make this uniformly say <X object at ...>.
2001-09-24 16:03:59 +00:00
Steven M. Gava c11ccf35f4 start of new config handling stuff 2001-09-24 09:43:17 +00:00
Tim Peters fa26f7cc39 More work on class display:
+ Minor code cleanup, generalization and simplification.

+ "Do something" to make the attribute aggregation more apparent:
    - In text mode, stick a "* " at the front of subgroup header lines.
    - In GUI mode, display a horizontal rule between subgroups.
   For GUI mode, this is a huge improvement, at least under IE.
2001-09-24 08:05:11 +00:00
Tim Peters b47879b239 Try to do for pydoc's GUI mode what the earlier checkin did for text
mode (identify the source class for class attrs; segregate attrs according
to source class, and whether class method, static method, property, plain
method, or data; display data attrs; display docstrings for data attrs
when possible).

Alas, this is mondo ugly, and I'm no HTML guy.  Part of the problem is
that pydoc's GUI mode has always been ugly under IE, largely because
<small> under IE renders docstrings unreadably small (while sometimes
non-docstring text is painfully large).  Another part is that these
segregated listings of attrs would *probably* look much better as bulleted
lists.  Alas, when I tried that, the bullets all ended up on lines by
themselves, before the method names; this is apparently because pydoc
(ab?)uses definition lists for format effects, and at least under IE
if a definition list is the first chunk of a list item, it gets rendered
on a line after the <li> bullet.

An HTML wizard would certainly be welcomed here.
2001-09-24 04:47:19 +00:00
Tim Peters 28355496c1 Part of a partial solution to SF bugs 463378, 463381, 463383, 463384.
This almost entirely replaces how pydoc pumps out class docs, but only
in text mode (like help(whatever) from a Python shell), not in GUI mode.

A class C's attrs are now grouped by the class in which they're defined,
attrs defined by C first, then inherited attrs grouped by alphabetic order
of the defining classes' names.

Within each of those groups, the attrs are subgrouped according to whether
they're plain methods, class methods, static methods, properties, or data.
Note that pydoc never dumped class data attrs before.  If a class data
attr is implemented via a data descriptor, the data docstring (if any)
is also displayed (e.g., file.softspace).

Within a subgroup, the attrs are listed alphabetically.

This is a friggin' mess, and there are bound to be glitches.  Please
beat on it and complain!  Here are three glitches:

1. __new__ gets classifed as 'data', for some reason.  This will
   have to get fixed in inspect.py, but since the latter is already
   looking for any clue that something is a method, pydoc will
   almost certainly not know what to do with it when its classification
   changes.

2. properties are special-cased to death.  Unlike any other kind of
   function or method, they don't have a __name__ attr, so none of
   pydoc's usual code can deal with them.  Worse, the getter and
   setter and del'er methods associated with a property don't appear
   to be discoverable from Python, so there's really nothing I can
   think of to do here beyond just listing their names.

   Note that a property can't be given a docstring, either (or at least
   I've been unable to sneak one in) -- perhaps the property()
   constructor could take an optional doc argument?

3. In a nested-scopes world, pydoc still doesn't know anything about
   nesting, so e.g. classes nested in functions are effectively invisible.
2001-09-23 21:29:55 +00:00
Tim Peters 2c9aa5ea8d Generalize file.writelines() to allow iterable objects. 2001-09-23 04:06:05 +00:00
Barry Warsaw d31db7e939 The test data (mostly example messages) for the email package test
suite.  Note that other tests can put input data in this directory.
2001-09-23 03:19:33 +00:00
Barry Warsaw 4107585a67 An extensive test suite for the email package. 2001-09-23 03:18:13 +00:00
Barry Warsaw ba92580f01 The email package version 1.0, prototyped as mimelib
<http://sf.net/projects/mimelib>.  There /are/ API differences between
mimelib and email, but most of the implementations are shared (except
where cool Py2.2 stuff like generators are used).
2001-09-23 03:17:28 +00:00
Tim Peters 13b49d3374 New function classify_class_attrs(). As a number of SF bug reports
point out, pydoc doesn't tell you where class attributes were defined,
gets several new 2.2 features wrong, and isn't aware of some new features
checked in on Thursday <wink>.  pydoc is hampered in part because
inspect.py has the same limitations.  Alas, I can't think of a way to
fix this within the current architecture of inspect/pydoc:  it's simply
not possible in 2.2 to figure out everything needed just from examining
the object you get back from class.attr.  You also need the class
context, and the method resolution order, and tests against various things
that simply didn't exist before.  OTOH, knowledge of how to do that is
getting quite complex, so doesn't belong in pydoc.

classify_class_attrs takes a different approach, analyzing all
the class attrs "at once", and returning the most interesting stuff for
each, all in one gulp.  pydoc needs to be reworked to use this for
classes (instead of the current "filter dir(class) umpteen times against
assorted predicates" approach).
2001-09-23 02:00:29 +00:00
Tim Peters 8a9c284437 Make difflib.ndiff() and difflib.Differ.compare() generators. This
restores the 2.1 ability of Tools/scripts/ndiff.py to start producing
output before the entire comparison is complete.
2001-09-22 21:30:22 +00:00
Tim Peters e0b2d7ac9a Add a function to compute a class's method resolution order. This is
easy for 2.2 new-style classes, but trickier for classic classes, and
different approaches are needed "depending".  The function will allow
later code to treat all flavors of classes uniformly.
2001-09-22 06:10:55 +00:00
Tim Peters c377b16d12 Since the most likely failure mode for an expected-output test is a change
somewhere inside a line, use ndiff so that intraline difference marking
can point out what changed within a line.  I don't remember diff-style
abbreviations either (haven't used it since '94, except to produce
patches), so say the rest in English too.
2001-09-22 05:31:03 +00:00
Barry Warsaw bdefa0b3de __iter__(): New method so that StringIO's can participate in the
iterator protocol.
2001-09-22 04:34:54 +00:00
Barry Warsaw 7f8ff471f8 Converted test_StringIO.py to use unittest, so
Lib/test/output/test_StringIO is no longer necessary.

Also, added a test of the iterator protocol that's just been added to
StringIO's and cStringIO's.
2001-09-22 04:33:47 +00:00
Fred Drake 3208d4b387 Start of a test to make sure the profiler/tracer support in the core
interpreter is reporting what we expect to see.
2001-09-22 04:28:19 +00:00
Guido van Rossum 19c1cd5b35 Add the __getattr__ hook back. The rules are now:
- if __getattribute__ exists, it is called first;
  if it doesn't exists, PyObject_GenericGetAttr is called first.
- if the above raises AttributeError, and __getattr__ exists,
  it is called.
2001-09-21 21:24:49 +00:00
Guido van Rossum cf691935bb reportdiff(): print a "plain diff" style diff.
XXX This should really be a unified diff, but I can't be bothered.
2001-09-21 21:06:22 +00:00
Guido van Rossum 0a07639779 Oops. I didn't expect that some tests (test_cookie) have expected
output *and* doctest stuff.  Assuming the doctest stuff comes after the
expected output, this fixes that.
2001-09-21 20:45:44 +00:00
Guido van Rossum 0fcca4e815 Change the way unexpected output is reported: rather than stopping at
the first difference, let the test run till completion, then gather
all the output and compare it to the expected output using difflib.

XXX Still to do: produce diff output that only shows the sections that
differ; currently it produces ndiff-style output because that's the
easiest to produce with difflib, but this becomes a liability when the
output is voluminous and there are only a few differences.
2001-09-21 20:31:52 +00:00
Guido van Rossum 867a8d2e26 Change the name of the __getattr__ special method for new-style
classes to __getattribute__, to make it crystal-clear that it doesn't
have the same semantics as overriding __getattr__ on classic classes.

This is a halfway checkin -- I'll proceed to add a __getattr__ hook
that works the way it works in classic classes.
2001-09-21 19:29:08 +00:00
Guido van Rossum dbb718fa87 Make these modules work when Python is compiled without Unicode support. 2001-09-21 19:22:34 +00:00
Guido van Rossum 11310bf867 Add tests for repr() of strings containing string quotes as well. 2001-09-21 15:46:41 +00:00
Guido van Rossum e4874aeab0 Test basic functioning of unicode repr(). (If this breaks Jython,
please let me know and we'll figure out how to fix the test.)
2001-09-21 15:36:41 +00:00
Guido van Rossum 8b9cc7e69e Add a small test to verify that member and getset descriptors now have
docstrings (using file.closed and file.name as examples).
2001-09-20 21:49:53 +00:00
Guido van Rossum a56b42b1ba Change testdescr.py to use the test_main() approach. 2001-09-20 21:39:07 +00:00
Fred Drake 2e2be3760c Change the PyUnit-based tests to use the test_main() approach. This
allows using the tests with unittest.py as a script.  The tests will
still run when run as a script themselves.
2001-09-20 21:33:42 +00:00
Marc-André Lemburg 3508e30861 Fix Unicode .join() method to raise a TypeError for sequence
elements which are not Unicode objects or strings. (This matches
the string.join() behaviour.)

Fix a memory leak in the .join() method which occurs in case
the Unicode resize fails.

Restore the test_unicode output.
2001-09-20 17:22:58 +00:00
Marc-André Lemburg 5e89bd656f Update test output after the unicode() change. 2001-09-20 16:37:23 +00:00
Marc-André Lemburg 35b0cb09d7 Python part of the UTF-7 codec by Brian Quinlan. 2001-09-20 12:56:14 +00:00
Marc-André Lemburg 6871f6ac57 Implement the changes proposed in patch #413333. unicode(obj) now
works just like str(obj) in that it tries __str__/tp_str on the object
in case it finds that the object is not a string or buffer.
2001-09-20 12:53:16 +00:00