@dloopfun
def first(self):
try:
- if self.fd is None:
+ if self.fd is missing:
self.item = self._decode(self.cur.first())
else:
k, v = self._decode(self.cur.set_range(self.typ.encode(self.fd)))
@dloopfun
def last(self):
try:
- if self.fd is None:
+ if self.ld is missing:
self.item = self._decode(self.cur.last())
else:
- k, v = self._decode(self.cur.set_range(self.typ.encode(self.ld)))
- if self.fi:
- while self.typ.compare(k, self.fd) == 0:
+ try:
+ k, v = self._decode(self.cur.set_range(self.typ.encode(self.ld)))
+ except notfound:
+ k, v = self._decode(self.cur.last())
+ if self.li:
+ while self.typ.compare(k, self.ld) == 0:
k, v = self._decode(self.cur.next())
- k, v = self._decode(self.cur.prev())
+ while self.typ.compare(k, self.ld) > 0:
+ k, v = self._decode(self.cur.prev())
else:
- while self.typ.compare(k, self.fd) >= 0:
+ while self.typ.compare(k, self.ld) >= 0:
k, v = self._decode(self.cur.prev())
self.item = k, v
except notfound:
def next(self):
try:
k, v = self.item = self._decode(self.cur.next())
- if ((self.li and self.typ.compare(k, self.ld) > 0) or
- (not self.li and self.typ.compare(k, self.ld) >= 0)):
+ if (self.ld is not missing and
+ ((self.li and self.typ.compare(k, self.ld) > 0) or
+ (not self.li and self.typ.compare(k, self.ld) >= 0))):
self.item = StopIteration
except notfound:
self.item = StopIteration
def prev(self):
try:
self.item = self._decode(self.cur.prev())
- if ((self.fi and self.typ.compare(k, self.fd) < 0) or
- (not self.fi and self.typ.compare(k, self.fd) <= 0)):
+ if (self.fd is not missing and
+ ((self.fi and self.typ.compare(k, self.fd) < 0) or
+ (not self.fi and self.typ.compare(k, self.fd) <= 0))):
self.item = StopIteration
except notfound:
self.item = StopIteration
def get(self, *, match=missing, ge=missing, gt=missing, lt=missing, le=missing, all=False, reverse=False):
if all:
- cur = self.cursor(self, None, True, None, True, reverse)
+ cur = self.cursor(self, missing, True, missing, True, reverse)
elif match is not missing:
cur = self.cursor(self, match, True, match, True, reverse)
elif ge is not missing or gt is not missing or lt is not missing or le is not missing:
elif gt is not missing:
fd, fi = gt, False
else:
- fd, fi = None, True
+ fd, fi = missing, True
if le is not missing:
ld, li = le, True
elif lt is not missing:
ld, li = lt, False
else:
- ld, li = None, True
+ ld, li = missing, True
cur = self.cursor(self, fd, fi, ld, li, reverse)
else:
raise NameError("invalid get() specification")