2.3. 最终完成的 svnauthz

在 Python 交互模式下测试 svnauthz 模组:

>>> buff = '''# admin: / = administrator
... [groups]
... group1=user1,user2
... [/]
... $authenticated=r
... [/trunk]
... @group1 = r
... user3 = rw'''
>>> import StringIO
>>> file = StringIO.StringIO(buff)
>>> authz=SvnAuthz()
>>> authz.load(file)
>>> [x.name for x in authz.reposlist]
['/']
>>> [x.uname for x in authz.userlist]
[u'administrator', u'user1', u'user2', u'user3']
>>> [x.uname for x in authz.userlist]
[u'administrator', u'user1', u'user2', u'user3']
>>> [x.uname for x in authz.grouplist]
[u'@group1', u'$authenticated']
>>> [x.uname for x in authz.aliaslist]
[]
>>> print authz.grouplist
[groups]
group1 = user1, user2

>>> print authz.aliaslist
[aliases]
>>> authz.is_admin('administrator','/')
True
>>> authz.is_admin('administrator','repos1')
True
>>> authz.add_rules('/', '/trunk', '&admin=rw; $authenticated=')
>>> module1 = authz.get_module('/', '/trunk')
>>> [str(x) for x in module1]
['@group1 = r', 'user3 = rw', '$authenticated = ', '&admin = rw']

现在是时候给 svnauthz 套上一个华丽一点的外衣了。