~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/hardwaredb/scripts/hwdbsubmissions.py

[r=abentley][no-qa] allow bad data in <comment> nodes in HWDB
        submissions.

Show diffs side-by-side

added added

removed removed

Lines of Context:
71
71
    """,
72
72
    re.VERBOSE)
73
73
 
 
74
_broken_comment_nodes_re = re.compile('(<comment>.*?</comment>)', re.DOTALL)
 
75
 
74
76
ROOT_UDI = '/org/freedesktop/Hal/devices/computer'
75
77
UDEV_ROOT_PATH = '/devices/LNXSYSTM:00'
76
78
 
158
160
            self.logger.warning(
159
161
                'Parsing submission %s: %s' % (self.submission_key, message))
160
162
 
 
163
    def fixFrequentErrors(self, submission):
 
164
        """Fixes for frequent formal errors in the submissions.
 
165
        """
 
166
        # A considerable number of reports for Lucid has ESC characters
 
167
        # in comment nodes. We don't need the comment nodes at all, so
 
168
        # we can simply empty them.
 
169
        return _broken_comment_nodes_re.sub('<comment/>', submission)
 
170
 
161
171
    def _getValidatedEtree(self, submission, submission_key):
162
172
        """Create an etree doc from the XML string submission and validate it.
163
173
 
164
174
        :return: an `lxml.etree` instance representation of a valid
165
175
            submission or None for invalid submissions.
166
176
        """
 
177
        submission = self.fixFrequentErrors(submission)
167
178
        try:
168
179
            tree = etree.parse(StringIO(submission), parser=self.doc_parser)
169
180
        except SyntaxError, error_value: