• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python bag.Bag类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Python中tiddlyweb.model.bag.Bag的典型用法代码示例。如果您正苦于以下问题:Python Bag类的具体用法?Python Bag怎么用?Python Bag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Bag类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。

示例1: retrieve_from_store

def retrieve_from_store(email):
    """
    get the tiddler requested by the email from the store 
    and return it as an email
    """
    store = get_store(config)
    tiddler_title = clean_subject(email["subject"])
    tiddler = Tiddler(tiddler_title)
    bag = determine_bag(email["to"])
    tiddler.bag = bag

    try:
        tiddler = store.get(tiddler)
        response_text = tiddler.text
    except NoTiddlerError:
        # Tiddler not found. Return a list of all tiddlers
        bag = Bag(bag)
        bag = store.get(bag)
        response_text = "The following tiddlers are in %s:\n" % email["to"].split("@")[1]
        tiddlers = bag.gen_tiddlers()
        tiddlers = [tiddler for tiddler in tiddlers]
        response_text += "\n".join([tiddler.title for tiddler in tiddlers])

    response_email = {"from": email["to"], "to": email["from"], "subject": tiddler.title, "body": response_text}

    return response_email
开发者ID:jdlrobson,项目名称:tiddlywebplugins.email,代码行数:26,代码来源:mail.py


示例2: _create_bag

def _create_bag(environ):
    """Take the form input and turn it into a bag."""
    query_data = _flatten_form_data(environ['tiddlyweb.query'])
    logging.debug(query_data)
    store = environ['tiddlyweb.store']
    try:
        new_bag_name = query_data['bag_name']

        if _bag_exists(store, new_bag_name):
            raise HTTP409('That bag may not be created.')

        new_bag = Bag(new_bag_name)

        username = environ['tiddlyweb.usersign']['name']
        new_bag.policy.owner = username
        new_bag.policy.manage = [username]
        new_bag.desc = query_data.get('bag_desc', '')

        for policy_type in ('read', 'write', 'create', 'delete'):
            texted = query_data.get(policy_type + '_text', None)
            logging.debug('texted: %s' % texted)
            if texted:
                new_bag.policy.__setattr__(policy_type, [x.lstrip().rstrip() for x in texted.split(',')])
            else:
                set = query_data[policy_type]
                new_bag.policy.__setattr__(policy_type, _policy_form_to_entry(username, set))

        store.put(new_bag)
    except KeyError, exc:
        raise HTTP400('something went wrong processing for: %s' % exc)
开发者ID:FND,项目名称:tiddlyweb-plugins-1,代码行数:30,代码来源:mine.py


示例3: setup_module

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)
开发者ID:pads,项目名称:tiddlywebplugins.bfw,代码行数:35,代码来源:test_web.py


示例4: test_get_revision

def test_get_revision():
    """
    Test we are able to retrieve a particular revision.
    """

    bagone = Bag('bagone')
    bagone.add_tiddlers(tiddlers)

    store.put(bagone)
    store.put(bagone)
    tiddler = Tiddler('RevisionTiddler')
    tiddler.text='how now 1'
    tiddler.bag = 'bagone'
    store.put(tiddler)
    tiddler.text = 'how now 2'
    store.put(tiddler)
    tiddler.text = 'how now 3'
    store.put(tiddler)

    tiddler = Tiddler(title='RevisionTiddler', bag='bagone')
    tiddler = store.get(tiddler)

    assert tiddler.text == 'how now 3'
    assert tiddler.revision == 3

    tiddler = Tiddler(title='RevisionTiddler', bag='bagone')
    tiddler.revision = 2
    tiddler = store.get(tiddler)

    assert tiddler.text == 'how now 2'
    assert tiddler.revision == 2

    revisions = store.list_tiddler_revisions(tiddler)
    assert len(revisions) == 3
    assert revisions[0] == 3
开发者ID:djswagerman,项目名称:tiddlyweb,代码行数:35,代码来源:test_store_tiddler.py


示例5: remove_user

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)
开发者ID:FND,项目名称:tiddlyspace.old,代码行数:30,代码来源:users_old.py


示例6: create_wiki

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
开发者ID:pads,项目名称:tank,代码行数:30,代码来源:wiki.py


示例7: test_validate_bag_desc

def test_validate_bag_desc():
    bag = Bag('barney')
    bag.desc = '<script>alert("foo");</script>'

    validate_bag(bag)

    assert bag.desc == '&lt;script&gt;alert("foo");&lt;/script&gt;'
