[Zope] restricted execution

Florent Guillaume fg at nuxeo.com
Thu Feb 24 10:43:25 EST 2005


Tuttle, Gene <cetuttle at rottlundhomes.com> wrote:
> I am trying to get the re module into zope
> 
> I have created a folder in the products folder called GlobalModules
> I have created a __init__.py in this folder it contains:
> 
> from Products.PythonScripts.Utility import allow_module
> 
> allow_module('re')
> 
> This allows the import to work and the line:
> matchstr = re.compile(r"""\D""")  # search for non numbers
> Zope does not error on the above line.
> however it does not like:
> phone_primary = matchstr.sub(r'',phone_primary)  # remove non numbers for
> the string
> 
> The error is 
> Error Type: Unauthorized
> Error Value: You are not allowed to access 'sub' in this context
> How do I get the  matchstr.sub to work?

  from AccessControl import allow_type
  ModuleSecurityInfo('re').declarePublic('compile', 'findall',
    'match', 'search', 'split', 'sub', 'subn', 'error',
    'I', 'L', 'M', 'S', 'X')
  import re
  allow_type(type(re.sub('x', 'x', 'x')))

You may also want to add:

  allow_type(type(re.compile('x')))
  allow_type(type(re.match('x', 'x')))

Florent

-- 
Florent Guillaume, Nuxeo (Paris, France)   CTO, Director of R&D
+33 1 40 33 71 59   http://nuxeo.com   fg at nuxeo.com


More information about the Zope mailing list