diff roundup/cgi/TAL/markupbase.py @ 2348:8c2402a78bb0

beginning getting ZPT up to date: TAL first
author Richard Jones <richard@users.sourceforge.net>
date Fri, 21 May 2004 05:36:30 +0000
parents fc52d57c6c3e
children 12fe83f90f0d
line wrap: on
line diff
--- a/roundup/cgi/TAL/markupbase.py	Thu May 20 23:16:58 2004 +0000
+++ b/roundup/cgi/TAL/markupbase.py	Fri May 21 05:36:30 2004 +0000
@@ -1,9 +1,6 @@
-"""Shared support for scanning document type declarations in HTML and XHTML.
-"""
-__docformat__ = 'restructuredtext'
+"""Shared support for scanning document type declarations in HTML and XHTML."""
 
-import re
-import string
+import re, string
 
 _declname_match = re.compile(r'[a-zA-Z][-_.a-zA-Z0-9]*\s*').match
 _declstringlit_match = re.compile(r'(\'[^\']*\'|"[^"]*")\s*').match
@@ -23,6 +20,13 @@
         """Return current line number and offset."""
         return self.lineno, self.offset
 
+    def error(self, message):
+        """Return an error, showing current line number and offset.
+
+        Concrete subclasses *must* override this method.
+        """
+        raise NotImplementedError
+
     # Internal -- update line number and offset.  This should be
     # called for each piece of data exactly once, in order -- in other
     # words the concatenation of all the input strings to this
@@ -31,10 +35,10 @@
         if i >= j:
             return j
         rawdata = self.rawdata
-        nlines = string.count(rawdata, "\n", i, j)
+        nlines = rawdata.count("\n", i, j)
         if nlines:
             self.lineno = self.lineno + nlines
-            pos = string.rindex(rawdata, "\n", i, j) # Should not fail
+            pos = rawdata.rindex("\n", i, j) # Should not fail
             self.offset = j-(pos+1)
         else:
             self.offset = self.offset + j-i
@@ -171,7 +175,7 @@
             return -1
         # style content model; just skip until '>'
         if '>' in rawdata[j:]:
-            return string.find(rawdata, ">", j) + 1
+            return rawdata.find(">", j) + 1
         return -1
 
     # Internal -- scan past <!ATTLIST declarations
@@ -195,10 +199,10 @@
             if c == "(":
                 # an enumerated type; look for ')'
                 if ")" in rawdata[j:]:
-                    j = string.find(rawdata, ")", j) + 1
+                    j = rawdata.find(")", j) + 1
                 else:
                     return -1
-                while rawdata[j:j+1] in string.whitespace:
+                while rawdata[j:j+1].isspace():
                     j = j + 1
                 if not rawdata[j:]:
                     # end of buffer, incomplete
@@ -299,10 +303,10 @@
         m = _declname_match(rawdata, i)
         if m:
             s = m.group()
-            name = string.strip(s)
+            name = s.strip()
             if (i + len(s)) == n:
                 return None, -1  # end of buffer
-            return string.lower(name), m.end()
+            return name.lower(), m.end()
         else:
             self.updatepos(declstartpos, i)
-            self.error("expected name token", self.getpos())
+            self.error("expected name token")

Roundup Issue Tracker: http://roundup-tracker.org/