Bastion Documentation Error?
Jim Dennis
jimd at vega.starshine.org
Tue Apr 2 22:23:15 EST 2002
I'm a bit confused by the Bastion.Bastion() function.
From the documentation I read:
"""
Protect the object object, returning a bastion for the object. Any
attempt to access one of the object's attributes will have to be
approved by the filter function; if the access is denied an
AttributeError exception will be raised.
"""
... but playing with it I find that it raises an AttributeError on
any attempt to access any class or instance variables. It always
seems to call the filter function, then (regardless of the results)
it seems to then check to see if the attribute is a method and block
access even if the filter function returned a true value.
If that is the intent (that only *methods* can be exposed through
regardless of the filter function) then I think this should be made
more clear in the documentation.
Here's a simple transcript that should demonstrate the issue:
Python 2.2.1c1 (#1, Mar 15 2002, 08:13:47)
[GCC 2.95.4 20011002 (Debian prerelease)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Bastion
>>> flt_args=[]
>>> def flt(attr):
... flt_args.append(attr)
... if attr[0] == "_": return None
... else: return 1
...
>>> class Kls:
... foo = 1
... _foo = 2
... def __init__(self):
... self.bar = 3
... self._bar = 4
... def getfoo(): return seself): return self.foo
... def getbar(self): return self.bar
... def _getfoo(self): return self._foo
... def _getbar(self): return self._bar
...
>>> a=Kls()
>>> b=Bastion.Bastion(a,flt)
>>> b.foo
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/Bastion.py", line 79, in __getattr__
attribute = self._get_(name)
File "/usr/lib/python2.2/Bastion.py", line 122, in get2
return get1(name)
File "/usr/lib/python2.2/Bastion.py", line 118, in get1
raise AttributeError, name
AttributeError: foo
>>> flt_args
['foo']
>>> b.getfoo()
1
>>> b.getbar()
3
>>> b._getfoo()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/Bastion.py", line 79, in __getattr__
attribute = self._get_(name)
File "/usr/lib/python2.2/Bastion.py", line 122, in get2
return get1(name)
File "/usr/lib/python2.2/Bastion.py", line 118, in get1
raise AttributeError, name
AttributeError: _getfoo
>>> b._getbar()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/Bastion.py", line 79, in __getattr__
attribute = self._get_(name)
File "/usr/lib/python2.2/Bastion.py", line 122, in get2
return get1(name)
File "/usr/lib/python2.2/Bastion.py", line 118, in get1
raise AttributeError, name
AttributeError: _getbar
>>> flt_args
['foo', 'getfoo', 'getbar', '_getfoo', '_getbar']
>>> b.bar
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/Bastion.py", line 79, in __getattr__
attribute = self._get_(name)
File "/usr/lib/python2.2/Bastion.py", line 122, in get2
return get1(name)
File "/usr/lib/python2.2/Bastion.py", line 118, in get1
raise AttributeError, name
AttributeError: bar
>>> b._foo
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/Bastion.py", line 79, in __getattr__
attribute = self._get_(name)
File "/usr/lib/python2.2/Bastion.py", line 122, in get2
return get1(name)
File "/usr/lib/python2.2/Bastion.py", line 118, in get1
raise AttributeError, name
AttributeError: _foo
>>> b._bar
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/Bastion.py", line 79, in __getattr__
attribute = self._get_(name)
File "/usr/lib/python2.2/Bastion.py", line 122, in get2
return get1(name)
File "/usr/lib/python2.2/Bastion.py", line 118, in get1
raise AttributeError, name
AttributeError: _bar
>>> b.getbar()
3
>>> b.getbar
<bound method Kls.getbar of <__main__.Kls instance at 0x80a4a84>>
>>>
More information about the Python-list
mailing list