Changed interface for flask.g

This now makes it behave like it did before, it's just an object.
It did however gain ``__contains__`` and ``__iter__`` and I added
a ``get()`` method to fetch an attribute without raising an
error.  This fixes #759.
This commit is contained in:
Armin Ronacher 2013-06-09 12:06:33 +01:00
parent efd6e468ae
commit c889fbc231
4 changed files with 29 additions and 19 deletions

View file

@ -24,17 +24,14 @@ from .signals import appcontext_pushed, appcontext_popped
class _AppCtxGlobals(object):
"""A plain object."""
def __getitem__(self, name):
try:
return getattr(self, name)
except AttributeError:
return None
def get(self, name, default=None):
return self.__dict__.get(name, default)
def __setitem__(self, name, value):
setattr(self, name, value)
def __contains__(self, item):
return item in self.__dict__
def __delitem__(self, name, value):
delattr(self, name, value)
def __iter__(self):
return iter(self.__dict__)
def __repr__(self):
top = _app_ctx_stack.top