Back to index

plone3  3.1.7
Functions | Variables
GroupUserFolder.class_utility Namespace Reference

Functions

def showaq
def listBaseMetaTypes
def isBaseMetaType
def _populateBaseMetaTypes
def objectIds
def objectValues
def objectItems
def listBaseClasses
def isBaseClass
def _populateBaseClasses

Variables

string __version__ = "$Revision: $"
 GroupUserFolder Copyright (C)2006 Ingeniweb.
string __docformat__ = 'restructuredtext'
tuple _BASECLASSESLOCK = threading.RLock()
dictionary _BASECLASSES = {}
tuple _BASEMETALOCK = threading.RLock()
dictionary _BASEMETA = {}

Function Documentation

Fill the base classes structure

Definition at line 179 of file class_utility.py.

00179 
00180 def _populateBaseClasses(cl):
00181     """Fill the base classes structure"""
00182     # Fill the base classes list
00183     ret = [cl]
00184     for b in cl.__bases__:
00185         ret = list(listBaseClasses(b, 1)) + ret
00186 
00187     # Fill the base classes dict
00188     bases = {}
00189     for b in ret:
00190         bases[b] = 1
00191 
00192     _BASECLASSESLOCK.acquire()
00193     try:
00194         rev = ret[:]
00195         rev.reverse()
00196         _BASECLASSES[cl] = (tuple(rev), tuple(ret), bases)
00197     finally:
00198         _BASECLASSESLOCK.release()

Here is the call graph for this function:

Here is the caller graph for this function:

Fill the base classes structure

Definition at line 84 of file class_utility.py.

00084 
00085 def _populateBaseMetaTypes(cl):
00086     """Fill the base classes structure"""
00087     # Fill the base classes list
00088     try:
00089         ret = [cl.meta_type]
00090     except AttributeError:
00091         ret = []
00092 
00093     for b in cl.__bases__:
00094         ret = list(listBaseMetaTypes(b, 1)) + ret
00095 
00096     # Fill the base classes dict
00097     bases = {}
00098     for b in ret:
00099         bases[b] = 1
00100 
00101     _BASEMETALOCK.acquire()
00102     try:
00103         rev = ret[:]
00104         rev.reverse()
00105         _BASEMETA[cl] = (tuple(rev), tuple(ret), bases)
00106     finally:
00107         _BASEMETALOCK.release()

Here is the call graph for this function:

Here is the caller graph for this function:

isBaseClass(base, cl) => Boolean
Return true if base is a base class of cl

Definition at line 167 of file class_utility.py.

00167 
00168 def isBaseClass(base, cl):
00169     """
00170     isBaseClass(base, cl) => Boolean
00171     Return true if base is a base class of cl
00172     """
00173     try:
00174         return _BASECLASSES[cl][2].has_key(base)
00175     except:
00176         _populateBaseClasses(cl)
00177         return isBaseClass(base, cl)
00178 

Here is the call graph for this function:

Definition at line 76 of file class_utility.py.

00076 
00077 def isBaseMetaType(meta, cl):
00078     try:
00079         return _BASEMETA[cl][2].has_key(meta)
00080 
00081     except KeyError:
00082         _populateBaseMetaTypes(cl)
00083         return isBaseMetaType(meta, cl)

Here is the call graph for this function:

Here is the caller graph for this function:

def GroupUserFolder.class_utility.listBaseClasses (   cl,
  reverse = 0 
)
listBaseClasses(cl, reverse = 0) => list of classes

List all the base classes of an object.
When reverse is 0, return the self class first.
When reverse is 1, return the self class last.

WARNING : reverse is 0 or 1, it is an integer, NOT A BOOLEAN ! (optim issue)

CACHE RESULTS

WARNING : for optimization issues, the ORIGINAL tuple is returned : please do not change it !

Definition at line 144 of file class_utility.py.

00144 
00145 def listBaseClasses(cl, reverse = 0):
00146     """
00147     listBaseClasses(cl, reverse = 0) => list of classes
00148 
00149     List all the base classes of an object.
00150     When reverse is 0, return the self class first.
00151     When reverse is 1, return the self class last.
00152 
00153     WARNING : reverse is 0 or 1, it is an integer, NOT A BOOLEAN ! (optim issue)
00154 
00155     CACHE RESULTS
00156 
00157     WARNING : for optimization issues, the ORIGINAL tuple is returned : please do not change it !
00158     """
00159     # Look for the class in _BASECLASSES cache
00160     try:
00161         return _BASECLASSES[cl][reverse]
00162 
00163     except:
00164         _populateBaseClasses(cl)
00165         return listBaseClasses(cl, reverse)
00166 

