[Python-checkins] r79533 - in python/trunk: Lib/py_compile.py Misc/NEWS

barry.warsaw python-checkins at python.org
Wed Mar 31 23:07:16 CEST 2010


Author: barry.warsaw
Date: Wed Mar 31 23:07:16 2010
New Revision: 79533
Log:
- Issue #8233: When run as a script, py_compile.py optionally takes a single
 argument `-` which tells it to read files to compile from stdin. Each line
 is read on demand and the named file is compiled immediately. (Original
 patch by Piotr Ożarowski).
Modified:
 python/trunk/Lib/py_compile.py
 python/trunk/Misc/NEWS
Modified: python/trunk/Lib/py_compile.py
==============================================================================
--- python/trunk/Lib/py_compile.py	(original)
+++ python/trunk/Lib/py_compile.py	Wed Mar 31 23:07:16 2010
@@ -135,19 +135,35 @@
 not specified) are compiled and the resulting bytecode is cached
 in the normal manner. This function does not search a directory
 structure to locate source files; it only compiles files named
- explicitly.
+ explicitly. If '-' is the only parameter in args, the list of
+ files is taken from standard input.
 
 """
 if args is None:
 args = sys.argv[1:]
 rv = 0
- for filename in args:
- try:
- compile(filename, doraise=True)
- except PyCompileError, err:
- # return value to indicate at least one failure
- rv = 1
- sys.stderr.write(err.msg)
+ if args == ['-']:
+ while True:
+ filename = sys.stdin.readline()
+ if not filename:
+ break
+ filename = filename.rstrip('\n')
+ try:
+ compile(filename, doraise=True)
+ except PyCompileError as error:
+ rv = 1
+ sys.stderr.write("%s\n" % error.msg)
+ except IOError as error:
+ rv = 1
+ sys.stderr.write("%s\n" % error)
+ else:
+ for filename in args:
+ try:
+ compile(filename, doraise=True)
+ except PyCompileError as err:
+ # return value to indicate at least one failure
+ rv = 1
+ sys.stderr.write(error.msg)
 return rv
 
 if __name__ == "__main__":
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Wed Mar 31 23:07:16 2010
@@ -32,8 +32,13 @@
 Library
 -------
 
-- Issue #3135: Add inspect.getcallargs, which binds arguments to a function like
- a normal call.
+- Issue #8233: When run as a script, py_compile.py optionally takes a single
+ argument `-` which tells it to read files to compile from stdin. Each line
+ is read on demand and the named file is compiled immediately. (Original
+ patch by Piotr Ożarowski).
+
+- Issue #3135: Add inspect.getcallargs, which binds arguments to a function
+ like a normal call.
 
 - Backwards incompatible change: Unicode codepoints line tabulation (0x0B) and
 form feed (0x0C) are now considered linebreaks, as specified in Unicode


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /