本文整理汇总了Python中tiddlyweb.model.bag.Bag.policy方法的典型用法代码示例。如果您正苦于以下问题:Python Bag.policy方法的具体用法?Python Bag.policy怎么用?Python Bag.policy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tiddlyweb.model.bag.Bag
的用法示例。
在下文中一共展示了Bag.policy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_wiki
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def create_wiki(environ, name, mode='private', username=None, desc='',
validate=True):
"""
Create a wiki with the name, name.
For now a wiki is just a bag a policy.
"""
store = environ['tiddlyweb.store']
if username is None:
username = environ['tiddlyweb.usersign']['name']
bag = Bag(name)
# We want this get to fail.
try:
store.get(bag)
return False
except NoBagError:
pass
try:
bag.policy = WIKI_MODES[mode](username)
except KeyError:
bag.policy = WIKI_MODES['private'](username)
bag.desc = desc
if validate:
validate_bag(bag, environ)
store.put(bag)
return bag
示例2: setup_module
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def setup_module(module):
module.TMPDIR = tempfile.mkdtemp()
_initialize_app(TMPDIR)
module.ADMIN_COOKIE = make_cookie('tiddlyweb_user', 'admin',
mac_key=CONFIG['secret'])
module.STORE = get_store(CONFIG)
# register admin user
data = {
'username': 'admin',
'password': 'secret',
'password_confirmation': 'secret'
}
response, content = _req('POST', '/register', urlencode(data),
headers={ 'Content-Type': 'application/x-www-form-urlencoded' })
bag = Bag('alpha')
bag.policy = Policy(read=['admin'], write=['admin'], create=['admin'],
delete=['admin'], manage=['admin'])
STORE.put(bag)
bag = Bag('bravo')
STORE.put(bag)
bag = Bag('charlie')
bag.policy = Policy(read=['nobody'], write=['nobody'], create=['nobody'],
delete=['nobody'], manage=['nobody'])
STORE.put(bag)
tiddler = Tiddler('index', 'bravo')
tiddler.text = 'lorem ipsum\ndolor *sit* amet'
tiddler.type = 'text/x-markdown'
STORE.put(tiddler)
示例3: _make_space
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def _make_space(environ, space_name):
"""
The details of creating the bags and recipes that make up a space.
"""
store = environ['tiddlyweb.store']
member = environ['tiddlyweb.usersign']['name']
# XXX stub out the clumsy way for now
# can make this much more declarative
space = Space(space_name)
for bag_name in space.list_bags():
bag = Bag(bag_name)
bag.policy = _make_policy(member)
if Space.bag_is_public(bag_name):
bag.policy.read = []
store.put(bag)
public_recipe = Recipe(space.public_recipe())
public_recipe.set_recipe(space.public_recipe_list())
private_recipe = Recipe(space.private_recipe())
private_recipe.set_recipe(space.private_recipe_list())
private_recipe.policy = _make_policy(member)
public_recipe.policy = _make_policy(member)
public_recipe.policy.read = []
store.put(public_recipe)
store.put(private_recipe)
示例4: make_space
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def make_space(space_name, store, member):
"""
The details of creating the bags and recipes that make up a space.
"""
space = Space(space_name)
for bag_name in space.list_bags():
bag = Bag(bag_name)
bag.policy = _make_policy(member)
if Space.bag_is_public(bag_name):
bag.policy.read = []
store.put(bag)
info_tiddler = Tiddler('SiteInfo', space.public_bag())
info_tiddler.text = 'Space %s' % space_name
store.put(info_tiddler)
public_recipe = Recipe(space.public_recipe())
public_recipe.set_recipe(space.public_recipe_list())
private_recipe = Recipe(space.private_recipe())
private_recipe.set_recipe(space.private_recipe_list())
private_recipe.policy = _make_policy(member)
public_recipe.policy = _make_policy(member)
public_recipe.policy.read = []
store.put(public_recipe)
store.put(private_recipe)
示例5: remove_user
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def remove_user(environ, space_name, user_name):
"""
remove user_name from space_name while
checking the policy allows the logged
in user to do it
"""
store = environ['tiddlyweb.store']
user = User(user_name)
user = store.get(user)
logged_in_user = environ['tiddlyweb.usersign']
space_definition = environ['tiddlyweb.config']['space']
space = []
for name, values in space_definition['bags'].iteritems():
bag = Bag(name.replace('SPACE_NAME', space_name))
bag = store.get(bag)
bag.policy.allows(logged_in_user, 'manage')
bag.policy = remove_from_policy(user, bag.policy)
space.append(bag)
for name, values in space_definition['recipes'].iteritems():
recipe = Recipe(name.replace('SPACE_NAME', space_name))
recipe = store.get(recipe)
recipe.policy.allows(logged_in_user, 'manage')
recipe.policy = remove_from_policy(user, recipe.policy)
space.append(recipe)
for thing in space:
store.put(thing)
示例6: test_bag_policy
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def test_bag_policy():
bag = Bag('policy_tester')
bag.policy = Policy(read=['chris','jeremy'])
assert bag.policy.allows(chris_info, 'read')
py.test.raises(UserRequiredError, 'bag.policy.allows(guest_info, "read")')
示例7: _bag_policy
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def _bag_policy(environ, bag_name, publicity):
user = get_user_object(environ)
store = environ['tiddlyweb.store']
bag = Bag(bag_name)
bag = store.get(bag)
bag.policy.allows(user, 'manage')
if publicity == 'custom':
raise HTTP303(bag_url(environ, bag) + '/tiddlers')
if publicity == 'public':
bag.policy = public_policy(user['name'])
elif publicity == 'protected':
bag.policy = protected_policy(user['name'])
else:
bag.policy = private_policy(user['name'])
store.put(bag)
raise HTTP303(bag_url(environ, bag) + '/tiddlers')
示例8: test_reuse_policy_object
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def test_reuse_policy_object():
"""
Explicitly test a bug fix in policy handling wherein the owner
field could get transformed into (and stay) a list thus ruining
second use. Not that second use is encourage, but it could happen.
"""
policy = Policy()
policy.owner = u'campy'
bag = Bag('policytest1')
bag.policy = policy
STORE.put(bag)
bag = Bag('policytest2')
bag.policy = policy
STORE.put(bag)
bag1 = STORE.get(Bag('policytest1'))
bag2 = STORE.get(Bag('policytest2'))
assert bag1.policy.owner == 'campy'
assert bag2.policy.owner == 'campy'
assert bag1.policy.owner == bag2.policy.owner
示例9: test_reuse_policy_object
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def test_reuse_policy_object():
"""
Explicitly test a bug fix in policy handling wherein the owner
field could get transformed into (and stay) a list thus ruining
second use. Not that second use is encourage, but it could happen.
"""
policy = Policy()
policy.owner = u"campy"
bag = Bag("policytest1")
bag.policy = policy
store.put(bag)
bag = Bag("policytest2")
bag.policy = policy
store.put(bag)
bag1 = store.get(Bag("policytest1"))
bag2 = store.get(Bag("policytest2"))
assert bag1.policy.owner == "campy"
assert bag2.policy.owner == "campy"
assert bag1.policy.owner == bag2.policy.owner
示例10: _create_wiki
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def _create_wiki(store, name, owner, private):
bag = Bag(name)
try:
store.get(bag)
raise HTTP409('wiki name unavailable')
except NoBagError:
pass
read_constraint = [owner] if private else None
bag.policy = Policy(read=read_constraint, write=[owner], create=[owner],
delete=[owner], manage=[owner]) # XXX: too limiting!?
store.put(bag)
示例11: setup_module
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def setup_module(module):
instance = make_instance()
module.STORE = instance['store']
module.ADMIN_COOKIE = instance['admin_cookie']
bag = Bag('alpha')
bag.policy = Policy(read=['admin'], write=['admin'], create=['admin'],
delete=['admin'], manage=['admin'])
STORE.put(bag)
bag = Bag('bravo')
STORE.put(bag)
bag = Bag('charlie')
bag.policy = Policy(read=['nobody'], write=['nobody'], create=['nobody'],
delete=['nobody'], manage=['nobody'])
STORE.put(bag)
tiddler = Tiddler('index', 'bravo')
tiddler.text = 'lorem ipsum\ndolor *sit* amet'
tiddler.type = 'text/x-markdown'
STORE.put(tiddler)
示例12: bag_policy
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def bag_policy(environ, start_response):
user = get_user_object(environ)
store = environ['tiddlyweb.store']
publicity = environ['tiddlyweb.query'].get('publicity', [''])[0]
bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
bag = Bag(bag_name)
bag.skinny = True
bag = store.get(bag)
bag.policy.allows(user, 'manage')
if publicity == 'custom':
raise HTTP303(bag_url(environ, bag) + '/tiddlers')
if publicity == 'public':
bag.policy = public_policy(user['name'])
elif publicity == 'protected':
bag.policy = protected_policy(user['name'])
else:
bag.policy = private_policy(user['name'])
store.put(bag)
raise HTTP303(bag_url(environ, bag) + '/tiddlers')
示例13: add_archive
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def add_archive(args):
"""add archive bags to the store: twanager add_archive"""
store = get_store(config)
bags = store.list_bags()
for bag in bags:
if bag.name.endswith('_private'):
space_name = bag.name.rsplit('_', 1)[0]
archive = Bag('%s_archive' % space_name)
try:
archive = store.get(archive)
except NoBagError:
archive.policy = bag.policy
store.put(archive)
示例14: setup_module
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def setup_module(module):
cfg = _initialize_app({ 'tagdex_db': 'tagdex_test.sqlite' })
module.STORE = get_store(cfg)
database.reset(cfg)
module.STORE.put(Bag('alpha'))
module.STORE.put(Bag('bravo'))
bag = Bag('charlie')
bag.policy = Policy(read=['bob'])
module.STORE.put(bag)
_put_tiddler('HelloWorld', 'alpha', ['foo', 'bar'], 'lorem ipsum')
_put_tiddler('HelloWorld', 'bravo', ['foo', 'bar'], 'lorem ipsum')
_put_tiddler('Lipsum', 'alpha', ['bar', 'baz'], '...')
_put_tiddler('Confidential', 'charlie', ['private', 'secret'], '...')
_put_tiddler('1984', 'alpha', ['book', 'scifi', 'political'], 'Orwell, G.')
_put_tiddler('Foundation', 'alpha', ['book', 'scifi'], 'Asimov, I.')
示例15: _check_bag
# 需要导入模块: from tiddlyweb.model.bag import Bag [as 别名]
# 或者: from tiddlyweb.model.bag.Bag import policy [as 别名]
def _check_bag(name, environ, user):
"""
Get the user's bag. Create if required.
"""
store = environ['tiddlyweb.store']
name = '%s-%s' % (user, name)
name = name.replace('.', '_')
try:
bag = Bag(name)
bag = store.get(bag)
except NoBagError:
uni_user = unicode(user)
policy = Policy(owner=uni_user, manage=[uni_user],
read=[uni_user], write=[uni_user],
delete=[uni_user], create=[uni_user])
bag.policy = policy
bag.desc = 'Twotes for %s' % uni_user;
store.put(bag)
return bag