Exemplo n.º 1
0
def test_interleaved_tiddler_revisions():
    bag_name = u"bag8"
    for i in xrange(20):
        tiddler1 = Tiddler(u"oh yes", bag_name)
        tiddler2 = Tiddler(u"oh no", bag_name)
        tiddler1.text = u"%s times we yes" % i
        tiddler2.text = u"%s times we no" % i
        tiddler1.fields[u"%s" % i] = u"%s" % i
        tiddler2.fields[u"%s" % i] = u"%s" % i
        store.put(tiddler1)
        store.put(tiddler2)

    revisions = store.list_tiddler_revisions(Tiddler("oh yes", bag_name))
    assert len(revisions) == 20
    first_revision = revisions[-1]
    tiddler = Tiddler("oh yes", bag_name)
    tiddler.revision = first_revision + 26
    tiddler = store.get(tiddler)
    assert tiddler.title == "oh yes"
    assert tiddler.text == "13 times we yes"
    assert tiddler.fields["13"] == "13"
    assert "12" not in tiddler.fields

    tiddler.revision = 90
    py.test.raises(NoTiddlerError, "store.get(tiddler)")

    py.test.raises(NoTiddlerError, 'store.list_tiddler_revisions(Tiddler("sleepy", "cow"))')
Exemplo n.º 2
0
def migrate_bags(source, target, bags=None):
    print "migrate bags"
    if bags:
        bags = [Bag(bag) for bag in bags]
    else:
        bags = source.list_bags()

    for bag in bags:
        bag = source.get(bag)
        try:
            tiddlers = bag.list_tiddlers()
        except AttributeError:
            tiddlers = source.list_bag_tiddlers(bag)
        target.put(bag)
        for tiddler in tiddlers:
            for revision_id in reversed(
                    source.list_tiddler_revisions(tiddler)):
                tiddler_revision = Tiddler(tiddler.title, tiddler.bag)
                tiddler_revision.revision = revision_id
                tiddler_revision = source.get(tiddler_revision)
                print "putting tiddler %s:%s in bag %s" % (
                    tiddler_revision.title.encode('utf-8'),
                    tiddler_revision.revision,
                    tiddler_revision.bag.encode('utf-8'))
                tiddler_revision.revision = None
                target.put(tiddler_revision)
def test_tiddler_revisions():
    bag_name = u'bag8'
    for i in xrange(20):
        tiddler = Tiddler(u'oh hi', bag_name)
        tiddler.text = u'%s times we go' % i
        tiddler.fields[u'%s' % i] = u'%s' % i
        tiddler.fields[u'other%s' % i] = u'%s' % i
        tiddler.fields[u'carutther%s' % i] = u'x%s' % i
        store.put(tiddler)

    revisions = store.list_tiddler_revisions(Tiddler('oh hi', bag_name))
    assert len(revisions) == 20
    first_revision = revisions[-1]
    tiddler = Tiddler(u'oh hi', bag_name)
    tiddler.revision = first_revision + 13
    tiddler = store.get(tiddler)
    assert tiddler.title == 'oh hi'
    assert tiddler.text == '13 times we go'
    assert tiddler.fields['13'] == '13'
    assert tiddler.fields['other13'] == '13'
    assert tiddler.fields['carutther13'] == 'x13'
    assert '12' not in tiddler.fields

    tiddler.revision = 90
    py.test.raises(NoTiddlerError, 'store.get(tiddler)')

    py.test.raises(NoTiddlerError,
            'store.list_tiddler_revisions(Tiddler(u"sleepy", u"cow"))')
Exemplo n.º 4
0
def test_interleaved_tiddler_revisions():
    bag_name = u'bag8'
    for i in xrange(20):
        tiddler1 = Tiddler(u'oh yes', bag_name)
        tiddler2 = Tiddler(u'oh no', bag_name)
        tiddler1.text = u'%s times we yes' % i
        tiddler2.text = u'%s times we no' % i
        tiddler1.fields[u'%s' % i] = u'%s' % i
        tiddler2.fields[u'%s' % i] = u'%s' % i
        store.put(tiddler1)
        store.put(tiddler2)

    revisions = store.list_tiddler_revisions(Tiddler(u'oh yes', bag_name))
    assert len(revisions) == 20
    first_revision = revisions[-1]
    tiddler = Tiddler(u'oh yes', bag_name)
    tiddler.revision = first_revision + 26
    tiddler = store.get(tiddler)
    assert tiddler.title == 'oh yes'
    assert tiddler.text == '13 times we yes'
    assert tiddler.fields['13'] == '13'
    assert '12' not in tiddler.fields

    tiddler.revision = 9999999  # big number to avoid auto increment issues
    py.test.raises(NoTiddlerError, 'store.get(tiddler)')

    py.test.raises(NoTiddlerError,
                   'store.list_tiddler_revisions(Tiddler(u"sleepy", u"cow"))')
Exemplo n.º 5
0
 def _process_tiddler_revisions(self, feed, tiddler, link, do_revisions):
     try:
         from tiddlywebplugins.differ import compare_tiddlers
     except ImportError:
         self._add_item(feed, tiddler, link, tiddler.title,
                 'unable to diff without tiddlywebplugins.differ')
     try:
         depth = int(do_revisions)
     except ValueError:
         depth = 1
     store = self.environ['tiddlyweb.store']
     revision_ids = store.list_tiddler_revisions(tiddler)
     while depth >= 0:
         try:
             rev_older = Tiddler(tiddler.title, tiddler.bag)
             rev_older.revision = revision_ids[depth + 1]
             rev_older = store.get(rev_older)
         except IndexError:
             depth -= 1
             continue
         rev_current = Tiddler(tiddler.title, tiddler.bag)
         rev_current.revision = revision_ids[depth]
         rev_current = store.get(rev_current)
         if binary_tiddler(tiddler):
             self._add_item(feed, tiddler, link, tiddler.title,
                     'Binary Content')
         else:
             title = '%s comparing version %s to %s' % (tiddler.title,
                     rev_older.revision, rev_current.revision)
             self._add_item(feed, rev_current, link, title,
                     '<pre>' + compare_tiddlers(rev_older, rev_current)
                     + '</pre>')
         depth -= 1
def test_interleaved_tiddler_revisions():
    bag_name = u'bag8'
    for i in xrange(20):
        tiddler1 = Tiddler(u'oh yes', bag_name)
        tiddler2 = Tiddler(u'oh no', bag_name)
        tiddler1.text = u'%s times we yes' % i
        tiddler2.text = u'%s times we no' % i
        tiddler1.fields[u'%s' % i] = u'%s' % i
        tiddler2.fields[u'%s' % i] = u'%s' % i
        store.put(tiddler1)
        store.put(tiddler2)

    revisions = store.list_tiddler_revisions(Tiddler('oh yes', bag_name))
    assert len(revisions) == 20
    first_revision = revisions[-1]
    tiddler = Tiddler('oh yes', bag_name)
    tiddler.revision = first_revision + 26 
    tiddler = store.get(tiddler)
    assert tiddler.title == 'oh yes'
    assert tiddler.text == '13 times we yes'
    assert tiddler.fields['13'] == '13'
    assert '12' not in tiddler.fields

    tiddler.revision = 9999999 # big number to avoid auto increment issues
    py.test.raises(NoTiddlerError, 'store.get(tiddler)')

    py.test.raises(NoTiddlerError,
            'store.list_tiddler_revisions(Tiddler(u"sleepy", u"cow"))')
Exemplo n.º 7
0
def migrate_bags(source, target, bags=None):
    """
    Migrate all the bags unless the bags are is set. If it is
    then it is assumed to be a list of bags to migrate. Useful
    for migrating just one bag.
    """
    print "migrate bags"
    if bags:
        bags = [Bag(bag) for bag in bags]
    else:
        bags = source.list_bags()

    for bag in bags:
        bag = source.get(bag)
        try:
            tiddlers = bag.list_tiddlers()
        except AttributeError:
            tiddlers = source.list_bag_tiddlers(bag)
        target.put(bag)
        for tiddler in tiddlers:
            for revision_id in reversed(
                    source.list_tiddler_revisions(tiddler)):
                tiddler_revision = Tiddler(tiddler.title, tiddler.bag)
                tiddler_revision.revision = revision_id
                tiddler_revision = source.get(tiddler_revision)
                print "putting tiddler %s:%s in bag %s" % (
                        tiddler_revision.title.encode('utf-8'),
                        tiddler_revision.revision,
                        tiddler_revision.bag.encode('utf-8'))
                tiddler_revision.revision = None
                target.put(tiddler_revision)
