Exemplo n.º 1
0
    def keys_dict(self):
        fd = self._fd
        index_start, index_len, data_len = self._check_magic(fd)
        data_start = index_start + index_len
        keys_dict = OrderedDict()
        key_rewrite = self._reading_key_rewrites.get
        while index_len:
            key_len = struct.unpack(">L", fd.read(4))[0]
            key = fd.read(key_len)
            key = key.decode('ascii')
            if len(key) != key_len:
                raise MalformedXpak(
                    "tried reading key %i of len %i, but hit EOF" % (
                        len(keys_dict) + 1, key_len))
            try:
                offset, data_len = struct.unpack(">LL", fd.read(8))
            except struct.error as e:
                raise MalformedXpak(
                    "key %i, tried reading data offset/len but hit EOF" % (
                        len(keys_dict) + 1)) from e
            key = key_rewrite(key, key)
            keys_dict[key] = (
                data_start + offset, data_len,
                not key.startswith("environment"))
            index_len -= (key_len + 12) # 12 for key_len, offset, data_len longs

        return keys_dict
Exemplo n.º 2
0
    def keys_dict(self):
        fd = self._fd
        index_start, index_len, data_len = self._check_magic(fd)
        data_start = index_start + index_len
        keys_dict = OrderedDict()
        key_rewrite = self._reading_key_rewrites.get
        while index_len:
            key_len = struct.unpack(">L", fd.read(4))[0]
            key = fd.read(key_len)
            key = key.decode('ascii')
            if len(key) != key_len:
                raise MalformedXpak(
                    "tried reading key %i of len %i, but hit EOF" % (
                        len(keys_dict) + 1, key_len))
            try:
                offset, data_len = struct.unpack(">LL", fd.read(8))
            except struct.error as e:
                raise MalformedXpak(
                    "key %i, tried reading data offset/len but hit EOF" % (
                        len(keys_dict) + 1)) from e
            key = key_rewrite(key, key)
            keys_dict[key] = (
                data_start + offset, data_len,
                not key.startswith("environment"))
            index_len -= (key_len + 12) # 12 for key_len, offset, data_len longs

        return keys_dict