import datetime
import re

from .exceptions import ObjectIsNotADate


def format_date(value, format="%d %M %Y"):
    regex = re.match(r"(?P<year>\d{4})-(?P<month>\d{2})-(?P<day>\d{2})", value)
    if regex is not None:
        date = datetime.date(
            int(regex.group("year")),
            int(regex.group("month")),
            int(regex.group("day")))
    else:
        raise ObjectIsNotADate

    return date.strftime(format)

[((8, 12, 8, 79), 're.match', 're.match', ({(8, 21, 8, 71): '"""(?P<year>\\\\d{4})-(?P<month>\\\\d{2})-(?P<day>\\\\d{2})"""', (8, 73, 8, 78): 'value'}, {}), "('(?P<year>\\\\d{4})-(?P<month>\\\\d{2})-(?P<day>\\\\d{2})', value)", False, 'import re\n')]