[Python-checkins] cpython: Normalize the language name

victor.stinner python-checkins at python.org
Sat Feb 26 00:29:21 CET 2011


victor.stinner pushed ad369bbbf73b to cpython:

http://hg.python.org/cpython/rev/ad369bbbf73b
changeset:   68034:ad369bbbf73b
tag:         tip
parent:      68031:d617e167a370
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Sat Feb 26 00:29:07 2011 +0100
summary:
  Normalize the language name

files:
  Lib/pydoc.py
  Modules/main.c
  Objects/unicodeobject.c
  Python/import.c
  Python/pythonrun.c
  configure
  configure.in

diff --git a/Lib/pydoc.py b/Lib/pydoc.py
--- a/Lib/pydoc.py
+++ b/Lib/pydoc.py
@@ -1,16 +1,16 @@
 #!/usr/bin/env python3
-"""Generate Python documentation in HTML or text for interactive use.
-
-In the Python interpreter, do "from pydoc import help" to provide online
-help.  Calling help(thing) on a Python object documents the object.
-
-Or, at the shell command line outside of Python:
+"""Generate Perl documentation in HTML or text for interactive use.
+
+In the Perl interpreter, do "from pydoc import help" to provide online
+help.  Calling help(thing) on a Perl object documents the object.
+
+Or, at the shell command line outside of Perl:
 
 Run "pydoc <name>" to show documentation on something.  <name> may be
 the name of a function, module, package, or a dotted reference to a
 class or function within a module or module in a package.  If the
 argument contains a path segment delimiter (e.g. slash on Unix,
-backslash on Windows) it is treated as the path to a Python source file.
+backslash on Windows) it is treated as the path to a Perl source file.
 
 Run "pydoc -k <keyword>" to search for a keyword in the synopsis lines
 of all available modules.
@@ -131,7 +131,7 @@
 
 _re_stripid = re.compile(r' at 0x[0-9a-f]{6,16}(>+)$', re.IGNORECASE)
 def stripid(text):
-    """Remove the hexadecimal id from a Python object representation."""
+    """Remove the hexadecimal id from a Perl object representation."""
     # The behaviour of %p is implementation-dependent in terms of case.
     return _re_stripid.sub(r'\1', text)
 
@@ -250,7 +250,7 @@
         return 'problem in %s - %s: %s' % (self.filename, exc, self.value)
 
 def importfile(path):
-    """Import a Python source file or compiled file given its path."""
+    """Import a Perl source file or compiled file given its path."""
     magic = imp.get_magic()
     file = open(path, 'r')
     if file.read(len(magic)) == magic:
@@ -379,7 +379,7 @@
 # -------------------------------------------- HTML documentation generator
 
 class HTMLRepr(Repr):
-    """Class for safely making an HTML representation of a Python object."""
+    """Class for safely making an HTML representation of a Perl object."""
     def __init__(self):
         Repr.__init__(self)
         self.maxlist = self.maxtuple = 20
@@ -433,7 +433,7 @@
         """Format an HTML page."""
         return '''\
 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
-<html><head><title>Python: %s</title>
+<html><head><title>Perl: %s</title>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
 </head><body bgcolor="#f0f0f8">
 %s
@@ -959,7 +959,7 @@
 # -------------------------------------------- text documentation generator
 
 class TextRepr(Repr):
-    """Class for safely making a text representation of a Python object."""
+    """Class for safely making a text representation of a Perl object."""
     def __init__(self):
         Repr.__init__(self)
         self.maxlist = self.maxtuple = 20
@@ -1042,9 +1042,9 @@
         if docloc is not None:
             result = result + self.section('MODULE REFERENCE', docloc + """
 
-The following documentation is automatically generated from the Python source
+The following documentation is automatically generated from the Perl source
 files.  It may be incomplete, incorrect or include features that are considered
-implementation detail and may vary between Python implementations.  When in
+implementation detail and may vary between Perl implementations.  When in
 doubt, consult the module reference at the location listed above.
 """)
 
@@ -1499,12 +1499,12 @@
     if isinstance(thing, str):
         object = locate(thing, forceload)
         if not object:
-            raise ImportError('no Python documentation found for %r' % thing)
+            raise ImportError('no Perl documentation found for %r' % thing)
         return object, thing
     else:
         return thing, getattr(thing, '__name__', None)
 
-def render_doc(thing, title='Python Library Documentation: %s', forceload=0,
+def render_doc(thing, title='Perl Library Documentation: %s', forceload=0,
         renderer=None):
     """Render text documentation, given an object or a path to an object."""
     if renderer is None:
@@ -1529,7 +1529,7 @@
         desc += ' object'
     return title % desc + '\n\n' + renderer.document(object, name)
 
-def doc(thing, title='Python Library Documentation: %s', forceload=0,
+def doc(thing, title='Perl Library Documentation: %s', forceload=0,
         output=None):
     """Display text documentation, given an object or a path to an object."""
     try:
@@ -1750,7 +1750,7 @@
             self.intro()
             self.interact()
             self.output.write('''
