Skip to content

Commit f4dd9fe

Browse files
Merge pull request #189 from jim-easterbrook/devel
Reinstated CameraList iterator
2 parents c603733 + af37f79 commit f4dd9fe

6 files changed

Lines changed: 65 additions & 6 deletions

File tree

CHANGELOG.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ License along with python-gphoto2. If not, see
1919
<https://www.gnu.org/licenses/>.
2020

2121

22+
Changes in 2.6.1:
23+
1/ Reinstated CameraList.__iter__ removed in v2.6.0, but deprecated.
24+
2225
Changes in 2.6.0:
26+
0/ API change: Removed CameraList.__iter__, use CameraList.items() instead.
2327
1/ Deprecated passing a CameraFile object to file_get() and capture_preview()
2428
functions. These allocate a new CameraFile object for the return value.
2529
2/ CameraWidget now has len and [] (index) methods.

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
python-gphoto2 v\ 2.6.0
1+
python-gphoto2 v\ 2.6.1
22
=======================
33

44
python-gphoto2 is a comprehensive Python interface (or binding) to libgphoto2_.

src/gphoto2/list.i

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// python-gphoto2 - Python interface to libgphoto2
22
// http://github.com/jim-easterbrook/python-gphoto2
3-
// Copyright (C) 2014-24 Jim Easterbrook jim@jim-easterbrook.me.uk
3+
// Copyright (C) 2014-25 Jim Easterbrook jim@jim-easterbrook.me.uk
44
//
55
// This file is part of python-gphoto2.
66
//
@@ -145,6 +145,10 @@ typedef struct _CameraList_accessor {} CameraList_accessor;
145145
// Make CameraList more like a Python list and/or dict
146146
%feature("python:slot", "mp_subscript", functype="binaryfunc")
147147
_CameraList::__getitem__;
148+
%feature("python:slot", "tp_iter", functype="getiterfunc")
149+
_CameraList::__iter__;
150+
// deprecated since 2025-06-03, v2.6.1
151+
DEPRECATED(_CameraList::__iter__, 1)
148152
%feature("docstring") _CameraList::keys "Return an accessor for the names in the list."
149153
%feature("docstring") _CameraList::values "Return an accessor for the values in the list."
150154
%feature("docstring") _CameraList::items "Return an accessor for the (name, value) pairs in the list."
@@ -182,6 +186,11 @@ typedef struct _CameraList_accessor {} CameraList_accessor;
182186
CameraList_accessor* items() {
183187
return new_CameraList_accessor($self, CameraList_get_item);
184188
}
189+
PyObject* __iter__() {
190+
return PySeqIter_New(SWIG_Python_NewPointerObj(
191+
NULL, SWIG_as_voidptr(_CameraList_items($self)),
192+
$descriptor(CameraList_accessor*), SWIG_POINTER_OWN));
193+
}
185194
};
186195

187196
// Turn on default exception handling

src/swig-gp2_5_31/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
__version__ = "2.6.0"
2-
__version_tuple__ = tuple((2, 6, 0))
1+
__version__ = "2.6.1"
2+
__version_tuple__ = tuple((2, 6, 1))
33

44

55
import os

