diff options
| author | Julian Andres Klode <jak@debian.org> | 2010-02-13 15:34:24 +0100 |
|---|---|---|
| committer | Julian Andres Klode <jak@debian.org> | 2010-02-13 15:34:24 +0100 |
| commit | c8fa835540d60393f2a1168625bf5d5ae01c4538 (patch) | |
| tree | b99415fbe2d2bfe2249c3beb5083c2b0587734c9 /python/tag.cc | |
| parent | 0401747854d7fc26eb097663822e26a988cf4aa4 (diff) | |
| download | python-apt-c8fa835540d60393f2a1168625bf5d5ae01c4538.tar.gz | |
python/tagfile.cc: Implement the iterator protocol in TagFile.
Diffstat (limited to 'python/tag.cc')
| -rw-r--r-- | python/tag.cc | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/python/tag.cc b/python/tag.cc index 2aaf3beb..4971a03d 100644 --- a/python/tag.cc +++ b/python/tag.cc @@ -258,6 +258,28 @@ static PyObject *TagFileStep(PyObject *Self,PyObject *Args) return HandleErrors(Py_BuildValue("i",1)); } +// TagFile Wrappers /*{{{*/ +static PyObject *TagFileNext(PyObject *Self) +{ + TagFileData &Obj = *(TagFileData *)Self; + // Replace the section. + Py_CLEAR(Obj.Section); + Obj.Section = (TagSecData*)(&PyTagSection_Type)->tp_alloc(&PyTagSection_Type, 0); + new (&Obj.Section->Object) pkgTagSection(); + Obj.Section->Owner = Self; + Py_INCREF(Obj.Section->Owner); + Obj.Section->Data = 0; + if (Obj.Object.Step(Obj.Section->Object) == false) + return HandleErrors(NULL); + Py_INCREF(Obj.Section); + return HandleErrors(Obj.Section); +} + +static PyObject *TagFileIter(PyObject *Self) { + Py_INCREF(Self); + return Self; +} + static char *doc_Offset = "Offset() -> Integer"; static PyObject *TagFileOffset(PyObject *Self,PyObject *Args) { @@ -541,9 +563,13 @@ static PyGetSetDef TagFileGetSet[] = { static char *doc_TagFile = "TagFile(file) -> TagFile() object. \n\n" "TagFile() objects provide access to debian control files, which consists\n" "of multiple RFC822-like formatted sections.\n\n" - "A file may consists of multiple sections, and you can use Step() to move\n" - "forward. The current TagSection() is available via the attribute section" - ".\n\n" + "To provide access to those sections, TagFile objects provide an iterator\n" + "which yields TagSection objects for each section.\n\n" + "TagFile objects also provide another API which uses a shared TagSection\n" + "object in the 'section' member. The functions step() and jump() can be\n" + "used to navigate in the file; and offset() tells the current position.\n\n" + "It is important to not mix the use of both APIs, because this can have\n" + "unwanted effects.\n\n" "The parameter *file* refers to an object providing a fileno() method or\n" "a file descriptor (an integer)"; @@ -578,8 +604,8 @@ PyTypeObject PyTagFile_Type = TagFileClear, // tp_clear 0, // tp_richcompare 0, // tp_weaklistoffset - 0, // tp_iter - 0, // tp_iternext + TagFileIter, // tp_iter + TagFileNext, // tp_iternext TagFileMethods, // tp_methods 0, // tp_members TagFileGetSet, // tp_getset |
