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

Christian 'Tiran' Heimes heimes at faho.rwth-aachen.de
Thu May 13 12:20:34 EDT 2004


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

Modified Files:
      Tag: Zope-2_7-branch
	__init__.py components.py frontmatter.py misc.py parts.py 
	peps.py references.py universal.py 
Log Message:
Merge from tiran-restfixing-branch


=== Zope/lib/python/docutils/transforms/__init__.py 1.2.10.3 => 1.2.10.4 ===
--- Zope/lib/python/docutils/transforms/__init__.py:1.2.10.3	Sun Nov 30 11:05:26 2003
+++ Zope/lib/python/docutils/transforms/__init__.py	Thu May 13 12:20:03 2004
@@ -59,6 +59,7 @@
         self.language = languages.get_language(
             document.settings.language_code)
         """Language module local to this document."""
+        
 
     def apply(self):
         """Override to apply the transform to the document tree."""
@@ -76,7 +77,8 @@
 
     default_transforms = (universal.Decorations,
                           universal.FinalChecks,
-                          universal.Messages)
+                          universal.Messages,
+                          universal.FilterMessages)
     """These transforms are applied to all document trees."""
 
     def __init__(self, document):
@@ -84,6 +86,9 @@
         """List of transforms to apply.  Each item is a 3-tuple:
         ``(priority string, transform class, pending node or None)``."""
 
+        self.unknown_reference_resolvers = []
+        """List of hook functions which assist in resolving references"""
+
         self.document = document
         """The `nodes.document` object this Transformer is attached to."""
 
@@ -149,6 +154,16 @@
             self.add_transforms(component.default_transforms)
             self.components[component.component_type] = component
         self.sorted = 0
+        # Setup all of the reference resolvers for this transformer. Each
+        # component of this transformer is able to register its own helper
+        # functions to help resolve references.
+        unknown_reference_resolvers = []
+        for i in components:
+            unknown_reference_resolvers.extend(i.unknown_reference_resolvers)
+        decorated_list = [(f.priority, f) for f in unknown_reference_resolvers]
+        decorated_list.sort()
+        self.unknown_reference_resolvers.extend([f[1] for f in decorated_list])
+
 
     def apply_transforms(self):
         """Apply all of the stored transforms, in priority order."""


=== Zope/lib/python/docutils/transforms/components.py 1.2.10.3 => 1.2.10.4 ===


