cinap_lenrekadd hg and python4bb9e2215 years agoHistory
57 lines · 2.6 KB · TeX
RawDownload
\section{\module{Bastion} ---         Restricting access to objects} \declaremodule{standard}{Bastion}\modulesynopsis{Providing restricted access to objects.}\moduleauthor{Barry Warsaw}{bwarsaw@python.org}\versionchanged[Disabled module]{2.3} \begin{notice}[warning]  The documentation has been left in place to help in reading old code  that uses the module.\end{notice} % I'm concerned that the word 'bastion' won't be understood by people% for whom English is a second language, making the module name% somewhat mysterious.  Thus, the brief definition... --amk According to the dictionary, a bastion is ``a fortified area orposition'', or ``something that is considered a stronghold.''  It's asuitable name for this module, which provides a way to forbid accessto certain attributes of an object.  It must always be used with the\refmodule{rexec} module, in order to allow restricted-mode programsaccess to certain safe attributes of an object, while denying accessto other, unsafe attributes. % I've punted on the issue of documenting keyword arguments for now. \begin{funcdesc}{Bastion}{object\optional{, filter\optional{,                          name\optional{, class}}}}Protect the object \var{object}, returning a bastion for theobject.  Any attempt to access one of the object's attributes willhave to be approved by the \var{filter} function; if the access isdenied an \exception{AttributeError} exception will be raised. If present, \var{filter} must be a function that accepts a stringcontaining an attribute name, and returns true if access to thatattribute will be permitted; if \var{filter} returns false, the accessis denied.  The default filter denies access to any function beginningwith an underscore (\character{_}).  The bastion's string representationwill be \samp{<Bastion for \var{name}>} if a value for\var{name} is provided; otherwise, \samp{repr(\var{object})} will beused. \var{class}, if present, should be a subclass of \class{BastionClass}; see the code in \file{bastion.py} for the details.  Overriding thedefault \class{BastionClass} will rarely be required.\end{funcdesc}  \begin{classdesc}{BastionClass}{getfunc, name}Class which actually implements bastion objects.  This is the defaultclass used by \function{Bastion()}.  The \var{getfunc} parameter is afunction which returns the value of an attribute which should beexposed to the restricted execution environment when called with thename of the attribute as the only parameter.  \var{name} is used toconstruct the \function{repr()} of the \class{BastionClass} instance.\end{classdesc}