当前位置: 首页>>代码示例>>Python>>正文


Python utils.get_store函数代码示例

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


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

示例1: setup_module

def setup_module(module):
    module.store = get_store(config)
    module.environ = {"tiddlyweb.config": config, "tiddlyweb.store": module.store}
    session = module.store.storage.session
    # delete everything
    Base.metadata.drop_all()
    Base.metadata.create_all()
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.sqlalchemy,代码行数:7,代码来源:test_search.py

示例2: test_cookie_set

def test_cookie_set():
    """
    test that we get a cookie relating to the space we are in
    """
    store = get_store(config)
    hostname = "foo.0.0.0.0:8080"
    user = User(u"f\u00F6o")
    user.set_password("foobar")
    store.put(user)

    user_cookie = get_auth(u"f\u00F6o", "foobar")

    response, content = http.request(
        "http://foo.0.0.0.0:8080/", method="GET", headers={"Cookie": 'tiddlyweb_user="%s"' % user_cookie}
    )

    assert response["status"] == "200", content

    time = datetime.utcnow().strftime("%Y%m%d%H")
    cookie = "csrf_token=%s:%s:%s" % (
        time,
        user.usersign,
        sha("%s:%s:%s:%s" % (user.usersign, time, hostname, config["secret"])).hexdigest(),
    )
    assert response["set-cookie"] == quote(cookie.encode("utf-8"), safe=".!~*'():=")
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.csrf,代码行数:25,代码来源:test_post_validate.py

示例3: url

def url(args):
    """Add a URL via tiddlywebplugins.URLs. Redirect is optional. [--redirect] <selector_path> <destination_url>"""
    if 2 != len(args) != 3:
        print >> sys.stderr, ('you must include both the path you want to use (selector path) and the destination url')
        
    store = get_store(config)
    
    if args[0] == '--redirect':
        redirect = args.pop(0).lstrip('-')
    else:
        redirect = None
    
    selector_path = args[0]
    destination_url = args[1]
    
    tiddler = Tiddler(selector_path)
    tiddler.bag = config['url_bag']
    
    tiddler.text = destination_url
    if redirect:
        tiddler.tags = [redirect]
    
    if validate_url(tiddler):
        store.put(tiddler)
    
    return True
开发者ID:bengillies,项目名称:tiddlywebplugins.urls,代码行数:26,代码来源:twanager.py

示例4: init

def init(config):
    """
    init function for tiddlywebpages.
    Set URLs
    define serializers
    """
    merge_config(config, twp_config)

    # provide a way to allow people to refresh their URLs
    config["selector"].add("/tiddlywebpages/refresh", GET=refresh)

    # get the store
    store = get_store(config)

    # set the default config info
    BAG_OF_TEMPLATES = config["tw_pages"]["template_bag"]

    if "config" in config["tw_pages"]:
        register_config(config, store)

    for new_filter in config["tw_pages"]["filters"]:
        _temp = __import__(new_filter, {}, {}, [new_filter])
        TW_PAGES_FILTERS.append((new_filter, getattr(_temp, new_filter)))

    if "config" in config["tw_pages"]:
        register_config(config, store)
    register_templates(config, store)
开发者ID:bengillies,项目名称:TiddlyWeb-Plugins,代码行数:27,代码来源:__init__.py

示例5: 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

示例6: setup_module

def setup_module(module):
    if os.path.exists('store'):
        shutil.rmtree('store')
    init(config)
    module.savedin = sys.stdin
    module.store = get_store(config)
    module.store.put(Bag('bag1'))
开发者ID:bengillies,项目名称:tiddlywebplugins.csv,代码行数:7,代码来源:test_import_csv.py

示例7: twimport

 def twimport(args):
     """Import tiddlers, recipes, wikis, binary content: <bag> <URI>"""
     bag = args[0]
     urls = args[1:]
     if not bag or not urls:
         raise IndexError('missing args')
     import_list(bag, urls, get_store(config))
开发者ID:bengillies,项目名称:tiddlywebplugins.twimport,代码行数:7,代码来源:twimport.py

