exception occurred so it should only be closed in the else clause.
Without this change we can an UnboundLocalError on Linux:
Traceback (most recent call last):
File "Lib/test/test_mmap.py", line 304, in ?
test_both()
File "Lib/test/test_mmap.py", line 208, in test_both
m.close()
UnboundLocalError: local variable 'm' referenced before assignment
with a size larger than the underlying file worked on Windows. It
does <wink>. However, merely creating an mmap that way has the side
effect of growing the file on disk to match the specified size. A
*later* test assumed that the file on disk was still exactly as it was
before the new "size too big" test was added, but that's no longer true.
So added a hack at the end of the "size too big" test to truncate the
disk file back to its original size on Windows.
_handle_text(): Use _isstring() for stringiness test.
_handle_multipart(): Add a test before the ListType test, checking for
stringiness of the payload. String payloads for multitypes means a
message with broken MIME chrome was parsed by a lax parser. Instead
of raising a BoundaryError in those cases, the entire body is assigned
to the message payload (but since the content type is still
multipart/*, the Generator needs to be updated too).
the same. Added check to verify the two names are not the same. Does not
check the actual files to see if there is a symbolic link.
Closes SF bug 490165 and Tzot's patch 604600.
Add read(), write(), and readwrite() helper functions to shorten poll
functions. Use get() instead of try/except KeyError for lookup.
XXX How could the lookup ever fail?
Remove module-level DEBUG flag.
Use iteritems() instead of items() when walking the socket map.
Reformat the functions I touched so that are consistently Pythonic.
from SF patch http://www.python.org/sf/554192
This adds two new functions to mimetypes:
guess_all_extensions() which returns a list of all known
extensions for a mime type, and add_type() which adds one
mapping between a mime type and an extension.
Broytmann in SF patch #600096. Specifically, the former function now
encodes the triplets, while the latter adds optional charset and
language arguments.
M RemoteDebugger.py
M ScriptBinding.py
Restart the execution server with a clean environment and execute the
active module from scratch upon activation of Run/F5.
Add functionality to PyShell.py to restart the execution server in a new
subprocess. The server makes a connection to the Idle client which sends a
block of code to be executed.
Modify ScriptBinding.py to restart the subprocess upon Run/F5, assuming that
an execution is not currently in progress. Remove Import Module functionality,
not required now that the code is executed in a clean environment.
If the Debugger is active, also restart the subprocess side of the split
debugger. Add functionality to RemoteDebugger.py to support this.
At this time breakpoints will be lost in the subprocess if Run/F5 is activated.
A subsequent checkin of PyShell.py will implement reloading of the breakpoints
into the subprocess debugger. I'm keeping this separate as the design may
change.
The problem was that it expected rfc822.parseaddr() to return None
upon a parse failure. The actual, documented return value for a
parse failure is (None, None).
Closes SF bug 602029.
Unicode strings (with arbitrary length) are allowed
as entries in the unicode.translate mapping.
Add a test case for multicharacter replacements.
(Multicharacter replacements were enabled by the
PEP 293 patch)
to fix it. (It fails when the day of the month is a 1-digit number,
because %c produces space+digit there, while strptime seems to expect
zero+digit somehow.)
The new execvpe code would sometimes do the wrong thing when a
non-executable file existed earlier in the path and an executable file
of the same name existed later in the path. This patch restores the
proper behavior (which is to execute the second file). When only a
non-executable file exists, the correct error is still reported.
of PyString_DecodeEscape(). This prevents a call to
_PyString_Resize() for the empty string, which would
result in a PyErr_BadInternalCall(), because the
empty string has more than one reference.
This closes SF bug http://www.python.org/sf/603937
Use a slightly different strategy to determine when not to call the line
trace function. This removes the need for the RETURN_NONE opcode, so
that's gone again. Update docs and comments to match.
Thanks to Neal and Armin!
Also add a test suite. This should have come with the original patch...
because it added it to 12 PM too. 12 PM should be hour 12 not hour
24.
Also cleaned up a minor style nit. There are more style problems in
this file that I'll clean up next (but I didn't want them to overwhelm
the substance of this fix).
localtime, which in -0400 is 12 noon GMT. The bug boiled down to
broken conversion of 12 PM to hour 12 for the '%I %p' format string.
Added a test for this specific condition: Strptime12AMPMTests. Fix to
_strptime.py coming momentarily.
the tokenize module by test_tokenize.py. The FutureWarnings only
appeared during installation, and I've figured out a way to suppress
those in a different way.
sure these are the best fixes.
- Test maxint-1 against the negative octal constant -020000000000
- Comment out the tests for oct -1 and hex -1, since 037777777777 and
0xffffffff raise FutureWarnings now and in Python 2.4 those
constants will produce positive values, not negative values. So the
existing test seems to test something that won't be true in 2.4.
instead.
2. Preserve the Idle client's listening socket for reuse with the
fresh subprocess.
3. Remove some unused rpc code, comment out additional unused code.
Modified Files:
ScriptBinding.py rpc.py run.py
underlying dictionaries, there were no reasonable use cases (lexicographic
sorting of a list of sets is somewhat esoteric). Frees the operators
for other uses (such as strict subset and superset comparisons).
Updated documentation and test suite accordingly.
the inplace operators. The strategy is to have the operator overloading
code do the work and then to define equivalent method calls which rely on
the operators. The changes facilitate proper application of TypeError
and NonImplementedErrors.
Added corresponding tests to the test suite to make sure both the operator
and method call versions get exercised.
Add missing tests for difference_update().
immediately after the comparison, there in no use in caching the hashcode.
The test, 'if self._hashcode is None', never fails. Removing the caching
saves a few lines and a little time.
2. Replaced calls to Set([]) with Set() -- Timbot's suggestion
3. Fixed subtle bug in sets of sets:
The following code did not work (will add to test suite):
d = Set('d')
s = Set([d]) # Stores inner set as an ImmutableSet
s.remove(d) # For comparison, wraps d in _TemporarilyImmutableSet
The comparison proceeds by computing the hash of the
_TemporarilyImmutableSet and finding it in the dictionary.
It then verifies equality by calling ImmutableSet.__eq__()
and crashes from the binary sanity check.
The problem is that the code assumed equality would be checked
with _TemporarilyImmutableSet.__eq__().
The solution is to let _TemporarilyImmutableSet derive from BaseSet
so it will pass the sanity check and then to provide it with the
._data element from the wrapped set so that ImmutableSet.__eq__()
will find ._data where it expects.
Since ._data is now provided and because BaseSet is the base class,
_TemporarilyImmutableSet no longer needs .__eq__() or .__ne__().
Note that inheriting all of BaseSet's methods is harmless because
none of those methods (except ones starting with an underscore)
can mutate the .data element. Also _TemporarilyImmutableSet is only
used internally as is not otherwise visible.
wrong thing for a unicode subclass when there were zero string
replacements. The example given in the SF bug report was only one way
to trigger this; replacing a string of length >= 2 that's not found is
another. The code would actually write outside allocated memory if
replacement string was longer than the search string.
(I wonder how many more of these are lurking? The unicode code base
is full of wonders.)
Bugfix candidate; this same bug is present in 2.2.1.
base class (WrapperTestCase) instead, and call it repeatedly in the
methods that used to have a loop-over-subcases. Much simpler.
Rename perennial temp variable 't' to 'text'.
<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.