MCPcopy Create free account
hub / github.com/MagicStack/asyncpg / record_item_by_name

Function record_item_by_name

asyncpg/protocol/record/recordobj.c:431–474  ·  view source on GitHub ↗

Lookup a record value by its name. Return 0 on success, -2 if the * value was not found (with KeyError set), and -1 on all other errors. */

Source from the content-addressed store, hash-verified

429 * value was not found (with KeyError set), and -1 on all other errors.
430 */
431static item_by_name_result_t
432record_item_by_name(ApgRecordObject *o, PyObject *item, PyObject **result)
433{
434 PyObject *mapped;
435 PyObject *val;
436 Py_ssize_t i;
437
438 mapped = PyObject_GetItem(o->desc->mapping, item);
439 if (mapped == NULL) {
440 goto noitem;
441 }
442
443 if (!PyIndex_Check(mapped)) {
444 Py_DECREF(mapped);
445 goto error;
446 }
447
448 i = PyNumber_AsSsize_t(mapped, PyExc_IndexError);
449 Py_DECREF(mapped);
450
451 if (i < 0) {
452 if (PyErr_Occurred())
453 PyErr_Clear();
454 goto error;
455 }
456
457 val = record_item(o, i);
458 if (val == NULL) {
459 PyErr_Clear();
460 goto error;
461 }
462
463 *result = val;
464
465 return APG_ITEM_FOUND;
466
467noitem:
468 PyErr_SetObject(PyExc_KeyError, item);
469 return APG_ITEM_NOT_FOUND;
470
471error:
472 PyErr_SetString(PyExc_RuntimeError, "invalid record descriptor");
473 return APG_ERROR;
474}
475
476static PyObject *
477record_subscript(PyObject *op, PyObject *item)

Callers 2

record_subscriptFunction · 0.85
record_getFunction · 0.85

Calls 1

record_itemFunction · 0.85

Tested by

no test coverage detected