Commit 0746dfea authored by Jim Fulton's avatar Jim Fulton

Replaced try/except with get

parent 61881ebe
...@@ -10,8 +10,8 @@ ...@@ -10,8 +10,8 @@
__doc__='''Simple column indexes __doc__='''Simple column indexes
$Id: Index.py,v 1.12 1997/12/02 19:34:39 jeffrey Exp $''' $Id: Index.py,v 1.13 1998/02/05 19:02:37 jim Exp $'''
__version__='$Revision: 1.12 $'[11:-2] __version__='$Revision: 1.13 $'[11:-2]
from BTree import BTree from BTree import BTree
from intSet import intSet from intSet import intSet
...@@ -51,6 +51,7 @@ class Index: ...@@ -51,6 +51,7 @@ class Index:
"""Recompute index data for data with ids >= start.""" """Recompute index data for data with ids >= start."""
index=self._index index=self._index
get=index.get
if not start: index.clear() if not start: index.clear()
...@@ -66,10 +67,8 @@ class Index: ...@@ -66,10 +67,8 @@ class Index:
if k is None or k == MV: continue if k is None or k == MV: continue
try: set=index[k] set=get(k)
except KeyError: if set is None: index[k]=set=intSet()
set=intSet()
index[k]=set
set.insert(i) set.insert(i)
def index_item(self,i): def index_item(self,i):
...@@ -89,10 +88,8 @@ class Index: ...@@ -89,10 +88,8 @@ class Index:
if k is None or k == MV: return if k is None or k == MV: return
try: set=index[k] set=index.get(k)
except KeyError: if set is None: index[k]=set=intSet()
set=intSet()
index[k]=set
set.insert(i) set.insert(i)
def unindex_item(self,i): def unindex_item(self,i):
...@@ -109,10 +106,9 @@ class Index: ...@@ -109,10 +106,9 @@ class Index:
row=self._data[i] row=self._data[i]
k=f(row,id) k=f(row,id)
try:
set=index[k] set=index.get(k)
set.remove(i) if set is not None: set.remove(i)
except KeyError: pass
def _apply_index(self, request, cid=''): def _apply_index(self, request, cid=''):
"""Apply the index to query parameters given in the argument, request """Apply the index to query parameters given in the argument, request
...@@ -134,10 +130,11 @@ class Index: ...@@ -134,10 +130,11 @@ class Index:
""" """
id=self.id #name of the column id=self.id #name of the column
try: keys=request["%s/%s" % (cid,id)] cidid="%s/%s" % (cid,id)
except: has_key=request.has_key
try: keys=request[id] if has_key(cidid): keys=request[cidid]
except: return None elif has_key(id): keys=request[id]
else: return None
if type(keys) is not ListType: keys=[keys] if type(keys) is not ListType: keys=[keys]
index=self._index index=self._index
...@@ -148,10 +145,7 @@ class Index: ...@@ -148,10 +145,7 @@ class Index:
if request.has_key(id+'_usage'): if request.has_key(id+'_usage'):
# see if any usage params are sent to field # see if any usage params are sent to field
opr=string.split(string.lower(request[id+"_usage"]),':') opr=string.split(string.lower(request[id+"_usage"]),':')
try:
opr, opr_args=opr[0], opr[1:] opr, opr_args=opr[0], opr[1:]
except IndexError:
opr, opr_args=opr[0], []
if opr=="range": if opr=="range":
if 'min' in opr_args: lo=min(keys) if 'min' in opr_args: lo=min(keys)
...@@ -168,13 +162,13 @@ class Index: ...@@ -168,13 +162,13 @@ class Index:
else: r=r.union(set) else: r=r.union(set)
except KeyError: pass except KeyError: pass
else: #not a range else: #not a range
get=index.get
for key in keys: for key in keys:
if key: anyTrue=1 if key: anyTrue=1
try: set=get(key)
set=index[key] if set is not None:
if r is None: r=set if r is None: r=set
else: r = r.union(set) else: r = r.union(set)
except KeyError: pass
if r is None: if r is None:
if anyTrue: r=intSet() if anyTrue: r=intSet()
...@@ -186,6 +180,9 @@ class Index: ...@@ -186,6 +180,9 @@ class Index:
############################################################################## ##############################################################################
# #
# $Log: Index.py,v $ # $Log: Index.py,v $
# Revision 1.13 1998/02/05 19:02:37 jim
# Replaced try/except with get
#
# Revision 1.12 1997/12/02 19:34:39 jeffrey # Revision 1.12 1997/12/02 19:34:39 jeffrey
# fixed buglet in .clear() method # fixed buglet in .clear() method
# #
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment