Move loading DTD into a function as the call caused a hang when loaded into wsgi
authorDiane Trout <diane@caltech.edu>
Tue, 17 Dec 2013 19:11:04 +0000 (11:11 -0800)
committerDiane Trout <diane@caltech.edu>
Tue, 17 Dec 2013 19:11:04 +0000 (11:11 -0800)
htsworkflow/util/ethelp.py

index 7398963999bfa470e7ffb9ee17822a4a8bc7ddd4..f2f3e019b20782146c0855f32a4e41e02468336e 100644 (file)
@@ -5,11 +5,6 @@ import os
 LOGGER = logging.getLogger(__name__)
 
 import lxml.etree
-try:
-    XHTML_RDF_DTD = lxml.etree.DTD(external_id='-//W3C//DTD XHTML+RDFa 1.0//EN')
-except lxml.etree.DTDParseError as e:
-    XHTML_RDF_DTD = None
-    LOGGER.warn("Unable to load XHTML DTD %s" % (str(e),))
 
 def indent(elem, level=0):
     """
@@ -49,8 +44,11 @@ def validate_xhtml(html, base_url='http://localhost'):
     Returns True if it passed validation
     and False if it fails.
     """
-    if XHTML_RDF_DTD is None:
-        return None
+    try:
+        XHTML_RDF_DTD = lxml.etree.DTD(external_id='-//W3C//DTD XHTML+RDFa 1.0//EN')
+    except lxml.etree.DTDParseError as e:
+        LOGGER.warn("Unable to load XHTML DTD %s" % (str(e),))
+        return
 
     try:
         root = lxml.etree.fromstring(html, base_url=base_url)