Kaydet (Commit) 414a195a authored tarafından Jack Jansen's avatar Jack Jansen

Backport of 1.18 through 1.21:

- 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.
üst 109cd5c5
......@@ -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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment