bpo-28238: Implement "{*}tag" and "{ns}*" wildcard tag selection support for ElementPath, and extend the surrounding tests and docs. (GH-12997)

This commit is contained in:
Stefan Behnel 2019-05-03 20:58:16 +02:00 committed by GitHub
parent cf48e55f7f
commit 47541689cc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 171 additions and 15 deletions

View file

@ -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] == '}')