[Zope3-checkins] CVS: Zope3/src/zope/configuration - xmlconfig.py:1.11

Jim Fulton jim@zope.com
Wed, 30 Jul 2003 10:35:04 -0400


Update of /cvs-repository/Zope3/src/zope/configuration
In directory cvs.zope.org:/tmp/cvs-serv1034/src/zope/configuration

Modified Files:
	xmlconfig.py 
Log Message:
Fixed two bugs in the stringification of parser info objects:

- The column positions were off by one. Strangely, the parser
  gives 1-based line numbers and 0-based column positions. :/

- The end-tag column positions point at the beginning of the end
  tag. This caused end tags to me ommitted from info strs.  I added
  logic to detect this case and find the end of the end tags.

Also keep leading whitespace when start tags are the first non-blank
text on a line.


=== Zope3/src/zope/configuration/xmlconfig.py 1.10 => 1.11 ===
--- Zope3/src/zope/configuration/xmlconfig.py:1.10	Mon Jul 28 18:22:39 2003
+++ Zope3/src/zope/configuration/xmlconfig.py	Wed Jul 30 10:35:00 2003
@@ -84,24 +84,24 @@
     This includes the directive location, as well as text data
     contained in the directive.
 
-    >>> info = ParserInfo('tests//sample.zcml', 1, 1)
+    >>> info = ParserInfo('tests//sample.zcml', 1, 0)
     >>> info
-    File "tests//sample.zcml", line 1.1
+    File "tests//sample.zcml", line 1.0
 
     >>> print info
-    File "tests//sample.zcml", line 1.1
+    File "tests//sample.zcml", line 1.0
 
     >>> info.characters("blah\\n")
     >>> info.characters("blah")
     >>> info.text
     u'blah\\nblah'
 
-    >>> info.end(7,16)
+    >>> info.end(7, 0)
     >>> info
-    File "tests//sample.zcml", line 1.1-7.16
+    File "tests//sample.zcml", line 1.0-7.0
 
     >>> print info
-    File "tests//sample.zcml", line 1.1-7.16
+    File "tests//sample.zcml", line 1.0-7.0
       <zopeConfigure xmlns='http://namespaces.zope.org/zope'>
         <!-- zope.configure -->
         <directives namespace="http://namespaces.zope.org/zope">
@@ -147,8 +147,21 @@
             src = "  Could not read source."
         else:
             lines = f.readlines()[self.line-1:self.eline]
-            lines[0] = lines[0][self.column-1:]
-            lines[-1] = lines[-1][:self.ecolumn]
+            ecolumn = self.ecolumn
+            if lines[-1][ecolumn:ecolumn+2] == '</':
+                # We're pointing to the start of an end tag. Try to find
+                # the end
+                l = lines[-1].find('>', ecolumn)
+                if l >= 0:
+                    lines[-1] = lines[-1][:l+1]
+            else:
+                lines[-1] = lines[-1][:ecolumn+1]
+
+            column = self.column
+            if lines[0][:column].strip():
+                # Remove text before start if it's noy whitespace
+                lines[0] = lines[0][self.column:]
+                
             src = ''.join([u"  "+l for l in lines])
 
         return "%s\n%s" % (`self`, src)