Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

py31compat.py 1.6 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import sys
  2. import unittest
  3. __all__ = ['get_config_vars', 'get_path']
  4. try:
  5. # Python 2.7 or >=3.2
  6. from sysconfig import get_config_vars, get_path
  7. except ImportError:
  8. from distutils.sysconfig import get_config_vars, get_python_lib
  9. def get_path(name):
  10. if name not in ('platlib', 'purelib'):
  11. raise ValueError("Name must be purelib or platlib")
  12. return get_python_lib(name=='platlib')
  13. try:
  14. # Python >=3.2
  15. from tempfile import TemporaryDirectory
  16. except ImportError:
  17. import shutil
  18. import tempfile
  19. class TemporaryDirectory(object):
  20. """"
  21. Very simple temporary directory context manager.
  22. Will try to delete afterward, but will also ignore OS and similar
  23. errors on deletion.
  24. """
  25. def __init__(self):
  26. self.name = None # Handle mkdtemp raising an exception
  27. self.name = tempfile.mkdtemp()
  28. def __enter__(self):
  29. return self.name
  30. def __exit__(self, exctype, excvalue, exctrace):
  31. try:
  32. shutil.rmtree(self.name, True)
  33. except OSError: #removal errors are not the only possible
  34. pass
  35. self.name = None
  36. unittest_main = unittest.main
  37. _PY31 = (3, 1) <= sys.version_info[:2] < (3, 2)
  38. if _PY31:
  39. # on Python 3.1, translate testRunner==None to TextTestRunner
  40. # for compatibility with Python 2.6, 2.7, and 3.2+
  41. def unittest_main(*args, **kwargs):
  42. if 'testRunner' in kwargs and kwargs['testRunner'] is None:
  43. kwargs['testRunner'] = unittest.TextTestRunner
  44. return unittest.main(*args, **kwargs)