# -*- coding: utf-8 mode: python -*- vim:sw=4:sts=4:et:ai:si:sta:fenc=utf-8

__all__ = ('BooleanF',)

from ..uio import _s
from ..input import is_yes, is_no

from .strings import UnicodeF

class BooleanF(UnicodeF):
    def parse(self, s):
        if s in (None, True, False): return s

        s = UnicodeF.parse(self, s)
        if is_yes(s): return True
        elif is_no(s): return False
        else: raise ValueError("Invalid boolean: %s" % s)

    def format(self, b):
        if b is None: return u""
        elif b: return u"Oui"
        else: return u"Non"
