blob: 8f103e7a02826c53991e73cc498a852a28e28b9c [file] [log] [blame]
Georg Brandl8ec7f652007-08-15 14:28:01 +00001
2:mod:`Bastion` --- Restricting access to objects
3================================================
4
5.. module:: Bastion
6 :synopsis: Providing restricted access to objects.
Brett Cannon4c1f8812008-05-10 02:27:04 +00007 :deprecated:
Georg Brandlc62ef8b2009-01-03 20:55:06 +00008
Brett Cannon4c1f8812008-05-10 02:27:04 +00009.. deprecated:: 2.6
Brett Cannona975cd42008-05-11 01:06:54 +000010 The :mod:`Bastion` module has been removed in Python 3.0.
Georg Brandlc62ef8b2009-01-03 20:55:06 +000011
Georg Brandl8ec7f652007-08-15 14:28:01 +000012.. moduleauthor:: Barry Warsaw <bwarsaw@python.org>
13
14
15.. versionchanged:: 2.3
16 Disabled module.
17
Georg Brandlb44c9f32009-04-27 15:29:26 +000018.. note::
Georg Brandl8ec7f652007-08-15 14:28:01 +000019
20 The documentation has been left in place to help in reading old code that uses
21 the module.
22
23According to the dictionary, a bastion is "a fortified area or position", or
24"something that is considered a stronghold." It's a suitable name for this
25module, which provides a way to forbid access to certain attributes of an
26object. It must always be used with the :mod:`rexec` module, in order to allow
27restricted-mode programs access to certain safe attributes of an object, while
28denying access to other, unsafe attributes.
29
Georg Brandlb19be572007-12-29 10:57:00 +000030.. I'm concerned that the word 'bastion' won't be understood by people
31.. for whom English is a second language, making the module name
32.. somewhat mysterious. Thus, the brief definition... --amk
Georg Brandl8ec7f652007-08-15 14:28:01 +000033
Georg Brandlb19be572007-12-29 10:57:00 +000034.. I've punted on the issue of documenting keyword arguments for now.
Georg Brandl8ec7f652007-08-15 14:28:01 +000035
36
37.. function:: Bastion(object[, filter[, name[, class]]])
38
39 Protect the object *object*, returning a bastion for the object. Any attempt to
40 access one of the object's attributes will have to be approved by the *filter*
41 function; if the access is denied an :exc:`AttributeError` exception will be
42 raised.
43
44 If present, *filter* must be a function that accepts a string containing an
45 attribute name, and returns true if access to that attribute will be permitted;
46 if *filter* returns false, the access is denied. The default filter denies
47 access to any function beginning with an underscore (``'_'``). The bastion's
48 string representation will be ``<Bastion for name>`` if a value for *name* is
49 provided; otherwise, ``repr(object)`` will be used.
50
51 *class*, if present, should be a subclass of :class:`BastionClass`; see the
52 code in :file:`bastion.py` for the details. Overriding the default
53 :class:`BastionClass` will rarely be required.
54
55
56.. class:: BastionClass(getfunc, name)
57
58 Class which actually implements bastion objects. This is the default class used
59 by :func:`Bastion`. The *getfunc* parameter is a function which returns the
60 value of an attribute which should be exposed to the restricted execution
61 environment when called with the name of the attribute as the only parameter.
62 *name* is used to construct the :func:`repr` of the :class:`BastionClass`
63 instance.
64