Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 
 

77 lignes
2.3 KiB

  1. def __boot():
  2. import sys
  3. import os
  4. PYTHONPATH = os.environ.get('PYTHONPATH')
  5. if PYTHONPATH is None or (sys.platform=='win32' and not PYTHONPATH):
  6. PYTHONPATH = []
  7. else:
  8. PYTHONPATH = PYTHONPATH.split(os.pathsep)
  9. pic = getattr(sys,'path_importer_cache',{})
  10. stdpath = sys.path[len(PYTHONPATH):]
  11. mydir = os.path.dirname(__file__)
  12. #print "searching",stdpath,sys.path
  13. for item in stdpath:
  14. if item==mydir or not item:
  15. continue # skip if current dir. on Windows, or my own directory
  16. importer = pic.get(item)
  17. if importer is not None:
  18. loader = importer.find_module('site')
  19. if loader is not None:
  20. # This should actually reload the current module
  21. loader.load_module('site')
  22. break
  23. else:
  24. try:
  25. import imp # Avoid import loop in Python >= 3.3
  26. stream, path, descr = imp.find_module('site',[item])
  27. except ImportError:
  28. continue
  29. if stream is None:
  30. continue
  31. try:
  32. # This should actually reload the current module
  33. imp.load_module('site',stream,path,descr)
  34. finally:
  35. stream.close()
  36. break
  37. else:
  38. raise ImportError("Couldn't find the real 'site' module")
  39. #print "loaded", __file__
  40. known_paths = dict([(makepath(item)[1],1) for item in sys.path]) # 2.2 comp
  41. oldpos = getattr(sys,'__egginsert',0) # save old insertion position
  42. sys.__egginsert = 0 # and reset the current one
  43. for item in PYTHONPATH:
  44. addsitedir(item)
  45. sys.__egginsert += oldpos # restore effective old position
  46. d, nd = makepath(stdpath[0])
  47. insert_at = None
  48. new_path = []
  49. for item in sys.path:
  50. p, np = makepath(item)
  51. if np==nd and insert_at is None:
  52. # We've hit the first 'system' path entry, so added entries go here
  53. insert_at = len(new_path)
  54. if np in known_paths or insert_at is None:
  55. new_path.append(item)
  56. else:
  57. # new path after the insert point, back-insert it
  58. new_path.insert(insert_at, item)
  59. insert_at += 1
  60. sys.path[:] = new_path
  61. if __name__=='site':
  62. __boot()
  63. del __boot