开发者ID:JazzDeben,项目名称:tiddlyweb-xmobile,代码行数:7,代码来源:test_validate.py


示例8: test_post_no_title

def test_post_no_title():
    """
    post a tiddler with no title set
    and make sure it gets into the store
    """
    store = setup_store()
    setup_web()
    http = httplib2.Http()
    
    #post some fields to a tiddler 
    response = http.request('http://test_domain:8001/bags/foo/tiddlers',
        method='POST', 
        headers={'Content-type': 'application/x-www-form-urlencoded'},
        body='text=Hi%20There')[0]
    assert response.status == 204
    
    #now find the tiddler just entered and check it
    bag = Bag('foo')
    bag = store.get(bag)
    tiddlers = bag.list_tiddlers()
    
    assert len(tiddlers) == 1
    
    tiddler = store.get(tiddlers[0])
    assert tiddler.title != ''
    assert tiddler.text == 'Hi There'
开发者ID:jdlrobson,项目名称:tiddlywebplugins.form,代码行数:26,代码来源:test_post_text.py


示例9: tiddler_as

 def tiddler_as(self, tiddler):
     """
     entry point for a single tiddler. Sets some variables
     and passes the tiddler into list_tiddlers for turning
     into HTML
     """
     if 'tiddler' not in self.environ['tiddlyweb.recipe_template']:
         self.environ['tiddlyweb.recipe_template']['tiddler'] = tiddler.title
     if 'bag' not in self.environ['tiddlyweb.recipe_template']:
         self.environ['tiddlyweb.recipe_template']['bag'] = tiddler.bag
     if tiddler.recipe and 'recipe' not in self.environ['tiddlyweb.recipe_template']:
         self.environ['tiddlyweb.recipe_template']['recipe'] = tiddler.recipe
         
     bag = Bag('tmpbag',tmpbag=True)
     bag.add_tiddler(tiddler)
     
     self.plugin_name = self.set_plugin_name('single_tiddler')
     
     if self.plugin_name not in self.environ['tiddlyweb.config']['tw_pages_serializers']:
         content = self.pass_through_external_serializer(self.plugin_name, tiddler)
         return content
         
     self.page_title = self.environ['tiddlyweb.config']['tw_pages_serializers'][self.plugin_name]['title'] or tiddler.title
     
     return self.list_tiddlers(bag)
开发者ID:bengillies,项目名称:TiddlyWeb-Plugins,代码行数:25,代码来源:serialization.py


示例10: _bag_list

 def _bag_list(self, tiddlers):
     if '/feedbag' in self.environ['selector.matches'][0]:
         representation_link = '%s/feedbag' % (self._server_prefix())
         bag = Bag('feedbag')
         bag.policy.manage = ["NONE"]
         bag.policy.delete = ["NONE"]
         bag.desc = 'Recent Public Stuff'
     else:
         name = self.environ['wsgiorg.routing_args'][1]['bag_name']
         name = urllib.unquote(name)
         name = name.decode('utf-8')
         representation_link = '%s/bags/%s/tiddlers' % (
                 self._server_prefix(), encode_name(name))
         bag = self.environ['tiddlyweb.store'].get(Bag(name))
     representations = self._tiddler_list_header(representation_link)
     user_object = get_user_object(self.environ)
     publicity = ''
     try:
         bag.policy.allows(user_object, 'manage')
         policy = bag.policy
         publicity = determine_publicity(user_object, policy)
     except (UserRequiredError, ForbiddenError):
         policy = None
     try:
         bag.policy.allows(user_object, 'delete')
         delete = True
     except (UserRequiredError, ForbiddenError):
         delete = False
     data = {'title': 'TiddlyHoster Bag %s' % bag.name, 'policy': policy,
             'publicity': publicity, 'delete': delete,
             'bag': bag, 'tiddlers': tiddlers, 'representations': representations}
     del self.environ['tiddlyweb.title']
     return send_template(self.environ, 'baglist.html', data)
开发者ID:ralphbtp,项目名称:tiddlyhoster,代码行数:33,代码来源:serialization.py


