Commits

Lynn Rees committed c39730b

- fixes

Comments (0)

Files changed (4)

webstring/base.py

         '''Sets template variable delimiter.'''
         self._mark = mark
 
-    def pipe(self, info=None, format='xml', encoding='utf-8'):
+    def pipe(self, info=None, format='xml'):
         '''
         Returns the string output of the internal template and
         resets the Template.
 
         @param info Data to substitute into a template (default: None)
         @param format Document format (default:'xml')
-        @param encoding Encoding of return string (default: 'utf-8')
         '''
-        output = self.render(info, format, encoding)
+        output = self.render(info, format)
         self.reset()
         return output
 
         else:
             self.__iadd__(self.default)
 
-    def write(self, path, info=None, format='xml', encoding='utf-8'):
+    def write(self, path, info=None, format='xml'):
         '''
         Writes a Template's string output to a file.
 
         @param path Output file path
         @param info Data to substitute into a template (default: None)
         @param format Document format (default:'xml')
-        @param encoding Encoding of output string (default: 'utf-8')
         '''
-        open(path, 'wb').write(self.render(info, format, encoding))
+        open(path, 'wb').write(self.render(info, format))
 
 
 class _Many(_Base):

webstring/tests/test_webstring.py

 
     def test_lroot_radd_raise(self):
         '''Raises TypeError if wrong type right-side added to root Template.'''
-        def tempfunc(): return [1, 1, 1] + self.atemplate
+        def tempfunc():
+            return [1, 1, 1] + self.atemplate
         self.assertRaises(TypeError, tempfunc)
 
     def test_lroot_iadd_raise(self):
 
     def test_lgroup_radd_raise(self):
         '''Raises TypeError if wrong type is right-side added to group.'''
-        def tempfunc(): return [1, 1, 1] + self.agrouptest.tr1
+        def tempfunc():
+            return [1, 1, 1] + self.agrouptest.tr1
         self.assertRaises(TypeError, tempfunc)
 
     def test_lgroup_iadd_raise(self):
 
     def test_lsubfield_radd_raise(self):
         '''Raises TypeError if wrong type is right-side added to subfield.'''
-        def tempfunc(): return [1, 1, 1] + self.agrouptest.tr1.td1
+        def tempfunc():
+            return [1, 1, 1] + self.agrouptest.tr1.td1
         self.assertRaises(TypeError, tempfunc)
 
     def test_lsubfield_iadd_raise(self):
 
     def test_lroot_string_mod(self):
         '''Raises TypeError if string passed to a root Template.'''
-        def tempfunc(): return self.gentemplate % 'Test Page'
+        def tempfunc():
+            return self.gentemplate % 'Test Page'
         self.assertRaises(TypeError, tempfunc)
 
     def test_lfield_mod_str_wrongtype(self):
         '''Raises TypeError if wrong type passed to a field.'''
-        def tempfunc(): return self.gentemplate.content % ['Test Page']
+        def tempfunc():
+            return self.gentemplate.content % ['Test Page']
         self.assertRaises(TypeError, tempfunc)
 
     def test_lroot_group_str_mod_toofew(self):
         '''Raises TypeError if string passed to root containing only group.'''
-        def tempfunc(): return self.agrouptest % 'Test Page'
+        def tempfunc():
+            return self.agrouptest % 'Test Page'
         self.assertRaises(TypeError, tempfunc)
 
     def test_lfield_group_str_mod_toofew(self):
         '''Raises TypeError if string passed to a group.'''
-        def tempfunc(): return self.agrouptest.tr1 % 'Test Page'
+        def tempfunc():
+            return self.agrouptest.tr1 % 'Test Page'
         self.assertRaises(TypeError, tempfunc)
 
     def test_lroot_tuple_imod(self):
 
     def test_lroot_tuple_mod_wrongtype(self):
         '''Raises TypeError if wrong type in tuple is subbed into root.'''
-        def tempfunc(): return self.gentemplate % (set(['Test Page']),)
+        def tempfunc():
+            return self.gentemplate % (set(['Test Page']),)
         self.assertRaises(TypeError, tempfunc)
 
     def test_lgroup_tuple_mod_wrongtype(self):
         '''Raises TypeError if wrong type in tuple is subbed into group.'''
-        def tempfunc(): return self.agrouptest.tr1 % (set(['Test Page']),)
+        def tempfunc():
+            return self.agrouptest.tr1 % (set(['Test Page']),)
         self.assertRaises(TypeError, tempfunc)
 
     def test_lroot_tuple_mod_toomany(self):
         '''Raises TypeError if too many items in tuple are subbed in root.'''
-        def tempfunc(): return self.gentemplate % ('Test', 'Test', 'Too Many')
+        def tempfunc():
+            return self.gentemplate % ('Test', 'Test', 'Too Many')
         self.assertRaises(TypeError, tempfunc)
 
     def test_lgroup_tuple_mod_toomany(self):
         '''Raises TypeError if too many items in tuple are subbed in group.'''
-        def tempfunc(): return self.agrouptest.tr1 % ('Test', 'Test', 'Test')
+        def tempfunc():
+            return self.agrouptest.tr1 % ('Test', 'Test', 'Test')
         self.assertRaises(TypeError, tempfunc)
 
     def test_lroot_tuple_mod_toofew(self):
         '''Raises TypeError if too few items in tuple are subbed into root.'''
-        def tempfunc(): return self.gentemplate % ('Test Page')
+        def tempfunc():
+            return self.gentemplate % ('Test Page')
         self.assertRaises(TypeError, tempfunc)
 
     def test_lgroup_tuple_mod_toofew(self):
         '''Raises TypeError if too few items in tuple are subbed into group.'''
-        def tempfunc(): return self.agrouptest.tr1 % ('Test Page')
+        def tempfunc():
+            return self.agrouptest.tr1 % ('Test Page')
         self.assertRaises(TypeError, tempfunc)
 
     def test_lroot_dict_imod(self):
 
     def test_lroot_dict_tuple_imod_expand(self):
         '''Tests a modifying dictionary tuple sub/expansion of a root.'''
-        self.modtemplate3 %= {'title':'Title', 'content':('Test1', 'Test2'),
-            "content2":('Test1', 'Test2')}
+        self.modtemplate3 %= {'title': 'Title', 'content': ('Test1', 'Test2'),
+            "content2": ('Test1', 'Test2')}
         self.assertEqual(self.modtest3, self.modtemplate3.pipe())
 
     def test_lgroup_dict_tuple_imod_expand(self):
         '''Tests a modifying dict tuple substitution/expansion of a group.'''
