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 get_urls(url_bag, store): """ retrieve a list of selector/destination pairs based on the tiddlers in the url bag """ bag = Bag(url_bag) bag = store.get(bag) tiddlers = get_tiddlers_from_bag(bag) return (tiddler for tiddler in tiddlers)
def test_get_tiddlers_from_bag(): """ Make sure a bag comes to life as expected. """ bag = Bag('bag0') bag = store.get(bag) tiddlers = list(control.get_tiddlers_from_bag(bag)) assert len(tiddlers) == 10, 'there are 10 tiddlers in bag0' text = '' for tiddler in tiddlers: text += tiddler.text assert 'i am tiddler 4' in text, 'we got some of the right text'
def test_get_tiddlers_from_bag(): """ Make sure a bag comes to life as expected. """ bag = Bag('bag0') bag = store.get(bag) tiddlers = list(control.get_tiddlers_from_bag(bag)) assert len(tiddlers) == 10 text = '' for tiddler in tiddlers: store.get(tiddler) text += tiddler.text assert 'i am tiddler 4' in text
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(control.get_tiddlers_from_bag(bag), environ['tiddlyweb.filters']) start_response('200 OK', [ ('Content-Type', 'text/plain; charset=utf-8') ]) return "\n".join(survey_field_values(environ,tiddlers,fieldName,limit))
def register_urls(store, config): """ add all the urls in the urls bag to selector """ url_bag = config['url_bag'] selector = config['selector'] bag = Bag(url_bag) try: bag = store.get(bag) except NoBagError: logging.debug('tiddlywebplugins.urls Error: No bag found for urls. Please create bag \"%s\".' % url_bag) raise NoBagError tiddlers = get_tiddlers_from_bag(bag) for tiddler in tiddlers: register_url(selector, tiddler)
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 register_templates(config, store): """ get the templates out of the store, register them as extensions- types and serializers with TiddlyWeb, and put them into environ ready for use. """ #get the templates out of the store bag = Bag(BAG_OF_TEMPLATES) bag = store.get(bag) tiddlers = control.get_tiddlers_from_bag(bag) #register them in config config['tw_pages_serializers'] = {} for tiddler in tiddlers: try: extensionType = tiddler.fields.pop('mime_type') if extensionType not in DEFAULT_TEMPLATES: config['serializers'][extensionType] = ['tiddlywebpages.serialization','%s; charset=UTF-8' % extensionType] except KeyError: extensionType = 'application/twpages' if tiddler.title != 'Default': config['extension_types'][tiddler.title] = extensionType try: page_title = tiddler.fields.pop('page_title') except KeyError: page_title = None try: wrapper = tiddler.fields.pop('wrapper') except KeyError: wrapper = None config['tw_pages_serializers'][tiddler.title] = { 'title': page_title, 'type': extensionType, 'plugins': tiddler.fields, 'template': tiddler.text, 'wrapper': wrapper } #finally, set the serializers for mime_type in DEFAULT_TEMPLATES: config['serializers'][mime_type] = ['tiddlywebpages.serialization','text/html; charset=UTF-8']
def _no_script(self, url): """ returns static HTML representation of a list of tiddlers """ try: static_index = self.environ["tiddlyweb.config"]["static_index"] except KeyError: # default static_index = default_static_index store = self.environ["tiddlyweb.store"] routing_args = self.environ["wsgiorg.routing_args"][1] try: # recipe recipe = routing_args["recipe_name"] recipe = Recipe(recipe) recipe = store.get(recipe) tiddlers = control.get_tiddlers_from_recipe(recipe, self.environ) except KeyError: # bag bag = routing_args["bag_name"] bag = Bag(bag) bag = store.get(bag) tiddlers = control.get_tiddlers_from_bag(bag) tiddlers = dict([(tiddler.title, tiddler) for tiddler in tiddlers]) static_tiddlers = [] try: index_tiddler = tiddlers[static_index] for title in _read_bracketed_list(index_tiddler.text): tiddler = tiddlers.get(title) try: text = render_wikitext(tiddler, self.environ) static_tiddlers.append(tiddler_template % (tiddler.title, text)) except AttributeError: # tiddler does not exist pass except KeyError: # static_index tiddler does not exist pass intro = super(Serialization, self)._no_script(url) return "%s\n%s" % (intro, "\n".join(static_tiddlers))
def test_bags_tiddlers(): for i in xrange(50): store.put(Tiddler(str(i), 'bagone')) bag = store.get(Bag('bagone')) tiddlers = list(control.get_tiddlers_from_bag(bag)) assert len(tiddlers) == 51
def _tags_for_bag(bag): tiddlers = control.get_tiddlers_from_bag(bag) tags = set() for tiddler in tiddlers: tags.update(set(tiddler.tags)) return tags