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
def _do_hook(self, method, thing): """ Call the hook in HOOKS identified by method on thing. """ hooked_class = superclass_name(thing) hooks = _get_hooks(method, hooked_class) for hook in hooks: hook(self, thing)
def entity_to_keys(entity): """ Given an entity, return a list of approrpriate keys to purge. Dispatch on the class of the entity. """ return DISPATCH[superclass_name(entity)](entity)
def __str__(self): lower_class = superclass_name(self.object) try: string_func = getattr(self.serialization, '%s_as' % lower_class) except AttributeError, exc: raise AttributeError( 'unable to find to string function for %s: %s' % (lower_class, exc))
def _figure_function(self, activity, storable): """ Determine which function on the StorageInterface we should use to store or retrieve storable. """ lower_class = superclass_name(storable) try: func = getattr(self.storage, '%s_%s' % (lower_class, activity)) except AttributeError, exc: raise AttributeError('unable to figure function for %s: %s' % (lower_class, exc))
def from_string(self, input_string): """ Turn the provided input_string into a TiddlyWeb entity object of the type of self.object. That is: populate self.object based on input_string. """ lower_class = superclass_name(self.object) try: object_func = getattr(self.serialization, 'as_%s' % lower_class) except AttributeError, exc: raise AttributeError( 'unable to find from string function for %s: %s' % (lower_class, exc))
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
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