Example 2: Querying a structure
Let us use the structure created in Example 1. Simple queries can be made
like below.
|
>>> import gd
>>> root = gd.loadFile('cmsrights.pic')
Is Zaphod a member in int.news.read?
>>> root.isMember('zaphod', 'int.news.read')
False
Ok, is he related somehow to int.news.read?
>>> root.isIn('zaphod', 'int.news.read')
True
Which groups is he a member of anyway?
>>> root.isMemberOf('zaphod')
['public', 'admins']
Who is public news forum administrator, (pub.news.adm)?
>>> root.getMembers('pub.news.adm')
['ford', 'marvin', 'adm.publ']
Is Trillian related to, (allowed in...) pub.news.adm?
>>> root.isIn('trillian', 'pub.news.adm')
True
Is Arthur allowed in pub.news.read?
>>> root.isIn('arthur', 'pub.news.read')
True
Who is member of pub.news.read?
>>> root.getMembers('pub.news.read')
['public']
Who is member of public?
>>> root.getMembers('public')
['public', 'admins', 'adm.publ', 'int.news.adm', 'pub.news.adm',
'int.news.delete', 'int.news.write', 'int.news.read', 'pub.news.delete',
'pub.news.write', 'pub.news.read', 'zaphod', 'trillian', 'marvin', 'ford',
'arthur'] |