Skip to content

Commit a8c87eb

Browse files
Deprecated exposing objects with buffer interface
This may become unavailable for some Python versions when SWIG is next updated. See swig/swig#3211 The buffer interface is a lot of overhead for little gain, and using the data() method to get an object's contents is a lot more explicit.
1 parent ffd568e commit a8c87eb

File tree

11 files changed

+45
-16
lines changed

11 files changed

+45
-16
lines changed

CHANGELOG.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ Changes in v0.18.0:
2626
4/ Add data() method to exiv2.PreviewImage, deprecate pData() method.
2727
5/ Deprecated many BasicIo methods (read, write, seek, etc.) that should not
2828
be needed in Python scripts. Let me know if this is a problem.
29+
6/ Deprecated 'buffer interface' to BasicIo, DataBuf, and PreviewImage. They
30+
all have 'data()' to get their contents.
2931

3032
Changes in v0.17.3:
3133
1/ Binary wheels incorporate libexiv2 v0.28.5.

src/interface/shared/buffers.i

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,9 @@ RETURN_VIEW_CB(signature, size_func, flags, NULL, doc_method)
164164
fragment="get_ptr_size"{object_type}) {
165165
static int getbuffer_%mangle(object_type)(
166166
PyObject* exporter, Py_buffer* view, int flags) {
167+
// Deprecated since 2025-07-09
168+
PyErr_WarnEx(PyExc_DeprecationWarning, "Please use 'data()' to get a"
169+
" memoryview of object_type", 1);
167170
object_type* self = 0;
168171
Exiv2::byte* ptr = 0;
169172
Py_ssize_t size = 0;

src/swig-0_27_7/basicio_wrap.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4387,6 +4387,9 @@ static bool get_ptr_size(Exiv2::BasicIo* self, bool is_writeable,
43874387

43884388
static int getbuffer_Exiv2_BasicIo(
43894389
PyObject* exporter, Py_buffer* view, int flags) {
4390+
// Deprecated since 2025-07-09
4391+
PyErr_WarnEx(PyExc_DeprecationWarning, "Please use 'data()' to get a"
4392+
" memoryview of Exiv2::BasicIo", 1);
43904393
Exiv2::BasicIo* self = 0;
43914394
Exiv2::byte* ptr = 0;
43924395
Py_ssize_t size = 0;

src/swig-0_27_7/preview_wrap.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5430,6 +5430,9 @@ static bool get_ptr_size(Exiv2::PreviewImage* self, bool is_writeable,
54305430

54315431
static int getbuffer_Exiv2_PreviewImage(
54325432
PyObject* exporter, Py_buffer* view, int flags) {
5433+
// Deprecated since 2025-07-09
5434+
PyErr_WarnEx(PyExc_DeprecationWarning, "Please use 'data()' to get a"
5435+
" memoryview of Exiv2::PreviewImage", 1);
54335436
Exiv2::PreviewImage* self = 0;
54345437
Exiv2::byte* ptr = 0;
54355438
Py_ssize_t size = 0;

src/swig-0_27_7/types_wrap.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4599,6 +4599,9 @@ static bool get_ptr_size(Exiv2::DataBuf* self, bool is_writeable,
45994599

46004600
static int getbuffer_Exiv2_DataBuf(
46014601
PyObject* exporter, Py_buffer* view, int flags) {
4602+
// Deprecated since 2025-07-09
4603+
PyErr_WarnEx(PyExc_DeprecationWarning, "Please use 'data()' to get a"
4604+
" memoryview of Exiv2::DataBuf", 1);
46024605
Exiv2::DataBuf* self = 0;
46034606
Exiv2::byte* ptr = 0;
46044607
Py_ssize_t size = 0;

src/swig-0_28_5/basicio_wrap.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4388,6 +4388,9 @@ static bool get_ptr_size(Exiv2::BasicIo* self, bool is_writeable,
43884388

43894389
static int getbuffer_Exiv2_BasicIo(
43904390
PyObject* exporter, Py_buffer* view, int flags) {
4391+
// Deprecated since 2025-07-09
4392+
PyErr_WarnEx(PyExc_DeprecationWarning, "Please use 'data()' to get a"
4393+
" memoryview of Exiv2::BasicIo", 1);
43914394
Exiv2::BasicIo* self = 0;
43924395
Exiv2::byte* ptr = 0;
43934396
Py_ssize_t size = 0;

src/swig-0_28_5/preview_wrap.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5430,6 +5430,9 @@ static bool get_ptr_size(Exiv2::PreviewImage* self, bool is_writeable,
54305430

54315431
static int getbuffer_Exiv2_PreviewImage(
54325432
PyObject* exporter, Py_buffer* view, int flags) {
5433+
// Deprecated since 2025-07-09
5434+
PyErr_WarnEx(PyExc_DeprecationWarning, "Please use 'data()' to get a"
5435+
" memoryview of Exiv2::PreviewImage", 1);
54335436
Exiv2::PreviewImage* self = 0;
54345437
Exiv2::byte* ptr = 0;
54355438
Py_ssize_t size = 0;

src/swig-0_28_5/types_wrap.cxx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4599,6 +4599,9 @@ static bool get_ptr_size(Exiv2::DataBuf* self, bool is_writeable,
45994599

46004600
static int getbuffer_Exiv2_DataBuf(
46014601
PyObject* exporter, Py_buffer* view, int flags) {
4602+
// Deprecated since 2025-07-09
4603+
PyErr_WarnEx(PyExc_DeprecationWarning, "Please use 'data()' to get a"
4604+
" memoryview of Exiv2::DataBuf", 1);
46024605
Exiv2::DataBuf* self = 0;
46034606
Exiv2::byte* ptr = 0;
46044607
Py_ssize_t size = 0;

tests/test_basicio.py

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,12 +95,13 @@ def test_MemIo(self):
9595
self.assertEqual(view[0], 0)
9696
self.assertEqual(io.munmap(), 0)
9797
# Python buffer interface
98-
with memoryview(io) as view:
99-
self.assertIsInstance(view, memoryview)
100-
self.assertEqual(view, b'')
101-
self.assertEqual(view.readonly, False)
102-
with self.assertRaises(IndexError):
103-
view[0] = 0
98+
with self.assertWarns(DeprecationWarning):
99+
with memoryview(io) as view:
100+
self.assertIsInstance(view, memoryview)
101+
self.assertEqual(view, b'')
102+
self.assertEqual(view.readonly, False)
103+
with self.assertRaises(IndexError):
104+
view[0] = 0
104105
# data() easy access
105106
with io.data(False) as view:
106107
self.assertIsInstance(view, memoryview)
@@ -143,9 +144,10 @@ def test_MemIo(self):
143144
with self.assertRaises(ValueError):
144145
self.assertEqual(view1[0], self.data[0])
145146
# Python buffer interface
146-
with memoryview(io) as view:
147-
self.assertEqual(view, self.data)
148-
self.assertEqual(view.readonly, False)
147+
with self.assertWarns(DeprecationWarning):
148+
with memoryview(io) as view:
149+
self.assertEqual(view, self.data)
150+
self.assertEqual(view.readonly, False)
149151
# data() easy access
150152
with io.data() as view:
151153
self.assertIsInstance(view, memoryview)
@@ -214,7 +216,8 @@ def test_MemIo(self):
214216
with self.assertWarns(DeprecationWarning):
215217
self.assertEqual(io.write(b'+jim'), 4)
216218
self.assertEqual(len(io), len(self.data) + 9)
217-
self.assertEqual(memoryview(io), self.data + b'+fred+jim')
219+
with self.assertWarns(DeprecationWarning):
220+
self.assertEqual(memoryview(io), self.data + b'+fred+jim')
218221

219222
def test_ref_counts(self):
220223
# MemIo keeps a reference to the data buffer

tests/test_exif.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,12 +199,14 @@ def test_ExifThumb(self):
199199
self.assertEqual(len(thumb.copy()), 0)
200200
exif_data = exiv2.ExifData()
201201
thumb = exiv2.ExifThumb(exif_data)
202-
thumb.setJpegThumbnail(data)
202+
with self.assertWarns(DeprecationWarning):
203+
thumb.setJpegThumbnail(data)
203204
self.assertEqual(len(thumb.copy()), 2532)
204205
thumb.erase()
205206
self.assertEqual(len(thumb.copy()), 0)
206-
thumb.setJpegThumbnail(
207-
data, exiv2.URational((160, 1)), exiv2.URational((120, 1)), 1)
207+
with self.assertWarns(DeprecationWarning):
208+
thumb.setJpegThumbnail(
209+
data, exiv2.URational((160, 1)), exiv2.URational((120, 1)), 1)
208210
self.assertEqual(len(thumb.copy()), 2532)
209211
if not exiv2.versionInfo()['EXV_ENABLE_FILESYSTEM']:
210212
self.skipTest('EXV_ENABLE_FILESYSTEM is off')

0 commit comments

Comments
 (0)