Whitespace normalization.

This commit is contained in:
Tim Peters 2004-10-12 21:51:32 +00:00
parent 4eb59782a8
commit e718f615b8
4 changed files with 43 additions and 47 deletions

View File

@ -115,7 +115,7 @@ def formatdate(timeval=None, localtime=False, usegmt=False):
returns a date relative to the local timezone instead of UTC, properly returns a date relative to the local timezone instead of UTC, properly
taking daylight savings time into account. taking daylight savings time into account.
Optional argument usegmt means that the timezone is written out as Optional argument usegmt means that the timezone is written out as
an ascii string, not numeric one (so "GMT" instead of "+0000"). This an ascii string, not numeric one (so "GMT" instead of "+0000"). This
is needed for HTTP, and is only used when localtime==False. is needed for HTTP, and is only used when localtime==False.
""" """

View File

@ -946,7 +946,7 @@ Deletes the specified alias."""
into an absolute file name. into an absolute file name.
""" """
if os.path.isabs(filename) and os.path.exists(filename): if os.path.isabs(filename) and os.path.exists(filename):
return filename return filename
f = os.path.join(sys.path[0], filename) f = os.path.join(sys.path[0], filename)
if os.path.exists(f) and self.canonic(f) == self.mainpyfile: if os.path.exists(f) and self.canonic(f) == self.mainpyfile:
return f return f
@ -967,8 +967,8 @@ Deletes the specified alias."""
# Start with fresh empty copy of globals and locals and tell the script # Start with fresh empty copy of globals and locals and tell the script
# that it's being run as __main__ to avoid scripts being able to access # that it's being run as __main__ to avoid scripts being able to access
# the pdb.py namespace. # the pdb.py namespace.
globals_ = {"__name__" : "__main__"} globals_ = {"__name__" : "__main__"}
locals_ = globals_ locals_ = globals_
# When bdb sets tracing, a number of call and line events happens # When bdb sets tracing, a number of call and line events happens
# BEFORE debugger even reaches user's code (and the exact sequence of # BEFORE debugger even reaches user's code (and the exact sequence of
@ -1057,7 +1057,7 @@ def main():
pdb._runscript(mainpyfile) pdb._runscript(mainpyfile)
if pdb._user_requested_quit: if pdb._user_requested_quit:
break break
print "The program finished and will be restarted" print "The program finished and will be restarted"
except SystemExit: except SystemExit:
# In most cases SystemExit does not warrant a post-mortem session. # In most cases SystemExit does not warrant a post-mortem session.
print "The program exited via sys.exit(). Exit status: ", print "The program exited via sys.exit(). Exit status: ",
@ -1076,4 +1076,3 @@ def main():
# When invoked as main program, invoke the debugger on a script # When invoked as main program, invoke the debugger on a script
if __name__=='__main__': if __name__=='__main__':
main() main()

View File

