[Erp5-report] r19517 - /erp5/trunk/products/ERP5Type/ExtensibleTraversable.py

nobody at svn.erp5.org nobody at svn.erp5.org
Tue Feb 26 15:35:22 CET 2008


Author: jp
Date: Tue Feb 26 15:35:19 2008
New Revision: 19517

URL: http://svn.erp5.org?rev=19517&view=rev
Log:
A class which provides an easy way to extend __bobo_traverse__

Added:
    erp5/trunk/products/ERP5Type/ExtensibleTraversable.py

Added: erp5/trunk/products/ERP5Type/ExtensibleTraversable.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5Type/ExtensibleTraversable.py?rev=19517&view=auto
==============================================================================
--- erp5/trunk/products/ERP5Type/ExtensibleTraversable.py (added)
+++ erp5/trunk/products/ERP5Type/ExtensibleTraversable.py Tue Feb 26 15:35:19 2008
@@ -1,0 +1,55 @@
+##############################################################################
+#
+# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
+# Copyright (c) 2008 Nexedi SA and Contributors. All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+# WARNING: This program as such is intended to be used by professional
+# programmers who take the whole responsability of assessing all potential
+# consequences resulting from its eventual inadequacies and bugs
+# End users who are looking for a ready-to-use solution with commercial
+# garantees and support are strongly adviced to contract a Free Software
+# Service Company
+#
+##############################################################################
+
+from Acquisition import aq_base
+
+class ExtensibleTraversableMixIn:
+
+    def __bobo_traverse__(self, request, name):
+      """
+        If no subobject is found through Folder API
+        then try to lookup the object by invoking getDocumentValue
+      """
+      # Normal traversal
+      try:
+        return getattr(self, name)
+      except AttributeError:
+        pass
+
+      try:
+        return self[name]
+      except KeyError:
+        pass
+
+      document = self._getExtensibleContent(request, name)
+      if document is not None:
+        return aq_base(document).__of__(self)
+
+      # Not found section
+      method = request.get('REQUEST_METHOD', 'GET')
+      if not method in ('GET', 'POST'):
+        return NullResource(self, name, request).__of__(self)
+      # Waaa. unrestrictedTraverse calls us with a fake REQUEST.
+      # There is proabably a better fix for this.
+      try:
+        request.RESPONSE.notFoundError("%s\n%s" % (name, method))
+      except AttributeError:
+        raise KeyError, name




More information about the Erp5-report mailing list