Changeset 6411

Show
Ignore:
Timestamp:
08/19/08 16:58:17 (5 months ago)
Author:
cdent
Message:

tiddlyweb - add support for deleting recipes

In the process make it so the system can survive appropriately
when a store doesn't implement a particular store method. The
store will raise StoreMethodNotImplemented? and the web handlers
will transform this to HTTP400.

Location:
Trunk/contributors/ChrisDent/experimental/TiddlyWeb
Files:
10 modified

Legend:

Unmodified
Added
Removed
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/googleappengine/googledata.py

    r6067 r6411  
    187187            return [] 
    188188 
    189     def list_tiddler_revisions(self, tiddler): 
    190         return [] 
    191  
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/test/test_web_recipe.py

    r6384 r6411  
    193193 
    194194    assert response['status'] == '415' 
     195 
     196def test_delete_recipe(): 
     197    """ 
     198    DELETE the other recipe 
     199    """ 
     200    http = httplib2.Http() 
     201    response, content = http.request('http://our_test_domain:8001/recipes/other', 
     202            method='DELETE') 
     203    print content 
     204    assert response['status'] == '204' 
     205 
     206    response, content = http.request('http://our_test_domain:8001/recipes/other', 
     207            method='GET') 
     208    assert response['status'] == '404' 
     209 
     210    # what happens when we delete the same recipe again? 
     211    response, content = http.request('http://our_test_domain:8001/recipes/other', 
     212            method='DELETE') 
     213    assert response['status'] == '404' 
    195214 
    196215def test_get_recipe_wiki_bag_constraints(): 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/tiddlyweb/store.py

    r5802 r6411  
    1010 
    1111from tiddlyweb.config import config 
     12 
     13class StoreMethodNotImplemented(IOError): 
     14    pass 
    1215 
    1316class NoBagError(IOError): 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/tiddlyweb/stores/__init__.py

    r6408 r6411  
    44system. 
    55""" 
     6 
     7from tiddlyweb.store import StoreMethodNotImplemented 
    68 
    79class StorageInterface(object): 
     
    2325        self.environ = environ 
    2426 
     27    def recipe_delete(self, recipe): 
     28        raise StoreMethodNotImplemented 
     29 
    2530    def recipe_get(self, recipe): 
    26         pass 
     31        raise StoreMethodNotImplemented 
    2732 
    2833    def recipe_put(self, recipe): 
    29         pass 
     34        raise StoreMethodNotImplemented 
    3035 
    3136    def bag_delete(self, bag): 
    32         pass 
     37        raise StoreMethodNotImplemented 
    3338 
    3439    def bag_get(self, bag): 
    35         pass 
     40        raise StoreMethodNotImplemented 
    3641 
    3742    def bag_put(self, recipe): 
    38         pass 
     43        raise StoreMethodNotImplemented 
    3944 
    4045    def tiddler_delete(self, tiddler): 
    41         pass 
     46        raise StoreMethodNotImplemented 
    4247 
    4348    def tiddler_get(self, tiddler): 
    44         pass 
     49        raise StoreMethodNotImplemented 
    4550 
    4651    def tiddler_put(self, tiddler): 
    47         pass 
     52        raise StoreMethodNotImplemented 
    4853 
    4954    def user_get(self, user): 
    50         pass 
     55        raise StoreMethodNotImplemented 
    5156 
    5257    def user_put(self, user): 
    53         pass 
     58        raise StoreMethodNotImplemented 
    5459 
    5560    def list_recipes(self): 
    56         pass 
     61        raise StoreMethodNotImplemented 
    5762 
    5863    def list_bags(self): 
    59         pass 
     64        raise StoreMethodNotImplemented 
    6065 
    6166    def list_tiddler_revisions(self, tiddler): 
    62         pass 
     67        raise StoreMethodNotImplemented 
    6368 
    6469    def tiddler_written(self, tiddler): 
     
    7176 
    7277    def search(self, search_query): 
    73         pass 
     78        raise StoreMethodNotImplemented 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/tiddlyweb/stores/text.py

    r6408 r6411  
    1818 
    1919class Store(StorageInterface): 
     20 
     21    def recipe_delete(self, recipe): 
     22        recipe_path = self._recipe_path(recipe) 
     23 
     24        try: 
     25            if not os.path.exists(recipe_path): 
     26                raise NoRecipeError, '%s not present' % recipe_path 
     27            os.remove(recipe_path) 
     28        except NoRecipeError: 
     29            raise 
     30        except Exception, e: 
     31            raise IOError, 'unable to delete recipe %s: %s' % (recipe.name, e) 
    2032 
    2133    def recipe_get(self, recipe): 
     
    5062        try: 
    5163            if not os.path.exists(bag_path): 
    52                 raise NoBagError, '%s not present' % tiddler_base_filename 
    53             print 'bag_path to delete %s' % bag_path 
     64                raise NoBagError, '%s not present' % bag_path 
    5465            shutil.rmtree(bag_path) 
    55             # XXX: We need to return a value so the caller knows 
    56             # that we did something otherwise it will choose 
    57             # to raise a 415. Not satisfied with this solution 
    58             # as it doesn't map to how the rest of the system behaves. 
    59             # Probably need to raise exceptions from the interface.  
    60             return 1 
    6166        except NoBagError: 
    6267            raise 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/tiddlyweb/web/bag.py

    r6408 r6411  
    1111 
    1212from tiddlyweb.bag import Bag 
    13 from tiddlyweb.store import Store, NoBagError 
     13from tiddlyweb.store import Store, NoBagError, StoreMethodNotImplemented 
    1414from tiddlyweb.serializer import Serializer, NoSerializationError 
    1515from tiddlyweb import control 
     
    3434    # we don't need to check for existence here because 
    3535    # the above get already did 
    36     if bag.store.delete(bag) is not None: 
    37         start_response("204 No Content", []) 
    38         return [] 
     36    try: 
     37        bag.store.delete(bag) 
     38    except StoreMethodNotImplemented: 
     39        raise HTTP400, 'Bag DELETE not supported' 
    3940 
    40     raise HTTP415, 'DELETE not supported' 
     41    start_response("204 No Content", []) 
     42    return [] 
    4143 
    4244def get(environ, start_response): 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/tiddlyweb/web/recipe.py

    r6250 r6411  
    1010from tiddlyweb.recipe import Recipe 
    1111from tiddlyweb.bag import Bag 
    12 from tiddlyweb.store import Store, NoRecipeError, NoBagError 
     12from tiddlyweb.store import Store, NoRecipeError, NoBagError, StoreMethodNotImplemented 
    1313from tiddlyweb.serializer import Serializer, NoSerializationError 
    14 from tiddlyweb.web.http import HTTP415, HTTP404, HTTP403 
     14from tiddlyweb.web.http import HTTP400, HTTP415, HTTP404, HTTP403 
    1515from tiddlyweb.web.tiddlers import send_tiddlers 
    1616from tiddlyweb import control 
    1717from tiddlyweb.web import util as web 
     18 
     19def delete(environ, start_response): 
     20    """ 
     21    Delete a recipe, where what delete means 
     22    depends on the store used. 
     23 
     24    XXX: There are no permissions on this method. 
     25    There should be! 
     26    """ 
     27    recipe = _determine_recipe(environ) 
     28 
     29    try: 
     30        recipe.store.delete(recipe) 
     31    except StoreMethodNotImplemented: 
     32        raise HTTP400, 'Recipe DELETE not supported' 
     33 
     34    start_response("204 No Content", []) 
     35    return [] 
    1836 
    1937def get(environ, start_response): 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/tiddlyweb/web/search.py

    r6266 r6411  
    1111from tiddlyweb.bag import Bag 
    1212from tiddlyweb.auth import ForbiddenError, UserRequiredError 
     13from tiddlyweb.store import StoreMethodNotImplemented 
    1314from tiddlyweb.web import util as web 
    1415from tiddlyweb.web.tiddlers import send_tiddlers 
     
    2829     
    2930    store = environ['tiddlyweb.store'] 
    30     tiddlers = store.search(search_query) 
     31    try: 
     32        tiddlers = store.search(search_query) 
     33    except StoreMethodNotImplemented: 
     34        raise HTTP400, 'Search system not implemented' 
    3135 
    3236    usersign = environ['tiddlyweb.usersign'] 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/tiddlyweb/web/tiddler.py

    r6249 r6411  
    99from tiddlyweb.recipe import Recipe 
    1010from tiddlyweb.bag import Bag 
    11 from tiddlyweb.store import Store, NoTiddlerError, NoBagError 
     11from tiddlyweb.store import Store, NoTiddlerError, NoBagError, StoreMethodNotImplemented 
    1212from tiddlyweb.serializer import Serializer, TiddlerFormatError 
    1313from tiddlyweb.web.http import HTTP404, HTTP415, HTTP412, HTTP409, HTTP403, HTTP304 
     
    114114            try: 
    115115                revision = store.list_tiddler_revisions(tiddler)[0] 
    116             except IndexError: 
     116            except StoreMethodNotImplemented: 
    117117                revision = 1 
    118118            tiddler.revision = revision 
     
    218218        # If a tiddler is not present in the store. 
    219219        raise HTTP404, 'tiddler %s not found, %s' % (tiddler.title, e) 
     220    except StoreMethodNotImplemented: 
     221        raise HTTP400, 'no revision support' 
    220222 
    221223    return send_tiddlers(environ, start_response, tmp_bag) 
  • Trunk/contributors/ChrisDent/experimental/TiddlyWeb/urls.map

    r6408 r6411  
    3333    GET tiddlyweb.web.recipe:get 
    3434    PUT tiddlyweb.web.recipe:put 
     35    DELETE tiddlyweb.web.recipe:delete 
    3536 
    3637# the tiddlers produced by this recipe