py-cvs-rel2_1 (Rev 1.2) merge
[python/dscho.git] / Doc / lib / libbastion.tex
blob7a4f93264e3845e030fef134674fcc30b1027094
1 \section{\module{Bastion} ---
2 Restricting access to objects}
4 \declaremodule{standard}{Bastion}
5 \modulesynopsis{Providing restricted access to objects.}
6 \moduleauthor{Barry Warsaw}{bwarsaw@python.org}
9 % I'm concerned that the word 'bastion' won't be understood by people
10 % for whom English is a second language, making the module name
11 % somewhat mysterious. Thus, the brief definition... --amk
13 According to the dictionary, a bastion is ``a fortified area or
14 position'', or ``something that is considered a stronghold.'' It's a
15 suitable name for this module, which provides a way to forbid access
16 to certain attributes of an object. It must always be used with the
17 \refmodule{rexec} module, in order to allow restricted-mode programs
18 access to certain safe attributes of an object, while denying access
19 to other, unsafe attributes.
21 % I've punted on the issue of documenting keyword arguments for now.
23 \begin{funcdesc}{Bastion}{object\optional{, filter\optional{,
24 name\optional{, class}}}}
25 Protect the object \var{object}, returning a bastion for the
26 object. Any attempt to access one of the object's attributes will
27 have to be approved by the \var{filter} function; if the access is
28 denied an \exception{AttributeError} exception will be raised.
30 If present, \var{filter} must be a function that accepts a string
31 containing an attribute name, and returns true if access to that
32 attribute will be permitted; if \var{filter} returns false, the access
33 is denied. The default filter denies access to any function beginning
34 with an underscore (\character{_}). The bastion's string representation
35 will be \samp{<Bastion for \var{name}>} if a value for
36 \var{name} is provided; otherwise, \samp{repr(\var{object})} will be
37 used.
39 \var{class}, if present, should be a subclass of \class{BastionClass};
40 see the code in \file{bastion.py} for the details. Overriding the
41 default \class{BastionClass} will rarely be required.
42 \end{funcdesc}
45 \begin{classdesc}{BastionClass}{getfunc, name}
46 Class which actually implements bastion objects. This is the default
47 class used by \function{Bastion()}. The \var{getfunc} parameter is a
48 function which returns the value of an attribute which should be
49 exposed to the restricted execution environment when called with the
50 name of the attribute as the only parameter. \var{name} is used to
51 construct the \function{repr()} of the \class{BastionClass} instance.
52 \end{classdesc}