obsoletepythonsupport.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # The contents of this file are subject to the Python Software Foundation
  2. # License Version 2.3 (the License). You may not copy or use this file, in
  3. # either source code or executable form, except in compliance with the License.
  4. # You may obtain a copy of the License at http://www.python.org/license.
  5. #
  6. # Software distributed under the License is distributed on an AS IS basis,
  7. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
  8. # for the specific language governing rights and limitations under the
  9. # License.
  10. from __future__ import generators
  11. def import_curses():
  12. import curses
  13. if not hasattr(curses, 'use_default_colors'):
  14. def use_default_colors():
  15. return
  16. curses.use_default_colors = use_default_colors
  17. return curses
  18. has_set = False
  19. try:
  20. # python 2.4
  21. from __builtin__ import set
  22. has_set = True
  23. except (ImportError, NameError): # I don't know if NameError ever gets raised
  24. try:
  25. # python 2.3
  26. from sets import Set
  27. set = Set
  28. has_set = True
  29. except ImportError:
  30. # python 2.2
  31. set = None
  32. pass
  33. try:
  34. from os import urandom
  35. except:
  36. import random
  37. def urandom(n):
  38. return ''.join([ chr(random.randint(0, 255)) for x in xrange(n)])