-        self.agrouptest.tr1 %= {'td1':('Test1', 'Test2'),
-            'td2':('Test1', 'Test2')}
+        self.agrouptest.tr1 %= {'td1': ('Test1', 'Test2'),
+            'td2': ('Test1', 'Test2')}
         self.assertEqual(self.groupmod3, self.agrouptest.pipe())
 
     def test_lroot_dict_mod_wrongtype(self):
         '''Raises TypeError if wrong type in a dict are subbed into a root.'''
-        def tempfunc(): return self.gentemplate % {'content':set(['Test'])}
+        def tempfunc():
+            return self.gentemplate % {'content': set(['Test'])}
         self.assertRaises(TypeError, tempfunc)
 
     def test_lgroup_dict_mod_wrongtype(self):
         '''Raises TypeError if wrong type in a dict are subbed into a group.'''
-        def tempfunc(): return self.agrouptest.tr1 % {'td1':set(['Test Page'])}
+        def tempfunc():
+            return self.agrouptest.tr1 % {'td1': set(['Test Page'])}
         self.assertRaises(TypeError, tempfunc)
 
     def test_lroot_dict_mod_toomany(self):
         '''Raises TypeError if too many items in dict are subbed into root.'''
         def tempfunc():
-            return self.gentemplate % {'content':'Content Goes Here',
-                'title':'Test Page', 'test':'Too many'}
+            return self.gentemplate % {'content': 'Content Goes Here',
+                'title': 'Test Page', 'test': 'Too many'}
         self.assertRaises(TypeError, tempfunc)
 
     def test_lgroup_dict_mod_toomany(self):
         '''Raises TypeError if too many items in dict are subbed into group.'''
         def tempfunc():
-            return self.agrouptest.tr1 % {'td1':'Content Goes Here',
-                'td2':'Test Page', 'td3':'Too many'}
+            return self.agrouptest.tr1 % {'td1': 'Content Goes Here',
+                'td2': 'Test Page', 'td3': 'Too many'}
         self.assertRaises(TypeError, tempfunc)
 
     def test_lroot_dict_mod_toofew(self):
         '''Raises TypeError if too few items in dict are subbed into root.'''
-        def tempfunc(): return self.gentemplate % {'content':'Content'}
+        def tempfunc():
+            return self.gentemplate % {'content': 'Content'}
         self.assertRaises(TypeError, tempfunc)
 
     def test_lgroup_dict_mod_toofew(self):
         '''Raises TypeError if too few items in dict are subbed into group.'''
-        def tempfunc(): return self.gentemplate % {'content':'Content'}
+        def tempfunc():
+            return self.gentemplate % {'content': 'Content'}
         self.assertRaises(TypeError, tempfunc)
 
     def test_lroot_imod_mass_temp_subs(self):
         '''Tests a mass templates/substitution assignment on a root.'''
-        final = '''<rss version="2.0">
-<channel>
-<title>Example</title>
-<link>http://www.example.org/</link>
-<description>RSS Example</description>
-<language>en-us</language>
-<pubDate id="cpubdate">$month $day, $year</pubDate>
-<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
-<item class="item">
-<title id="title">Example Title: First Example</title>
-<link id="link">http://www.example.com/rss/5423092</link>
-<guid id="guid" isPermaLink="true">http://www.example.com/rss/5423092</guid>
-<description id="description">Example of assigning text to a field.</description>
-<pubDate id="ipubdate">June 06, 2006</pubDate>
-</item>
-<item class="item">
-<title id="title">Example Title: Second Example</title>
-<link id="link">http://www.example.com/rss/5423093</link>
-<guid id="guid" isPermaLink="true">http://www.example.com/rss/5423093</guid>
-<description id="description">Example of group repetition.</description>
-<pubDate id="ipubdate">June 06, 2006</pubDate>
-</item>
-</channel>
-</rss>'''
         self.rss.item %= {
-            'templates':{
-                'title':{'text':'Example Title: $content'},
-                'ipubdate':{'text':'$month $day, $year'},
-                'link':{'text':'http://www.example.com/rss/$id'}},
-            'subs':(
-                ({'text':{'content':'First Example'}},
-                {'text':{'id':'5423092'}},
+            'templates': {
+                'title': {'text': 'Example Title: $content'},
+                'ipubdate': {'text': '$month $day, $year'},
+                'link': {'text': 'http://www.example.com/rss/$id'}},
+            'subs': (
+                ({'text': {'content': 'First Example'}},
+                {'text': {'id': '5423092'}},
                 'http://www.example.com/rss/5423092',
                 'Example of assigning text to a field.',
-                {'text':{'month':'June', 'day':'06', 'year':'2006'}}),
-                ({'text':{'content':'Second Example'}},
-                {'text':{'id':'5423093'}},
+                {'text': {'month': 'June', 'day': '06', 'year': '2006'}}),
+                ({'text': {'content': 'Second Example'}},
+                {'text': {'id': '5423093'}},
                 'http://www.example.com/rss/5423093',
                 'Example of group repetition.',
-                {'text':{'month':'June', 'day':'06', 'year':'2006'}}))}
-        self.assertEqual(final, self.rss.pipe())
+                {'text': {'month': 'June', 'day': '06', 'year': '2006'}}))}
+        self.assertEqual('''<rss version="2.0">
+<channel>
+<title>Example</title>
+<link>http://www.example.org/</link>
+<description>RSS Example</description>
+<language>en-us</language>
+<pubDate id="cpubdate">$month $day, $year</pubDate>
+<lastBuildDate id="lastbuilddate">%(month)s %(day)s, %(year)s</lastBuildDate>
+<item class="item">
+<title id="title">Example Title: First Example</title>
+<link id="link">http://www.example.com/rss/5423092</link>
+<guid id="guid" isPermaLink="true">http://www.example.com/rss/5423092</guid>
+<description id="description">Example of assigning text to a field.</description>
+<pubDate id="ipubdate">June 06, 2006</pubDate>
+</item>
+<item class="item">
+<title id="title">Example Title: Second Example</title>
+<link id="link">http://www.example.com/rss/5423093</link>
+<guid id="guid" isPermaLink="true">http://www.example.com/rss/5423093</guid>
+<description id="description">Example of group repetition.</description>
+<pubDate id="ipubdate">June 06, 2006</pubDate>
+</item>
+</channel>
+</rss>''', self.rss.pipe())
 
     def test_lroot_imod_extended_format(self):
         '''Tests an extended format substitution on a root.'''
