| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1638,6 +1638,9 @@ They all return *NULL* or ``-1`` if an exception occurs. | |||
| 1638 | 1638 | Compare two strings and return ``-1``, ``0``, ``1`` for less than, equal, and greater than, | |
| 1639 | 1639 | respectively. | |
| 1640 | 1640 | ||
| 1641 | + This function returns ``-1`` upon failure, so one should call | ||
| 1642 | + :c:func:`PyErr_Occurred` to check for errors. | ||
| 1643 | + | ||
| 1641 | 1644 | ||
| 1642 | 1645 | .. c:function:: int PyUnicode_CompareWithASCIIString(PyObject *uni, const char *string) | |
| 1643 | 1646 | ||
@@ -1646,6 +1649,9 @@ They all return *NULL* or ``-1`` if an exception occurs. | |||
| 1646 | 1649 | ASCII-encoded strings, but the function interprets the input string as | |
| 1647 | 1650 | ISO-8859-1 if it contains non-ASCII characters. | |
| 1648 | 1651 | ||
| 1652 | + This function returns ``-1`` upon failure, so one should call | ||
| 1653 | + :c:func:`PyErr_Occurred` to check for errors. | ||
| 1654 | + | ||
| 1649 | 1655 | ||
| 1650 | 1656 | .. c:function:: PyObject* PyUnicode_RichCompare(PyObject *left, PyObject *right, int op) | |
| 1651 | 1657 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2011,6 +2011,17 @@ PyAPI_FUNC(int) PyUnicode_CompareWithASCIIString( | |||
| 2011 | 2011 | const char *right /* ASCII-encoded string */ | |
| 2012 | 2012 | ); | |
| 2013 | 2013 | ||
| 2014 | + #ifndef Py_LIMITED_API | ||
| 2015 | + /* Test whether a unicode is equal to ASCII string. Return 1 if true, | ||
| 2016 | + 0 otherwise. Return 0 if any argument contains non-ASCII characters. | ||
| 2017 | + Any error occurs inside will be cleared before return. */ | ||
| 2018 | + | ||
| 2019 | + PyAPI_FUNC(int) _PyUnicode_EqualToASCIIString( | ||
| 2020 | + PyObject *left, | ||
| 2021 | + const char *right /* ASCII-encoded string */ | ||
| 2022 | + ); | ||
| 2023 | + #endif | ||
| 2024 | + | ||
| 2014 | 2025 | /* Rich compare two strings and return one of the following: | |
| 2015 | 2026 | ||
| 2016 | 2027 | - NULL in case an exception was raised | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1119,12 +1119,12 @@ context_getattr(PyObject *self, PyObject *name) | |||
| 1119 | 1119 | PyObject *retval; | |
| 1120 | 1120 | ||
| 1121 | 1121 | if (PyUnicode_Check(name)) { | |
| 1122 | - if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) { | ||
| 1122 | + if (_PyUnicode_EqualToASCIIString(name, "traps")) { | ||
| 1123 | 1123 | retval = ((PyDecContextObject *)self)->traps; | |
| 1124 | 1124 | Py_INCREF(retval); | |
| 1125 | 1125 | return retval; | |
| 1126 | 1126 | } | |
| 1127 | - if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) { | ||
| 1127 | + if (_PyUnicode_EqualToASCIIString(name, "flags")) { | ||
| 1128 | 1128 | retval = ((PyDecContextObject *)self)->flags; | |
| 1129 | 1129 | Py_INCREF(retval); | |
| 1130 | 1130 | return retval; | |
@@ -1144,10 +1144,10 @@ context_setattr(PyObject *self, PyObject *name, PyObject *value) | |||
| 1144 | 1144 | } | |
| 1145 | 1145 | ||
| 1146 | 1146 | if (PyUnicode_Check(name)) { | |
| 1147 | - if (PyUnicode_CompareWithASCIIString(name, "traps") == 0) { | ||
| 1147 | + if (_PyUnicode_EqualToASCIIString(name, "traps")) { | ||
| 1148 | 1148 | return context_settraps_dict(self, value); | |
| 1149 | 1149 | } | |
| 1150 | - if (PyUnicode_CompareWithASCIIString(name, "flags") == 0) { | ||
| 1150 | + if (_PyUnicode_EqualToASCIIString(name, "flags")) { | ||
| 1151 | 1151 | return context_setstatus_dict(self, value); | |
| 1152 | 1152 | } | |
| 1153 | 1153 | } | |
@@ -2446,14 +2446,14 @@ dectuple_as_str(PyObject *dectuple) | |||
| 2446 | 2446 | tmp = PyTuple_GET_ITEM(dectuple, 2); | |
| 2447 | 2447 | if (PyUnicode_Check(tmp)) { | |
| 2448 | 2448 | /* special */ | |
| 2449 | - if (PyUnicode_CompareWithASCIIString(tmp, "F") == 0) { | ||
| 2449 | + if (_PyUnicode_EqualToASCIIString(tmp, "F")) { | ||
| 2450 | 2450 | strcat(sign_special, "Inf"); | |
| 2451 | 2451 | is_infinite = 1; | |
| 2452 | 2452 | } | |
| 2453 | - else if (PyUnicode_CompareWithASCIIString(tmp, "n") == 0) { | ||
| 2453 | + else if (_PyUnicode_EqualToASCIIString(tmp, "n")) { | ||
| 2454 | 2454 | strcat(sign_special, "NaN"); | |
| 2455 | 2455 | } | |
| 2456 | - else if (PyUnicode_CompareWithASCIIString(tmp, "N") == 0) { | ||
| 2456 | + else if (_PyUnicode_EqualToASCIIString(tmp, "N")) { | ||
| 2457 | 2457 | strcat(sign_special, "sNaN"); | |
| 2458 | 2458 | } | |
| 2459 | 2459 | else { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3686,11 +3686,11 @@ xmlparser_getattro(XMLParserObject* self, PyObject* nameobj) | |||
| 3686 | 3686 | { | |
| 3687 | 3687 | if (PyUnicode_Check(nameobj)) { | |
| 3688 | 3688 | PyObject* res; | |
| 3689 | - if (PyUnicode_CompareWithASCIIString(nameobj, "entity") == 0) | ||
| 3689 | + if (_PyUnicode_EqualToASCIIString(nameobj, "entity")) | ||
| 3690 | 3690 | res = self->entity; | |
| 3691 | - else if (PyUnicode_CompareWithASCIIString(nameobj, "target") == 0) | ||
| 3691 | + else if (_PyUnicode_EqualToASCIIString(nameobj, "target")) | ||
| 3692 | 3692 | res = self->target; | |
| 3693 | - else if (PyUnicode_CompareWithASCIIString(nameobj, "version") == 0) { | ||
| 3693 | + else if (_PyUnicode_EqualToASCIIString(nameobj, "version")) { | ||
| 3694 | 3694 | return PyUnicode_FromFormat( | |
| 3695 | 3695 | "Expat %d.%d.%d", XML_MAJOR_VERSION, | |
| 3696 | 3696 | XML_MINOR_VERSION, XML_MICRO_VERSION); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1023,7 +1023,7 @@ _io_TextIOWrapper___init___impl(textio *self, PyObject *buffer, | |||
| 1023 | 1023 | else if (PyUnicode_Check(res)) { | |
| 1024 | 1024 | encodefuncentry *e = encodefuncs; | |
| 1025 | 1025 | while (e->name != NULL) { | |
| 1026 | - if (!PyUnicode_CompareWithASCIIString(res, e->name)) { | ||
| 1026 | + if (_PyUnicode_EqualToASCIIString(res, e->name)) { | ||
| 1027 | 1027 | self->encodefunc = e->encodefunc; | |
| 1028 | 1028 | break; | |
| 1029 | 1029 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -185,7 +185,7 @@ normalizeUserObj(PyObject *obj) | |||
| 185 | 185 | } | |
| 186 | 186 | } | |
| 187 | 187 | if (modname != NULL) { | |
| 188 | - if (PyUnicode_CompareWithASCIIString(modname, "builtins") != 0) { | ||
| 188 | + if (!_PyUnicode_EqualToASCIIString(modname, "builtins")) { | ||
| 189 | 189 | PyObject *result; | |
| 190 | 190 | result = PyUnicode_FromFormat("<%U.%s>", modname, | |
| 191 | 191 | fn->m_ml->ml_name); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1675,7 +1675,7 @@ whichmodule(PyObject *global, PyObject *dotted_path) | |||
| 1675 | 1675 | while (PyDict_Next(modules_dict, &i, &module_name, &module)) { | |
| 1676 | 1676 | PyObject *candidate; | |
| 1677 | 1677 | if (PyUnicode_Check(module_name) && | |
| 1678 | - !PyUnicode_CompareWithASCIIString(module_name, "__main__")) | ||
| 1678 | + _PyUnicode_EqualToASCIIString(module_name, "__main__")) | ||
| 1679 | 1679 | continue; | |
| 1680 | 1680 | if (module == Py_None) | |
| 1681 | 1681 | continue; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1216,7 +1216,7 @@ static int pysqlite_connection_set_isolation_level(pysqlite_Connection* self, Py | |||
| 1216 | 1216 | return -1; | |
| 1217 | 1217 | } | |
| 1218 | 1218 | for (candidate = begin_statements; *candidate; candidate++) { | |
| 1219 | - if (!PyUnicode_CompareWithASCIIString(uppercase_level, *candidate + 6)) | ||
| 1219 | + if (_PyUnicode_EqualToASCIIString(uppercase_level, *candidate + 6)) | ||
| 1220 | 1220 | break; | |
| 1221 | 1221 | } | |
| 1222 | 1222 | Py_DECREF(uppercase_level); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2310,7 +2310,7 @@ test_string_from_format(PyObject *self, PyObject *args) | |||
| 2310 | 2310 | result = PyUnicode_FromFormat(FORMAT, (TYPE)1); \ | |
| 2311 | 2311 | if (result == NULL) \ | |
| 2312 | 2312 | return NULL; \ | |
| 2313 | - if (PyUnicode_CompareWithASCIIString(result, "1")) { \ | ||
| 2313 | + if (!_PyUnicode_EqualToASCIIString(result, "1")) { \ | ||
| 2314 | 2314 | msg = FORMAT " failed at 1"; \ | |
| 2315 | 2315 | goto Fail; \ | |
| 2316 | 2316 | } \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1247,8 +1247,7 @@ handlername2int(PyObject *name) | |||
| 1247 | 1247 | { | |
| 1248 | 1248 | int i; | |
| 1249 | 1249 | for (i = 0; handler_info[i].name != NULL; i++) { | |
| 1250 | - if (PyUnicode_CompareWithASCIIString( | ||
| 1251 | - name, handler_info[i].name) == 0) { | ||
| 1250 | + if (_PyUnicode_EqualToASCIIString(name, handler_info[i].name)) { | ||
| 1252 | 1251 | return i; | |
| 1253 | 1252 | } | |
| 1254 | 1253 | } | |
@@ -1286,45 +1285,45 @@ xmlparse_getattro(xmlparseobject *self, PyObject *nameobj) | |||
| 1286 | 1285 | ||
| 1287 | 1286 | first_char = PyUnicode_READ_CHAR(nameobj, 0); | |
| 1288 | 1287 | if (first_char == 'E') { | |
| 1289 | - if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorCode") == 0) | ||
| 1288 | + if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorCode")) | ||
| 1290 | 1289 | return PyLong_FromLong((long) | |
| 1291 | 1290 | XML_GetErrorCode(self->itself)); | |
| 1292 | - if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorLineNumber") == 0) | ||
| 1291 | + if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorLineNumber")) | ||
| 1293 | 1292 | return PyLong_FromLong((long) | |
| 1294 | 1293 | XML_GetErrorLineNumber(self->itself)); | |
| 1295 | - if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorColumnNumber") == 0) | ||
| 1294 | + if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorColumnNumber")) | ||
| 1296 | 1295 | return PyLong_FromLong((long) | |
| 1297 | 1296 | XML_GetErrorColumnNumber(self->itself)); | |
| 1298 | - if (PyUnicode_CompareWithASCIIString(nameobj, "ErrorByteIndex") == 0) | ||
| 1297 | + if (_PyUnicode_EqualToASCIIString(nameobj, "ErrorByteIndex")) | ||
| 1299 | 1298 | return PyLong_FromLong((long) | |
| 1300 | 1299 | XML_GetErrorByteIndex(self->itself)); | |
| 1301 | 1300 | } | |
| 1302 | 1301 | if (first_char == 'C') { | |
| 1303 | - if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentLineNumber") == 0) | ||
| 1302 | + if (_PyUnicode_EqualToASCIIString(nameobj, "CurrentLineNumber")) | ||
| 1304 | 1303 | return PyLong_FromLong((long) | |
| 1305 | 1304 | XML_GetCurrentLineNumber(self->itself)); | |
| 1306 | - if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentColumnNumber") == 0) | ||
| 1305 | + if (_PyUnicode_EqualToASCIIString(nameobj, "CurrentColumnNumber")) | ||
| 1307 | 1306 | return PyLong_FromLong((long) | |
| 1308 | 1307 | XML_GetCurrentColumnNumber(self->itself)); | |
| 1309 | - if (PyUnicode_CompareWithASCIIString(nameobj, "CurrentByteIndex") == 0) | ||
| 1308 | + if (_PyUnicode_EqualToASCIIString(nameobj, "CurrentByteIndex")) | ||
| 1310 | 1309 | return PyLong_FromLong((long) | |
| 1311 | 1310 | XML_GetCurrentByteIndex(self->itself)); | |
| 1312 | 1311 | } | |
| 1313 | 1312 | if (first_char == 'b') { | |
| 1314 | - if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_size") == 0) | ||
| 1313 | + if (_PyUnicode_EqualToASCIIString(nameobj, "buffer_size")) | ||
| 1315 | 1314 | return PyLong_FromLong((long) self->buffer_size); | |
| 1316 | - if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_text") == 0) | ||
| 1315 | + if (_PyUnicode_EqualToASCIIString(nameobj, "buffer_text")) | ||
| 1317 | 1316 | return get_pybool(self->buffer != NULL); | |
| 1318 | - if (PyUnicode_CompareWithASCIIString(nameobj, "buffer_used") == 0) | ||
| 1317 | + if (_PyUnicode_EqualToASCIIString(nameobj, "buffer_used")) | ||
| 1319 | 1318 | return PyLong_FromLong((long) self->buffer_used); | |
| 1320 | 1319 | } | |
| 1321 | - if (PyUnicode_CompareWithASCIIString(nameobj, "namespace_prefixes") == 0) | ||
| 1320 | + if (_PyUnicode_EqualToASCIIString(nameobj, "namespace_prefixes")) | ||
| 1322 | 1321 | return get_pybool(self->ns_prefixes); | |
| 1323 | - if (PyUnicode_CompareWithASCIIString(nameobj, "ordered_attributes") == 0) | ||
| 1322 | + if (_PyUnicode_EqualToASCIIString(nameobj, "ordered_attributes")) | ||
| 1324 | 1323 | return get_pybool(self->ordered_attributes); | |
| 1325 | - if (PyUnicode_CompareWithASCIIString(nameobj, "specified_attributes") == 0) | ||
| 1324 | + if (_PyUnicode_EqualToASCIIString(nameobj, "specified_attributes")) | ||
| 1326 | 1325 | return get_pybool((long) self->specified_attributes); | |
| 1327 | - if (PyUnicode_CompareWithASCIIString(nameobj, "intern") == 0) { | ||
| 1326 | + if (_PyUnicode_EqualToASCIIString(nameobj, "intern")) { | ||
| 1328 | 1327 | if (self->intern == NULL) { | |
| 1329 | 1328 | Py_INCREF(Py_None); | |
| 1330 | 1329 | return Py_None; | |
@@ -1388,7 +1387,7 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) | |||
| 1388 | 1387 | PyErr_SetString(PyExc_RuntimeError, "Cannot delete attribute"); | |
| 1389 | 1388 | return -1; | |
| 1390 | 1389 | } | |
| 1391 | - if (PyUnicode_CompareWithASCIIString(name, "buffer_text") == 0) { | ||
| 1390 | + if (_PyUnicode_EqualToASCIIString(name, "buffer_text")) { | ||
| 1392 | 1391 | int b = PyObject_IsTrue(v); | |
| 1393 | 1392 | if (b < 0) | |
| 1394 | 1393 | return -1; | |
@@ -1410,30 +1409,30 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) | |||
| 1410 | 1409 | } | |
| 1411 | 1410 | return 0; | |
| 1412 | 1411 | } | |
| 1413 | - if (PyUnicode_CompareWithASCIIString(name, "namespace_prefixes") == 0) { | ||
| 1412 | + if (_PyUnicode_EqualToASCIIString(name, "namespace_prefixes")) { | ||
| 1414 | 1413 | int b = PyObject_IsTrue(v); | |
| 1415 | 1414 | if (b < 0) | |
| 1416 | 1415 | return -1; | |
| 1417 | 1416 | self->ns_prefixes = b; | |
| 1418 | 1417 | XML_SetReturnNSTriplet(self->itself, self->ns_prefixes); | |
| 1419 | 1418 | return 0; | |
| 1420 | 1419 | } | |
| 1421 | - if (PyUnicode_CompareWithASCIIString(name, "ordered_attributes") == 0) { | ||
| 1420 | + if (_PyUnicode_EqualToASCIIString(name, "ordered_attributes")) { | ||
| 1422 | 1421 | int b = PyObject_IsTrue(v); | |
| 1423 | 1422 | if (b < 0) | |
| 1424 | 1423 | return -1; | |
| 1425 | 1424 | self->ordered_attributes = b; | |
| 1426 | 1425 | return 0; | |
| 1427 | 1426 | } | |
| 1428 | - if (PyUnicode_CompareWithASCIIString(name, "specified_attributes") == 0) { | ||
| 1427 | + if (_PyUnicode_EqualToASCIIString(name, "specified_attributes")) { | ||
| 1429 | 1428 | int b = PyObject_IsTrue(v); | |
| 1430 | 1429 | if (b < 0) | |
| 1431 | 1430 | return -1; | |
| 1432 | 1431 | self->specified_attributes = b; | |
| 1433 | 1432 | return 0; | |
| 1434 | 1433 | } | |
| 1435 | 1434 | ||
| 1436 | - if (PyUnicode_CompareWithASCIIString(name, "buffer_size") == 0) { | ||
| 1435 | + if (_PyUnicode_EqualToASCIIString(name, "buffer_size")) { | ||
| 1437 | 1436 | long new_buffer_size; | |
| 1438 | 1437 | if (!PyLong_Check(v)) { | |
| 1439 | 1438 | PyErr_SetString(PyExc_TypeError, "buffer_size must be an integer"); | |
@@ -1479,7 +1478,7 @@ xmlparse_setattro(xmlparseobject *self, PyObject *name, PyObject *v) | |||
| 1479 | 1478 | return 0; | |
| 1480 | 1479 | } | |
| 1481 | 1480 | ||
| 1482 | - if (PyUnicode_CompareWithASCIIString(name, "CharacterDataHandler") == 0) { | ||
| 1481 | + if (_PyUnicode_EqualToASCIIString(name, "CharacterDataHandler")) { | ||
| 1483 | 1482 | /* If we're changing the character data handler, flush all | |
| 1484 | 1483 | * cached data with the old handler. Not sure there's a | |
| 1485 | 1484 | * "right" thing to do, though, but this probably won't | |
| Back | FazBrowse Home | New Git URL |
0 commit comments