@contextmanager
def mktemp(contents):
    ' Create a temporary file with the given contents, and yield its path '
    (_, path) = tempfile.mkstemp()
    fp = io.open(path, 'wt+', encoding='utf-8')
    fp.write(contents)
    fp.flush()
    try:
        (yield path)
    finally:
        fp.close()
        os.unlink(path)
Create a temporary file with the given contents, and yield its path
@contextmanager
def mktemp(contents):
    '  '
    (_, path) = tempfile.mkstemp()
    fp = io.open(path, 'wt+', encoding='utf-8')
    fp.write(contents)
    fp.flush()
    try:
        (yield path)
    finally:
        fp.close()
        os.unlink(path)