Mercurial > cpython-lru_cache-weakref
annotate Lib/user.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 86f66061003c |
| children |
| rev | line source |
|---|---|
|
6182
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
1 """Hook to allow user-specified customization code to run. |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 As a policy, Python doesn't run user-specified code on startup of |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 Python programs (interactive sessions execute the script specified in |
|
12114
2721c7cc0b27
Lawrence Kesteloot noted: Lib/user.py has a comment that says that the
Guido van Rossum <guido@python.org>
parents:
7755
diff
changeset
|
5 the PYTHONSTARTUP environment variable if it exists). |
|
6182
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 However, some programs or sites may find it convenient to allow users |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 to have a standard customization file, which gets run when a program |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 requests it. This module implements such a mechanism. A program |
| 6209 | 10 that wishes to use the mechanism must execute the statement |
|
6182
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 import user |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 The user module looks for a file .pythonrc.py in the user's home |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 directory and if it can be opened, execfile()s it in its own global |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 namespace. Errors during this phase are not caught; that's up to the |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 program that imports the user module, if it wishes. |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 The user's .pythonrc.py could conceivably test for sys.version if it |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 wishes to do different things depending on the Python version. |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 """ |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 import os |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6736
diff
changeset
|
26 home = os.curdir # Default |
|
6736
53fd42aa3bbf
Refinement of home for NT, courtesy Jeff Bauer.
Guido van Rossum <guido@python.org>
parents:
6209
diff
changeset
|
27 if os.environ.has_key('HOME'): |
|
6182
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 home = os.environ['HOME'] |
| 25601 | 29 elif os.name == 'posix': |
| 30 home = os.path.expanduser("~/") | |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6736
diff
changeset
|
31 elif os.name == 'nt': # Contributed by Jeff Bauer |
|
6736
53fd42aa3bbf
Refinement of home for NT, courtesy Jeff Bauer.
Guido van Rossum <guido@python.org>
parents:
6209
diff
changeset
|
32 if os.environ.has_key('HOMEPATH'): |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6736
diff
changeset
|
33 if os.environ.has_key('HOMEDRIVE'): |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6736
diff
changeset
|
34 home = os.environ['HOMEDRIVE'] + os.environ['HOMEPATH'] |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6736
diff
changeset
|
35 else: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6736
diff
changeset
|
36 home = os.environ['HOMEPATH'] |
|
6182
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
37 |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
38 pythonrc = os.path.join(home, ".pythonrc.py") |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
39 try: |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 f = open(pythonrc) |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 except IOError: |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 pass |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 else: |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 f.close() |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 execfile(pythonrc) |
