From b5983a485d3bac6ffaa59e4d867b85b9e7bc09bc Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Thu, 11 May 2017 17:39:49 +0200 Subject: [PATCH] [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. --- addons/mail/models/html2text.py | 2 +- odoo/tools/misc.py | 44 +++++++++++++-------------------- 2 files changed, 18 insertions(+), 28 deletions(-) diff --git a/addons/mail/models/html2text.py b/addons/mail/models/html2text.py index 8830cb0266d..fa2a8507af9 100755 --- a/addons/mail/models/html2text.py +++ b/addons/mail/models/html2text.py @@ -13,7 +13,7 @@ __contributors__ = ["Martin 'Joey' Schulze", "Ricardo Reyes", "Kevin Jay North"] # Support decoded entities with unifiable. import re, sys, htmlentitydefs, codecs -import sgmllib +import sgmllib # pylint: disable=deprecated-module sgmllib.charref = re.compile('&#([xX]?[0-9a-fA-F]+)[^0-9a-fA-F]') try: from textwrap import wrap 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 @@ -36,12 +37,6 @@ try: 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: @@ -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