summaryrefslogtreecommitdiff
path: root/update-error-constants.py
diff options
context:
space:
mode:
authorscoder <none@none>2008-02-15 15:15:14 +0100
committerscoder <none@none>2008-02-15 15:15:14 +0100
commite056284013cf160ebc9cdd4f02cf4b30ac91f96c (patch)
treedb3b0a87c549ddabd8e22a6b071abf967acee92d /update-error-constants.py
parent8f6692dc41086fe6f3c5ba068f4c99b7883cef31 (diff)
downloadpython-lxml-e056284013cf160ebc9cdd4f02cf4b30ac91f96c.tar.gz
[svn r3304] r3524@delle: sbehnel | 2008-02-15 13:39:53 +0100
integrate all error type enums: parser, XPath, schema, relaxng --HG-- branch : trunk
Diffstat (limited to 'update-error-constants.py')
-rw-r--r--update-error-constants.py45
1 files changed, 31 insertions, 14 deletions
diff --git a/update-error-constants.py b/update-error-constants.py
index 873c23d2..5cc6de40 100644
--- a/update-error-constants.py
+++ b/update-error-constants.py
@@ -11,20 +11,24 @@ if len(sys.argv) < 2 or sys.argv[1].lower() in ('-h', '--help'):
print sys.argv[0], "/path/to/libxml2-doc-dir"
sys.exit(len(sys.argv) > 1)
-HTML_FILE = os.path.join(sys.argv[1], 'html', 'libxml-xmlerror.html')
-os.stat(HTML_FILE) # raise an error if we can't find it
+HTML_DIR = os.path.join(sys.argv[1], 'html')
+os.stat(HTML_DIR) # 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', 'XML_ERR_'),
- 'xmlErrorDomain' : ('__ERROR_DOMAINS', 'XML_FROM_'),
- 'xmlParserErrors' : ('__ERROR_TYPES', 'XML_')
+ 'xmlErrorLevel' : ('__ERROR_LEVELS', 'XML_ERR_'),
+ 'xmlErrorDomain' : ('__ERROR_DOMAINS', 'XML_FROM_'),
+ 'xmlParserErrors' : ('__PARSER_ERROR_TYPES', 'XML_'),
+ 'xmlXPathError' : ('__XPATH_ERROR_TYPES', ''),
+ 'xmlSchemaValidError' : ('__XMLSCHEMA_ERROR_TYPES', 'XML_'),
+ 'xmlRelaxNGValidErr' : ('__RELAXNG_ERROR_TYPES', 'XML_'),
}
-ENUM_ORDER = ('xmlErrorLevel', 'xmlErrorDomain', 'xmlParserErrors')
+ENUM_ORDER = ('xmlErrorLevel', 'xmlErrorDomain', 'xmlParserErrors',
+ 'xmlXPathError', 'xmlSchemaValidError', 'xmlRelaxNGValidErr')
COMMENT = """
# This section is generated by the script '%s'.
@@ -61,27 +65,40 @@ def regenerate_file(filename, result):
f.write(''.join(post))
f.close()
-def parse_enums(html_file):
+def parse_enums(html_dir, html_filename, enum_dict):
PARSE_ENUM_NAME = re.compile('\s*enum\s+(\w+)\s*{', re.I).match
PARSE_ENUM_VALUE = re.compile('\s*=\s+([0-9]+)\s*(?::\s*(.*))?').match
- tree = etree.parse(html_file)
+ tree = etree.parse(os.path.join(html_dir, html_filename))
xpath = etree.XPathEvaluator(
tree, namespaces={'html' : 'http://www.w3.org/1999/xhtml'})
+ collect_text = etree.XPath("string()")
- enum_dict = {}
- enums = xpath.evaluate("//html:pre[@class = 'programlisting' and contains(text(), 'Enum') and html:a[@name]]")
+ enums = xpath.evaluate("//html:pre[@class = 'programlisting' and contains(text(), 'Enum')]")
for enum in enums:
- enum_name = PARSE_ENUM_NAME(enum.text).group(1)
+ enum_name = PARSE_ENUM_NAME(collect_text(enum))
+ if not enum_name or enum_name not in ENUM_MAP:
+ continue
+ enum_name = enum_name.group(1)
print "Found enum", enum_name
entries = []
- enum_dict[enum_name] = entries
for child in enum:
name = child.text
- value, descr = PARSE_ENUM_VALUE(child.tail).groups()
+ match = PARSE_ENUM_VALUE(child.tail)
+ if not match:
+ print("Ignoring enum %s (failed to parse field '%s')" % (
+ enum_name, name))
+ break
+ value, descr = match.groups()
entries.append((name, int(value), descr))
+ else:
+ enum_dict[enum_name] = entries
return enum_dict
-enum_dict = parse_enums(HTML_FILE)
+enum_dict = {}
+parse_enums(HTML_DIR, 'libxml-xmlerror.html', enum_dict)
+parse_enums(HTML_DIR, 'libxml-xpath.html', enum_dict)
+parse_enums(HTML_DIR, 'libxml-xmlschemas.html', enum_dict)
+parse_enums(HTML_DIR, 'libxml-relaxng.html', enum_dict)
# regenerate source files
pxi_result = []