diff options
| author | Guido van Rossum <guido@python.org> | 1990-10-24 16:40:15 (GMT) | 
|---|---|---|
| committer | Guido van Rossum <guido@python.org> | 1990-10-24 16:40:15 (GMT) | 
| commit | f49ef1cad0a7d7aa597dd8c9430a802084ec16a2 (patch) | |
| tree | 8c7c0889608b25f21935201e180f99fc84d7cb26 /Lib/commands.py | |
| parent | 276123d1dc79e2592d3bab37a9558b95519ff2ef (diff) | |
| download | cpython-f49ef1cad0a7d7aa597dd8c9430a802084ec16a2.zip cpython-f49ef1cad0a7d7aa597dd8c9430a802084ec16a2.tar.gz cpython-f49ef1cad0a7d7aa597dd8c9430a802084ec16a2.tar.bz2  | |
Mad readfile() read the file in one fell swoop.
Diffstat (limited to 'Lib/commands.py')
| -rw-r--r-- | Lib/commands.py | 12 | 
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/commands.py b/Lib/commands.py index c96953c..dc46740 100644 --- a/Lib/commands.py +++ b/Lib/commands.py @@ -41,7 +41,17 @@ def getstatusoutput(cmd):  # Return a string containing a file's contents.  #  def readfile(fn): -	return open(fn, 'r').read(posix.stat(fn)[stat.ST_SIZE]) +	st = posix.stat(fn) +	size = st[stat.ST_SIZE] +	if not size: return '' +	try: +		fp = open(fn, 'r') +	except: +		raise posix.error, 'readfile(' + fn + '): open failed' +	try: +		return fp.read(size) +	except: +		raise posix.error, 'readfile(' + fn + '): read failed'  # Make command argument from directory and pathname (prefix space, add quotes).  | 
