summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlastair Tse <liquidx@gentoo.org>2003-07-07 23:39:22 +0000
committerAlastair Tse <liquidx@gentoo.org>2003-07-07 23:39:22 +0000
commitc85b1ed7d62808ee05732988496e585c64b9f662 (patch)
treefd01d4cbab54bfa2f0e63b2383dc92c79f5d1ce5 /dev-python
parentrevision bump. changes to glep scripts and docutils installation (diff)
downloadgentoo-2-c85b1ed7d62808ee05732988496e585c64b9f662.tar.gz
gentoo-2-c85b1ed7d62808ee05732988496e585c64b9f662.tar.bz2
gentoo-2-c85b1ed7d62808ee05732988496e585c64b9f662.zip
revision bump. changes to glep scripts and docutils installation
Diffstat (limited to 'dev-python')
-rw-r--r--dev-python/docutils/ChangeLog11
-rw-r--r--dev-python/docutils/Manifest13
-rw-r--r--dev-python/docutils/docutils-0.3-r1.ebuild70
-rw-r--r--dev-python/docutils/files/digest-docutils-0.3-r11
-rw-r--r--dev-python/docutils/files/docutils-0.3-extramodules.patch32
-rw-r--r--dev-python/docutils/files/glep-0.3-r1/glep.py27
-rw-r--r--dev-python/docutils/files/glep-0.3-r1/glep_htmlwrite.py112
-rw-r--r--dev-python/docutils/files/glep-0.3-r1/glepread.py53
-rw-r--r--dev-python/docutils/files/glep-0.3-r1/glepstrans.py293
9 files changed, 605 insertions, 7 deletions
diff --git a/dev-python/docutils/ChangeLog b/dev-python/docutils/ChangeLog
index 444b95085e83..11ef25fc00d1 100644
--- a/dev-python/docutils/ChangeLog
+++ b/dev-python/docutils/ChangeLog
@@ -1,6 +1,15 @@
# ChangeLog for dev-python/docutils
# Copyright 2000-2003 Gentoo Technologies, Inc.; Distributed under the GPL v2
-# $Header: /var/cvsroot/gentoo-x86/dev-python/docutils/ChangeLog,v 1.6 2003/07/01 09:46:37 liquidx Exp $
+# $Header: /var/cvsroot/gentoo-x86/dev-python/docutils/ChangeLog,v 1.7 2003/07/07 23:39:10 liquidx Exp $
+
+*docutils-0.3-r1 (08 Jul 2003)
+
+ 08 Jul 2003; Alastair Tse <liquidx@gentoo.org> docutils-0.3-r1.ebuild,
+ files/docutils-0.3-extramodules.patch, files/glep-0.3-r1/glep.py,
+ files/glep-0.3-r1/glep_htmlwrite.py, files/glep-0.3-r1/glepread.py,
+ files/glep-0.3-r1/glepstrans.py:
+ fixed glep scripts for docutils 0.3, changed install script for optparse.py
+ and textwrap.py.
*docutils-0.3 (01 Jul 2003)
diff --git a/dev-python/docutils/Manifest b/dev-python/docutils/Manifest
index 896b29a99e4b..580e4bb336e1 100644
--- a/dev-python/docutils/Manifest
+++ b/dev-python/docutils/Manifest
@@ -1,9 +1,9 @@
-MD5 b71562bab84945c99c2fd6521c166609 ChangeLog 1645
+MD5 96898c1cd94fbb3f0c3de8d00c0dc5de ChangeLog 2021
MD5 2196352ff09a0911d140c0c894967808 docutils-0.3_pre20030530.ebuild 716
MD5 3b77f1541dc354b1155715d80f197bad docutils-0.3_pre20030530-r3.ebuild 1543
MD5 4ecda915abc9c0f1242895c64464440e docutils-0.3.ebuild 1529
MD5 71c4638c9c88af75b58e5f5cb54fe008 metadata.xml 159
-MD5 b84bbbc2ab319e4c4f8c3f7da8e52bc2 docutils-0.3-r1.ebuild 1623
+MD5 c68688b4f37ace0b9d079728ba9b80d4 docutils-0.3-r1.ebuild 1768
MD5 8c6d9ea3ddd2e36b369112ee20b660fb files/digest-docutils-0.3_pre20030530 73
MD5 8c6d9ea3ddd2e36b369112ee20b660fb files/digest-docutils-0.3_pre20030530-r3 73
MD5 4787b6c5e6678d3f211ec7f8ec71aa03 files/glep.py 699
@@ -12,7 +12,8 @@ MD5 0a2c7c1478f8b72f97b3d12534b4159e files/glepread.py 1647
MD5 fded948d9eac24154eab24b2b56d15d6 files/glepstrans.py 10420
MD5 694b883b9a8f714dc375a547cdf62b1d files/digest-docutils-0.3 64
MD5 694b883b9a8f714dc375a547cdf62b1d files/digest-docutils-0.3-r1 64
-MD5 ea99a173052fbcf2ca59d32803202932 files/glep-0.3-r1/glep_htmlwrite.py 4168
-MD5 4787b6c5e6678d3f211ec7f8ec71aa03 files/glep-0.3-r1/glep.py 699
-MD5 0a2c7c1478f8b72f97b3d12534b4159e files/glep-0.3-r1/glepread.py 1647
-MD5 fded948d9eac24154eab24b2b56d15d6 files/glep-0.3-r1/glepstrans.py 10420
+MD5 7c025532adb8b09116980747be7ccc61 files/docutils-0.3-extramodules.patch 1155
+MD5 a273d63de34b5da93a15764998c054d2 files/glep-0.3-r1/glep_htmlwrite.py 4168
+MD5 770e48a59980bce89ab956ab96396a7c files/glep-0.3-r1/glep.py 699
+MD5 d6fc669e125324930e72f2421779a5c2 files/glep-0.3-r1/glepread.py 1647
+MD5 b2120566d66f102103180c02e3dc89dd files/glep-0.3-r1/glepstrans.py 10420
diff --git a/dev-python/docutils/docutils-0.3-r1.ebuild b/dev-python/docutils/docutils-0.3-r1.ebuild
new file mode 100644
index 000000000000..d7239c38ae13
--- /dev/null
+++ b/dev-python/docutils/docutils-0.3-r1.ebuild
@@ -0,0 +1,70 @@
+# Copyright 1999-2002 Gentoo Technologies, Inc.
+# Distributed under the terms of the GNU General Public License v2
+# $Header: /var/cvsroot/gentoo-x86/dev-python/docutils/docutils-0.3-r1.ebuild,v 1.1 2003/07/07 23:39:10 liquidx Exp $
+
+inherit distutils
+
+DESCRIPTION="Set of python tools for processing plaintext docs into HTML, XML, etc."
+HOMEPAGE="http://docutils.sourceforge.net/"
+SRC_URI="mirror://sourceforge/docutils/${P}.tar.gz"
+
+LICENSE="public-domain PYTHON BSD"
+SLOT="0"
+KEYWORDS="~x86"
+IUSE=""
+
+DEPEND=">=dev-lang/python-2.1"
+
+# GLEP version
+GLEP_SRC=${FILESDIR}/glep-${PVR}
+
+src_unpack() {
+ unpack ${A}
+ # simplified algorithm to select installing optparse and textwrap
+ epatch ${FILESDIR}/${P}-extramodules.patch
+}
+
+src_compile() {
+ distutils_src_compile
+
+ # Generate html docs from reStructured text sources
+ PYTHONPATH=${S}/build/lib ${python} \
+ tools/buildhtml.py --config=tools/docutils.conf
+}
+
+
+install_txt_doc() {
+ local doc=${1}
+ local dir="txt/$(dirname ${doc})"
+ docinto ${dir}
+ dodoc ${doc}
+}
+
+src_install() {
+ mydoc="MANIFEST.in *.txt"
+ distutils_src_install
+ # Tools
+ cd ${S}/tools
+ for tool in *.py
+ do
+ newbin ${tool} docutils-${tool}
+ done
+ # Docs
+ cd ${S}
+ dohtml -r docs spec tools
+ for doc in $(find docs spec tools -name '*.txt')
+ do
+ install_txt_doc $doc
+ done
+
+ # installing Gentoo GLEP tools. Uses versioned GLEP distribution
+ distutils_python_version
+ newbin ${GLEP_SRC}/glep.py docutils-glep.py
+ insinto /usr/lib/python${PYVER}/site-packages/docutils/readers
+ newins ${GLEP_SRC}/glepread.py glep.py
+ insinto /usr/lib/python${PYVER}/site-packages/docutils/transforms
+ newins ${GLEP_SRC}/glepstrans.py gleps.py
+ insinto /usr/lib/python${PYVER}/site-packages/docutils/writers
+ newins ${GLEP_SRC}/glep_htmlwrite.py glep_html.py
+}
+
diff --git a/dev-python/docutils/files/digest-docutils-0.3-r1 b/dev-python/docutils/files/digest-docutils-0.3-r1
new file mode 100644
index 000000000000..bdb677fa30f3
--- /dev/null
+++ b/dev-python/docutils/files/digest-docutils-0.3-r1
@@ -0,0 +1 @@
+MD5 d8c78dd09610055431ac8df30312bdb9 docutils-0.3.tar.gz 485575
diff --git a/dev-python/docutils/files/docutils-0.3-extramodules.patch b/dev-python/docutils/files/docutils-0.3-extramodules.patch
new file mode 100644
index 000000000000..a7e34def3165
--- /dev/null
+++ b/dev-python/docutils/files/docutils-0.3-extramodules.patch
@@ -0,0 +1,32 @@
+--- docutils-0.3/setup.py 2003-06-25 02:47:04.000000000 +0100
++++ docutils-0.3/setup.py.new 2003-07-08 00:21:59.000000000 +0100
+@@ -78,20 +78,15 @@
+ List of (module name, minimum __version__ string, [attribute names])."""
+
+ def get_extras():
+- extras = []
+- for module_name, version, attributes in extra_modules:
+- try:
+- module = __import__(module_name)
+- if version and module.__version__ < version:
+- raise ValueError
+- for attribute in attributes or []:
+- getattr(module, attribute)
+- print ('"%s" module already present; ignoring extras/%s.py.'
+- % (module_name, module_name))
+- except (ImportError, AttributeError, ValueError):
+- extras.append(module_name)
+- return extras
+-
++ # old method does not work for upgrading/downgrading docutils.
++ # so we use a simple rule, 'optparse' and 'textwrap' are not installed
++ # for >=python-2.3
++
++ pyver = sys.version_info
++ if pyver[0] == 2 and pyver[1] > 2:
++ return ["roman"]
++ else:
++ return ["optparse","textwrap","roman"]
+
+ class dual_build_py(build_py):
+
diff --git a/dev-python/docutils/files/glep-0.3-r1/glep.py b/dev-python/docutils/files/glep-0.3-r1/glep.py
new file mode 100644
index 000000000000..f023008f2bf7
--- /dev/null
+++ b/dev-python/docutils/files/glep-0.3-r1/glep.py
@@ -0,0 +1,27 @@
+#!/usr/bin/env python
+
+# Author: David Goodger
+# Contact: goodger@users.sourceforge.net
+# Revision: $Revision: 1.1 $
+# Date: $Date: 2003/07/07 23:39:10 $
+# Copyright: This module has been placed in the public domain.
+
+"""
+A minimal front end to the Docutils Publisher, producing HTML from PEP
+(Python Enhancement Proposal) documents.
+"""
+
+import locale
+try:
+ locale.setlocale(locale.LC_ALL, '')
+except:
+ pass
+
+from docutils.core import publish_cmdline, default_description
+
+
+description = ('Generates (X)HTML from reStructuredText-format PEP files. '
+ + default_description)
+
+publish_cmdline(reader_name='glep', writer_name='glep_html',
+ description=description)
diff --git a/dev-python/docutils/files/glep-0.3-r1/glep_htmlwrite.py b/dev-python/docutils/files/glep-0.3-r1/glep_htmlwrite.py
new file mode 100644
index 000000000000..7d4b7f9bdf99
--- /dev/null
+++ b/dev-python/docutils/files/glep-0.3-r1/glep_htmlwrite.py
@@ -0,0 +1,112 @@
+# Author: David Goodger
+# Contact: goodger@users.sourceforge.net
+# Revision: $Revision: 1.1 $
+# Date: $Date: 2003/07/07 23:39:10 $
+# Copyright: This module has been placed in the public domain.
+
+"""
+PEP HTML Writer.
+"""
+
+__docformat__ = 'reStructuredText'
+
+
+import sys
+import docutils
+from docutils import nodes, frontend, utils
+from docutils.writers import html4css1
+
+class Writer(html4css1.Writer):
+
+ settings_spec = html4css1.Writer.settings_spec + (
+ 'PEP/HTML-Specific Options',
+ 'The HTML --footnote-references option is set to "brackets" by '
+ 'default.',
+ (('Specify a PEP stylesheet URL, used verbatim. Default is '
+ '--stylesheet\'s value. If given, --pep-stylesheet overrides '
+ '--stylesheet.',
+ ['--pep-stylesheet'],
+ {'metavar': '<URL>'}),
+ ('Specify a PEP stylesheet file, relative to the current working '
+ 'directory. The path is adjusted relative to the output HTML '
+ 'file. Overrides --pep-stylesheet and --stylesheet-path.',
+ ['--pep-stylesheet-path'],
+ {'metavar': '<path>'}),
+ ('Specify a template file. Default is "pep-html-template".',
+ ['--pep-template'],
+ {'default': 'pep-html-template', 'metavar': '<file>'}),
+ ('Python\'s home URL. Default is ".." (parent directory).',
+ ['--python-home'],
+ {'default': '..', 'metavar': '<URL>'}),
+ ('Home URL prefix for PEPs. Default is "." (current directory).',
+ ['--pep-home'],
+ {'default': '.', 'metavar': '<URL>'}),
+ # Workaround for SourceForge's broken Python
+ # (``import random`` causes a segfault).
+ (frontend.SUPPRESS_HELP,
+ ['--no-random'], {'action': 'store_true'}),))
+
+ settings_default_overrides = {'footnote_references': 'brackets'}
+
+ relative_path_settings = ('pep_stylesheet_path', 'pep_template')
+
+ def __init__(self):
+ html4css1.Writer.__init__(self)
+ self.translator_class = HTMLTranslator
+
+ def translate(self):
+ html4css1.Writer.translate(self)
+ settings = self.document.settings
+ template = open(settings.pep_template).read()
+ # Substitutions dict for template:
+ subs = {}
+ subs['encoding'] = settings.output_encoding
+ subs['version'] = docutils.__version__
+ subs['stylesheet'] = ''.join(self.stylesheet)
+ pyhome = settings.python_home
+ subs['pyhome'] = pyhome
+ subs['pephome'] = settings.pep_home
+ if pyhome == '..':
+ subs['pepindex'] = '.'
+ else:
+ subs['pepindex'] = 'http://www.gentoo.org/proj/en/glep'
+ index = self.document.first_child_matching_class(nodes.field_list)
+ header = self.document[index]
+ pepnum = header[0][1].astext()
+ subs['pep'] = pepnum
+ if settings.no_random:
+ subs['banner'] = 0
+ else:
+ import random
+ subs['banner'] = random.randrange(64)
+ try:
+ subs['pepnum'] = '%04i' % int(pepnum)
+ except:
+ subs['pepnum'] = pepnum
+ subs['title'] = header[1][1].astext()
+ subs['body'] = ''.join(
+ self.body_pre_docinfo + self.docinfo + self.body)
+ subs['body_suffix'] = ''.join(self.body_suffix)
+ self.output = template % subs
+
+
+class HTMLTranslator(html4css1.HTMLTranslator):
+
+ def get_stylesheet_reference(self, relative_to=None):
+ settings = self.settings
+ if relative_to == None:
+ relative_to = settings._destination
+ if settings.pep_stylesheet_path:
+ return utils.relative_path(relative_to,
+ settings.pep_stylesheet_path)
+ elif settings.pep_stylesheet:
+ return settings.pep_stylesheet
+ elif settings._stylesheet_path:
+ return utils.relative_path(relative_to, settings.stylesheet_path)
+ else:
+ return settings.stylesheet
+
+ def depart_field_list(self, node):
+ html4css1.HTMLTranslator.depart_field_list(self, node)
+ if node.get('class') == 'rfc2822':
+ self.body.append('<hr />\n')
diff --git a/dev-python/docutils/files/glep-0.3-r1/glepread.py b/dev-python/docutils/files/glep-0.3-r1/glepread.py
new file mode 100644
index 000000000000..ec3b4cb23592
--- /dev/null
+++ b/dev-python/docutils/files/glep-0.3-r1/glepread.py
@@ -0,0 +1,53 @@
+# Author: David Goodger
+# Contact: goodger@users.sourceforge.net
+# Revision: $Revision: 1.1 $
+# Date: $Date: 2003/07/07 23:39:10 $
+# Copyright: This module has been placed in the public domain.
+
+"""
+Gentoo Linux Enhancement Proposal (GLEP) Reader.
+"""
+
+__docformat__ = 'reStructuredText'
+
+
+import sys
+import os
+import re
+from docutils import nodes
+from docutils.readers import standalone
+from docutils.transforms import gleps, references
+from docutils.parsers import rst
+
+
+class Reader(standalone.Reader):
+
+ supported = ('glep',)
+ """Contexts this reader supports."""
+
+ settings_spec = (
+ 'PEP Reader Option Defaults',
+ 'The --pep-references and --rfc-references options (for the '
+ 'reStructuredText parser) are on by default.',
+ ())
+
+ default_transforms = (references.Substitutions,
+ gleps.Headers,
+ gleps.Contents,
+ references.ChainedTargets,
+ references.AnonymousHyperlinks,
+ references.IndirectHyperlinks,
+ gleps.TargetNotes,
+ references.Footnotes,
+ references.ExternalTargets,
+ references.InternalTargets,)
+
+ settings_default_overrides = {'pep_references': 1, 'rfc_references': 1}
+
+ inliner_class = rst.states.Inliner
+
+ def __init__(self, parser=None, parser_name=None):
+ """`parser` should be ``None``."""
+ if parser is None:
+ parser = rst.Parser(rfc2822=1, inliner=self.inliner_class())
+ standalone.Reader.__init__(self, parser, '')
diff --git a/dev-python/docutils/files/glep-0.3-r1/glepstrans.py b/dev-python/docutils/files/glep-0.3-r1/glepstrans.py
new file mode 100644
index 000000000000..8bd348371d91
--- /dev/null
+++ b/dev-python/docutils/files/glep-0.3-r1/glepstrans.py
@@ -0,0 +1,293 @@
+# Author: David Goodger
+# Contact: goodger@users.sourceforge.net
+# Revision: $Revision: 1.1 $
+# Date: $Date: 2003/07/07 23:39:10 $
+# Copyright: This module has been placed in the public domain.
+
+"""
+Transforms for GLEP processing.
+
+- `Headers`: Used to transform a PEP's initial RFC-2822 header. It remains a
+ field list, but some entries get processed.
+- `Contents`: Auto-inserts a table of contents.
+"""
+
+__docformat__ = 'reStructuredText'
+
+import sys
+import os
+import re
+import time
+from docutils import nodes, utils
+from docutils import ApplicationError, DataError
+from docutils.transforms import Transform, TransformError
+from docutils.transforms import parts, references, misc
+
+
+class Headers(Transform):
+
+ """
+ Process fields in a GLEP's initial RFC-2822 header.
+ """
+
+ default_priority = 360
+
+ pep_url = 'glep-%04d.html'
+ pep_cvs_url = ('http://cvs.gentoo.org/cgi-bin/viewcvs.cgi/gentoo/'
+ 'xml/htdocs/proj/en/glep/glep-%04d.txt')
+ rcs_keyword_substitutions = (
+ (re.compile(r'\$' r'RCSfile: (.+),v \$$', re.IGNORECASE), r'\1'),
+ (re.compile(r'\$[a-zA-Z]+: (.+) \$$'), r'\1'),)
+
+ def apply(self):
+ if not len(self.document):
+ # @@@ replace these DataErrors with proper system messages
+ raise DataError('Document tree is empty.')
+ header = self.document[0]
+ if not isinstance(header, nodes.field_list) or \
+ header.get('class') != 'rfc2822':
+ raise DataError('Document does not begin with an RFC-2822 '
+ 'header; it is not a PEP.')
+ pep = None
+ for field in header:
+ if field[0].astext().lower() == 'glep': # should be the first field
+ value = field[1].astext()
+ try:
+ pep = int(value)
+ cvs_url = self.pep_cvs_url % pep
+ except ValueError:
+ pep = value
+ cvs_url = None
+ msg = self.document.reporter.warning(
+ '"GLEP" header must contain an integer; "%s" is an '
+ 'invalid value.' % pep, base_node=field)
+ msgid = self.document.set_id(msg)
+ prb = nodes.problematic(value, value or '(none)',
+ refid=msgid)
+ prbid = self.document.set_id(prb)
+ msg.add_backref(prbid)
+ if len(field[1]):
+ field[1][0][:] = [prb]
+ else:
+ field[1] += nodes.paragraph('', '', prb)
+ break
+ if pep is None:
+ raise DataError('Document does not contain an RFC-2822 "GLEP" '
+ 'header.')
+ if pep == 0:
+ # Special processing for PEP 0.
+ pending = nodes.pending(PEPZero)
+ self.document.insert(1, pending)
+ self.document.note_pending(pending)
+ if len(header) < 2 or header[1][0].astext().lower() != 'title':
+ raise DataError('No title!')
+ for field in header:
+ name = field[0].astext().lower()
+ body = field[1]
+ if len(body) > 1:
+ raise DataError('GLEP header field body contains multiple '
+ 'elements:\n%s' % field.pformat(level=1))
+ elif len(body) == 1:
+ if not isinstance(body[0], nodes.paragraph):
+ raise DataError('GLEP header field body may only contain '
+ 'a single paragraph:\n%s'
+ % field.pformat(level=1))
+ elif name == 'last-modified':
+ date = time.strftime(
+ '%d-%b-%Y',
+ time.localtime(os.stat(self.document['source'])[8]))
+ if cvs_url:
+ body += nodes.paragraph(
+ '', '', nodes.reference('', date, refuri=cvs_url))
+ else:
+ # empty
+ continue
+ para = body[0]
+ if name == 'author':
+ for node in para:
+ if isinstance(node, nodes.reference):
+ node.parent.replace(node, mask_email(node))
+ elif name == 'discussions-to':
+ for node in para:
+ if isinstance(node, nodes.reference):
+ node.parent.replace(node, mask_email(node, pep))
+ elif name in ('replaces', 'replaced-by', 'requires'):
+ newbody = []
+ space = nodes.Text(' ')
+ for refpep in re.split(',?\s+', body.astext()):
+ pepno = int(refpep)
+ newbody.append(nodes.reference(
+ refpep, refpep, refuri=self.pep_url % pepno))
+ newbody.append(space)
+ para[:] = newbody[:-1] # drop trailing space
+ elif name == 'last-modified':
+ utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)
+ if cvs_url:
+ date = para.astext()
+ para[:] = [nodes.reference('', date, refuri=cvs_url)]
+ elif name == 'content-type':
+ pep_type = para.astext()
+ uri = self.pep_url % 2
+ para[:] = [nodes.reference('', pep_type, refuri=uri)]
+ elif name == 'version' and len(body):
+ utils.clean_rcs_keywords(para, self.rcs_keyword_substitutions)
+
+
+class Contents(Transform):
+
+ """
+ Insert a table of contents transform placeholder into the document after
+ the RFC 2822 header.
+ """
+
+ default_priority = 380
+
+ def apply(self):
+ pending = nodes.pending(parts.Contents, {'title': None})
+ self.document.insert(1, pending)
+ self.document.note_pending(pending)
+
+
+class TargetNotes(Transform):
+
+ """
+ Locate the "References" section, insert a placeholder for an external
+ target footnote insertion transform at the end, and schedule the
+ transform to run immediately.
+ """
+
+ default_priority = 520
+
+ def apply(self):
+ doc = self.document
+ i = len(doc) - 1
+ refsect = copyright = None
+ while i >= 0 and isinstance(doc[i], nodes.section):
+ title_words = doc[i][0].astext().lower().split()
+ if 'references' in title_words:
+ refsect = doc[i]
+ break
+ elif 'copyright' in title_words:
+ copyright = i
+ i -= 1
+ if not refsect:
+ refsect = nodes.section()
+ refsect += nodes.title('', 'References')
+ doc.set_id(refsect)
+ if copyright:
+ # Put the new "References" section before "Copyright":
+ doc.insert(copyright, refsect)
+ else:
+ # Put the new "References" section at end of doc:
+ doc.append(refsect)
+ pending = nodes.pending(references.TargetNotes)
+ refsect.append(pending)
+ self.document.note_pending(pending, 0)
+ pending = nodes.pending(misc.CallBack,
+ details={'callback': self.cleanup_callback})
+ refsect.append(pending)
+ self.document.note_pending(pending, 1)
+
+ def cleanup_callback(self, pending):
+ """
+ Remove an empty "References" section.
+
+ Called after the `references.TargetNotes` transform is complete.
+ """
+ if len(pending.parent) == 2: # <title> and <pending>
+ pending.parent.parent.remove(pending.parent)
+
+
+class PEPZero(Transform):
+
+ """
+ Special processing for PEP 0.
+ """
+
+ default_priority =760
+
+ def apply(self):
+ visitor = PEPZeroSpecial(self.document)
+ self.document.walk(visitor)
+ self.startnode.parent.remove(self.startnode)
+
+
+class PEPZeroSpecial(nodes.SparseNodeVisitor):
+
+ """
+ Perform the special processing needed by PEP 0:
+
+ - Mask email addresses.
+
+ - Link PEP numbers in the second column of 4-column tables to the PEPs
+ themselves.
+ """
+
+ pep_url = Headers.pep_url
+
+ def unknown_visit(self, node):
+ pass
+
+ def visit_reference(self, node):
+ node.parent.replace(node, mask_email(node))
+
+ def visit_field_list(self, node):
+ if node.hasattr('class') and node['class'] == 'rfc2822':
+ raise nodes.SkipNode
+
+ def visit_tgroup(self, node):
+ self.pep_table = node['cols'] == 4
+ self.entry = 0
+
+ def visit_colspec(self, node):
+ self.entry += 1
+ if self.pep_table and self.entry == 2:
+ node['class'] = 'num'
+
+ def visit_row(self, node):
+ self.entry = 0
+
+ def visit_entry(self, node):
+ self.entry += 1
+ if self.pep_table and self.entry == 2 and len(node) == 1:
+ node['class'] = 'num'
+ p = node[0]
+ if isinstance(p, nodes.paragraph) and len(p) == 1:
+ text = p.astext()
+ try:
+ pep = int(text)
+ ref = self.pep_url % pep
+ p[0] = nodes.reference(text, text, refuri=ref)
+ except ValueError:
+ pass
+
+
+non_masked_addresses = ('peps@python.org',
+ 'python-list@python.org',
+ 'python-dev@python.org')
+
+def mask_email(ref, pepno=None):
+ """
+ Mask the email address in `ref` and return a replacement node.
+
+ `ref` is returned unchanged if it contains no email address.
+
+ For email addresses such as "user@host", mask the address as "user at
+ host" (text) to thwart simple email address harvesters (except for those
+ listed in `non_masked_addresses`). If a PEP number (`pepno`) is given,
+ return a reference including a default email subject.
+ """
+ if ref.hasattr('refuri') and ref['refuri'].startswith('mailto:'):
+ if ref['refuri'][8:] in non_masked_addresses:
+ replacement = ref[0]
+ else:
+ replacement_text = ref.astext().replace('@', '&#32;&#97;t&#32;')
+ replacement = nodes.raw('', replacement_text, format='html')
+ if pepno is None:
+ return replacement
+ else:
+ ref['refuri'] += '?subject=PEP%%20%s' % pepno
+ ref[:] = [replacement]
+ return ref
+ else:
+ return ref