[Zope-Checkins] CVS: Zope/lib/python/Products/ZCatalog - Catalog.py:1.98.6.6

Andreas Jung andreas@andreas-jung.com
Sun, 19 Jan 2003 06:09:16 -0500


Update of /cvs-repository/Zope/lib/python/Products/ZCatalog
In directory cvs.zope.org:/tmp/cvs-serv29123/lib/python/Products/ZCatalog

Modified Files:
      Tag: Zope-2_6-branch
	Catalog.py 
Log Message:
providing a fallback for safe_callable() when ZCatalog is used outside Zope

=== Zope/lib/python/Products/ZCatalog/Catalog.py 1.98.6.5 => 1.98.6.6 ===
--- Zope/lib/python/Products/ZCatalog/Catalog.py:1.98.6.5	Fri Jan 17 11:59:26 2003
+++ Zope/lib/python/Products/ZCatalog/Catalog.py	Sun Jan 19 06:09:12 2003
@@ -22,7 +22,6 @@
 
 from Lazy import LazyMap, LazyFilter, LazyCat, LazyValues
 from CatalogBrains import AbstractCatalogBrain, NoBrainer
-from DocumentTemplate import cDocumentTemplate
 from BTrees.IIBTree import intersection, weightedIntersection, IISet
 from BTrees.OIBTree import OIBTree
 from BTrees.IOBTree import IOBTree
@@ -31,6 +30,24 @@
 
 import time, sys, types
 from bisect import bisect
+
+# Collector #771: provide a safe_callable() method with a
+# fallback (when ZCatalog might be used outside Zope)
+
+try:
+    from DocumentTemplate.cDocumentTemplate import safe_callable
+except:
+
+    def safe_callable(ob):
+        # Works with ExtensionClasses and Acquisition.
+        if hasattr(ob, '__class__'):
+            if hasattr(ob, '__call__'):
+                return 1
+            else:
+                return type(ob) in ClassTypes
+        else:
+            return callable(ob)
+
 
 class Catalog(Persistent, Acquisition.Implicit, ExtensionClass.Base):
     """ An Object Catalog