Back to index

plone3  3.1.7
Public Member Functions
Archetypes.ClassGen.Generator Class Reference

List of all members.

Public Member Functions

def computeMethodName
def makeMethod

Detailed Description

Definition at line 35 of file ClassGen.py.


Member Function Documentation

def Archetypes.ClassGen.Generator.computeMethodName (   self,
  field,
  mode 
)

Definition at line 36 of file ClassGen.py.

00036 
00037     def computeMethodName(self, field, mode):
00038         if mode not in _modes.keys():
00039             raise TypeError("Unsupported Mode %s in field: %s (%s)" % \
00040                             (field.getName(), mode))
00041 
00042         prefix = _modes[mode]['prefix']
00043         name   = capitalize(field.getName())
00044         return "%s%s" % (prefix, name)

Here is the call graph for this function:

def Archetypes.ClassGen.Generator.makeMethod (   self,
  klass,
  field,
  mode,
  methodName 
)

Definition at line 45 of file ClassGen.py.

00045 
00046     def makeMethod(self, klass, field, mode, methodName):
00047         name = field.getName()
00048         method = None
00049         if mode == "r":
00050             def generatedAccessor(self, **kw):
00051                 """Default Accessor."""
00052                 if kw.has_key('schema'):
00053                     schema = kw['schema']
00054                 else:
00055                     schema = self.Schema()
00056                     kw['schema'] = schema
00057                 return schema[name].get(self, **kw)
00058             method = generatedAccessor
00059         elif mode == "m":
00060             def generatedEditAccessor(self, **kw):
00061                 """Default Edit Accessor."""
00062                 if kw.has_key('schema'):
00063                     schema = kw['schema']
00064                 else:
00065                     schema = self.Schema()
00066                     kw['schema'] = schema
00067                 return schema[name].getRaw(self, **kw)
00068             method = generatedEditAccessor
00069         elif mode == "w":
00070             def generatedMutator(self, value, **kw):
00071                 """Default Mutator."""
00072                 if kw.has_key('schema'):
00073                     schema = kw['schema']
00074                 else:
00075                     schema = self.Schema()
00076                     kw['schema'] = schema
00077                 return schema[name].set(self, value, **kw)
00078             method = generatedMutator
00079         else:
00080             raise GeneratorError("""Unhandled mode for method creation:
00081             %s:%s -> %s:%s""" %(klass.__name__,
00082                                 name,
00083                                 methodName,
00084                                 mode))
00085 
00086         # Zope security requires all security protected methods to have a
00087         # function name. It uses this name to determine which roles are allowed
00088         # to access the method.
00089         # This code is renaming the internal name from e.g. generatedAccessor to
00090         # methodName.
00091         method = function(method.func_code,
00092                           method.func_globals,
00093                           methodName,
00094                           method.func_defaults,
00095                           method.func_closure,
00096                          )
00097         setattr(klass, methodName, method)

Here is the call graph for this function:


The documentation for this class was generated from the following file: