<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def temp_file( content=None, suffix='', prefix='tmp', parent_dir=None):
 """ Create a temporary file and optionally populate it with content. The file is deleted when the context exits. The temporary file is created when entering the context manager and deleted when exiting it. The user may also supply some content for the file to be populated with: The temporary file can be placed in a custom directory: If, for some reason, the user wants to delete the temporary file before exiting the context, that's okay too: """

    binary = isinstance(content, (bytes, bytearray))
    parent_dir = parent_dir if parent_dir is None else str(parent_dir)
    fd, abs_path = tempfile.mkstemp(suffix, prefix, parent_dir, text=False)
    path = pathlib.Path(abs_path)
    try:
        try:
            if content:
                os.write(fd, content if binary else content.encode())
        finally:
            os.close(fd)
        yield path.resolve()
    finally:
        with temporary.util.allow_missing_file():
            path.unlink()