[Zope3-checkins] SVN: Zope3/branches/ZopeX3-3.0/src/zope/app/
Improved STX renderer to handle unicode correctly.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Tue Sep 7 09:08:39 EDT 2004
Log message for revision 27465:
Improved STX renderer to handle unicode correctly.
Changed:
U Zope3/branches/ZopeX3-3.0/src/zope/app/apidoc/classmodule/browser.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/apidoc/ifacemodule/browser.py
U Zope3/branches/ZopeX3-3.0/src/zope/app/renderer/stx.py
-=-
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/apidoc/classmodule/browser.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/apidoc/classmodule/browser.py 2004-09-07 13:00:28 UTC (rev 27464)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/apidoc/classmodule/browser.py 2004-09-07 13:08:38 UTC (rev 27465)
@@ -375,7 +375,7 @@
>>> view = getFunctionDetailsView()
>>> view.getDocString()
- '<p>This is the foo function.</p>\n'
+ u'<p>This is the foo function.</p>\n'
"""
return renderText(self.context.getDocString() or '',
zapi.getParent(self.context).getPath())
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/apidoc/ifacemodule/browser.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/apidoc/ifacemodule/browser.py 2004-09-07 13:00:28 UTC (rev 27464)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/apidoc/ifacemodule/browser.py 2004-09-07 13:08:38 UTC (rev 27465)
@@ -311,8 +311,8 @@
>>> attrs = details.getAttributes()
>>> pprint(attrs)
- [[('doc', '<p>This is bar.</p>\n'), ('name', 'bar')],
- [('doc', '<p>This is foo.</p>\n'), ('name', 'foo')]]
+ [[('doc', u'<p>This is bar.</p>\n'), ('name', 'bar')],
+ [('doc', u'<p>This is foo.</p>\n'), ('name', 'foo')]]
"""
# The `Interface` and `Attribute` class have no security declarations,
# so that we are not able to access any API methods on proxied
@@ -339,10 +339,10 @@
>>> methods = details.getMethods()
>>> pprint(methods)
- [[('doc', '<p>This is blah.</p>\n'),
+ [[('doc', u'<p>This is blah.</p>\n'),
('name', 'blah'),
('signature', '()')],
- [('doc', '<p>This is get.</p>\n'),
+ [('doc', u'<p>This is get.</p>\n'),
('name', 'get'),
('signature', '(key, default=None)')]]
"""
@@ -372,7 +372,7 @@
[('name', 'TextLine'),
('path', 'zope/schema/_bootstrapfields/TextLine')]),
('default', "u'Foo'"),
- ('description', '<p>Title</p>\n'),
+ ('description', u'<p>Title</p>\n'),
('iface',
[('id', 'zope.schema.interfaces.ITextLine'),
('name', 'ITextLine')]),
@@ -382,7 +382,7 @@
[('name', 'Text'),
('path', 'zope/schema/_bootstrapfields/Text')]),
('default', "u'Foo.'"),
- ('description', '<p>Desc</p>\n'),
+ ('description', u'<p>Desc</p>\n'),
('iface',
[('id', 'zope.schema.interfaces.IText'), ('name', 'IText')]),
('name', 'description'),
Modified: Zope3/branches/ZopeX3-3.0/src/zope/app/renderer/stx.py
===================================================================
--- Zope3/branches/ZopeX3-3.0/src/zope/app/renderer/stx.py 2004-09-07 13:00:28 UTC (rev 27464)
+++ Zope3/branches/ZopeX3-3.0/src/zope/app/renderer/stx.py 2004-09-07 13:08:38 UTC (rev 27465)
@@ -43,19 +43,26 @@
>>> source = StructuredTextSourceFactory(u'This is source.')
>>> renderer = StructuredTextToHTMLRenderer(source, TestRequest())
>>> renderer.render()
- '<p>This is source.</p>\n'
+ u'<p>This is source.</p>\n'
+ Make sure that unicode works as well.
+
+ >>> source = StructuredTextSourceFactory(u'This is \xc3\x9c.')
+ >>> renderer = StructuredTextToHTMLRenderer(source, TestRequest())
+ >>> renderer.render()
+ u'<p>This is \xc3\x9c.</p>\n'
"""
implements(IHTMLRenderer)
__used_for__ = IStructuredTextSource
def render(self):
"See zope.app.interfaces.renderer.IHTMLRenderer"
- doc = Document()(str(self.context))
+ encoded = self.context.encode('UTF-8')
+ doc = Document()(encoded)
html = HTML()(doc)
# strip html & body added by some zope versions
html = re.sub(
r'(?sm)^<html.*<body.*?>\n(.*)</body>\n</html>\n',r'\1', html)
- return html
+ return html.decode('UTF-8')
More information about the Zope3-Checkins
mailing list