gh-139489: Add xml.utils.is_valid_name()#139768
gh-139489: Add xml.utils.is_valid_name()#139768serhiy-storchaka wants to merge 8 commits intopython:mainfrom
Conversation
It allows to check whether a string can be used as an element or attribute name in XML.
|
Why not adding the function in the The function doesn't seem to be specific to the sax implementation. Is it? |
|
There is no an |
I'm suggesting to create such |
|
This is an interesting idea. |
|
This PR is stale because it has been open for 30 days with no activity. |
|
See also Place for XML helper functions discussion. |
Documentation build overview
33 files changed ·
|
Co-authored-by: Victor Stinner <vstinner@python.org>
| ``False`` otherwise. | ||
|
|
||
| Almost all characters are permitted in names, except control characters and | ||
| those which either are or reasonably could be used as delimiters. |
There was a problem hiding this comment.
Maybe add a link to the specs if any?
There was a problem hiding this comment.
Link found in the implementation: https://www.w3.org/TR/xml/#NT-Name.
There was a problem hiding this comment.
I think it would be good to add it in the online docs as well. It'll be more accessible.
There was a problem hiding this comment.
I am going to add several more functions. Some functions will need several links, and some links will be repeated for different functions. If we want to add links, it is better to add root links to the XML specifications at the top of the module documentation.
There was a problem hiding this comment.
That's also ok. As long as the online docs contain some links to some specifications, it's ok.
| @@ -0,0 +1,25 @@ | |||
| lazy import re | |||
There was a problem hiding this comment.
Are we worried about the stability of xml.utils? Maybe we could have xml._utils first and then promote it to a public module later?
There was a problem hiding this comment.
I'm also in favor of making this sub-module private (rename to xml._utils). There is a risk that developers start depending on xml.utils.is_valid_name name and it would break projects if the function is moved later (ex: to xml/__init__.py).
There was a problem hiding this comment.
xml and xml.utils were two initial suggestions, and they got the same amount of voices. If there is a chance of xml.utils been documented officially, it is better to keep this name from beginning. It is also more pickle-friendly.
| @@ -0,0 +1,25 @@ | |||
| lazy import re | |||
|
|
|||
|
|
|||
There was a problem hiding this comment.
It's needed. Currently, the re module is exposed as a xml attribute:
$ ./python
>>> import xml
>>> xml.re
<module 're' from '/home/vstinner/python/main/Lib/re/__init__.py'>
It allows to check whether a string can be used as an element or attribute name in XML.
📚 Documentation preview 📚: https://cpython-previews--139768.org.readthedocs.build/