You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

28 lines
606 B

  1. import os
  2. import time
  3. import hashlib
  4. from itertools import dropwhile
  5. import sys
  6. import tempfile
  7. sys.path.append(os.path.dirname(__file__))
  8. def load(module_source):
  9. descriptor, tmpfilepath = tempfile.mkstemp(suffix='.py')
  10. tmpfiledir = os.path.dirname(tmpfilepath)
  11. tmpfilename = os.path.splitext(os.path.split(tmpfilepath)[-1])[0]
  12. sys.path.append(tmpfiledir)
  13. try:
  14. with open(tmpfilepath, 'w') as f:
  15. f.write(module_source)
  16. return __import__(tmpfilename)
  17. finally:
  18. os.close(descriptor)
  19. os.remove(tmpfilepath)
  20. if __name__ == '__main__':
  21. pass