Exemplo n.º 8
0
def test_tiddler_revisions():
    bag_name = u'bag8'
    for i in xrange(20):
        tiddler = Tiddler(u'oh hi', bag_name)
        tiddler.text = u'%s times we go' % i
        tiddler.fields[u'%s' % i] = u'%s' % i
        tiddler.fields[u'other%s' % i] = u'%s' % i
        tiddler.fields[u'carutther%s' % i] = u'x%s' % i
        store.put(tiddler)

    revisions = store.list_tiddler_revisions(Tiddler(u'oh hi', bag_name))
    assert len(revisions) == 20
    first_revision = revisions[-1]
    tiddler = Tiddler(u'oh hi', bag_name)
    tiddler.revision = first_revision + 13
    tiddler = store.get(tiddler)
    assert tiddler.title == 'oh hi'
    assert tiddler.text == '13 times we go'
    assert tiddler.fields['13'] == '13'
    assert tiddler.fields['other13'] == '13'
    assert tiddler.fields['carutther13'] == 'x13'
    assert '12' not in tiddler.fields

    tiddler.revision = 90
    py.test.raises(NoTiddlerError, 'store.get(tiddler)')

    py.test.raises(NoTiddlerError,
                   'store.list_tiddler_revisions(Tiddler(u"sleepy", u"cow"))')
Exemplo n.º 9
0
def test_revision_get():
    bag = Bag('alpha')
    STORE.put(bag)

    # create a bunch of revisions
    tiddler_data = [
        { 'text': 'hello world', 'tags': ['foo'] },
        { 'text': 'lorem ipsum', 'tags': ['foo', 'bar'] },
        { 'text': 'lorem ipsum\ndolor sit amet', 'tags': [] }
    ]
    for tid in tiddler_data:
        tiddler = Tiddler('Foo', bag.name)
        tiddler.text = tid['text']
        tiddler.tags = tid['tags']
        STORE.put(tiddler)
        tid['revision'] = tiddler.revision

    tiddler = Tiddler('Foo', bag.name)
    tiddler.revision = None
    tiddler = STORE.get(tiddler)
    assert tiddler.text == 'lorem ipsum\ndolor sit amet'
    assert len(tiddler.tags) == 0

    for i, tid in enumerate(tiddler_data):
        tiddler = Tiddler('Foo', bag.name)
        tiddler.revision = tid['revision']
        tiddler = STORE.get(tiddler)
        assert tiddler.text == tid['text']
        assert len(tiddler.revision) == 10
        assert len(tiddler.tags) == len(tid['tags'])

    tiddler = Tiddler('Foo', bag.name)
    tiddler.revision = 'N/A'
    with raises(NoTiddlerError):
        STORE.get(tiddler)
Exemplo n.º 10
0
def migrate_bags(source, target):
    print "migrate bags"
    for bag in source.list_bags():
        bag = source.get(bag)
        tiddlers = bag.list_tiddlers()
        target.put(bag)
        for tiddler in tiddlers:
            for revision_id in reversed(source.list_tiddler_revisions(tiddler)):
                tiddler_revision = Tiddler(tiddler.title, tiddler.bag)
                tiddler_revision.revision = revision_id
                tiddler_revision = source.get(tiddler_revision)
                print "putting tiddler %s:%s in bag %s" % (tiddler_revision.title.encode('utf-8'), tiddler_revision.revision, tiddler_revision.bag.encode('utf-8'))
                tiddler_revision.revision = None
                target.put(tiddler_revision)
Exemplo n.º 11
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))
def test_delete_gets_revisions():
    """this relies on the previous test"""
    removed = Tiddler('tiddler1', 'holder')
    store.delete(removed)
    revision = Tiddler('tiddler1', 'holder')
    revision.revision = 2
    py.test.raises(NoTiddlerError, 'store.get(revision)')
Exemplo n.º 13
0
    def add(self, tiddler):
        """
        Add a reference to the tiddler to the container,
        updating the digest and modified information.
        """
        self._update_digest(tiddler)

        if self.store:
            reference = Tiddler(tiddler.title, tiddler.bag)
            if tiddler.revision:
                reference.revision = tiddler.revision
            if tiddler.recipe:
                reference.recipe = tiddler.recipe

            self._container.append(reference)
        else:
            self._container.append(tiddler)

        try:
            modified_string = str(tiddler.modified)
            modified_string = modified_string.ljust(14, '0')
            if modified_string > self.modified:
                self.modified = modified_string
        except AttributeError:
            pass
Exemplo n.º 14
0
def test_delete_gets_revisions():
    """this relies on the previous test"""
    removed = Tiddler('tiddler1', 'holder')
    store.delete(removed)
    revision = Tiddler('tiddler1', 'holder')
    revision.revision = 2
    py.test.raises(NoTiddlerError, 'store.get(revision)')
Exemplo n.º 15
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))
Exemplo n.º 16
0
 def add(self, tiddler):
     """
     Add a reference to the tiddler to the container,
     updating the digest and modified information. If
     the tiddler has recently been deleted, resulting
     in a StoreError, simply don't add it.
     """
     if not tiddler.store and self.store:
         try:
             tiddler = self.store.get(tiddler)
         except StoreError, exc:
             LOGGER.debug(
                     'tried to add missing tiddler to collection: %s, %s',
                     tiddler, exc)
             return
         if not self.store.environ['tiddlyweb.config'].get(
                 'collections.use_memory', False):
             reference = Tiddler(tiddler.title, tiddler.bag)
             if tiddler.revision:
                 reference.revision = tiddler.revision
             if tiddler.recipe:
                 reference.recipe = tiddler.recipe
             self._container.append(reference)
         else:
             self._container.append(tiddler)
Exemplo n.º 17
0
 def add(self, tiddler):
     """
     Add a reference to the :py:class:`tiddler
     <tiddlyweb.model.tiddler.Tiddler>` to the container, updating the
     digest and modified information. If the tiddler has recently been
     deleted, resulting in a :py:class:`StoreError
     <tiddlyweb.store.StoreError>`, don't add it.
     """
     if not tiddler.store and self.store:
         try:
             tiddler = self.store.get(tiddler)
         except StoreError as exc:
             LOGGER.debug(
                     'tried to add missing tiddler to collection: %s, %s',
                     tiddler, exc)
             return
         if not self.store.environ['tiddlyweb.config'].get(
                 'collections.use_memory', False):
             reference = Tiddler(tiddler.title, tiddler.bag)
             if tiddler.revision:
                 reference.revision = tiddler.revision
             if tiddler.recipe:
                 reference.recipe = tiddler.recipe
             self._container.append(reference)
         else:
             self._container.append(tiddler)
     else:
         self._container.append(tiddler)
     self._update_digest(tiddler)
     modified_string = str(tiddler.modified)
     modified_string = modified_string.ljust(14, '0')
     if modified_string > self.modified:
         self.modified = modified_string
Exemplo n.º 18
0
def test_get_revision():
    """
    Test we are able to retrieve a particular revision.
    """
    bagone = Bag('bagone')

    store.put(bagone)
    tiddler = Tiddler('RevisionTiddler')
    tiddler.text = 'how now 1'
    tiddler.bag = u'bagone'
    store.put(tiddler)
    tiddler.text = 'how now 2'
    store.put(tiddler)
    tiddler.text = 'how now 3'
    store.put(tiddler)

    tiddler = Tiddler('RevisionTiddler', 'bagone')
    tiddler = store.get(tiddler)

    assert tiddler.text == 'how now 3'
    assert tiddler.revision == 3

    tiddler = Tiddler('RevisionTiddler', '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
def test_revision_type_bug():
    tiddler = Tiddler('testtwo', 'pone')
    tiddler.text = u'testone'
    store.put(tiddler)
    store.put(tiddler)

    # Invalid revision
    tiddler.revision = 'I have a monkey'
    py.test.raises(NoTiddlerError, 'tiddler = store.get(tiddler)')
Exemplo n.º 20
0
def test_revision_type_bug():
    tiddler = Tiddler("testtwo", "pone")
    tiddler.text = u"testone"
    store.put(tiddler)
    store.put(tiddler)

    # Invalid revision
    tiddler.revision = "I have a monkey"
    py.test.raises(NoTiddlerError, "tiddler = store.get(tiddler)")
Exemplo n.º 21
0
def migrate_bags(source, target, bags=None):
    print "migrate bags"
    if bags:
        bags = [Bag(bag) for bag in bags]
    else:
        bags = source.list_bags()

    for bag in bags:
        bag = source.get(bag)
        try:
            tiddlers = bag.list_tiddlers()
        except AttributeError:
            tiddlers = source.list_bag_tiddlers(bag)
        target.put(bag)
        for tiddler in tiddlers:
            for revision_id in reversed(source.list_tiddler_revisions(tiddler)):
                tiddler_revision = Tiddler(tiddler.title, tiddler.bag)
                tiddler_revision.revision = revision_id
                tiddler_revision = source.get(tiddler_revision)
                print "putting tiddler %s:%s in bag %s" % (tiddler_revision.title.encode('utf-8'), tiddler_revision.revision, tiddler_revision.bag.encode('utf-8'))
                tiddler_revision.revision = None
                target.put(tiddler_revision)
Exemplo n.º 22
0
def test_tiddler_revision_create():
    """
    Confirm that when we set revision in a new Tiddler,
    we are able to retrieve that attribute.
    """

    tiddler = Tiddler('test tiddler r')
    tiddler.text = 'revision test'
    tiddler.revision = 5

    assert type(tiddler) == Tiddler, \
            'Tiddler returns a Tiddler'
    assert tiddler.revision == 5, \
            'revision is set as expected, to 5'
def test_revision_bug():
    store.put(Bag('pone'))
    tiddler = Tiddler('testone', 'pone')
    tiddler.text = u'testone'
    store.put(tiddler)
    tiddler = Tiddler('testtwo', 'pone')
    tiddler.text = u'testtwo'
    store.put(tiddler)

    tiddler = store.get(tiddler)
    tiddler_rev = Tiddler('testone', 'pone')
    tiddler_rev.revision = tiddler.revision

    py.test.raises(NoTiddlerError, 'tiddler_rev = store.get(tiddler_rev)')
Exemplo n.º 24
0
def test_revision_bug():
    store.put(Bag("pone"))
    tiddler = Tiddler("testone", "pone")
    tiddler.text = u"testone"
    store.put(tiddler)
    tiddler = Tiddler("testtwo", "pone")
    tiddler.text = u"testtwo"
    store.put(tiddler)

    tiddler = store.get(tiddler)
    tiddler_rev = Tiddler("testone", "pone")
    tiddler_rev.revision = tiddler.revision

    py.test.raises(NoTiddlerError, "tiddler_rev = store.get(tiddler_rev)")
Exemplo n.º 25
0
def _require_valid_etag_for_write(environ, tiddler):
    """
    Unless there is an etag and it is valid
    we send a 412.
    """
    incoming_etag = environ.get('HTTP_IF_MATCH', None)
    if not incoming_etag:
        raise HTTP412('If Match header required to update tiddlers.')
    tiddler_copy = Tiddler(tiddler.title, tiddler.bag)
    try:
        tiddler_copy = environ['tiddlyweb.store'].get(tiddler_copy)
    except NoTiddlerError:
        tiddler_copy.revision = 0
    return _validate_tiddler_headers(environ, tiddler_copy)
Exemplo n.º 26
0
def _require_valid_etag_for_write(environ, tiddler):
    """
    Unless there is an etag and it is valid
    we send a 412.
    """
    incoming_etag = environ.get('HTTP_IF_MATCH', None)
    if not incoming_etag:
        raise HTTP412('If Match header required to update tiddlers.')
    tiddler_copy = Tiddler(tiddler.title, tiddler.bag)
    try:
        tiddler_copy = environ['tiddlyweb.store'].get(tiddler_copy)
    except NoTiddlerError:
        tiddler_copy.revision = 0
    return _validate_tiddler_headers(environ, tiddler_copy)
Exemplo n.º 27
0
def test_tiddler_revision_create():
    """
    Confirm that when we set revision in a new Tiddler,
    we are able to retrieve that attribute.
    """

    tiddler = Tiddler('test tiddler r')
    tiddler.text = 'revision test'
    tiddler.revision = 5

    assert type(tiddler) == Tiddler, \
            'Tiddler returns a Tiddler'
    assert tiddler.revision == 5, \
            'revision is set as expected, to 5'
def test_put_get_tiddlers():
    tiddler = Tiddler('tiddler1', 'holder')
    tiddler.text = 'rev1'
    store.put(tiddler)
    tiddler.text = 'rev2'
    store.put(tiddler)
    tiddler.text = 'rev3'
    store.put(tiddler)

    retrieved = Tiddler('tiddler1', 'holder')
    retrieved = store.get(retrieved)
    assert retrieved.revision == 3
    assert retrieved.text == 'rev3'
    assert retrieved.bag == 'holder'

    retrieved.revision = 1
    retrieved = store.get(retrieved)
    assert retrieved.revision == 1
    assert retrieved.text == 'rev1'

    retrieved.revision = 2
    retrieved = store.get(retrieved)
    assert retrieved.revision == 2
    assert retrieved.text == 'rev2'
Exemplo n.º 29
0
def test_put_get_tiddlers():
    tiddler = Tiddler('tiddler1', 'holder')
    tiddler.text = 'rev1'
    store.put(tiddler)
    tiddler.text = 'rev2'
    store.put(tiddler)
    tiddler.text = 'rev3'
    store.put(tiddler)

    retrieved = Tiddler('tiddler1', 'holder')
    retrieved = store.get(retrieved)
    assert retrieved.revision == 3
    assert retrieved.text == 'rev3'
    assert retrieved.bag == 'holder'

    retrieved.revision = 1
    retrieved = store.get(retrieved)
    assert retrieved.revision == 1
    assert retrieved.text == 'rev1'

    retrieved.revision = 2
    retrieved = store.get(retrieved)
    assert retrieved.revision == 2
    assert retrieved.text == 'rev2'
Exemplo n.º 30
0
def _get_entity(entity, store):
    """
    Load the provided entity from the store if it has not already
    been loaded. In this context only tiddlers will not have been
    loaded already.
    """
    if store and not entity.store:
        try:
            stored_entity = Tiddler(entity.title, entity.bag)
            if entity.revision:
                stored_entity.revision = entity.revision
            stored_entity = store.get(stored_entity)
        except (AttributeError, NoTiddlerError):
            stored_entity = entity
    else:
        stored_entity = entity
    return stored_entity
Exemplo n.º 31
0
def test_tiddler_revisions():
    bag_name = u'bag8'
    for i in xrange(20):
        tiddler = Tiddler(u'oh hi', bag_name)
        tiddler.text = u'%s times we go' % i
        tiddler.fields[u'%s' % i] = u'%s' % i
        STORE.put(tiddler)

    revisions = STORE.list_tiddler_revisions(Tiddler('oh hi', bag_name))
    assert len(revisions) == 20
    tiddler = Tiddler('oh hi', bag_name)

    tiddler.revision = 90
    py.test.raises(NoTiddlerError, 'STORE.get(tiddler)')

    py.test.raises(NoBagError,
            'STORE.list_tiddler_revisions(Tiddler("sleepy", "cow"))')
Exemplo n.º 32
0
def _get_entity(entity, store):
    """
    Load the provided entity from the store if it has not already
    been loaded. In this context only tiddlers will not have been
    loaded already.
    """
    if store and not entity.store:
        try:
            stored_entity = Tiddler(entity.title, entity.bag)
            if entity.revision:
                stored_entity.revision = entity.revision
            stored_entity = store.get(stored_entity)
        except (AttributeError, NoTiddlerError):
            stored_entity = entity
    else:
        stored_entity = entity
    return stored_entity
Exemplo n.º 33
0
def _get_tiddler(id, store):  # XXX: rename
    """
	retrieve a tiddler revision based on an identifier

	returns the text serialization of the respective revision
	"""
    # retrieve tiddler revision from store
    type, name, title, rev = _resolve_identifier(id)
    if type == "bag":
        tiddler = Tiddler(title, name)
    else:
        raise HTTP400("recipes not supported")  # TODO?
    tiddler.revision = rev
    try:
        return store.get(tiddler)
    except NoTiddlerError:
        raise HTTP404("tiddler %s not found" % tiddler.title)
Exemplo n.º 34
0
 def add(self, tiddler):
     """
     Add a reference to the tiddler to the container,
     updating the digest and modified information. If
     the tiddler has recently been deleted, resulting
     in a StoreError, simply don't add it.
     """
     if not tiddler.store and self.store:
         try:
             tiddler = self.store.get(tiddler)
         except StoreError, exc:
             logging.debug("tried to add missing tiddler to collection: %s, %s", tiddler, exc)
             return
         reference = Tiddler(tiddler.title, tiddler.bag)
         if tiddler.revision:
             reference.revision = tiddler.revision
         if tiddler.recipe:
             reference.recipe = tiddler.recipe
         self._container.append(reference)
Exemplo n.º 35
0
 def key_gen(entity):
     """
     Reify the attribute needed for sorting. If the entity
     has not already been loaded from the store, do so.
     """
     if store and not entity.store:
         stored_entity = Tiddler(entity.title, entity.bag)
         if entity.revision:
             stored_entity.revision = entity.revision
         stored_entity = store.get(stored_entity)
     else:
         stored_entity = entity
     try:
         return func(getattr(stored_entity, attribute))
     except AttributeError, attribute_exc:
         try:
             return func(stored_entity.fields[attribute])
         except (AttributeError, KeyError), exc:
             raise AttributeError('on %s, no attribute: %s, %s, %s'
                     % (stored_entity, attribute, attribute_exc, exc))
Exemplo n.º 36
0
 def add(self, tiddler):
     """
     Add a reference to the tiddler to the container,
     updating the digest and modified information.
     """
     if not tiddler.store and self.store:
         tiddler = self.store.get(tiddler)
         reference = Tiddler(tiddler.title, tiddler.bag)
         if tiddler.revision:
             reference.revision = tiddler.revision
         if tiddler.recipe:
             reference.recipe = tiddler.recipe
         self._container.append(reference)
     else:
         self._container.append(tiddler)
     self._update_digest(tiddler)
     modified_string = str(tiddler.modified)
     modified_string = modified_string.ljust(14, '0')
     if modified_string > self.modified:
         self.modified = modified_string
Exemplo n.º 37
0
 def add(self, tiddler):
     """
     Add a reference to the tiddler to the container,
     updating the digest and modified information.
     """
     if not tiddler.store and self.store:
         tiddler = self.store.get(tiddler)
         reference = Tiddler(tiddler.title, tiddler.bag)
         if tiddler.revision:
             reference.revision = tiddler.revision
         if tiddler.recipe:
             reference.recipe = tiddler.recipe
         self._container.append(reference)
     else:
         self._container.append(tiddler)
     self._update_digest(tiddler)
     modified_string = str(tiddler.modified)
     modified_string = modified_string.ljust(14, '0')
     if modified_string > self.modified:
         self.modified = modified_string
Exemplo n.º 38
0
def test_interleaved_tiddler_revisions():
    bag_name = u'bag8'
    for i in xrange(20):
        tiddler1 = Tiddler(u'oh yes', bag_name)
        tiddler2 = Tiddler(u'oh no', bag_name)
        tiddler1.text = u'%s times we yes' % i
        tiddler2.text = u'%s times we no' % i
        tiddler1.fields[u'%s' % i] = u'%s' % i
        tiddler2.fields[u'%s' % i] = u'%s' % i
        STORE.put(tiddler1)
        STORE.put(tiddler2)

    revisions = STORE.list_tiddler_revisions(Tiddler('oh yes', bag_name))
    assert len(revisions) == 20

    tiddler = Tiddler('oh yes', bag_name)
    tiddler.revision = 90
    py.test.raises(NoTiddlerError, 'STORE.get(tiddler)')

    py.test.raises(NoBagError,
            'STORE.list_tiddler_revisions(Tiddler("sleepy", "cow"))')
Exemplo n.º 39
0
 def add(self, tiddler):
     """
     Add a reference to the tiddler to the container,
     updating the digest and modified information. If
     the tiddler has recently been deleted, resulting
     in a StoreError, simply don't add it.
     """
     if not tiddler.store and self.store:
         try:
             tiddler = self.store.get(tiddler)
         except StoreError, exc:
             logging.debug(
                     'tried to add missing tiddler to collection: %s, %s',
                     tiddler, exc)
             return
         reference = Tiddler(tiddler.title, tiddler.bag)
         if tiddler.revision:
             reference.revision = tiddler.revision
         if tiddler.recipe:
             reference.recipe = tiddler.recipe
         self._container.append(reference)
Exemplo n.º 40
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))
Exemplo n.º 41
0
def _send_tiddler_revisions(environ, start_response, tiddler):
    """
    Push the list of tiddler revisions out the network.
    """
    store = environ['tiddlyweb.store']

    tmp_bag = Bag('tmp', tmpbag=True, revbag=True)
    try:
        for revision in store.list_tiddler_revisions(tiddler):
            tmp_tiddler = Tiddler(title=tiddler.title, bag=tiddler.bag)
            tmp_tiddler.revision = revision
            try:
                tmp_tiddler = store.get(tmp_tiddler)
            except NoTiddlerError, exc:
                # If a particular revision is not present in the store.
                raise HTTP404('tiddler %s at revision % not found, %s' %
                        (tiddler.title, revision, exc))
            tmp_bag.add_tiddler(tmp_tiddler)
    except NoTiddlerError, exc:
        # If a tiddler is not present in the store.
        raise HTTP404('tiddler %s not found, %s' % (tiddler.title, exc))
Exemplo n.º 42
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))
Exemplo n.º 43
0
 def key_gen(entity):
     """
     Reify the attribute needed for sorting. If the entity
     has not already been loaded from the store, do so.
     """
     if store and not entity.store:
         stored_entity = Tiddler(entity.title, entity.bag)
         if entity.revision:
             stored_entity.revision = entity.revision
         stored_entity = store.get(stored_entity)
     else:
         stored_entity = entity
     try:
         return func(getattr(stored_entity, attribute))
     except AttributeError, attribute_exc:
         try:
             return func(stored_entity.fields[attribute])
         except (AttributeError, KeyError), exc:
             raise AttributeError(
                 'on %s, no attribute: %s, %s, %s' %
                 (stored_entity, attribute, attribute_exc, exc))
Exemplo n.º 44
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)
Exemplo n.º 45
0
def _determine_tiddler(environ, bag_finder):
    """
    Determine, using URL info, the target tiddler.
    This can be complicated because of the mechanics
    of recipes and bags.
    """
    tiddler_name = web.get_route_value(environ, 'tiddler_name')
    try:
        revision = web.get_route_value(environ, 'revision')
        revision = web.handle_extension(environ, revision)
    except KeyError:
        tiddler_name = web.handle_extension(environ, tiddler_name)
        revision = None

    tiddler = Tiddler(tiddler_name)
    if revision:
        try:
            revision = int(revision)
            tiddler.revision = revision
        except ValueError, exc:
            raise HTTP404('%s not a revision of %s: %s' %
                          (revision, tiddler_name, exc))