-        final = '<body><a id="fieldtest" href="caliban.html#test" title="This '\
-        'link goes to test">This template is a first test.</a><a '\
-        'id="fieldtest" href="caliban.html#linktest" title="This link goes to '\
-        'Link Test">This other template is a link test.</a><tr '\
-        'class="grouptest"><td id="groupfield1" align="left" title="This '\
-        'column is column first">This first test is the first column.</td>'\
-        '<td id="groupfield1" align="right" title="This col is column '\
-        'second">This second test is the second column.</td><td '\
-        'id="groupfield2" align="left" title="This test is next.">This test '\
-        'is first.</td><td id="groupfield2">This coltest is a next.</td></tr></body>'
         self.subcombotest %= {
-            'grouptest':{
-                'groupfield1':{
-                    'template':{
-                        'text':'This %(one)s is the %(num)s column.',
-                        'attrib':{'title':'This %(one)s is column %(num)s'}
-                    }, 'sub':({
-                        'text':{'one':'first test', 'num':'first'},
-                        'attrib':{
-                            'align':'left',
-                            'title':{'one':'column', 'num':'first'}}}, {
-                        'text':'This second test is the second column.',
-                        'attrib':{
-                            'align':'right',
-                            'title':{'one':'col', 'num':'second'}}})},
-                    'groupfield2':{
-                        'template':{
-                            'text':'This $test is a $fill.',
-                            'attrib':{
-                                'title':'This %(one)s is next.'}},
-                        'sub':({
-                            'text':'This test is first.',
-                            'attrib':{
-                                'align':'left',
-                                'title':{'one':'test'}}}, {
-                            'text':{'test':'coltest', 'fill':'next'},
-                            'attrib':{
-                                 'href':{'link':'linktest'},
-                                 'title':{'other':'Link Test'}}})}},
-            'fieldtest':{
-                'template':{
-                    'text':'This %(run)s is a %(test)s.',
-                    'attrib':{
-                        'href':'caliban.html#%(link)s',
-                        'title':'This link goes to %(other)s'}},
-                'sub':({
-                    'text':{'test':'first test', 'run':'template'},
-                    'attrib':{
-                        'href':{'link':'test'},
-                        'title':{'other':'test'}}}, {
-                    'text':{'test':'link test', 'run':'other template'},
-                    'attrib':{
-                         'href':{'link':'linktest'},
-                         'title':{'other':'Link Test'}}})}}
-        self.assertEqual(final, self.subcombotest.pipe())
+            'grouptest': {
+                'groupfield1': {
+                    'template': {
+                        'text': 'This %(one)s is the %(num)s column.',
+                        'attrib': {'title': 'This %(one)s is column %(num)s'}
+                    }, 'sub': ({
+                        'text': {'one': 'first test', 'num': 'first'},
+                        'attrib': {
+                            'align': 'left',
+                            'title': {'one': 'column', 'num': 'first'}}}, {
+                        'text': 'This second test is the second column.',
+                        'attrib': {
+                            'align': 'right',
+                            'title': {'one': 'col', 'num': 'second'}}})},
+                    'groupfield2': {
+                        'template': {
+                            'text': 'This $test is a $fill.',
+                            'attrib': {
+                                'title': 'This %(one)s is next.'}},
+                        'sub': ({
+                            'text': 'This test is first.',
+                            'attrib': {
+                                'align': 'left',
+                                'title': {'one': 'test'}}}, {
+                            'text': {'test': 'coltest', 'fill': 'next'},
+                            'attrib': {
+                                 'href': {'link': 'linktest'},
+                                 'title': {'other': 'Link Test'}}})}},
+            'fieldtest': {
+                'template': {
+                    'text': 'This %(run)s is a %(test)s.',
+                    'attrib': {
+                        'href': 'caliban.html#%(link)s',
+                        'title': 'This link goes to %(other)s'}},
+                'sub': ({
+                    'text': {'test': 'first test', 'run': 'template'},
+                    'attrib': {
+                        'href': {'link': 'test'},
+                        'title': {'other': 'test'}}}, {
+                    'text': {'test': 'link test', 'run': 'other template'},
+                    'attrib': {
+                         'href': {'link': 'linktest'},
+                         'title': {'other': 'Link Test'}}})}}
+        self.assertEqual(
+            '<body><a id="fieldtest" href="caliban.html#test" title="This '
+        'link goes to test">This template is a first test.</a><a '
+        'id="fieldtest" href="caliban.html#linktest" title="This link goes to '
+        'Link Test">This other template is a link test.</a><tr '
+        'class="grouptest"><td id="groupfield1" align="left" title="This '
+        'column is column first">This first test is the first column.</td>'
+        '<td id="groupfield1" align="right" title="This col is column '
+        'second">This second test is the second column.</td><td '
+        'id="groupfield2" align="left" title="This test is next.">This test '
+        'is first.</td><td id="groupfield2">This coltest is a next.</td></tr>'
+        '</body>', self.subcombotest.pipe()
+        )
 
     def test_lfield_imod_extended_format(self):
         '''Tests an extended format substitution on a field.'''
-        final = '<body><a id="fieldtest" href="caliban.html#test" ' \
-            'title="This link goes to test">This template is a first ' \
-            'test.</a><a id="fieldtest" href="caliban.html#linktest" ' \
-            'title="This link goes to Link Test">This other template ' \
-            'is a link test.</a><tr class="grouptest"><td ' \
-            'id="groupfield1"/><td id="groupfield2"/></tr></body>'
         self.subcombotest.fieldtest %= {
-            'template':{
-                'text':'This %(run)s is a %(test)s.',
-                'attrib':{
-                    'href':'caliban.html#%(link)s',
-                    'title':'This link goes to %(other)s'}},
-            'sub':({
-                'text':{'test':'first test', 'run':'template'},
-                'attrib':{
-                    'href':{'link':'test'},
-                    'title':{'other':'test'}}}, {
-                'text':{'test':'link test', 'run':'other template'},
-                'attrib':{
-                     'href':{'link':'linktest'},
-                     'title':{'other':'Link Test'}}})}
-        self.assertEqual(final, self.subcombotest.pipe())
+            'template': {
+                'text': 'This %(run)s is a %(test)s.',
+                'attrib': {
+                    'href': 'caliban.html#%(link)s',
+                    'title': 'This link goes to %(other)s'}},
+            'sub': ({
+                'text': {'test': 'first test', 'run': 'template'},
+                'attrib': {
+                    'href': {'link': 'test'},
+                    'title': {'other': 'test'}}}, {
+                'text': {'test': 'link test', 'run': 'other template'},
+                'attrib': {
+                     'href': {'link': 'linktest'},
+                     'title': {'other': 'Link Test'}}})}
+        self.assertEqual(
+            '<body><a id="fieldtest" href="caliban.html#test" '
+            'title="This link goes to test">This template is a first '
+            'test.</a><a id="fieldtest" href="caliban.html#linktest" '
+            'title="This link goes to Link Test">This other template '
+            'is a link test.</a><tr class="grouptest"><td '
+            'id="groupfield1"/><td id="groupfield2"/></tr></body>',
+            self.subcombotest.pipe()
+        )
 
     def test_lfield_imod_attrib_extended_format(self):
         '''Tests an extended attribute format substitution on a field.'''
-        final = '<body><a id="fieldtest" href="caliban.html#test" title="This '\
-        'link goes to test">This is a test.</a><a id="fieldtest" '\
-        'href="caliban.html#linktest" title="This link goes to Link Test">This is another test.'\
-        '</a><tr class="grouptest"><td id="groupfield1"/><td id="groupfield2"/></tr></body>'
         self.subcombotest.fieldtest %= {
-            'template':{
-                'attrib':{
-                    'href':'caliban.html#%(link)s',
-                    'title':'This link goes to %(other)s'}},
-            'sub':({
-                'text':'This is a test.',
-                'attrib':{
-                    'href':{'link':'test'},
-                    'title':{'other':'test'}}}, {
-                'text':'This is another test.',
-                'attrib':{
-                     'href':{'link':'linktest'},
-                     'title':{'other':'Link Test'}}})}
-        self.assertEqual(final, self.subcombotest.pipe())
+            'template': {
+                'attrib': {
+                    'href': 'caliban.html#%(link)s',
+                    'title': 'This link goes to %(other)s'}},
+            'sub': ({
+                'text': 'This is a test.',
+                'attrib': {
+                    'href': {'link': 'test'},
+                    'title': {'other': 'test'}}}, {
+                'text': 'This is another test.',
+                'attrib': {
+                     'href': {'link': 'linktest'},
+                     'title': {'other': 'Link Test'}}})}
+        self.assertEqual(
+            '<body><a id="fieldtest" href="caliban.html#test" title="This '
+        'link goes to test">This is a test.</a><a id="fieldtest" '
+        'href="caliban.html#linktest" title="This link goes to Link Test">'
+        'This is another test.</a><tr class="grouptest"><td id="groupfield1"/>'
+        '<td id="groupfield2"/></tr></body>',
+        self.subcombotest.pipe()
+    )
 
     def test_lfield_imod_text_extended_format(self):
         '''Tests a text extended format substitution on a field.'''
-        final = '<body><a id="fieldtest" href="atest">This template is ' \
-            'a first test.</a><a id="fieldtest" href="atest">This other' \
-            ' template is a link test.</a><tr class="grouptest"><td id' \
-            '="groupfield1"/><td id="groupfield2"/></tr></body>'
         self.subcombotest.fieldtest %= {
-            'template':{
-                'text':'This %(run)s is a %(test)s.'},
-            'sub':({
-                'text':{'test':'first test', 'run':'template'}}, {
-                'text':{'test':'link test', 'run':'other template'}})}
-        self.assertEqual(final, self.subcombotest.pipe())
+            'template': {
+                'text': 'This %(run)s is a %(test)s.'},
+            'sub': ({
+                'text': {'test': 'first test', 'run': 'template'}}, {
+                'text': {'test': 'link test', 'run': 'other template'}})}
+        self.assertEqual(
+            '<body><a id="fieldtest" href="atest">This template is '
+            'a first test.</a><a id="fieldtest" href="atest">This other'
+            ' template is a link test.</a><tr class="grouptest"><td id'
+            '="groupfield1"/><td id="groupfield2"/></tr></body>',
+            self.subcombotest.pipe()
+        )
 
     def test_lgroup_imod_combo_extended_format(self):
         '''Tests an extended format substitution on a group.'''
-        final = '<body><a id="fieldtest" href="atest"/><tr class="grouptest">'\
-        '<td id="groupfield1" align="left" title="This column is column first">'\
-        'This first test is the first column.</td><td id="groupfield1" '\
-        'align="right" title="This col is column second">This second test is '\
-        'the second column.</td><td id="groupfield2" align="left" title="This '\
-        'test is next.">This test is first.</td><td id="groupfield2">This '\
-        'coltest is a next.</td></tr></body>'
         self.subcombotest.grouptest %= {
-                'groupfield1':{
-                    'template':{
-                        'text':'This %(one)s is the %(num)s column.',
-                        'attrib':{'title':'This %(one)s is column %(num)s'}
-                     }, 'sub':({
-                        'text':{'one':'first test', 'num':'first'},
-                        'attrib':{
-                            'align':'left',
-                            'title':{'one':'column', 'num':'first'}}}, {
-                        'text':'This second test is the second column.',
-                        'attrib':{
-                            'align':'right',
-                            'title':{'one':'col', 'num':'second'}}})},
-                    'groupfield2':{
-                        'template':{
-                            'text':'This $test is a $fill.',
-                            'attrib':{
-                                'title':'This %(one)s is next.'}},
-                        'sub':({
-                            'text':'This test is first.',
-                            'attrib':{
-                                'align':'left',
-                                'title':{'one':'test'}}}, {
-                            'text':{'test':'coltest', 'fill':'next'},
-                            'attrib':{
-                                 'href':{'link':'linktest'},
-                                 'title':{'other':'Link Test'}}})}}
-        self.assertEqual(final, self.subcombotest.pipe())
+                'groupfield1': {
+                    'template': {
+                        'text': 'This %(one)s is the %(num)s column.',
+                        'attrib': {'title': 'This %(one)s is column %(num)s'}
+                     }, 'sub': ({
+                        'text': {'one': 'first test', 'num': 'first'},
+                        'attrib': {
+                            'align': 'left',
+                            'title': {'one': 'column', 'num': 'first'}}}, {
+                        'text': 'This second test is the second column.',
+                        'attrib': {
+                            'align': 'right',
+                            'title': {'one': 'col', 'num': 'second'}}})},
+                    'groupfield2': {
+                        'template': {
+                            'text': 'This $test is a $fill.',
+                            'attrib': {
+                                'title': 'This %(one)s is next.'}},
+                        'sub': ({
+                            'text': 'This test is first.',
+                            'attrib': {
+                                'align': 'left',
+                                'title': {'one': 'test'}}}, {
+                            'text': {'test': 'coltest', 'fill': 'next'},
+                            'attrib': {
+                                 'href': {'link': 'linktest'},
+                                 'title': {'other': 'Link Test'}}})}}
+        self.assertEqual(
+            '<body><a id="fieldtest" href="atest"/><tr class="grouptest">'
+            '<td id="groupfield1" align="left" title="This column is column '
+            'first">'
+            'This first test is the first column.</td><td id="groupfield1" '
+            'align="right" title="This col is column second">This second test'
+            ' is the second column.</td><td id="groupfield2" align="left" '
+            'title="This test is next.">This test is first.</td><td '
+            'id="groupfield2">This coltest is a next.</td></tr></body>',
+            self.subcombotest.pipe()
+        )
 
     def test_lfield_pow(self):
         '''Tests a expansion of a field.'''
 
     def test_lfield_pow_wrongtype(self):
         '''Raises TypeError if wrong type passed in for field expansion.'''
