import re
import optparse


def _check_boolean(option, opt, value):
    """Type checking function for command line parser's 'boolean' type."""
    true_reg_ex_pattern = r"^(true|t|y|yes|1)$"
    true_reg_ex = re.compile(true_reg_ex_pattern, re.IGNORECASE)
    if true_reg_ex.match(value):
        return True
    false_reg_ex_pattern = r"^(false|f|n|no|0)$"
    false_reg_ex = re.compile(false_reg_ex_pattern, re.IGNORECASE)
    if false_reg_ex.match(value):
        return False
    msg = "option %s: should be one of true, false, yes, no, 1 or 0" % opt
    raise optparse.OptionValueError(msg)