<commit_before>#!/usr/bin/python2.7
# -*- coding: utf-8 -*-

import md5

class File:
    def __init__(self, abspath, waver):
        self.abspath = abspath
        self.waver = waver
        self.state = None

    def read_pieces(self, idx):
        pieces = ""
        path, idx_rel = self.waver.pieces.at(idx)
        with open(self.abspath + path) as f:
            f.seek(idx_rel * self.waver.pieces_sz)
            pieces = f.read(self.waver.pieces_sz)
        return pieces

    def write_pieces(self, string, idx):
        if md5.md5(string).hexdigest() == self.waver.hashes[idx - 1]:
            with open(self.abspath + path) as f:
                f.seek(idx_rel * self.waver.pieces_sz)
                pieces = f.write(string)
        else:
            #throw Exception BadPieces



    def update():
        pass<commit_msg>file.py: Écriture de pièces<commit_after>#!/usr/bin/python2.7
# -*- coding: utf-8 -*-

import md5

class BadPiece(Exception):
       pass

class File:
    def __init__(self, abspath, waver):
        self.abspath = abspath
        self.waver = waver
        self.state = None

    def read_pieces(self, idx):
        pieces = ""
        path, idx_rel = self.waver.pieces.at(idx)
        with open(self.abspath + path) as f:
            f.seek(idx_rel * self.waver.pieces_sz)
            pieces = f.read(self.waver.pieces_sz)
        return pieces

    def write_pieces(self, string, idx):
        if md5.md5(string).hexdigest() == self.waver.hashes[idx - 1]:
            with open(self.abspath + path) as f:
                f.seek(idx_rel * self.waver.pieces_sz)
                pieces = f.write(string)
            # mise a jour de self.state
        else:
            raise BadPiece

    def update():
        # Renvoie l'index de 5 premieres pieces a telecharger
        pass
{'fraction_non_alphanumeric': 0.11479028697571744, 'fraction_numerical': 0.008278145695364239, 'mean_word_length': 1.8823529411764706, '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': '3667434', 'n_tokens_mistral': 631, 'n_tokens_neox': 600, 'n_words': 135}