| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 74b944a commit d636e3c
11 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -172,6 +172,20 @@ XMLParser Objects | |||
| 172 | 172 | or ``None`` if :meth:`SetBase` hasn't been called. | |
| 173 | 173 | ||
| 174 | 174 | ||
| 175 | + .. method:: xmlparser.GetSpecifiedAttributeCount() | ||
| 176 | + | ||
| 177 | + Return the index just past the attributes given in the start tag. | ||
| 178 | + Attributes defaulted from the DTD follow the specified ones, | ||
| 179 | + so attributes at lower indices in the list | ||
| 180 | + passed to :attr:`StartElementHandler` were given in the start tag. | ||
| 181 | + Each attribute takes two items in that list, | ||
| 182 | + its name and its value. | ||
| 183 | + Only meaningful inside a :attr:`StartElementHandler` call, | ||
| 184 | + and only if :attr:`ordered_attributes` is true. | ||
| 185 | + | ||
| 186 | + .. versionadded:: next | ||
| 187 | + | ||
| 188 | + | ||
| 175 | 189 | .. method:: xmlparser.GetInputContext() | |
| 176 | 190 | ||
| 177 | 191 | Returns the input data that generated the current event as a string. The data is | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -261,23 +261,31 @@ rules apply: | |||
| 261 | 261 | :attr:`~xml.dom.DocumentType.notations` are read-only and support only | |
| 262 | 262 | ``len()`` and subscription by a name. | |
| 263 | 263 | ||
| 264 | - * :attr:`~xml.dom.Document.strictErrorChecking` and | ||
| 265 | - :attr:`~xml.dom.Attr.specified` are always ``False``. | ||
| 264 | + * :attr:`~xml.dom.Document.strictErrorChecking` is always ``False``. | ||
| 266 | 265 | ||
| 267 | - * :meth:`~xml.dom.Element.removeAttribute` and | ||
| 268 | - :meth:`~xml.dom.Element.removeAttributeNS` raise | ||
| 269 | - :exc:`~xml.dom.NotFoundErr` if there is no matching attribute, | ||
| 270 | - while the DOM specifies that this has no effect. | ||
| 266 | + .. versionchanged:: next | ||
| 267 | + Previously, :attr:`~xml.dom.Attr.specified` was always ``False``. | ||
| 268 | + | ||
| 269 | + * The constraints of the DOM are now enforced, | ||
| 270 | + and the corresponding exceptions are raised. | ||
| 271 | + | ||
| 272 | + .. versionchanged:: next | ||
| 273 | + Previously, many invalid operations silently succeeded | ||
| 274 | + and produced an invalid document, | ||
| 275 | + but removing an absent attribute raised :exc:`~xml.dom.NotFoundErr`. | ||
| 271 | 276 | ||
| 272 | 277 | The following interfaces have no implementation in :mod:`!xml.dom.minidom`: | |
| 273 | 278 | ||
| 274 | 279 | * :class:`DOMTimeStamp` | |
| 275 | 280 | ||
| 276 | - * :class:`EntityReference` | ||
| 277 | - | ||
| 278 | - Most of these reflect information in the XML document that is not of general | ||
| 281 | + This reflects information in the XML document that is not of general | ||
| 279 | 282 | utility to most DOM users. | |
| 280 | 283 | ||
| 284 | + .. versionchanged:: next | ||
| 285 | + :class:`~xml.dom.EntityReference` is now implemented. | ||
| 286 | + Note that the parser expands entity references, | ||
| 287 | + so they only occur in a document if created explicitly. | ||
| 288 | + | ||
| 281 | 289 | .. rubric:: Footnotes | |
| 282 | 290 | ||
| 283 | 291 | .. [1] The encoding name included in the XML output should conform to | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -232,6 +232,8 @@ DOM Level 2 added the ability to create new :class:`Document` and | |||
| 232 | 232 | *qualifiedName*, *publicId*, and *systemId* strings, representing the | |
| 233 | 233 | information contained in an XML document type declaration. | |
| 234 | 234 | ||
| 235 | + Raise :exc:`InvalidCharacterErr` if the name is not a valid XML name. | ||
| 236 | + | ||
| 235 | 237 | ||
| 236 | 238 | .. _dom-node-objects: | |
| 237 | 239 | ||
@@ -457,6 +459,10 @@ for each node type are: | |||
| 457 | 459 | children, returning *newChild*. If the node was already in | |
| 458 | 460 | the tree, it is removed first. | |
| 459 | 461 | ||
| 462 | + Raise :exc:`WrongDocumentErr` if *newChild* was created by another | ||
| 463 | + document, and :exc:`HierarchyRequestErr` if it is this node itself or | ||
| 464 | + its ancestor. | ||
| 465 | + | ||
| 460 | 466 | ||
| 461 | 467 | .. method:: Node.insertBefore(newChild, refChild) | |
| 462 | 468 | ||
@@ -465,6 +471,10 @@ for each node type are: | |||
| 465 | 471 | *newChild* is returned. If *refChild* is ``None``, it inserts *newChild* at the | |
| 466 | 472 | end of the children's list. | |
| 467 | 473 | ||
| 474 | + Raise :exc:`WrongDocumentErr` if *newChild* was created by another | ||
| 475 | + document, and :exc:`HierarchyRequestErr` if it is this node itself or | ||
| 476 | + its ancestor. | ||
| 477 | + | ||
| 468 | 478 | ||
| 469 | 479 | .. method:: Node.removeChild(oldChild) | |
| 470 | 480 | ||
@@ -479,6 +489,10 @@ for each node type are: | |||
| 479 | 489 | Replace an existing node with a new node. It must be the case that *oldChild* | |
| 480 | 490 | is a child of this node; if not, :exc:`NotFoundErr` is raised. | |
| 481 | 491 | ||
| 492 | + Raise :exc:`WrongDocumentErr` if *newChild* was created by another | ||
| 493 | + document, and :exc:`HierarchyRequestErr` if it is this node itself or | ||
| 494 | + its ancestor. | ||
| 495 | + | ||
| 482 | 496 | ||
| 483 | 497 | .. method:: Node.normalize() | |
| 484 | 498 | ||
@@ -665,6 +679,8 @@ inherits properties from :class:`Node`. | |||
| 665 | 679 | document when it is created. You need to explicitly insert it with one of the | |
| 666 | 680 | other methods such as :meth:`~Node.insertBefore` or :meth:`~Node.appendChild`. | |
| 667 | 681 | ||
| 682 | + Raise :exc:`InvalidCharacterErr` if the name is not a valid XML name. | ||
| 683 | + | ||
| 668 | 684 | ||
| 669 | 685 | .. method:: Document.createElementNS(namespaceURI, tagName) | |
| 670 | 686 | ||
@@ -673,6 +689,8 @@ inherits properties from :class:`Node`. | |||
| 673 | 689 | need to explicitly insert it with one of the other methods such as | |
| 674 | 690 | :meth:`~Node.insertBefore` or :meth:`~Node.appendChild`. | |
| 675 | 691 | ||
| 692 | + Raise :exc:`InvalidCharacterErr` if the name is not a valid XML name. | ||
| 693 | + | ||
| 676 | 694 | ||
| 677 | 695 | .. method:: Document.createTextNode(data) | |
| 678 | 696 | ||
@@ -681,6 +699,16 @@ inherits properties from :class:`Node`. | |||
| 681 | 699 | tree. | |
| 682 | 700 | ||
| 683 | 701 | ||
| 702 | + .. method:: Document.createEntityReference(name) | ||
| 703 | + | ||
| 704 | + Create and return a new entity reference node. | ||
| 705 | + The node is not inserted into the document when it is created. | ||
| 706 | + | ||
| 707 | + Raise :exc:`InvalidCharacterErr` if the name is not a valid XML name. | ||
| 708 | + | ||
| 709 | + .. versionadded:: next | ||
| 710 | + | ||
| 711 | + | ||
| 684 | 712 | .. method:: Document.createComment(data) | |
| 685 | 713 | ||
| 686 | 714 | Create and return a comment node containing the data passed as a parameter. As | |
@@ -694,6 +722,8 @@ inherits properties from :class:`Node`. | |||
| 694 | 722 | *data* passed as parameters. As with the other creation methods, this one does | |
| 695 | 723 | not insert the node into the tree. | |
| 696 | 724 | ||
| 725 | + Raise :exc:`InvalidCharacterErr` if the name is not a valid XML name. | ||
| 726 | + | ||
| 697 | 727 | ||
| 698 | 728 | .. method:: Document.createAttribute(name) | |
| 699 | 729 | ||
@@ -702,6 +732,8 @@ inherits properties from :class:`Node`. | |||
| 702 | 732 | :meth:`~Element.setAttributeNode` on the appropriate :class:`Element` object | |
| 703 | 733 | to use the newly created attribute instance. | |
| 704 | 734 | ||
| 735 | + Raise :exc:`InvalidCharacterErr` if the name is not a valid XML name. | ||
| 736 | + | ||
| 705 | 737 | ||
| 706 | 738 | .. method:: Document.createAttributeNS(namespaceURI, qualifiedName) | |
| 707 | 739 | ||
@@ -710,6 +742,8 @@ inherits properties from :class:`Node`. | |||
| 710 | 742 | element. You must use :meth:`~Element.setAttributeNode` on the appropriate | |
| 711 | 743 | :class:`Element` object to use the newly created attribute instance. | |
| 712 | 744 | ||
| 745 | + Raise :exc:`InvalidCharacterErr` if the name is not a valid XML name. | ||
| 746 | + | ||
| 713 | 747 | ||
| 714 | 748 | .. method:: Document.getElementById(id) | |
| 715 | 749 | ||
@@ -844,6 +878,8 @@ of that class. | |||
| 844 | 878 | ||
| 845 | 879 | Set an attribute value from a string. | |
| 846 | 880 | ||
| 881 | + Raise :exc:`InvalidCharacterErr` if the name is not a valid XML name. | ||
| 882 | + | ||
| 847 | 883 | ||
| 848 | 884 | .. method:: Element.setAttributeNode(newAttr) | |
| 849 | 885 | ||
@@ -852,6 +888,8 @@ of that class. | |||
| 852 | 888 | occurs, the old attribute node will be returned. If *newAttr* is already in use, | |
| 853 | 889 | :exc:`InuseAttributeErr` will be raised. | |
| 854 | 890 | ||
| 891 | + Raise :exc:`WrongDocumentErr` if *newAttr* was created by another document. | ||
| 892 | + | ||
| 855 | 893 | ||
| 856 | 894 | .. method:: Element.setAttributeNodeNS(newAttr) | |
| 857 | 895 | ||
@@ -861,12 +899,16 @@ of that class. | |||
| 861 | 899 | returned. If *newAttr* is already in use, :exc:`InuseAttributeErr` will be | |
| 862 | 900 | raised. | |
| 863 | 901 | ||
| 902 | + Raise :exc:`WrongDocumentErr` if *newAttr* was created by another document. | ||
| 903 | + | ||
| 864 | 904 | ||
| 865 | 905 | .. method:: Element.setAttributeNS(namespaceURI, qname, value) | |
| 866 | 906 | ||
| 867 | 907 | Set an attribute value from a string, given a *namespaceURI* and a *qname*. | |
| 868 | 908 | Note that a qname is the whole attribute name. This is different than above. | |
| 869 | 909 | ||
| 910 | + Raise :exc:`InvalidCharacterErr` if the name is not a valid XML name. | ||
| 911 | + | ||
| 870 | 912 | ||
| 871 | 913 | .. _dom-attr-objects: | |
| 872 | 914 | ||
@@ -972,13 +1014,19 @@ NamedNodeMap Objects | |||
| 972 | 1014 | Add *node* to the map, using its :attr:`~Attr.name` as the key. | |
| 973 | 1015 | Return the node which it replaces, or ``None`` if it replaces no node. | |
| 974 | 1016 | ||
| 1017 | + Raise :exc:`WrongDocumentErr` if *node* was created by another document, | ||
| 1018 | + and :exc:`InuseAttributeErr` if it belongs to another element. | ||
| 1019 | + | ||
| 975 | 1020 | ||
| 976 | 1021 | .. method:: NamedNodeMap.setNamedItemNS(node) | |
| 977 | 1022 | ||
| 978 | 1023 | Add *node* to the map, | |
| 979 | 1024 | using its namespace URI and local name as the key. | |
| 980 | 1025 | Return the node which it replaces, or ``None`` if it replaces no node. | |
| 981 | 1026 | ||
| 1027 | + Raise :exc:`WrongDocumentErr` if *node* was created by another document, | ||
| 1028 | + and :exc:`InuseAttributeErr` if it belongs to another element. | ||
| 1029 | + | ||
| 982 | 1030 | ||
| 983 | 1031 | .. method:: NamedNodeMap.removeNamedItem(name) | |
| 984 | 1032 | ||
@@ -1224,6 +1272,23 @@ The name of the notation is its :attr:`~Node.nodeName`. | |||
| 1224 | 1272 | The system identifier of the notation, | |
| 1225 | 1273 | or ``None`` if it is not specified. | |
| 1226 | 1274 | This is a read-only attribute. | |
| 1275 | + .. _dom-entityreference-objects: | ||
| 1276 | + | ||
| 1277 | + EntityReference Objects | ||
| 1278 | + ^^^^^^^^^^^^^^^^^^^^^^^ | ||
| 1279 | + | ||
| 1280 | + .. class:: EntityReference | ||
| 1281 | + :no-typesetting: | ||
| 1282 | + | ||
| 1283 | + :class:`EntityReference` represents an entity reference in the XML document. | ||
| 1284 | + It is a subclass of :class:`Node`. | ||
| 1285 | + The name of the referenced entity is its :attr:`~Node.nodeName`. | ||
| 1286 | + Its children are the replacement text of the entity, and are read-only. | ||
| 1287 | + | ||
| 1288 | + Parsers may expand entity references, | ||
| 1289 | + so such a node only occurs in a document if it was created explicitly. | ||
| 1290 | + | ||
| 1291 | + .. versionadded:: next | ||
| 1227 | 1292 | ||
| 1228 | 1293 | ||
| 1229 | 1294 | .. _dom-exceptions: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -630,6 +630,24 @@ xml | |||
| 630 | 630 | instead of failing later, when encountering non-ASCII data. | |
| 631 | 631 | (Contributed by Serhiy Storchaka in :gh:`62259`.) | |
| 632 | 632 | ||
| 633 | + * :mod:`xml.dom.minidom` now conforms closer to the DOM Level 1 specification. | ||
| 634 | + It checks names passed to the factory methods, | ||
| 635 | + rejects inserting or setting a node created by another document | ||
| 636 | + or making a node a descendant of itself, | ||
| 637 | + rejects a second element or document type child of a document | ||
| 638 | + and a notation child of a document fragment, | ||
| 639 | + reports attributes defaulted in the DTD | ||
| 640 | + and whether an attribute was given in the start tag, | ||
| 641 | + and implements :class:`!EntityReference` nodes | ||
| 642 | + and :meth:`!Document.createEntityReference`. | ||
| 643 | + (Contributed by Jason Orendorff and Serhiy Storchaka in :gh:`44871`.) | ||
| 644 | + | ||
| 645 | + * Add :meth:`!GetSpecifiedAttributeCount` method | ||
| 646 | + to the :mod:`XML parser <xml.parsers.expat>` objects. | ||
| 647 | + It tells how many of the reported attributes were given in the start tag | ||
| 648 | + rather than defaulted from the DTD. | ||
| 649 | + (Contributed by Jason Orendorff and Serhiy Storchaka in :gh:`44871`.) | ||
| 650 | + | ||
| 633 | 651 | zipfile | |
| 634 | 652 | ------- | |
| 635 | 653 | ||
@@ -845,6 +863,24 @@ that may require changes to your code. | |||
| 845 | 863 | :exc:`TypeError`. | |
| 846 | 864 | (Contributed by Serhiy Storchaka in :gh:`152587`.) | |
| 847 | 865 | ||
| 866 | + * :mod:`xml.dom.minidom` now raises :exc:`~xml.dom.InvalidCharacterErr` | ||
| 867 | + for a name which is not a valid XML name, | ||
| 868 | + :exc:`~xml.dom.WrongDocumentErr` | ||
| 869 | + for inserting or setting a node created by another document, | ||
| 870 | + :exc:`~xml.dom.InuseAttributeErr` for setting an attribute node | ||
| 871 | + which belongs to another element, | ||
| 872 | + and :exc:`~xml.dom.HierarchyRequestErr` for inserting a node into itself | ||
| 873 | + or its descendant. | ||
| 874 | + It also rejects a second element or document type child of a document | ||
| 875 | + and a notation child of a document fragment. | ||
| 876 | + Such operations formerly succeeded | ||
| 877 | + and produced an invalid document or an endless loop. | ||
| 878 | + On the other hand, :meth:`!Element.removeAttribute` and | ||
| 879 | + :meth:`!Element.removeAttributeNS` no longer raise | ||
| 880 | + :exc:`~xml.dom.NotFoundErr` if there is no matching attribute. | ||
| 881 | + Attributes defaulted in the DTD are no longer omitted when parsing. | ||
| 882 | + (Contributed by Jason Orendorff and Serhiy Storchaka in :gh:`44871`.) | ||
| 883 | + | ||
| 848 | 884 | * On Windows, seeking a pipe now fails instead of silently appearing to | |
| 849 | 885 | succeed: :func:`os.lseek` and :meth:`~io.IOBase.seek` raise :exc:`OSError`, | |
| 850 | 886 | and :meth:`~io.IOBase.seekable` returns ``False``. As a consequence, | |
| Back | FazBrowse Home | New Git URL |
0 commit comments