~cjwatson/lazr.restful/test-fixes

« back to all changes in this revision

Viewing changes to src/lazr/restful/example/base/root.py

  • Committer: Colin Watson
  • Date: 2016-02-17 01:07:21 UTC
  • Revision ID: cjwatson@canonical.com-20160217010721-4d5fqqml5q97ss59
Switch zope.interface, zope.component, and lazr.delegates users from class advice to class decorators.

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
import grokcore.component
15
15
 
16
 
from zope.interface import implements
 
16
from zope.interface import implementer
17
17
from zope.location.interfaces import ILocation
18
18
from zope.component import getMultiAdapter, getUtility
19
19
from zope.schema.interfaces import IBytes
36
36
    """A basic object published through the web service."""
37
37
 
38
38
 
 
39
@implementer(IByteStorage, ILocation)
39
40
class SimpleByteStorage(CookbookWebServiceObject,
40
41
                        grokcore.component.MultiAdapter):
41
42
    """A simple IByteStorage implementation"""
42
 
    implements(IByteStorage, ILocation)
43
43
    grokcore.component.adapts(IEntry, IBytes)
44
44
    grokcore.component.provides(IByteStorage)
45
45
 
87
87
        setattr(self.entry, self.field.__name__, None)
88
88
 
89
89
 
 
90
@implementer(ICookbook)
90
91
class Cookbook(CookbookWebServiceObject):
91
92
    """An object representing a cookbook"""
92
 
    implements(ICookbook)
93
93
    def __init__(self, name, description, cuisine, copyright_date,
94
94
                 last_printing=None, price=0, confirmed=False):
95
95
        self.name = name
153
153
        storage.createStored('application/octet-stream', cover, 'cover')
154
154
 
155
155
 
 
156
@implementer(IDish)
156
157
class Dish(CookbookWebServiceObject):
157
 
    implements(IDish)
158
158
 
159
159
    def __init__(self, name):
160
160
        self.name = name
172
172
        self.recipes.remove(recipe)
173
173
 
174
174
 
 
175
@implementer(IRecipe)
175
176
class Recipe(CookbookWebServiceObject):
176
 
    implements(IRecipe)
177
177
 
178
178
    def __init__(self, id, cookbook, dish, instructions, private=False):
179
179
        self.id = id
197
197
        getUtility(IRecipeSet).removeRecipe(self)
198
198
 
199
199
# Top-level objects.
 
200
@implementer(ILocation)
200
201
class CookbookTopLevelObject(CookbookWebServiceObject,
201
202
                             grokcore.component.GlobalUtility):
202
203
    """An object published at the top level of the web service."""
203
 
    implements(ILocation)
204
204
 
205
205
    @property
206
206
    def __parent__(self):
211
211
        raise NotImplementedError()
212
212
 
213
213
 
 
214
@implementer(ITopLevelEntryLink)
214
215
class FeaturedCookbookLink(CookbookTopLevelObject):
215
216
    """A link to the currently featured cookbook."""
216
 
    implements(ITopLevelEntryLink)
217
217
    grokcore.component.provides(ITopLevelEntryLink)
218
218
 
219
219
    @property
226
226
    entry_type = ICookbook
227
227
 
228
228
 
 
229
@implementer(ICookbookSet)
229
230
class CookbookSet(CookbookTopLevelObject):
230
231
    """The set of all cookbooks."""
231
 
    implements(ICookbookSet)
232
232
    grokcore.component.provides(ICookbookSet)
233
233
 
234
234
    __name__ = "cookbooks"
275
275
        return cookbook
276
276
 
277
277
 
 
278
@implementer(IDishSet)
278
279
class DishSet(CookbookTopLevelObject):
279
280
    """The set of all dishes."""
280
 
    implements(IDishSet)
281
281
    grokcore.component.provides(IDishSet)
282
282
 
283
283
    __name__ = "dishes"
297
297
        return None
298
298
 
299
299
 
 
300
@implementer(IRecipeSet)
300
301
class RecipeSet(CookbookTopLevelObject):
301
302
    """The set of all recipes."""
302
 
    implements(IRecipeSet)
303
303
    grokcore.component.provides(IRecipeSet)
304
304
 
305
305
    __name__ = "recipes"
359
359
 
360
360
 
361
361
# Define classes for the service root.
 
362
@implementer(IHasGet)
362
363
class CookbookServiceRootResource(ServiceRootResource):
363
364
    """A service root for the cookbook web service.
364
365
 
365
366
    Traversal to top-level resources is handled with the get() method.
366
367
    The top-level objects are stored in the top_level_names dict.
367
368
    """
368
 
    implements(IHasGet)
369
369
 
370
370
    @property
371
371
    def top_level_names(self):