mirror of
https://github.com/webrecorder/pywb.git
synced 2025-03-24 06:59:52 +01:00
lxml: ensure lxml support is optional: if not available,
use_lxml_parser() will return false and doctests/pytest collection won't test the lxml parser
This commit is contained in:
parent
4e53c2e9d8
commit
da0623fbbb
@ -1,4 +1,10 @@
|
|||||||
import lxml.etree
|
try:
|
||||||
|
import lxml.etree
|
||||||
|
LXML_SUPPORTED = True
|
||||||
|
except ImportError:
|
||||||
|
LXML_SUPPORTED = False
|
||||||
|
pass
|
||||||
|
|
||||||
import cgi
|
import cgi
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -13,14 +13,17 @@ HTML = HTMLRewriter
|
|||||||
|
|
||||||
#=================================================================
|
#=================================================================
|
||||||
def use_lxml_parser():
|
def use_lxml_parser():
|
||||||
try:
|
import logging
|
||||||
import logging
|
from lxml_html_rewriter import LXMLHTMLRewriter, LXML_SUPPORTED
|
||||||
from lxml_html_rewriter import LXMLHTMLRewriter
|
|
||||||
|
if LXML_SUPPORTED:
|
||||||
global HTML
|
global HTML
|
||||||
HTML = LXMLHTMLRewriter
|
HTML = LXMLHTMLRewriter
|
||||||
logging.debug('Using LXML Parser')
|
logging.debug('Using LXML Parser')
|
||||||
except ImportError:
|
return True
|
||||||
logging.debug('Error Loading LXML Parser')
|
else:
|
||||||
|
logging.debug('LXML Parser not available')
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
#=================================================================
|
#=================================================================
|
||||||
|
@ -114,10 +114,7 @@ ur"""
|
|||||||
|
|
||||||
from pywb.rewrite.url_rewriter import UrlRewriter
|
from pywb.rewrite.url_rewriter import UrlRewriter
|
||||||
|
|
||||||
try:
|
from pywb.rewrite.lxml_html_rewriter import LXMLHTMLRewriter, LXML_SUPPORTED
|
||||||
from pywb.rewrite.lxml_html_rewriter import LXMLHTMLRewriter
|
|
||||||
except ImportError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
urlrewriter = UrlRewriter('20131226101010/http://example.com/some/path/index.html', '/web/')
|
urlrewriter = UrlRewriter('20131226101010/http://example.com/some/path/index.html', '/web/')
|
||||||
|
|
||||||
@ -127,5 +124,13 @@ def parse(data, head_insert=None):
|
|||||||
print parser.rewrite(data) + parser.close()
|
print parser.rewrite(data) + parser.close()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
import doctest
|
if LXML_SUPPORTED:
|
||||||
doctest.testmod()
|
import doctest
|
||||||
|
doctest.testmod()
|
||||||
|
else:
|
||||||
|
# skip if not supported and lxml not available
|
||||||
|
if not LXML_SUPPORTED:
|
||||||
|
import pytest
|
||||||
|
lxml = pytest.importorskip('lxml.etree')
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user