def _ref(self, offset, data, kind, withSchema, attribute, view, name, afterLoadHooks): flags = data[offset] offset += 1 if flags & DBItemWriter.NONE: if flags & DBItemWriter.LIST: return offset, Empty else: return offset, None elif flags & DBItemWriter.SINGLE: return offset + 1, ItemRef(data[offset], view) elif flags & DBItemWriter.LIST: uuid = data[offset] offset += 1 if withSchema: otherName = data[offset] offset += 1 else: otherName = kind.getOtherName(name, None) value = view._createRefList(None, name, otherName, None, False, False, uuid) offset = self._readIndexes(offset, data, value, afterLoadHooks) return offset, value elif flags & DBItemWriter.SET: value = AbstractSet.makeValue(data[offset]) value._setView(view) offset = self._readIndexes(offset + 1, data, value, afterLoadHooks) return offset, value elif flags & DBItemWriter.DICT: if withSchema: otherName = data[offset] offset += 1 else: otherName = kind.getOtherName(name, None) value = RefDict(None, name, otherName) count = data[offset] offset += 1 for i in xrange(count): key, uuid = data[offset:offset + 2] offset += 2 value._dict[key] = view._createRefList(None, name, otherName, key, False, False, uuid) return offset, value else: raise LoadValueError, (self.name or self.uItem, name, "invalid cardinality: 0x%x" % (flags))
def _ref(self, offset, data, kind, withSchema, attribute, view, name, afterLoadHooks): flags = data[offset] offset += 1 if flags & DBItemWriter.NONE: if flags & DBItemWriter.LIST: return offset, Empty else: return offset, None elif flags & DBItemWriter.SINGLE: return offset + 1, ItemRef(data[offset], view) elif flags & DBItemWriter.LIST: uuid = data[offset] offset += 1 if withSchema: otherName = data[offset] offset += 1 else: otherName = kind.getOtherName(name, None) value = view._createRefList(None, name, otherName, None, False, False, uuid) offset = self._readIndexes(offset, data, value, afterLoadHooks) return offset, value elif flags & DBItemWriter.SET: value = AbstractSet.makeValue(data[offset]) value._setView(view) offset = self._readIndexes(offset + 1, data, value, afterLoadHooks) return offset, value elif flags & DBItemWriter.DICT: if withSchema: otherName = data[offset] offset += 1 else: otherName = kind.getOtherName(name, None) value = RefDict(None, name, otherName) count = data[offset] offset += 1 for i in xrange(count): key, uuid = data[offset : offset + 2] offset += 2 value._dict[key] = view._createRefList(None, name, otherName, key, False, False, uuid) return offset, value else: raise LoadValueError, (self.name or self.uItem, name, "invalid cardinality: 0x%x" % (flags))
def hasTrueValue(self, view, uValue): store = self.store record = store._values.c.loadValue(self.uItem, uValue, DBValueReader.VALUE_TYPES) uAttr, vFlags, data = record.data withSchema = (self.status & CItem.WITHSCHEMA) != 0 if withSchema: attribute = None offset, name = 1, data[0] else: attribute = view[uAttr] offset, name = 0, attribute.itsName flags = data[offset] if flags & DBItemWriter.VALUE: if flags & DBItemWriter.SIMPLE: value = data[offset + 1] else: offset, value = self._value(offset, data, None, withSchema, attribute, view, name, []) return not not value elif flags & DBItemWriter.REF: if flags & DBItemWriter.NONE: return False elif flags & DBItemWriter.SINGLE: return True elif flags & DBItemWriter.LIST: uuid = data[offset + 1] ref = self.store._refs.loadRef(view, uuid, self.version, uuid, True) return ref[2] > 0 elif flags & DBItemWriter.SET: value = AbstractSet.makeValue(data[offset + 1]) value._setView(view) return not not value else: raise ValueError, flags else: raise ValueError, flags
def readValue(self, view, uValue, toIndex=False): store = self.store record = store._values.c.loadValue(self.uItem, uValue, DBValueReader.VALUE_TYPES) uAttr, vFlags, data = record.data if toIndex and not (vFlags & CValues.TOINDEX): return uAttr, Nil withSchema = (self.status & CItem.WITHSCHEMA) != 0 if withSchema: attribute = None offset, name = 1, data[0] else: attribute = view[uAttr] offset, name = 0, attribute.itsName flags = data[offset] if flags & DBItemWriter.VALUE: if flags & DBItemWriter.SIMPLE: value = data[offset + 1] else: offset, value = self._value(offset, data, None, withSchema, attribute, view, name, []) return uAttr, value elif flags & DBItemWriter.REF: if flags & DBItemWriter.NONE: return uAttr, None elif flags & DBItemWriter.SINGLE: return uAttr, data[offset + 1] elif flags & DBItemWriter.LIST: return uAttr, DBStandAloneRefList(view, data[offset + 1], self.version) elif flags & DBItemWriter.SET: value = AbstractSet.makeValue(data[offset + 1]) value._setView(view) return uAttr, value elif flags & DBItemWriter.DICT: if withSchema: offset += 2 else: offset += 1 value = {} count = data[offset] offset += 1 for i in xrange(count): key, uuid = data[offset:offset + 2] offset += 2 value[key] = DBStandAloneRefList(view, uuid, self.version) return uAttr, value else: raise ValueError, flags else: raise ValueError, flags
def readValue(self, view, uValue, toIndex=False): store = self.store record = store._values.c.loadValue(self.uItem, uValue, DBValueReader.VALUE_TYPES) uAttr, vFlags, data = record.data if toIndex and not (vFlags & CValues.TOINDEX): return uAttr, Nil withSchema = (self.status & CItem.WITHSCHEMA) != 0 if withSchema: attribute = None offset, name = 1, data[0] else: attribute = view[uAttr] offset, name = 0, attribute.itsName flags = data[offset] if flags & DBItemWriter.VALUE: if flags & DBItemWriter.SIMPLE: value = data[offset + 1] else: offset, value = self._value(offset, data, None, withSchema, attribute, view, name, []) return uAttr, value elif flags & DBItemWriter.REF: if flags & DBItemWriter.NONE: return uAttr, None elif flags & DBItemWriter.SINGLE: return uAttr, data[offset + 1] elif flags & DBItemWriter.LIST: return uAttr, DBStandAloneRefList(view, data[offset + 1], self.version) elif flags & DBItemWriter.SET: value = AbstractSet.makeValue(data[offset + 1]) value._setView(view) return uAttr, value elif flags & DBItemWriter.DICT: if withSchema: offset += 2 else: offset += 1 value = {} count = data[offset] offset += 1 for i in xrange(count): key, uuid = data[offset : offset + 2] offset += 2 value[key] = DBStandAloneRefList(view, uuid, self.version) return uAttr, value else: raise ValueError, flags else: raise ValueError, flags