@ -1,6 +1,6 @@
# subprocess - Subprocesses with accessible I/O streams # subprocess - Subprocesses with accessible I/O streams
# #
# For more information about this module, see PEP 324. # For more information about this module, see PEP 324.
# #
# Copyright (c) 2003-2004 by Peter Astrand <astrand@lysator.liu.se> # Copyright (c) 2003-2004 by Peter Astrand <astrand@lysator.liu.se>
# #
@ -174,7 +174,7 @@ communicate(input=None)
terminate. The optional stdin argument should be a string to be terminate. The optional stdin argument should be a string to be
sent to the child process, or None, if no data should be sent to sent to the child process, or None, if no data should be sent to
the child. the child.
communicate() returns a tuple (stdout, stderr). communicate() returns a tuple (stdout, stderr).
Note: The data read is buffered in memory, so do not use this Note: The data read is buffered in memory, so do not use this
@ -262,7 +262,7 @@ except OSError, e:
Replacing os.spawn* Replacing os.spawn*
------------------- -------------------
P_NOWAIT example: P_NOWAIT example:
pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg") pid = os.spawnlp(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg")
==> ==>
@ -276,21 +276,21 @@ retcode = os.spawnlp(os.P_WAIT, "/bin/mycmd", "mycmd", "myarg")
retcode = call(["/bin/mycmd", "myarg"]) retcode = call(["/bin/mycmd", "myarg"])
Vector example: Vector example:
os.spawnvp(os.P_NOWAIT, path, args) os.spawnvp(os.P_NOWAIT, path, args)
==> ==>
Popen([path] + args[1:]) Popen([path] + args[1:])
Environment example: Environment example:
os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env) os.spawnlpe(os.P_NOWAIT, "/bin/mycmd", "mycmd", "myarg", env)
==> ==>
Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"}) Popen(["/bin/mycmd", "myarg"], env={"PATH": "/usr/bin"})
Replacing os.popen* Replacing os.popen*
------------------- -------------------
pipe = os.popen(cmd, mode='r', bufsize) pipe = os.popen(cmd, mode='r', bufsize)
==> ==>
@ -352,7 +352,7 @@ except that:
* the capturestderr argument is replaced with the stderr argument. * the capturestderr argument is replaced with the stderr argument.
* stdin=PIPE and stdout=PIPE must be specified. * stdin=PIPE and stdout=PIPE must be specified.
* popen2 closes all filedescriptors by default, but you have to specify * popen2 closes all filedescriptors by default, but you have to specify
close_fds=True with subprocess.Popen. close_fds=True with subprocess.Popen.
""" """
@ -468,10 +468,10 @@ def list2cmdline(seq):
for c in arg: for c in arg:
if c == '\\': if c == '\\':
# Don't know if we need to double yet. # Don't know if we need to double yet.
bs_buf.append(c) bs_buf.append(c)
elif c == '"': elif c == '"':
# Double backspaces. # Double backspaces.
result.append('\\' * len(bs_buf)*2) result.append('\\' * len(bs_buf)*2)
bs_buf = [] bs_buf = []
result.append('\\"') result.append('\\"')
@ -482,7 +482,7 @@ def list2cmdline(seq):
bs_buf = [] bs_buf = []
result.append(c) result.append(c)
# Add remaining backspaces, if any. # Add remaining backspaces, if any.
if bs_buf: if bs_buf:
result.extend(bs_buf) result.extend(bs_buf)
@ -513,7 +513,7 @@ class Popen(object):
if creationflags != 0: if creationflags != 0:
raise ValueError("creationflags is only supported on Windows platforms") raise ValueError("creationflags is only supported on Windows platforms")
self.stdin = None self.stdin = None
self.stdout = None self.stdout = None
self.stderr = None self.stderr = None
self.pid = None self.pid = None
@ -534,7 +534,7 @@ class Popen(object):
# are file descriptors on both platforms. The parent objects # are file descriptors on both platforms. The parent objects
# are None when not using PIPEs. The child objects are None # are None when not using PIPEs. The child objects are None
# when not redirecting. # when not redirecting.
(p2cread, p2cwrite, (p2cread, p2cwrite,
c2pread, c2pwrite, c2pread, c2pwrite,
errread, errwrite) = self._get_handles(stdin, stdout, stderr) errread, errwrite) = self._get_handles(stdin, stdout, stderr)
@ -558,7 +558,7 @@ class Popen(object):
self.stderr = os.fdopen(errread, 'rU', bufsize) self.stderr = os.fdopen(errread, 'rU', bufsize)
else: else:
self.stderr = os.fdopen(errread, 'rb', bufsize) self.stderr = os.fdopen(errread, 'rb', bufsize)
_active.append(self) _active.append(self)
@ -578,7 +578,7 @@ class Popen(object):
""" """
if stdin == None and stdout == None and stderr == None: if stdin == None and stdout == None and stderr == None:
return (None, None, None, None, None, None) return (None, None, None, None, None, None)
p2cread, p2cwrite = None, None p2cread, p2cwrite = None, None
c2pread, c2pwrite = None, None c2pread, c2pwrite = None, None
errread, errwrite = None, None errread, errwrite = None, None
@ -651,7 +651,7 @@ class Popen(object):
"for Popen to work with your shell or platform.") "for Popen to work with your shell or platform.")
return w9xpopen return w9xpopen
def _execute_child(self, args, executable, preexec_fn, close_fds, def _execute_child(self, args, executable, preexec_fn, close_fds,
cwd, env, universal_newlines, cwd, env, universal_newlines,
startupinfo, creationflags, shell, startupinfo, creationflags, shell,
@ -685,7 +685,7 @@ class Popen(object):
if startupinfo == None: if startupinfo == None:
startupinfo = STARTUPINFO() startupinfo = STARTUPINFO()
if not None in (p2cread, c2pwrite, errwrite): if not None in (p2cread, c2pwrite, errwrite):
startupinfo.dwFlags |= STARTF_USESTDHANDLES startupinfo.dwFlags |= STARTF_USESTDHANDLES
startupinfo.hStdInput = p2cread startupinfo.hStdInput = p2cread
startupinfo.hStdOutput = c2pwrite startupinfo.hStdOutput = c2pwrite
startupinfo.hStdError = errwrite startupinfo.hStdError = errwrite
@ -724,7 +724,7 @@ class Popen(object):
if errwrite != None: if errwrite != None:
errwrite.Close() errwrite.Close()
def poll(self): def poll(self):
"""Check if child process has terminated. Returns returncode """Check if child process has terminated. Returns returncode
attribute.""" attribute."""
@ -830,7 +830,7 @@ class Popen(object):
c2pwrite = stdout c2pwrite = stdout
else: else:
# Assuming file-like object # Assuming file-like object
c2pwrite = stdout.fileno() c2pwrite = stdout.fileno()
if stderr == None: if stderr == None:
pass pass
@ -867,8 +867,8 @@ class Popen(object):
os.close(i) os.close(i)
except: except:
pass pass
def _execute_child(self, args, executable, preexec_fn, close_fds, def _execute_child(self, args, executable, preexec_fn, close_fds,
cwd, env, universal_newlines, cwd, env, universal_newlines,
startupinfo, creationflags, shell, startupinfo, creationflags, shell,
@ -976,7 +976,7 @@ class Popen(object):
_active.remove(self) _active.remove(self)
def poll(self): def poll(self):
"""Check if child process has terminated. Returns returncode """Check if child process has terminated. Returns returncode
attribute.""" attribute."""
@ -1022,7 +1022,7 @@ class Popen(object):
self.stdin.close() self.stdin.close()
if self.stdout: if self.stdout:
read_set.append(self.stdout) read_set.append(self.stdout)
stdout = [] stdout = []
if self.stderr: if self.stderr:
read_set.append(self.stderr) read_set.append(self.stderr)
stderr = [] stderr = []
@ -1137,5 +1137,3 @@ if __name__ == "__main__":
_demo_windows() _demo_windows()
else: else:
_demo_posix() _demo_posix()

View File

@ -26,7 +26,7 @@ class ProcessTestCase(unittest.TestCase):
else: else:
fname = tempfile.mktemp() fname = tempfile.mktemp()
return os.open(fname, os.O_RDWR|os.O_CREAT), fname return os.open(fname, os.O_RDWR|os.O_CREAT), fname
# #
# Generic tests # Generic tests
# #
@ -85,7 +85,7 @@ class ProcessTestCase(unittest.TestCase):
def test_stdin_filedes(self): def test_stdin_filedes(self):
"""stdin is set to open file descriptor""" """stdin is set to open file descriptor"""
tf = tempfile.TemporaryFile() tf = tempfile.TemporaryFile()
d = tf.fileno() d = tf.fileno()
os.write(d, "pear") os.write(d, "pear")
os.lseek(d, 0, 0) os.lseek(d, 0, 0)
@ -115,7 +115,7 @@ class ProcessTestCase(unittest.TestCase):
def test_stdout_filedes(self): def test_stdout_filedes(self):
"""stdout is set to open file descriptor""" """stdout is set to open file descriptor"""
tf = tempfile.TemporaryFile() tf = tempfile.TemporaryFile()
d = tf.fileno() d = tf.fileno()
p = subprocess.Popen([sys.executable, "-c", p = subprocess.Popen([sys.executable, "-c",
'import sys; sys.stdout.write("orange")'], 'import sys; sys.stdout.write("orange")'],
@ -126,7 +126,7 @@ class ProcessTestCase(unittest.TestCase):
def test_stdout_fileobj(self): def test_stdout_fileobj(self):
"""stdout is set to open file object""" """stdout is set to open file object"""
tf = tempfile.TemporaryFile() tf = tempfile.TemporaryFile()
p = subprocess.Popen([sys.executable, "-c", p = subprocess.Popen([sys.executable, "-c",
'import sys; sys.stdout.write("orange")'], 'import sys; sys.stdout.write("orange")'],
stdout=tf) stdout=tf)
@ -143,7 +143,7 @@ class ProcessTestCase(unittest.TestCase):
def test_stderr_filedes(self): def test_stderr_filedes(self):
"""stderr is set to open file descriptor""" """stderr is set to open file descriptor"""
tf = tempfile.TemporaryFile() tf = tempfile.TemporaryFile()
d = tf.fileno() d = tf.fileno()
p = subprocess.Popen([sys.executable, "-c", p = subprocess.Popen([sys.executable, "-c",
'import sys; sys.stderr.write("strawberry")'], 'import sys; sys.stderr.write("strawberry")'],
@ -154,7 +154,7 @@ class ProcessTestCase(unittest.TestCase):
def test_stderr_fileobj(self): def test_stderr_fileobj(self):
"""stderr is set to open file object""" """stderr is set to open file object"""
tf = tempfile.TemporaryFile() tf = tempfile.TemporaryFile()
p = subprocess.Popen([sys.executable, "-c", p = subprocess.Popen([sys.executable, "-c",
'import sys; sys.stderr.write("strawberry")'], 'import sys; sys.stderr.write("strawberry")'],
stderr=tf) stderr=tf)
@ -230,7 +230,7 @@ class ProcessTestCase(unittest.TestCase):
def test_communicate_pipe_buf(self): def test_communicate_pipe_buf(self):
"""communicate() with writes larger than pipe_buf""" """communicate() with writes larger than pipe_buf"""
# This test will probably deadlock rather than fail, if # This test will probably deadlock rather than fail, if
# communicate() does not work properly. # communicate() does not work properly.
x, y = os.pipe() x, y = os.pipe()
if mswindows: if mswindows:
pipe_buf = 512 pipe_buf = 512
@ -239,7 +239,7 @@ class ProcessTestCase(unittest.TestCase):
os.close(x) os.close(x)
os.close(y) os.close(y)
p = subprocess.Popen([sys.executable, "-c", p = subprocess.Popen([sys.executable, "-c",
'import sys,os;' 'import sys,os;'
'sys.stdout.write(sys.stdin.read(47));' \ 'sys.stdout.write(sys.stdin.read(47));' \
'sys.stderr.write("xyz"*%d);' \ 'sys.stderr.write("xyz"*%d);' \
'sys.stdout.write(sys.stdin.read())' % pipe_buf], 'sys.stdout.write(sys.stdin.read())' % pipe_buf],
@ -258,7 +258,7 @@ class ProcessTestCase(unittest.TestCase):
(stdout, stderr) = p.communicate("split") (stdout, stderr) = p.communicate("split")
self.assertEqual(stdout, "bananasplit") self.assertEqual(stdout, "bananasplit")
self.assertEqual(stderr, "") self.assertEqual(stderr, "")
def test_universal_newlines(self): def test_universal_newlines(self):
"""universal newlines""" """universal newlines"""
p = subprocess.Popen([sys.executable, "-c", p = subprocess.Popen([sys.executable, "-c",
@ -354,7 +354,7 @@ class ProcessTestCase(unittest.TestCase):
self.assertEqual(p.wait(), 0) self.assertEqual(p.wait(), 0)
# Subsequent invocations should just return the returncode # Subsequent invocations should just return the returncode
self.assertEqual(p.wait(), 0) self.assertEqual(p.wait(), 0)
# #
# POSIX tests # POSIX tests
# #
@ -370,7 +370,7 @@ class ProcessTestCase(unittest.TestCase):
self.assertNotEqual(e.child_traceback.find("os.chdir"), -1) self.assertNotEqual(e.child_traceback.find("os.chdir"), -1)
else: else:
self.fail("Expected OSError") self.fail("Expected OSError")
def test_run_abort(self): def test_run_abort(self):
"""returncode handles signal termination""" """returncode handles signal termination"""
p = subprocess.Popen([sys.executable, "-c", "import os; os.abort()"]) p = subprocess.Popen([sys.executable, "-c", "import os; os.abort()"])
@ -394,7 +394,7 @@ class ProcessTestCase(unittest.TestCase):
'import sys,os;' \ 'import sys,os;' \
'sys.stdout.write(str(os.dup(0)))'], 'sys.stdout.write(str(os.dup(0)))'],
stdout=subprocess.PIPE, close_fds=1) stdout=subprocess.PIPE, close_fds=1)
# When all fds are closed, the next free fd should be 3. # When all fds are closed, the next free fd should be 3.
self.assertEqual(p.stdout.read(), "3") self.assertEqual(p.stdout.read(), "3")
def test_args_string(self): def test_args_string(self):
@ -446,7 +446,7 @@ class ProcessTestCase(unittest.TestCase):
rc = subprocess.call(fname) rc = subprocess.call(fname)
self.assertEqual(rc, 47) self.assertEqual(rc, 47)
# #
# Windows tests # Windows tests
# #
@ -454,7 +454,7 @@ class ProcessTestCase(unittest.TestCase):
def test_startupinfo(self): def test_startupinfo(self):
"""startupinfo argument""" """startupinfo argument"""
# We uses hardcoded constants, because we do not want to # We uses hardcoded constants, because we do not want to
# depend on win32all. # depend on win32all.
STARTF_USESHOWWINDOW = 1 STARTF_USESHOWWINDOW = 1
SW_MAXIMIZE = 3 SW_MAXIMIZE = 3
startupinfo = subprocess.STARTUPINFO() startupinfo = subprocess.STARTUPINFO()
@ -486,7 +486,7 @@ class ProcessTestCase(unittest.TestCase):
newenv = os.environ.copy() newenv = os.environ.copy()
newenv["FRUIT"] = "physalis" newenv["FRUIT"] = "physalis"
p = subprocess.Popen(["set"], shell=1, p = subprocess.Popen(["set"], shell=1,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
env=newenv) env=newenv)
self.assertNotEqual(p.stdout.read().find("physalis"), -1) self.assertNotEqual(p.stdout.read().find("physalis"), -1)
@ -495,7 +495,7 @@ class ProcessTestCase(unittest.TestCase):
newenv = os.environ.copy() newenv = os.environ.copy()
newenv["FRUIT"] = "physalis" newenv["FRUIT"] = "physalis"
p = subprocess.Popen("set", shell=1, p = subprocess.Popen("set", shell=1,
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
env=newenv) env=newenv)
self.assertNotEqual(p.stdout.read().find("physalis"), -1) self.assertNotEqual(p.stdout.read().find("physalis"), -1)
@ -511,4 +511,3 @@ def test_main():
if __name__ == "__main__": if __name__ == "__main__":
test_main() test_main()