Commit 8430ae6c authored by Casey Duncan's avatar Casey Duncan

Remove unused import

Remove dependancy on PlugInIndexes product by using randint directly to generate rids. randint now works properly with negative number in Python 2.2
Fix bare except. Simplify python implementation of safe_callable
parent f5c1e8eb
...@@ -14,7 +14,6 @@ ...@@ -14,7 +14,6 @@
from Persistence import Persistent from Persistence import Persistent
import Acquisition import Acquisition
import ExtensionClass import ExtensionClass
from Products.PluginIndexes.TextIndex.Lexicon import Lexicon
from MultiMapping import MultiMapping from MultiMapping import MultiMapping
import Record import Record
from Missing import MV from Missing import MV
...@@ -26,25 +25,19 @@ from BTrees.IIBTree import intersection, weightedIntersection, IISet ...@@ -26,25 +25,19 @@ from BTrees.IIBTree import intersection, weightedIntersection, IISet
from BTrees.OIBTree import OIBTree from BTrees.OIBTree import OIBTree
from BTrees.IOBTree import IOBTree from BTrees.IOBTree import IOBTree
import BTrees.Length import BTrees.Length
from Products.PluginIndexes.common.randid import randid
import time, sys, types import time, sys, types
from bisect import bisect from bisect import bisect
from random import randint
# Collector #771: provide a safe_callable() method with a
# fallback (when ZCatalog might be used outside Zope)
try: try:
from DocumentTemplate.cDocumentTemplate import safe_callable from DocumentTemplate.cDocumentTemplate import safe_callable
except: except ImportError:
# Fallback to python implementation to avoid dependancy on DocumentTemplate
def safe_callable(ob): def safe_callable(ob):
# Works with ExtensionClasses and Acquisition. # Works with ExtensionClasses and Acquisition.
if hasattr(ob, '__class__'): if hasattr(ob, '__class__'):
if hasattr(ob, '__call__'): return hasattr(ob, '__call__') or isinstance(ob, types.ClassType)
return 1
else:
return isinstance(ob, types.ClassType)
else: else:
return callable(ob) return callable(ob)
...@@ -324,12 +317,13 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base): ...@@ -324,12 +317,13 @@ class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
# new data # new data
if type(data) is IOBTree: if type(data) is IOBTree:
# New style, get radom id # New style, get random id
index=getattr(self, '_v_nextid', 0) index=getattr(self, '_v_nextid', 0)
if index%4000 == 0: index = randid() if index % 4000 == 0:
index = randint(-2000000000, 2000000000)
while not data.insert(index, newDataRecord): while not data.insert(index, newDataRecord):
index=randid() index = randint(-2000000000, 2000000000)
# We want ids to be somewhat random, but there are # We want ids to be somewhat random, but there are
# advantages for having some ids generated # advantages for having some ids generated
......
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