| 1 | n/a | """Hook to allow user-specified customization code to run. |
|---|
| 2 | n/a | |
|---|
| 3 | n/a | As a policy, Python doesn't run user-specified code on startup of |
|---|
| 4 | n/a | Python programs (interactive sessions execute the script specified in |
|---|
| 5 | n/a | the PYTHONSTARTUP environment variable if it exists). |
|---|
| 6 | n/a | |
|---|
| 7 | n/a | However, some programs or sites may find it convenient to allow users |
|---|
| 8 | n/a | to have a standard customization file, which gets run when a program |
|---|
| 9 | n/a | requests it. This module implements such a mechanism. A program |
|---|
| 10 | n/a | that wishes to use the mechanism must execute the statement |
|---|
| 11 | n/a | |
|---|
| 12 | n/a | import user |
|---|
| 13 | n/a | |
|---|
| 14 | n/a | The user module looks for a file .pythonrc.py in the user's home |
|---|
| 15 | n/a | directory and if it can be opened, execfile()s it in its own global |
|---|
| 16 | n/a | namespace. Errors during this phase are not caught; that's up to the |
|---|
| 17 | n/a | program that imports the user module, if it wishes. |
|---|
| 18 | n/a | |
|---|
| 19 | n/a | The user's .pythonrc.py could conceivably test for sys.version if it |
|---|
| 20 | n/a | wishes to do different things depending on the Python version. |
|---|
| 21 | n/a | |
|---|
| 22 | n/a | """ |
|---|
| 23 | n/a | from warnings import warnpy3k |
|---|
| 24 | n/a | warnpy3k("the user module has been removed in Python 3.0", stacklevel=2) |
|---|
| 25 | n/a | del warnpy3k |
|---|
| 26 | n/a | |
|---|
| 27 | n/a | import os |
|---|
| 28 | n/a | |
|---|
| 29 | n/a | home = os.curdir # Default |
|---|
| 30 | n/a | if 'HOME' in os.environ: |
|---|
| 31 | n/a | home = os.environ['HOME'] |
|---|
| 32 | n/a | elif os.name == 'posix': |
|---|
| 33 | n/a | home = os.path.expanduser("~/") |
|---|
| 34 | n/a | elif os.name == 'nt': # Contributed by Jeff Bauer |
|---|
| 35 | n/a | if 'HOMEPATH' in os.environ: |
|---|
| 36 | n/a | if 'HOMEDRIVE' in os.environ: |
|---|
| 37 | n/a | home = os.environ['HOMEDRIVE'] + os.environ['HOMEPATH'] |
|---|
| 38 | n/a | else: |
|---|
| 39 | n/a | home = os.environ['HOMEPATH'] |
|---|
| 40 | n/a | |
|---|
| 41 | n/a | pythonrc = os.path.join(home, ".pythonrc.py") |
|---|
| 42 | n/a | try: |
|---|
| 43 | n/a | f = open(pythonrc) |
|---|
| 44 | n/a | except IOError: |
|---|
| 45 | n/a | pass |
|---|
| 46 | n/a | else: |
|---|
| 47 | n/a | f.close() |
|---|
| 48 | n/a | execfile(pythonrc) |
|---|