def __init__(self, *args, **kwargs): """ Initialize a Schema. The first positional argument may be a sequence of Fields. (All further positional arguments are ignored.) Keyword arguments are added to my properties. """ Schemata.__init__(self) self._props = self._properties.copy() self._props.update(kwargs) if len(args): if type(args[0]) in [ListType, TupleType]: for field in args[0]: self.addField(field) else: msg = ( "You are passing positional arguments " "to the Schema constructor. " "Please consult the docstring " "for %s.BasicSchema.__init__" % (self.__class__.__module__,) ) level = 3 if self.__class__ is not BasicSchema: level = 4 warn(msg, level=level) for field in args: self.addField(args[0])
def updateSecurity(self, klass, field, mode, methodName): security = _getSecurity(klass) perm = _modes[mode]['security'] perm = getattr(field, perm, None) method__roles__ = getattr(klass, '%s__roles__' % methodName, 0) # Check copied from SecurityInfo to avoid stomping over # existing permissions. if security.names.get(methodName, perm) != perm: warn('The method \'%s\' was already protected by a ' 'different permission than the one declared ' 'on the field. Assuming that the explicit ' 'permission declared is the correct one and ' 'has preference over the permission declared ' 'on the field.' % methodName) elif method__roles__ is None: security.declarePublic(methodName) elif method__roles__ == (): security.declarePrivate(methodName) else: security.declareProtected(perm, methodName)