From 1b76e57ec57494d8398f89892537b965ce7d0c91 Mon Sep 17 00:00:00 2001
From: Mayoro Diagne <mayoro@nexedi.com>
Date: Sat, 28 Jun 2008 19:07:07 +0000
Subject: [PATCH] using getattr to get co_varnames; using unrestrictedTraverse
 instead of resolveCtagegory to avoid warning in case of unexisting category

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@22052 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 .../AccessorMethodDocumentationHelper.py      | 54 ++++++++++---------
 ...DCWorkflowPermissionDocumentationHelper.py |  4 +-
 .../DocumentationHelper.py                    | 17 +++---
 ...talTypePropertySheetDocumentationHelper.py |  2 +-
 4 files changed, 38 insertions(+), 39 deletions(-)

diff --git a/product/ERP5Type/DocumentationHelper/AccessorMethodDocumentationHelper.py b/product/ERP5Type/DocumentationHelper/AccessorMethodDocumentationHelper.py
index 0e1f832574..fdf96543dc 100644
--- a/product/ERP5Type/DocumentationHelper/AccessorMethodDocumentationHelper.py
+++ b/product/ERP5Type/DocumentationHelper/AccessorMethodDocumentationHelper.py
@@ -34,36 +34,38 @@ from Products.ERP5Type import Permissions
 
 #return the definition string of an object representing a workflow method or a class method or an accessor
 def getDefinitionString(obj=None):
-  if obj == None:
+  if obj is None:
     return ""
+  func_code = getattr(obj, "func_code", None)
+  if func_code is None:
+    return ""
+  fc_var_names = getattr(func_code, "co_varnames", [])
+  fc = []
+  for i in range(len(fc_var_names)):
+    if fc_var_names[i] == 'args':
+      fc.append('*args')
+    elif fc_var_names[i] == 'kw':
+      fc.append('**kw')
+    else:
+      fc.append(fc_var_names[i])
+  fd = obj.func_defaults
+  acc_def = obj.__name__ + ' ('
+  if fd == None:
+    acc_def += ', '.join(fc)
   else:
-    fc_var_names = obj.func_code.co_varnames
-    fc = []
-    for i in range(len(fc_var_names)):
-      if fc_var_names[i] == 'args':
-        fc.append('*args')
-      elif fc_var_names[i] == 'kw':
-        fc.append('**kw')
+    for x in range(len(fc)):
+      if (len(fc)-(x+1)<len(fd)):
+        if (x == len(fc)-1):
+          acc_def += " "+str(fc[x])+"='"+str(fd[x-len(fd)])+"'"
+        else:
+          acc_def += " "+str(fc[x])+"='"+str(fd[x-len(fd)])+"',"
       else:
-        fc.append(fc_var_names[i])
-    fd = obj.func_defaults
-    acc_def = obj.__name__ + ' ('
-    if fd == None:
-      acc_def += ', '.join(fc)
-    else:
-      for x in range(len(fc)):
-        if (len(fc)-(x+1)<len(fd)):
-          if (x == len(fc)-1):
-            acc_def += " "+str(fc[x])+"='"+str(fd[x-len(fd)])+"'"
-          else:
-            acc_def += " "+str(fc[x])+"='"+str(fd[x-len(fd)])+"',"
+        if (x == len(fc)-1):
+          acc_def += " "+str(fc[x])
         else:
-          if (x == len(fc)-1):
-            acc_def += " "+str(fc[x])
-          else:
-            acc_def += " "+str(fc[x])+","
-    acc_def += ")"
-    return acc_def
+          acc_def += " "+str(fc[x])+","
+  acc_def += ")"
+  return acc_def
 
 
 class AccessorMethodDocumentationHelper(DocumentationHelper):
diff --git a/product/ERP5Type/DocumentationHelper/DCWorkflowPermissionDocumentationHelper.py b/product/ERP5Type/DocumentationHelper/DCWorkflowPermissionDocumentationHelper.py
index c81c3001a4..eb0408023b 100644
--- a/product/ERP5Type/DocumentationHelper/DCWorkflowPermissionDocumentationHelper.py
+++ b/product/ERP5Type/DocumentationHelper/DCWorkflowPermissionDocumentationHelper.py
@@ -31,6 +31,7 @@ from AccessControl import ClassSecurityInfo
 from Globals import InitializeClass
 from DocumentationHelper import DocumentationHelper
 from Products.ERP5Type import Permissions
