[Patches] Adding -U command line option

M.-A. Lemburg mal@lemburg.com
Fri, 28 Apr 2000 21:49:24 +0200


This is a multi-part message in MIME format.
--------------9D1A897A1EADDA003E5CBA4B
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

The attached patch adds a new experimental option -U to the
Python interpreter. With the option enabled the Python compiler
interprets all "..." strings as u"..." (same with r"..." and
ur"...").

This provides a way to "look into the future" when someday
all strings turn into Unicode and also simplifies testing the
Unicode/string integration.

Patch Set Contents:
-------------------

Include/pydebug.h:

Added Py_UnicodeFlag for use by the -U command line option.

Modules/main.c:

Added -U command line option.

With the option enabled the Python compiler interprets all "..."
strings as u"..." (same with r"..." and ur"...").

Python/compile.c:

Support for the new -U command line option option:
with the option enabled the Python compiler
interprets all "..." strings as u"..." (same with r"..." and
ur"...").

Python/pythonrun.c:

Added Py_UnicodeFlag for use by the -U command line option.

_____________________________________________________________________
Disclaimer:

I confirm that, to the best of my knowledge and belief, this
contribution is free of any claims of third parties under copyright,
patent or other rights or interests ("claims").  To the extent that I
have any such claims, I hereby grant to CNRI a nonexclusive,
irrevocable, royalty-free, worldwide license to reproduce, distribute,
perform and/or display publicly, prepare derivative versions, and
otherwise use this contribution as part of the Python software and its
related documentation, or any derivative versions thereof, at no cost
to CNRI or its licensed users, and to authorize others to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or
not to incorporate this contribution in the Python software and its
related documentation.  I further grant CNRI permission to use my name
and other identifying information provided to CNRI by me for use in
connection with the Python software and its related documentation.

-- 
Marc-Andre Lemburg
______________________________________________________________________
Business:                                      http://www.lemburg.com/
Python Pages:                           http://www.lemburg.com/python/
--------------9D1A897A1EADDA003E5CBA4B
Content-Type: text/plain; charset=us-ascii;
 name="Unicode-Implementation-2000-04-28.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Unicode-Implementation-2000-04-28.patch"

diff -u -rbP -x *.o -x *.pyc -x Makefile -x *~ -x *.so -x add2lib -x pgen -x buildno -x config.* -x libpython* -x python -x Setup -x Setup.local -x Setup.thread -x hassignal -x Makefile.pre -x configure -x *.bak -x *.s -x DEADJOE -x *.rej -x *.orig -x Demo -x CVS -x Doc -x *.orig -x .#* -x distutils -x PC -x PCbuild -x *.py -x ACKS -x *.txt -x README CVS-Python/Include/pydebug.h Python+Unicode/Include/pydebug.h
--- CVS-Python/Include/pydebug.h	Fri Dec  4 19:48:15 1998
+++ Python+Unicode/Include/pydebug.h	Fri Apr 28 20:42:35 2000
@@ -43,6 +43,7 @@
 extern DL_IMPORT(int) Py_UseClassExceptionsFlag;
 extern DL_IMPORT(int) Py_FrozenFlag;
 extern DL_IMPORT(int) Py_TabcheckFlag;
+extern DL_IMPORT(int) Py_UnicodeFlag;
 
 DL_IMPORT(void) Py_FatalError	Py_PROTO((char *));
 
diff -u -rbP -x *.o -x *.pyc -x Makefile -x *~ -x *.so -x add2lib -x pgen -x buildno -x config.* -x libpython* -x python -x Setup -x Setup.local -x Setup.thread -x hassignal -x Makefile.pre -x configure -x *.bak -x *.s -x DEADJOE -x *.rej -x *.orig -x Demo -x CVS -x Doc -x *.orig -x .#* -x distutils -x PC -x PCbuild -x *.py -x ACKS -x *.txt -x README CVS-Python/Modules/main.c Python+Unicode/Modules/main.c
--- CVS-Python/Modules/main.c	Mon Apr 19 19:54:19 1999
+++ Python+Unicode/Modules/main.c	Fri Apr 28 20:47:36 2000
@@ -75,6 +75,7 @@
 ";
 static char *usage_mid = "\
 -u     : unbuffered binary stdout and stderr (also PYTHONUNBUFFERED=x)\n\
+-U     : experimental: turns '...' into u'...'\n\
 -v     : verbose (trace import statements) (also PYTHONVERBOSE=x)\n\
 -x     : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
 -X     : disable class based built-in exceptions\n\
@@ -119,7 +120,7 @@
 	if ((p = getenv("PYTHONUNBUFFERED")) && *p != '\0')
 		unbuffered = 1;
 
-	while ((c = getopt(argc, argv, "c:diOStuvxX")) != EOF) {
+	while ((c = getopt(argc, argv, "c:diOStuUvxX")) != EOF) {
 		if (c == 'c') {
 			/* -c is the last option; following arguments
 			   that look like options are left for the
@@ -170,6 +171,10 @@
 
 		case 'X':
 			Py_UseClassExceptionsFlag = 0;
+			break;
+
+		case 'U':
+			Py_UnicodeFlag++;
 			break;
 
 		/* This space reserved for other options */
diff -u -rbP -x *.o -x *.pyc -x Makefile -x *~ -x *.so -x add2lib -x pgen -x buildno -x config.* -x libpython* -x python -x Setup -x Setup.local -x Setup.thread -x hassignal -x Makefile.pre -x configure -x *.bak -x *.s -x DEADJOE -x *.rej -x *.orig -x Demo -x CVS -x Doc -x *.orig -x .#* -x distutils -x PC -x PCbuild -x *.py -x ACKS -x *.txt -x README CVS-Python/Python/compile.c Python+Unicode/Python/compile.c
--- CVS-Python/Python/compile.c	Thu Apr 13 18:10:59 2000
+++ Python+Unicode/Python/compile.c	Fri Apr 28 20:41:23 2000
@@ -907,7 +907,7 @@
 			return NULL;
 		}
 	}
-	if (unicode) {
+	if (unicode || Py_UnicodeFlag) {
 		if (rawmode)
 			return PyUnicode_DecodeRawUnicodeEscape(
 				s, len, NULL);
diff -u -rbP -x *.o -x *.pyc -x Makefile -x *~ -x *.so -x add2lib -x pgen -x buildno -x config.* -x libpython* -x python -x Setup -x Setup.local -x Setup.thread -x hassignal -x Makefile.pre -x configure -x *.bak -x *.s -x DEADJOE -x *.rej -x *.orig -x Demo -x CVS -x Doc -x *.orig -x .#* -x distutils -x PC -x PCbuild -x *.py -x ACKS -x *.txt -x README CVS-Python/Python/pythonrun.c Python+Unicode/Python/pythonrun.c
--- CVS-Python/Python/pythonrun.c	Tue Apr 25 12:34:21 2000
+++ Python+Unicode/Python/pythonrun.c	Fri Apr 28 20:34:42 2000
@@ -88,6 +88,7 @@
 int Py_NoSiteFlag; /* Suppress 'import site' */
 int Py_UseClassExceptionsFlag = 1; /* Needed by bltinmodule.c */
 int Py_FrozenFlag; /* Needed by getpath.c */
+int Py_UnicodeFlag = 0; /* Needed by compile.c */
 
 static int initialized = 0;
 

--------------9D1A897A1EADDA003E5CBA4B--