示例8: make_subscription

def make_subscription(email):
    """
    add somebody to a subscription
    """
    store = get_store(config)
    recipe = determine_bag(email['to'])
    fromAddress = email['from']
    subscription_bag = get_subscriptions_bag(store)
    subscribers_tiddler = Tiddler('bags/%s/tiddlers' % recipe, subscription_bag)
    try:
        subscribers_tiddler = store.get(subscribers_tiddler)
        subscriber_emails = subscribers_tiddler.text.splitlines()
        if fromAddress not in subscriber_emails:
            subscriber_emails.append(fromAddress)
        subscribers_tiddler.text = '\n'.join(subscriber_emails)
        store.put(subscribers_tiddler)
    except NoTiddlerError:
        subscribers_tiddler.text = fromAddress 
        store.put(subscribers_tiddler)

    return {'from': email['to'],
        'to': email['from'],
        'subject': 'You have subscribed to %s' % recipe,
        'body': 'You will now receive daily digests. To unsubscribe please email [email protected]%s'
    }
开发者ID:bengillies,项目名称:tiddlywebplugins.email,代码行数:25,代码来源:subscriptions.py

示例9: setup_module

def setup_module(module):
    try:
        shutil.rmtree('indexdir')
        shutil.rmtree('store')
    except:
        pass
    app = load_app()

    def app_fn(): return app

    requests_intercept.install()
    wsgi_intercept.add_wsgi_intercept('tankt.peermore.com', 8080, app_fn)

    store = get_store(config)
    test_bag1 = Bag('newtank')

    try:
        store.delete(test_bag1)
    except StoreError:
        pass

    test_bag1.policy.accept = ['NONE']
    store.put(test_bag1)
    module.environ = {'tiddlyweb.store': store, 'tiddlyweb.config': config}
    module.store = store
    module.cookie, module.csrf = establish_user_auth(config, store,
            'tankt.peermore.com:8080', 'tester')
开发者ID:BillSeitz,项目名称:tank,代码行数:27,代码来源:test_closet.py

示例10: determine_entries

def determine_entries(environ):
    """
    returns descendant resources based on the WSGI environment
    """
    candidates = { # XXX: hard-coded; ideally descendants should be determined via HATEOAS-y clues
        "[/]": lambda *args: [Collection("/bags"), Collection("/recipes")],
        "/bags[.{format}]": _bags,
        "/recipes[.{format}]": _recipes,
        "/bags/{bag_name:segment}/tiddlers[.{format}]": _tiddlers
    }

    current_uri = environ["SCRIPT_NAME"]
    config = environ["tiddlyweb.config"]
    store = get_store(config)
    router = Router(mapfile=config["urls_map"], prefix=config["server_prefix"]) # XXX: does not support extensions

    for regex, supported_methods in router.mappings:
        if regex.search(current_uri): # matching route
            pattern = router.routes[regex]
            descendants = candidates[pattern]
            routing_args = environ["wsgiorg.routing_args"]
            descendants = descendants(store, *routing_args[0], **routing_args[1])
            break

    return chain([Collection(current_uri)], descendants)
开发者ID:FND,项目名称:tiddlywebplugins.webdav,代码行数:25,代码来源:collections.py

示例11: setup_module

def setup_module(module):
    try:
        shutil.rmtree('store')
    except:
        pass
    config['markdown.wiki_link_base'] = ''
    store = get_store(config)

    environ['tiddlyweb.store'] = store

    store.put(Bag('bag'))
    module.store = store

    recipe = Recipe('recipe_public')
    recipe.set_recipe([('bag', '')])
    store.put(recipe)

    tiddlerA = Tiddler('tiddler a', 'bag')
    tiddlerA.text = 'I am _tiddler_'
    store.put(tiddlerA)

    tiddlerB = Tiddler('tiddler b')
    tiddlerB.text = '''
You wish

{{tiddler a}}

And I wish too.
'''
    module.tiddlerB = tiddlerB
开发者ID:FND,项目名称:tiddlywebplugins.markdown,代码行数:30,代码来源:test_transclusion.py

