From 74784533592823753eb13376757059f85e2237f6 Mon Sep 17 00:00:00 2001 From: "Jose M. Guisado" Date: Tue, 20 Dec 2022 16:04:52 +0100 Subject: context: add label to repr function Adds label information to context repr function. %R is used to get the repr result of a PyObject, in this case this object is the LabelObject representing the context's label information. Helps showing more of the context information when printing out a context object instance. >>> import fdisk >>> cxt = fdisk.Context('disk.bin') >>> cxt , details=True, readonly=False> --- context.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/context.c b/context.c index 94a9fe7..805a2b7 100644 --- a/context.c +++ b/context.c @@ -296,8 +296,14 @@ static PyGetSetDef Context_getseters[] = { static PyObject *Context_repr(ContextObject *self) { - return PyUnicode_FromFormat("", + PyObject *lbo = Py_None; + + if (fdisk_has_label(self->cxt)) + lbo = PyObjectResultLabel(fdisk_get_label(self->cxt, NULL)); + + return PyUnicode_FromFormat("", self, + lbo, fdisk_is_details(self->cxt) ? "True" : "False", fdisk_is_readonly(self->cxt) ? "True" : "False"); } -- cgit v1.2.3-18-g5258