示例11: tiddler_as

 def tiddler_as(self, tiddler):
     logging.debug("###################################\nDOING TIDDLER_AS\n\n\n###################################")
     """
     Take the single tiddler provided and inject it into
     a TiddlyWiki.
     """
     environ = self.environ
     store = self.environ["tiddlyweb.store"]
     try:
       recipe_name =tiddler.recipe
       tiddler_as_name = tiddler.title
       resource = Recipe(recipe_name)
       resource= store.get(resource)
       tiddlers = control.get_tiddlers_from_recipe(resource)
       bag =Bag("tmp",tmpbag=True)
       logging.debug("have tiddlers %s"%tiddlers)
       for a_tiddler in tiddlers:
         a_tiddler.recipe = recipe_name
         a_tiddler = store.get(a_tiddler)
         if a_tiddler.title == "DefaultTiddlers":
           a_tiddler.text = "[[%s]]"%tiddler_as_name
           logging.debug("tiddler_as overriding DefaultTiddlers")
         bag.add_tiddler(a_tiddler)
         
     except AttributeError:
       resource = Bag(tiddler.bag)
       bag = store.get(resource)
       
     self._prepare_twp(bag)
     
     return self.build_non_js_version(bag,default=[tiddler])
开发者ID:FND,项目名称:tiddlywiki-svn-mirror,代码行数:31,代码来源:twpwiki.py


示例12: test_post_fields

def test_post_fields():
    """
    post some fields to a tiddler
    """
    store = setup_store()
    setup_web()
    http = httplib2.Http()
    
    #make sure there is nothing in bag 'foo'
    bag = Bag('foo')
    bag = store.get(bag)
    assert len(bag.list_tiddlers()) == 0
    
    response = http.request('http://test_domain:8001/bags/foo/tiddlers',
        method='POST', 
        headers={'Content-type': 'application/x-www-form-urlencoded'},
        body='title=HelloWorld&field1=foo&field2=bar')[0]
    assert response.status == 204
    
    #now find the tiddler just entered
    tiddler = Tiddler('HelloWorld', 'foo')
    try:
        store.get(tiddler)
    except NoTiddlerError:
        raise AssertionError('tiddler was not put into store')
    
    #and check the fields
    assert tiddler.title == 'HelloWorld'
    assert len(tiddler.fields) == 2
    assert tiddler.fields['field1'] == 'foo'
    assert tiddler.fields['field2'] == 'bar'
开发者ID:jdlrobson,项目名称:tiddlywebplugins.form,代码行数:31,代码来源:test_post_text.py


示例13: test_filter_bag_by_filter

def test_filter_bag_by_filter():
    """
    Confirm a bag will properly filter.
    """
    bagfour = Bag('bagfour')
    store.put(bagfour)
    bagfour.store = store
    for tiddler in tiddlers:
        tiddler.bag = 'bagfour'
        store.put(tiddler)

    filtered_tiddlers = list(control._filter_tiddlers_from_bag(bagfour,
        'select=title:TiddlerOne', environ=environ))
    assert len(filtered_tiddlers) == 1
    assert filtered_tiddlers[0].title == 'TiddlerOne'

    filtered_tiddlers = list(control._filter_tiddlers_from_bag(bagfour,
        'select=tag:tagone', environ=environ))
    assert len(filtered_tiddlers) == 2

    filters, thing = parse_for_filters(
            'select=tag:tagone;select=title:TiddlerThree', environ=environ)
    filtered_tiddlers = list(control._filter_tiddlers_from_bag(bagfour,
        filters, environ=environ))
    assert len(filtered_tiddlers) == 1
    assert filtered_tiddlers[0].title == 'TiddlerThree'
开发者ID:24king,项目名称:tiddlyweb,代码行数:26,代码来源:test_bag_filtering.py


示例14: _ensure_bags

    def _ensure_bags(self, environ, username):

      # for privacy in ["public", "protected", "private"]:
      for privacy in ["private", "protected"]:

        only_user = ["admin", username]
        if privacy=="public":
          readPerms = []
          writePerms = []
        elif privacy=="protected":
          readPerms = []
          writePerms = only_user
        elif privacy=="private":
          readPerms = only_user
          writePerms = only_user

        bag = Bag(privacy+"-"+username)
        store = environ['tiddlyweb.store']
        try:
            store.get(bag)
            return
        except NoBagError:
            bag.desc = 'tiddlyguv private user bag'
            bag.policy.owner = username
            bag.policy.manage = ["admin", username]
            bag.policy.read = readPerms
            bag.policy.write = writePerms
            bag.policy.create = ["admin", username]
            bag.policy.delete = ["admin", username]
            store.put(bag)
