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

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


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

Modified Files:
      Tag: Zope-2_5-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.81.16.2 => 1.81.16.3 ===
--- Zope/lib/python/Products/ZCatalog/Catalog.py:1.81.16.2	Fri Jan 17 12:06:56 2003
+++ Zope/lib/python/Products/ZCatalog/Catalog.py	Sun Jan 19 06:08:37 2003
@@ -23,7 +23,6 @@
 
 from Lazy import LazyMap, LazyFilter, LazyCat
 from CatalogBrains import AbstractCatalogBrain, NoBrainer
-from DocumentTemplate import cDocumentTemplate
 from BTrees.IIBTree import intersection, weightedIntersection
 from BTrees.OIBTree import OIBTree
 from BTrees.IOBTree import IOBTree
@@ -32,6 +31,24 @@
 
 import time
 from cgi import escape
+
+# 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