guarded_import does not support 5-args form
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
Zope 2 |
Invalid
|
Medium
|
Unassigned |
Bug Description
Environment:
- python 2.6.5
- Zope 2.12.9
Symptom:
TypeError: guarded_import() takes at most 4 arguments (5 given)
I triggered this problem indirectly, when calling xrange with a float argument.
This triggers this error, because xrange tries internally (disclaimer: I didn't check exactly what does the import) to import __doc__ from _warnings module using the 5-arguments form, and it uses ZopeGuards' version to do so, which fails with above error.
This bug report is just about guarded_import parameter count, but for completeness I must also say that, after adding a dummy fifth parameter to guarded_import, calling "xrange(0.1)" failed with
Unauthorized: You are not allowed to access '__doc__' in this context
For the ones who are about to question the sanity of calling xrange with a float value:
- given error makes diagnostic non-straightforward (this is the most important point to me as I didn't intend to give it a float value)
- it does work in "pure" python (this is secondary to me, I won't use this - but I don't see a reason to prevent this from working)
Regards,
Vincent Pelletier
description: | updated |
Changed in zope2: | |
status: | In Progress → Triaged |
I've seen the same problem.
I added the first workaround in r117566 in the 2.12 branch (and merged to the standalone AccessControl distribution). The guared_import function now accepts the level argument, but only supports level 0 at the moment. You get an explicit Unauthorized message if a different level is specified.
I couldn't find a good explanation of the semantics of the level argument, so I couldn't easily figure out how to support it in full.