|
7 | 7 | import copy
|
8 | 8 | import datetime
|
9 | 9 | import textwrap
|
10 |
| -import lxml |
11 | 10 | import os
|
12 | 11 | import re
|
13 | 12 | import xml2rfc.log
|
@@ -1057,7 +1056,7 @@ def write_section_rec(self, section, count_str="1.", appendix=False,
|
1057 | 1056 | p_count = 1 # Paragraph counter
|
1058 | 1057 | for element in section:
|
1059 | 1058 | # Check for a PI
|
1060 |
| - if element.tag is lxml.etree.PI: |
| 1059 | + if element.tag is etree.PI: |
1061 | 1060 | pidict = self.parse_pi(element)
|
1062 | 1061 | if pidict and "needLines" in pidict:
|
1063 | 1062 | self.needLines(pidict["needLines"])
|
@@ -1297,7 +1296,7 @@ def _build_index(self):
|
1297 | 1296 | if 'anchor' in ref.attrib:
|
1298 | 1297 | self._indexRef(ref_counter, title=title.text, anchor=ref.attrib["anchor"])
|
1299 | 1298 | else:
|
1300 |
| - raise RfcWriterError("Reference is missing an anchor: %s" % lxml.etree.tostring(ref)) |
| 1299 | + raise RfcWriterError("Reference is missing an anchor: %s" % etree.tostring(ref)) |
1301 | 1300 |
|
1302 | 1301 | # Appendix sections
|
1303 | 1302 | back = self.r.find('back')
|
@@ -1646,7 +1645,7 @@ def write_to_file(self, file):
|
1646 | 1645 |
|
1647 | 1646 | v3_rnc_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'data', 'v3.rnc')
|
1648 | 1647 | v3_rng_file = os.path.join(os.path.dirname(os.path.dirname(__file__)), 'data', 'v3.rng')
|
1649 |
| -v3_schema = lxml.etree.ElementTree(file=v3_rng_file) |
| 1648 | +v3_schema = etree.ElementTree(file=v3_rng_file) |
1650 | 1649 |
|
1651 | 1650 | def get_element_tags():
|
1652 | 1651 | tags = set()
|
@@ -1733,7 +1732,7 @@ def __init__(self, xmlrfc, quiet=None, options=default_options, date=None):
|
1733 | 1732 | self.date = date if date is not None else datetime.date.today()
|
1734 | 1733 | self.v3_rnc_file = v3_rnc_file
|
1735 | 1734 | self.v3_rng_file = v3_rng_file
|
1736 |
| - self.v3_rng = lxml.etree.RelaxNG(file=self.v3_rng_file) |
| 1735 | + self.v3_rng = etree.RelaxNG(file=self.v3_rng_file) |
1737 | 1736 | self.v3_schema = v3_schema
|
1738 | 1737 | self.schema = v3_schema
|
1739 | 1738 | self.index_items = []
|
@@ -1780,21 +1779,21 @@ def get_relevant_pis(self, e):
|
1780 | 1779 | if e != None:
|
1781 | 1780 | # directly inside element
|
1782 | 1781 | for c in e.getchildren():
|
1783 |
| - if c.tag == lxml.etree.PI and c.target == xml2rfc.V3_PI_TARGET: |
| 1782 | + if c.tag == etree.PI and c.target == xml2rfc.V3_PI_TARGET: |
1784 | 1783 | pis.append(c)
|
1785 | 1784 | # siblings before element
|
1786 | 1785 | for s in e.itersiblings(preceding=True):
|
1787 |
| - if s.tag == lxml.etree.PI and s.target == xml2rfc.V3_PI_TARGET: |
| 1786 | + if s.tag == etree.PI and s.target == xml2rfc.V3_PI_TARGET: |
1788 | 1787 | pis.append(s)
|
1789 | 1788 | # ancestor's earlier siblings
|
1790 | 1789 | for a in e.iterancestors():
|
1791 | 1790 | for s in a.itersiblings(preceding=True):
|
1792 |
| - if s.tag == lxml.etree.PI and s.target == xml2rfc.V3_PI_TARGET: |
| 1791 | + if s.tag == etree.PI and s.target == xml2rfc.V3_PI_TARGET: |
1793 | 1792 | pis.append(s)
|
1794 | 1793 | # before root elements
|
1795 | 1794 | p = self.root.getprevious()
|
1796 | 1795 | while p != None:
|
1797 |
| - if p.tag == lxml.etree.PI and p.target == xml2rfc.V3_PI_TARGET: |
| 1796 | + if p.tag == etree.PI and p.target == xml2rfc.V3_PI_TARGET: |
1798 | 1797 | pis.append(p)
|
1799 | 1798 | p = p.getprevious()
|
1800 | 1799 | return pis
|
@@ -2045,9 +2044,9 @@ def pretty_print_prep(self, e, p):
|
2045 | 2044 | ind = self.options.indent
|
2046 | 2045 | ## The actual printing is done in self.write()
|
2047 | 2046 | def indent(e, i):
|
2048 |
| - if e.tag in (lxml.etree.CDATA, ): |
| 2047 | + if e.tag in (etree.CDATA, ): |
2049 | 2048 | return
|
2050 |
| - if e.tag in (lxml.etree.Comment, lxml.etree.PI, ): |
| 2049 | + if e.tag in (etree.Comment, etree.PI, ): |
2051 | 2050 | if not e.tail:
|
2052 | 2051 | if e.getnext() != None:
|
2053 | 2052 | e.tail = '\n'+' '*i
|
@@ -2128,13 +2127,6 @@ def validate(self, when='', warn=False):
|
2128 | 2127 | self.v3_rng.assertValid(tree)
|
2129 | 2128 | return True
|
2130 | 2129 | except Exception as e:
|
2131 |
| - lxmlver = lxml.etree.LXML_VERSION[:3] |
2132 |
| - if lxmlver < (3, 8, 0): |
2133 |
| - self.warn(None, "The available version of the lxml library (%s) does not provide xpath " |
2134 |
| - "information as part of validation errors. Upgrade to version 3.8.0 or " |
2135 |
| - "higher for better error messages." % ('.'.join(str(v) for v in lxmlver), )) |
2136 |
| - # These warnings are occasionally incorrect -- disable this |
2137 |
| - # output for now: |
2138 | 2130 | deadly = False
|
2139 | 2131 | if hasattr(e, 'error_log'):
|
2140 | 2132 | for error in e.error_log:
|
@@ -2166,6 +2158,19 @@ def validate_before(self, e, p):
|
2166 | 2158 | if not self.validate('before'):
|
2167 | 2159 | self.note(None, "Schema validation failed for input document")
|
2168 | 2160 |
|
| 2161 | + self.validate_draft_name() |
| 2162 | + |
| 2163 | + def validate_draft_name(self): |
| 2164 | + if not self.root.attrib.get('number', False): |
| 2165 | + docName = self.root.attrib.get('docName', None) |
| 2166 | + info = self.root.find('./front/seriesInfo[@name="Internet-Draft"]') |
| 2167 | + si_draft_name = info.get('value') if info != None else None |
| 2168 | + |
| 2169 | + if all([docName, si_draft_name]) and docName != si_draft_name: |
| 2170 | + self.die(self.root, 'docName and value in <seriesInfo name="Internet-Draft" ..> must match.') |
| 2171 | + |
| 2172 | + return True |
| 2173 | + |
2169 | 2174 | def validate_after(self, e, p):
|
2170 | 2175 | # XXX: There is an issue with exponential increase in validation time
|
2171 | 2176 | # as a function of the number of attributes on the root element, on
|
|
0 commit comments