Skip to content

Commit eb2c638

Browse files
Fix metadata pointer str() func not being used
1 parent 09b5d9a commit eb2c638

File tree

11 files changed

+39
-16
lines changed

11 files changed

+39
-16
lines changed

src/interface/shared/metadatum_wrappers.i

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ is expected."
6161
%feature("docstring") datum_type##_pointer::operator-> "
6262
Return the :class:`"#datum_type"` object being pointed to."
6363
%fragment("metadatum_str");
64+
// Define __str__ slot before defining class
65+
TP_STR_SLOT(datum_type##_pointer, self->__str__())
6466
%inline %{
6567
class datum_type##_pointer {
6668
protected:
@@ -122,8 +124,8 @@ public:
122124
}
123125
};
124126
%}
125-
// Add __str__ slot
126-
TP_STR(datum_type##_pointer, self->__str__())
127+
// Define __str__ function after defining class
128+
TP_STR_FUNC(datum_type##_pointer, self->__str__())
127129

128130
// Metadatum iterator wrapper
129131
%feature("python:slot", "tp_iter", functype="getiterfunc")

src/interface/shared/slots.i

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ static PyObject* _getitem_%mangle(type)_closure(
196196
%enddef // SQ_ITEM
197197

198198

199-
// Macro to add tp_str slot and function
200-
%define TP_STR(type, func)
199+
// Macros to add tp_str slot and function
200+
%define TP_STR_FUNC(type, func)
201201
%fragment("str"{type}, "header") {
202202
static PyObject* _str_%mangle(type)(PyObject* py_self) {
203203
type* self = NULL;
@@ -207,5 +207,11 @@ static PyObject* _str_%mangle(type)(PyObject* py_self) {
207207
};
208208
}
209209
%fragment("str"{type});
210+
%enddef
211+
%define TP_STR_SLOT(type, func)
210212
%feature("python:tp_str") type QUOTE(_str_%mangle(type));
213+
%enddef
214+
%define TP_STR(type, func)
215+
TP_STR_FUNC(type, func)
216+
TP_STR_SLOT(type, func)
211217
%enddef // TP_STR

src/swig-0_27_7/exif_wrap.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10177,7 +10177,7 @@ static PyHeapTypeObject SwigPyBuiltin__Exifdatum_pointer_type = {
1017710177
&SwigPyBuiltin__Exifdatum_pointer_type.as_mapping, /* tp_as_mapping */
1017810178
SwigPyObject_hash, /* tp_hash */
1017910179
(ternaryfunc) 0, /* tp_call */
10180-
(reprfunc) 0, /* tp_str */
10180+
_str_Exifdatum_pointer, /* tp_str */
1018110181
(getattrofunc) 0, /* tp_getattro */
1018210182
(setattrofunc) 0, /* tp_setattro */
1018310183
&SwigPyBuiltin__Exifdatum_pointer_type.as_buffer, /* tp_as_buffer */
@@ -10411,7 +10411,7 @@ static PyTypeObject *SwigPyBuiltin__Exifdatum_pointer_type_create(PyTypeObject *
1041110411
"is expected.\n"
1041210412
"" },
1041310413
{ Py_tp_repr, (void *)(reprfunc) 0 },
10414-
{ Py_tp_str, (void *)(reprfunc) 0 },
10414+
{ Py_tp_str, (void *)_str_Exifdatum_pointer },
1041510415
{ Py_tp_traverse, (void *)(traverseproc) 0 },
1041610416
{ Py_tp_clear, (void *)(inquiry) 0 },
1041710417
{ Py_tp_richcompare, (void *)SwigPyBuiltin__Exifdatum_pointer_richcompare },

src/swig-0_27_7/iptc_wrap.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9269,7 +9269,7 @@ static PyHeapTypeObject SwigPyBuiltin__Iptcdatum_pointer_type = {
92699269
&SwigPyBuiltin__Iptcdatum_pointer_type.as_mapping, /* tp_as_mapping */
92709270
SwigPyObject_hash, /* tp_hash */
92719271
(ternaryfunc) 0, /* tp_call */
9272-
(reprfunc) 0, /* tp_str */
9272+
_str_Iptcdatum_pointer, /* tp_str */
92739273
(getattrofunc) 0, /* tp_getattro */
92749274
(setattrofunc) 0, /* tp_setattro */
92759275
&SwigPyBuiltin__Iptcdatum_pointer_type.as_buffer, /* tp_as_buffer */
@@ -9503,7 +9503,7 @@ static PyTypeObject *SwigPyBuiltin__Iptcdatum_pointer_type_create(PyTypeObject *
95039503
"is expected.\n"
95049504
"" },
95059505
{ Py_tp_repr, (void *)(reprfunc) 0 },
9506-
{ Py_tp_str, (void *)(reprfunc) 0 },
9506+
{ Py_tp_str, (void *)_str_Iptcdatum_pointer },
95079507
{ Py_tp_traverse, (void *)(traverseproc) 0 },
95089508
{ Py_tp_clear, (void *)(inquiry) 0 },
95099509
{ Py_tp_richcompare, (void *)SwigPyBuiltin__Iptcdatum_pointer_richcompare },

src/swig-0_27_7/xmp_wrap.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9301,7 +9301,7 @@ static PyHeapTypeObject SwigPyBuiltin__Xmpdatum_pointer_type = {
93019301
&SwigPyBuiltin__Xmpdatum_pointer_type.as_mapping, /* tp_as_mapping */
93029302
SwigPyObject_hash, /* tp_hash */
93039303
(ternaryfunc) 0, /* tp_call */
9304-
(reprfunc) 0, /* tp_str */
9304+
_str_Xmpdatum_pointer, /* tp_str */
93059305
(getattrofunc) 0, /* tp_getattro */
93069306
(setattrofunc) 0, /* tp_setattro */
93079307
&SwigPyBuiltin__Xmpdatum_pointer_type.as_buffer, /* tp_as_buffer */
@@ -9535,7 +9535,7 @@ static PyTypeObject *SwigPyBuiltin__Xmpdatum_pointer_type_create(PyTypeObject *t
95359535
"is expected.\n"
95369536
"" },
95379537
{ Py_tp_repr, (void *)(reprfunc) 0 },
9538-
{ Py_tp_str, (void *)(reprfunc) 0 },
9538+
{ Py_tp_str, (void *)_str_Xmpdatum_pointer },
95399539
{ Py_tp_traverse, (void *)(traverseproc) 0 },
95409540
{ Py_tp_clear, (void *)(inquiry) 0 },
95419541
{ Py_tp_richcompare, (void *)SwigPyBuiltin__Xmpdatum_pointer_richcompare },

src/swig-0_28_7/exif_wrap.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10347,7 +10347,7 @@ static PyHeapTypeObject SwigPyBuiltin__Exifdatum_pointer_type = {
1034710347
&SwigPyBuiltin__Exifdatum_pointer_type.as_mapping, /* tp_as_mapping */
1034810348
SwigPyObject_hash, /* tp_hash */
1034910349
(ternaryfunc) 0, /* tp_call */
10350-
(reprfunc) 0, /* tp_str */
10350+
_str_Exifdatum_pointer, /* tp_str */
1035110351
(getattrofunc) 0, /* tp_getattro */
1035210352
(setattrofunc) 0, /* tp_setattro */
1035310353
&SwigPyBuiltin__Exifdatum_pointer_type.as_buffer, /* tp_as_buffer */
@@ -10581,7 +10581,7 @@ static PyTypeObject *SwigPyBuiltin__Exifdatum_pointer_type_create(PyTypeObject *
1058110581
"is expected.\n"
1058210582
"" },
1058310583
{ Py_tp_repr, (void *)(reprfunc) 0 },
10584-
{ Py_tp_str, (void *)(reprfunc) 0 },
10584+
{ Py_tp_str, (void *)_str_Exifdatum_pointer },
1058510585
{ Py_tp_traverse, (void *)(traverseproc) 0 },
1058610586
{ Py_tp_clear, (void *)(inquiry) 0 },
1058710587
{ Py_tp_richcompare, (void *)SwigPyBuiltin__Exifdatum_pointer_richcompare },

src/swig-0_28_7/iptc_wrap.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9446,7 +9446,7 @@ static PyHeapTypeObject SwigPyBuiltin__Iptcdatum_pointer_type = {
94469446
&SwigPyBuiltin__Iptcdatum_pointer_type.as_mapping, /* tp_as_mapping */
94479447
SwigPyObject_hash, /* tp_hash */
94489448
(ternaryfunc) 0, /* tp_call */
9449-
(reprfunc) 0, /* tp_str */
9449+
_str_Iptcdatum_pointer, /* tp_str */
94509450
(getattrofunc) 0, /* tp_getattro */
94519451
(setattrofunc) 0, /* tp_setattro */
94529452
&SwigPyBuiltin__Iptcdatum_pointer_type.as_buffer, /* tp_as_buffer */
@@ -9680,7 +9680,7 @@ static PyTypeObject *SwigPyBuiltin__Iptcdatum_pointer_type_create(PyTypeObject *
96809680
"is expected.\n"
96819681
"" },
96829682
{ Py_tp_repr, (void *)(reprfunc) 0 },
9683-
{ Py_tp_str, (void *)(reprfunc) 0 },
9683+
{ Py_tp_str, (void *)_str_Iptcdatum_pointer },
96849684
{ Py_tp_traverse, (void *)(traverseproc) 0 },
96859685
{ Py_tp_clear, (void *)(inquiry) 0 },
96869686
{ Py_tp_richcompare, (void *)SwigPyBuiltin__Iptcdatum_pointer_richcompare },

src/swig-0_28_7/xmp_wrap.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9525,7 +9525,7 @@ static PyHeapTypeObject SwigPyBuiltin__Xmpdatum_pointer_type = {
95259525
&SwigPyBuiltin__Xmpdatum_pointer_type.as_mapping, /* tp_as_mapping */
95269526
SwigPyObject_hash, /* tp_hash */
95279527
(ternaryfunc) 0, /* tp_call */
9528-
(reprfunc) 0, /* tp_str */
9528+
_str_Xmpdatum_pointer, /* tp_str */
95299529
(getattrofunc) 0, /* tp_getattro */
95309530
(setattrofunc) 0, /* tp_setattro */
95319531
&SwigPyBuiltin__Xmpdatum_pointer_type.as_buffer, /* tp_as_buffer */
@@ -9759,7 +9759,7 @@ static PyTypeObject *SwigPyBuiltin__Xmpdatum_pointer_type_create(PyTypeObject *t
97599759
"is expected.\n"
97609760
"" },
97619761
{ Py_tp_repr, (void *)(reprfunc) 0 },
9762-
{ Py_tp_str, (void *)(reprfunc) 0 },
9762+
{ Py_tp_str, (void *)_str_Xmpdatum_pointer },
97639763
{ Py_tp_traverse, (void *)(traverseproc) 0 },
97649764
{ Py_tp_clear, (void *)(inquiry) 0 },
97659765
{ Py_tp_richcompare, (void *)SwigPyBuiltin__Xmpdatum_pointer_richcompare },

tests/test_exif.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,10 @@ def test_ExifData(self):
7878
b = data.begin()
7979
e = data.end()
8080
self.assertIsInstance(str(b), str)
81+
self.assertEqual(str(b), 'iterator<Exif.Image.ProcessingSoftware:'
82+
' Photini editor v2022.12.0.3>')
8183
self.assertIsInstance(str(e), str)
84+
self.assertEqual(str(e), 'iterator<data end>')
8285
count = 0
8386
while b != e:
8487
next(b)
@@ -148,6 +151,8 @@ def test_ExifData(self):
148151

149152
def _test_datum(self, datum):
150153
self.assertIsInstance(str(datum), str)
154+
self.assertEqual(str(datum.__deref__()), 'Exif.Image.ImageDescription:'
155+
' Good view of the lighthouse.')
151156
buf = bytearray(datum.count())
152157
with self.assertWarns(DeprecationWarning):
153158
self.assertEqual(

tests/test_iptc.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,9 @@ def test_IptcData(self):
8181
b = data.begin()
8282
e = data.end()
8383
self.assertIsInstance(str(b), str)
84+
self.assertEqual(str(b), 'iterator<Iptc.Envelope.CharacterSet: \x1b%G>')
8485
self.assertIsInstance(str(e), str)
86+
self.assertEqual(str(e), 'iterator<data end>')
8587
count = 0
8688
while b != e:
8789
next(b)
@@ -124,6 +126,8 @@ def test_IptcData(self):
124126

125127
def _test_datum(self, datum):
126128
self.assertIsInstance(str(datum), str)
129+
self.assertEqual(str(datum.__deref__()), 'Iptc.Application2.Caption:'
130+
' Good view of the lighthouse.')
127131
buf = bytearray(datum.count())
128132
with self.assertWarns(DeprecationWarning):
129133
self.assertEqual(

0 commit comments

Comments
 (0)