Skip to content

Commit

Permalink
[FIX] P3: remove cPickle use
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
xmo-odoo committed May 15, 2017
1 parent 01e3514 commit b5983a4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
2 changes: 1 addition & 1 deletion addons/mail/models/html2text.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# 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
Expand Down
44 changes: 17 additions & 27 deletions odoo/tools/misc.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
"""
Miscellaneous tools used by OpenERP.
"""

from functools import wraps
import babel
from contextlib import contextmanager
Expand All @@ -14,11 +13,13 @@
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
Expand All @@ -36,12 +37,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:
Expand Down Expand Up @@ -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 comments on commit b5983a4

Please sign in to comment.