]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport of 1.18 through 1.21:
authorJack Jansen <jack.jansen@cwi.nl>
Sun, 24 Feb 2002 23:23:52 +0000 (23:23 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Sun, 24 Feb 2002 23:23:52 +0000 (23:23 +0000)
- Get rid of keyword list and use keyword.iskeyword() function (which I wasn't aware of previously).
- Identify() enum values. This was changed in 1.14, but I don't think it is a good idea.

Mac/scripts/gensuitemodule.py

index a1ae7744387281bfe0c762533afb3118316f64dd..5a4c806ab18ca89d027c8435deb140f50140af7f 100644 (file)
@@ -13,6 +13,7 @@ import sys
 import types
 import StringIO
 import macfs
+import keyword
 
 from Carbon.Res import *
 
@@ -360,6 +361,10 @@ def compilesuite((suite, fss, modname), major, minor, language, script, fname, b
                # Standard_Suite or so). Import everything from our base module
                fp.write('from %s import *\n'%basepackage._code_to_fullname[code][0])
                basemodule = basepackage._code_to_module[code]
+       elif basepackage and basepackage._code_to_module.has_key(code.lower()):
+               # This is needed by CodeWarrior and some others.
+               fp.write('from %s import *\n'%basepackage._code_to_fullname[code.lower()][0])
+               basemodule = basepackage._code_to_module[code.lower()]
        else:
                # We are not an extension.
                basemodule = None
@@ -744,7 +749,7 @@ class ObjectCompiler:
        
        def compileenumerator(self, item):
                [name, code, desc] = item
-               self.fp.write("\t%s : %s,\t# %s\n" % (`name`, `code`, desc))
+               self.fp.write("\t%s : %s,\t# %s\n" % (`identify(name)`, `code`, desc))
                
        def checkforenum(self, enum):
                """This enum code is used by an event. Make sure it's available"""
@@ -812,10 +817,6 @@ def compiledataflags(flags):
                                bits.append(`i`)
        return '[%s]' % string.join(bits)
        
-# XXXX Do we have a set of python keywords somewhere?
-illegal_ids = [ "for", "in", "from", "and", "or", "not", "print", "class", "return",
-       "def" ]
-
 def identify(str):
        """Turn any string into an identifier:
        - replace space by _
@@ -835,7 +836,7 @@ def identify(str):
                else:
                        rv = rv + '_%02.2x_'%ord(c)
                ok = ok2
-       if rv in illegal_ids:
+       if keyword.iskeyword(rv):
                rv = '_' + rv
        return rv
 
@@ -844,3 +845,4 @@ def identify(str):
 if __name__ == '__main__':
        main()
        sys.exit(1)
+print identify('for')
\ No newline at end of file