-        def tempfunc(): return self.powtemplate ** 'This is a test.'
+        def tempfunc():
+            return self.powtemplate ** 'This is a test.'
         self.assertRaises(TypeError, tempfunc)
 
     def test_lgroup_pow_wrongtype(self):
         '''Raises TypeError if wrong type passed in for group expansion.'''
-        def tempfunc(): return self.agrouptest.tr1 ** 'This is a test.'
+        def tempfunc():
+            return self.agrouptest.tr1 ** 'This is a test.'
         self.assertRaises(TypeError, tempfunc)
 
     def test_lfield_delattr_dict(self):
         '''Tests deletion of field attributes from internal dict.'''
         atst = self.btemplate.default
         del atst.content
-        self.assertEqual(False, atst._fielddict.has_key('content'))
+        self.assertEqual(False, 'content' in atst._fielddict)
 
     def test_lgroup_delattr_dict(self):
         '''Tests deletion of group attributes from internal dict.'''
         atst = self.agrouptest.default
         del atst.tr1
-        self.assertEqual(False, atst._fielddict.has_key('tr1'))
+        self.assertEqual(False, 'tr1' in atst._fielddict)
 
     def test_lsubfield_delattr_dict(self):
         '''Tests deletion of group attributes from internal dict.'''
         atst = self.agrouptest.default
         del atst.tr1.td1
-        self.assertEqual(False, atst.tr1._fielddict.has_key('td1'))
+        self.assertEqual(False, 'td1' in atst.tr1._fielddict)
 
     def test_lfield_delattr(self):
         '''Tests deletion of field attributes from internal list.'''
         '''Tests setting XML attribute attributes with a dict.'''
         atst = Template('<table><tr class="tr1"><td id="td1" ' \
         'align="left"/><td id="td2"/></tr></table>')
-        atst.tr1.td1.atemplates({'align':'This is $dir'})
-        atst.tr1.td1.align = {'dir':'right'}
+        atst.tr1.td1.atemplates({'align': 'This is $dir'})
+        atst.tr1.td1.align = {'dir': 'right'}
         self.assertEqual(atst.tr1.td1.align, 'This is right')
 
     def test_lfield_delete_attribute(self):
         '''Tests setting attributes via key w/o automagic with a dict.'''
         atst = Template('<table><tr class="tr1"><td id="td1" ' \
         'align="left"/><td id="td2"/></tr></table>', False)
-        atst['tr1']['td1'].atemplates({'align':'This is $dir'})
-        atst['tr1']['td1']['align'] = {'dir':'right'}
+        atst['tr1']['td1'].atemplates({'align': 'This is $dir'})
+        atst['tr1']['td1']['align'] = {'dir': 'right'}
         self.assertEqual(atst['tr1']['td1']['align'], 'This is right')
 
     def test_lfield_attribute_delete_key_noauto(self):
         '''Tests setting attributes via key with a dict.'''
         atst = Template('<table><tr class="tr1"><td id="td1" ' \
         'align="left"/><td id="td2"/></tr></table>')
-        atst.tr1.td1.atemplates({'align':'This is $dir'})
-        atst.tr1.td1['align'] = {'dir':'right'}
+        atst.tr1.td1.atemplates({'align': 'This is $dir'})
+        atst.tr1.td1['align'] = {'dir': 'right'}
         self.assertEqual(atst.tr1.td1['align'], 'This is right')
 
     def test_lfield_attribute_delete_key(self):
 
     def test_lupdate(self):
         '''Tests mass addition of XML attributes.'''
-        final = '<head><link id="test" href="thing.css" type="text/css"/></head>'
         test = Template('<head><link id="test"/></head>')
-        test.test.update({'href':'thing.css', 'type':'text/css'})
-        self.assertEqual(final, test.render())
+        test.test.update({'href': 'thing.css', 'type': 'text/css'})
+        self.assertEqual(
+            '<head><link id="test" href="thing.css" type="text/css"/></head>',
+            test.render()
+        )
 
     def test_lupdate_wrong_type(self):
         '''Tests update to see if it throws exception with wrong type.'''
     def test_latemplate_interpolation(self):
         '''Tests substituting attributes text with string interpolation.'''
         atst = self.gentemplate.default
-        atst.content.atemplates({'span':'%(direction)s'})
-        atst.content.update({'span':{'direction':'left'}})
-        self.assertEqual(atst.content.render(), '<p id="content" span="left"/>')
+        atst.content.atemplates({'span': '%(direction)s'})
+        atst.content.update({'span': {'direction': 'left'}})
+        self.assertEqual(
+            atst.content.render(), '<p id="content" span="left"/>'
+        )
 
     def test_latemplate_string_template(self):
         '''Tests substituting attributes text with string.Template.'''
         atst = self.gentemplate.default
