diff options
author | Alastair Tse <liquidx@gentoo.org> | 2003-07-07 23:39:22 +0000 |
---|---|---|
committer | Alastair Tse <liquidx@gentoo.org> | 2003-07-07 23:39:22 +0000 |
commit | c85b1ed7d62808ee05732988496e585c64b9f662 (patch) | |
tree | fd01d4cbab54bfa2f0e63b2383dc92c79f5d1ce5 /dev-python/docutils/files | |
parent | revision bump. changes to glep scripts and docutils installation (diff) | |
download | gentoo-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/docutils/files')
-rw-r--r-- | dev-python/docutils/files/digest-docutils-0.3-r1 | 1 | ||||
-rw-r--r-- | dev-python/docutils/files/docutils-0.3-extramodules.patch | 32 | ||||
-rw-r--r-- | dev-python/docutils/files/glep-0.3-r1/glep.py | 27 | ||||
-rw-r--r-- | dev-python/docutils/files/glep-0.3-r1/glep_htmlwrite.py | 112 | ||||
-rw-r--r-- | dev-python/docutils/files/glep-0.3-r1/glepread.py | 53 | ||||
-rw-r--r-- | dev-python/docutils/files/glep-0.3-r1/glepstrans.py | 293 |
6 files changed, 518 insertions, 0 deletions
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('@', ' at ') + 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 |