--- /dev/null
+# Copyright 1999-2020 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=7
+
+PYTHON_COMPAT=( python{2_7,3_{6,7,8}} pypy3 )
+
+inherit distutils-r1
+
+DESCRIPTION="Python Documentation Utilities"
+HOMEPAGE="http://docutils.sourceforge.net/ https://pypi.org/project/docutils/"
+#SRC_URI="mirror://sourceforge/${PN}/${P}.tar.gz"
+SRC_URI="mirror://pypi/${PN:0:1}/${PN}/${P}.tar.gz"
+
+LICENSE="BSD-2 GPL-3 public-domain"
+SLOT="0"
+KEYWORDS="~alpha ~amd64 ~arm ~arm64 ~hppa ~ia64 ~m68k ~mips ~ppc ~ppc64 ~riscv ~s390 ~sh ~sparc ~x86 ~ppc-aix ~x64-cygwin ~amd64-linux ~x86-linux ~ppc-macos ~x64-macos ~x86-macos ~m68k-mint ~sparc-solaris ~sparc64-solaris ~x64-solaris ~x86-solaris"
+IUSE=""
+
+BDEPEND="dev-python/setuptools[${PYTHON_USEDEP}]
+ dev-python/pygments[${PYTHON_USEDEP}]"
+RDEPEND="${DEPEND}"
+
+PATCHES=(
+ "${FILESDIR}"/${P}-tests.patch
+)
+
+python_compile_all() {
+ # Generate html docs from reStructured text sources.
+
+ # Place html4css1.css in base directory to ensure that the generated reference to it is correct.
+ cp docutils/writers/html4css1/html4css1.css . || die
+
+ cd tools || die
+ "${EPYTHON}" buildhtml.py --input-encoding=utf-8 \
+ --stylesheet-path=../html4css1.css, --traceback ../docs || die
+}
+
+src_test() {
+ cd test || die
+ distutils-r1_src_test
+}
+
+python_test() {
+ "${EPYTHON}" alltests.py -v || die "Testing failed with ${EPYTHON}"
+}
+
+python_install() {
+ distutils-r1_python_install
+
+ # Install tools.
+ python_doscript tools/{buildhtml,quicktest}.py
+}
+
+install_txt_doc() {
+ local doc="${1}"
+ local dir="txt/$(dirname ${doc})"
+ docinto "${dir}"
+ dodoc "${doc}"
+}
+
+python_install_all() {
+ local DOCS=( *.txt )
+ local HTML_DOCS=( docs tools docutils/writers/html4css1/html4css1.css )
+
+ distutils-r1_python_install_all
+
+ local doc
+ while IFS= read -r -d '' doc; do
+ install_txt_doc "${doc}"
+ done < <(find docs tools -name '*.txt' -print0)
+}
--- /dev/null
+Index: docutils/test/test_parsers/test_rst/test_directives/test_code.py
+===================================================================
+--- docutils/test/test_parsers/test_rst/test_directives/test_code.py (revision 8494)
++++ docutils/test/test_parsers/test_rst/test_directives/test_code.py (working copy)
+@@ -107,7 +107,7 @@
+ <document source="test data">
+ <literal_block classes="code python testclass" xml:space="preserve">
+ \n\
+- <inline classes="keyword">
++ <inline classes="name builtin">
+ print
+ <inline classes="punctuation">
+ (
+@@ -167,7 +167,7 @@
+ <inline classes="ln">
+ 12 \n\
+ \n\
+- <inline classes="keyword">
++ <inline classes="name builtin">
+ print
+ <inline classes="punctuation">
+ (
+Index: docutils/test/test_parsers/test_rst/test_directives/test_code_long.py
+===================================================================
+--- docutils/test/test_parsers/test_rst/test_directives/test_code_long.py (revision 8494)
++++ docutils/test/test_parsers/test_rst/test_directives/test_code_long.py (working copy)
+@@ -69,7 +69,7 @@
+ <inline classes="ln">
+ 12 \n\
+ \n\
+- <inline classes="keyword">
++ <inline classes="name builtin">
+ print
+ <inline classes="punctuation">
+ (
+Index: docutils/test/test_parsers/test_rst/test_directives/test_tables.py
+===================================================================
+--- docutils/test/test_parsers/test_rst/test_directives/test_tables.py (revision 8494)
++++ docutils/test/test_parsers/test_rst/test_directives/test_tables.py (working copy)
+@@ -45,10 +45,11 @@
+ # some error messages changed in Python 3.3, CPython has backported to 2.7.4,
+ # PyPy has not
+ csv_eod_error_str = 'unexpected end of data'
+-if sys.version_info < (2,7,4) or platform.python_implementation() == 'PyPy':
++if sys.version_info < (2,7,4) or (platform.python_implementation() == 'PyPy'
++ and sys.version_info < (3,0)):
+ csv_eod_error_str = 'newline inside string'
+ # pypy adds a line number
+-if sys.version_info >= (3, 0) and platform.python_implementation() == 'PyPy':
++if platform.python_implementation() == 'PyPy':
+ csv_eod_error_str = 'line 1: ' + csv_eod_error_str
+ csv_unknown_url = "'bogus.csv'"
+ if sys.version_info < (3, 0):
+Index: docutils/test/test_parsers/test_rst/test_interpreted.py
+===================================================================
+--- docutils/test/test_parsers/test_rst/test_interpreted.py (revision 8494)
++++ docutils/test/test_parsers/test_rst/test_interpreted.py (working copy)
+@@ -283,7 +283,7 @@
+ <paragraph>
+ Python code \n\
+ <literal classes="code testclass python">
+- <inline classes="keyword">
++ <inline classes="name builtin">
+ print
+ <inline classes="punctuation">
+ (