<commit_before>from __future__ import with_statement
import os
import sys
import csv
import datetime


class VacalcError(Exception): pass
class DuplicateUser(VacalcError): pass


class UserStore(object):

    def __init__(self, db_file='db.csv'):
        self._db_file = db_file
        if db_file and os.path.isfile(db_file):
            self._users = self._read_users(db_file)
        else:
            self._users = {}

    def _read_users(self, path):
        users = {}
        with open(path) as db:
            for row in csv.reader(db):
                user = User(row[0], row[1])
                users[user.name] = user
        return users

    def get_user(self, name):
        for row in csv.reader(open(self._db_file)):
            if row[0] == name:
                return User(row[0], row[1])

    def add_user(self, name, startdate):
        if name in self._users:
            raise DuplicateUser(name)
        user = User(name, startdate)
        self._users[user.name] = user
        self._serialize(user)
        return user

    def _serialize(self, user):
        with open(self._db_file, 'a') as db:
            writer = csv.writer(db, lineterminator='\n')
            writer.writerow([user.name, user.startdate.isoformat()])


class VacationCalculator(object):

    def __init__(self, userstore):
        self._userstore = userstore

    def vacation(self, name, year):
        user = self._userstore.get_user(name, year)
        return user.count_vacation(year)

    def add_user(self, name, startdate):
        user = self._userstore.add_user(name, startdate)
        return "Successfully added user '%s'." % user.name
<commit_msg>implemented get_user<commit_after>from __future__ import with_statement
import os
import sys
import csv
import datetime


class VacalcError(Exception): pass
class DuplicateUser(VacalcError): pass


class UserStore(object):

    def __init__(self, db_file='db.csv'):
        self._db_file = db_file
        if db_file and os.path.isfile(db_file):
            self._users = self._read_users(db_file)
        else:
            self._users = {}

    def _read_users(self, path):
        users = {}
        with open(path) as db:
            for row in csv.reader(db):
                user = User(row[0], row[1])
                users[user.name] = user
        return users

    def get_user(self, name):
        for row in csv.reader(open(self._db_file)):
            if row[0] == name:
                return User(row[0], row[1])

    def add_user(self, name, startdate):
        if name in self._users:
            raise DuplicateUser(name)
        user = User(name, startdate)
        self._users[user.name] = user
        self._serialize(user)
        return user

    def _serialize(self, user):
        with open(self._db_file, 'a') as db:
            writer = csv.writer(db, lineterminator='\n')
            writer.writerow([user.name, user.startdate.isoformat()])


class VacationCalculator(object):

    def __init__(self, userstore):
        self._userstore = userstore

    def vacation(self, name, year):
        user = self._userstore.get_user(name, year)
        return user.count_vacation(year)

    def add_user(self, name, startdate):
        user = self._userstore.add_user(name, startdate)
        return "Successfully added user '%s'." % user.name

    def get_user(self, name):
        user = self._userstore.get_user(name)
        return '%s: start date %s' % (user.name, user.startdate.isoformat())

{'fraction_non_alphanumeric': 0.1102158273381295, 'fraction_numerical': 0.0028776978417266188, 'mean_word_length': 2.3813229571984436, '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': '7193442', 'n_tokens_mistral': 1101, 'n_tokens_neox': 1049, 'n_words': 263}