Here is the call graph for this function:

Here is the caller graph for this function:

def GroupUserFolder.class_utility.listBaseMetaTypes (   cl,
  reverse = 0 
)
listBaseMetaTypes(cl, reverse = 0) => list of strings

List all base meta types for this class.

Definition at line 62 of file class_utility.py.

00062 
00063 def listBaseMetaTypes(cl, reverse = 0):
00064     """
00065     listBaseMetaTypes(cl, reverse = 0) => list of strings
00066 
00067     List all base meta types for this class.
00068     """
00069     # Look for the class in _BASEMETA cache
00070     try:
00071         return _BASEMETA[cl][reverse]
00072 
00073     except KeyError:
00074         _populateBaseMetaTypes(cl)
00075         return listBaseMetaTypes(cl, reverse)

Here is the call graph for this function:

Here is the caller graph for this function:

def GroupUserFolder.class_utility.objectIds (   container,
  meta_types = [] 
)

Definition at line 108 of file class_utility.py.

00108 
00109 def objectIds(container, meta_types = []):
00110     """
00111     """
00112     return map(lambda x: x[0], objectItems(container, meta_types))

Here is the call graph for this function:

Here is the caller graph for this function:

def GroupUserFolder.class_utility.objectItems (   container,
  meta_types = [] 
)
objectItems(container, meta_types = [])
Same as a container's objectItem method, meta_types are scanned in the base classes too.
Ie. all objects derivated from Folder will be returned by objectItem(x, ['Folder'])

Definition at line 118 of file class_utility.py.

00118 
00119 def objectItems(container, meta_types = []):
00120     """
00121     objectItems(container, meta_types = [])
00122     Same as a container's objectItem method, meta_types are scanned in the base classes too.
00123     Ie. all objects derivated from Folder will be returned by objectItem(x, ['Folder'])
00124     """
00125     # Convert input type
00126     if type(meta_types) not in (type(()), type([])):
00127         meta_types = [meta_types]
00128 
00129     # Special case where meta_types is empty
00130     if not meta_types:
00131         return container.objectItems()
00132 
00133     # Otherwise : check parent for each meta_type
00134     ret = []
00135     for (id, obj) in container.objectItems():
00136         for mt in meta_types:
00137             if isBaseMetaType(mt, obj.__class__):
00138                 ret.append((id, obj))
00139                 break
00140 
00141     return ret
00142 
00143 

Here is the call graph for this function:

Here is the caller graph for this function:

def GroupUserFolder.class_utility.objectValues (   container,
  meta_types = [] 
)

Definition at line 113 of file class_utility.py.

00113 
00114 def objectValues(container, meta_types = []):
00115     """
00116     """
00117     return map(lambda x: x[1], objectItems(container, meta_types))

Here is the call graph for this function:

Here is the caller graph for this function:

def GroupUserFolder.class_utility.showaq (   self,
  indent = '' 
)

Definition at line 37 of file class_utility.py.

00037 
00038 def showaq(self, indent=''):
00039     "showaq"
00040     rval = ""
00041     obj = self
00042     base = getattr(obj, 'aq_base', obj)
00043     try: id = base.id
00044     except: id = str(base)
00045     try: id = id()
00046     except: pass
00047 
00048     if hasattr(obj, 'aq_self'):
00049         if hasattr(obj.aq_self, 'aq_self'):
00050             rval = rval + indent + "(" + id + ")\n"
00051             rval = rval + indent + "|  \\\n"
00052             rval = rval + showaq(obj.aq_self, '|   ' + indent)
00053             rval = rval + indent + "|\n"
00054         if hasattr(obj, 'aq_parent'):
00055             rval = rval + indent + id + "\n"
00056             rval = rval + indent + "|\n"
00057             rval = rval + showaq(obj.aq_parent, indent)
00058     else:
00059         rval = rval + indent + id + "\n"
00060     return rval
00061 


Variable Documentation

string GroupUserFolder.class_utility.__docformat__ = 'restructuredtext'

Definition at line 24 of file class_utility.py.

GroupUserFolder Copyright (C)2006 Ingeniweb.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Definition at line 21 of file class_utility.py.

Definition at line 33 of file class_utility.py.

Definition at line 32 of file class_utility.py.

Definition at line 35 of file class_utility.py.

Definition at line 34 of file class_utility.py.