开发者ID:FND,项目名称:tiddlywiki-svn-mirror,代码行数:30,代码来源:ldap.py


示例15: _process_choices

def _process_choices(environ, start_response, form):
    store = environ['tiddlyweb.store']
    user = environ['tiddlyweb.usersign']

    tmp_bag = form['tmp_bag'][0]
    bag = form['target_bag'][0]
    if bag:
        bag = Bag(bag)
        try:
            bag.skinny = True
            bag = store.get(bag)
        except NoBagError:
            return _send_wimport(environ, start_response,
                    'chosen bag does not exist')
    else:
        bag = form['new_bag'][0]
        bag = _make_bag(environ, bag)

    try:
        bag.policy.allows(user, 'write')
    except (ForbiddenError, UserRequiredError):
        return _send_wimport(environ, start_response,
                'you may not write to that bag')

    tiddler_titles = form['tiddler']
    for title in tiddler_titles:
        tiddler = Tiddler(title.decode('utf-8', 'ignore'), tmp_bag)
        tiddler = store.get(tiddler)
        tiddler.bag = bag.name
        store.put(tiddler)
    tmp_bag = Bag(tmp_bag)
    store.delete(tmp_bag)
    bagurl = bag_url(environ, bag) + '/tiddlers'
    raise HTTP302(bagurl)
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.wimporter,代码行数:34,代码来源:wimporter.py


示例16: post_createbag

def post_createbag(environ, start_response):
    user = get_user_object(environ)
    store = environ['tiddlyweb.store']
    bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
    publicity = environ['tiddlyweb.query'].get('publicity', [''])[0]
    description = environ['tiddlyweb.query'].get('description', [''])[0]

    if not bag_name:
        raise HTTP400('missing data')

    bag = Bag(bag_name)

    try:
        bag.skinny = True
        bag = store.get(bag)
        raise HTTP400('bag exists')
    except NoBagError:
        pass
    if publicity == 'public':
        bag = ensure_public_bag(
                store, user['name'], desc=description, name=bag_name)
    elif publicity == 'protected':
        bag = ensure_protected_bag(
                store, user['name'], desc=description, name=bag_name)
    else:
        bag = ensure_private_bag(
                store, user['name'], desc=description, name=bag_name)

    # the bag has already been stored

    raise HTTP303('%s/tiddlers' % bag_url(environ, bag))
开发者ID:bengillies,项目名称:tiddlyhoster,代码行数:31,代码来源:__init__.py


示例17: test_bag_policy

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")')
开发者ID:angeluseve,项目名称:tiddlyweb,代码行数:7,代码来源:test_policy.py


示例18: make_space

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)
开发者ID:ramanathanr,项目名称:tiddlyspace,代码行数:26,代码来源:spaces.py


示例19: determine_tiddler_bag_from_recipe

def determine_tiddler_bag_from_recipe(recipe, tiddler, environ=None):
    """
    We have a recipe and a tiddler. We need to
    know the bag in which this tiddler can be found.
    This is different from determine_bag_for_tiddler().
    That one finds the bag the tiddler _could_ be in.
    This is the bag the tiddler _is_ in.

    We reverse the recipe_list, and filter each bag
    according to the rule. Then we look in the list of
    tiddlers and see if ours is in there.
    """
    store = recipe.store
    template = _recipe_template(environ)
    for bag, filter_string in reversed(recipe.get_recipe(template)):
        if isinstance(bag, basestring):
            bag = Bag(name=bag)
        if store:
            bag = store.get(bag)
        # If there is a filter_string then we need to load the tiddlers off
        # the store. If there's not, then we can just use the list that is
        # already in the bag, saving a bit of time.
        if filter_string:
            for candidate_tiddler in filter_tiddlers_from_bag(bag,
                    filter_string):
                if tiddler.title == candidate_tiddler.title:
                    return bag
        else:
            for candidate_tiddler in bag.gen_tiddlers():
                if tiddler.title == candidate_tiddler.title:
                    return bag

    raise NoBagError('no suitable bag for %s' % tiddler.title)
开发者ID:djswagerman,项目名称:tiddlyweb,代码行数:33,代码来源:control.py


示例20: _make_space

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)
开发者ID:carnotip,项目名称:tiddlyspace,代码行数:28,代码来源:spaces.py



注:本文中的tiddlyweb.model.bag.Bag类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python collections.Tiddlers类代码示例发布时间:2022-05-27
下一篇:
Python models.TicketsEventMeta类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap