示例#1
0
文件: bag.py 项目: FND/tiddlyweb
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.
    """
    store = environ["tiddlyweb.store"]
    filters = environ["tiddlyweb.filters"]
    bag_name = web.get_route_value(environ, "bag_name")
    bag = _get_bag(environ, bag_name)
    title = "Tiddlers From Bag %s" % bag.name
    title = environ["tiddlyweb.query"].get("title", [title])[0]

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

    tiddlers = Tiddlers(title=title)
    if not filters:
        tiddlers.store = store
    tiddlers.bag = bag_name

    # A special bag can raise NoBagError here.
    try:
        for tiddler in store.list_bag_tiddlers(bag):
            tiddlers.add(tiddler)
    except NoBagError, exc:
        raise HTTP404("%s not found, %s" % (bag.name, exc))
示例#2
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.
    """
    store = environ['tiddlyweb.store']
    search_query = get_search_query(environ)
    title = 'Search for %s' % search_query
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    try:
        tiddlers = get_tiddlers(environ)

        usersign = environ['tiddlyweb.usersign']

        candidate_tiddlers = Tiddlers(title=title, store=store)
        candidate_tiddlers.is_search = True

        for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign):
            candidate_tiddlers.add(tiddler)

    except StoreMethodNotImplemented:
        raise HTTP400('Search system not implemented')
    except StoreError, exc:
        raise HTTP400('Error while processing search: %s' % exc)
def whoosher_search(environ, start_response):
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    search_query = get_search_query(environ)
    title = 'Search for %s' % search_query
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    try:
        tiddlers = whoosh_search(environ)

        usersign = environ['tiddlyweb.usersign']

        if filters:
            candidate_tiddlers = Tiddlers(title=title)
        else:
            candidate_tiddlers = Tiddlers(title=title, store=store)
        candidate_tiddlers.is_search = True

        for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign):
            candidate_tiddlers.add(tiddler)

    except StoreMethodNotImplemented:
        raise HTTP400('Search system not implemented')
    except StoreError as exc:
        raise HTTP400('Error while processing search: %s' % exc)

    return send_tiddlers(environ, start_response, tiddlers=candidate_tiddlers)
示例#4
0
def setup_module(module):
    module.bag = Bag(name='foobag')
    from fixtures import tiddlers as tids
# we need to copy tiddlers otherwise the test below which 
# messes with the contents of tiddlers screws with others tests
    module.tiddlers = copy.deepcopy(tids)
    container = Tiddlers()
    container.add(module.tiddlers[0])
    module.bag.tiddlers = container
示例#5
0
def setup_module(module):
    module.bag = Bag(name='foobag')
    from fixtures import tiddlers as tids
    # we need to copy tiddlers otherwise the test below which
    # messes with the contents of tiddlers screws with others tests
    module.tiddlers = copy.deepcopy(tids)
    container = Tiddlers()
    container.add(module.tiddlers[0])
    module.bag.tiddlers = container
示例#6
0
 def tiddler_as(self, tiddler):
     """
     Take the single tiddler provided and inject it into
     a TiddlyWiki.
     """
     tiddlers = Tiddlers(title=tiddler.title, bag=tiddler.bag,
             recipe=tiddler.recipe)
     tiddlers.add(tiddler)
     tiddlers.link = tiddler_url(self.environ, tiddler, full=False)
     # Join with '' to return a string not generator.
     return ''.join(self._put_tiddlers_in_tiddlywiki(tiddlers))
示例#7
0
def test_tiddler_collection():
    tiddlers = Tiddlers()
    n = 4
    for title in [u'how', u'now', u'cow']:
        n = n - 1
        tiddler = Tiddler(title, 'bag')
        tiddler.modified = n
        tiddlers.add(tiddler)
    modified = tiddlers.modified
    assert [u'how', u'now', u'cow'] == list(
            tiddler.title for tiddler in tiddlers)
    assert modified == '30000000000000'
def test_tiddler_collection():
    tiddlers = Tiddlers()
    n = 4
    for title in ['how', 'now', 'cow']:
        n = n - 1
        tiddler = Tiddler(title, 'bag')
        tiddler.modified = n 
        tiddlers.add(tiddler)
    digest = tiddlers.hexdigest()
    modified = tiddlers.modified
    assert ['how', 'now', 'cow'] == list(tiddler.title for tiddler in tiddlers)
    assert modified == '30000000000000'
示例#9
0
def send_tiddlers(environ, start_response, tiddlers=None):
    """
    Output the tiddlers contained in the provided
    Tiddlers collection 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']
    store = environ['tiddlyweb.store']

    if tiddlers.store is None and not filters:
        logging.warn('Incoming tiddlers no store set %s', inspect.stack()[1])

    if filters:
        candidate_tiddlers = Tiddlers(store=store)
        try:
            candidate_tiddlers.title = tiddlers.title
            candidate_tiddlers.link = tiddlers.link
            candidate_tiddlers.is_search = tiddlers.is_search
            candidate_tiddlers.is_revisions = tiddlers.is_revisions
        except AttributeError:
            pass
        try:
            for tiddler in recursive_filter(filters, tiddlers):
                candidate_tiddlers.add(tiddler)
        except FilterError, exc:
            raise HTTP400('malformed filter: %s' % exc)
示例#10
0
def _send_tiddler_revisions(environ, start_response, tiddler):
    """
    Push the list of tiddler revisions out the network.
    """
    store = environ['tiddlyweb.store']

    title = 'Revisions of Tiddler %s' % tiddler.title
    title = environ['tiddlyweb.query'].get('title', [title])[0]
    container = 'recipes' if tiddler.recipe else 'bags'

    if environ['tiddlyweb.filters']:
        tiddlers = Tiddlers(title=title)
    else:
        tiddlers = Tiddlers(title=title, store=store)

    tiddlers.is_revisions = True
    tiddlers.link = '%s/revisions' % web.tiddler_url(
        environ, tiddler, container=container, full=False)

    recipe = tiddler.recipe
    try:
        for revision in store.list_tiddler_revisions(tiddler):
            tmp_tiddler = Tiddler(title=tiddler.title, bag=tiddler.bag)
            tmp_tiddler.revision = revision
            if recipe:
                tmp_tiddler.recipe = recipe
            tiddlers.add(tmp_tiddler)
    except NoTiddlerError, exc:
        # If a tiddler is not present in the store.
        raise HTTP404('tiddler %s not found, %s' % (tiddler.title, exc))
示例#11
0
文件: tiddler.py 项目: tup/tiddlyweb
def _send_tiddler_revisions(environ, start_response, tiddler):
    """
    Push the list of tiddler revisions out the network.
    """
    store = environ['tiddlyweb.store']

    title = 'Revisions of Tiddler %s' % tiddler.title
    title = environ['tiddlyweb.query'].get('title', [title])[0]
    container = 'recipes' if tiddler.recipe else 'bags'

    if environ['tiddlyweb.filters']:
        tiddlers = Tiddlers(title=title)
    else:
        tiddlers = Tiddlers(title=title, store=store)

    tiddlers.is_revisions = True
    tiddlers.link = '%s/revisions' % tiddler_url(environ, tiddler,
            container=container, full=False)

    # Set the container on the tiddlers. Since tiddler.recipe
    # defaults to None, we're "safe" here.
    tiddlers.recipe = tiddler.recipe
    tiddlers.bag = tiddler.bag

    try:
        for revision in store.list_tiddler_revisions(tiddler):
            tmp_tiddler = Tiddler(title=tiddler.title, bag=tiddler.bag)
            tmp_tiddler.revision = revision
            tmp_tiddler.recipe = tiddler.recipe
            tiddlers.add(tmp_tiddler)
    except NoTiddlerError, exc:
        # If a tiddler is not present in the store.
        raise HTTP404('tiddler %s not found, %s' % (tiddler.title, exc))
示例#12
0
def public_stuff(environ, start_response):
    """
    A collection of the most recent stuff.
    A place where _all_ the content readable
    by the current user can be viewed.
    """
    user = get_user_object(environ)
    store = environ['tiddlyweb.store']
    kept_bags = get_stuff(store, store.list_bags(), user)
    tiddlers = Tiddlers()
    for bag in kept_bags:
        bag = store.get(bag)
        for tiddler in store.list_bag_tiddlers(bag):
            tiddlers.add(tiddler)
    return send_tiddlers(environ, start_response, tiddlers=tiddlers)
示例#13
0
def test_tiddlers_container():
    tiddlers = Tiddlers()

    assert not tiddlers.is_search
    assert not tiddlers.is_revisions
    assert not tiddlers.bag
    assert not tiddlers.recipe

    tiddlers = Tiddlers(bag='foobar')
    assert tiddlers.bag == 'foobar'
    assert not tiddlers.recipe

    tiddlers = Tiddlers(recipe='foobar')
    assert tiddlers.recipe == 'foobar'
    assert not tiddlers.bag
示例#14
0
def public_stuff(environ, start_response):
    """
    A collection of the most recent stuff.
    A place where _all_ the content readable
    by the current user can be viewed.
    """
    user = get_user_object(environ)
    store = environ['tiddlyweb.store']
    kept_bags = get_stuff(store, store.list_bags(), user)
    tiddlers = Tiddlers()
    for bag in kept_bags:
        bag = store.get(bag)
        for tiddler in store.list_bag_tiddlers(bag):
            tiddlers.add(tiddler)
    return send_tiddlers(environ, start_response, tiddlers=tiddlers)
示例#15
0
def test_content_type():
    bag = Bag('holder')
    bag = store.get(bag)
    tiddlers = Tiddlers(store=store)
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.add(tiddler)

    serializer = Serializer('tiddlywebwiki.serialization', {'tiddlyweb.config': config})
    output = ''.join(serializer.list_tiddlers(tiddlers))

    # we are expecting an img link to the image tiddler
    assert 'server.content-type="image/png"' in output

    # but we want just an html anchor link to the zero
    assert 'server.content-type="application/octet-stream"' in output

    assert 'server.content-type="text/html"' in output
def test_collection():
    tiddlers = Tiddlers()
    tiddler = Tiddler('foo', 'null')
    tiddler.text = 'bam'
    tiddler.modifier = 'cdent'
    tiddlers.add(tiddler)
    tiddler = Tiddler('bar', 'null')
    tiddler.text = 'zoom'
    tiddler.modifier = 'cdent'
    tiddlers.add(tiddler)

    output = serializer.list_tiddlers(tiddlers)

    assert '<name>cdent</name>' in output
    assert '<uri>http://0.0.0.0:8080/profiles/cdent</uri>' in output
    assert '<link href="http://pubsubhubbub.appspot.com/" rel="hub">' in output
    assert 'rel="avatar"' in output, output
示例#17
0
文件: bag.py 项目: funkyeah/tiddlyweb
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.
    """
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    bag_name = web.get_route_value(environ, 'bag_name')
    bag = _get_bag(environ, bag_name)
    title = 'Tiddlers From Bag %s' % bag.name
    title = environ['tiddlyweb.query'].get('title', [title])[0]

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

    if filters:
        tiddlers = Tiddlers(title=title)
    else:
        tiddlers = Tiddlers(title=title, store=store)
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.add(tiddler)

    tiddlers.link = '%s/tiddlers' % web.bag_url(environ, bag, full=False)

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)
示例#18
0
def send_tiddlers(environ, start_response, tiddlers=None):
    """
    Output the tiddlers contained in the provided
    Tiddlers collection 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']
    store = environ['tiddlyweb.store']

    if tiddlers.store is None and not filters:
        logging.warn('Incoming tiddlers no store set %s', inspect.stack()[1])

    if filters:
        candidate_tiddlers = Tiddlers(store=store)
        try:
            candidate_tiddlers.title = tiddlers.title
            candidate_tiddlers.link = tiddlers.link
            candidate_tiddlers.is_search = tiddlers.is_search
            candidate_tiddlers.is_revisions = tiddlers.is_revisions
        except AttributeError:
            pass
        try:
            for tiddler in recursive_filter(filters, tiddlers):
                candidate_tiddlers.add(tiddler)
        except FilterError, exc:
            raise HTTP400('malformed filter: %s' % exc)
示例#19
0
def send_tiddlers(environ, start_response, tiddlers=None):
    """
    Output the tiddlers contained in the provided
    Tiddlers collection 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']
    store = environ['tiddlyweb.store']

    if filters:
        candidate_tiddlers = Tiddlers(store=store)
        try:
            candidate_tiddlers.title = tiddlers.title
            candidate_tiddlers.is_search = tiddlers.is_search
            candidate_tiddlers.is_revisions = tiddlers.is_revisions
        except AttributeError:
            pass
        try:
            for tiddler in recursive_filter(filters, tiddlers):
                recipe = tiddler.recipe
                if not tiddler.store:
                    tiddler = store.get(tiddler)
                    if recipe:
                        tiddler.recipe = recipe
                candidate_tiddlers.add(tiddler)
        except FilterError, exc:
            raise HTTP400('malformed filter: %s' % exc)
