[Mumps2Py:] [72] added __del__ method to the Token class.

[ Thread Index | Date Index | More lists.mumps2py.org/discuss Archives ]


Revision: 72
Author:   pgallot
Date:     2008-01-31 21:33:21 +0000 (Thu, 31 Jan 2008)

Log Message:
-----------
added __del__ method to the Token class. I can be convinced that it's not necessary, but for now it's there. 

Modified Paths:
--------------
    trunk/mumps2py/tokens.py


Modified: trunk/mumps2py/tokens.py
===================================================================
--- trunk/mumps2py/tokens.py	2008-01-31 21:20:34 UTC (rev 71)
+++ trunk/mumps2py/tokens.py	2008-01-31 21:33:21 UTC (rev 72)
@@ -328,6 +328,18 @@
         self.repcount = None
         self.indirect = None
 
+    def __del__(self):
+        """delete any sub-tokens"""
+        for varname in [key for key in self.__dict__.keys() \
+                    if key not in \
+                    ('start', 'end', 'toktype', 'lineno')]:
+            var = self.__dict__[varname]
+            if isinstance(var, DictType):
+                var.clear()
+            elif isinstance(var, ListType):
+                while len(var):
+                    var.pop()
+        
     def __str__(self):
         """returns a string expression of a token contents and subtokens"""
         if TOKEN_REVERSE_DICT.has_key(self.toktype):


Mail converted by MHonArc 2.6.19+ http://listengine.tuxfamily.org/