diff options
author | Stefan Behnel <stefan_ml@behnel.de> | 2019-05-03 18:58:16 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-03 18:58:16 (GMT) |
commit | 47541689ccea79dfcb055c6be5800b13fcb6bdd2 (patch) | |
tree | 7580016557a064cc019fe41d1d62e57ac3dcc8c6 /Modules/_elementtree.c | |
parent | cf48e55f7f7718482fa712552f0cbc0aea1c826f (diff) | |
download | cpython-47541689ccea79dfcb055c6be5800b13fcb6bdd2.zip cpython-47541689ccea79dfcb055c6be5800b13fcb6bdd2.tar.gz cpython-47541689ccea79dfcb055c6be5800b13fcb6bdd2.tar.bz2 |
bpo-28238: Implement "{*}tag" and "{ns}*" wildcard tag selection support for ElementPath, and extend the surrounding tests and docs. (GH-12997)
Diffstat (limited to 'Modules/_elementtree.c')
-rw-r--r-- | Modules/_elementtree.c | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c index b69e3a4..1e58ddb 100644 --- a/Modules/_elementtree.c +++ b/Modules/_elementtree.c @@ -1149,6 +1149,13 @@ checkpath(PyObject* tag) const Py_ssize_t len = PyUnicode_GET_LENGTH(tag); void *data = PyUnicode_DATA(tag); unsigned int kind = PyUnicode_KIND(tag); + if (len >= 3 && PyUnicode_READ(kind, data, 0) == '{' && ( + PyUnicode_READ(kind, data, 1) == '}' || ( + PyUnicode_READ(kind, data, 1) == '*' && + PyUnicode_READ(kind, data, 2) == '}'))) { + /* wildcard: '{}tag' or '{*}tag' */ + return 1; + } for (i = 0; i < len; i++) { Py_UCS4 ch = PyUnicode_READ(kind, data, i); if (ch == '{') @@ -1162,7 +1169,13 @@ checkpath(PyObject* tag) } if (PyBytes_Check(tag)) { char *p = PyBytes_AS_STRING(tag); - for (i = 0; i < PyBytes_GET_SIZE(tag); i++) { + const Py_ssize_t len = PyBytes_GET_SIZE(tag); + if (len >= 3 && p[0] == '{' && ( + p[1] == '}' || p[1] == '*' && p[2] == '}')) { + /* wildcard: '{}tag' or '{*}tag' */ + return 1; + } + for (i = 0; i < len; i++) { if (p[i] == '{') check = 0; else if (p[i] == '}') |