-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-54873: Add support for namespaces prefixes to xml.sax.expatreader
#118317
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
6ecfc28
e9ac454
9c365c2
2fc666a
fe9d82f
be878cb
0e3f870
c88e7ed
27cb273
91112b9
d3cbe5f
1d343f1
256a97b
7c0da60
e219450
34af031
8075f8b
2004846
c3e00e2
d3b08ec
e8bcb30
dfff704
7de4ce5
08d659e
7cdc402
cd7de73
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -79,7 +79,7 @@ def getSystemId(self): | |
| class ExpatParser(xmlreader.IncrementalParser, xmlreader.Locator): | ||
| """SAX driver for the pyexpat C module.""" | ||
|
|
||
| def __init__(self, namespaceHandling=0, namespacePrefixesHandling=0, bufsize=2**16-20): | ||
| def __init__(self, namespaceHandling=0, bufsize=2**16-20): | ||
| xmlreader.IncrementalParser.__init__(self, bufsize) | ||
| self._source = xmlreader.InputSource() | ||
| self._parser = None | ||
|
|
@@ -89,7 +89,7 @@ def __init__(self, namespaceHandling=0, namespacePrefixesHandling=0, bufsize=2** | |
| self._entity_stack = [] | ||
| self._external_ges = 0 | ||
| self._interning = None | ||
| self._namespace_prefixes = namespacePrefixesHandling | ||
| self._namespace_prefixes = 0 | ||
|
|
||
| # XMLReader methods | ||
|
|
||
|
|
@@ -147,8 +147,6 @@ def setFeature(self, name, state): | |
| self._interning = {} | ||
| else: | ||
| self._interning = None | ||
| elif name == feature_namespace_prefixes: | ||
| self._namespace_prefixes = state | ||
| elif name == feature_validation: | ||
| if state: | ||
| raise SAXNotSupportedException( | ||
|
|
@@ -157,6 +155,8 @@ def setFeature(self, name, state): | |
| if state: | ||
| raise SAXNotSupportedException( | ||
| "expat does not read external parameter entities") | ||
| elif name == feature_namespace_prefixes: | ||
| self._namespace_prefixes = state | ||
|
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. @ukarroum I wonder what the expected behaviors is here when
Just thinking aloud.
Contributor
Author
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. good point, I think it will make sense to just enable feature_namespaces when feature_namespace_prefixes is also enabled (and also disable feature_namespace_prefixes if feature_namespaces is disabled).
Contributor
Author
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. actually one drawback I see for this is : enable feature_namespace_prefixes this will result in feature_namespace_prefixes being disabled which feels odd.
Contributor
Author
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. I went with 1) instead.
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. @ukarroum I like it. I think one small dedicated test for that would be great where namespaces are disabled and the exception is raise with the expected message. (Arguably, the success case is already covered by existing tests.)
Contributor
Author
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. added test |
||
| else: | ||
| raise SAXNotRecognizedException( | ||
| "Feature '%s' not recognized" % name) | ||
|
|
@@ -375,6 +375,9 @@ def start_element_ns(self, name, attrs): | |
| newattrs[apair] = value | ||
| qnames[apair] = qname | ||
|
|
||
| if not self._namespace_prefixes: | ||
| elem_qname = None | ||
|
|
||
| self._cont_handler.startElementNS(pair, elem_qname, | ||
|
ukarroum marked this conversation as resolved.
|
||
| AttributesNSImpl(newattrs, qnames)) | ||
|
|
||
|
|
||
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.
Don't leave 3 blank lines, only 2 is sufficient.
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.
Fixed