/Doc/library/bastion.rst

http://unladen-swallow.googlecode.com/ · ReStructuredText · 64 lines · 44 code · 20 blank · 0 comment · 0 complexity · ca7d393fc23450bba9a3bd715fce6d12 MD5 · raw file

  1. :mod:`Bastion` --- Restricting access to objects
  2. ================================================
  3. .. module:: Bastion
  4. :synopsis: Providing restricted access to objects.
  5. :deprecated:
  6. .. deprecated:: 2.6
  7. The :mod:`Bastion` module has been removed in Python 3.0.
  8. .. moduleauthor:: Barry Warsaw <bwarsaw@python.org>
  9. .. versionchanged:: 2.3
  10. Disabled module.
  11. .. note::
  12. The documentation has been left in place to help in reading old code that uses
  13. the module.
  14. According to the dictionary, a bastion is "a fortified area or position", or
  15. "something that is considered a stronghold." It's a suitable name for this
  16. module, which provides a way to forbid access to certain attributes of an
  17. object. It must always be used with the :mod:`rexec` module, in order to allow
  18. restricted-mode programs access to certain safe attributes of an object, while
  19. denying access to other, unsafe attributes.
  20. .. I'm concerned that the word 'bastion' won't be understood by people
  21. .. for whom English is a second language, making the module name
  22. .. somewhat mysterious. Thus, the brief definition... --amk
  23. .. I've punted on the issue of documenting keyword arguments for now.
  24. .. function:: Bastion(object[, filter[, name[, class]]])
  25. Protect the object *object*, returning a bastion for the object. Any attempt to
  26. access one of the object's attributes will have to be approved by the *filter*
  27. function; if the access is denied an :exc:`AttributeError` exception will be
  28. raised.
  29. If present, *filter* must be a function that accepts a string containing an
  30. attribute name, and returns true if access to that attribute will be permitted;
  31. if *filter* returns false, the access is denied. The default filter denies
  32. access to any function beginning with an underscore (``'_'``). The bastion's
  33. string representation will be ``<Bastion for name>`` if a value for *name* is
  34. provided; otherwise, ``repr(object)`` will be used.
  35. *class*, if present, should be a subclass of :class:`BastionClass`; see the
  36. code in :file:`bastion.py` for the details. Overriding the default
  37. :class:`BastionClass` will rarely be required.
  38. .. class:: BastionClass(getfunc, name)
  39. Class which actually implements bastion objects. This is the default class used
  40. by :func:`Bastion`. The *getfunc* parameter is a function which returns the
  41. value of an attribute which should be exposed to the restricted execution
  42. environment when called with the name of the attribute as the only parameter.
  43. *name* is used to construct the :func:`repr` of the :class:`BastionClass`
  44. instance.