Exemplo n.º 46
0
def _base_tiddler_object(environ, tiddler_name, revisions):
    """
    Create a tiddler object, without bag or recipe, based on
    URI values.

    ``revisions`` is true when the request is for a revisions
    collection. When true, extension handling is not done on
    the tiddler_name.
    """
    if not revisions:
        try:
            revision = get_route_value(environ, 'revision')
            revision = handle_extension(environ, revision)
        except KeyError:
            tiddler_name = handle_extension(environ, tiddler_name)
            revision = None
    else:
        revision = None

    tiddler = Tiddler(tiddler_name)
    tiddler.revision = revision  # reset to default None if HEAD
    return tiddler
Exemplo n.º 47
0
def _determine_tiddler(environ, bag_finder):
    """
    Determine, using URL info, the target tiddler.
    This can be complicated because of the mechanics
    of recipes and bags.
    """
    tiddler_name = environ['wsgiorg.routing_args'][1]['tiddler_name']
    tiddler_name = urllib.unquote(tiddler_name)
    tiddler_name = unicode(tiddler_name, 'utf-8')
    revision = environ['wsgiorg.routing_args'][1].get('revision', None)
    if revision:
        revision = web.handle_extension(environ, revision)
    else:
        tiddler_name = web.handle_extension(environ, tiddler_name)

    tiddler = Tiddler(tiddler_name)
    if revision:
        try:
            revision = int(revision)
            tiddler.revision = revision
        except ValueError, exc:
            raise HTTP404('%s not a revision of %s: %s' %
                          (revision, tiddler_name, exc))
