[Zope3-checkins] CVS: Zope3/src/zope/app/location - __init__.py:1.7

Jim Fulton jim at zope.com
Mon Apr 5 15:44:10 EDT 2004


Update of /cvs-repository/Zope3/src/zope/app/location
In directory cvs.zope.org:/tmp/cvs-serv13504/src/zope/app/location

Modified Files:
	__init__.py 
Log Message:
Make sure proxies give out the proxied object's __doc__.


=== Zope3/src/zope/app/location/__init__.py 1.6 => 1.7 ===
--- Zope3/src/zope/app/location/__init__.py:1.6	Sat Mar 20 08:37:01 2004
+++ Zope3/src/zope/app/location/__init__.py	Mon Apr  5 15:44:07 2004
@@ -447,9 +447,18 @@
         root = LocationPhysicallyLocatable(self.location).getRoot()
         return ITraverser(root).traverse(path[1:])
 
+class ClassAndInstanceDescr(object):
+
+    def __init__(self, *args):
+        self.funcs = args
+
+    def __get__(self, inst, cls):
+        if inst is None:
+            return self.funcs[1](cls)
+        return self.funcs[0](inst)
 
 class LocationProxy(ProxyBase):
-    """Contained-object proxy
+    __doc__ = """Location-object proxy
 
     This is a non-picklable proxy that can be put around objects that
     don't implement ILocation.
@@ -469,6 +478,10 @@
     ...
     TypeError: Not picklable
 
+    Proxies should get their doc strings from the object they proxy:
+
+    >>> p.__doc__ == l.__doc__
+    True
 
     """
 
@@ -488,6 +501,12 @@
     def __reduce__(self, proto=None):
         raise TypeError, "Not picklable"
 
+
+    __doc__ = ClassAndInstanceDescr(
+        lambda inst: getProxiedObject(inst).__doc__,
+        lambda cls, __doc__ = __doc__: __doc__,
+        )
+    
     __reduce_ex__ = __reduce__
 
     __providedBy__ = DecoratorSpecificationDescriptor()




More information about the Zope3-Checkins mailing list