=== Zope/lib/python/docutils/transforms/frontmatter.py 1.2.10.3 => 1.2.10.4 ===
--- Zope/lib/python/docutils/transforms/frontmatter.py:1.2.10.3	Sun Nov 30 11:05:26 2003
+++ Zope/lib/python/docutils/transforms/frontmatter.py	Thu May 13 12:20:03 2004
@@ -334,10 +334,10 @@
         return 1
 
     rcs_keyword_substitutions = [
-          (re.compile(r'\$' r'Date: (\d\d\d\d)/(\d\d)/(\d\d) [\d:]+ \$$',
+          (re.compile(r'\$' r'Date: (\d\d\d\d)/(\d\d)/(\d\d) [\d:]+ \$',
                       re.IGNORECASE), r'\1-\2-\3'),
-          (re.compile(r'\$' r'RCSfile: (.+),v \$$', re.IGNORECASE), r'\1'),
-          (re.compile(r'\$[a-zA-Z]+: (.+) \$$'), r'\1'),]
+          (re.compile(r'\$' r'RCSfile: (.+),v \$', re.IGNORECASE), r'\1'),
+          (re.compile(r'\$[a-zA-Z]+: (.+) \$'), r'\1'),]
 
     def extract_authors(self, field, name, docinfo):
         try:


=== Zope/lib/python/docutils/transforms/misc.py 1.2.10.3 => 1.2.10.4 ===


=== Zope/lib/python/docutils/transforms/parts.py 1.2.10.3 => 1.2.10.4 ===
--- Zope/lib/python/docutils/transforms/parts.py:1.2.10.3	Sun Nov 30 11:05:26 2003
+++ Zope/lib/python/docutils/transforms/parts.py	Thu May 13 12:20:03 2004
@@ -34,7 +34,8 @@
     def apply(self):
         self.maxdepth = self.startnode.details.get('depth', sys.maxint)
         self.startnode.parent.remove(self.startnode)
-        self.update_section_numbers(self.document)
+        if self.document.settings.sectnum_xform:
+            self.update_section_numbers(self.document)
 
     def update_section_numbers(self, node, prefix=(), depth=0):
         depth += 1
@@ -58,11 +59,11 @@
     """
     This transform generates a table of contents from the entire document tree
     or from a single branch.  It locates "section" elements and builds them
-    into a nested bullet list, which is placed within a "topic".  A title is
-    either explicitly specified, taken from the appropriate language module,
-    or omitted (local table of contents).  The depth may be specified.
-    Two-way references between the table of contents and section titles are
-    generated (requires Writer support).
+    into a nested bullet list, which is placed within a "topic" created by the
+    contents directive.  A title is either explicitly specified, taken from
+    the appropriate language module, or omitted (local table of contents).
+    The depth may be specified.  Two-way references between the table of
+    contents and section titles are generated (requires Writer support).
 
     This transform requires a startnode, which which contains generation
     options and provides the location for the generated table of contents (the
@@ -72,41 +73,26 @@
     default_priority = 720
 
     def apply(self):
-        topic = nodes.topic(CLASS='contents')
         details = self.startnode.details
-        if details.has_key('class'):
-            topic.set_class(details['class'])
-        title = details['title']
         if details.has_key('local'):
-            startnode = self.startnode.parent
+            startnode = self.startnode.parent.parent
             # @@@ generate an error if the startnode (directive) not at
             # section/document top-level? Drag it up until it is?
             while not isinstance(startnode, nodes.Structural):
                 startnode = startnode.parent
         else:
             startnode = self.document
-            if not title:
-                title = nodes.title('', self.language.labels['contents'])
-        if title:
-            name = title.astext()
-            topic += title
-        else:
-            name = self.language.labels['contents']
-        name = nodes.fully_normalize_name(name)
-        if not self.document.has_name(name):
-            topic['name'] = name
-        self.document.note_implicit_target(topic)
-        self.toc_id = topic['id']
+
+        self.toc_id = self.startnode.parent['id']
         if details.has_key('backlinks'):
             self.backlinks = details['backlinks']
         else:
             self.backlinks = self.document.settings.toc_backlinks
         contents = self.build_contents(startnode)
         if len(contents):
-            topic += contents
-            self.startnode.parent.replace(self.startnode, topic)
+            self.startnode.parent.replace(self.startnode, contents)
         else:
-            self.startnode.parent.remove(self.startnode)
+            self.startnode.parent.parent.remove(self.startnode.parent)
 
     def build_contents(self, node, level=0):
         level += 1


=== Zope/lib/python/docutils/transforms/peps.py 1.2.10.3 => 1.2.10.4 ===
--- Zope/lib/python/docutils/transforms/peps.py:1.2.10.3	Sun Nov 30 11:05:26 2003
+++ Zope/lib/python/docutils/transforms/peps.py	Thu May 13 12:20:03 2004
@@ -19,7 +19,7 @@
 import os
 import re
 import time
-from docutils import nodes, utils
+from docutils import nodes, utils, languages
 from docutils import ApplicationError, DataError
 from docutils.transforms import Transform, TransformError
 from docutils.transforms import parts, references, misc
@@ -137,15 +137,24 @@
 class Contents(Transform):
 
     """
-    Insert a table of contents transform placeholder into the document after
-    the RFC 2822 header.
+    Insert an empty table of contents topic and a 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)
+        language = languages.get_language(self.document.settings.language_code)
+        name = language.labels['contents']
+        title = nodes.title('', name)
+        topic = nodes.topic('', title, CLASS='contents')
+        name = nodes.fully_normalize_name(name)
+        if not self.document.has_name(name):
+            topic['name'] = name
+        self.document.note_implicit_target(topic)
+        pending = nodes.pending(parts.Contents)
+        topic += pending
+        self.document.insert(1, topic)
         self.document.note_pending(pending)
 
 


=== Zope/lib/python/docutils/transforms/references.py 1.2.10.3 => 1.2.10.4 ===
--- Zope/lib/python/docutils/transforms/references.py:1.2.10.3	Sun Nov 30 11:05:26 2003
+++ Zope/lib/python/docutils/transforms/references.py	Thu May 13 12:20:03 2004
@@ -216,7 +216,13 @@
         refname = target['refname']
         reftarget_id = self.document.nameids.get(refname)
         if not reftarget_id:
