Movatterモバイル変換


[0]ホーム

URL:


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:17.1.3 An exampleUp:17. Restricted ExecutionNext:18. Python Language Services

17.2Bastion -- Restricting access to objects

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 therexec module, in order to allow restricted-mode programsaccess to certain safe attributes of an object, while denying accessto other, unsafe attributes.

Bastion(object[, filter[, name[, class]]])
Protect the objectobject, returning a bastion for theobject. Any attempt to access one of the object's attributes willhave to be approved by thefilter function; if the access isdenied anAttributeError exception will be raised.

If present,filter must be a function that accepts a stringcontaining an attribute name, and returns true if access to thatattribute will be permitted; iffilter returns false, the accessis denied. The default filter denies access to any function beginningwith an underscore ("_"). The bastion's string representationwill be "<Bastion forname>" if a value forname is provided; otherwise, "repr(object)" will beused.

class, if present, should be a subclass ofBastionClass; see the code inbastion.py for the details. Overriding thedefaultBastionClass will rarely be required.

classBastionClass(getfunc, name)
Class which actually implements bastion objects. This is the defaultclass used byBastion(). Thegetfunc 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.name is used toconstruct therepr() of theBastionClass instance.


Previous PageUp One LevelNext PagePython Library ReferenceContentsModule IndexIndex
Previous:17.1.3 An exampleUp:17. Restricted ExecutionNext:18. Python Language Services
Release 2.2.3, documentation updated on 30 May 2003.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2026 Movatter.jp