Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

_compat.py 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. ##############################################################################
  2. #
  3. # Copyright (c) 2002 Zope Foundation and Contributors.
  4. # All Rights Reserved.
  5. #
  6. # This software is subject to the provisions of the Zope Public License,
  7. # Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
  8. # THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
  9. # WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  10. # WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
  11. # FOR A PARTICULAR PURPOSE
  12. #
  13. ##############################################################################
  14. """Python versions compatiblity
  15. """
  16. import sys
  17. import platform
  18. PY3 = sys.version_info[0] >= 3
  19. PY32 = sys.version_info[:2] == (3, 2)
  20. PYPY = getattr(platform, 'python_implementation', lambda: None)() == 'PyPy'
  21. WIN = sys.platform.startswith('win')
  22. if PY3:
  23. from zodbpickle.pickle import Pickler, Unpickler as _Unpickler, dump, dumps, loads
  24. class Unpickler(_Unpickler):
  25. # Py3: Python 3 doesn't allow assignments to find_global,
  26. # instead, find_class can be overridden
  27. find_global = None
  28. def find_class(self, modulename, name):
  29. if self.find_global is None:
  30. return super(Unpickler, self).find_class(modulename, name)
  31. return self.find_global(modulename, name)
  32. else:
  33. try:
  34. import zodbpickle.fastpickle as cPickle
  35. except ImportError:
  36. import zodbpickle.pickle as cPickle
  37. Pickler = cPickle.Pickler
  38. Unpickler = cPickle.Unpickler
  39. dump = cPickle.dump
  40. dumps = cPickle.dumps
  41. loads = cPickle.loads
  42. # String and Bytes IO
  43. from ZODB._compat import BytesIO
  44. if PY3:
  45. import _thread as thread
  46. if PY32:
  47. from threading import _get_ident as get_ident
  48. else:
  49. from threading import get_ident
  50. else:
  51. import thread
  52. from thread import get_ident
  53. try:
  54. from cStringIO import StringIO
  55. except:
  56. from io import StringIO