]>
Commit | Line | Data |
---|---|---|
c8b5c51e | 1 | # Copyright (C) 2012 W. Trevor King <wking@tremily.us> |
075f4ea0 | 2 | # |
c8b5c51e TK |
3 | # This file is part of python-kmod. |
4 | # | |
5 | # python-kmod is free software: you can redistribute it and/or modify it under | |
6 | # the terms of the GNU Lesser General Public License version 2.1 as published | |
7 | # by the Free Software Foundation. | |
8 | # | |
9 | # python-kmod is distributed in the hope that it will be useful, but WITHOUT | |
10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
11 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
12 | # details. | |
075f4ea0 TK |
13 | # |
14 | # You should have received a copy of the GNU Lesser General Public License | |
c8b5c51e | 15 | # along with python-kmod. If not, see <http://www.gnu.org/licenses/>. |
075f4ea0 | 16 | |
f7c62154 TK |
17 | cimport _libkmod_h |
18 | ||
19 | ||
20 | cdef class ModListItem (object): | |
21 | "Wrap a struct kmod_list* list item" | |
22 | def __cinit__(self): | |
23 | self.list = NULL | |
24 | ||
25 | ||
26 | cdef class ModList (ModListItem): | |
27 | "Wrap a struct kmod_list* list with iteration" | |
28 | def __cinit__(self): | |
29 | self._next = NULL | |
30 | ||
31 | def __dealloc__(self): | |
32 | if self.list is not NULL: | |
33 | _libkmod_h.kmod_module_unref_list(self.list) | |
34 | ||
35 | def __iter__(self): | |
36 | self._next = self.list | |
37 | return self | |
38 | ||
39 | def __next__(self): | |
40 | if self._next is NULL: | |
41 | raise StopIteration() | |
42 | mli = ModListItem() | |
43 | mli.list = self._next | |
44 | self._next = _libkmod_h.kmod_list_next(self.list, self._next) | |
45 | return mli |