mail[Wesnoth-commits] r34299 - /trunk/data/tools/wesnoth/wmliterator.py


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by esr on March 30, 2009 - 22:49:
Author: esr
Date: Mon Mar 30 22:49:38 2009
New Revision: 34299

URL: http://svn.gna.org/viewcvs/wesnoth?rev=34299&view=rev
Log:
Improved convenience methods for testing element types.

Modified:
    trunk/data/tools/wesnoth/wmliterator.py

Modified: trunk/data/tools/wesnoth/wmliterator.py
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/tools/wesnoth/wmliterator.py?rev=34299&r1=34298&r2=34299&view=diff
==============================================================================
--- trunk/data/tools/wesnoth/wmliterator.py (original)
+++ trunk/data/tools/wesnoth/wmliterator.py Mon Mar 30 22:49:38 2009
@@ -62,13 +62,31 @@
     "Are we looking at a closing tag?"
     if isinstance(elem, WmlIterator):
         elem = elem.element
-    return elem.startswith("[/")
+    return type(elem) == type("") and elem.startswith("[/")
+
+def isMacroCloser(elem):
+    "Are we looking at a macro closer?"
+    if isinstance(elem, WmlIterator):
+        elem = elem.element
+    return type(elem) == type("") and elem.startswith("}")
 
 def isOpener(elem):
     "Are we looking at an opening tag?"
     if isinstance(elem, WmlIterator):
         elem = elem.element
-    return elem.startswith("[") and not isCloser(elem)
+    return type(elem) == type("") and elem.startswith("[") and not 
isCloser(elem)
+
+def isMacroOpener(elem):
+    "Are we looking at a macro opener?"
+    if isinstance(elem, WmlIterator):
+        elem = elem.element
+    return type(elem) == type("") and elem.startswith("{")
+
+def isAttribute(elem):
+    "Are we looking at an attribute?"
+    if isinstance(elem, WmlIterator):
+        elem = elem.element
+    return type(elem) == type(()) or (type(elem) == type("") and 
elem.endswith("="))
 
 class WmlIterator(object):
     """Return an iterable WML navigation object.
@@ -355,6 +373,21 @@
             raise StopIteration
         return self
 
+    def isOpener(self):
+        return isOpener(self)
+
+    def isCloser(self):
+        return isCloser(self)
+
+    def isMacroOpener(self):
+        return isMacroOpener(self)
+
+    def isMacroCloser(self):
+        return isMacroCloser(self)
+
+    def isAttribute(self):
+        return isAttribute(self)
+
     def iterScope(self):
         """Return an iterator for the current scope"""
         if not self.scopes:




Related Messages


Powered by MHonArc, Updated Mon Mar 30 23:20:28 2009