• Shane Hathaway's avatar
    Based on some semi-formal performance tests, read guards turned out to be · f25d5315
    Shane Hathaway authored
    slower than the old code.  With this change, we're using simple function
    calls again to perform security checks.  But the calling sequence is
    intended to be easier to comprehend than the old code.  Now instead of
    DT_String.String subclasses having a validate() method attached to them, they
    subclass AccessControl.DTML.RestrictedDTML, which provides a guarded_getattr()
    method and a guarded_getitem() method.
    
    Note that the functionality of guarded_getattr() used to be implemented
    both in C and Python (in cDocumentTemplate and DT_Util), but now it's in
    one place, ZopeGuards.py.  Thus it's not only reusable but easy to
    optimize.
    
    I ran all the tests and ran the new code through the profiler again.  The
    change sped up restricted code a little more than expected, which is
    definitely a good thing, but that may indicate that nested scopes
    have a hidden speed penalty.
    
    Also, RestrictedPython is now restrictive about printing to targets and
    two forms of augmented assignment had to be forbidden.
    f25d5315
DT_String.py 20.6 KB