[Zope3-checkins] CVS: Zope3/src/zope/app/dublincore -
xmlmetadata.py:1.2
Fred L. Drake, Jr.
fred at zope.com
Fri Aug 22 10:03:20 EDT 2003
Update of /cvs-repository/Zope3/src/zope/app/dublincore
In directory cvs.zope.org:/tmp/cvs-serv20916
Modified Files:
xmlmetadata.py
Log Message:
- fix some references to data in dcterms
- make sure we properly encode values included in the output
=== Zope3/src/zope/app/dublincore/xmlmetadata.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/dublincore/xmlmetadata.py:1.1 Wed Aug 20 17:25:15 2003
+++ Zope3/src/zope/app/dublincore/xmlmetadata.py Fri Aug 22 09:03:19 2003
@@ -22,7 +22,7 @@
import xml.sax.handler
from cStringIO import StringIO
-from xml.sax.saxutils import quoteattr
+from xml.sax.saxutils import escape, quoteattr
from zope.app.dublincore import dcterms
@@ -48,20 +48,30 @@
if prev != group:
sio.write("\n")
prev = group
- if name in name_to_element:
- element, t = name_to_element[name]
+ if name in dcterms.name_to_element:
+ element, t = dcterms.name_to_element[name]
if not type:
type = t
if type:
type = " xsi:type=" + quoteattr(type)
for value in values:
sio.write(" <%s%s>\n %s\n </%s>\n"
- % (element, type, value, element))
+ % (element, type, _encode_string(value), element))
else:
raise RuntimeError("could not serialize %r metadata element"
% name)
sio.write("</metadata>\n")
return sio.getvalue()
+
+try:
+ unicode
+except NameError:
+ _encode_string = escape
+else:
+ def _encode_string(s):
+ if isinstance(s, unicode):
+ s = s.encode('utf-8')
+ return escape(s)
def parse(source, error_handler=None):
More information about the Zope3-Checkins
mailing list