summaryrefslogtreecommitdiff
path: root/update-error-constants.py
diff options
context:
space:
mode:
authorscoder <none@none>2006-06-03 11:17:09 +0200
committerscoder <none@none>2006-06-03 11:17:09 +0200
commit0790a8f3e4360235b195959d06cddcc69a455687 (patch)
treed834d72f1433e450ecfc838ce7e52a62da0e7d7c /update-error-constants.py
parent12b4454f6906e32fcdb551141e67399c5e87c460 (diff)
downloadpython-lxml-0790a8f3e4360235b195959d06cddcc69a455687.tar.gz
[svn r1390] update-error-constants.py: strip prefixes and indentation before storing constant strings to safe setup overhead and space in the binary
--HG-- branch : trunk
Diffstat (limited to 'update-error-constants.py')
-rw-r--r--update-error-constants.py39
1 files changed, 23 insertions, 16 deletions
diff --git a/update-error-constants.py b/update-error-constants.py
index 7fab7e25..a38bd439 100644
--- a/update-error-constants.py
+++ b/update-error-constants.py
@@ -17,20 +17,17 @@ os.stat(HTML_FILE) # raise an error if we can't find it
sys.path.insert(0, 'src')
from lxml import etree
+# map enum name to Python variable name and alignment for constant name
ENUM_MAP = {
- 'xmlErrorLevel' : '__ERROR_LEVELS',
- 'xmlErrorDomain' : '__ERROR_DOMAINS',
- 'xmlParserErrors' : '__ERROR_TYPES'
+ 'xmlErrorLevel' : ('__ERROR_LEVELS', 'XML_ERR_'),
+ 'xmlErrorDomain' : ('__ERROR_DOMAINS', 'XML_FROM_'),
+ 'xmlParserErrors' : ('__ERROR_TYPES', 'XML_')
}
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])
@@ -91,32 +88,42 @@ append_pxi = pxi_result.append
pxd_result = []
append_pxd = pxd_result.append
+append_pxd('cdef extern from "libxml/xmlerror.h":')
+append_pxi('''\
+# 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.
+''')
+
ctypedef_indent = ' '*4
constant_indent = ctypedef_indent*2
-append_pxd('cdef extern from "libxml/xmlerror.h":')
for enum_name in ENUM_ORDER:
constants = enum_dict[enum_name]
- pxi_name = ENUM_MAP[enum_name]
+ pxi_name, prefix = ENUM_MAP[enum_name]
append_pxd(ctypedef_indent + 'ctypedef enum %s:' % enum_name)
append_pxi('cdef object %s' % pxi_name)
append_pxi('%s = ("""\\' % pxi_name)
- length = 0
+
+ prefix_len = len(prefix)
+ length = 2 # each string ends with '\n\0'
for name, val, descr in constants:
if descr:
- line = "%-50s = %7d # %s" % (name, val, descr)
+ line = '%-50s = %7d # %s' % (name, val, descr)
else:
- line = "%-50s = %7d" % (name, val)
-
+ line = '%-50s = %7d' % (name, val)
append_pxd(constant_indent + line)
- if length + len(line) > 2000: # max string length in MSVC
+ if name[:prefix_len] == prefix and len(name) > prefix_len:
+ name = name[prefix_len:]
+ line = '%s=%d' % (name, val)
+ if length + len(line) >= 2040: # max string length in MSVC is 2048
append_pxi('""",')
append_pxi('"""\\')
- length = 0
+ length = 2 # each string ends with '\n\0'
append_pxi(line)
- length += len(line) + 1
+ length += len(line) + 2 # + '\n\0'
append_pxd('')
append_pxi('""",)')