Code

svn repository setup
[roundup.git] / roundup / cgi / TAL / markupbase.py
index 2bcf6a7bbd1fb3adc4cbb943df4ce1ccdffed290..b25b3eded254ddc858c351313255728023f04632 100644 (file)
@@ -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 @@ class ParserBase:
         """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 @@ class ParserBase:
         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 @@ class ParserBase:
             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 @@ class ParserBase:
             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 @@ class ParserBase:
         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")