Back to index

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

List of all members.

Public Member Functions

def updateSecurity
def generateName
def checkSchema
def generateClass
def generateMethods
def handle_mode

Detailed Description

Definition at line 98 of file ClassGen.py.


Member Function Documentation

Definition at line 125 of file ClassGen.py.

00125 
00126     def checkSchema(self, klass):
00127         # backward compatibility, should be removed later on
00128         if klass.__dict__.has_key('type') and \
00129            not klass.__dict__.has_key('schema'):
00130             deprecated('Class %s has type attribute, should be schema' % \
00131                        klass.__name__, level = 4)
00132             klass.schema = klass.type

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 133 of file ClassGen.py.

00133 
00134     def generateClass(self, klass):
00135         # We are going to assert a few things about the class here
00136         # before we start, set meta_type, portal_type based on class
00137         # name, but only if they are not set yet
00138         if (not getattr(klass, 'meta_type', None) or
00139             'meta_type' not in klass.__dict__.keys()):
00140             klass.meta_type = klass.__name__
00141         if (not getattr(klass, 'portal_type', None) or
00142             'portal_type' not in klass.__dict__.keys()):
00143             klass.portal_type = klass.__name__
00144         klass.archetype_name = getattr(klass, 'archetype_name',
00145                                        self.generateName(klass))
00146 
00147         self.checkSchema(klass)
00148         fields = klass.schema.fields()
00149         self.generateMethods(klass, fields)

Here is the call graph for this function:

def Archetypes.ClassGen.ClassGenerator.generateMethods (   self,
  klass,
  fields 
)

Definition at line 150 of file ClassGen.py.

00150 
00151     def generateMethods(self, klass, fields):
00152         generator = Generator()
00153         for field in fields:
00154             assert not 'm' in field.mode, 'm is an implicit mode'
00155 
00156             # Make sure we want to muck with the class for this field
00157             if "c" not in field.generateMode: continue
00158             type = getattr(klass, 'type')
00159             for mode in field.mode: #(r, w)
00160                 self.handle_mode(klass, generator, type, field, mode)
00161                 if mode == 'w':
00162                     self.handle_mode(klass, generator, type, field, 'm')
00163 
00164         InitializeClass(klass)

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 122 of file ClassGen.py.

00122 
00123     def generateName(self, klass):
00124         return re.sub('([a-z])([A-Z])', '\g<1> \g<2>', klass.__name__)

Here is the caller graph for this function:

def Archetypes.ClassGen.ClassGenerator.handle_mode (   self,
  klass,
  generator,
  type,
  field,
  mode 
)

Definition at line 165 of file ClassGen.py.

00165 
00166     def handle_mode(self, klass, generator, type, field, mode):
00167         attr = _modes[mode]['attr']
00168         # Did the field request a specific method name?
00169         methodName = getattr(field, attr, None)
00170         if not methodName:
00171             methodName = generator.computeMethodName(field, mode)
00172 
00173         # Avoid name space conflicts
00174         if not hasattr(klass, methodName) \
00175                or getattr(klass, methodName) is AT_GENERATE_METHOD:
00176             if type.has_key(methodName):
00177                 raise GeneratorError("There is a conflict"
00178                                      "between the Field(%s) and the attempt"
00179                                      "to generate a method of the same name on"
00180                                      "class %s" % (
00181                     methodName,
00182                     klass.__name__))
00183 
00184 
00185             # Make a method for this klass/field/mode
00186             generator.makeMethod(klass, field, mode, methodName)
00187 
00188         # Update security regardless of the method being generated or
00189         # not. Not protecting the method by the permission defined on
00190         # the field may leave security open and lead to misleading
00191         # bugs.
00192         self.updateSecurity(klass, field, mode, methodName)
00193 
00194         # Note on the class what we did (even if the method existed)
00195         attr = _modes[mode]['attr']
00196         setattr(field, attr, methodName)

Here is the call graph for this function:

Here is the caller graph for this function:

def Archetypes.ClassGen.ClassGenerator.updateSecurity (   self,
  klass,
  field,
  mode,
  methodName 
)

Definition at line 99 of file ClassGen.py.

00099 
00100     def updateSecurity(self, klass, field, mode, methodName):
00101         security = _getSecurity(klass)
00102 
00103         perm = _modes[mode]['security']
00104         perm = getattr(field, perm, None)
00105         method__roles__ = getattr(klass, '%s__roles__' % methodName, 0)
00106 
00107         # Check copied from SecurityInfo to avoid stomping over
00108         # existing permissions.
00109         if security.names.get(methodName, perm) != perm:
00110             warn('The method \'%s\' was already protected by a '
00111                  'different permission than the one declared '
00112                  'on the field. Assuming that the explicit '
00113                  'permission declared is the correct one and '
00114                  'has preference over the permission declared '
00115                  'on the field.' % methodName)
00116         elif method__roles__ is None:
00117             security.declarePublic(methodName)
00118         elif method__roles__ == ():
00119             security.declarePrivate(methodName)
00120         else:
00121             security.declareProtected(perm, methodName)

Here is the call graph for this function:

Here is the caller graph for this function:


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