Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _resolve(self, node):
resolved = node - self._meta.node_count + self._meta.node_count * 8
size = bytes2long(0, 0, self.data[resolved], self.data[resolved + 1])
if (resolved+2+size) > len(self.data):
raise DatabaseError("database is error")
return self.data[resolved+2:resolved+2+size]
def __init__(self, name):
self._v4offset = 0
self._v6offsetCache = {}
file = open(name, "rb")
self.data = file.read()
self._file_size = len(self.data)
file.close()
meta_length = bytes2long(self.data[0], self.data[1], self.data[2], self.data[3])
if sys.version_info < (3,0):
meta = json.loads(str(self.data[4:meta_length + 4]))
else:
meta = json.loads(str(self.data[4:meta_length + 4], 'utf-8'))
self._meta = MetaData(**meta)
if len(self._meta.languages) == 0 or len(self._meta.fields) == 0:
raise DatabaseError("database meta error")
if self._file_size != (4 + meta_length + self._meta.total_size):
raise DatabaseError("database size error")
self.data = self.data[4+meta_length:]
def _read_node(self, node, idx):
off = idx * 4 + node * 8
return bytes2long(self.data[off], self.data[off + 1], self.data[off + 2], self.data[off + 3])