KDE 4.9 PyKDE API Reference

- KDE's Python API

# NodeIterator Class Reference

`from PyKDE4.soprano import *`

Subclasses: Soprano.Client.DBusNodeIterator, Soprano.Util.SimpleNodeIterator
Namespace: Soprano

## Detailed Description

\class NodeIterator nodeiterator.h Soprano/NodeIterator

An iterator that provides a stream of Nodes.

The most common use of %NodeIterator is through Model.listContexts().

Many backends do lock the underlying Model during iteration. Thus, it is always a good idea to cache the results if they are to be used to modify the model to prevent a deadlock:

     Soprano.NodeIterator it = model->listContexts();
     QList<Node> allNodes = it.allElements();
     Q_FOREACH( Soprano.Node n, allNodes ) {
        modifyTheModel( model, n );
     }

Iterators have to be closed. This can either be achieved by deleting the iterator, finishing it (next() does return false), or calling close(). Before that other operations on the Model may block.

Iterators are not thread-safe. Two threads using the same iterator may result in undefined behaviour and even crashes. An iterator needs to be closed by the same thread that opened it (except if the iterator contains special code to handle such a situation.)

Warning:
  Be aware that iterators in Soprano are shared objects which means that copies of one iterator object work on the same data.

For further details on %Soprano iterators see Iterator.

Author:
  Sebastian Trueg <trueg@kde.org>

## Methods

| __init__ (self)
| __init__ (self, Soprano.NodeIterator sti)
[Soprano.Node] | allElements (self)
[Soprano.Node] | allNodes (self)
| close (self)
Soprano.Node | current (self)
bool | isValid (self)
bool | next (self)

## Method Documentation

__init__ | ( |  | self ) |

Creates and empty, invalid iterator.

__init__ | ( | self, |
|  | Soprano.NodeIterator | sti
| ) |  |  |

Create a new NodeIterator instance that uses sti as backend. NodeIterator will take ownership of the backend.

[Soprano.Node] allElements | ( |  | self ) |

[Soprano.Node] allNodes | ( |  | self ) |

Convenience method which extracts all nodes (this does not include the nodes that have already been read from the iterator) from the iterator and returns them in a list.

Be aware that after calling this method the iterator will be invalid.

Returns:
  A list of all nodes that rest in the iterator.

close | ( |  | self ) |

Soprano.Node current | ( |  | self ) |

bool isValid | ( |  | self ) |

bool next | ( |  | self ) |