Module Bastion
Bastionification utility.
A bastion (for another object -- the 'original') is an object that has
the same methods as the original but does not give access to its instance
variables. Bastions have a number of uses, but the most obvious one is
to provide code executing in restricted mode with a safe interface to an
object implemented in unrestricted mode.
The bastionification routine has an optional second argument which is
a filter function. Only those methods for which the filter method
(called with the method name as argument) returns true are accessible.
The default filter method returns true unless the method name begins with
an underscore.
There are a number of possible implementations of bastions. We use a
'lazy' approach where the bastion's __getattr__() discipline does all the
work for a particular method the first time it is used. This is usually
fastest, especially if the user doesn't call all available methods. The
retrieved methods are stored as instance variables of the bastion, so the
overhead is only occurred on the first use of each method.
Detail: the bastion class has a __repr__() discipline which includes
the repr() of the original object. This is precomputed when the bastion
is created.
|
Bastion(object,
filter=<function <lambda> at 0x409e009c>,
name=None,
bastionclass=<class Bastion.BastionClass at 0x409de3bc>)
Create a bastion for an object, using an optional filter. |
|
|
|
_test()
Test the Bastion() function. |
|
|
Imports:
MethodType
Bastion(object,
filter=<function <lambda> at 0x409e009c>,
name=None,
bastionclass=<class Bastion.BastionClass at 0x409de3bc>)
|
|
Create a bastion for an object, using an optional filter.
See the Bastion module's documentation for background.
Arguments:
object - the original object
filter - a predicate that decides whether a function name is OK;
by default all names are OK that don't start with '_'
name - the name of the object; default repr(object)
bastionclass - class used to create the bastion; default BastionClass
|