Mercurial > cpython-lru_cache-weakref
annotate Lib/user.py @ 80661:94de77bd0b4b 2.7
Issue #16194: document imp.load_dynamic problems
when read several extension modules from the same binary object file.
| author | Andrew Svetlov <andrew.svetlov@gmail.com> |
|---|---|
| date | Thu, 29 Nov 2012 19:51:28 +0200 |
| parents | fb1984fb182d |
| 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 """ |
|
46764
fb1984fb182d
Deprecate the user module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents:
25126
diff
changeset
|
23 from warnings import warnpy3k |
|
fb1984fb182d
Deprecate the user module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents:
25126
diff
changeset
|
24 warnpy3k("the user module has been removed in Python 3.0", stacklevel=2) |
|
fb1984fb182d
Deprecate the user module for removal in 3.0.
Brett Cannon <bcannon@gmail.com>
parents:
25126
diff
changeset
|
25 del warnpy3k |
|
6182
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 import os |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6736
diff
changeset
|
29 home = os.curdir # Default |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
12114
diff
changeset
|
30 if 'HOME' in os.environ: |
|
6182
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 home = os.environ['HOME'] |
|
25126
56f9f5ab6ec1
SF # 555779, import user doesn't work with CGIs
Neal Norwitz <nnorwitz@gmail.com>
parents:
23620
diff
changeset
|
32 elif os.name == 'posix': |
|
56f9f5ab6ec1
SF # 555779, import user doesn't work with CGIs
Neal Norwitz <nnorwitz@gmail.com>
parents:
23620
diff
changeset
|
33 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
|
34 elif os.name == 'nt': # Contributed by Jeff Bauer |
|
23620
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
12114
diff
changeset
|
35 if 'HOMEPATH' in os.environ: |
|
a1de0bab5475
SF 563203. Replaced 'has_key()' with 'in'.
Raymond Hettinger <python@rcn.com>
parents:
12114
diff
changeset
|
36 if 'HOMEDRIVE' in os.environ: |
|
7755
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6736
diff
changeset
|
37 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
|
38 else: |
|
fb4b4d069cc7
Mass check-in after untabifying all files that need it.
Guido van Rossum <guido@python.org>
parents:
6736
diff
changeset
|
39 home = os.environ['HOMEPATH'] |
|
6182
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
40 |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
41 pythonrc = os.path.join(home, ".pythonrc.py") |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
42 try: |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
43 f = open(pythonrc) |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
44 except IOError: |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
45 pass |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
46 else: |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
47 f.close() |
|
43b8c4a696d1
user.py -- when imported, execfile(~/.pythonrc.py).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
48 execfile(pythonrc) |