-        atst.content.atemplates({'span':'$direction'})
-        atst.content.update({'span':{'direction':'left'}})
+        atst.content.atemplates({'span': '$direction'})
+        atst.content.update({'span': {'direction': 'left'}})
         self.assertEqual(atst.content.render(),
             '<p id="content" span="left"/>')
 
         final = '<body><p id="content" title="This run is a test."/></body>'
         atst = Template('<body><p id="content" title="This %(t1)s is a ' \
             '%(t2)s"/></body>')
-        atst.content.update({'title':{'t1':'run', 't2':'test.'}})
+        atst.content.update({'title': {'t1': 'run', 't2': 'test.'}})
         self.assertEqual(final, atst.render())
 
     def test_latemplate_source_string_template(self):
         final = '<body><p id="content" title="This run is a test."/></body>'
         atst = Template('<body><p id="content" title="This $t1 is a ' \
             '$t2"/></body>')
-        atst.content.update({'title':{'t1':'run', 't2':'test.'}})
+        atst.content.update({'title': {'t1': 'run', 't2': 'test.'}})
         self.assertEqual(final, atst.render())
 
     def test_latemplate_wrongtype(self):
         '''Tests substituting inline attribute text.'''
         def tempfunc():
             atst = self.gentemplate.default
-            atst.content.atemplates({'span':'direction'})
+            atst.content.atemplates({'span': 'direction'})
         self.assertRaises(TypeError, tempfunc)
 
     def test_lauto_auto_off_attribute(self):
         atst = self.btemplate.default
         val = False
         for i in atst:
-            if i['id'] == 'content1': val = True
+            if i['id'] == 'content1':
+                val = True
         self.assertEqual(False, val)
 
     def test_liter_true(self):
         atst = self.btemplate.default
         val = False
         for i in atst:
-            if i['id'] == 'content': val = True
+            if i['id'] == 'content':
+                val = True
         self.assertEqual(True, val)
 
     def test_liter_assign(self):
         '''Tests if an iterator assigns correctly.'''
         atst = self.btemplate.default
-        for i in atst: i %= 'Test'
+        for i in atst:
+            i %= 'Test'
         self.assertEqual('Test', atst.content.text)
 
     def test_ltemplates(self):
         '''Tests batch addition of templates to a root Template.'''
-        final = '<body><a id="fieldtest" href="caliban.html#test" '\
-        'title="This link goes to test">This template is a first test.</a><a '\
-        'id="fieldtest" href="caliban.html#linktest" title="This link goes to '\
-        'Link Test">This other template is a link test.</a><tr '\
-        'class="grouptest"><td id="groupfield1" align="left" title="This '\
-        'column is column first">This first test is the first column.</td>' \
-        '<td id="groupfield1" align="right" title="This col is column '\
-        'second">This second test is the second column.</td><td '\
-        'id="groupfield2" align="left" title="This test is next.">This test '\
-        'is first.</td><td id="groupfield2">This coltest is a next.</td></tr></body>'
         self.subcombotest.templates({
-            'grouptest':{
-                'groupfield1':{
-                    'text':'This %(one)s is the %(num)s column.',
-                    'attrib':{'title':'This %(one)s is column %(num)s'}},
-                'groupfield2':{
-                    'text':'This $test is a $fill.',
-                    'attrib':{
-                        'title':'This %(one)s is next.'}}},
-            'fieldtest':{
-                'text':'This %(run)s is a %(test)s.',
-                'attrib':{
-                    'href':'caliban.html#%(link)s',
-                    'title':'This link goes to %(other)s'}}})
+            'grouptest': {
+                'groupfield1': {
+                    'text': 'This %(one)s is the %(num)s column.',
+                    'attrib': {'title': 'This %(one)s is column %(num)s'}},
+                'groupfield2': {
+                    'text': 'This $test is a $fill.',
+                    'attrib': {
+                        'title': 'This %(one)s is next.'}}},
+            'fieldtest': {
+                'text': 'This %(run)s is a %(test)s.',
+                'attrib': {
+                    'href': 'caliban.html#%(link)s',
+                    'title': 'This link goes to %(other)s'}}})
         self.subcombotest %= {
-            'grouptest':{
-                'groupfield1':{
-                    'sub':({
-                        'text':{'one':'first test', 'num':'first'},
-                        'attrib':{
-                            'align':'left',
-                            'title':{'one':'column', 'num':'first'}}}, {
-                        'text':'This second test is the second column.',
-                        'attrib':{
-                            'align':'right',
-                            'title':{'one':'col', 'num':'second'}}})},
-                    'groupfield2':{
-                        'sub':({
-                            'text':'This test is first.',
-                            'attrib':{
-                                'align':'left',
-                                'title':{'one':'test'}}}, {
-                            'text':{'test':'coltest', 'fill':'next'},
-                            'attrib':{
-                                 'href':{'link':'linktest'},
-                                 'title':{'other':'Link Test'}}})}},
-            'fieldtest':{
-                'sub':({
-                    'text':{'test':'first test', 'run':'template'},
-                    'attrib':{
-                        'href':{'link':'test'},
-                        'title':{'other':'test'}}}, {
-                    'text':{'test':'link test', 'run':'other template'},
-                    'attrib':{
-                         'href':{'link':'linktest'},
-                         'title':{'other':'Link Test'}}})}}
-        self.assertEqual(final, self.subcombotest.pipe())
+            'grouptest': {
+                'groupfield1': {
+                    'sub': ({
+                        'text': {'one': 'first test', 'num': 'first'},
+                        'attrib': {
+                            'align': 'left',
+                            'title': {'one': 'column', 'num': 'first'}}}, {
+                        'text': 'This second test is the second column.',
+                        'attrib': {
+                            'align': 'right',
+                            'title': {'one': 'col', 'num': 'second'}}})},
+                    'groupfield2': {
+                        'sub': ({
+                            'text': 'This test is first.',
+                            'attrib': {
+                                'align': 'left',
+                                'title': {'one': 'test'}}}, {
+                            'text': {'test': 'coltest', 'fill': 'next'},
+                            'attrib': {
+                                 'href': {'link': 'linktest'},
+                                 'title': {'other': 'Link Test'}}})}},
+            'fieldtest': {
+                'sub': ({
+                    'text': {'test': 'first test', 'run': 'template'},
+                    'attrib': {
+                        'href': {'link': 'test'},
+                        'title': {'other': 'test'}}}, {
+                    'text': {'test': 'link test', 'run': 'other template'},
+                    'attrib': {
+                         'href': {'link': 'linktest'},
+                         'title': {'other': 'Link Test'}}})}}
+        self.assertEqual(
+        '<body><a id="fieldtest" href="caliban.html#test" '
+        'title="This link goes to test">This template is a first test.</a><a '
+        'id="fieldtest" href="caliban.html#linktest" title="This link goes to '
+        'Link Test">This other template is a link test.</a><tr '
+        'class="grouptest"><td id="groupfield1" align="left" title="This '
+        'column is column first">This first test is the first column.</td>'
+        '<td id="groupfield1" align="right" title="This col is column '
+        'second">This second test is the second column.</td><td '
+        'id="groupfield2" align="left" title="This test is next.">This test '
+        'is first.</td><td id="groupfield2">This coltest is a next.</td></tr>'
+        '</body>', self.subcombotest.pipe()
+        )
 
     def test_ltemplates_mixin(self):
         '''Tests batch addition of templates to a root Template.'''
