1 #=======================================================================
3 __version__
= '''0.0.12'''
4 __sub_version__
= '''20050110052820'''
5 __copyright__
= '''(c) Alex A. Naanou 2003'''
8 #-----------------------------------------------------------------------
12 objects that want to use this protocol may define the following
15 __public__ : if True will render the object accessible;
16 if False will prevent access to the object;
18 __public_attrs__ : will define a list of attributes that are to be visible.
19 __private_attrs__ : will define a list of attributes that are not to be visible.
20 __writable_attrs__ : will define a list of attributes that are writable.
21 __readonly_attrs__ : will define a list of attributes that are not writable.
24 __global_methods_allowed__
25 : will define the allowed global methods for the current object.
27 __global_methods_disallowed__
28 : will define the disallowed global methods for the current object.
29 if True disallow all... (takes priority over __global_methods_allowed__)
31 TODO do global method acl for attrs...
33 __acl__ : ... (not yet done...)
34 the format is as follows:
35 { <obj_id> : {<prop>:<val>[, <prop>:<val>[...]]}[, ...]}
36 <obj_id> : this can be an object or a class (name or ref).
37 <prop> : this can be any of the above (except __acl__)
44 # <qualifier-name> : <action>[, <action>[...]]
45 # <action> : <qualifier-name>[, <qualifier-name>[...]]
52 # <action-name> : <method-name>
55 # setacl(method, <acl>)
61 # TODO rename all attrs to __acl_<name>__ (???)
64 #-----------------------------------------------------------------------
70 ##_delattr = __builtin__.delattr
74 #-----------------------------------------------------------------------
75 # TODO process __acl__
76 #-----------------------------------------------------------isvisible---
77 def isvisible(obj
, uid
=None):
80 if _hasattr(obj
, '__visible__') and not obj
.__visible
__:
85 #--------------------------------------------------------isaccessible---
86 def isaccessible(obj
, uid
=None):
89 if _hasattr(obj
, '__public__') and not obj
.__public
__:
94 #-----------------------------------------------isglobalmethodallowed---
95 def isglobalmethodallowed(obj
, meth
, uid
=None):
98 if isaccessible(obj
) and \
99 (not _hasattr(obj
, '__global_methods_disallowed__') or meth
not in obj
.__global
_methods
_disallowed
__) and \
100 (not _hasattr(obj
, '__global_methods_allowed__') or meth
in obj
.__global
_methods
_allowed
__):
105 #-------------------------------------------------------------hasattr---
106 def hasattr(obj
, name
, uid
=None):
109 if isaccessible(obj
) and \
110 (not _hasattr(obj
, '__private_attrs__') or name
not in obj
.__private
_attrs
__) and\
111 (not _hasattr(obj
, '__public_attrs__') or name
in obj
.__public
_attrs
__):
112 if not _hasattr(obj
, name
):
114 o_obj
= _getattr(obj
, name
)
115 if isaccessible(o_obj
):
120 #-------------------------------------------------------------getattr---
121 def getattr(obj
, name
, uid
=None):
124 if isaccessible(obj
) and \
125 (not _hasattr(obj
, '__private_attrs__') or name
not in obj
.__private
_attrs
__) and\
126 (not _hasattr(obj
, '__public_attrs__') or name
in obj
.__public
_attrs
__):
127 o_obj
= _getattr(obj
, name
)
128 if isaccessible(o_obj
):
130 raise AttributeError, '"%s" object has no attribute "%s".' % (obj
, name
)
133 #----------------------------------------------------------iswritable---
134 def iswritable(obj
, name
, uid
=None):
137 if isaccessible(obj
) and \
138 (not _hasattr(obj
, '__private_attrs__') or name
not in obj
.__private
_attrs
__) and\
139 (not _hasattr(obj
, '__public_attrs__') or name
in obj
.__public
_attrs
__) and\
140 (not _hasattr(obj
, '__writable_attrs__') or name
in obj
.__writable
_attrs
__) and\
141 (not _hasattr(obj
, '__readonly_attrs__') or name
not in obj
.__readonly
_attrs
__):
143 o_obj
= _getattr(obj
, name
)
144 if isaccessible(o_obj
):
146 except AttributeError:
151 #-------------------------------------------------------------setattr---
152 def setattr(obj
, name
, val
, uid
=None):
155 if isaccessible(obj
) and \
156 (not _hasattr(obj
, '__private_attrs__') or name
not in obj
.__private
_attrs
__) and\
157 (not _hasattr(obj
, '__public_attrs__') or name
in obj
.__public
_attrs
__) and\
158 (not _hasattr(obj
, '__writable_attrs__') or name
in obj
.__writable
_attrs
__) and\
159 (not _hasattr(obj
, '__readonly_attrs__') or name
not in obj
.__readonly
_attrs
__):
160 return _setattr(obj
, name
, val
)
161 raise AttributeError, 'can\'t write attribute "%s" of object "%s".' % (name
, obj
)
164 ###-------------------------------------------------------------delattr---
165 ##def delattr(obj, name, uid=None):
170 ###--------------------------------------------inheritclasssecuritylist---
171 ##def inheritclasssecuritylist(prop):
173 ## this will return a tuple which is the union of the security option
174 ## given, set in the classes bases.
176 ## cls = sys._getframe(1)
178 ## for c in cls.__bases__:
179 ## if _hasattr(c, prop):
180 ## res += _getattr(c, prop)
181 ## return tuple(dict([(i, None) for i in res]).keys())
184 #=======================================================================
185 # vim:set ts=4 sw=4 nowrap: