_std.py 668 B

123456789101112131415161718192021222324252627
  1. import sys
  2. import warnings
  3. class PyStdIsDeprecatedWarning(DeprecationWarning):
  4. pass
  5. class Std(object):
  6. """ makes top-level python modules available as an attribute,
  7. importing them on first access.
  8. """
  9. def __init__(self):
  10. self.__dict__ = sys.modules
  11. def __getattr__(self, name):
  12. warnings.warn("py.std is deprecated, please import %s directly" % name,
  13. category=PyStdIsDeprecatedWarning,
  14. stacklevel=2)
  15. try:
  16. m = __import__(name)
  17. except ImportError:
  18. raise AttributeError("py.std: could not import %s" % name)
  19. return m
  20. std = Std()