-        final = '<body><a id="fieldtest" href="atest"/><tr class="grouptest">'\
-        '<td id="groupfield1" align="left" title="This column is column '\
-        'first">one</td><td id="groupfield1" align="right" title="This col '\
-        'is column second">This second test is the second column.</td><td '\
-        'id="groupfield2">This test is first.</td><td id="groupfield2">This '\
-        'coltest is a next.</td></tr></body>'
         self.subcombotest.grouptest.templates({
-            'groupfield1':{
-                'attrib':{'title':'This %(one)s is column %(num)s'}},
-            'groupfield2':{
-                'text':'This $test is a $fill.'}})
+            'groupfield1': {
+                'attrib': {'title': 'This %(one)s is column %(num)s'}},
+            'groupfield2': {
+                'text': 'This $test is a $fill.'}})
         self.subcombotest.grouptest %= {
-                'groupfield1':{
-                    'sub':({
-                        'text':'one',
-                        'attrib':{
-                            'align':'left',
-                            'title':{'one':'column', 'num':'first'}}}, {
-                        'text':'This second test is the second column.',
-                        'attrib':{
-                            'align':'right',
-                            'title':{'one':'col', 'num':'second'}}})},
-                'groupfield2':{
-                    'sub':({
-                        'text':'This test is first.'}, {
-                        'text':{'test':'coltest', 'fill':'next'}})}}
-        self.assertEqual(final, self.subcombotest.pipe())
+                'groupfield1': {
+                    'sub': ({
+                        'text': 'one',
+                        'attrib': {
+                            'align': 'left',
+                            'title': {'one': 'column', 'num': 'first'}}}, {
+                        'text': 'This second test is the second column.',
+                        'attrib': {
+                            'align': 'right',
+                            'title': {'one': 'col', 'num': 'second'}}})},
+                'groupfield2': {
+                    'sub': ({
+                        'text': 'This test is first.'}, {
+                        'text': {'test': 'coltest', 'fill': 'next'}})}}
+        self.assertEqual(
+            '<body><a id="fieldtest" href="atest"/><tr class="grouptest">'
+        '<td id="groupfield1" align="left" title="This column is column '
+        'first">one</td><td id="groupfield1" align="right" title="This col '
+        'is column second">This second test is the second column.</td><td '
+        'id="groupfield2">This test is first.</td><td id="groupfield2">This '
+        'coltest is a next.</td></tr></body>',
+        self.subcombotest.pipe()
+        )
 
     def test_ltemplates_toomany(self):
         '''Raises TypeError if too many templates.'''
         def tempfunc():
             '''Stub'''
             self.subcombotest.grouptest.templates({
-                'groupfield1':{
-                    'attrib':{'title':'This %(one)s is column %(num)s'}},
-                'groupfield2':{
-                    'text':'This $test is a $fill.'},
-                'groupfield3':{
-                    'text':'This $test is a $fill.'}})
+                'groupfield1': {
+                    'attrib': {'title': 'This %(one)s is column %(num)s'}},
+                'groupfield2': {
+                    'text': 'This $test is a $fill.'},
+                'groupfield3': {
+                    'text': 'This $test is a $fill.'}})
         self.assertRaises(TypeError, tempfunc)
 
     def test_ltemplates_wrongtype(self):
 
     def test_ltext_wrongtype(self):
         '''Raises a TypeError if wrong type passed to text.'''
-        def tempfunc(): self.gentemplate.content.text = [{'place':'test'}]
+        def tempfunc():
+            self.gentemplate.content.text = [{'place':'test'}]
         self.assertRaises(TypeError, tempfunc)
 
     def test_ltemplate_from_src_string_template(self):
         '''Tests a template passed in with markup with the Template source.'''
         final = '<body><p id="stuff">This run is a test.</p></body>'
         ast = Template('<body><p id="stuff">This $tst1 is a $tst2</p></body>')
-        ast.stuff.text = {'tst1':'run', 'tst2':'test.'}
+        ast.stuff.text = {'tst1': 'run', 'tst2': 'test.'}
         self.assertEqual(final, ast.render())
 
     def test_ltemplate_from_src_interpolation(self):
     def test_lhtmltemplate_output_xhtml10(self):
         '''Tests for correct XHTML 1.0 output.'''
         self.htmlt %= ('Test Page', 'Test Content')
-        self.assertEqual('<?xml version="1.0" encoding="utf-8"?>\n<?xml-stylesheet '\
-        'href="test.css" type="text/css" ?>\n<!DOCTYPE html PUBLIC '\
-        '"-//W3C//DTD XHTML 1.0 Strict//EN" '\
-        '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html>'\
-        '<head><link href="test.css" type="text/css"/><title id="title">'\
-        'Test Page</title></head><body><p id="content">Test Content</p></body></html>', self.htmlt.pipe(None, 'xhtml10'))
+        self.assertEqual(
+            '<?xml version="1.0" encoding="utf-8"?>\n<?xml-stylesheet '
+        'href="test.css" type="text/css" ?>\n<!DOCTYPE html PUBLIC '
+        '"-//W3C//DTD XHTML 1.0 Strict//EN" '
+        '"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">\n<html>'
+        '<head><link href="test.css" type="text/css"/><title id="title">'
+        'Test Page</title></head><body><p id="content">Test Content</p>'
+        '</body></html>',
+        self.htmlt.pipe(None, 'xhtml10'))
 
     def test_lhtmltemplate_output_xhtml11(self):
         '''Tests for correct XHTML 1.1 output.'''
         self.htmlt %= ('Test Page', 'Test Content')
