[IMP] api: make Environment implement the Mapping API

This commit is contained in:
Raphael Collet
2016-06-16 16:50:48 +02:00
parent 5ba7ce138b
commit 4edcba696e
+16 -5
View File
@@ -45,11 +45,9 @@ __all__ = [
]
import logging
import operator
from inspect import currentframe, getargspec
from collections import defaultdict, MutableMapping
from collections import defaultdict, Mapping
from contextlib import contextmanager
from inspect import currentframe, getargspec
from pprint import pformat
from weakref import WeakSet
from werkzeug.local import Local, release_local
@@ -813,7 +811,7 @@ def expected(decorator, func):
class Environment(object):
class Environment(Mapping):
""" An environment wraps data for ORM records:
- :attr:`cr`, the current database cursor;
@@ -871,6 +869,10 @@ class Environment(object):
envs.add(self)
return self
#
# Mapping methods
#
def __contains__(self, model_name):
""" Test whether the given model exists. """
return model_name in self.registry
@@ -887,6 +889,15 @@ class Environment(object):
""" Return the size of the model registry. """
return len(self.registry)
def __eq__(self, other):
return self is other
def __ne__(self, other):
return self is not other
def __hash__(self):
return object.__hash__(self)
def __call__(self, cr=None, user=None, context=None):
""" Return an environment based on ``self`` with modified parameters.