示例#20
0
def test_content_type():
    bag = Bag('holder')
    bag = store.get(bag)
    tiddlers = Tiddlers(store=store)
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.add(tiddler)

    serializer = Serializer('tiddlywebwiki.serialization',
                            {'tiddlyweb.config': config})
    output = ''.join(serializer.list_tiddlers(tiddlers))

    # we are expecting an img link to the image tiddler
    assert 'server.content-type="image/png"' in output

    # but we want just an html anchor link to the zero
    assert 'server.content-type="application/octet-stream"' in output

    assert 'server.content-type="text/html"' in output
def test_tiddler_racing():
    bag = Bag('foo')
    store.put(bag)
    tiddlers = Tiddlers(store=store)

    for title in ['x', 'y', 'z']:
        tiddler = Tiddler(title, 'foo')
        store.put(tiddler)
        tiddlers.add(tiddler)

    tiddler = Tiddler('y', 'foo')
    store.delete(tiddler)

    tids = list(tiddlers)
    assert len(tids) == 2
    assert 'x' in [tiddler.title for tiddler in tids]
    assert 'z' in [tiddler.title for tiddler in tids]
    assert 'y' not in [tiddler.title for tiddler in tids]
示例#22
0
    def race_tiddlers(bag_name, count=2, intitles=['x', 'z'], outtitles=['y']):
        bag = Bag(bag_name)
        store.put(bag)
        tiddlers = Tiddlers(store=store)

        for title in ['x', 'y', 'z']:
            tiddler = Tiddler(title, 'foo')
            store.put(tiddler)
            tiddlers.add(tiddler)

        tiddler = Tiddler('y', 'foo')
        store.delete(tiddler)

        tids = list(tiddlers)
        assert len(tids) == count
        for title in intitles:
            assert title in [tiddler.title for tiddler in tids]
        for title in outtitles:
            assert title not in [tiddler.title for tiddler in tids]
示例#23
0
def _filter_tiddlers(filters, store, tiddlers):
    """
    Filter the tiddlers by filters provided by the environment.
    """
    candidate_tiddlers = Tiddlers(store=store)
    try:
        candidate_tiddlers.title = tiddlers.title
        candidate_tiddlers.link = tiddlers.link
        candidate_tiddlers.is_search = tiddlers.is_search
        candidate_tiddlers.is_revisions = tiddlers.is_revisions
        candidate_tiddlers.bag = tiddlers.bag
        candidate_tiddlers.recipe = tiddlers.recipe
    except AttributeError:
        pass
    try:
        for tiddler in recursive_filter(filters, tiddlers):
            candidate_tiddlers.add(tiddler)
    except FilterError as exc:
        raise HTTP400('malformed filter: %s' % exc)
    return candidate_tiddlers
示例#24
0
    def race_tiddlers(bag_name, count=2, intitles=['x', 'z'],
            outtitles=['y']):
        bag = Bag(bag_name)
        store.put(bag)
        tiddlers = Tiddlers(store=store)

        for title in ['x', 'y', 'z']:
            tiddler = Tiddler(title, 'foo')
            store.put(tiddler)
            tiddlers.add(tiddler)

        tiddler = Tiddler('y', 'foo')
        store.delete(tiddler)

        tids = list(tiddlers)
        assert len(tids) == count
        for title in intitles:
            assert title in [tid.title for tid in tids]
        for title in outtitles:
            assert title not in [tid.title for tid in tids]
示例#25
0
def get_tiddlers(environ, start_response):
    """
    Handle ``GET`` on a tiddlers-within-a-recipe URI.

    Get a list representation of the :py:class:`tiddlers
    <tiddlyweb.model.tiddler.Tiddler>` generated from a :py:class:`recipe
    <tiddlyweb.model.recipe.Recipe>`.

    The information sent is dependent on the serialization chosen
    via :py:mod:`tiddlyweb.web.negotiate`.
    """
    usersign = environ['tiddlyweb.usersign']
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    recipe = _determine_recipe(environ)
    title = 'Tiddlers From Recipe %s' % recipe.name
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    # check the recipe can be read
    recipe.policy.allows(usersign, 'read')

    # check the bags in the recipe can be read
    try:
        template = control.recipe_template(environ)
        for bag_name, _ in recipe.get_recipe(template):
            bag = Bag(bag_name)
            bag = store.get(bag)
            bag.policy.allows(usersign, 'read')
    except NoBagError as exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                      (recipe.name, exc))

    # from this point forward we know the tiddlers are
    # readable

    # get the tiddlers from the recipe and uniquify them
    try:
        candidate_tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    except NoBagError as exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                      (recipe.name, exc))
    except FilterError as exc:
        raise HTTP400('malformed filter: %s' % exc)

    tiddlers = Tiddlers(title=title)
    if not filters:
        tiddlers.store = store
    tiddlers.recipe = recipe.name

    for tiddler in candidate_tiddlers:
        tiddler.recipe = recipe.name
        tiddlers.add(tiddler)

    tiddlers.link = '%s/tiddlers' % web.recipe_url(environ, recipe, full=False)

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)
示例#26
0
def recent_changes(tiddler, environ):
    """
    Display recent changes for the wiki. RecentChanges is handled
    as a SPECIAL_PAGES, described below.

    Recent changes are simply the 30 most recently modified tiddlers
    from the recipe. We make a list of those tiddlers and provide
    them to the changes.html template.
    """
    # XXX to be strict we should do permissions checking
    # on the bags of all the tiddlers returned.
    store = environ["tiddlyweb.store"]
    recipe = _get_recipe(environ)
    recipe = store.get(Recipe(recipe))
    tiddlers = Tiddlers()
    for tiddler in control.get_tiddlers_from_recipe(recipe, environ):
        tiddlers.add(tiddler)
    tiddlers = control.filter_tiddlers(tiddlers, "sort=-modified;limit=30")
    template = get_template(environ, "changes.html")
    environ["tiddlyweb.title"] = "Recent Changes"
    return template.generate(tiddlers=(store.get(tiddler) for tiddler in tiddlers))
示例#27
0
def _send_tiddler_revisions(environ, start_response, tiddler):
    """
    Push the list of tiddler revisions out the network.
    """
    store = environ['tiddlyweb.store']

    title = 'Revisions of Tiddler %s' % tiddler.title
    title = environ['tiddlyweb.query'].get('title', [title])[0]
    tiddlers = Tiddlers(title=title, store=store)
    tiddlers.is_revisions = True
    recipe = tiddler.recipe
    try:
        for revision in store.list_tiddler_revisions(tiddler):
            tmp_tiddler = Tiddler(title=tiddler.title, bag=tiddler.bag)
            tmp_tiddler.revision = revision
            if recipe:
                tmp_tiddler.recipe = recipe
            tiddlers.add(tmp_tiddler)
    except NoTiddlerError, exc:
        # If a tiddler is not present in the store.
        raise HTTP404('tiddler %s not found, %s' % (tiddler.title, exc))
示例#28
0
def _send_tiddler_revisions(environ, start_response, tiddler):
    """
    Push the list of tiddler revisions out the network.
    """
    store = environ['tiddlyweb.store']

    title = 'Revisions of Tiddler %s' % tiddler.title
    title = environ['tiddlyweb.query'].get('title', [title])[0]
    tiddlers = Tiddlers(title=title, store=store)
    tiddlers.is_revisions = True
    recipe = tiddler.recipe
    try:
        for revision in store.list_tiddler_revisions(tiddler):
            tmp_tiddler = Tiddler(title=tiddler.title, bag=tiddler.bag)
            tmp_tiddler.revision = revision
            if recipe:
                tmp_tiddler.recipe = recipe
            tiddlers.add(tmp_tiddler)
    except NoTiddlerError, exc:
        # If a tiddler is not present in the store.
        raise HTTP404('tiddler %s not found, %s' % (tiddler.title, exc))
示例#29
0
文件: bag.py 项目: rdrake98/tiddlyweb
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.
    """
    store = environ['tiddlyweb.store']
    bag_name = _determine_bag_name(environ)
    bag = _get_bag(environ, bag_name)
    title = 'Tiddlers From Bag %s' % bag.name
    title = environ['tiddlyweb.query'].get('title', [title])[0]

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

    tiddlers = Tiddlers(title=title, store=store)
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.add(tiddler)

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)
示例#30
0
def send_tiddlers(environ, start_response, tiddlers=None):
    """
    Output the tiddlers contained in the provided
    Tiddlers collection 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']
    store = environ['tiddlyweb.store']

    if filters:
        candidate_tiddlers = Tiddlers(store=store)
        try:
            candidate_tiddlers.title = tiddlers.title
            candidate_tiddlers.is_search = tiddlers.is_search
            candidate_tiddlers.is_revisions = tiddlers.is_revisions
        except AttributeError:
            pass
        try:
            for tiddler in recursive_filter(filters, tiddlers):
                recipe = tiddler.recipe
                if not tiddler.store:
                    tiddler = store.get(tiddler)
                    if recipe:
                        tiddler.recipe = recipe
                candidate_tiddlers.add(tiddler)
        except FilterError, exc:
            raise HTTP400('malformed filter: %s' % exc)