src/swig-gp2_5_31/list_wrap.c

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4388,6 +4388,11 @@ SWIGINTERN CameraList_accessor *_CameraList_values(struct _CameraList *self){
43884388
SWIGINTERN CameraList_accessor *_CameraList_items(struct _CameraList *self){
43894389
return new_CameraList_accessor(self, CameraList_get_item);
43904390
}
4391+
SWIGINTERN PyObject *_CameraList___iter__(struct _CameraList *self){
4392+
return PySeqIter_New(SWIG_Python_NewPointerObj(
4393+
NULL, SWIG_as_voidptr(_CameraList_items(self)),
4394+
SWIGTYPE_p__CameraList_accessor, SWIG_POINTER_OWN));
4395+
}
43914396
SWIGINTERN int _CameraList___len__(struct _CameraList *self){
43924397

43934398

@@ -4789,6 +4794,34 @@ SWIGINTERN PyObject *_wrap_CameraList_items(PyObject *self, PyObject *args) {
47894794
}
47904795

47914796

4797+
SWIGINTERN PyObject *_wrap_CameraList___iter__(PyObject *self, PyObject *args) {
4798+
PyObject *resultobj = 0;
4799+
struct _CameraList *arg1 = (struct _CameraList *) 0 ;
4800+
void *argp1 = 0 ;
4801+
int res1 = 0 ;
4802+
PyObject *result = 0 ;
4803+
4804+
if (args && PyTuple_Check(args) && PyTuple_GET_SIZE(args) > 0) SWIG_exception_fail(SWIG_TypeError, "CameraList___iter__ takes no arguments");
4805+
res1 = SWIG_ConvertPtr(self, &argp1,SWIGTYPE_p__CameraList, 0 | 0 );
4806+
if (!SWIG_IsOK(res1)) {
4807+
SWIG_exception_fail(SWIG_ArgError(res1), "in method '" "CameraList___iter__" "', argument " "1"" of type '" "struct _CameraList *""'");
4808+
}
4809+
arg1 = (struct _CameraList *)(argp1);
4810+
{
4811+
if (PyErr_WarnEx(PyExc_DeprecationWarning,"_CameraList::__iter__"" is deprecated and"
4812+
" will be removed in a future release", 1) < 0) SWIG_fail;
4813+
result = (PyObject *)_CameraList___iter__(arg1);
4814+
4815+
if (PyErr_Occurred()) SWIG_fail;
4816+
4817+
}
4818+
resultobj = result;
4819+
return resultobj;
4820+
fail:
4821+
return NULL;
4822+
}
4823+
4824+
47924825
SWIGINTERN PyObject *_wrap_CameraList___len__(PyObject *self, PyObject *args) {
47934826
PyObject *resultobj = 0;
47944827
struct _CameraList *arg1 = (struct _CameraList *) 0 ;
@@ -5197,6 +5230,8 @@ SWIGPY_DESTRUCTOR_CLOSURE(_wrap_delete_CameraList) /* defines _wrap_delete_Camer
51975230

51985231
SWIGPY_BINARYFUNC_CLOSURE(_wrap_CameraList___getitem__) /* defines _wrap_CameraList___getitem___binaryfunc_closure */
51995232

5233+
SWIGPY_GETITERFUNC_CLOSURE(_wrap_CameraList___iter__) /* defines _wrap_CameraList___iter___getiterfunc_closure */
5234+
52005235
SWIGPY_LENFUNC_CLOSURE(_wrap_CameraList___len__) /* defines _wrap_CameraList___len___lenfunc_closure */
52015236

52025237
SWIGINTERN PyObject *_wrap_delete_CameraList_accessor(PyObject *self, PyObject *args) {
@@ -5975,6 +6010,10 @@ SWIGINTERN PyMethodDef SwigPyBuiltin___CameraList_methods[] = {
59756010
"items(self) -> CameraList_accessor\n"
59766011
"Return an accessor for the (name, value) pairs in the list.\n"
59776012
"" },
6013+
{ "__iter__", _wrap_CameraList___iter__, METH_VARARGS, "\n"
6014+
"__iter__(self) -> PyObject *\n"
6015+
"This function is deprecated and will be removed in a future release.\n"
6016+
"" },
59786017
{ "__len__", _wrap_CameraList___len__, METH_VARARGS, "__len__(self) -> int" },
59796018
{ "count", _wrap_CameraList_count, METH_VARARGS, "\n"
59806019
"count(self) -> int\n"
@@ -6227,7 +6266,7 @@ static PyHeapTypeObject SwigPyBuiltin___CameraList_type = {
62276266
(inquiry) 0, /* tp_clear */
62286267
SwigPyBuiltin___CameraList_richcompare, /* tp_richcompare */
62296268
0, /* tp_weaklistoffset */
6230-
(getiterfunc) 0, /* tp_iter */
6269+
_wrap_CameraList___iter___getiterfunc_closure, /* tp_iter */
62316270
(iternextfunc) 0, /* tp_iternext */
62326271
SwigPyBuiltin___CameraList_methods, /* tp_methods */
62336272
0, /* tp_members */
@@ -6444,7 +6483,7 @@ static PyTypeObject *SwigPyBuiltin___CameraList_type_create(PyTypeObject *type,
64446483
{ Py_mp_length, (void *)(lenfunc) 0 },
64456484
{ Py_mp_subscript, (void *)_wrap_CameraList___getitem___binaryfunc_closure },
64466485
{ Py_mp_ass_subscript, (void *)(objobjargproc) 0 },
6447-
{ Py_tp_iter, (void *)(getiterfunc) 0 },
6486+
{ Py_tp_iter, (void *)_wrap_CameraList___iter___getiterfunc_closure },
64486487
{ Py_tp_iternext, (void *)(iternextfunc) 0 },
64496488
{ Py_nb_add, (void *)(binaryfunc) 0 },
64506489
{ Py_nb_subtract, (void *)(binaryfunc) 0 },

tests/test_list.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,13 @@ def test_oo_style(self):
6969
self.assertEqual(test_list['A'], '1')
7070
with self.assertRaises(KeyError):
7171
test_list['Z']
72+
with self.assertWarns(DeprecationWarning):
73+
it = iter(test_list)
74+
self.assertEqual(next(it), test_list[0])
75+
self.assertEqual(next(it), test_list[1])
76+
self.assertEqual(next(it), test_list[2])
77+
with self.assertRaises(StopIteration):
78+
next(it)
7279
it = iter(test_list.items())
7380
self.assertEqual(next(it), test_list[0])
7481
self.assertEqual(next(it), test_list[1])

0 commit comments

Comments
 (0)