Mercurial > sqlpython
comparison sqlpyPlus.py @ 8:8e909570e7de
history works
author | catherine@serenity.wpafb.af.mil |
---|---|
date | Thu, 06 Dec 2007 10:37:59 -0500 |
parents | d44784122203 |
children | 2ef0e2608123 |
comparison
equal
deleted
inserted
replaced
7:d44784122203 | 8:8e909570e7de |
---|---|
353 def pr(self): | 353 def pr(self): |
354 print '-------------------------[%d]' % (self.idx) | 354 print '-------------------------[%d]' % (self.idx) |
355 print self | 355 print self |
356 | 356 |
357 class History(list): | 357 class History(list): |
358 digitsOnly = re.compile('^[\d]+$') | 358 rangeFrom = re.compile(r'^([\d])+\s*\-$') |
359 rangeTo = re.compile(r'^\-\s*([-d])+$') | |
360 def append(self, new): | 359 def append(self, new): |
361 new = HistoryItem(new) | 360 new = HistoryItem(new) |
362 list.append(self, new) | 361 list.append(self, new) |
363 new.idx = len(self) | 362 new.idx = len(self) |
364 def extend(self, new): | 363 def extend(self, new): |
365 for n in new: | 364 for n in new: |
366 self.append(n) | 365 self.append(n) |
367 def get(self, getme): | 366 def get(self, getme): |
368 getme = getme.strip() | 367 try: |
369 if not getme: | 368 getme = int(getme) |
369 if getme < 0: | |
370 return self[:(-1 * getme)] | |
371 else: | |
372 return self[getme-1] | |
373 except IndexError: | |
370 return [] | 374 return [] |
371 if self.digitsOnly.search(getme): | 375 except (ValueError, TypeError): |
372 try: | 376 getme = getme.strip() |
373 idx = int(getme) | 377 mtch = self.rangeFrom.search(getme) |
374 try: | 378 if mtch: |
375 return [self[idx-1]] | 379 return self[(int(mtch.group(1))-1):] |
376 except IndexError: | |
377 return [] | |
378 m = self.rangeTo.search(getme) | |
379 if m: | |
380 return self[int(:m.group(1))] | |
381 | |
382 excep | |
383 except ValueError: # search for a string | |
384 try: | |
385 getme = getme.strip() | |
386 except: | |
387 print "Don't know how to handle %s." % (str(getme)) | |
388 return | |
389 if getme.startswith(r'/') and getme.endswith(r'/'): | 380 if getme.startswith(r'/') and getme.endswith(r'/'): |
390 finder = re.compile(getme[1:-1], re.DOTALL | re.MULTILINE | re.IGNORECASE) | 381 finder = re.compile(getme[1:-1], re.DOTALL | re.MULTILINE | re.IGNORECASE) |
391 def isin(hi): | 382 def isin(hi): |
392 return finder.search(hi) | 383 return finder.search(hi) |
393 else: | 384 else: |