import re


def parse_hashed_filepath(filename, hash_len=12):
    """
    Given a name like '/static/my_file.deadbeef1234.txt', return a tuple of the file name
    without the hash, and the hash itself, like this:

        ('/static/my_file.txt', 'deadbeef1234')

    If no hash part is found, then return (None, None).
    """
    pat = '^(?P<before>.*)\.(?P<hash>[0-9,a-f]{%s})(?P<after>.*?)$' % hash_len
    m = re.match(pat, filename)
    if m is None:
        return None, None
    parts = m.groupdict()
    return '{before}{after}'.format(**parts), parts['hash']