annotate Lib/os.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 a37cfc1c9716
children 1b1d99dda2a1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16972
b83a3b78314e Use r""" instead of """ for the docstring so that backslashes are preserved.
Ka-Ping Yee <ping@zesty.ca>
parents: 16954
diff changeset
1 r"""OS routines for Mac, DOS, NT, or Posix depending on what system we're on.
580
3169d38f6774 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
3 This exports:
11708
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 11706
diff changeset
4 - all functions from posix, nt, dos, os2, mac, or ce, e.g. unlink, stat, etc.
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 11706
diff changeset
5 - os.path is one of the modules posixpath, ntpath, macpath, or dospath
16949
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
6 - os.name is 'posix', 'nt', 'dos', 'os2', 'mac', 'ce' or 'riscos'
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
7 - os.curdir is a string representing the current directory ('.' or ':')
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
8 - os.pardir is a string representing the parent directory ('..' or '::')
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
9 - os.sep is the (or a most common) pathname separator ('/' or ':' or '\\')
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20551
diff changeset
10 - os.extsep is the extension separator ('.' or '/')
11708
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 11706
diff changeset
11 - os.altsep is the alternate pathname separator (None or '/')
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
12 - os.pathsep is the component separator used in $PATH etc
11708
4a23cc49e2b0 Actually, the previous batch's comment should have been different;
Guido van Rossum <guido@python.org>
parents: 11706
diff changeset
13 - os.linesep is the line separator in text files ('\r' or '\n' or '\r\n')
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
14 - os.defpath is the default search path for executables
580
3169d38f6774 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
15
11706
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
16 Programs that import and use 'os' stand a better chance of being
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
17 portable between different platforms. Of course, they must then
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
18 only use functions that are defined by all platforms (e.g., unlink
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
19 and opendir), and leave all pathname manipulation to os.path
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
20 (e.g., split and join).
b6f52c1ef6da More trivial comment -> docstring transformations by Ka-Ping Yee,
Guido van Rossum <guido@python.org>
parents: 11431
diff changeset
21 """
580
3169d38f6774 Initial revision
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
23 #'
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
24
6204
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
25 import sys
772
d945cf33a64f Added definition for pardir ('..')
Guido van Rossum <guido@python.org>
parents: 580
diff changeset
26
6204
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
27 _names = sys.builtin_module_names
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
28
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
29 altsep = None
1785
dd167bfd7a08 do fake "import posix" for freeze.py script
Guido van Rossum <guido@python.org>
parents: 1745
diff changeset
30
16820
f54bae86a2c6 added some elements missing from __all__
Skip Montanaro <skip@pobox.com>
parents: 16460
diff changeset
31 __all__ = ["altsep", "curdir", "pardir", "sep", "pathsep", "linesep",
f54bae86a2c6 added some elements missing from __all__
Skip Montanaro <skip@pobox.com>
parents: 16460
diff changeset
32 "defpath", "name"]
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
33
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
34 def _get_exports_list(module):
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
35 try:
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
36 return list(module.__all__)
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
37 except AttributeError:
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
38 return [n for n in dir(module) if n[0] != '_']
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
39
6204
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
40 if 'posix' in _names:
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
41 name = 'posix'
8413
55fc8d933087 introduce a new platform-specific variable: os.linesep is the
Guido van Rossum <guido@python.org>
parents: 6760
diff changeset
42 linesep = '\n'
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
43 curdir = '.'; pardir = '..'; sep = '/'; pathsep = ':'
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
44 defpath = ':/bin:/usr/bin'
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
45 from posix import *
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
46 try:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
47 from posix import _exit
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
48 except ImportError:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
49 pass
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
50 import posixpath
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
51 path = posixpath
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
52 del posixpath
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
53
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
54 import posix
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
55 __all__.extend(_get_exports_list(posix))
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
56 del posix
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
57
6204
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
58 elif 'nt' in _names:
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
59 name = 'nt'
8413
55fc8d933087 introduce a new platform-specific variable: os.linesep is the
Guido van Rossum <guido@python.org>
parents: 6760
diff changeset
60 linesep = '\r\n'
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
61 curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
62 defpath = '.;C:\\bin'
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
63 from nt import *
10266
2f425a57d9af As Finn Bock points out, _P_WAIT etc. don't have a leading underscore
Guido van Rossum <guido@python.org>
parents: 10068
diff changeset
64 for i in ['_exit']:
10068
6d6f427ab6ec Special-case _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 9907
diff changeset
65 try:
6d6f427ab6ec Special-case _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 9907
diff changeset
66 exec "from nt import " + i
6d6f427ab6ec Special-case _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 9907
diff changeset
67 except ImportError:
6d6f427ab6ec Special-case _P_WAIT etc. for NT.
Guido van Rossum <guido@python.org>
parents: 9907
diff changeset
68 pass
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
69 import ntpath
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
70 path = ntpath
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
71 del ntpath
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
72
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
73 import nt
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
74 __all__.extend(_get_exports_list(nt))
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
75 del nt
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
76
6204
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
77 elif 'dos' in _names:
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
78 name = 'dos'
8413
55fc8d933087 introduce a new platform-specific variable: os.linesep is the
Guido van Rossum <guido@python.org>
parents: 6760
diff changeset
79 linesep = '\r\n'
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
80 curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
81 defpath = '.;C:\\bin'
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
82 from dos import *
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
83 try:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
84 from dos import _exit
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
85 except ImportError:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
86 pass
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
87 import dospath
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
88 path = dospath
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
89 del dospath
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
90
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
91 import dos
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
92 __all__.extend(_get_exports_list(dos))
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
93 del dos
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
94
6626
5e31d381fa47 os2 patch by Jeff Rush
Guido van Rossum <guido@python.org>
parents: 6204
diff changeset
95 elif 'os2' in _names:
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
96 name = 'os2'
8413
55fc8d933087 introduce a new platform-specific variable: os.linesep is the
Guido van Rossum <guido@python.org>
parents: 6760
diff changeset
97 linesep = '\r\n'
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
98 curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
99 defpath = '.;C:\\bin'
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
100 from os2 import *
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
101 try:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
102 from os2 import _exit
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
103 except ImportError:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
104 pass
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
105 import ntpath
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
106 path = ntpath
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
107 del ntpath
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
108
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
109 import os2
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
110 __all__.extend(_get_exports_list(os2))
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
111 del os2
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
112
6204
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
113 elif 'mac' in _names:
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
114 name = 'mac'
8413
55fc8d933087 introduce a new platform-specific variable: os.linesep is the
Guido van Rossum <guido@python.org>
parents: 6760
diff changeset
115 linesep = '\r'
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
116 curdir = ':'; pardir = '::'; sep = ':'; pathsep = '\n'
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
117 defpath = ':'
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
118 from mac import *
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
119 try:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
120 from mac import _exit
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
121 except ImportError:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
122 pass
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
123 import macpath
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
124 path = macpath
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
125 del macpath
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
126
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
127 import mac
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
128 __all__.extend(_get_exports_list(mac))
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
129 del mac
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
130
10971
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
131 elif 'ce' in _names:
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
132 name = 'ce'
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
133 linesep = '\r\n'
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
134 curdir = '.'; pardir = '..'; sep = '\\'; pathsep = ';'
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
135 defpath = '\\Windows'
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
136 from ce import *
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
137 for i in ['_exit']:
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
138 try:
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
139 exec "from ce import " + i
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
140 except ImportError:
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
141 pass
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
142 # We can use the standard Windows path.
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
143 import ntpath
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
144 path = ntpath
ddd216003bd1 Mark Hammond: patch for Windows/CE.
Guido van Rossum <guido@python.org>
parents: 10811
diff changeset
145 del ntpath
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
146
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
147 import ce
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
148 __all__.extend(_get_exports_list(ce))
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
149 del ce
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
150
16949
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
151 elif 'riscos' in _names:
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
152 name = 'riscos'
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
153 linesep = '\n'
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
154 curdir = '@'; pardir = '^'; sep = '.'; pathsep = ','
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
155 defpath = '<Run$Dir>'
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
156 from riscos import *
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
157 try:
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
158 from riscos import _exit
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
159 except ImportError:
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
160 pass
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
161 import riscospath
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
162 path = riscospath
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
163 del riscospath
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
164
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
165 import riscos
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
166 __all__.extend(_get_exports_list(riscos))
17000
e59eda525fc1 fix typo in extending __all__ for riscos platform - closes bug 406296
Skip Montanaro <skip@pobox.com>
parents: 16972
diff changeset
167 del riscos
16949
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
168
1745
d5b67d2ec7ee Merge changes
Guido van Rossum <guido@python.org>
parents: 1463
diff changeset
169 else:
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
170 raise ImportError, 'no os specific module found'
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1197
diff changeset
171
20654
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20551
diff changeset
172
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20551
diff changeset
173 if sep=='.':
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20551
diff changeset
174 extsep = '/'
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20551
diff changeset
175 else:
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20551
diff changeset
176 extsep = '.'
edd9d0b3c47e SF patch #474590 -- RISC OS support
Guido van Rossum <guido@python.org>
parents: 20551
diff changeset
177
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
178 __all__.append("path")
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
179
6204
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
180 del _names
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
181
9907
11414f023ad0 Enable os.path as a mostly-normal submodule, including "from os.path
Fred Drake <fdrake@acm.org>
parents: 8814
diff changeset
182 sys.modules['os.path'] = path
11414f023ad0 Enable os.path as a mostly-normal submodule, including "from os.path
Fred Drake <fdrake@acm.org>
parents: 8814
diff changeset
183
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
184 #'
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
185
8744
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
186 # Super directory utilities.
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
187 # (Inspired by Eric Raymond; the doc strings are mostly his)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
188
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
189 def makedirs(name, mode=0777):
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
190 """makedirs(path [, mode=0777]) -> None
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
191
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
192 Super-mkdir; create a leaf directory and all intermediate ones.
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
193 Works like mkdir, except that any intermediate path segment (not
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
194 just the rightmost) will be created if it does not exist. This is
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
195 recursive.
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
196
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
197 """
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
198 head, tail = path.split(name)
13711
48886fa82ad5 makedirs(), removedirs(): If the tail of the path is empty, do a second
Fred Drake <fdrake@acm.org>
parents: 13620
diff changeset
199 if not tail:
48886fa82ad5 makedirs(), removedirs(): If the tail of the path is empty, do a second
Fred Drake <fdrake@acm.org>
parents: 13620
diff changeset
200 head, tail = path.split(head)
8744
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
201 if head and tail and not path.exists(head):
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
202 makedirs(head, mode)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
203 mkdir(name, mode)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
204
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
205 def removedirs(name):
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
206 """removedirs(path) -> None
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
207
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
208 Super-rmdir; remove a leaf directory and empty all intermediate
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
209 ones. Works like rmdir except that, if the leaf directory is
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
210 successfully removed, directories corresponding to rightmost path
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
211 segments will be pruned way until either the whole path is
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
212 consumed or an error occurs. Errors during this latter phase are
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
213 ignored -- they generally mean that a directory was not empty.
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
214
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
215 """
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
216 rmdir(name)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
217 head, tail = path.split(name)
13711
48886fa82ad5 makedirs(), removedirs(): If the tail of the path is empty, do a second
Fred Drake <fdrake@acm.org>
parents: 13620
diff changeset
218 if not tail:
48886fa82ad5 makedirs(), removedirs(): If the tail of the path is empty, do a second
Fred Drake <fdrake@acm.org>
parents: 13620
diff changeset
219 head, tail = path.split(head)
8744
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
220 while head and tail:
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
221 try:
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
222 rmdir(head)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
223 except error:
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
224 break
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
225 head, tail = path.split(head)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
226
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
227 def renames(old, new):
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
228 """renames(old, new) -> None
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
229
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
230 Super-rename; create directories as necessary and delete any left
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
231 empty. Works like rename, except creation of any intermediate
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
232 directories needed to make the new pathname good is attempted
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
233 first. After the rename, directories corresponding to rightmost
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
234 path segments of the old name will be pruned way until either the
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
235 whole path is consumed or a nonempty directory is found.
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
236
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
237 Note: this function can fail with the new directory structure made
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
238 if you lack permissions needed to unlink the leaf directory or
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
239 file.
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
240
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
241 """
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
242 head, tail = path.split(new)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
243 if head and tail and not path.exists(head):
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
244 makedirs(head)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
245 rename(old, new)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
246 head, tail = path.split(old)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
247 if head and tail:
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
248 try:
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
249 removedirs(head)
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
250 except error:
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
251 pass
1d581a6dfeee Add makedirs(), removedirs(), renames() -- ESR-inspired super-versions
Guido van Rossum <guido@python.org>
parents: 8413
diff changeset
252
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
253 __all__.extend(["makedirs", "removedirs", "renames"])
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
254
6204
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
255 # Make sure os.environ exists, at least
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
256 try:
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
257 environ
6204
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
258 except NameError:
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
259 environ = {}
6204
24d668454cb0 Write out the dynamic OS choice, to avoid exec statements.
Guido van Rossum <guido@python.org>
parents: 3805
diff changeset
260
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1197
diff changeset
261 def execl(file, *args):
12488
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
262 """execl(file, *args)
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
263
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
264 Execute the executable file with argument list args, replacing the
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
265 current process. """
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
266 execv(file, args)
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1197
diff changeset
267
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1197
diff changeset
268 def execle(file, *args):
12488
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
269 """execle(file, *args, env)
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
270
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
271 Execute the executable file with argument list args and
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
272 environment env, replacing the current process. """
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
273 env = args[-1]
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
274 execve(file, args[:-1], env)
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1197
diff changeset
275
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1197
diff changeset
276 def execlp(file, *args):
12488
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
277 """execlp(file, *args)
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
278
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
279 Execute the executable file (which is searched for along $PATH)
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
280 with argument list args, replacing the current process. """
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
281 execvp(file, args)
1403
6278933d02e3 * string.py: added rindex(), rfind(); changed index() to interpret
Guido van Rossum <guido@python.org>
parents: 1197
diff changeset
282
2539
534a97c400cc add execvpe -- mix of execvp and execve
Guido van Rossum <guido@python.org>
parents: 1932
diff changeset
283 def execlpe(file, *args):
12488
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
284 """execlpe(file, *args, env)
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
285
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
286 Execute the executable file (which is searched for along $PATH)
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
287 with argument list args and environment env, replacing the current
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 14913
diff changeset
288 process. """
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
289 env = args[-1]
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
290 execvpe(file, args[:-1], env)
2539
534a97c400cc add execvpe -- mix of execvp and execve
Guido van Rossum <guido@python.org>
parents: 1932
diff changeset
291
534a97c400cc add execvpe -- mix of execvp and execve
Guido van Rossum <guido@python.org>
parents: 1932
diff changeset
292 def execvp(file, args):
12488
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
293 """execp(file, args)
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
294
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
295 Execute the executable file (which is searched for along $PATH)
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
296 with argument list args, replacing the current process.
13620
5b727ab37092 Spelling fixes supplied by Rob W. W. Hooft. All these are fixes in either
Thomas Wouters <thomas@python.org>
parents: 12502
diff changeset
297 args may be a list or tuple of strings. """
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
298 _execvpe(file, args)
2539
534a97c400cc add execvpe -- mix of execvp and execve
Guido van Rossum <guido@python.org>
parents: 1932
diff changeset
299
534a97c400cc add execvpe -- mix of execvp and execve
Guido van Rossum <guido@python.org>
parents: 1932
diff changeset
300 def execvpe(file, args, env):
25103
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
301 """execvpe(file, args, env)
12488
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
302
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
303 Execute the executable file (which is searched for along $PATH)
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
304 with argument list args and environment env , replacing the
8b330d163800 Michael Hudson:
Guido van Rossum <guido@python.org>
parents: 12434
diff changeset
305 current process.
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 14913
diff changeset
306 args may be a list or tuple of strings. """
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
307 _execvpe(file, args, env)
2539
534a97c400cc add execvpe -- mix of execvp and execve
Guido van Rossum <guido@python.org>
parents: 1932
diff changeset
308
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
309 __all__.extend(["execl","execle","execlp","execlpe","execvp","execvpe"])
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
310
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
311 def _execvpe(file, args, env=None):
24667
579f09c0fdbc Backport of SF patch 590294: os._execvpe security fix (Zack Weinberg).
Guido van Rossum <guido@python.org>
parents: 22335
diff changeset
312 from errno import ENOENT, ENOTDIR
579f09c0fdbc Backport of SF patch 590294: os._execvpe security fix (Zack Weinberg).
Guido van Rossum <guido@python.org>
parents: 22335
diff changeset
313
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
314 if env is not None:
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
315 func = execve
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
316 argrest = (args, env)
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
317 else:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
318 func = execv
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
319 argrest = (args,)
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
320 env = environ
24667
579f09c0fdbc Backport of SF patch 590294: os._execvpe security fix (Zack Weinberg).
Guido van Rossum <guido@python.org>
parents: 22335
diff changeset
321
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
322 head, tail = path.split(file)
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
323 if head:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
324 apply(func, (file,) + argrest)
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
325 return
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
326 if env.has_key('PATH'):
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
327 envpath = env['PATH']
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
328 else:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
329 envpath = defpath
12232
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
330 PATH = envpath.split(pathsep)
25103
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
331 saved_exc = None
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
332 saved_tb = None
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
333 for dir in PATH:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
334 fullname = path.join(dir, file)
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
335 try:
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
336 apply(func, (fullname,) + argrest)
25103
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
337 except error, e:
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
338 tb = sys.exc_info()[2]
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
339 if (e.errno != ENOENT and e.errno != ENOTDIR
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
340 and saved_exc is None):
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
341 saved_exc = e
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
342 saved_tb = tb
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
343 if saved_exc:
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
344 raise error, saved_exc, saved_tb
f9e4243ff792 Backport:
Guido van Rossum <guido@python.org>
parents: 24667
diff changeset
345 raise error, e, tb
16949
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
346
17007
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
347 # Change environ to automatically call putenv() if it exists
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
348 try:
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
349 # This will fail if there's no putenv
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
350 putenv
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
351 except NameError:
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
352 pass
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
353 else:
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
354 import UserDict
3805
4f73962aaba6 Added hook to os.environ to call putenv(), if it exists.
Guido van Rossum <guido@python.org>
parents: 2921
diff changeset
355
20551
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
356 # Fake unsetenv() for Windows
20765
3a07bd2b0386 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 20654
diff changeset
357 # not sure about os2 and dos here but
20551
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
358 # I'm guessing they are the same.
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
359
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
360 if name in ('os2', 'nt', 'dos'):
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
361 def unsetenv(key):
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
362 putenv(key, "")
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
363
17007
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
364 if name == "riscos":
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
365 # On RISC OS, all env access goes through getenv and putenv
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
366 from riscosenviron import _Environ
4c17cb2c621e Unify _Environ processing on riscos with other platforms.
Martin v. Löwis <martin@v.loewis.de>
parents: 17000
diff changeset
367 elif name in ('os2', 'nt', 'dos'): # Where Env Var Names Must Be UPPERCASE
8814
6738e5383977 Support case insensitive treatment of os.environ keys on Windows and
Guido van Rossum <guido@python.org>
parents: 8744
diff changeset
368 # But we store them as upper case
25142
deb64dfc8416 Have os.environ inherit from the iterable version of UserDict.
Raymond Hettinger <python@rcn.com>
parents: 25103
diff changeset
369 class _Environ(UserDict.IterableUserDict):
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
370 def __init__(self, environ):
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
371 UserDict.UserDict.__init__(self)
8814
6738e5383977 Support case insensitive treatment of os.environ keys on Windows and
Guido van Rossum <guido@python.org>
parents: 8744
diff changeset
372 data = self.data
6738e5383977 Support case insensitive treatment of os.environ keys on Windows and
Guido van Rossum <guido@python.org>
parents: 8744
diff changeset
373 for k, v in environ.items():
12232
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
374 data[k.upper()] = v
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
375 def __setitem__(self, key, item):
8814
6738e5383977 Support case insensitive treatment of os.environ keys on Windows and
Guido van Rossum <guido@python.org>
parents: 8744
diff changeset
376 putenv(key, item)
12232
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
377 self.data[key.upper()] = item
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
378 def __getitem__(self, key):
12232
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
379 return self.data[key.upper()]
20551
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
380 try:
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
381 unsetenv
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
382 except NameError:
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
383 def __delitem__(self, key):
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
384 del self.data[key.upper()]
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
385 else:
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
386 def __delitem__(self, key):
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
387 unsetenv(key)
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
388 del self.data[key.upper()]
10811
d73a3293c47b The case-insensitive _Environ class was lacking a case-insensitive has_key().
Guido van Rossum <guido@python.org>
parents: 10266
diff changeset
389 def has_key(self, key):
12232
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
390 return self.data.has_key(key.upper())
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
391 def get(self, key, failobj=None):
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
392 return self.data.get(key.upper(), failobj)
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
393 def update(self, dict):
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
394 for k, v in dict.items():
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
395 self[k] = v
3805
4f73962aaba6 Added hook to os.environ to call putenv(), if it exists.
Guido van Rossum <guido@python.org>
parents: 2921
diff changeset
396
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
397 else: # Where Env Var Names Can Be Mixed Case
25162
a37cfc1c9716 Change UserDict to IterableUserDict
Raymond Hettinger <python@rcn.com>
parents: 25142
diff changeset
398 class _Environ(UserDict.IterableUserDict):
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
399 def __init__(self, environ):
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
400 UserDict.UserDict.__init__(self)
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
401 self.data = environ
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
402 def __setitem__(self, key, item):
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
403 putenv(key, item)
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
404 self.data[key] = item
12232
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
405 def update(self, dict):
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
406 for k, v in dict.items():
63135e9def24 Patch by Fred Gansevles.
Guido van Rossum <guido@python.org>
parents: 11708
diff changeset
407 self[k] = v
20551
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
408 try:
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
409 unsetenv
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
410 except NameError:
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
411 pass
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
412 else:
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
413 def __delitem__(self, key):
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
414 unsetenv(key)
c9608c790f6f SF patch #460805 by Chris Gonnerman: Support for unsetenv()
Guido van Rossum <guido@python.org>
parents: 17007
diff changeset
415 del self.data[key]
20765
3a07bd2b0386 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 20654
diff changeset
416
6760
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
417
0204d461d219 Reindented according to new standard, without tabs.
Guido van Rossum <guido@python.org>
parents: 6690
diff changeset
418 environ = _Environ(environ)
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
419
16949
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
420 def getenv(key, default=None):
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
421 """Get an environment variable, return None if it doesn't exist.
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
422 The optional second argument can specify an alternate default."""
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
423 return environ.get(key, default)
09ba15ee1961 RISCOS changes by dschwertberger.
Guido van Rossum <guido@python.org>
parents: 16820
diff changeset
424 __all__.append("getenv")
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
425
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
426 def _exists(name):
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
427 try:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
428 eval(name)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
429 return 1
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
430 except NameError:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
431 return 0
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
432
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
433 # Supply spawn*() (probably only for Unix)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
434 if _exists("fork") and not _exists("spawnv") and _exists("execv"):
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
435
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
436 P_WAIT = 0
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
437 P_NOWAIT = P_NOWAITO = 1
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
438
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
439 # XXX Should we support P_DETACH? I suppose it could fork()**2
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
440 # and close the std I/O streams. Also, P_OVERLAY is the same
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
441 # as execv*()?
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
442
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
443 def _spawnvef(mode, file, args, env, func):
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
444 # Internal helper; func is the exec*() function to use
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
445 pid = fork()
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
446 if not pid:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
447 # Child
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
448 try:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
449 if env is None:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
450 func(file, args)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
451 else:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
452 func(file, args, env)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
453 except:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
454 _exit(127)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
455 else:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
456 # Parent
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
457 if mode == P_NOWAIT:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
458 return pid # Caller is responsible for waiting!
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
459 while 1:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
460 wpid, sts = waitpid(pid, 0)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
461 if WIFSTOPPED(sts):
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
462 continue
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
463 elif WIFSIGNALED(sts):
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
464 return -WTERMSIG(sts)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
465 elif WIFEXITED(sts):
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
466 return WEXITSTATUS(sts)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
467 else:
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
468 raise error, "Not stopped, signaled or exited???"
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
469
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
470 def spawnv(mode, file, args):
12434
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
471 """spawnv(mode, file, args) -> integer
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
472
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
473 Execute file with arguments from args in a subprocess.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
474 If mode == P_NOWAIT return the pid of the process.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
475 If mode == P_WAIT return the process's exit code if it exits normally;
15870
010d03853546 Whitespace normalization.
Tim Peters <tim.peters@gmail.com>
parents: 14913
diff changeset
476 otherwise return -SIG, where SIG is the signal that killed it. """
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
477 return _spawnvef(mode, file, args, None, execv)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
478
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
479 def spawnve(mode, file, args, env):
12434
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
480 """spawnve(mode, file, args, env) -> integer
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
481
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
482 Execute file with arguments from args in a subprocess with the
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
483 specified environment.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
484 If mode == P_NOWAIT return the pid of the process.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
485 If mode == P_WAIT return the process's exit code if it exits normally;
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
486 otherwise return -SIG, where SIG is the signal that killed it. """
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
487 return _spawnvef(mode, file, args, env, execve)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
488
11431
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
489 # Note: spawnvp[e] is't currently supported on Windows
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
490
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
491 def spawnvp(mode, file, args):
12434
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
492 """spawnvp(mode, file, args) -> integer
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
493
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
494 Execute file (which is looked for along $PATH) with arguments from
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
495 args in a subprocess.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
496 If mode == P_NOWAIT return the pid of the process.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
497 If mode == P_WAIT return the process's exit code if it exits normally;
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
498 otherwise return -SIG, where SIG is the signal that killed it. """
11431
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
499 return _spawnvef(mode, file, args, None, execvp)
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
500
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
501 def spawnvpe(mode, file, args, env):
12434
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
502 """spawnvpe(mode, file, args, env) -> integer
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
503
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
504 Execute file (which is looked for along $PATH) with arguments from
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
505 args in a subprocess with the supplied environment.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
506 If mode == P_NOWAIT return the pid of the process.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
507 If mode == P_WAIT return the process's exit code if it exits normally;
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
508 otherwise return -SIG, where SIG is the signal that killed it. """
11431
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
509 return _spawnvef(mode, file, args, env, execvpe)
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
510
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
511 if _exists("spawnv"):
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
512 # These aren't supplied by the basic Windows code
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
513 # but can be easily implemented in Python
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
514
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
515 def spawnl(mode, file, *args):
12434
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
516 """spawnl(mode, file, *args) -> integer
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
517
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
518 Execute file with arguments from args in a subprocess.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
519 If mode == P_NOWAIT return the pid of the process.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
520 If mode == P_WAIT return the process's exit code if it exits normally;
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
521 otherwise return -SIG, where SIG is the signal that killed it. """
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
522 return spawnv(mode, file, args)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
523
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
524 def spawnle(mode, file, *args):
12434
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
525 """spawnle(mode, file, *args, env) -> integer
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
526
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
527 Execute file with arguments from args in a subprocess with the
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
528 supplied environment.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
529 If mode == P_NOWAIT return the pid of the process.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
530 If mode == P_WAIT return the process's exit code if it exits normally;
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
531 otherwise return -SIG, where SIG is the signal that killed it. """
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
532 env = args[-1]
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
533 return spawnve(mode, file, args[:-1], env)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
534
11431
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
535 if _exists("spawnvp"):
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
536 # At the moment, Windows doesn't implement spawnvp[e],
a316cf9f81a7 Oops. spawnl() and spawnle() should be implemented on Windows too.
Guido van Rossum <guido@python.org>
parents: 11427
diff changeset
537 # so it won't have spawnlp[e] either.
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
538 def spawnlp(mode, file, *args):
12434
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
539 """spawnlp(mode, file, *args, env) -> integer
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
540
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
541 Execute file (which is looked for along $PATH) with arguments from
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
542 args in a subprocess with the supplied environment.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
543 If mode == P_NOWAIT return the pid of the process.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
544 If mode == P_WAIT return the process's exit code if it exits normally;
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
545 otherwise return -SIG, where SIG is the signal that killed it. """
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
546 return spawnvp(mode, file, args)
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
547
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
548 def spawnlpe(mode, file, *args):
12434
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
549 """spawnlpe(mode, file, *args, env) -> integer
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
550
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
551 Execute file (which is looked for along $PATH) with arguments from
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
552 args in a subprocess with the supplied environment.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
553 If mode == P_NOWAIT return the pid of the process.
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
554 If mode == P_WAIT return the process's exit code if it exits normally;
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
555 otherwise return -SIG, where SIG is the signal that killed it. """
11427
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
556 env = args[-1]
98997aa49164 Checking in a bunch of spawn functions. These are only defined if we
Guido van Rossum <guido@python.org>
parents: 10971
diff changeset
557 return spawnvpe(mode, file, args[:-1], env)
12434
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
558
6a8cd0682096 Doc strings for the spawn* functions, by Michael Hudson.
Guido van Rossum <guido@python.org>
parents: 12232
diff changeset
559
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
560 __all__.extend(["spawnlp","spawnlpe","spawnv", "spawnve","spawnvp",
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
561 "spawnvpe","spawnl","spawnle",])
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
562
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
563
14675
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
564 # Supply popen2 etc. (for Unix)
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
565 if _exists("fork"):
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
566 if not _exists("popen2"):
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
567 def popen2(cmd, mode="t", bufsize=-1):
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
568 import popen2
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
569 stdout, stdin = popen2.popen2(cmd, bufsize)
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
570 return stdin, stdout
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
571 __all__.append("popen2")
14236
58d7995ce795 Added os.popen2() and os.popen3() for non-Windows platforms.
Fred Drake <fdrake@acm.org>
parents: 13711
diff changeset
572
14675
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
573 if not _exists("popen3"):
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
574 def popen3(cmd, mode="t", bufsize=-1):
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
575 import popen2
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
576 stdout, stdin, stderr = popen2.popen3(cmd, bufsize)
22011d976917 Only supply popen2, popen3 when fork exists.
Guido van Rossum <guido@python.org>
parents: 14236
diff changeset
577 return stdin, stdout, stderr
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
578 __all__.append("popen3")
14913
a062749b80f8 popen4(): Added for Unix.
Fred Drake <fdrake@acm.org>
parents: 14675
diff changeset
579
a062749b80f8 popen4(): Added for Unix.
Fred Drake <fdrake@acm.org>
parents: 14675
diff changeset
580 if not _exists("popen4"):
a062749b80f8 popen4(): Added for Unix.
Fred Drake <fdrake@acm.org>
parents: 14675
diff changeset
581 def popen4(cmd, mode="t", bufsize=-1):
a062749b80f8 popen4(): Added for Unix.
Fred Drake <fdrake@acm.org>
parents: 14675
diff changeset
582 import popen2
a062749b80f8 popen4(): Added for Unix.
Fred Drake <fdrake@acm.org>
parents: 14675
diff changeset
583 stdout, stdin = popen2.popen4(cmd, bufsize)
a062749b80f8 popen4(): Added for Unix.
Fred Drake <fdrake@acm.org>
parents: 14675
diff changeset
584 return stdin, stdout
16460
c18ac8c2f036 added several more __all__ lists
Skip Montanaro <skip@pobox.com>
parents: 15870
diff changeset
585 __all__.append("popen4")
22164
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
586
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
587 import copy_reg as _copy_reg
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
588
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
589 def _make_stat_result(tup, dict):
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
590 return stat_result(tup, dict)
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
591
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
592 def _pickle_stat_result(sr):
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
593 (type, args) = sr.__reduce__()
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
594 return (_make_stat_result, args)
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
595
22335
0fd3831cf2a0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22164
diff changeset
596 try:
0fd3831cf2a0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22164
diff changeset
597 _copy_reg.pickle(stat_result, _pickle_stat_result, _make_stat_result)
0fd3831cf2a0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22164
diff changeset
598 except NameError: # stat_result may not exist
0fd3831cf2a0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22164
diff changeset
599 pass
22164
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
600
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
601 def _make_statvfs_result(tup, dict):
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
602 return statvfs_result(tup, dict)
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
603
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
604 def _pickle_statvfs_result(sr):
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
605 (type, args) = sr.__reduce__()
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
606 return (_make_statvfs_result, args)
af6122df28e0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 20765
diff changeset
607
22335
0fd3831cf2a0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22164
diff changeset
608 try:
0fd3831cf2a0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22164
diff changeset
609 _copy_reg.pickle(statvfs_result, _pickle_statvfs_result,
0fd3831cf2a0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22164
diff changeset
610 _make_statvfs_result)
0fd3831cf2a0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22164
diff changeset
611 except NameError: # statvfs_result may not exist
0fd3831cf2a0 backport my checkin of
Michael W. Hudson <mwh@python.net>
parents: 22164
diff changeset
612 pass