give minidom.py behaviour that complies with the DOM Level 1 REC,
which says that when a node newChild is added to the tree, "if the
newChild is already in the tree, it is first removed."
pulldom.py is patched to use the public minidom interface instead
of setting .parentNode itself. Possibly this reduces pulldom's
efficiency; someone else will have to pronounce on that.
so we can't use it.
While I'm at it, got rid of string module use. (Found several new
hard special cases for a hypothetical conversion tool: from string
import join, find, rfind; and a local assignment "find=string.find".)
required to work around restrictions on the arguments of
u.translate():
1) don't pass the deletions argument if it's empty;
2) convert table to Unicode if s is Unicode.
This fixes SF bug #124060.
bugs #126161 and 123634).
The solution doesn't use the unicode-escape encoding; that has other
problems (it seems not 100% reversible). Rather, it transforms the
input Unicode object slightly before encoding it using
raw-unicode-escape, so that the decoding will reconstruct the original
string: backslash and newline characters are translated into their
\uXXXX counterparts.
This is backwards incompatible for strings containing backslashes, but
for some of those strings, the pickling was already broken.
obsolete!).
Fix a bug in ftpwrapper.retrfile() where somehow ftplib.error_perm was
assumed to be a string. (The fix applies str().)
Also break some long lines and change the output from test() slightly.
Make Node inherit from xml.dom.Node to pick up the NodeType values
defined by the W3C recommendation.
When raising AttributeError, be sure to provide the name of the attribute
that does not exist.
Node.normalize(): Make sure we do not allow an empty text node to survive
as the first child; update the sibling links properly.
_getElementsByTagNameNSHelper(): Make recursive calls using the right
number of parameters.
Attr.__setattr__(): Be sure to update name and nodeName at the same time
since they are synonyms for this node type.
AttributeList: Renamed to NamedNodeMap (AttributeList maintained as an
alias). Compute the length attribute dynamically to allow
the underlying structures to mutate.
AttributeList.item(): Call .keys() on the dictionary rather than using
self.keys() for performance.
AttributeList.setNamedItem(), .setNamedItemNS():
Added methods.
Text.splitText():
Added method.
DocumentType:
Added implementation class.
DOMImplementation:
Added implementation class.
Document.appendChild(): Do not allow a second document element to be added.
Document.documentElement: Find this dynamically, so that one can be
removed and another added.
Document.unlink(): Clear the doctype attribute.
_get_StringIO(): Only use the StringIO module; cStringIO does not support
Unicode.
objects; uses minidom if one is not provided to the constructor.
parse(): Pick up the default_bufsize default value dynamically so that
the value in the module may be (meaningfully) changed at runtime.
This (partially) closes patch #102477.
can't be imported. This makes StringIO.py work with Jython.
Also, get rid of the string module by converting to string methods.
Shorten some lines by using augmented assignment where appropriate.
encodings package aliases mapping dictionary rather than in the
internal cache used by the search function.
This enables aliases to take advantage of the full normalization
process applied to encoding names which was previously not available.
The patch restricts alias registration to new aliases. Existing
aliases cannot be overridden anymore.
roundtrip(): Show the offending syntax tree when things break; this makes
it a little easier to debug the module by adding test cases.
(Still need better tests for this module, but there's not enough time
today.)
socket in httplib.py.
The bug reports that on Windows, you must pass sock._sock to the
socket.ssl() call. But on Unix, you must pass sock itself. (sock is
a wrapper on Windows but not on Unix; the ssl() call wants the real
socket object, not the wrapper.)
So we see if sock has an _sock attribute and if so, extract it.
Unfortunately, the submitter of the bug didn't confirm that this patch
works, so I'll just have to believe it (can't test it myself since I
don't have OpenSSL on Windows set up, and that's a nontrivial thing I
believe).
- Use new Error class (subclass of RuntimeError so is backward
compatible) which is raised when RuntimeError used to be raised.
- Report original attribute name in error messages instead of name
mangled with namespace URL.
also test join method of 8-bit strings.
Also changed the test() function to (1) compare the types of the
expected and actual result, and (2) in verbose mode, print the repr()
of the output.
testAAA(),
testAAB(): Added checks that the results are right.
testTooManyDocumentElements(): Added code to actually test this.
testCloneElementDeep()
testCloneElementShallow(): Filled these in with test code.
_testCloneElementCopiesAttributes(),
_setupCloneElement(): Helper functions used with the other
testCloneElement*() functions.
testCloneElementShallowCopiesAttributes(): No longer a separate test;
_setupCloneElement() uses _testCloneElementCopiesAttributes() to
test that this is always done.
testNormalize(): Added to check Node.normalize().
behavior.
Added support for the Attr.ownerElement attribute.
Everywhere: Define constant object attributes in the classes rather than
on the instances during object construction. This reduces the amount of
work needed for object construction and destruction; these need to be
lightweight operations on a DOM.
Node._get_firstChild(),
Node._get_lastChild(): Return None if there are no children (required for
compliance with DOM level 1).
Node.insertBefore(): If refChild is None, append the new node instead of
failing (required for compliance). Also, update the sibling
relationships. Return the inserted node (required for compliance).
Node.appendChild(): Update the parent of the appended node.
Node.replaceChild(): Actually replace the old child! Update the parent
and sibling relationships of both the old and new children. Return
the replaced child (required for compliance).
Node.normalize(): Implemented the normalize() method. Required for
compliance, but missing from the release. Useful for joining
adjacent Text nodes into a single node for easier processing.
Node.cloneNode(): Actually make this work. Don't let the new node share
the instance __dict__ with the original. Do proper recursion if
doing a "deep" clone. Move the attribute cloning out of the base
class, since only Element is supposed to have attributes.
Node.unlink(): Simplify handling of child nodes for efficiency, and
remove the attribute handling since only Element nodes support
attributes.
Attr.cloneNode(): Extend this to clear the ownerElement attribute in
the clone.
AttributeList.items(),
AttributeList.itemsNS(): Slight performance improvement (avoid lambda).
Element.cloneNode(): Extend Node.cloneNode() with support for the
attributes. Clone the Attr objects after creating the underlying
clone.
Element.unlink(): Clean out the attributes here instead of in the base
class, since this is the only class that will have them.
Element.toxml(): Adjust to create only one AttributeList instance; minor
efficiency improvement.
_nssplit(): No need to re-import string.
Document.__init__(): No longer needed once constant attributes are
initialized in the class itself.
Document.createElementNS(),
Document.createAttributeNS(): Use the defined constructors rather than
directly access the classes.
_get_StringIO(): New function. Create an output StringIO using the most
efficient available flavor.
parse(),
parseString(): Import pulldom here instead of in the public namespace of
the module.
file uploads.
In response to SF bugs 110674 and 119806, and discussions on
python-dev, we are removing the self.lines attribute from the
FieldStorage class. Specifically touched where methods __init__(),
read_lines_to_eof(), and skip_lines().
No one can remember why self.lines was added. Technically, it's part
of the public interface for the class, but it was never documented.
It's possible clever or nosy code will break because of this, but it
was decided to remove it and see who complains.
This resolution also closes the second half of the cgi.py entry in PEP
42. The first half of that PEP concerns specifically binary file
uploads, where there may be no end-of-line marker for a very long
time. This patch does not address that issue.
embedded code objects (e.g. functions) rather than the generated code
object. This change means that the compiler generates code for
everything at the end, rather then generating code for each function
as it finds it. Implementation note: _convert_LOAD_CONST in
pyassem.py must be change to call getCode().
Other changes follow. Several changes creates extra edges between
basic blocks to reflect control flow for loops and exceptions. These
missing edges had gone unnoticed because they do not affect the
current compilation process.
pyassem.py:
Add _enable_debug() and _disable_debug() methods that print
instructions and blocks to stdout as they are generated.
Add edges between blocks for instructions like SETUP_LOOP,
FOR_LOOP, etc.
Add pruneNext to get rid of bogus edges remaining after
unconditional transfer ops (e.g. JUMP_FORWARD)
Change repr of Block to omit block length.
pycodegen.py:
Make sure a new block is started after FOR_LOOP, etc.
Change assert implementation to use RAISE_VARARGS 1 when there is
no user-specified failure output.
misc.py:
Implement __contains__ and copy for Set.
When a method is called with no regular arguments and * args, defer
the first arg is subclass check until after the * args have been
expanded.
N.B. The CALL_FUNCTION implementation is getting really hairy; should
review it to see if it can be simplified.
-- fixed negative lookbehind to work correctly at the beginning
of the target string (bug #117242)
-- improved syntax check; you can no longer refer to a group
inside itself (bug #110866)
Reformatting -- long lines, "[ ]" -> "[]", a few indentation nits.
Replace calls to Node function (which constructed ast nodes) with
calls to actual constructors imported from ast module.
Optimize com_node (most frequently used method) for the common case --
the appropriate method is found in _dispatch.
Fix com_augassign to use class object's rather than node names
(rendered invalid by recent changes to ast)
Remove expensive tests for sequence-ness in com_stmt and
com_append_stmt. These tests should never fail; if they do, something
is really broken and exception will be raised elsewhere.
Fix com_stmt and com_append_stmt to use isinstance rather than
testing's type slot of ast node (this slot disappeared with recent
changes to ast).
Betlehem, verified by Peter Funk. Fixes preservation of language
search order lost due to use of dictionary keys instead of a list.
Closes SF bug #116964.
1.5.2. The compiler generates code for the version of the interpreter
it is run under.
ast.py:
Print and Printnl add dest attr for extended print
new node AugAssign for augmented assignments
new nodes ListComp, ListCompFor, and ListCompIf for list
comprehensions
pyassem.py:
add work around for string-Unicode comparison raising UnicodeError
on comparison of two objects in code object's const table
pycodegen.py:
define VERSION, the Python major version number
get magic number using imp.get_magic() instead of hard coding
implement list comprehensions, extended print, and augmented
assignment; augmented assignment uses Delegator classes (see
doc string)
fix import and tuple unpacking for 1.5.2
transformer.py:
various changes to support new 2.0 grammar and old 1.5 grammar
add debug_tree helper than converts and symbol and token numbers
to their names
First, only report garbage that the GC cannot free. Second, only report
the number of objects found, not their repr(). People can dig deeper on
their own if they find a leak.
- don't close the fp, since that appears to also close the socket
- join the original url with the redirect reponse to deal with
relative redirect URL
wrap two socket ops in try/except to turn them into URLErrors, so that
client code need only catch one exception.
in HTTPError.__del__ only close fp if fp is not None
style changes:
- use f(*args) instead of apply(f, args)
- use __super_init instead of super.__init__(self, ...)
Let's hope this is correct (I'm not sure why the sys.platform would be
'Darwin1.2' rather than 'darwin1', which seems to be the convention).
Someone with Darwin please test this!
libm result is 0). Cautiously add a few libm exception test cases:
1. That exp(-huge) returns 0 without exception.
2. That exp(+huge) triggers OverflowError.
3. That sqrt(-1) raises ValueError specifically (apparently under glibc linked
with -lieee, it was raising OverflowError due to an accident of the way
mathmodule.c's CHECK() macro happened to deal with Infs and NaNs under gcc).
support for extension types, not classes.
pickle(): If the type is a class or if the reduction function is not
callable, raise a TypeError.
constructor(): If the constructor is not callable, raise TypeError.
This (partially) closes SourceForge patch #101859.
didn't bother to close the files. This caused the new test_wave test to fail
under Windows, as Windows won't let you delete a file that's open. Fixed
that by ensuring the wave read & write classes' .close() and __del__ methods
close files that were opened by their constructors.
driver code, so that each test gets this; it had been done inconsistently.
Remove the lines that set the variables holding dom objects to None; not
needed since the interpreter cleans up locals on function return.
Lownds. (#101816)
[Note: I'm not sure that this is really the right fix. Surely Darwin
doesn't require you to say "python.exe" everywhere??? Even Windows
doesn't! Or am I misunderstanding the point?]