Esempio n. 1
0
def profile_listing_tiddlers():
    store = Store('text', environ=environ)
    environ['tiddlyweb.store'] = store

    bag = Bag('profiler')
    bag.skinny = True
    store.get(bag)

    print 'filter', time()
    filter_string = 'select=tag:100'
    filters, leftovers = parse_for_filters(filter_string, environ)
    tiddlers = control.filter_tiddlers_from_bag(bag, filters)

    print 'tmp bag', time()
    tmp_bag = Bag('tmp_bag', tmpbag=True)
    tmp_bag.add_tiddlers(tiddlers)

    print 'output', time()
    print[tiddler.title for tiddler in control.get_tiddlers_from_bag(tmp_bag)]

    #print 'serializer', time()
    #serializer = Serializer('wiki', environ)
    #print 'wikify', time()
    #output = serializer.list_tiddlers(tmp_bag)

    print 'done', time()
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
Esempio n. 3
0
def tagged_tiddlers(environ, start_response):
    store = environ['tiddlyweb.store']
    bag_name = unicode(urllib.unquote(environ['wsgiorg.routing_args'][1]['bag_name']), 'utf-8')
    tag_name = unicode(urllib.unquote(environ['wsgiorg.routing_args'][1]['tag_name']), 'utf-8')
    bag = store.get(Bag(bag_name))
    tmp_bag = Bag('tmpbag', tmpbag=True)
    tmp_bag.add_tiddlers(control.filter_tiddlers_from_bag(bag, 'select=tag:%s' % tag_name))

    return send_tiddlers(environ, start_response, tmp_bag)
Esempio n. 4
0
    def get_tiddlers_bag_for_recipe(self,recipe_name):
        store = self.environ['tiddlyweb.store'] 
        recipe = store.get(Recipe(recipe_name))
        list_tiddlers = control.get_tiddlers_from_recipe(recipe)
    
        tiddlers = []

        tempbag = Bag("tempbag",tmpbag=True)
    
        tempbag.add_tiddlers(list_tiddlers)
        return tempbag
Esempio n. 5
0
def get(environ, start_response):
    """
    Perform a search on the store. What search
    means and what results are returned is dependent
    on the search implementation (if any) in the
    chosen store.
    """
    try:
        search_query = environ['tiddlyweb.query']['q'][0]
        search_query = urllib.unquote(search_query)
        search_query = unicode(search_query, 'utf-8')
    except (KeyError, IndexError):
        raise HTTP400('query string required')

    filters = environ['tiddlyweb.filters']

    store = environ['tiddlyweb.store']
    try:
        tiddlers = store.search(search_query)
    except StoreMethodNotImplemented:
        raise HTTP400('Search system not implemented')

    usersign = environ['tiddlyweb.usersign']

# It's necessary to get the tiddler off the store
# in case we are doing wiki or atom outputs of the
# search.
    tmp_bag = Bag('tmp_bag', tmpbag=True, searchbag=True)
    bag_readable = {}

    for tiddler in tiddlers:
        try:
            if bag_readable[tiddler.bag]:
                tmp_bag.add_tiddler(store.get(tiddler))
        except KeyError:
            bag = Bag(tiddler.bag)
            bag.skinny = True
            bag = store.get(bag)
            try:
                bag.policy.allows(usersign, 'read')
                tmp_bag.add_tiddler(store.get(tiddler))
                bag_readable[tiddler.bag] = True
            except(ForbiddenError, UserRequiredError):
                bag_readable[tiddler.bag] = False

    if len(filters):
        tiddlers = control.filter_tiddlers_from_bag(tmp_bag, filters)
        tmp_bag = Bag('tmp_bag', tmpbag=True)
        tmp_bag.add_tiddlers(tiddlers)

    return send_tiddlers(environ, start_response, tmp_bag)
Esempio n. 6
0
def user_page(environ, start_response): 
    print(environ)
    name = environ['wsgiorg.routing_args'][1].get('name', 'default')
    recipe = Recipe('tmp')
    recipe.set_recipe([
        [name, '']
   	     ]) 
    # establish the store on the recipe so that get_tiddlers_from_recipe
    # will load the bags and their tiddler lists from the store
    recipe.store = environ['tiddlyweb.store']
    tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    bag = Bag('tmp', tmpbag=True)
    bag.add_tiddlers(tiddlers)
    return send_tiddlers(environ, start_response, bag)