示例#31
0
def _send_tiddler_revisions(environ, start_response, tiddler):
    """
    Push the list of tiddler revisions out the network.
    """
    store = environ['tiddlyweb.store']

    title = 'Revisions of Tiddler %s' % tiddler.title
    title = environ['tiddlyweb.query'].get('title', [title])[0]
    container = 'recipes' if tiddler.recipe else 'bags'

    if environ['tiddlyweb.filters']:
        tiddlers = Tiddlers(title=title)
    else:
        tiddlers = Tiddlers(title=title, store=store)

    tiddlers.is_revisions = True
    tiddlers.link = '%s/revisions' % tiddler_url(environ, tiddler,
            container=container, full=False)

    # Set the container on the tiddlers. Since tiddler.recipe
    # defaults to None, we're "safe" here.
    tiddlers.recipe = tiddler.recipe
    tiddlers.bag = tiddler.bag

    try:
        for revision in store.list_tiddler_revisions(tiddler):
            tmp_tiddler = Tiddler(title=tiddler.title, bag=tiddler.bag)
            tmp_tiddler.revision = revision
            tmp_tiddler.recipe = tiddler.recipe
            tiddlers.add(tmp_tiddler)
    except NoTiddlerError as exc:
        # If a tiddler is not present in the store.
        raise HTTP404('tiddler %s not found, %s' % (tiddler.title, exc))
    except NoBagError as exc:
        raise HTTP404('tiddler %s not found, bag %s does not exist, %s'
                % (tiddler.title, tiddler.bag, exc))
    except StoreMethodNotImplemented:
        raise HTTP400('no revision support')

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)
def test_content_type():
    bag = Bag('holder')
    bag = store.get(bag)
    tiddlers = Tiddlers(store=store)
    # duplicate what the handler would do
    tiddlers.link = bag_url({'tiddlyweb.config': config}, bag,
            full=False) + '/tiddlers'
    for tiddler in store.list_bag_tiddlers(bag):
        tiddlers.add(tiddler)

    serializer = Serializer('tiddlywebwiki.serialization',
            {'tiddlyweb.config': config})
    output = ''.join(serializer.list_tiddlers(tiddlers))

    # we are expecting an img link to the image tiddler
    assert 'server.content-type="image/png"' in output

    # but we want just an html anchor link to the zero
    assert 'server.content-type="application/octet-stream"' in output

    assert 'server.content-type="text/html"' in output
    assert ('you may still <a href="/bags/holder/tiddlers">browse' in output)
示例#33
0
def _filter_tiddlers(filters, store, tiddlers):
    """
    Filter the tiddlers by filters provided by the enviornment.
    """
    candidate_tiddlers = Tiddlers(store=store)
    try:
        candidate_tiddlers.title = tiddlers.title
        candidate_tiddlers.link = tiddlers.link
        candidate_tiddlers.is_search = tiddlers.is_search
        candidate_tiddlers.is_revisions = tiddlers.is_revisions
        candidate_tiddlers.bag = tiddlers.bag
        candidate_tiddlers.recipe = tiddlers.recipe
    except AttributeError:
        pass
    try:
        for tiddler in recursive_filter(filters, tiddlers):
            candidate_tiddlers.add(tiddler)
    except FilterError, exc:
        raise HTTP400('malformed filter: %s' % exc)
示例#34
0
def get_tiddlers(environ, start_response):
    """
    Handle ``GET`` on a tiddlers-within-a-recipe URI.

    Get a list representation of the :py:class:`tiddlers
    <tiddlyweb.model.tiddler.Tiddler>` generated from a :py:class:`recipe
    <tiddlyweb.model.recipe.Recipe>`.

    The information sent is dependent on the serialization chosen
    via :py:mod:`tiddlyweb.web.negotiate`.
    """
    usersign = environ['tiddlyweb.usersign']
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    recipe = _determine_recipe(environ)
    title = 'Tiddlers From Recipe %s' % recipe.name
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    # check the recipe can be read
    recipe.policy.allows(usersign, 'read')

    # check the bags in the recipe can be read
    try:
        template = control.recipe_template(environ)
        for bag_name, _ in recipe.get_recipe(template):
            bag = Bag(bag_name)
            bag = store.get(bag)
            bag.policy.allows(usersign, 'read')
    except NoBagError as exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                (recipe.name, exc))

    # from this point forward we know the tiddlers are
    # readable

    # get the tiddlers from the recipe and uniquify them
    try:
        candidate_tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    except NoBagError as exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                (recipe.name, exc))
    except FilterError as exc:
        raise HTTP400('malformed filter: %s' % exc)

    tiddlers = Tiddlers(title=title)
    if not filters:
        tiddlers.store = store
    tiddlers.recipe = recipe.name

    for tiddler in candidate_tiddlers:
        tiddler.recipe = recipe.name
        tiddlers.add(tiddler)

    tiddlers.link = '%s/tiddlers' % web.recipe_url(environ, recipe,
            full=False)

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)
示例#35
0
def get(environ, start_response):
    """
    Handle ``GET`` on the search URI.

    Perform a search against the :py:class:`store <tiddlyweb.store.Store>`.

    What search means and what results are returned is dependent
    on the search implementation (if any) in the :py:class:`chosen store
    <tiddlyweb.stores.StorageInterface>`.
    """
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    search_query = get_search_query(environ)
    title = 'Search for %s' % search_query
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    try:
        tiddlers = get_tiddlers(environ)

        usersign = environ['tiddlyweb.usersign']

        if filters:
            candidate_tiddlers = Tiddlers(title=title)
        else:
            candidate_tiddlers = Tiddlers(title=title, store=store)
        candidate_tiddlers.is_search = True

        for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign):
            candidate_tiddlers.add(tiddler)

    except StoreMethodNotImplemented:
        raise HTTP400('Search system not implemented')
    except StoreError as exc:
        raise HTTP400('Error while processing search: %s' % exc)

    return send_tiddlers(environ, start_response, tiddlers=candidate_tiddlers)
