blob: 9f45c47a2c740c14ad53a569a113dab162020a0a [file] [log] [blame]
Fred Drake295da241998-08-10 19:42:37 +00001\section{\module{Bastion} ---
Fred Drakeb9971b91999-04-13 21:39:31 +00002 Restricting access to objects}
Fred Drakeb91e9341998-07-23 17:59:49 +00003
Fred Drakeb9971b91999-04-13 21:39:31 +00004\declaremodule{standard}{Bastion}
Fred Drakeb91e9341998-07-23 17:59:49 +00005\modulesynopsis{Providing restricted access to objects.}
Fred Drakeb9971b91999-04-13 21:39:31 +00006\moduleauthor{Barry Warsaw}{bwarsaw@python.org}
Andrew M. Kuchlingeabd9a12003-05-13 14:16:18 +00007\versionchanged[Disabled module]{2.3}
Fred Drakeb91e9341998-07-23 17:59:49 +00008
Andrew M. Kuchlingeabd9a12003-05-13 14:16:18 +00009\begin{notice}[warning]
10 The documentation has been left in place to help in reading old code
11 that uses the module.
12\end{notice}
Guido van Rossumbe0a8a61996-09-10 17:37:05 +000013
14% I'm concerned that the word 'bastion' won't be understood by people
15% for whom English is a second language, making the module name
16% somewhat mysterious. Thus, the brief definition... --amk
17
18According to the dictionary, a bastion is ``a fortified area or
19position'', or ``something that is considered a stronghold.'' It's a
20suitable name for this module, which provides a way to forbid access
21to certain attributes of an object. It must always be used with the
Fred Drakeb9971b91999-04-13 21:39:31 +000022\refmodule{rexec} module, in order to allow restricted-mode programs
23access to certain safe attributes of an object, while denying access
24to other, unsafe attributes.
Guido van Rossumbe0a8a61996-09-10 17:37:05 +000025
26% I've punted on the issue of documenting keyword arguments for now.
27
Fred Drakeda70ee11998-04-02 18:51:30 +000028\begin{funcdesc}{Bastion}{object\optional{, filter\optional{,
29 name\optional{, class}}}}
Fred Drakea705da71998-02-23 14:42:00 +000030Protect the object \var{object}, returning a bastion for the
Guido van Rossumbe0a8a61996-09-10 17:37:05 +000031object. Any attempt to access one of the object's attributes will
32have to be approved by the \var{filter} function; if the access is
Fred Drakea705da71998-02-23 14:42:00 +000033denied an \exception{AttributeError} exception will be raised.
Guido van Rossumbe0a8a61996-09-10 17:37:05 +000034
35If present, \var{filter} must be a function that accepts a string
36containing an attribute name, and returns true if access to that
37attribute will be permitted; if \var{filter} returns false, the access
38is denied. The default filter denies access to any function beginning
Fred Drakeb9971b91999-04-13 21:39:31 +000039with an underscore (\character{_}). The bastion's string representation
Fred Drakea705da71998-02-23 14:42:00 +000040will be \samp{<Bastion for \var{name}>} if a value for
41\var{name} is provided; otherwise, \samp{repr(\var{object})} will be
42used.
Guido van Rossumbe0a8a61996-09-10 17:37:05 +000043
Fred Drakeda70ee11998-04-02 18:51:30 +000044\var{class}, if present, should be a subclass of \class{BastionClass};
Guido van Rossumbe0a8a61996-09-10 17:37:05 +000045see the code in \file{bastion.py} for the details. Overriding the
Fred Drakea705da71998-02-23 14:42:00 +000046default \class{BastionClass} will rarely be required.
Guido van Rossumbe0a8a61996-09-10 17:37:05 +000047\end{funcdesc}
Fred Drakeda70ee11998-04-02 18:51:30 +000048
49
50\begin{classdesc}{BastionClass}{getfunc, name}
51Class which actually implements bastion objects. This is the default
52class used by \function{Bastion()}. The \var{getfunc} parameter is a
53function which returns the value of an attribute which should be
54exposed to the restricted execution environment when called with the
55name of the attribute as the only parameter. \var{name} is used to
56construct the \function{repr()} of the \class{BastionClass} instance.
57\end{classdesc}