<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def populate_readme(revision, rtd_version, **extra_kwargs):
 """Populate README template with values. Args: revision (str):
 The branch, commit, etc. being referred to (e.g. ``master``). rtd_version (str):
 The version to use for RTD (Read the Docs) links (e.g. ``latest``). extra_kwargs (Dict[str, str]):
 Over-ride for template arguments. Returns: str: The populated README contents. Raises: ValueError: If the ``sphinx_modules`` encountered are not as expected. ValueError: If the ``sphinx_docs`` encountered are not as expected. """

    with open(TEMPLATE_FILE, "r") as file_obj:
        template = file_obj.read()
    img_prefix = IMG_PREFIX.format(revision=revision)
    extra_links = EXTRA_LINKS.format(
        rtd_version=rtd_version, revision=revision
    )
    docs_img = DOCS_IMG.format(rtd_version=rtd_version)
    bernstein_basis = BERNSTEIN_BASIS_PLAIN.format(img_prefix=img_prefix)
    bezier_defn = BEZIER_DEFN_PLAIN.format(img_prefix=img_prefix)
    sum_to_unity = SUM_TO_UNITY_PLAIN.format(img_prefix=img_prefix)
    template_kwargs = {
        "code_block1": PLAIN_CODE_BLOCK,
        "code_block2": PLAIN_CODE_BLOCK,
        "code_block3": PLAIN_CODE_BLOCK,
        "testcleanup": "",
        "toctree": "",
        "bernstein_basis": bernstein_basis,
        "bezier_defn": bezier_defn,
        "sum_to_unity": sum_to_unity,
        "img_prefix": img_prefix,
        "extra_links": extra_links,
        "docs": "|docs| ",
        "docs_img": docs_img,
        "pypi": "\n\n|pypi| ",
        "pypi_img": PYPI_IMG,
        "versions": "|versions|\n\n",
        "versions_img": VERSIONS_IMG,
        "rtd_version": rtd_version,
        "revision": revision,
        "circleci_badge": CIRCLECI_BADGE,
        "circleci_path": "",
        "travis_badge": TRAVIS_BADGE,
        "travis_path": "",
        "appveyor_badge": APPVEYOR_BADGE,
        "appveyor_path": "",
        "coveralls_badge": COVERALLS_BADGE,
        "coveralls_path": COVERALLS_PATH,
        "zenodo": "|zenodo|",
        "zenodo_img": ZENODO_IMG,
        "joss": " |JOSS|",
        "joss_img": JOSS_IMG,
    }
    template_kwargs.update(**extra_kwargs)
    readme_contents = template.format(**template_kwargs)
    # Apply regular expressions to convert Sphinx "roles" to plain reST.
    readme_contents = INLINE_MATH_EXPR.sub(inline_math, readme_contents)
    sphinx_modules = []
    to_replace = functools.partial(mod_replace, sphinx_modules=sphinx_modules)
    readme_contents = MOD_EXPR.sub(to_replace, readme_contents)
    if sphinx_modules != ["bezier.curve", "bezier.surface"]:
        raise ValueError("Unexpected sphinx_modules", sphinx_modules)

    sphinx_docs = []
    to_replace = functools.partial(doc_replace, sphinx_docs=sphinx_docs)
    readme_contents = DOC_EXPR.sub(to_replace, readme_contents)
    if sphinx_docs != ["python/reference/bezier", "development"]:
        raise ValueError("Unexpected sphinx_docs", sphinx_docs)

    return readme_contents