ยปCore Development>Code coverage>Lib/user.py

Python code coverage for Lib/user.py

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