changeset 8:8e909570e7de

history works
author catherine@serenity.wpafb.af.mil
date Thu, 06 Dec 2007 10:37:59 -0500
parents d44784122203
children f70cc3be6377
files sqlpyPlus.py
diffstat 1 files changed, 13 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpyPlus.py	Wed Dec 05 16:27:43 2007 -0500
+++ b/sqlpyPlus.py	Thu Dec 06 10:37:59 2007 -0500
@@ -355,8 +355,7 @@
         print self
         
 class History(list):
-    digitsOnly = re.compile('^[\d]+$')
-    rangeTo = re.compile(r'^\-\s*([-d])+$')
+    rangeFrom = re.compile(r'^([\d])+\s*\-$')
     def append(self, new):
         new = HistoryItem(new)
         list.append(self, new)
@@ -365,27 +364,19 @@
         for n in new:
             self.append(n)
     def get(self, getme):
-        getme = getme.strip()
-        if not getme:
+        try:
+            getme = int(getme)
+            if getme < 0:
+                return self[:(-1 * getme)]
+            else:
+                return self[getme-1]
+        except IndexError:
             return []
-        if self.digitsOnly.search(getme):        
-            try:
-                idx = int(getme)
-                try:
-                    return [self[idx-1]]
-                except IndexError:
-                    return []
-        m = self.rangeTo.search(getme)
-        if m:
-            return self[int(:m.group(1))]
-        
-            excep
-        except ValueError:  # search for a string
-            try:
-                getme = getme.strip()
-            except:
-                print "Don't know how to handle %s." % (str(getme))
-                return 
+        except (ValueError, TypeError):
+            getme = getme.strip()
+            mtch = self.rangeFrom.search(getme)
+            if mtch:
+                return self[(int(mtch.group(1))-1):]
             if getme.startswith(r'/') and getme.endswith(r'/'):
                 finder = re.compile(getme[1:-1], re.DOTALL | re.MULTILINE | re.IGNORECASE)
                 def isin(hi):