def test_maptags(): twanagerutils.init(config) setup_testdata() twanagerutils.lowertags(["tmp"]) twanagerutils.maptags(["tmp","cat=feline;kitty=feline;lion=feline;tiger=feline"]) filtered_felines = list(control.filter_tiddlers_from_bag(store.get(Bag("tmp")),"select=tag:feline")) assert len(filtered_felines) is 6
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_filter_bag_by_filter_string(): """ Confirm a bag will properly filter by string. """ filtered_tiddlers = control.filter_tiddlers_from_bag(bagfour, '[tag[tagone]]') assert len(filtered_tiddlers) == 2, \ 'filtering by title should result in one tiddler, got %s tiddlers' \ % len(filtered_tiddlers) filtered_tiddlers = control.filter_tiddlers_from_bag(bagfour, '[tag[tagone]] TiddlerTwo') assert len(filtered_tiddlers) == 3, \ 'filtering by title should result in one tiddler, got %s tiddlers' \ % len(filtered_tiddlers)
def test_filter_bag_by_filter(): """ Confirm a bag will properly filter. """ filtered_tiddlers = control.filter_tiddlers_from_bag(bagfour, 'select=title:TiddlerOne') assert len(filtered_tiddlers) == 1 assert filtered_tiddlers[0].title == 'TiddlerOne' filtered_tiddlers = control.filter_tiddlers_from_bag(bagfour, 'select=tag:tagone') assert len(filtered_tiddlers) == 2 filters, thing = parse_for_filters('select=tag:tagone;select=title:TiddlerThree') filtered_tiddlers = control.filter_tiddlers_from_bag(bagfour, filters) assert len(filtered_tiddlers) == 1 assert filtered_tiddlers[0].title == 'TiddlerThree'
def todos(args): """List the todos.""" store = get_store(global_config) bag = Bag('do') bag = store.get(bag) titles = [(tiddler.modified, tiddler.title) for tiddler in control.filter_tiddlers_from_bag(bag, 'sort=modified')] print '\n'.join(['%s: %s' % title for title in titles])
def tiddlyWebComments(context,*args): ctiddler = context.tiddler if ctiddler: comments = control.filter_tiddlers_from_bag(context.bag,"select=root:%s&sort=-created"%ctiddler.title) res = "" for comment in comments: res += "<div class='comment'><div class='heading'><div class='commentTitle'>comment</div></div><div class='commentText'>%s</div></div>"%comment.text return res
def test_filter_by_text_string_negate(): bag = Bag('bag0') bag = store.get(bag) bags_tiddlers = bag.list_tiddlers() assert len(bags_tiddlers) == 10 found_tiddlers = control.filter_tiddlers_from_bag(bag, '[!text[tiddler 0]]') assert len(found_tiddlers) == 9
def test_filter_tiddlers_from_bag(): """ Make sure a bag comes to life and filters as expect. """ bag = Bag('bag0') bag = store.get(bag) tiddlers = list(control.filter_tiddlers_from_bag(bag, 'select=tag:tagfour')) assert len(tiddlers) == 3
def test_filter_tiddlers_from_bag(): """ Make sure a bag comes to life and filters as expect. """ bag = Bag('bag0') bag = store.get(bag) tiddlers = control.filter_tiddlers_from_bag(bag, '[tag[tagfour]]') assert len(tiddlers) == 3, 'there are 3 tiddlers when filters on tagfour'
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)
def test_filter_by_text_string_negate(): bag = Bag('bag0') bag = store.get(bag) bags_tiddlers = bag.list_tiddlers() assert len(bags_tiddlers) == 10 found_tiddlers = list(control.filter_tiddlers_from_bag(bag, 'select=text:!tiddler 0')) assert len(found_tiddlers) == 9
def applyAndFilter(self,token): logging.debug("in applyAndFilter:") self.saveAndFilterArg(token) logging.debug("applyAndFilter: filter=%s"%self.filter) newtiddlers = control.filter_tiddlers_from_bag(self.bag,self.filter) for tiddler in newtiddlers: if tiddler not in self.final_tiddlers: self.final_tiddlers.append(tiddler) self.reset_args()
def test_filter_by_text(): bag = Bag('bag0') bag = store.get(bag) bags_tiddlers = bag.list_tiddlers() assert len(bags_tiddlers) == 10 found_tiddlers = list(control.filter_tiddlers_from_bag(bag, 'select=text:tiddler 0')) assert len(found_tiddlers) == 1 assert found_tiddlers[0].title == 'tiddler0'
def test_filter_by_text_string(): bag = Bag('bag0') bag = store.get(bag) bags_tiddlers = bag.list_tiddlers() assert len(bags_tiddlers) == 10 found_tiddlers = control.filter_tiddlers_from_bag(bag, '[text[tiddler 0]]') assert len(found_tiddlers) == 1 assert found_tiddlers[0].title == 'tiddler0'
def reporttime(args): """Report total time from bag: <bag>""" store = get_store(global_config) start_bag_name = "%s-start" % args[0] stop_bag_name = "%s-stop" % args[0] try: start_bag = store.get(Bag(start_bag_name)) start_tiddlers = control.filter_tiddlers_from_bag(start_bag, "sort=title") except NoBagError: start_tiddlers = [] try: stop_bag = store.get(Bag(stop_bag_name)) stop_tiddlers = control.filter_tiddlers_from_bag(stop_bag, "sort=title") except NoBagError: stop_tiddlers = [] starts = [int(tiddler.title) for tiddler in start_tiddlers] stops = [int(tiddler.title) for tiddler in stop_tiddlers] total_time = count_times(starts, stops) print "Total time: %s" % (float(total_time) / (60 * 60))
def test_filter_bag_by_filter(): """ Confirm a bag will properly filter. """ filtered_tiddlers = control.filter_tiddlers_from_bag(bagfour, filter.by_title, 'TiddlerOne') assert len(filtered_tiddlers) == 1, \ 'filtering by title should result in one tiddler, got %s tiddlers' \ % len(filtered_tiddlers) assert filtered_tiddlers[0].title == 'TiddlerOne', \ 'resulting tiddler should be TiddlerOne, is %s' \ % filtered_tiddlers[0].title
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)
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)
def send_tiddlers(environ, start_response, bag): """ Output the tiddlers contained in the provided bag in a Negotiated representation. Often, but not always, a wiki. """ last_modified = None etag = None download = environ["tiddlyweb.query"].get("download", [None])[0] filters = environ["tiddlyweb.filters"] try: tiddlers = control.filter_tiddlers_from_bag(bag, filters) except FilterError, exc: raise HTTP400("malformed filter: %s" % exc)
def get_thing_from_bag(environ, start_response): bagName = environ["wsgiorg.routing_args"][1]["bagName"] try: fieldName = environ["wsgiorg.routing_args"][1]["fieldName"] except KeyError: fieldName = "tags" try: limit = int(environ["tiddlyweb.query"]["max"][0]) except KeyError: limit = 0 store = environ["tiddlyweb.store"] bag = store.get(Bag(bagName)) tiddlers = control.filter_tiddlers_from_bag(bag, environ["tiddlyweb.filters"]) start_response("200 OK", [("Content-Type", "text/plain; charset=utf-8")]) return get_tags_from_bag(environ, tiddlers, fieldName, limit)
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)]
def applyORFilter(self,token): logging.debug("applyORFilter: apply or filter %s"%self.arg1) if self.arg1 == 'server.bag': self.arg1 = "bag" try: try: index = self.arg1.index("sort") logging.debug("applyORFilter: found index %s"%index) self.apply_sort() except ValueError: index = self.arg1.index("limit") self.apply_limit() except ValueError: newtiddlers = control.filter_tiddlers_from_bag(self.bag,"select=%s:%s"%(self.arg1,self.arg2)) for tiddler in newtiddlers: if tiddler not in self.final_tiddlers: self.final_tiddlers.append(tiddler) self.reset_args()
def get_tiddlers(environ, start_response): """ Get a list representation of the tiddlers in a bag. The information sent is dependent on the serialization chosen. """ 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)
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()
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)
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)) # then filter those tiddlers try: tiddlers = control.filter_tiddlers_from_bag(tmp_bag, filter_string) except FilterError, exc: raise HTTP400('malformed filter: %s' % exc) tmp_bag = Bag('tmp_bag2', tmpbag=True) # Make an optimization so we are not going # to the database to load the policies of # the same bag over and over. policies = {} for tiddler in tiddlers: bag_name = tiddler.bag try: policies[bag_name].allows(usersign, 'read') except KeyError: bag = Bag(tiddler.bag) bag = store.get(bag)