-            self.nonexistent_indirect_target(target)
+            # Check the unknown_reference_resolvers
+            for resolver_function in (self.document.transformer
+                                      .unknown_reference_resolvers):
+                if resolver_function(target):
+                    break
+            else:
+                self.nonexistent_indirect_target(target)
             return
         reftarget = self.document.ids[reftarget_id]
         if isinstance(reftarget, nodes.target) \
@@ -248,7 +254,11 @@
         reftarget.referenced = 1
 
     def nonexistent_indirect_target(self, target):
-        self.indirect_target_error(target, 'which does not exist')
+        if self.document.nameids.has_key(target['refname']):
+            self.indirect_target_error(target, 'which is a duplicate, and '
+                                       'cannot be used as a unique reference')
+        else:
+            self.indirect_target_error(target, 'which does not exist')
 
     def circular_indirect_reference(self, target):
         self.indirect_target_error(target, 'forming a circular reference')
@@ -353,7 +363,8 @@
                 try:
                     reflist = self.document.refnames[name]
                 except KeyError, instance:
-                    if target.referenced:
+                    # @@@ First clause correct???
+                    if not isinstance(target, nodes.target) or target.referenced:
                         continue
                     msg = self.document.reporter.info(
                           'External hyperlink target "%s" is not referenced.'


=== Zope/lib/python/docutils/transforms/universal.py 1.2.10.3 => 1.2.10.4 ===
--- Zope/lib/python/docutils/transforms/universal.py:1.2.10.3	Sun Nov 30 11:05:26 2003
+++ Zope/lib/python/docutils/transforms/universal.py	Thu May 13 12:20:03 2004
@@ -111,6 +111,29 @@
             self.document += section
 
 
+class FilterMessages(Transform):
+
+    """
+    Remove system messages below verbosity threshold.
+    """
+
+    default_priority = 870
+
+    def apply(self):
+        visitor = SystemMessageFilterVisitor(self.document)
+        self.document.walk(visitor)
+
+
+class SystemMessageFilterVisitor(nodes.SparseNodeVisitor):
+
+    def unknown_visit(self, node):
+        pass
+
+    def visit_system_message(self, node):
+        if node['level'] < self.document.reporter['writer'].report_level:
+            node.parent.remove(node)
+
+
 class TestMessages(Transform):
 
     """
@@ -136,7 +159,9 @@
     default_priority = 840
 
     def apply(self):
-        visitor = FinalCheckVisitor(self.document)
+        visitor = FinalCheckVisitor(
+            self.document,
+            self.document.transformer.unknown_reference_resolvers)
         self.document.walk(visitor)
         if self.document.settings.expose_internals:
             visitor = InternalAttributeExposer(self.document)
@@ -144,6 +169,11 @@
 
 
 class FinalCheckVisitor(nodes.SparseNodeVisitor):
+    
+    def __init__(self, document, unknown_reference_resolvers):
+        nodes.SparseNodeVisitor.__init__(self, document)
+        self.document = document
+        self.unknown_reference_resolvers = unknown_reference_resolvers
 
     def unknown_visit(self, node):
         pass
@@ -154,15 +184,24 @@
         refname = node['refname']
         id = self.document.nameids.get(refname)
         if id is None:
-            msg = self.document.reporter.error(
-                  'Unknown target name: "%s".' % (node['refname']),
-                  base_node=node)
-            msgid = self.document.set_id(msg)
-            prb = nodes.problematic(
-                  node.rawsource, node.rawsource, refid=msgid)
-            prbid = self.document.set_id(prb)
-            msg.add_backref(prbid)
-            node.parent.replace(node, prb)
+            for resolver_function in self.unknown_reference_resolvers:
+                if resolver_function(node):
+                    break
+            else:
+                if self.document.nameids.has_key(refname):
+                    msg = self.document.reporter.error(
+                        'Duplicate target name, cannot be used as a unique '
+                        'reference: "%s".' % (node['refname']), base_node=node)
+                else:
+                    msg = self.document.reporter.error(
+                        'Unknown target name: "%s".' % (node['refname']),
+                        base_node=node)
+                msgid = self.document.set_id(msg)
+                prb = nodes.problematic(
+                      node.rawsource, node.rawsource, refid=msgid)
+                prbid = self.document.set_id(prb)
+                msg.add_backref(prbid)
+                node.parent.replace(node, prb)
         else:
             del node['refname']
             node['refid'] = id




More information about the Zope-Checkins mailing list