import re


def indention(str, front=re.compile(r"^\s+").match):
    """Find the number of leading spaces. If none, return 0.
    """
    result = front(str)
    if result is not None:
        start, end = result.span()
        return end-start
    else:
        return 0     # no leading spaces