Example #1
0
 def get(self, thing):
     """
     Get a thing: recipe, bag, tiddler or user.
     """
     lower_class = superclass_name(thing)
     if lower_class == 'tiddler':
         retriever = get_bag_retriever(self.environ, thing.bag)
         if retriever:
             try:
                 thing = retriever[1](thing)
             except SpecialBagError as exc:
                 raise NoTiddlerError(
                         'unable to get special tiddler: %s:%s:%s'
                         % (thing.bag, thing.title, exc))
             thing.store = self
             self._do_hook('get', thing)
             return thing
     elif lower_class == 'bag':
         if get_bag_retriever(self.environ, thing.name):
             policy = Policy(read=[], write=['NONE'], create=['NONE'],
                     delete=['NONE'], manage=['NONE'], accept=['NONE'])
             thing.policy = policy
             thing.store = self
             self._do_hook('get', thing)
             return thing
     func = self._figure_function('get', thing)
     thing = func(thing)
     thing.store = self
     self._do_hook('get', thing)
     return thing
Example #2
0
def get_tiddlers_from_recipe(recipe, environ=None):
    """
    Return the list of tiddlers that result from processing the ``recipe``.

    This list of tiddlers is unique by title with tiddlers later in the
    recipe taking precedence over those earlier in the recipe.

    The tiddlers returned are empty objects (i.e. not loaded from the
    :py:mod:`store <tiddlyweb.store>`).
    """
    template = recipe_template(environ)
    store = recipe.store
    uniquifier = {}
    for bag, filter_string in recipe.get_recipe(template):

        if isinstance(bag, basestring):
            retriever = get_bag_retriever(environ, bag)
            if not retriever:
                bag = Bag(name=bag)
                retriever = store.list_bag_tiddlers
            else:
                retriever = retriever[0]
        else:
            retriever = store.list_bag_tiddlers

        try:
            for tiddler in filter_tiddlers(retriever(bag), filter_string,
                    environ=environ):
                uniquifier[tiddler.title] = tiddler
        except SpecialBagError as exc:
            raise NoBagError('unable to retrieve from special bag: %s, %s'
                    % (bag, exc))

    return uniquifier.values()
Example #3
0
    def recipe_as(self, recipe):
        """
        Dump a :py:class:`recipe <tiddlyweb.model.recipe.Recipe>` as text.
        """
        policy_dict = dict([(key, getattr(recipe.policy, key))
                            for key in Policy.attributes])
        lines = [
            'desc: %s' % recipe.desc,
            'policy: %s' % simplejson.dumps(policy_dict), ''
        ]

        for bag, filter_string in recipe.get_recipe():
            line = ''
            if not get_bag_retriever(self.environ, bag):
                # If there is a retriever for this bag name then
                # we want to write its name straight.
                line += '/bags/%s/tiddlers' % quote(bag.encode('utf-8'),
                                                    safe='')
            else:
                line += bag
            if filter_string:
                line += '?%s' % filter_string
            lines.append(line)

        return "\n".join(lines)
Example #4
0
    def recipe_as(self, recipe):
        """
        Recipe as text.
        """
        policy_dict = dict([(key, getattr(recipe.policy, key)) for
                key in Policy.attributes])
        lines = ['desc: %s' % recipe.desc, 'policy: %s' %
                simplejson.dumps(policy_dict), '']

        for bag, filter_string in recipe.get_recipe():
            line = ''
            if not isinstance(bag, basestring):
                bag = bag.name
            if not get_bag_retriever(self.environ, bag):
                # If there is a retriever for this bag name then
                # we want to write its name straight.
                line += '/bags/%s/tiddlers' % urllib.quote(
                        bag.encode('utf-8'), safe='')
            else:
                line += bag
            if filter_string:
                line += '?%s' % filter_string
            lines.append(line)

        return "\n".join(lines)
Example #5
0
def get_tiddlers_from_recipe(recipe, environ=None):
    """
    Return the list of tiddlers that result from processing the ``recipe``.

    This list of tiddlers is unique by title with tiddlers later in the
    recipe taking precedence over those earlier in the recipe.

    The tiddlers returned are empty objects (i.e. not loaded from the
    :py:mod:`store <tiddlyweb.store>`).
    """
    template = recipe_template(environ)
    store = recipe.store
    uniquifier = {}
    for bag, filter_string in recipe.get_recipe(template):

        if isinstance(bag, basestring):
            retriever = get_bag_retriever(environ, bag)
            if not retriever:
                bag = Bag(name=bag)
                retriever = store.list_bag_tiddlers
            else:
                retriever = retriever[0]
        else:
            retriever = store.list_bag_tiddlers

        try:
            for tiddler in filter_tiddlers(retriever(bag),
                                           filter_string,
                                           environ=environ):
                uniquifier[tiddler.title] = tiddler
        except SpecialBagError as exc:
            raise NoBagError('unable to retrieve from special bag: %s, %s' %
                             (bag, exc))

    return uniquifier.values()
