import re


def encoded(pth):
    """Searches the first two lines of a string looking for an `# encoding: ???` comment."""
    re_enc = re.compile(r'coding[=:]\s*([-\w.]+)')
    lines = open(pth, encoding='ascii', errors='ignore').readlines()
    for line in lines[:2]:
        if not line.strip().startswith('#'):
            continue
        m = re_enc.search(line)
        if not m:
            continue
        return m.group(1)
    return "utf-8"