Esempio n. 7
0
def tagged_tiddlers(environ, start_response):
    store = environ['tiddlyweb.store']
    bag_name = unicode(
        urllib.unquote(environ['wsgiorg.routing_args'][1]['bag_name']),
        'utf-8')
    tag_name = unicode(
        urllib.unquote(environ['wsgiorg.routing_args'][1]['tag_name']),
        'utf-8')
    bag = store.get(Bag(bag_name))
    tmp_bag = Bag('tmpbag', tmpbag=True)
    tmp_bag.add_tiddlers(
        control.filter_tiddlers_from_bag(bag, 'select=tag:%s' % tag_name))

    return send_tiddlers(environ, start_response, tmp_bag)
Esempio n. 8
0
def dyna(environ, start_response):
    name = environ['wsgiorg.routing_args'][1].get('name', 'default')
    username = environ['tiddlyweb.usersign']['name']
    recipe = Recipe('tmp')
    recipe.set_recipe([
        [BASE_BAG_NAME, ''],
        [name, ''],
        [username, '']
        ])
    # establish the store on the recipe so that get_tiddlers_from_recipe
    # will load the bags and their tiddler lists from the store
    recipe.store = environ['tiddlyweb.store']
    tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    bag = Bag('tmp', tmpbag=True)
    bag.add_tiddlers(tiddlers)
    return send_tiddlers(environ, start_response, bag)
Esempio n. 9
0
def profile_listing_tiddlers():
    store = Store('text', environ=environ)
    environ['tiddlyweb.store'] = store

    bag = Bag('profiler')
    bag.skinny = True
    store.get(bag)

    print 'filter', time()
    filter_string = 'select=tag:100'
    filters, leftovers = parse_for_filters(filter_string, environ)
    tiddlers = control.filter_tiddlers_from_bag(bag, filters)

    print 'tmp bag', time()
    tmp_bag = Bag('tmp_bag', tmpbag=True)
    tmp_bag.add_tiddlers(tiddlers)

    print 'output', time()
    print [tiddler.title for tiddler in control.get_tiddlers_from_bag(tmp_bag)]
Esempio n. 10
0
def get_tiddlers(environ, start_response):
    """
    Get the list of tiddlers produced by this
    recipe.
    """
    filter_string = web.filter_query_string(environ)
    usersign = environ['tiddlyweb.usersign']
    store = environ['tiddlyweb.store']
    recipe = _determine_recipe(environ)

    recipe.policy.allows(usersign, 'read')

    # get the tiddlers from the recipe and uniquify them
    try:
        tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
        tmp_bag = Bag('tmp_bag1', tmpbag=True)
        tmp_bag.add_tiddlers(tiddlers)
    except NoBagError, exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' % (recipe.name, exc))
    def pass_through_external_serializer(self, name, tiddlers):
        """
        The specified template has not been found, so assume it
        is a different serializer that has ended up here due to
        content-type confusion, or has been specified as a sub-
        template within another template.

        Passes the serializer name into the Serializer base class
        so that it is rendered by the correct serializer and 
        returns the output.
        """
        serializer_module = self.environ['tiddlyweb.config']['serializers'].get(self.environ['tiddlyweb.config']['extension_types'].get(name))[0]
        serializer = Serializer(serializer_module, self.environ)
        
        if (type(tiddlers) != Tiddler):
            bag = Bag('tmpBag', tmpbag=True)
            bag.add_tiddlers(tiddlers)
        try:
            serializer.object = tiddlers
            return serializer.to_string()
        except AttributeError:
            return serializer.list_tiddlers(bag)
Esempio n. 12
0
def tiddlers(context, *args):
    base = context.var_get_text("$BASE_URL")
    path = ""

    if not context.environ:
        return ""
    else:
        environ = context.environ

    store = get_store(config)

    tid = context.tiddler
    if tid.recipe:
        tids = control.get_tiddlers_from_recipe(store.get(Recipe(tid.recipe)))
    elif tid.bag:
        bag = store.get(Bag(tid.bag))
        tids = list(bag.list_tiddlers())
    else:
        return u""

    tiddlerTemplate = args[0].text
    templateText = ""
    for tid in tids:
        tid = store.get(tid)
        if tid.title == tiddlerTemplate:
            templateText = tid.text
    p = parseParams(args)
    if "filter" in p:
        filterBag = Bag("filter", tmpbag=True)
        filterBag.add_tiddlers(tids)
        filtered_tiddlers = filter_tiddlers(filterBag, p["filter"])
        output = u""
        for filtered_tiddler in filtered_tiddlers:
            output += u"%s" % wikitext_to_wikklyhtml(
                base, path, templateText, environ, tiddler=filtered_tiddler)
        return "<html>%s</html>" % output
    else:
        return u""
