_std.py 631 B

1234567891011121314151617181920212223242526
  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, plase import %s directly" % name,
  13. category=PyStdIsDeprecatedWarning)
  14. try:
  15. m = __import__(name)
  16. except ImportError:
  17. raise AttributeError("py.std: could not import %s" % name)
  18. return m
  19. std = Std()