Skip to content
Snippets Groups Projects
Commit b5983a48 authored by Xavier Morel's avatar Xavier Morel
Browse files

[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.
parent 01e35141
No related branches found
No related tags found
No related merge requests found
...@@ -13,7 +13,7 @@ __contributors__ = ["Martin 'Joey' Schulze", "Ricardo Reyes", "Kevin Jay North"] ...@@ -13,7 +13,7 @@ __contributors__ = ["Martin 'Joey' Schulze", "Ricardo Reyes", "Kevin Jay North"]
# Support decoded entities with unifiable. # Support decoded entities with unifiable.
import re, sys, htmlentitydefs, codecs 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]') sgmllib.charref = re.compile('&#([xX]?[0-9a-fA-F]+)[^0-9a-fA-F]')
try: from textwrap import wrap try: from textwrap import wrap
......
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
""" """
Miscellaneous tools used by OpenERP. Miscellaneous tools used by OpenERP.
""" """
from functools import wraps from functools import wraps
import babel import babel
from contextlib import contextmanager from contextlib import contextmanager
...@@ -14,11 +13,13 @@ import subprocess ...@@ -14,11 +13,13 @@ import subprocess
import io import io
import os import os
import passlib.utils import passlib.utils
import pickle as pickle_
import re import re
import socket import socket
import sys import sys
import threading import threading
import time import time
import types
import werkzeug.utils import werkzeug.utils
import zipfile import zipfile
from collections import defaultdict, Iterable, Mapping, MutableSet, OrderedDict from collections import defaultdict, Iterable, Mapping, MutableSet, OrderedDict
...@@ -36,12 +37,6 @@ try: ...@@ -36,12 +37,6 @@ try:
except ImportError: except ImportError:
import profile as cProfile import profile as cProfile
try:
# pylint: disable=bad-python3-import
import cPickle as pickle_
except ImportError:
import pickle as pickle_
try: try:
from html2text import html2text from html2text import html2text
except ImportError: except ImportError:
...@@ -1104,23 +1099,18 @@ def _consteq(str1, str2): ...@@ -1104,23 +1099,18 @@ def _consteq(str1, str2):
consteq = getattr(passlib.utils, 'consteq', _consteq) consteq = getattr(passlib.utils, 'consteq', _consteq)
class Pickle(object): def _pickle_load(stream, errors=False):
@classmethod unpickler = pickle_.Unpickler(stream)
def load(cls, stream, errors=False): # pickle builtins: str/unicode, int/long, float, bool, tuple, list, dict, None
unpickler = pickle_.Unpickler(stream) unpickler.find_global = None
# pickle builtins: str/unicode, int/long, float, bool, tuple, list, dict, None try:
unpickler.find_global = None return unpickler.load()
try: except Exception:
return unpickler.load() _logger.warning('Failed unpickling data, returning default: %r',
except Exception: errors, exc_info=True)
_logger.warning('Failed unpickling data, returning default: %r', errors, exc_info=True) return errors
return errors pickle = types.ModuleType(__name__ + '.pickle')
pickle.load = _pickle_load
@classmethod pickle.loads = lambda text: _pickle_load(io.BytesIO(text))
def loads(cls, text): pickle.dump = pickle_.dump
return cls.load(io.BytesIO(text)) pickle.dumps = pickle_.dumps
dumps = pickle_.dumps
dump = pickle_.dump
pickle = Pickle
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment