summaryrefslogtreecommitdiff
path: root/odoo/http.py
diff options
context:
space:
mode:
authorxmo-odoo <xmo@odoo.com>2017-05-10 09:39:55 +0200
committerGitHub <noreply@github.com>2017-05-10 09:39:55 +0200
commitfffaf735f58f1ac57781c095eb552de6d1fcdc47 (patch)
tree88ab0ab65430d871862a836524e0ecc890d1674d /odoo/http.py
parent10eee18a047d35305dc46282e610e88936d81ffc (diff)
[FIX] P3: list -> iterable builtins (#16811)
In Python 3: * various builtins and dict methods were changed to return view/iterable objects rather than lists * and the separate Python 2 view/iterable builtins and methods were removed altogether This is problematic when using these items as list (which the happens repeatedly in Odoo), but more viciously when iterating *multiple times* over them (which also happens, which I've messed up multiple times while writing this, and which is a pain to debug even when you've just created the issue). Convert all code using these to semantics-matching cross-version helper functions to get the LCD behaviour between P2 and P3, and forbid the builtins via lint. issue #8530
Diffstat (limited to 'odoo/http.py')
-rw-r--r--odoo/http.py22
1 files changed, 10 insertions, 12 deletions
diff --git a/odoo/http.py b/odoo/http.py
index 0b3ad105e39..fa5b44d1226 100644
--- a/odoo/http.py
+++ b/odoo/http.py
@@ -52,7 +52,7 @@ import odoo
from odoo.service.server import memory_info
from odoo.service import security, model as service_model
from odoo.tools.func import lazy_property
-from odoo.tools import ustr, consteq, frozendict
+from odoo.tools import ustr, consteq, frozendict, pycompat, unique
from odoo.modules.module import module_manifest
@@ -288,8 +288,8 @@ class WebRequest(object):
def set_handler(self, endpoint, arguments, auth):
# is this needed ?
- arguments = dict((k, v) for k, v in arguments.iteritems()
- if not k.startswith("_ignored_"))
+ arguments ={k: v for k, v in pycompat.items(arguments)
+ if not k.startswith("_ignored_")}
self.endpoint_arguments = arguments
self.endpoint = endpoint
self.auth_method = auth
@@ -837,7 +837,7 @@ more details.
"""
response = Response(data, headers=headers)
if cookies:
- for k, v in cookies.iteritems():
+ for k, v in pycompat.items(cookies):
response.set_cookie(k, v)
return response
@@ -878,7 +878,7 @@ class ControllerType(type):
super(ControllerType, cls).__init__(name, bases, attrs)
# flag old-style methods with req as first argument
- for k, v in attrs.items():
+ for k, v in pycompat.items(attrs):
if inspect.isfunction(v) and hasattr(v, 'original_func'):
# Set routing type on original functions
routing_type = v.routing.get('type')
@@ -941,14 +941,12 @@ def routing_map(modules, nodb_only, converters=None):
result = [klass]
return result
- uniq = lambda it: collections.OrderedDict((id(x), x) for x in it).values()
-
for module in modules:
if module not in controllers_per_module:
continue
for _, cls in controllers_per_module[module]:
- subclasses = uniq(c for c in get_subclasses(cls) if c is not cls)
+ subclasses = list(unique(c for c in get_subclasses(cls) if c is not cls))
if subclasses:
name = "%s (extended by %s)" % (cls.__name__, ', '.join(sub.__name__ for sub in subclasses))
cls = type(name, tuple(reversed(subclasses)), {})
@@ -1050,7 +1048,7 @@ class OpenERPSession(werkzeug.contrib.sessions.Session):
security.check(self.db, self.uid, self.password)
def logout(self, keep_db=False):
- for k in self.keys():
+ for k in list(self):
if not (keep_db and k == 'db'):
del self[k]
self._default_values()
@@ -1137,7 +1135,7 @@ class OpenERPSession(werkzeug.contrib.sessions.Session):
# NOTE we do not store files in the session itself to avoid loading them in memory.
# By storing them in the session store, we ensure every worker (even ones on other
# servers) can access them. It also allow stale files to be deleted by `session_gc`.
- for f in req.files.values():
+ for f in pycompat.values(req.files):
storename = 'werkzeug_%s_%s.file' % (self.sid, uuid.uuid4().hex)
path = os.path.join(root.session_store.path, storename)
with open(path, 'w') as fp:
@@ -1155,7 +1153,7 @@ class OpenERPSession(werkzeug.contrib.sessions.Session):
try:
if data:
# regenerate files filenames with the current session store
- for name, (storename, filename, content_type) in data['files'].iteritems():
+ for name, (storename, filename, content_type) in pycompat.items(data['files']):
path = os.path.join(root.session_store.path, storename)
files.add(name, (path, filename, content_type))
yield werkzeug.datastructures.CombinedMultiDict([data['form'], files])
@@ -1163,7 +1161,7 @@ class OpenERPSession(werkzeug.contrib.sessions.Session):
yield None
finally:
# cleanup files
- for f, _, _ in files.values():
+ for f, _, _ in pycompat.values(files):
try:
os.unlink(f)
except IOError: