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

Function record_repr

asyncpg/protocol/record/recordobj.c:546–620  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

544}
545
546static PyObject *
547record_repr(PyObject *self)
548{
549 ApgRecordObject *v = (ApgRecordObject *)self;
550 Py_ssize_t i, n;
551 PyObject *keys_iter;
552 PyUnicodeWriter *writer;
553
554 n = Py_SIZE(v);
555 if (n == 0) {
556 return PyUnicode_FromFormat("<%s>", get_typename(Py_TYPE(v)));
557 }
558
559 keys_iter = PyObject_GetIter(v->desc->keys);
560 if (keys_iter == NULL) {
561 return NULL;
562 }
563
564 i = Py_ReprEnter((PyObject *)v);
565 if (i != 0) {
566 Py_DECREF(keys_iter);
567 if (i > 0) {
568 return PyUnicode_FromFormat("<%s ...>", get_typename(Py_TYPE(v)));
569 }
570 return NULL;
571 }
572 writer = PyUnicodeWriter_Create(12); /* <Record a=1> */
573
574 if (PyUnicodeWriter_Format(writer, "<%s ", get_typename(Py_TYPE(v))) < 0) {
575 goto error;
576 }
577
578 for (i = 0; i < n; ++i) {
579 int res;
580 PyObject *key;
581
582 if (i > 0)
583 if (PyUnicodeWriter_WriteChar(writer, ' ') < 0)
584 goto error;
585
586 key = PyIter_Next(keys_iter);
587 if (key == NULL) {
588 PyErr_SetString(PyExc_RuntimeError, "invalid record mapping");
589 goto error;
590 }
591
592 res = PyUnicodeWriter_WriteStr(writer, key);
593 Py_DECREF(key);
594 if (res < 0)
595 goto error;
596
597 if (PyUnicodeWriter_WriteChar(writer, '=') < 0)
598 goto error;
599
600 if (Py_EnterRecursiveCall(" while getting the repr of a record"))
601 goto error;
602 res = PyUnicodeWriter_WriteRepr(writer, v->ob_item[i]);
603 Py_LeaveRecursiveCall();

Callers

nothing calls this directly

Calls 8

get_typenameFunction · 0.85
PyUnicodeWriter_CreateFunction · 0.85
PyUnicodeWriter_FormatFunction · 0.85
PyUnicodeWriter_WriteStrFunction · 0.85
PyUnicodeWriter_FinishFunction · 0.85
PyUnicodeWriter_DiscardFunction · 0.85

Tested by

no test coverage detected