Exemplo n.º 48
0
 def reify_revision(tiddler, revision_id):
     revision = Tiddler(tiddler.title, tiddler.bag)
     revision.revision = revision_id
     return store.get(revision)
Exemplo n.º 49
0
 def _create_tiddler_revision(self, tiddler, revision_id):
     revision = Tiddler(tiddler.title, tiddler.bag)
     revision.revision = revision_id
     return revision
Exemplo n.º 50
0
from tiddlywebplugins.wikklytextplugins.plugins import macros
from tiddlyweb.model.tiddler import Tiddler
from tiddlywebplugins import wikklytextplugins
from tiddlywebplugins import wikklytextrender
from tiddlyweb.config import config
from test_common import WikiArgument,WikiContext

test_tiddler=  Tiddler("Test Tiddler","bag")
test_tiddler.modified = "20071003201000"
test_tiddler.revision = 2

def test_view_date():
    out = macros.view(WikiContext(test_tiddler,{}), WikiArgument("modified"),WikiArgument("date"))
    assert '03 October 2007' in out
    
def test_view_text():
    text ="My name is the test tiddler!"
    test_tiddler.text = text
    test_tiddler.tags = ["jon","ben","jeremy ruston"]
    out = macros.view(WikiContext(test_tiddler,{}), WikiArgument("text"))
    assert text in out
    out = macros.view(WikiContext(test_tiddler,{}), WikiArgument("text"),WikiArgument("text"))
    assert text in out
    out = macros.view(WikiContext(test_tiddler,{}), WikiArgument("title"),WikiArgument("text"))
    assert 'Test Tiddler' in out
    
    out = macros.view(WikiContext(test_tiddler,{}), WikiArgument("server.bag"),WikiArgument("text"))
    assert 'bag' in out 
    
    out = macros.view(WikiContext(test_tiddler,{}), WikiArgument("server.page.revision"),WikiArgument("text"))
    assert '2' in out
Exemplo n.º 51
0
 def _make_tiddler(result_dict):
     tiddler = Tiddler(result_dict['title'])
     tiddler.bag = result_dict['bag']
     tiddler.revision = result_dict['revision']
     return tiddler