summaryrefslogtreecommitdiff
path: root/odoo
diff options
context:
space:
mode:
authorXavier Morel <xmo@odoo.com>2017-05-11 17:39:49 +0200
committerXavier Morel <xmo@odoo.com>2017-05-15 12:26:30 +0200
commitb5983a485d3bac6ffaa59e4d867b85b9e7bc09bc (patch)
treeb29ac506d6e735a8c4e69e56676044016f1cdea8 /odoo
parent01e35141479b8dfc4a390518f89fc52e7cec5396 (diff)
[FIX] P3: remove cPickle use
In Python 3 the native acceleration module was merged into pickle directly. For cross-version simplicity, just use the base module in Python 2 as well, we can reintroduce the accelerator somehow if it turns out too much of a performance hit.
Diffstat (limited to 'odoo')
-rw-r--r--odoo/tools/misc.py44
1 files changed, 17 insertions, 27 deletions
diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py
index 293ad148632..3eaf476fc8a 100644
--- a/odoo/tools/misc.py
+++ b/odoo/tools/misc.py
@@ -5,7 +5,6 @@
"""
Miscellaneous tools used by OpenERP.
"""
-
from functools import wraps
import babel
from contextlib import contextmanager
@@ -14,11 +13,13 @@ import subprocess
import io
import os
import passlib.utils
+import pickle as pickle_
import re
import socket
import sys
import threading
import time
+import types
import werkzeug.utils
import zipfile
from collections import defaultdict, Iterable, Mapping, MutableSet, OrderedDict
@@ -37,12 +38,6 @@ except ImportError:
import profile as cProfile
try:
- # pylint: disable=bad-python3-import
- import cPickle as pickle_
-except ImportError:
- import pickle as pickle_
-
-try:
from html2text import html2text
except ImportError:
html2text = None
@@ -1104,23 +1099,18 @@ def _consteq(str1, str2):
consteq = getattr(passlib.utils, 'consteq', _consteq)
-class Pickle(object):
- @classmethod
- def load(cls, stream, errors=False):
- unpickler = pickle_.Unpickler(stream)
- # pickle builtins: str/unicode, int/long, float, bool, tuple, list, dict, None
- unpickler.find_global = None
- try:
- return unpickler.load()
- except Exception:
- _logger.warning('Failed unpickling data, returning default: %r', errors, exc_info=True)
- return errors
-
- @classmethod
- def loads(cls, text):
- return cls.load(io.BytesIO(text))
-
- dumps = pickle_.dumps
- dump = pickle_.dump
-
-pickle = Pickle
+def _pickle_load(stream, errors=False):
+ unpickler = pickle_.Unpickler(stream)
+ # pickle builtins: str/unicode, int/long, float, bool, tuple, list, dict, None
+ unpickler.find_global = None
+ try:
+ return unpickler.load()
+ except Exception:
+ _logger.warning('Failed unpickling data, returning default: %r',
+ errors, exc_info=True)
+ return errors
+pickle = types.ModuleType(__name__ + '.pickle')
+pickle.load = _pickle_load
+pickle.loads = lambda text: _pickle_load(io.BytesIO(text))
+pickle.dump = pickle_.dump
+pickle.dumps = pickle_.dumps