def build_html_tree(self):
        from grab.base import GLOBAL_STATE

        if self._lxml_tree is None:
            fix_setting = self.grab.config['fix_special_entities']
            body = self.unicode_body(fix_special_entities=fix_setting).strip()
            if self.grab.config['lowercased_tree']:
                body = body.lower()
            if self.grab.config['strip_null_bytes']:
                body = body.replace(NULL_BYTE, '')
            # py3 hack
            if six.PY3:
                body = RE_UNICODE_XML_DECLARATION.sub('', body)
            else:
                body = RE_XML_DECLARATION.sub('', body)
            if not body:
                # Generate minimal empty content
                # which will not break lxml parser
                body = '<html></html>'
            start = time.time()

            try:
                self._lxml_tree = self._build_dom(body, 'html')
            except Exception as ex:
                if (isinstance(ex, ParserError)
                        and 'Document is empty' in str(ex)
                        and '<html' not in body):
                    # Fix for "just a string" body
                    body = '<html>%s</html>'.format(body)
                    self._lxml_tree = self._build_dom(body, 'html')

                elif (isinstance(ex, TypeError)
                      or "object of type 'NoneType' has no len" in str(ex)
                      and '<html' not in body):

                    # Fix for smth like "<frameset></frameset>"
                    body = '<html>%s</html>'.format(body)
                    self._lxml_tree = self._build_dom(body, 'html')
                else:
                    raise

            GLOBAL_STATE['dom_build_time'] += (time.time() - start)
        return self._lxml_tree
dataset/ETHPy150Open lorien/grab/grab/document.py/DomTreeExtension.build_html_tree/operator `and` -> `or`