@classmethod
def extract_template(cls, sql):
    """Turn bindable vars into '%s' and map any names to indices.

        This will vary from database engine to engine.  By default we'll
        match to one of the paramtypes listed in PEP 349.

        """
    newsql = ''
    names = []
    paramstyle = None
    matcher = None
    remainder = sql
    while remainder:
        if matcher:
            match = matcher(remainder)
        else:
            for style in cls.PARAMSTYLES.get(remainder[0], ()):
                match = style.matcher(remainder)
                if match:
                    matcher = style.matcher
                    paramstyle = style
                    break
            else:
                match = None
        if not match:
            newsql += remainder[0]
            remainder = remainder[1:]
            continue
        name, index, original, remainder = match
        names.append(name or index)
        newsql += '%s'
    return newsql, names
