[Zope-Checkins] CVS: Zope/lib/python/docutils/transforms - misc.py:1.1.2.1 __init__.py:1.1.2.2 components.py:1.1.2.2 frontmatter.py:1.1.2.2 parts.py:1.1.2.2 peps.py:1.1.2.2 references.py:1.1.2.2 universal.py:1.1.2.2

Andreas Jung andreas@andreas-jung.com
Sat, 25 Jan 2003 07:42:54 -0500


Update of /cvs-repository/Zope/lib/python/docutils/transforms
In directory cvs.zope.org:/tmp/cvs-serv1929/transforms

Modified Files:
      Tag: ajung-restructuredtext-integration-branch
	__init__.py components.py frontmatter.py parts.py peps.py 
	references.py universal.py 
Added Files:
      Tag: ajung-restructuredtext-integration-branch
	misc.py 
Log Message:
docutils updated

=== Added File Zope/lib/python/docutils/transforms/misc.py ===
# Author: David Goodger
# Contact: goodger@users.sourceforge.net
# Revision: $Revision: 1.1.2.1 $
# Date: $Date: 2003/01/25 12:42:49 $
# Copyright: This module has been placed in the public domain.

"""
Miscellaneous transforms.
"""

__docformat__ = 'reStructuredText'

from docutils.transforms import Transform, TransformError


class CallBack(Transform):

    """
    Inserts a callback into a document.  The callback is called when the
    transform is applied, which is determined by its priority.

    For use with `nodes.pending` elements.  Requires a ``details['callback']``
    entry, a bound method or function which takes one parameter: the pending
    node.  Other data can be stored in the ``details`` attribute or in the
    object hosting the callback method.
    """

    default_priority = 990

    def apply(self):
        pending = self.startnode
        pending.details['callback'](pending)
        pending.parent.remove(pending)


=== Zope/lib/python/docutils/transforms/__init__.py 1.1.2.1 => 1.1.2.2 ===


=== Zope/lib/python/docutils/transforms/components.py 1.1.2.1 => 1.1.2.2 ===


=== Zope/lib/python/docutils/transforms/frontmatter.py 1.1.2.1 => 1.1.2.2 ===


=== Zope/lib/python/docutils/transforms/parts.py 1.1.2.1 => 1.1.2.2 ===


=== Zope/lib/python/docutils/transforms/peps.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/docutils/transforms/peps.py:1.1.2.1	Tue Nov  5 04:03:59 2002
+++ Zope/lib/python/docutils/transforms/peps.py	Sat Jan 25 07:42:49 2003
@@ -22,7 +22,7 @@
 from docutils import nodes, utils
 from docutils import ApplicationError, DataError
 from docutils.transforms import Transform, TransformError
-from docutils.transforms import parts, references
+from docutils.transforms import parts, references, misc
 
 
 class Headers(Transform):
@@ -42,13 +42,14 @@
 
     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 = title = None
+        pep = None
         for field in header:
             if field[0].astext().lower() == 'pep': # should be the first field
                 value = field[1].astext()
@@ -79,6 +80,8 @@
             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]
@@ -150,7 +153,8 @@
 
     """
     Locate the "References" section, insert a placeholder for an external
-    target footnote insertion transform at the end, and run the transform.
+    target footnote insertion transform at the end, and schedule the
+    transform to run immediately.
     """
 
     default_priority = 520
@@ -170,6 +174,7 @@
         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)
@@ -179,6 +184,19 @@
         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):


=== Zope/lib/python/docutils/transforms/references.py 1.1.2.1 => 1.1.2.2 ===
--- Zope/lib/python/docutils/transforms/references.py:1.1.2.1	Tue Nov  5 04:03:59 2002
+++ Zope/lib/python/docutils/transforms/references.py	Sat Jan 25 07:42:49 2003
@@ -221,7 +221,14 @@
         reftarget = self.document.ids[reftarget_id]
         if isinstance(reftarget, nodes.target) \
               and not reftarget.resolved and reftarget.hasattr('refname'):
-            self.one_indirect_target(reftarget) # multiply indirect
+            if hasattr(target, 'multiply_indirect'):
+                #and target.multiply_indirect):
+                #del target.multiply_indirect
+                self.circular_indirect_reference(target)
+                return
+            target.multiply_indirect = 1
+            self.resolve_indirect_target(reftarget) # multiply indirect
+            del target.multiply_indirect
         if reftarget.hasattr('refuri'):
             target['refuri'] = reftarget['refuri']
             if target.hasattr('name'):
@@ -241,6 +248,12 @@
         reftarget.referenced = 1
 
     def nonexistent_indirect_target(self, target):
+        self.indirect_target_error(target, 'which does not exist')
+
+    def circular_indirect_reference(self, target):
+        self.indirect_target_error(target, 'forming a circular reference')
+
+    def indirect_target_error(self, target, explanation):
         naming = ''
         if target.hasattr('name'):
             naming = '"%s" ' % target['name']
@@ -248,9 +261,9 @@
         else:
             reflist = self.document.refids.get(target['id'], [])
         naming += '(id="%s")' % target['id']
-        msg = self.document.reporter.warning(
-              'Indirect hyperlink target %s refers to target "%s", '
-              'which does not exist.' % (naming, target['refname']),
+        msg = self.document.reporter.error(
+              'Indirect hyperlink target %s refers to target "%s", %s.'
+              % (naming, target['refname'], explanation),
               base_node=target)
         msgid = self.document.set_id(msg)
         for ref in reflist:


=== Zope/lib/python/docutils/transforms/universal.py 1.1.2.1 => 1.1.2.2 ===