Esempio n. 13
0
def test_simple_put():
    """
    put a tiddler to disk and make sure it is there.
    """
    bagone = Bag('bagone')
    bagone.add_tiddlers(tiddlers)

    store.put(bagone)
    tiddler = bagone.list_tiddlers()[0]
    print tiddler.revision
    tiddler.tags = ['tagone', 'tagtwo', 'tag five']
    tiddler.modified = '200803030303'
    store.put(tiddler)

    if type(store.storage) != Texter:
        py.test.skip('skipping this test for non-text store')
    
    assert os.path.exists(expected_stored_filename)

    f = file(expected_stored_filename)
    text = f.read()

    assert text == expected_stored_text
    def pass_through_external_serializer(self, name, tiddlers):
        """
        The specified template has not been found, so assume it
        is a different serializer that has ended up here due to
        content-type confusion, or has been specified as a sub-
        template within another template.

        Passes the serializer name into the Serializer base class
        so that it is rendered by the correct serializer and 
        returns the output.
        """
        serializer_module = self.environ['tiddlyweb.config']['serializers'].get(
            self.environ['tiddlyweb.config']['extension_types'].get(name))[0]
        serializer = Serializer(serializer_module, self.environ)

        if (type(tiddlers) != Tiddler):
            bag = Bag('tmpBag', tmpbag=True)
            bag.add_tiddlers(tiddlers)
        try:
            serializer.object = tiddlers
            return serializer.to_string()
        except AttributeError:
            return serializer.list_tiddlers(bag)
Esempio n. 15
0
def tiddlers(context, *args):
    base = context.var_get_text("$BASE_URL")
    path = ""
    
    if not context.environ:
        return ""
    else:
      environ = context.environ
    
    store = get_store(config)
    
    tid = context.tiddler
    if tid.recipe:
        tids = control.get_tiddlers_from_recipe(store.get(Recipe(tid.recipe)))
    elif tid.bag:
        bag = store.get(Bag(tid.bag))
        tids = list(bag.list_tiddlers())
    else:
        return u""
    
    tiddlerTemplate = args[0].text
    templateText = ""  
    for tid in tids:
        tid = store.get(tid)
        if tid.title == tiddlerTemplate:
            templateText = tid.text
    p = parseParams(args)
    if "filter" in p:
        filterBag = Bag("filter",tmpbag=True)
        filterBag.add_tiddlers(tids)
        filtered_tiddlers = filter_tiddlers(filterBag,p["filter"])
        output = u""
        for filtered_tiddler in filtered_tiddlers:
            output += u"%s"%wikitext_to_wikklyhtml(base,path, templateText, environ,tiddler=filtered_tiddler)
        return "<html>%s</html>"%output
    else:
        return u""
Esempio n. 16
0
def profile_listing_tiddlers():
    store = Store('text', environ=environ)

    bag = Bag('profiler')
    store.get(bag)

    print 'filter', time()
    #filter_string = '[sort[modified]]'
    filter_string = ''
    tiddlers = control.filter_tiddlers_from_bag(bag, filter_string)

    print 'tmp bag', time()
    tmp_bag = Bag('tmp_bag', tmpbag=True)
    tmp_bag.add_tiddlers(tiddlers)

    #print 'output', time()
    #print ['.' for tiddler in control.get_tiddlers_from_bag(tmp_bag)]

    print 'serializer', time()
    serializer = Serializer('wiki', environ)
    print 'wikify', time()
    output = serializer.list_tiddlers(tmp_bag)

    print 'done', time()
Esempio n. 17
0
 def apply_sort(self):
   bag = Bag("tmp",tmpbag=True)
   bag.add_tiddlers(self.final_tiddlers)
   tiddlers = control.filter_tiddlers_from_bag(bag,'sort=%s'%self.arg2) 
   self.final_tiddlers = list(tiddlers)
Esempio n. 18
0
    """
    filters = environ["tiddlyweb.filters"]

    bag_name = _determine_bag_name(environ)
    bag = _get_bag(environ, bag_name)

    usersign = environ["tiddlyweb.usersign"]
    # will raise exception if there are problems
    bag.policy.allows(usersign, "read")

    try:
        tiddlers = control.filter_tiddlers_from_bag(bag, filters)
    except FilterError, exc:
        raise HTTP400("malformed filter: %s" % exc)
    tmp_bag = Bag("tmp_bag", tmpbag=True)
    tmp_bag.add_tiddlers(tiddlers)

    return send_tiddlers(environ, start_response, tmp_bag)


def import_wiki(environ, start_response):
    """
    Accept a tiddlywiki as POST and using it as the source
    parse it for tiddlers to be stored in the named bag.
    """
    bag_name = _determine_bag_name(environ)
    bag = _get_bag(environ, bag_name, True)
    length = environ["CONTENT_LENGTH"]
    content = environ["wsgi.input"].read(int(length))

    bag.policy.allows(environ["tiddlyweb.usersign"], "create")