def invert(boolexpr):
    """invert

        >>> print invert('0=0')
        not (0=0)
    
        >>> print invert(invert('0=0'))
        0=0
    """
    if isinstance(boolexpr, Not):
        return boolexpr.element
    else:
        return Not(boolexpr)
invert

        >>> print invert('0=0')
        not (0=0)
    
        >>> print invert(invert('0=0'))
        0=0
    
recipes/Python/415345_write_sql_via_python/recipe-415345.py