diff options
author | Guido van Rossum <guido@python.org> | 2007-10-30 17:27:30 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-10-30 17:27:30 (GMT) |
commit | 2dced8b602df10531cab6cd87da5503c06f14888 (patch) | |
tree | bf87d57eb4945b66b672aadfb87c071449391441 /Lib/quopri.py | |
parent | 2673a5723433ff398fed901a8ebebb265031091e (diff) | |
download | cpython-2dced8b602df10531cab6cd87da5503c06f14888.zip cpython-2dced8b602df10531cab6cd87da5503c06f14888.tar.gz cpython-2dced8b602df10531cab6cd87da5503c06f14888.tar.bz2 |
Patch 1329 (partial) by Christian Heimes.
Add a closefd flag to open() which can be set to False to prevent closing
the file descriptor when close() is called or when the object is destroyed.
Useful to ensure that sys.std{in,out,err} keep their file descriptors open
when Python is uninitialized. (This was always a feature in 2.x, it just
wasn't implemented in 3.0 yet.)
Diffstat (limited to 'Lib/quopri.py')
-rwxr-xr-x | Lib/quopri.py | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/Lib/quopri.py b/Lib/quopri.py index 62c0503..6b3d13e 100755 --- a/Lib/quopri.py +++ b/Lib/quopri.py @@ -227,12 +227,14 @@ def main(): sys.stderr.write("%s: can't open (%s)\n" % (file, msg)) sts = 1 continue - if deco: - decode(fp, sys.stdout.buffer) - else: - encode(fp, sys.stdout.buffer, tabs) - if fp is not sys.stdin: - fp.close() + try: + if deco: + decode(fp, sys.stdout.buffer) + else: + encode(fp, sys.stdout.buffer, tabs) + finally: + if file != '-': + fp.close() if sts: sys.exit(sts) |