Example #6
0
 def list_bag_tiddlers(self, bag):
     """
     List all the tiddlers in the bag.
     """
     retriever = get_bag_retriever(self.environ, bag.name)
     if retriever:
         try:
             return retriever[0](bag.name)
         except SpecialBagError, exc:
             raise NoBagError('unable to get special bag: %s: %s'
                     % (bag.name, exc))
Example #7
0
 def list_bag_tiddlers(self, bag):
     """
     List all the tiddlers in the bag.
     """
     retriever = get_bag_retriever(self.environ, bag.name)
     if retriever:
         try:
             return retriever[0](bag.name)
         except SpecialBagError, exc:
             raise NoBagError('unable to get remote bag: %s: %s' %
                              (bag.name, exc))
Example #8
0
 def list_bag_tiddlers(self, bag):
     """
     List all the tiddlers in the bag.
     """
     retriever = get_bag_retriever(self.environ, bag.name)
     if retriever:
         try:
             return retriever[0](bag.name)
         except SpecialBagError as exc:
             raise NoBagError('unable to get special bag: %s: %s'
                     % (bag.name, exc))
     list_func = getattr(self.storage, 'list_bag_tiddlers')
     return list_func(bag)
Example #9
0
 def get(self, thing):
     """
     Get a thing: recipe, bag or tiddler
     """
     lower_class = superclass_name(thing)
     if lower_class == 'tiddler':
         retriever = get_bag_retriever(self.environ, thing.bag)
         if retriever:
             try:
                 thing = retriever[1](thing)
             except SpecialBagError, exc:
                 raise NoTiddlerError(
                         'unable to get special tiddler: %s:%s:%s'
                         % (thing.bag, thing.title, exc))
             thing.store = self
             self._do_hook('get', thing)
             return thing
Example #10
0
 def get(self, thing):
     """
     Get a thing: recipe, bag or tiddler
     """
     lower_class = superclass_name(thing)
     if lower_class == 'tiddler':
         retriever = get_bag_retriever(self.environ, thing.bag)
         if retriever:
             try:
                 thing = retriever[1](thing)
             except SpecialBagError, exc:
                 raise NoTiddlerError(
                     'unable to get remote tiddler: %s:%s:%s' %
                     (thing.bag, thing.title, exc))
             thing.store = self
             self._do_hook('get', thing)
             return thing
Example #11
0
        """
        lower_class = superclass_name(thing)
        if lower_class == 'tiddler':
            retriever = get_bag_retriever(self.environ, thing.bag)
            if retriever:
                try:
                    thing = retriever[1](thing)
                except SpecialBagError, exc:
                    raise NoTiddlerError(
                            'unable to get special tiddler: %s:%s:%s'
                            % (thing.bag, thing.title, exc))
                thing.store = self
                self._do_hook('get', thing)
                return thing
        elif lower_class == 'bag':
            if get_bag_retriever(self.environ, thing.name):
                policy = Policy(read=[], write=['NONE'], create=['NONE'],
                        delete=['NONE'], manage=['NONE'], accept=['NONE'])
                thing.policy = policy
                thing.store = self
                self._do_hook('get', thing)
                return thing
        func = self._figure_function('get', thing)
        thing = func(thing)
        thing.store = self
        self._do_hook('get', thing)
        return thing

    def put(self, thing):
        """
        Put a thing, recipe, bag or tiddler.
Example #12
0
 """
 lower_class = superclass_name(thing)
 if lower_class == 'tiddler':
     retriever = get_bag_retriever(self.environ, thing.bag)
     if retriever:
         try:
             thing = retriever[1](thing)
         except SpecialBagError, exc:
             raise NoTiddlerError(
                 'unable to get remote tiddler: %s:%s:%s' %
                 (thing.bag, thing.title, exc))
         thing.store = self
         self._do_hook('get', thing)
         return thing
 elif lower_class == 'bag':
     if get_bag_retriever(self.environ, thing.name):
         policy = Policy(read=[],
                         write=['NONE'],
                         create=['NONE'],
                         delete=['NONE'],
                         manage=['NONE'],
                         accept=['NONE'])
         thing.policy = policy
         thing.store = self
         self._do_hook('get', thing)
         return thing
 func = self._figure_function('get', thing)
 thing = func(thing)
 thing.store = self
 self._do_hook('get', thing)
 return thing