From 4edcba696ee247649d4548b68200e9b02effb087 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Wed, 1 Jun 2016 14:00:51 +0200 Subject: [PATCH] [IMP] api: make `Environment` implement the `Mapping` API --- openerp/api.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/openerp/api.py b/openerp/api.py index a846de540d1..b1241e4563c 100644 --- a/openerp/api.py +++ b/openerp/api.py @@ -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.