def __init__(self, cache, obj): self._cache = cache self._nl_object = None if not obj: self._end = 1 else: capi.nl_object_get(obj) self._nl_object = obj self._first = 1 self._end = 0
def next(self): if self._end: raise StopIteration() if self._first: ret = self._nl_object self._first = 0 else: ret = self.get_next() if not ret: self._end = 1 raise StopIteration() # return ref of previous element and acquire ref of current # element to have object stay around until we fetched the # next ptr capi.nl_object_put(self._nl_object) capi.nl_object_get(ret) self._nl_object = ret # reference used inside object capi.nl_object_get(ret) return self._cache._new_object(ret)