-        self.assertEqual('<?xml version="1.0" encoding="utf-8"?>\n<?xml-stylesheet ' \
-        'href="test.css" type="text/css" ?>\n<!DOCTYPE html PUBLIC '\
-        '"-//W3C//DTD XHTML 1.1//EN" '\
-        '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n<html><head><link '\
-        'href="test.css" type="text/css"/><title id="title">Test Page</title>'\
+        self.assertEqual(
+            '<?xml version="1.0" encoding="utf-8"?>\n<?xml-stylesheet '
+        'href="test.css" type="text/css" ?>\n<!DOCTYPE html PUBLIC '
+        '"-//W3C//DTD XHTML 1.1//EN" '
+        '"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">\n<html><head><link '
+        'href="test.css" type="text/css"/><title id="title">Test Page</title>'
         '</head><body><p id="content">Test Content</p></body></html>',
         self.htmlt.pipe(None, 'xhtml11'))
 

webstring/text.py

 
         @param info Data to substitute into a template (default: None)
         @param format Text format (default: 'text')
-        @param encoding Encoding of eturn string (default: 'utf-8')
+        @param encoding Encoding of return string (default: 'utf-8')
         '''
         if info is not None:
             self.__imod__(info)
         @param omax Maximum number of times a field can repeat (default: 25)
         '''
         super(_XMLOne, self).__init__(auto, omax, **kw)
+        self._group = _XMLGroup
         # Parent and inline text template
         self._parent, self._template = parent, kw.get('template')
         # Attribute templates
         '''
         return iter(self._attrib)
 
-    # Template variable delimiter attribute name
-    mark = property(lambda self: self._mark, _Field._setmark, _delmark)
-    # Internal element text
-    text = property(lambda self: self._tree.text, _settext, _deltext)
-    # Internal element text template
-    template = property(lambda self: self._template, _settemplate)
-
     def _delmark(self):
         # Removes variable delimiter attribute from output.
         self.__delitem__(self.mark)
         else:
             raise TypeError('invalid attribute source')
 
+    # Template variable delimiter attribute name
+    mark = property(lambda self: self._mark, _Field._setmark, _delmark)
+    # Internal element text
+    text = property(lambda self: self._tree.text, _settext, _deltext)
+    # Internal element text template
+    template = property(lambda self: self._template, _settemplate)
+
 
 class _Attribute(object):
 
 
     '''Dispatcher class for XML template fields.'''
 
+    _group, _klass = None, _XMLOne
+
     def __new__(cls, *arg, **kw):
         '''Dispatcher method for XML fields.'''
         c = cls._klass
 
     '''Class for XML group Templates.'''
 
+    _field = _XMLField
+
     def __init__(self, src=None, parent=None, auto=True, omax=25, **kw):
         '''
         Initialization method for a group Template
         self._templates = kw.get('templates')
         if self._templates is not None:
             self.templates(self._templates)
+        self._group = self.__class__
 
     def _delgmark(self):
         # Removes group mark attribute from output.
             if hasattr(field, 'groupmark'):
                 field.groupmark = mark
 
-    # Create property that returns the current Template state
-    current = property(lambda self: Template(_copytree(self._tree),
-        self._auto, self._max, templates=self._templates))
-    # Create property that returns the default Template state
-    default = property(lambda self: Template(_copytree(self._btree),
-        self._auto, self._max, templates=self._templates))
-    # XSLT property
-    xslt = property(lambda self: self._xslt, _setxslt)
-
-    # Template variable attribute name
-    mark = property(
-        lambda self: self._mark, _Field._setmark, _XMLMany._delmark
-    )
-    # Group delimiter attribute name
-    groupmark = property(
-        lambda self: self._groupmark, _Template._setgmark, _XMLMany._delgmark
-    )
-
     def _setxslt(self, stylesheet):
         '''
         Sets the XSLT stylesheet for a template.
             self._btree, self._auto, self._max, templates=self._templates
         )
 
+    # Create property that returns the current Template state
+    current = property(lambda self: Template(_copytree(self._tree),
+        self._auto, self._max, templates=self._templates))
+    # Create property that returns the default Template state
+    default = property(lambda self: Template(_copytree(self._btree),
+        self._auto, self._max, templates=self._templates))
+    # XSLT property
+    xslt = property(lambda self: self._xslt, _setxslt)
+
+    # Template variable attribute name
+    mark = property(
+        lambda self: self._mark, _Field._setmark, _XMLMany._delmark
+    )
+    # Group delimiter attribute name
+    groupmark = property(
+        lambda self: self._groupmark, _Template._setgmark, _XMLMany._delgmark
+    )
+
 
 class HTMLTemplate(Template):
 
     '''Template class for HTML documents.'''
 
+    def fromfile(self, path):
+        '''Creates an internal element from a file source.
+
+        @param path Path to a template source
+        '''
+        # Try ordinary XML parsing
+        try:
+            super(HTMLTemplate, self).fromfile(path)
+        # Feed through the HTML parser to handle broken HTML
+        except:
+            parser = HTMLParser()
+            self._setelement(parse(path), parser)
+
+    def fromstring(self, instring):
+        '''Creates an internal element from a string source.
+
+        @param path String source for an internal template
+        '''
+        # Try parsing the string as straight XML
+        try:
+            super(HTMLTemplate, self).fromstring(instring)
+        # Feed through the HTML parser to handle broken HTML
+        except:
+            self._setelement(HTML(instring))
+
     def pipe(self, info=None, format='html'):
         '''
         Returns a string version of the internal element's parent and
         @param format Format of document (default: 'html')
         '''
         super(HTMLTemplate, self).write(path, info, format)
-
-    def fromfile(self, path):
-        '''Creates an internal element from a file source.
-
-        @param path Path to a template source
-        '''
-        # Try ordinary XML parsing
-        try:
-            super(HTMLTemplate, self).fromfile(path)
-        # Feed through the HTML parser to handle broken HTML
-        except:
-            parser = HTMLParser()
-            self._setelement(parse(path), parser)
-
-    def fromstring(self, instring):
-        '''Creates an internal element from a string source.
-
-        @param path String source for an internal template
-        '''
-        # Try parsing the string as straight XML
-        try:
-            super(HTMLTemplate, self).fromstring(instring)
-        # Feed through the HTML parser to handle broken HTML
-        except:
-            self._setelement(HTML(instring))