[Zope-dev] testing types in PythonScripts

Steve Alexander steve@cat-box.net
Fri, 28 Sep 2001 12:49:39 +0100


I have a variable, f.

The value of f might be a list, or it might be a string.

I want to do different things to f depending what type it is.

How do I check its type from a PythonScript?


I can't use type(), as this opens up a security hole with Extension 
Classes, where the type is the class.

I can't import types, as that seems to be restricted.


I suggest that either one or both of the following be altered:

  * The types module is allowed to be imported into restricted stuff.

  * A safe version of type() is put into the restricted global namespace.


I seem to recall a discussion of this a few months ago, where someone 
(Evan?) proposed a safe version of type(). I guess this got lost in the 
conversion to RestrictedPython with Zope 2.4.


Oh yeah... an ugly workaround is to try to append to f and see if you 
get and AttributeError.

--
Steve Alexander
Software Engineer
Cat-Box limited