Changeset 53723
- Timestamp:
- 07/04/09 12:58:25 (8 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
CPS3/products/CPSDesignerThemes/trunk/INSTALL.txt
r53674 r53723 4 4 Dependencies 5 5 ------------ 6 At least one of these XML processing libraries is required : 7 6 8 cElementTree 1.0.6 or plain Elementree 1.3 7 9 … … 12 14 Documentation: http://effbot.org/zone/elementtree-13-intro.htm 13 15 14 lxml is also needed to run the tests. 16 lxml >= 2.2.2. Details: 17 Tested versions of the lxml package so far 18 - on lxml 2.1.2 (MacOSX build by plone buildout recipe) -> fails 19 - on lxml 2.2.2 (homemade build on Ubuntu 9.04) -> works 20 The discriminating issue between those versions is the following: 21 http://osdir.com/ml/python.lxml.devel/2006-06/msg00084.html 22 23 Run the unit tests to know if your version works, and don't 24 hesitate to report the results 25 26 Testing dependencies 27 -------------------- 28 The tests currently try and load all possible engines. Therefore, 29 you'll need to have both (c)ElementTree and lxml to run them. 30 This could be lifted in the future. 31 32 Even if you deactivate the testing of lxml engines, lxml will still 33 be required, because it's been used by the testing infrastructure 34 itself (to check the output produced by the tested engine) 35 15 36 16 37 Installing … … 42 63 --------------------- 43 64 All engine tests are ran for all engines. 44 The lxml engine doesn't work yet, isn't hooked by default, and fails45 on some tests.46 65 47 66 lxml is also needed to run the doctests, but this has nothing to do CPS3/products/CPSDesignerThemes/trunk/engine/lxmlengine.py
r53671 r53723 30 30 from Products.CPSDesignerThemes.utils import rewrite_uri 31 31 from base import BaseEngine 32 from twophase import TwoPhaseEngine 32 33 from etreeengine import ElementTreeEngine 33 34 from etreeengine import PORTLET_ATTR 35 from etreeengine import LINK_HTML_DOCUMENTS 34 36 35 37 NAMESPACES = dict(cps=NS_URI, xhtml=NS_XHTML) 36 37 LINK_HTML_DOCUMENTS = {'img' : 'src',38 'link' : 'href',39 'object' : 'data',40 'param' : 'value',41 }42 38 43 39 class LxmlEngine(ElementTreeEngine): … … 52 48 XML_HEADER = '<?xml version="1.0" encoding="%s"?>' % ENCODING 53 49 54 def __init__(self, html_file=None, theme_base_uri='', page_uri=''): 50 def __init__(self, html_file=None, theme_base_uri='', page_uri='', 51 cps_base_url=''): 55 52 self.tree = etree.parse(html_file) 56 53 self.root = self.tree.getroot() 57 54 BaseEngine.__init__(self, theme_base_uri=theme_base_uri, 58 page_uri=page_uri )55 page_uri=page_uri, cps_base_url=cps_base_url) 59 56 60 57 … … 73 70 # TODO GR: this works around the fact that entity support in 74 71 # my ElementTree version doesn't work as advertised 75 content = content.replace(' ', ' ')76 72 77 73 parser = etree.XMLParser() … … 98 94 return parsed 99 95 100 def rewriteUris(self ):96 def rewriteUris(self, rewriter_func=None): 101 97 """implementation: lxml.html has helpers for this. """ 98 if rewriter_func is None: 99 rewriter_func=rewrite_uri 102 100 for tag, attr in LINK_HTML_DOCUMENTS.items(): 103 101 for elt in self.root.iterfind('.//{%s}%s' % (NS_XHTML, tag)): 104 102 uri = elt.attrib[attr] 105 103 try: 106 new_uri = rewrite _uri(uri=uri,104 new_uri = rewriter_func(uri=uri, 107 105 absolute_base=self.theme_base_uri, 108 referer_uri=self.page_uri) 106 referer_uri=self.page_uri, 107 cps_base_url=self.cps_base_url) 109 108 except KeyError: 110 109 raise ValueError( … … 138 137 out = StringIO() 139 138 self.tree.write(out) 140 return out.getvalue() 139 # XXX GR couldn't find a way to change the nsmap 140 # to prevent now useless declaration 141 return out.getvalue().replace( 142 'xmlns:cps="http://xmlns.racinet.org/cps"', '', 1) 143 144 class TwoPhaseLxmlEngine(TwoPhaseEngine, LxmlEngine): 145 """Two phase version""" 146 147 def appendFragment(self, elt, fragment, is_element=False): 148 elt.append(etree.Element(self.computeInclusionMarkerTag(fragment))) 149 150 def insertFragment(self, index, elt, fragment, is_element=False): 151 elt.insert(index, 152 etree.Element(self.computeInclusionMarkerTag(fragment))) CPS3/products/CPSDesignerThemes/trunk/tests/test_engine.py
r53717 r53723 27 27 TwoPhaseElementTreeEngine, 28 28 ) 29 from Products.CPSDesignerThemes.engine.lxmlengine import LxmlEngine 29 from Products.CPSDesignerThemes.engine.lxmlengine import ( 30 LxmlEngine, 31 TwoPhaseLxmlEngine) 30 32 from Products.CPSDesignerThemes.constants import NS_XHTML 31 33 … … 84 86 '</p></div>' % (NS_XHTML, portlet[0], portlet[1])) 85 87 if not hasattr(self.EngineClass, 'secondPhase'): 86 expected = expected.replace(' ', ' ') 88 expected = expected.replace(' ', '\xa0') 89 # skip declaration: not what is being tested 90 rendered = re.sub(r'<\?xml.*\?>', '', rendered) 87 91 self.assertEquals(rendered, expected) 88 92 … … 113 117 return element.attrib 114 118 119 115 120 class TestLxmlEngine(TestElementTreeEngine): 116 121 117 122 EngineClass = LxmlEngine 118 123 124 def test_entities(self): 125 """lxml has no support for entities in the absence of a DTD. 126 127 partially serialized content with the DTD could be a problem. 128 Two-phase engines don't mind, and the most critical source of entities 129 is the dynamical content. 130 """ 131 132 119 133 class TestTwoPhaseElementTreeEngine(TestElementTreeEngine): 120 134 121 135 EngineClass = TwoPhaseElementTreeEngine 136 137 138 class TestTwoPhaseLxmlEngine(TestLxmlEngine): 139 140 EngineClass = TwoPhaseLxmlEngine 122 141 123 142 … … 136 155 suite = unittest.TestSuite() 137 156 138 for PageEngine in (ElementTreeEngine, TwoPhaseElementTreeEngine):#, LxmlEngine): 157 for PageEngine in (ElementTreeEngine, TwoPhaseElementTreeEngine, 158 LxmlEngine, TwoPhaseLxmlEngine): 139 159 suite.addTest(unittest.makeSuite(engines2test_case()[PageEngine])) 140 160 for test_file in ('engine/portlets_merging.txt',