+from zLOG import LOG, INFO
 
 class DCWorkflowPermissionDocumentationHelper(DocumentationHelper):
   """
@@ -44,7 +45,8 @@ class DCWorkflowPermissionDocumentationHelper(DocumentationHelper):
 
   security.declareProtected(Permissions.AccessContentsInformation, 'getDescription')
   def getDescription(self):
-    return getattr(self.getDocumentedObject(), "description", "")
+    #return  getattr(self.getDocumentedObject(), "description", "")
+    return ""
 
   security.declareProtected(Permissions.AccessContentsInformation, 'getType' )
   def getType(self):
diff --git a/product/ERP5Type/DocumentationHelper/DocumentationHelper.py b/product/ERP5Type/DocumentationHelper/DocumentationHelper.py
index 4a7f46aa96..58c7abc000 100644
--- a/product/ERP5Type/DocumentationHelper/DocumentationHelper.py
+++ b/product/ERP5Type/DocumentationHelper/DocumentationHelper.py
@@ -103,8 +103,6 @@ class DocumentationHelper(Implicit):
     if self.uri.startswith('portal_classes/temp_instance'):
       url, method = self.uri.split('#')
       portal_type = url.split('/')[-1]
-      #temp_folder = self.getPortalObject().portal_classes.newContent(id='temp_instance', portal_type='Folder', temp_object=1)
-      #temp_object = temp_folder.newContent(id=portal_type, portal_type=portal_type, temp_object=1)
       self.getTempInstance = TempObjectLibrary(self.getPortalObject().portal_classes)
       temp_object = self.getTempInstance(portal_type)
       if '/' not in method:
@@ -131,17 +129,14 @@ class DocumentationHelper(Implicit):
     elif '/' in self.uri and '#' not in self.uri:
       # URI refers to a portal object
       # and is a relative URL
-      try:
-        documented_object = self.getPortalObject().portal_categories.resolveCategory(self.uri)
-      except:
-        documented_object = None
+      documented_object = self.getPortalObject().portal_categories.unrestrictedTraverse(self.uri, None)
       if documented_object is None:
-        documented_object = self.getPortalObject().unrestrictedTraverse(self.uri)
+        documented_object = self.getPortalObject().unrestrictedTraverse(self.uri, None)
     elif '/' in self.uri and '#' in self.uri:
       if '?' in self.uri:
         base_url, url = self.uri.split('?')
         type, name = url.split('#')
-        parent_object = self.getPortalObject().unrestrictedTraverse(base_url)
+        parent_object = self.getPortalObject().unrestrictedTraverse(base_url, None)
         object_list = getattr(parent_object, type, None)
         documented_object = None
         if object_list is not None:
@@ -150,9 +145,9 @@ class DocumentationHelper(Implicit):
               documented_object = obj
       else:
         url, method = self.uri.split('#')
-        documented_object = self.getPortalObject().unrestrictedTraverse(url)
+        documented_object = self.getPortalObject().unrestrictedTraverse(url, None)
         if '/' not in method:
-          documented_object = self.getPortalObject().unrestrictedTraverse(url)
+          documented_object = self.getPortalObject().unrestrictedTraverse(url, None)
           documented_object = getattr(documented_object, method, None)
         else:
           path_method = method.split('/')
@@ -169,7 +164,7 @@ class DocumentationHelper(Implicit):
         import Products
         documented_object = Products
         for key in module_list[1:]:
-          documented_object = getattr(documented_object, key)
+          documented_object = getattr(documented_object, key, None)
       else:
         raise NotImplemented
         #fp, pathname, description = imp.find_module(base_module)
diff --git a/product/ERP5Type/DocumentationHelper/PortalTypePropertySheetDocumentationHelper.py b/product/ERP5Type/DocumentationHelper/PortalTypePropertySheetDocumentationHelper.py
index 277ed240cf..9f4cf90610 100644
--- a/product/ERP5Type/DocumentationHelper/PortalTypePropertySheetDocumentationHelper.py
+++ b/product/ERP5Type/DocumentationHelper/PortalTypePropertySheetDocumentationHelper.py
@@ -62,7 +62,7 @@ class PortalTypePropertySheetDocumentationHelper(DocumentationHelper):
     """
     Returns the title of the documentation helper
     """
-    return getattr(self.etDocumentedObject(), "name", '')
+    return getattr(self.getDocumentedObject(), "name", '')
 
   security.declareProtected( Permissions.AccessContentsInformation, 'getSourceCode' )
   def getSourceCode(self):
-- 
2.30.9