<peter@engcorp.com> based on a test script that's been kicking around my
home directory for a couple of months now and only saw the light of day
because I included it when I sent textwrap.py to python-dev for review.
than raising TypeError when the other argument is not a BaseSet. This
made it necessary to separate the implementation of e.g. __or__ from
the union method; the latter should not return NotImplemented but
raise TypeError. This is accomplished by making union(self, other)
return self|other, etc.; Python's binary operator machinery will raise
TypeError.
The idea behind this change is to allow other set implementations with
an incompatible internal structure; these can provide union (etc.) with
standard sets by implementing __ror__ etc.
I wish I could do this for comparisons too, but the default comparison
implementation allows comparing anything to anything else (returning
false); we don't want that (at least the test suite makes sure
e.g. Set()==42 raises TypeError). That's probably fine; otherwise
other set implementations would be constrained to implementing a hash
that's compatible with ours.
changed to use universal newlines.
Remove all imports from the compile() function; these are
now done at the top of the module ("Python normal form"),
and define a helper based on the platform instead of
testing the platform in the compile() function.
superficial errors and one deep one that aren't currently caught. I'm
headed for bed after this checkin.
- Fixed several typos introduced by Raymond Hettinger (through
cut-n-paste from my template): it's _as_temporarily_immutable, not
_as_temporary_immutable, and moreover when the element is added, we
should use _as_immutable.
- Made the seq argument to ImmutableSet.__init__ optional, so we can
write ImmutableSet() to create an immutable empty set.
- Rename the seq argument to Set and ImmutableSet to iterable.
- Add a Set.__hash__ method that raises a TypeError. We inherit a
default __hash__ implementation from object, and we don't want that.
We can then catch this in update(), so that
e.g. s.update([Set([1])]) will transform the Set([1]) to
ImmutableSet([1]).
- Added the dance to catch TypeError and try _as_immutable in the
constructors too (by calling _update()). This is needed so that
Set([Set([1])]) is correctly interpreted as
Set([ImmutableSet([1])]). (I was puzzled by a side effect of this
and the inherited __hash__ when comparing two sets of sets while
testing different powerset implementations: the Set element passed
to a Set constructor wasn't transformed to an ImmutableSet, and then
the dictionary didn't believe the Set found in one dict it was the
same as ImmutableSet in the other, because the hashes were
different.)
- Refactored Set.update() and both __init__() methods; moved the body
of update() into BaseSet as _update(), and call this from __init__()
and update().
- Changed the NotImplementedError in BaseSet.__init__ to TypeError,
both for consistency with basestring() and because we have to use
TypeError when denying Set.__hash__. Together those provide
sufficient evidence that an unimplemented method needs to raise
TypeError.
2045, section 5.2 states that if the Content-Type: header is
syntactically invalid, the default type should be text/plain.
Implement minimal sanity checking of the header -- it must have
exactly one slash in it. This closes SF patch #597593 by Skip, but in
a different way.
Note that these methods used to raise ValueError for invalid ctypes,
but now they won't.
get the MIME main and sub types, instead of getting the whole ctype
and splitting it here. The two more specific methods now correctly
implement RFC 2045, section 5.2.
Jeremy reported that this is not allowed by RFC 2396; however,
other tools support unescaped @'s so we should also.
Apply SF patch 596581 closing bug 581529.
Also, don't call gettempdir() in the default expression for the 'dir'
argument to various functions; use 'dir=None' for the default and
insert 'if dir is None: dir = gettemptir()' in the bodies. That way
the work done by gettempdir is postponed until needed.
Loosened the acceptable 'start' and 'stop' arguments so that any
Python (bounded) ints can be used. So, e.g., randrange(-sys.maxint-1,
sys.maxint) no longer blows up.
[ 587993 ] SET_LINENO killer
Remove SET_LINENO. Tracing is now supported by inspecting co_lnotab.
Many sundry changes to document and adapt to this change.
binary=True
to
text=False
by BDFL Pronouncement. All other changes follow from this. The change
to the docs is ready to go, but blocked by another JackMacLock in the
doc directory.
Although Cygwin attempts to be as Posix compliant
as possible, it has difficulties unlinking open
files. This is not surprising given that Cygwin is
dependent on Win32 which in turn has this problem
itself.
The attached tempfile patch acknowledges this
Cygwin limitation. Without this patch, Cygwin
fails test_tempfile (i.e., test_has_no_name) as
follows:
$ ./python -E -tt ../Lib/test/regrtest.py -l test_tempfile
test_tempfile
test test_tempfile failed -- Traceback (most recent call last):
File "/home/jt/src/PythonCvs/Lib/test/test_tempfile.py", line 689, in test_has_no_name
self.failOnException("rmdir", ei)
File "/home/jt/src/PythonCvs/Lib/test/test_tempfile.py", line 33, in failOnException
self.fail("%s raised %s: %s" % (what, ei[0], ei[1]))
File "/home/jt/src/PythonCvs/Lib/unittest.py", line 260, in fail
raise self.failureException, msg
AssertionError: rmdir raised exceptions.OSError: [Errno 90] Directory not empty: '/mnt/c/DOCUME~1/jatis/LOCALS~1/Temp/tmpM_z8nj'
do bizarre things to get a temp file, I changed it to use mkstemp instead
of NamedTemporaryFile. This tried to leave the file open while passing
its name to execfile(). On Win2K (but not Win9X), though, a file created
with O_TEMPORARY cannot be opened again, so the test failed with a
permission error when execfile tried to open it. Closer to the truth:
a file created with O_TEMPORARY can be opened again, but only if the
file is also created with SHARE_DELETE access via the Win32 CreateFile()
function. There's no way to get at that from MS's version of libc, though
(we'd have to ditch the "std" C file functions in favor of Win32 API
calls).
Close the bug report again -- this time for Cygwin due to a newlib bug.
See the following for the details:
http://sources.redhat.com/ml/newlib/2002/msg00369.html
Note that this commit is only a documentation (i.e., comment) change.
test was written. So boosted the number of "digits" this generates, and
also beefed up the "* / divmod" test to tickle numbers big enough to
trigger the Karatsuba algorithm. It takes about 2 seconds now on my box.
rewrite, by Zack Weinberg). This replaces most code in tempfile.py
(please review!!!) and adds extensive unit tests for it.
This will cause some warnings in the test suite; I'll check those in
soon, and also the docs.
least on OS/2 (see note on SF patch 555085 by A I MacIntyre) but
looks like the test *could* fail on any other platform too -- there's
no guarantee that recv() reads all data.
to delete the reference to self._sock, and the regular destructor will
do that just fine. This made some hacks in close() unnecessary.
The _fileobject class still has a __del__ method, because it must flush.
observation that _rbuf could never have more than one string in it.
So make _rbuf a string. The code branches for size<0 and size>=0
are completely separate now, both in read() and in readline().
I checked for tabs this time. :-)
to being a new-style class, to be more similar to the socket class
in the _socket module; it is now the same as the _socketobject class.
Added __slots__. Added docstrings, copied from the real socket class
where possible.
The _fileobject class is now also a new-style class with __slots__
(though without docstrings). The mode, name, softspace, bufsize and
closed attributes are properly supported (closed as a property; name
as a class attributes; the softspace, mode and bufsize as slots).
correctly (the test at least succeed, but they don't test everything yet).
Also fix a performance problem in read(-1): in unbuffered mode, this would
read 1 byte at a time. Since we're reading until EOF, that doesn't make
sense. Use the default buffer size if _rbufsize is <= 1.
prints function and module names, which is more informative now that
we repeat some tests in slightly modified subclasses.
Add a test for read() until EOF.
Add test suites for line-buffered (bufsize==1) and a small custom
buffer size (bufsize==2).
Restructure testUnbufferedRead() somewhat to avoid a potentially
infinite loop.
and this broke a Zope "pipelining" test which read multiple responses
from the same connection (this attaches a new file object to the
socket for each response). Added a test for this too.
(I want to do some code cleanup too, but I thought I'd first fix
the problem with as little code as possible, and add a unit test
for this case. So that's what this checkin is about.)
1) Do not attempt to exec a file which does not exist
just to find out what error the operating system
returns. This is an exploitable race on all platforms
that support symbolic links.
2) Immediately re-raise the exception if we get an
error other than errno.ENOENT or errno.ENOTDIR. This
may need to be adapted for other platforms.
(As a security issue, this should be considered for 2.1
and 2.2 as well as 2.3.)
on Windows. The test_sequence() ERROR is easily repaired if we're
willing to add an os.unlink() line to mhlib's updateline(). The
test_listfolders FAIL I gave up on -- I don't remember enough about Unix
link esoterica to recall why a link count of 2 is something a well-
written program should be keenly interested in <wink>.
substantially fewer array-element compares. This is best practice as of
Kntuh Volume 3 Ed 2, and the code is actually simpler this way (although
the key idea may be counter-intuitive at first glance! breaking out of
a loop early loses when it costs more to try to get out early than getting
out early saves).
Also added a comment block explaining the difference and giving some real
counts; demonstrating that heapify() is more efficient than repeated
heappush(); and emphasizing the obvious point thatlist.sort() is more
efficient if what you really want to do is sort.
Added new heapify() function, which transforms an arbitrary list into a
heap in linear time; that's a fundamental tool for using heaps in real
life <wink>.
Added heapyify() test. Added a "less naive" N-best algorithm to the test
suite, and noted that this could actually go much faster (building on
heapify()) if we had max-heaps instead of min-heaps (the iterative method
is appropriate when all the data isn't known in advance, but when it is
known in advance the tradeoffs get murkier).
at random, and replaces the elements at those positions with new random
values. I was pleasantly surprised by how fast this goes! It's hard to
conceive of an algorithm that could special-case for this effectively.
Plus it's exactly what happens if a burst of gamma rays corrupts your
sorted database on disk <wink>.
i 2**i *sort ... %sort
15 32768 0.18 ... 0.03
16 65536 0.24 ... 0.04
17 131072 0.53 ... 0.08
18 262144 1.17 ... 0.16
19 524288 2.56 ... 0.35
20 1048576 5.54 ... 0.77
and age of rampant computer breakins I imagine there are plenty of systems
with telnet disabled. Successful check of at least one getservbyname() call
is required for success
in the stability tests.
Bizarre: this takes 11x longer to run if and only if test_longexp is
run before it, on my box. The bigger REPS is in test_longexp, the
slower this gets. What happens on your box? It's not gc on my box
(which is good, because gc isn't a plausible candidate here).
The slowdown is massive in the parts of test_sort that implicitly
invoke a new-style class's __lt__ or __cmp__ methods. If I boost
REPS large enough in test_longexp, even the test_sort tests on an array
of size 64 visibly c-r-a-w-l. The relative slowdown is even worse in
a debug build. And if I reduce REPS in test_longexp, the slowdown in
test_sort goes away.
test_longexp does do horrid things to Win98's management of user
address space, but I thought I had made that a whole lot better a month
or so ago (by overallocating aggressively in the parser).
If the long is large enough, the return value will be a negative int.
In this case, calling the function a second time won't return the
original value passed in.
imports of test modules now import from the test package. Other
related oddities are also fixed (like DeprecationWarning filters that
weren't specifying the full import part, etc.). Also did a general
code cleanup to remove all "from test.test_support import *"'s. Other
from...import *'s weren't changed.
See there for a description.
Added test case.
Bugfix candidate for 2.2.x, not sure about previous versions:
probably low priority, because virtually no one runs debug builds.
to executing Run/F5 from an EditorWindow.
M ScriptBinding.py : add call to clear_the_environment()
M run.py : implemented Executive.clear_the_environment()
imports e.g. test_support must do so using an absolute package name
such as "import test.test_support" or "from test import test_support".
This also updates the README in Lib/test, and gets rid of the
duplicate data dirctory in Lib/test/data (replaced by
Lib/email/test/data).
Now Tim and Jack can have at it. :)
array. Our samplesort special-cases the snot out of this, running about
12x faster than *sort. The experimental mergesort runs it about 8x
faster than *sort without special-casing, but should really do better
than that (when merging runs of different lengths, right now it only
does something clever about finding where the second run begins in
the first and where the first run ends in the second, and that's more
of a temp-memory optimization).
from test.test_support import TestSkipped, run_unittest
to
from test_support import TestSkipped, run_unittest
Otherwise, if the Japanese codecs aren't installed, regrtest doesn't
believe the TestSkipped exception raised by this test matches the
except (ImportError, test_support.TestSkipped), msg:
it's looking for, and reports the skip as a crash failure instead of
as a skipped test.
I suppose this will make it harder to run this test outside of
regrtest, but under the assumption only Barry does that, better to
make it skip cleanly for everyone else.
(i.e. email.test), so move the guts of them here from Lib/test. The
latter directory will retain stubs to run the email.test tests using
Python's standard regression test.
test_email_torture.py is a torture tester which will not run under
Python's test suite because I don't want to commit megs of data to
that project (it will fail cleanly there). When run under the mimelib
project it'll stress test the package with megs of message samples
collected from various locations in the wild.