diff options
author | scoder <none@none> | 2006-06-03 10:17:40 +0200 |
---|---|---|
committer | scoder <none@none> | 2006-06-03 10:17:40 +0200 |
commit | 12b4454f6906e32fcdb551141e67399c5e87c460 (patch) | |
tree | a03fe72a09d5b6737c72fe67295b14ee0ca6bbeb /update-error-constants.py | |
parent | 6bdd7ac86a4367f0bbea1ec06981a013c9363185 (diff) | |
download | python-lxml-12b4454f6906e32fcdb551141e67399c5e87c460.tar.gz |
[svn r1389] store error constant strings in tuples instead of using string concatenation (simplifies setup code), add comment from generator script
--HG--
branch : trunk
Diffstat (limited to 'update-error-constants.py')
-rw-r--r-- | update-error-constants.py | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/update-error-constants.py b/update-error-constants.py index 2edff1b8..7fab7e25 100644 --- a/update-error-constants.py +++ b/update-error-constants.py @@ -25,6 +25,15 @@ ENUM_MAP = { ENUM_ORDER = ('xmlErrorLevel', 'xmlErrorDomain', 'xmlParserErrors') +COMMENT = """ +# This section is generated by the script '%s'. +# +# Constants are stored in tuples of strings, for which Pyrex generates very +# efficient setup code. To parse them, iterate over the tuples and parse each +# line in each string independently. + +""" % os.path.basename(sys.argv[0]) + def split(lines): lines = iter(lines) pre = [] @@ -50,6 +59,7 @@ def regenerate_file(filename, result): # write .pxi source file f = open(filename, 'w') f.write(''.join(pre)) + f.write(COMMENT) f.write('\n'.join(result)) f.write(''.join(post)) f.close() @@ -82,7 +92,7 @@ pxd_result = [] append_pxd = pxd_result.append ctypedef_indent = ' '*4 -constant_indent = ' '*8 +constant_indent = ctypedef_indent*2 append_pxd('cdef extern from "libxml/xmlerror.h":') for enum_name in ENUM_ORDER: @@ -91,7 +101,7 @@ for enum_name in ENUM_ORDER: append_pxd(ctypedef_indent + 'ctypedef enum %s:' % enum_name) append_pxi('cdef object %s' % pxi_name) - append_pxi('%s = """\\' % pxi_name) + append_pxi('%s = ("""\\' % pxi_name) length = 0 for name, val, descr in constants: if descr: @@ -102,16 +112,21 @@ for enum_name in ENUM_ORDER: append_pxd(constant_indent + line) if length + len(line) > 2000: # max string length in MSVC - append_pxi('""" + \\') + append_pxi('""",') append_pxi('"""\\') length = 0 append_pxi(line) length += len(line) + 1 append_pxd('') - append_pxi('"""') + append_pxi('""",)') append_pxi('') # write source files +print "Updating file", BUILD_SOURCE_FILE regenerate_file(BUILD_SOURCE_FILE, pxi_result) + +print "Updating file", BUILD_DEF_FILE regenerate_file(BUILD_DEF_FILE, pxd_result) + +print "Done" |