<commit_before>import hashlib
import datetime
import yaml

class VersionedStorage():
    def __init__(self, store, digest='md5'):
        self.store = store
        self.digest_type = digest
        self.meta_directory = '.keepaneyeon'

    def digest(self, filename):
        """
        Return hex digest of the given file. Uses the hash algorithm configured
        with the digest argument to the constructor.
        """
        chunk_size = 1024
        h = getattr(hashlib, self.digest_type)()
        with open(filename, 'rb') as f:
            while True:
                chunk = f.read(chunk_size)
                if not chunk:
                    break
                h.update(chunk)
        return h.hexdigest()

    def version_name(self, digest):
        return self.meta_directory + '/versions/' + digest

    def store_from_filename(self, name, filename):
        """
        Store given filename under the provided name.
        """
        # check if we already have this version
        digest = self.digest(filename)
        version_name = self.version_name(digest)
        if self.store.exists(version_name):
            return
        # this is new
        now = datetime.datetime.now()
        ts = now.strftime('%Y-%m-%dT%H:%M:%S')
        # store the new version
        name_timstamped = name + '/' + ts
        self.store.store_from_filename(name_timstamped, filename)
        # and record the new digest
        metadata = {
                'name': name,
                'timestamp': ts,
                }
        metadata_string = yaml.dump(metadata, default_flow_style=False)
        self.store.store_from_string(version_name, metadata_string)<commit_msg>Store datetime object natively with YAML<commit_after>import hashlib
import datetime
import yaml

class VersionedStorage():
    def __init__(self, store, digest='md5'):
        self.store = store
        self.digest_type = digest
        self.meta_directory = '.keepaneyeon'

    def digest(self, filename):
        """
        Return hex digest of the given file. Uses the hash algorithm configured
        with the digest argument to the constructor.
        """
        chunk_size = 1024
        h = getattr(hashlib, self.digest_type)()
        with open(filename, 'rb') as f:
            while True:
                chunk = f.read(chunk_size)
                if not chunk:
                    break
                h.update(chunk)
        return h.hexdigest()

    def version_name(self, digest):
        return self.meta_directory + '/versions/' + digest

    def store_from_filename(self, name, filename):
        """
        Store given filename under the provided name.
        """
        # check if we already have this version
        digest = self.digest(filename)
        version_name = self.version_name(digest)
        if self.store.exists(version_name):
            return
        # this is new
        now = datetime.datetime.now()
        ts = now.strftime('%Y-%m-%dT%H:%M:%S')
        # store the new version
        name_timstamped = name + '/' + ts
        self.store.store_from_filename(name_timstamped, filename)
        # and record the new digest
        metadata = {
                'name': name,
                'timestamp': now,
                }
        metadata_string = yaml.dump(metadata, default_flow_style=False)
        self.store.store_from_string(version_name, metadata_string)
{'fraction_non_alphanumeric': 0.09117647058823529, 'fraction_numerical': 0.0029411764705882353, 'mean_word_length': 1.9573913043478262, '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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5596358', 'n_tokens_mistral': 945, 'n_tokens_neox': 898, 'n_words': 252}