示例#36
0
def test_collection():
    tiddlers = Tiddlers()
    tiddler = Tiddler('foo', 'null')
    tiddler.text = 'bam'
    tiddler.modifier = 'cdent'
    tiddlers.add(tiddler)
    tiddler = Tiddler('bar', 'null')
    tiddler.text = 'zoom'
    tiddler.modifier = 'cdent'
    tiddlers.add(tiddler)

    output = serializer.list_tiddlers(tiddlers)

    assert '<name>cdent</name>' in output
    assert '<uri>http://0.0.0.0:8080/profiles/cdent</uri>' in output
    assert '<link href="http://pubsubhubbub.appspot.com/" rel="hub">' in output
    assert 'rel="avatar"' in output, output
示例#37
0
def get_tiddlers(environ, start_response):
    """
    Handle ``GET`` on a tiddlers-within-a-bag URI.

    Get a list representation of the :py:class:`tiddlers
    <tiddlyweb.model.tiddler.Tiddler>` in a :py:class:`bag
    <tiddlyweb.model.bag.Bag>`.

    The information sent is dependent on the serialization chosen
    via :py:mod:`tiddlyweb.web.negotiate`.
    """
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    bag_name = web.get_route_value(environ, 'bag_name')
    bag = _get_bag(environ, bag_name)
    title = 'Tiddlers From Bag %s' % bag.name
    title = environ['tiddlyweb.query'].get('title', [title])[0]

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

    tiddlers = Tiddlers(title=title)
    if not filters:
        tiddlers.store = store
    tiddlers.bag = bag_name

    # A special bag can raise NoBagError here.
    try:
        for tiddler in store.list_bag_tiddlers(bag):
            tiddlers.add(tiddler)
    except NoBagError as exc:
        raise HTTP404('%s not found, %s' % (bag.name, exc))

    tiddlers.link = '%s/tiddlers' % web.bag_url(environ, bag, full=False)

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)
示例#38
0
文件: search.py 项目: sgml/tiddlyweb
def get(environ, start_response):
    """
    Handle ``GET`` on the search URI.

    Perform a search against the :py:class:`store <tiddlyweb.store.Store>`.

    What search means and what results are returned is dependent
    on the search implementation (if any) in the :py:class:`chosen store
    <tiddlyweb.stores.StorageInterface>`.
    """
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    search_query = get_search_query(environ)
    title = 'Search for %s' % search_query
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    try:
        tiddlers = get_tiddlers(environ)

        usersign = environ['tiddlyweb.usersign']

        if filters:
            candidate_tiddlers = Tiddlers(title=title)
        else:
            candidate_tiddlers = Tiddlers(title=title, store=store)
        candidate_tiddlers.is_search = True

        for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign):
            candidate_tiddlers.add(tiddler)

    except StoreMethodNotImplemented:
        raise HTTP400('Search system not implemented')
    except StoreError as exc:
        raise HTTP400('Error while processing search: %s' % exc)

    return send_tiddlers(environ, start_response, tiddlers=candidate_tiddlers)
示例#39
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.
    """
    store = environ['tiddlyweb.store']
    search_query = get_search_query(environ)
    title = 'Search for %s' % search_query
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    try:
        tiddlers = get_tiddlers(environ)

        usersign = environ['tiddlyweb.usersign']

        candidate_tiddlers = Tiddlers(title=title, store=store)
        candidate_tiddlers.is_search = True

        bag_readable = {}

        for tiddler in tiddlers:
            try:
                if bag_readable[tiddler.bag]:
                    candidate_tiddlers.add(tiddler)
            except KeyError:
                bag = Bag(tiddler.bag)
                bag = store.get(bag)
                try:
                    bag.policy.allows(usersign, 'read')
                    candidate_tiddlers.add(tiddler)
                    bag_readable[tiddler.bag] = True
                except(ForbiddenError, UserRequiredError):
                    bag_readable[tiddler.bag] = False
    except StoreMethodNotImplemented:
        raise HTTP400('Search system not implemented')
    except StoreError, exc:
        raise HTTP400('Error while processing search: %s' % exc)
示例#40
0
文件: bag.py 项目: 24king/tiddlyweb
def get_tiddlers(environ, start_response):
    """
    Handle ``GET`` on a tiddlers-within-a-bag URI.

    Get a list representation of the :py:class:`tiddlers
    <tiddlyweb.model.tiddler.Tiddler>` in a :py:class:`bag
    <tiddlyweb.model.bag.Bag>`.

    The information sent is dependent on the serialization chosen
    via :py:mod:`tiddlyweb.web.negotiate`.
    """
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    bag_name = web.get_route_value(environ, 'bag_name')
    bag = _get_bag(environ, bag_name)
    title = 'Tiddlers From Bag %s' % bag.name
    title = environ['tiddlyweb.query'].get('title', [title])[0]

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

    tiddlers = Tiddlers(title=title)
    if not filters:
        tiddlers.store = store
    tiddlers.bag = bag_name

    # A special bag can raise NoBagError here.
    try:
        for tiddler in store.list_bag_tiddlers(bag):
            tiddlers.add(tiddler)
    except NoBagError as exc:
        raise HTTP404('%s not found, %s' % (bag.name, exc))

    tiddlers.link = '%s/tiddlers' % web.bag_url(environ, bag, full=False)

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)
示例#41
0
TiddlerTwo.modifier = u'AuthorTwo'
TiddlerTwo.text = u'b tiddler two content'

TiddlerThree = Tiddler('TiddlerThree')
TiddlerThree.modifier = u'AuthorThree'
TiddlerThree.text = u'a tiddler three content'
TiddlerThree.tags = [u'tagone', u'tagthree']

tiddlers = [TiddlerOne, TiddlerTwo, TiddlerThree]

bagone = Bag(name='bagone')
bagtwo = Bag(name='bagtwo')
bagthree = Bag(name='bagthree')
bagfour = Bag(name='bagfour')

tiddler_collection = Tiddlers()
for tiddler in tiddlers:
    tiddler.bag = u'bagfour'
    tiddler_collection.add(tiddler)


def initialize_app():
    app = load_app()

    def app_fn():
        return app

    httplib2_intercept.install()
    wsgi_intercept.add_wsgi_intercept('our_test_domain', 8001, app_fn)

示例#42
0
                      (recipe.name, exc))

    # from this point forward we know the tiddlers are
    # readable

    # get the tiddlers from the recipe and uniquify them
    try:
        candidate_tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    except NoBagError, exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                      (recipe.name, exc))
    except FilterError, exc:
        raise HTTP400('malformed filter: %s' % exc)

    if filters:
        tiddlers = Tiddlers(title=title)
    else:
        tiddlers = Tiddlers(title=title, store=store)

    for tiddler in candidate_tiddlers:
        tiddler.recipe = recipe.name
        tiddlers.add(tiddler)

    tiddlers.link = '%s/tiddlers' % web.recipe_url(environ, recipe, full=False)

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)


def list_recipes(environ, start_response):
    """
    Get a list of all recipes the current user can read.