示例12: _init_store

    def _init_store(self, struct):
        """
        creates basic store structure with bags, recipes and users

        (no support for user passwords for security reasons)
        """
        store = get_store(self.init_config)

        bags = struct.get("bags", {})
        for name, data in bags.items():
            desc = data.get("desc")
            bag = Bag(name, desc=desc)
            constraints = data.get("policy", {})
            _set_policy(bag, constraints)
            store.put(bag)

        recipes = struct.get("recipes", {})
        for name, data in recipes.items():  # TODO: DRY
            desc = data.get("desc")
            recipe = Recipe(name, desc=desc)
            recipe.set_recipe(data["recipe"])
            constraints = data.get("policy", {})
            _set_policy(recipe, constraints)
            store.put(recipe)

        users = struct.get("users", {})
        for name, data in users.items():
            note = data.get("note")
            user = User(name, note=note)
            password = data.get("_password")
            if password:
                user.set_password(password)
            for role in data.get("roles", []):
                user.add_role(role)
            store.put(user)
开发者ID:FND,项目名称:tiddlywebplugins.imaker,代码行数:35,代码来源:imaker.py

示例13: setup_store

def setup_store():
    """
    initialise a blank store, and fill it with some data
    """
    store = get_store(config)
    for bag in BAGS:
        bag = Bag(bag)
        try:
            store.delete(bag)
        except NoBagError:
            pass
        
        store.put(bag)
    
    for recipe, contents in RECIPES.iteritems():
        recipe = Recipe(recipe)
        try:
            store.delete(recipe)
        except NoRecipeError:
            pass
        
        recipe.set_recipe(contents)
        store.put(recipe)
        
    return store
开发者ID:jdlrobson,项目名称:tiddlywebplugins.form,代码行数:25,代码来源:setup_test.py

示例14: wreindex

 def wreindex(args):
     """Rebuild the entire whoosh index."""
     try:
         prefix = args[0]
     except IndexError:
         prefix = None
     store = get_store(config)
     schema = config.get('wsearch.schema',
             SEARCH_DEFAULTS['wsearch.schema'])
     if __name__ in config.get('beanstalk.listeners', []):
         _reindex_async(config)
     else:
         for bag in store.list_bags():
             bag = store.get(bag)
             writer = get_writer(config)
             if writer:
                 try:
                     try:
                         tiddlers = bag.get_tiddlers()
                     except AttributeError:
                         tiddlers = store.list_bag_tiddlers(bag)
                     for tiddler in tiddlers:
                         if prefix and not tiddler.title.startswith(prefix):
                             continue
                         tiddler = store.get(tiddler)
                         index_tiddler(tiddler, schema, writer)
                     writer.commit()
                 except:
                     LOGGER.debug('whoosher: exception while indexing: %s',
                             format_exc())
                     writer.cancel()
             else:
                 LOGGER.debug('whoosher: unable to get writer '
                         '(locked) for %s', bag.name)
开发者ID:tiddlyweb,项目名称:tiddlywebplugins.whoosher,代码行数:34,代码来源:whoosher.py

示例15: test_cookie_set

def test_cookie_set():
    """
    test that we get a cookie relating to the space we are in
    """
    store = get_store(config)
    space = 'foo'
    make_fake_space(store, space)
    user = User('foo')
    user.set_password('foobar')
    store.put(user)

    user_cookie = get_auth('foo', 'foobar')

    response, content = http.request('http://foo.0.0.0.0:8080/status',
        method='GET',
        headers={
            'Cookie': 'tiddlyweb_user="%s"' % user_cookie
        })

    assert response['status'] == '200', content

    time = datetime.now().strftime('%Y%m%d%H')
    cookie = 'csrf_token=%s:%s:%s' % (time, user.usersign,
        sha('%s:%s:%s:%s' % (user.usersign,
        time, space, config['secret'])).hexdigest())
    assert response['set-cookie'] == cookie
开发者ID:Erls-Corporation,项目名称:tiddlyspace,代码行数:26,代码来源:test_post_validate.py


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