[Zope3-checkins] CVS: Zope3/lib/python/Zope/ContextWrapper - SimpleMethodWrapper.py:1.10 __init__.py:1.5
Steve Alexander
steve@cat-box.net
Tue, 3 Dec 2002 16:54:09 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/ContextWrapper
In directory cvs.zope.org:/tmp/cvs-serv5452
Modified Files:
SimpleMethodWrapper.py __init__.py
Log Message:
fixed stuff - now __getitem__ can be a ContextMethod without unwanted
side-effects.
=== Zope3/lib/python/Zope/ContextWrapper/SimpleMethodWrapper.py 1.9 => 1.10 ===
--- Zope3/lib/python/Zope/ContextWrapper/SimpleMethodWrapper.py:1.9 Tue Dec 3 15:07:11 2002
+++ Zope3/lib/python/Zope/ContextWrapper/SimpleMethodWrapper.py Tue Dec 3 16:54:08 2002
@@ -59,13 +59,22 @@
__Zope_ContextWrapper_contextful_set__ = True
def wrapperCreator(object, context=None, **data):
- if hasattr(object, '__call__'):
- if getattr(object.__call__,
- '__Zope_ContextWrapper_contextful_get__', 0):
- return SimpleCallableMethodWrapper(object, context, **data)
-
- return SimpleMethodWrapper(object, context, **data)
+ has_call = (hasattr(object, '__call__') and
+ getattr(object.__call__,
+ '__Zope_ContextWrapper_contextful_get__', 0))
+ has_getitem = (hasattr(object, '__getitem__') and
+ getattr(object.__getitem__,
+ '__Zope_ContextWrapper_contextful_get__', 0))
+ if has_call and has_getitem:
+ factory = SimpleCallableGetitemMethodWrapper
+ elif has_call:
+ factory = SimpleCallableMethodWrapper
+ elif has_getitem:
+ factory = SimpleGetitemMethodWrapper
+ else:
+ factory = SimpleMethodWrapper
+ return factory(object, context, **data)
class SimpleMethodWrapper(Wrapper):
@@ -81,8 +90,6 @@
return Wrapper.__getattribute__(self, name)
-
-
def __setattr__(self, name, value):
"""Support for ContextProperty.__set__"""
obj = getbaseobject(self)
@@ -101,3 +108,17 @@
def __call__(self, *args, **kw):
attr = Wrapper.__getattribute__(self, '__call__')
return attr.__get__(self)(*args, **kw)
+
+class SimpleGetitemMethodWrapper(SimpleMethodWrapper):
+
+ def __getitem__(self, key, *args, **kw):
+ attr = Wrapper.__getattribute__(self, '__getitem__')
+ return attr.__get__(self)(key, *args, **kw)
+
+class SimpleCallableGetitemMethodWrapper(SimpleCallableMethodWrapper,
+ SimpleGetitemMethodWrapper):
+ pass
+
+wrapperTypes = (SimpleMethodWrapper, SimpleCallableMethodWrapper,
+ SimpleGetitemMethodWrapper,
+ SimpleCallableGetitemMethodWrapper)
=== Zope3/lib/python/Zope/ContextWrapper/__init__.py 1.4 => 1.5 ===
--- Zope3/lib/python/Zope/ContextWrapper/__init__.py:1.4 Tue Dec 3 15:44:43 2002
+++ Zope3/lib/python/Zope/ContextWrapper/__init__.py Tue Dec 3 16:54:09 2002
@@ -26,7 +26,5 @@
from SimpleMethodWrapper import ContextMethod, ContextProperty
from SimpleMethodWrapper import ContextGetProperty, ContextSetProperty
-from SimpleMethodWrapper import \
- SimpleMethodWrapper, SimpleCallableMethodWrapper
-wrapperTypes = (SimpleMethodWrapper, SimpleCallableMethodWrapper)
-del SimpleMethodWrapper, SimpleCallableMethodWrapper
+from SimpleMethodWrapper import wrapperTypes
+