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"]
# 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
......
......@@ -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
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