Skip to content

Commit

Permalink
Implemented a annotations adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Kraft committed Nov 2, 2009
1 parent a6e9c52 commit 9cb19cb
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions otto/app.py
Expand Up @@ -25,6 +25,29 @@ def __call__(self, obj, *args, **kwargs):
for handler in self.lookup(obj):
handler(obj, *args, **kwargs)

class Annotation(object):
""" Annotation on objects. Annotations are stored in a "_annotations" attribute.
>>> class MyObj(object):
... pass
>>> o = MyObj()
>>> annotations = Annotations(o, 'mynamespace')
>>> annotations
{}
"""
def __new__(self, obj, namespace):
try:
annotations = obj._annotations
except AttributeError:
# XXX Should we check if the object supports __setitem__?
obj._annotations = dict()
annotations = obj._annotations
try:
return annotations[namespace]
except KeyError:
annotations[namespace] = dict()
return annotations[namespace]


class Application(object):
"""WSGI-application.
Expand Down

0 comments on commit 9cb19cb

Please sign in to comment.