_compat.py 865 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # -*- coding: utf-8 -*-
  2. '''
  3. flask_login._compat
  4. -------------------
  5. A module providing tools for cross-version compatibility.
  6. '''
  7. import sys
  8. PY2 = sys.version_info[0] == 2
  9. if not PY2: # pragma: no cover
  10. unicode = str # needed for pyflakes in py3
  11. if PY2: # pragma: nocover
  12. from urlparse import urlparse, urlunparse
  13. def iteritems(d):
  14. return d.iteritems()
  15. def itervalues(d):
  16. return d.itervalues()
  17. text_type = unicode
  18. else: # pragma: nocover
  19. from urllib.parse import urlparse, urlunparse
  20. def iteritems(d):
  21. return iter(d.items())
  22. def itervalues(d):
  23. return iter(d.values())
  24. text_type = str
  25. __all__ = [
  26. 'PY2',
  27. 'unicode',
  28. 'urlparse',
  29. 'urlunparse',
  30. 'iteritems',
  31. 'itervalues',
  32. 'text_type',
  33. ]