-
-
Notifications
You must be signed in to change notification settings - Fork 34.8k
bpo-35018: Sax parser provides no user access to lexical handlers. #10328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
5a92d75
Add support for LexicalHandler class and documentation.
JonathanGossage a10380a
Merge branch 'master' of https://github.com/python/cpython.git into I…
JonathanGossage 9a2d3d1
Add testing CDATA handlers.
JonathanGossage 2c8d73c
Merge branch 'master' of https://github.com/python/cpython.git into I…
JonathanGossage 69ae816
Fix whitespace problem.
JonathanGossage d7d4d30
Fix CDATAHandlerTest - was not tested because of missing super class in
JonathanGossage db60cb5
Fix long-standing typo in xml.sax.handler.rst.
JonathanGossage d8dc65e
Fix areas suggested by review comments.
JonathanGossage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,8 @@ | |
| # | ||
| #============================================================================ | ||
|
|
||
| # ===== ERRORHANDLER ===== | ||
|
|
||
| #===== ERRORHANDLER ===== | ||
|
|
||
| class ErrorHandler: | ||
| """Basic interface for SAX error handlers. | ||
|
|
@@ -203,7 +204,7 @@ def skippedEntity(self, name): | |
| properties.""" | ||
|
|
||
|
|
||
| # ===== DTDHandler ===== | ||
| #===== DTDHandler ===== | ||
|
|
||
| class DTDHandler: | ||
| """Handle DTD events. | ||
|
|
@@ -218,7 +219,7 @@ def unparsedEntityDecl(self, name, publicId, systemId, ndata): | |
| "Handle an unparsed entity declaration event." | ||
|
|
||
|
|
||
| # ===== ENTITYRESOLVER ===== | ||
| #===== ENTITYRESOLVER ===== | ||
|
|
||
| class EntityResolver: | ||
| """Basic interface for resolving entities. If you create an object | ||
|
|
@@ -340,3 +341,57 @@ def resolveEntity(self, publicId, systemId): | |
| property_xml_string, | ||
| property_encoding, | ||
| property_interning_dict] | ||
|
|
||
|
|
||
| class LexicalHandler: | ||
| """Optional SAX2 handler for lexical events. | ||
|
|
||
| This handler is used to obtain lexical information about an XML | ||
| document, that is, information about how the document was encoded | ||
| (as opposed to what it contains, which is reported to the | ||
| ContentHandler), such as comments and CDATA marked section | ||
| boundaries. | ||
|
|
||
| To set the LexicalHandler of an XMLReader, use the setProperty | ||
| method with the property identifier | ||
| 'http://xml.org/sax/handlers/LexicalHandler'.""" | ||
|
|
||
| def xmlDecl(self, version, encoding, standalone): | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is not part of the |
||
| """Reports the contents of the XML declaration. | ||
|
|
||
| version is the XML version of the document. | ||
| encoding is the character encoding used to read the document. | ||
| standalone indicates that no default attribute values are | ||
| declared and no external entities are declared. | ||
| """ | ||
|
|
||
| def comment(self, content): | ||
| """Reports a comment anywhere in the document (including the | ||
| DTD and outside the document element). | ||
|
|
||
| content is a string that holds the contents of the comment.""" | ||
|
|
||
| def startDTD(self, name, public_id, system_id): | ||
| """Report the start of the DTD declarations, if the document | ||
| has an associated DTD. | ||
|
|
||
| A startEntity event will be reported before declaration events | ||
| from the external DTD subset are reported, and this can be | ||
| used to infer from which subset DTD declarations derive. | ||
|
|
||
| name is the name of the document element type, public_id the | ||
| public identifier of the DTD (or None if none were supplied) | ||
| and system_id the system identfier of the external subset (or | ||
| None if none were supplied).""" | ||
|
|
||
| def endDTD(self): | ||
| "Signals the end of DTD declarations." | ||
|
|
||
| def startCDATA(self): | ||
| """Reports the beginning of a CDATA marked section. | ||
|
|
||
| The contents of the CDATA marked section will be reported | ||
| through the characters event.""" | ||
|
|
||
| def endCDATA(self): | ||
| """Reports the end of a CDATA marked section.""" |
4 changes: 4 additions & 0 deletions
4
Misc/NEWS.d/next/Library/2018-11-03-21-21-32.bpo-35018.z1vnri.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| Add the LexicalHandler class that is present in other SAX XML | ||
| implementations. The plumbing is already supported by Python so this simply | ||
| adds the porcelain that makes it easy for users of the Python Sax parser to | ||
| handle lexical events. |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doing something in
TestCase.__init__(), especially setting up test data, is a very unusual thing to do. Please use the normal set-up methods instead.