<commit_before>from zc.zlibstorage import ZlibStorage
import logging
import zope.interface
from zerodb.transform import encrypt, decrypt, compress, decompress
from zerodb.util import encode_hex
from zerodb.util.debug import debug_loads


class TransformingStorage(ZlibStorage):
    """
    Storage which can transform (encrypt and/or compress) data.
    """

    def __init__(self, base, *args, **kw):
        """
        :param base: Storage to transform
        :param bool debug: Output debug log messages
        """
        self.base = base

        self.debug = kw.pop("debug", False)
        if self.debug:
            self._debug_download_size = 0
            self._debug_download_count = 0

        for name in self.copied_methods:
            v = getattr(base, name, None)
            if v is not None:
                setattr(self, name, v)

        zope.interface.directlyProvides(self, zope.interface.providedBy(base))

        base.registerDB(self)

        self._transform = lambda data: encrypt(compress(data), no_cipher_name=True)
        self._transform_named = lambda data: encrypt(compress(data), no_cipher_name=False)
        self._untransform = lambda data: decompress(decrypt(data))

        self._root_oid = None

    def loadBefore(self, oid, tid):
        """Load last state for a given oid before a given tid

        :param str oid: Object ID
        :param str tid: Transaction timestamp
        :return: Object and its serial number and following serial number
        :rtype: tuple
        """
        if self.debug:
            if oid not in self._cache.current:
                in_cache = False
            else:
                in_cache = True
<commit_msg>set root oid on construction<commit_after>from zc.zlibstorage import ZlibStorage
import logging
import zope.interface
from zerodb.transform import encrypt, decrypt, compress, decompress
from zerodb.util import encode_hex
from zerodb.util.debug import debug_loads


class TransformingStorage(ZlibStorage):
    """
    Storage which can transform (encrypt and/or compress) data.
    """

    def __init__(self, base, *args, **kw):
        """
        :param base: Storage to transform
        :param bool debug: Output debug log messages
        """
        self.base = base

        self.debug = kw.pop("debug", False)
        if self.debug:
            self._debug_download_size = 0
            self._debug_download_count = 0

        for name in self.copied_methods:
            v = getattr(base, name, None)
            if v is not None:
                setattr(self, name, v)

        zope.interface.directlyProvides(self, zope.interface.providedBy(base))

        base.registerDB(self)

        self._transform = lambda data: encrypt(compress(data), no_cipher_name=True)
        self._transform_named = lambda data: encrypt(compress(data), no_cipher_name=False)
        self._untransform = lambda data: decompress(decrypt(data))

        self._root_oid = base.get_root_id()

    def loadBefore(self, oid, tid):
        """Load last state for a given oid before a given tid

        :param str oid: Object ID
        :param str tid: Transaction timestamp
        :return: Object and its serial number and following serial number
        :rtype: tuple
        """
        if self.debug:
            if oid not in self._cache.current:
                in_cache = False
            else:
                in_cache = True

{'fraction_non_alphanumeric': 0.08184218245819888, 'fraction_numerical': 0.0011733646230566149, 'mean_word_length': 2.343137254901961, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4645144', 'n_tokens_mistral': 973, 'n_tokens_neox': 926, 'n_words': 294}