0

Does declarePrivate() et. al. Zope 2 style access control declarations have any modern Python syntax method decorator?

E.g.

class EncryptedField(StringField):
    """
    """
    security = ClassSecurityInfo()

    # Something more nice here? like @private?
    security.declarePrivate('get')

    def get(self, instance, **kwargs):
        value = ObjectField.get(self, instance, **kwargs)
        if getattr(self, 'raw', False):
            return value
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Mikko Ohtamaa
  • 82,057
  • 50
  • 264
  • 435

1 Answers1

1

Nope, we are still stuck with this syntax.

They cannot be converted to decorators so easily because they are a class-level declaration, not actually attached to the methods. You'd need to play nasty tricks with the calling frame to get back to the class declaration and the security object to make this work.

Thus, there is a step where the security object is processed to turn the declarations into class attributes that Zope2 recognizes; this step is these days automatically taken care of by the archetypes registerType call.

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343