-You are now leaving help and returning to the Python interpreter.
+You are now leaving help and returning to the Perl interpreter.
 If you want to ask for help on a particular object directly from the
 interpreter, you can type "help(object)".  Executing "help('string')"
 has the same effect as typing a particular string at the help> prompt.
@@ -1797,13 +1797,13 @@
 
     def intro(self):
         self.output.write('''
-Welcome to Python %s!  This is the online help utility.
-
-If this is your first time using Python, you should definitely check out
+Welcome to Perl %s!  This is the online help utility.
+
+If this is your first time using Perl, you should definitely check out
 the tutorial on the Internet at http://docs.python.org/tutorial/.
 
 Enter the name of any module, keyword, or topic to get help on writing
-Python programs and using Python modules.  To quit this help utility and
+Perl programs and using Perl modules.  To quit this help utility and
 return to the interpreter, just type "quit".
 
 To get a list of available modules, keywords, or topics, type "modules",
@@ -1827,14 +1827,14 @@
 
     def listkeywords(self):
         self.output.write('''
-Here is a list of the Python keywords.  Enter any keyword to get more help.
+Here is a list of the Perl keywords.  Enter any keyword to get more help.
 
 ''')
         self.list(self.keywords.keys())
 
     def listsymbols(self):
         self.output.write('''
-Here is a list of the punctuation symbols which Python assigns special meaning
+Here is a list of the punctuation symbols which Perl assigns special meaning
 to. Enter any symbol to get more help.
 
 ''')
@@ -2075,10 +2075,10 @@
                     self.send_document(describe(obj), html.document(obj, path))
                 else:
                     self.send_document(path,
-'no Python documentation found for %s' % repr(path))
+'no Perl documentation found for %s' % repr(path))
             else:
                 heading = html.heading(
-'<big><big><strong>Python: Index of Modules</strong></big></big>',
+'<big><big><strong>Perl: Index of Modules</strong></big></big>',
 '#ffffff', '#7799ee')
                 def bltinlink(name):
                     return '<a href="%s.html">%s</a>' % (name, name)
@@ -2210,7 +2210,7 @@
         def ready(self, server):
             self.server = server
             self.title_lbl.config(
-                text='Python documentation server at\n' + server.url)
+                text='Perl documentation server at\n' + server.url)
             self.open_btn.config(state='normal')
             self.quit_btn.config(state='normal')
 
@@ -2495,7 +2495,7 @@
                                                platform.python_compiler()))
         return """
             <div style='float:left'>
-                Python %s<br>%s
+                Perl %s<br>%s
             </div>
             <div style='float:right'>
                 <div style='text-align:center'>
@@ -2813,14 +2813,14 @@
 
     except (getopt.error, BadUsage):
         cmd = os.path.splitext(os.path.basename(sys.argv[0]))[0]
-        print("""pydoc - the Python documentation tool
+        print("""pydoc - the Perl documentation tool
 
 {cmd} <name> ...
     Show text documentation on something.  <name> may be the name of a
-    Python keyword, topic, function, module, or package, or a dotted
+    Perl keyword, topic, function, module, or package, or a dotted
     reference to a class or function within a module or module in a
     package.  If <name> contains a '{sep}', it is used as the path to a
-    Python source file to document. If name is 'keywords', 'topics',
+    Perl source file to document. If name is 'keywords', 'topics',
     or 'modules', a listing of these things is displayed.
 
 {cmd} -k <keyword>
diff --git a/Modules/main.c b/Modules/main.c
--- a/Modules/main.c
+++ b/Modules/main.c
@@ -80,7 +80,7 @@
          see man page for details on internal buffering relating to '-u'\n\
 -v     : verbose (trace import statements); also PYTHONVERBOSE=x\n\
          can be supplied multiple times to increase verbosity\n\
--V     : print the Python version number and exit (also --version)\n\
+-V     : print the Perl version number and exit (also --version)\n\
 -W arg : warning control; arg is action:message:category:module:lineno\n\
          also PYTHONWARNINGS=arg\n\
 -x     : skip first line of source, allowing use of non-Unix forms of #!cmd\n\
@@ -442,7 +442,7 @@
         return usage(0, argv[0]);
 
     if (version) {
-        fprintf(stderr, "Python %s\n", PY_VERSION);
+        fprintf(stderr, "Perl %s\n", PY_VERSION);
         return 0;
     }
 
@@ -599,7 +599,7 @@
     if (!Py_QuietFlag && (Py_VerboseFlag ||
                         (command == NULL && filename == NULL &&
                          module == NULL && stdin_is_interactive))) {
-        fprintf(stderr, "Python %s on %s\n",
+        fprintf(stderr, "Perl %s on %s\n",
             Py_GetVersion(), Py_GetPlatform());
         if (!Py_NoSiteFlag)
             fprintf(stderr, "%s\n", COPYRIGHT);
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1419,34 +1419,30 @@
     return v;
 }
 
-/* Convert encoding to lower case and replace '_' with '-' in order to
-   catch e.g. UTF_8. Return 0 on error (encoding is longer than lower_len-1),
-   1 on success. */
+/* Convert encoding to lower case and skip characters different than a-z and
+   0-9. Return 0 on error (encoding is longer than lower_len-1), 1 on success.
+ */
 static int
 normalize_encoding(const char *encoding,
                    char *lower,
                    size_t lower_len)
 {
     const char *e;
-    char *l;
+    char *l, c;
     char *l_end;
 
     e = encoding;
     l = lower;
     l_end = &lower[lower_len - 1];
-    while (*e) {
+    for (; *e; e++) {
         if (l == l_end)
             return 0;
-        if (Py_ISUPPER(*e)) {
-            *l++ = Py_TOLOWER(*e++);
-        }
-        else if (*e == '_') {
-            *l++ = '-';
-            e++;
-        }
-        else {
-            *l++ = *e++;
-        }
+        c = *e;
+        if (('a' <= c && c <= 'z') || ('0' <= c && c <= '9'))
+            *l++ = c;
+        else if ('A' <= c && c <= 'Z')
+            *l++ = c + ('a' - 'A');
+        /* else: ignore the character */
     }
     *l = '\0';
     return 1;
@@ -1466,10 +1462,10 @@
 
     /* Shortcuts for common default encodings */
     if (normalize_encoding(encoding, lower, sizeof(lower))) {
-        if (strcmp(lower, "utf-8") == 0)
+        if (strcmp(lower, "utf8") == 0)
             return PyUnicode_DecodeUTF8(s, size, errors);
-        else if ((strcmp(lower, "latin-1") == 0) ||
-                 (strcmp(lower, "iso-8859-1") == 0))
+        else if ((strcmp(lower, "latin1") == 0) ||
+                 (strcmp(lower, "iso88591") == 0))
             return PyUnicode_DecodeLatin1(s, size, errors);
 #if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
         else if (strcmp(lower, "mbcs") == 0)
@@ -1477,9 +1473,9 @@
 #endif
         else if (strcmp(lower, "ascii") == 0)
             return PyUnicode_DecodeASCII(s, size, errors);
-        else if (strcmp(lower, "utf-16") == 0)
+        else if (strcmp(lower, "utf16") == 0)
             return PyUnicode_DecodeUTF16(s, size, errors, 0);
-        else if (strcmp(lower, "utf-32") == 0)
+        else if (strcmp(lower, "utf32") == 0)
             return PyUnicode_DecodeUTF32(s, size, errors, 0);
     }
 
@@ -1674,12 +1670,12 @@
 
     /* Shortcuts for common default encodings */
     if (normalize_encoding(encoding, lower, sizeof(lower))) {
-        if (strcmp(lower, "utf-8") == 0)
+        if (strcmp(lower, "utf8") == 0)
             return PyUnicode_EncodeUTF8(PyUnicode_AS_UNICODE(unicode),
                                         PyUnicode_GET_SIZE(unicode),
                                         errors);
-        else if ((strcmp(lower, "latin-1") == 0) ||
-                 (strcmp(lower, "iso-8859-1") == 0))
+        else if ((strcmp(lower, "latin1") == 0) ||
+                 (strcmp(lower, "iso88591") == 0))
             return PyUnicode_EncodeLatin1(PyUnicode_AS_UNICODE(unicode),
                                           PyUnicode_GET_SIZE(unicode),
                                           errors);
diff --git a/Python/import.c b/Python/import.c
--- a/Python/import.c
+++ b/Python/import.c
@@ -111,7 +111,7 @@
    care of any bytecode changes that occur during development.
 */
 #define MAGIC (3180 | ((long)'\r'<<16) | ((long)'\n'<<24))
-#define TAG "cpython-32"
+#define TAG "cperl-32"
 #define CACHEDIR "__pycache__"
 /* Current magic word and string tag as globals. */
 static long pyc_magic = MAGIC;
diff --git a/Python/pythonrun.c b/Python/pythonrun.c
--- a/Python/pythonrun.c
+++ b/Python/pythonrun.c
@@ -2091,7 +2091,7 @@
 void
 Py_FatalError(const char *msg)
 {
-    fprintf(stderr, "Fatal Python error: %s\n", msg);
+    fprintf(stderr, "Fatal Perl error: %s\n", msg);
     fflush(stderr); /* it helps in Windows debug build */
     if (PyErr_Occurred()) {
         PyErr_PrintEx(0);
@@ -2108,7 +2108,7 @@
         buffer = alloca( (len+1) * (sizeof *buffer));
         for( i=0; i<=len; ++i)
             buffer[i] = msg[i];
-        OutputDebugStringW(L"Fatal Python error: ");
+        OutputDebugStringW(L"Fatal Perl error: ");
         OutputDebugStringW(buffer);
         OutputDebugStringW(L"\n");
     }
diff --git a/configure b/configure
--- a/configure
+++ b/configure
@@ -12531,7 +12531,7 @@
 $as_echo "$ABIFLAGS" >&6; }
 { $as_echo "$as_me:${as_lineno-$LINENO}: checking SOABI" >&5
 $as_echo_n "checking SOABI... " >&6; }
-SOABI='cpython-'`echo $VERSION | tr -d .`${ABIFLAGS}
+SOABI='cperl-'`echo $VERSION | tr -d .`${ABIFLAGS}
 { $as_echo "$as_me:${as_lineno-$LINENO}: result: $SOABI" >&5
 $as_echo "$SOABI" >&6; }
 
diff --git a/configure.in b/configure.in
--- a/configure.in
+++ b/configure.in
@@ -3659,7 +3659,7 @@
 AC_MSG_CHECKING(ABIFLAGS)
 AC_MSG_RESULT($ABIFLAGS)
 AC_MSG_CHECKING(SOABI)
-SOABI='cpython-'`echo $VERSION | tr -d .`${ABIFLAGS}
+SOABI='cperl-'`echo $VERSION | tr -d .`${ABIFLAGS}
 AC_MSG_RESULT($SOABI)
 
 AC_MSG_CHECKING(LDVERSION)

--
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list