示例#43
0
文件: recipe.py 项目: FND/tiddlyweb
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                (recipe.name, exc))

    # from this point forward we know the tiddlers are
    # readable

    # get the tiddlers from the recipe and uniquify them
    try:
        candidate_tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    except NoBagError, exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                (recipe.name, exc))
    except FilterError, exc:
        raise HTTP400('malformed filter: %s' % exc)

    tiddlers = Tiddlers(title=title)
    if not filters:
        tiddlers.store = store
    tiddlers.recipe = recipe.name

    for tiddler in candidate_tiddlers:
        tiddler.recipe = recipe.name
        tiddlers.add(tiddler)

    tiddlers.link = '%s/tiddlers' % web.recipe_url(environ, recipe,
            full=False)

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)


def list_recipes(environ, start_response):
示例#44
0
                (recipe.name, exc))

    # from this point forward we know the tiddlers are
    # readable

    # get the tiddlers from the recipe and uniquify them
    try:
        candidate_tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    except NoBagError, exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                (recipe.name, exc))
    except FilterError, exc:
        raise HTTP400('malformed filter: %s' % exc)

    if filters:
        tiddlers = Tiddlers(title=title)
    else:
        tiddlers = Tiddlers(title=title, store=store)

    for tiddler in candidate_tiddlers:
        tiddler.recipe = recipe.name
        tiddlers.add(tiddler)

    tiddlers.link = '%s/tiddlers' % web.recipe_url(environ, recipe,
            full=False)

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)


def list_recipes(environ, start_response):
    """
    host_tiddler = Tiddler(tiddler_title, bag_name)
    try:
        host_tiddler = store.get(host_tiddler)
    except StoreError, exc:
        raise HTTP404('No such tiddler: %s:%s, %s' % (host_tiddler.bag,
            host_tiddler.title, exc))

    links_manager = LinksManager(environ)

    try:
        links = getattr(links_manager, 'read_%s' % linktype)(host_tiddler)
    except AttributeError, exc:
        raise HTTP400('invalid links type: %s' % exc)

    if filters:
        tiddlers = Tiddlers(title=collection_title)
    else:
        tiddlers = Tiddlers(title=collection_title, store=store)
    tiddlers.link = link

    # continue over entries in database from previous format
    for link in links:
        if is_link(link):  # external link
            continue
        else:
            container, title = link.split(':', 1)
            if not title:  # plain space link
                continue
            elif title:
                if container != bag_name:
                    if container.endswith('_public'):
示例#46
0
            bag.policy.allows(usersign, 'read')
    except NoBagError, exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                      (recipe.name, exc))

    # from this point forward we know the tiddlers are
    # readable

    # get the tiddlers from the recipe and uniquify them
    try:
        candidate_tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    except NoBagError, exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                      (recipe.name, exc))

    tiddlers = Tiddlers(title=title, store=store)

    for tiddler in candidate_tiddlers:
        tiddler.recipe = recipe.name
        tiddlers.add(tiddler)

    return send_tiddlers(environ, start_response, tiddlers=tiddlers)


def list_recipes(environ, start_response):
    """
    Get a list of all recipes the current user can read.
    """
    store = environ['tiddlyweb.store']
    serialize_type, mime_type = web.get_serialize_type(environ)
    serializer = Serializer(serialize_type, environ)
示例#47
0
TiddlerOne.text = u'c tiddler one content'
TiddlerOne.tags = ['tagone', 'tagtwo']

TiddlerTwo = Tiddler('TiddlerTwo')
TiddlerTwo.modifier = u'AuthorTwo'
TiddlerTwo.text = u'b tiddler two content'

TiddlerThree = Tiddler('TiddlerThree')
TiddlerThree.modifier = u'AuthorThree'
TiddlerThree.text = u'a tiddler three content'
TiddlerThree.tags = [u'tagone', u'tagthree']

tiddlers = [TiddlerOne, TiddlerTwo, TiddlerThree]

bagone = Bag(name='bagone')
container = Tiddlers()
container.add(tiddlers[0])
bagone.tiddlers = container

bagtwo = Bag(name='bagtwo')
container = Tiddlers()
container.add(tiddlers[1])
bagtwo.tiddlers = container

bagthree = Bag(name='bagthree')
container = Tiddlers()
container.add(tiddlers[2])
bagthree.tiddlers = container

bagfour = Bag(name='bagfour')
container = Tiddlers()
示例#48
0
    # Get the list of core plugins
    core_plugin_tiddler_titles = _get_core_plugins(store)

    # Delete those plugins in the space's recipes which
    # duplicate the core plugins
    recipe = _delete_duplicates(environ, core_plugin_tiddler_titles,
            recipe_name, space_name)

    # Process the recipe. For those tiddlers which do not have a bag
    # in CORE_RECIPE, remove the systemConfig tag.
    try:
        candidate_tiddlers = control.get_tiddlers_from_recipe(recipe, environ)
    except NoBagError, exc:
        raise HTTP404('recipe %s lists an unknown bag: %s' %
                (recipe.name, exc))
    tiddlers_to_send = Tiddlers()
    for tiddler in candidate_tiddlers:
        if not tiddler.store:
            tiddler = store.get(tiddler)
        if tiddler.bag not in [recipe_bag for
                recipe_bag, _ in Space.CORE_RECIPE]:
            if 'systemConfig' in tiddler.tags:
                tiddler.tags.append('systemConfigDisable')
        tiddler.recipe = recipe.name
        tiddlers_to_send.add(tiddler)

    _, mime_type = get_serialize_type(environ)
    if 'text/html' in mime_type or 'x-www-form' in environ['tiddlyweb.type']:
        environ['tiddlyweb.type'] = 'text/x-tiddlywiki'
    return send_tiddlers(environ, start_response, tiddlers=tiddlers_to_send)
    tiddler = Tiddler(tiddler_title, bag_name)
    try:
        tiddler = store.get(tiddler)
    except StoreError, exc:
        raise HTTP404('No such tiddler: %s:%s, %s' % (tiddler.bag,
            tiddler.title, exc))

    links_manager = LinksManager(environ)

    try:
        links = getattr(links_manager, 'read_%s' % linktype)(tiddler)
    except AttributeError, exc:
        raise HTTP400('invalid links type: %s' % exc)

    if filters:
        tiddlers = Tiddlers(title=title)
    else:
        tiddlers = Tiddlers(title=title, store=store)

    for link in links:
        if is_link(link):
            tiddler = Tiddler(link, 'temp')
            tiddler.text = link
            tiddler.fields['_canonical_uri'] = link
            tiddler.store = store
        else:
            container, title = link.split(':', 1)
            if title:  # skip space links for now
                try:
                    recipe = Recipe(container)
                    recipe = store.get(recipe)
示例#50
0
TiddlerOne.text = u'c tiddler one content'
TiddlerOne.tags = ['tagone', 'tagtwo']

TiddlerTwo = Tiddler('TiddlerTwo')
TiddlerTwo.modifier = u'AuthorTwo'
TiddlerTwo.text = u'b tiddler two content'

TiddlerThree = Tiddler('TiddlerThree')
TiddlerThree.modifier = u'AuthorThree'
TiddlerThree.text = u'a tiddler three content'
TiddlerThree.tags = [u'tagone', u'tagthree']

tiddlers = [TiddlerOne, TiddlerTwo, TiddlerThree]

bagone = Bag(name='bagone')
container = Tiddlers()
container.add(tiddlers[0])
bagone.tiddlers = container

bagtwo = Bag(name='bagtwo')
container = Tiddlers()
container.add(tiddlers[1])
bagtwo.tiddlers = container

bagthree = Bag(name='bagthree')
container = Tiddlers()
container.add(tiddlers[2])
bagthree.tiddlers = container

bagfour = Bag(name='bagfour')
container = Tiddlers()
示例#51
0
    def list_tiddlers(self, tiddlers):
        """
        Turn the contents of a Tiddlers into an Atom Feed.
        """

        authors = set()
        try:
            from tiddlyweb.model.collections import Tiddlers
            config = self.environ['tiddlyweb.config']
            default_filter = config['atom.default_filter']
            filters, _ = parse_for_filters(default_filter, self.environ)
            new_tiddlers = Tiddlers()
            new_tiddlers.is_search = tiddlers.is_search
            new_tiddlers.is_revisions = tiddlers.is_revisions
            new_tiddlers.bag = tiddlers.bag
            new_tiddlers.recipe = tiddlers.recipe
            new_tiddlers.link = tiddlers.link
            for tiddler in recursive_filter(filters, tiddlers):
                new_tiddlers.add(tiddler)
                authors.add(tiddler.modifier)
            new_tiddlers.title = tiddlers.title
            new_tiddlers.is_search = tiddlers.is_search
            new_tiddlers.is_revisions = tiddlers.is_revisions
            tiddlers = new_tiddlers
        except (KeyError, ImportError):
            pass

        author_name = None
        author_link = None
        author_avatar = None
        if len(authors) == 1:
            author_name = authors.pop()
            author_link = self._get_author_link(author_name)
            author_avatar = self._get_author_avatar(author_name)

        hub = self.environ.get('tiddlyweb.config', {}).get('atom.hub', None)

        if tiddlers.link:
            link = tiddlers.link
        else:
            link = self._current_url()
        if not link.startswith('http'):
            link = u'%s%s' % (self._host_url(), link)

        feed = AtomFeed(link=link,
            language=u'en',
            hub=hub,
            author_name=author_name,
            author_link=author_link,
            author_avatar=author_avatar,
            title=tiddlers.title,
            description=tiddlers.title)

        for tiddler in tiddlers:
            self._add_tiddler_to_feed(feed, tiddler)

        # can we avoid sending utf-8 and let the wrapper handle it?
        return feed.writeString('utf-8')