Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
contexts_value = cspo.get(
b("^").join([b(""), s, p, o, b("")]), txn=txn) or b("")
contexts = set(contexts_value.split(b("^")))
contexts.discard(c)
contexts_value = b("^").join(contexts)
for i, _to_key, _from_key in self.__indicies_info:
i.delete(_to_key((s, p, o), c), txn=txn)
if not quoted:
if contexts_value:
for i, _to_key, _from_key in self.__indicies_info:
i.put(_to_key((s, p, o), b("")), contexts_value, txn=txn)
else:
for i, _to_key, _from_key in self.__indicies_info:
try:
i.delete(_to_key((s, p, o), b("")), txn=txn)
except db.DBNotFoundError:
pass # TODO: is it okay to ignore these?
cursor = index.cursor(txn=txn)
try:
current = cursor.set_range(prefix)
needs_sync = True
except db.DBNotFoundError:
current = None
needs_sync = False
cursor.close()
while current:
key, value = current
cursor = index.cursor(txn=txn)
try:
cursor.set_range(key)
# Hack to stop 2to3 converting this to next(cursor)
current = getattr(cursor, 'next')()
except db.DBNotFoundError:
current = None
cursor.close()
if key.startswith(prefix):
c, s, p, o = from_key(key)
if context is None:
contexts_value = index.get(key, txn=txn) or b("")
contexts = set(contexts_value.split(b("^"))) # remove triple from all non quoted contexts
contexts.add(b("")) # and from the conjunctive index
for c in contexts:
for i, _to_key, _ in self.__indicies_info:
i.delete(_to_key((s, p, o), c), txn=txn)
else:
self.__remove((s, p, o), c, txn=txn)
else:
break
def _subject_predicates(self, object, context):
fromkey = self.fromkey
tokey = self.tokey
if context!=None:
prefix = "%s" % tokey(context)
index = self.__cosp
else:
prefix = ""
index = self.__osp
prefix += "%s" % tokey(object)
cursor = index.cursor()
try:
current = cursor.set_range(prefix)
except db.DBNotFoundError:
current = None
cursor.close()
while current:
key, value = current
cursor = index.cursor()
try:
cursor.set_range(key)
current = cursor.next()
except db.DBNotFoundError:
current = None
cursor.close()
if key.startswith(prefix):
if context!=None:
c, o, s, p = split(key)
else:
o, s, p = split(key)
else:
prefix = ""
index = self.__spo
cursor = index.cursor()
try:
current = cursor.set_range(prefix)
except db.DBNotFoundError:
current = None
cursor.close()
while current:
key, value = current
cursor = index.cursor()
try:
cursor.set_range(key)
current = cursor.next()
except db.DBNotFoundError:
current = None
cursor.close()
if key.startswith(prefix):
if context!=None:
c, s, p, o = split(key)
else:
s, p, o = split(key)
yield fromkey(s), fromkey(p), fromkey(o)
else:
break
def __all_prefix(self, prefix, index='spoc'):
next = True
next_key = prefix
while next:
c = self.__indices[index].cursor()
try:
current = c.set_range(next_key)
next = c.next()
if next:
next_key, data = next
except db.DBNotFoundError, e:
next = None
# what happens when the cursor is closed and re-opened between
# each access, does this mean that the lookup will be done again
# or is the location preserved somehow?
# in the first case it is better to collect a list of results and
# then yield over this list
c.close()
if current:
key, data = current
if key and key.startswith(prefix):
yield key, data
if next_key and not next_key.startswith(prefix):
next = None
def _getSerial(self, oid):
c = self._serials.cursor()
try:
lastvalue = None
# Search for the largest oid+revid key in the serials table that
# doesn't have a revid component equal to the current revid.
try:
rec = c.set_range(oid)
except db.DBNotFoundError:
rec = None
while rec:
key, value = rec
koid = key[:8]
ktid = key[8:]
if koid <> oid:
break
lastvalue = value
if ktid == self._serial:
break
rec = c.next()
if lastvalue is None:
return None
return lastvalue[:8]
finally:
c.close()
_from_string = self._from_string
index, prefix, from_key, results_from_key = self.__lookup((subject, predicate, object), context, txn=txn)
cursor = index.cursor(txn=txn)
try:
current = cursor.set_range(prefix)
except db.DBNotFoundError:
current = None
cursor.close()
while current:
key, value = current
cursor = index.cursor(txn=txn)
try:
cursor.set_range(key)
current = cursor.next()
except db.DBNotFoundError:
current = None
cursor.close()
if key and key.startswith(prefix):
contexts_value = index.get(key, txn=txn)
yield results_from_key(key, subject, predicate, object, contexts_value)
else:
break
def __all_prefix(self, prefix, index='spoc'):
next = True
next_key = prefix
while next:
c = self.__indices[index].cursor()
try:
current = c.set_range(next_key)
next = c.next()
if next:
next_key, data = next
except db.DBNotFoundError, e:
next = None
# what happens when the cursor is closed and re-opened between
# each access, does this mean that the lookup will be done again
# or is the location preserved somehow?
# in the first case it is better to collect a list of results and
# then yield over this list
c.close()
if current:
key, data = current
if key and key.startswith(prefix):
yield key, data
if next_key and not next_key.startswith(prefix):
next = None
if start is None:
key, value = self.last()
else:
try:
key, value = self.set_location(start)
except DBNotFoundError:
key, value = self.last()
if start is None or key <= start:
yield key, value
while True:
try:
key, value = self.previous()
except DBNotFoundError:
raise StopIteration
else:
if key < end:
raise StopIteration
yield key, value