[Zope3-checkins] SVN: Zope3/trunk/ Fixed issue 333: XML Tree
doesn't load if some item contains
Dmitry Vasiliev
dima at hlabs.spb.ru
Wed May 4 09:24:21 EDT 2005
Log message for revision 30238:
Fixed issue 333: XML Tree doesn't load if some item contains
non-ASCII characters
Changed:
U Zope3/trunk/doc/CHANGES.txt
U Zope3/trunk/src/zope/app/component/testing.py
U Zope3/trunk/src/zope/app/rotterdam/tests/output/test1.xml
U Zope3/trunk/src/zope/app/rotterdam/tests/output/test4.xml
U Zope3/trunk/src/zope/app/rotterdam/tests/output/test5.xml
U Zope3/trunk/src/zope/app/rotterdam/tests/test_xmlnavigationviews.py
U Zope3/trunk/src/zope/app/rotterdam/tests/util.py
U Zope3/trunk/src/zope/app/rotterdam/xmlobject.py
U Zope3/trunk/src/zope/app/testing/setup.py
-=-
Modified: Zope3/trunk/doc/CHANGES.txt
===================================================================
--- Zope3/trunk/doc/CHANGES.txt 2005-05-04 11:50:10 UTC (rev 30237)
+++ Zope3/trunk/doc/CHANGES.txt 2005-05-04 13:24:21 UTC (rev 30238)
@@ -591,6 +591,9 @@
Bug Fixes
+ - Fixed issue #333: XML Tree doesn't load if some item
+ contains non-ASCII characters
+
- Fixed issue #301: Bug with i18n:name and i18n:translate
on the same element
Modified: Zope3/trunk/src/zope/app/component/testing.py
===================================================================
--- Zope3/trunk/src/zope/app/component/testing.py 2005-05-04 11:50:10 UTC (rev 30237)
+++ Zope3/trunk/src/zope/app/component/testing.py 2005-05-04 13:24:21 UTC (rev 30238)
@@ -44,19 +44,34 @@
class PlacefulSetup(PlacelessSetup):
# Places :)
- rootFolder = Place('')
+ rootFolder = Place(u'')
- folder1 = Place('folder1')
- folder1_1 = Place('folder1/folder1_1')
- folder1_1_1 = Place('folder1/folder1_1/folder1_1_1')
- folder1_1_2 = Place('folder1/folder1_2/folder1_1_2')
- folder1_2 = Place('folder1/folder1_2')
- folder1_2_1 = Place('folder1/folder1_2/folder1_2_1')
+ folder1 = Place(u'folder1')
+ folder1_1 = Place(u'folder1/folder1_1')
+ folder1_1_1 = Place(u'folder1/folder1_1/folder1_1_1')
+ folder1_1_2 = Place(u'folder1/folder1_2/folder1_1_2')
+ folder1_2 = Place(u'folder1/folder1_2')
+ folder1_2_1 = Place(u'folder1/folder1_2/folder1_2_1')
- folder2 = Place('folder2')
- folder2_1 = Place('folder2/folder2_1')
- folder2_1_1 = Place('folder2/folder2_1/folder2_1_1')
+ folder2 = Place(u'folder2')
+ folder2_1 = Place(u'folder2/folder2_1')
+ folder2_1_1 = Place(u'folder2/folder2_1/folder2_1_1')
+ folder3 = Place(u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER A}"
+ u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER KA}"
+ u"\N{CYRILLIC SMALL LETTER A}3")
+ folder3_1 = Place(u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER A}"
+ u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER KA}"
+ u"\N{CYRILLIC SMALL LETTER A}3/"
+ u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER A}"
+ u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER KA}"
+ u"\N{CYRILLIC SMALL LETTER A}3_1")
def setUp(self, folders=False, site=False):
setup.placefulSetUp()
Modified: Zope3/trunk/src/zope/app/rotterdam/tests/output/test1.xml
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/tests/output/test1.xml 2005-05-04 11:50:10 UTC (rev 30237)
+++ Zope3/trunk/src/zope/app/rotterdam/tests/output/test1.xml 2005-05-04 13:24:21 UTC (rev 30238)
@@ -1 +1 @@
-<?xml version="1.0" ?><children><collection name="[top]" baseURL="http://127.0.0.1/" length="2" icon_url="" isroot=""><collection name="folder1" length="2" icon_url=""></collection><collection name="folder2" length="1" icon_url=""/><collection name="++etc++site" length="1" icon_url=""/></collection></children>
+<?xml version="1.0" ?><children><collection name="[top]" baseURL="http://127.0.0.1/" length="3" icon_url="" isroot=""><collection name="folder1" length="2" icon_url=""></collection><collection name="folder2" length="1" icon_url=""/><collection name="папка3" length="1" icon_url=""/><collection name="++etc++site" length="1" icon_url=""/></collection></children>
Modified: Zope3/trunk/src/zope/app/rotterdam/tests/output/test4.xml
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/tests/output/test4.xml 2005-05-04 11:50:10 UTC (rev 30237)
+++ Zope3/trunk/src/zope/app/rotterdam/tests/output/test4.xml 2005-05-04 13:24:21 UTC (rev 30238)
@@ -1 +1 @@
-<?xml version="1.0" ?><children><collection name="folder1" length="2" icon_url=""/><collection name="folder2" length="1" icon_url=""/><collection name="++etc++site" length="1" icon_url=""/></children>
+<?xml version="1.0" ?><children><collection name="folder1" length="2" icon_url=""/><collection name="folder2" length="1" icon_url=""/><collection name="папка3" length="1" icon_url=""/><collection name="++etc++site" length="1" icon_url=""/></children>
Modified: Zope3/trunk/src/zope/app/rotterdam/tests/output/test5.xml
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/tests/output/test5.xml 2005-05-04 11:50:10 UTC (rev 30237)
+++ Zope3/trunk/src/zope/app/rotterdam/tests/output/test5.xml 2005-05-04 13:24:21 UTC (rev 30238)
@@ -1 +1 @@
-<?xml version="1.0" ?><children><collection name="[top]" baseURL="http://127.0.0.1/" length="2" icon_url="" isroot=""><collection name="folder1" length="2" icon_url=""><collection name="folder1_1" length="2" icon_url=""><collection name="folder1_1_1" length="1" icon_url=""></collection><collection name="folder1_1_2" length="0" icon_url=""/><item name="++etc++site" icon_url="" /></collection><collection name="folder1_2" length="1" icon_url=""/><item name="++etc++site" icon_url="" /></collection><collection name="folder2" length="1" icon_url=""/><collection name="++etc++site" length="1" icon_url=""/></collection></children>
+<?xml version="1.0" ?><children><collection name="[top]" baseURL="http://127.0.0.1/" length="3" icon_url="" isroot=""><collection name="folder1" length="2" icon_url=""><collection name="folder1_1" length="2" icon_url=""><collection name="folder1_1_1" length="1" icon_url=""></collection><collection name="folder1_1_2" length="0" icon_url=""/><item name="++etc++site" icon_url="" /></collection><collection name="folder1_2" length="1" icon_url=""/><item name="++etc++site" icon_url="" /></collection><collection name="folder2" length="1" icon_url=""/><collection name="папка3" length="1" icon_url=""/><collection name="++etc++site" length="1" icon_url=""/></collection></children>
Modified: Zope3/trunk/src/zope/app/rotterdam/tests/test_xmlnavigationviews.py
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/tests/test_xmlnavigationviews.py 2005-05-04 11:50:10 UTC (rev 30237)
+++ Zope3/trunk/src/zope/app/rotterdam/tests/test_xmlnavigationviews.py 2005-05-04 13:24:21 UTC (rev 30238)
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
@@ -40,7 +41,7 @@
pass
class TestXmlObject(PlacefulSetup, TestCase):
-
+
def setUp(self):
PlacefulSetup.setUp(self, site=True)
@@ -54,7 +55,7 @@
treeView = rcxov(self.folder1_1_1, TestRequest()).children
check_xml(treeView(), util.read_output('test3.xml'))
-
+
treeView = rcxov(self.rootFolder, TestRequest()).children
check_xml(treeView(), util.read_output('test4.xml'))
@@ -71,7 +72,7 @@
raise NotFound(self, name, request)
def __call__(self):
return self.singleBranchTree()
-
+
ztapi.browserView(IReadContainer, 'singleBranchTree.xml',
ReadContainerView)
@@ -89,7 +90,7 @@
sm = LocalSiteManager(folder1)
subsite.setSiteManager(sm)
folder1['subsite'] = subsite
-
+
# add some more folder to the subsite
subfolder1 = Folder()
subsite['subfolder1'] = subfolder1
@@ -97,7 +98,7 @@
subfolder2_1 = Folder()
subfolder2['subfolder2_1'] = subfolder2_1
subsite['subfolder2'] = subfolder2
-
+
# set the virtualhost on the request
request = TestRequest()
request._vh_root = subsite
@@ -109,11 +110,11 @@
rcxov = ReadContainerXmlObjectView
treeView = rcxov(subsite, request).singleBranchTree
check_xml(treeView(), util.read_output('test6.xml'))
-
+
rcxov = ReadContainerXmlObjectView
treeView = rcxov(subfolder1, request).singleBranchTree
check_xml(treeView(), util.read_output('test7.xml'))
-
+
rcxov = ReadContainerXmlObjectView
treeView = rcxov(subfolder2_1, request).singleBranchTree
check_xml(treeView(), util.read_output('test8.xml'))
Modified: Zope3/trunk/src/zope/app/rotterdam/tests/util.py
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/tests/util.py 2005-05-04 11:50:10 UTC (rev 30237)
+++ Zope3/trunk/src/zope/app/rotterdam/tests/util.py 2005-05-04 13:24:21 UTC (rev 30238)
@@ -24,8 +24,8 @@
def read_input(filename):
filename = os.path.join(input_dir, filename)
- return open(filename, 'r').read()
+ return open(filename, 'r').read().decode("utf-8")
def read_output(filename):
filename = os.path.join(output_dir, filename)
- return open(filename, 'r').read()
+ return open(filename, 'r').read().decode("utf-8")
Modified: Zope3/trunk/src/zope/app/rotterdam/xmlobject.py
===================================================================
--- Zope3/trunk/src/zope/app/rotterdam/xmlobject.py 2005-05-04 11:50:10 UTC (rev 30237)
+++ Zope3/trunk/src/zope/app/rotterdam/xmlobject.py 2005-05-04 13:24:21 UTC (rev 30238)
@@ -21,28 +21,32 @@
from zope.interface import Interface
from zope.proxy import sameProxiedObjects
from zope.security.interfaces import Unauthorized, Forbidden
+from zope.i18n import translate
from zope.app import zapi
from zope.app.publisher.browser import BrowserView
from zope.app.container.interfaces import IReadContainer
from zope.app.traversing.api import getParents, getParent, traverse
+from zope.app.i18n import ZopeMessageIDFactory as _
+
def setNoCacheHeaders(response):
"""Ensure that the tree isn't cached"""
response.setHeader('Pragma', 'no-cache')
response.setHeader('Cache-Control', 'no-cache')
- response.setHeader('Expires', formatdate(time.time()-7*86400))#7 days ago
+ response.setHeader('Expires',
+ formatdate(time.time() - 7 * 86400)) # 7 days ago
def xmlEscape(format, *args):
- quotedArgs = [ quoteattr(str(arg)) for arg in args ]
- return format%tuple(quotedArgs)
-
+ quotedArgs = [quoteattr(unicode(arg)) for arg in args]
+ return format % tuple(quotedArgs)
+
def xmlEscapeWithCData(format, *args):
cData = args[-1]
- quotedArgs = [ quoteattr(str(arg)) for arg in args[:-1] ]
+ quotedArgs = [quoteattr(unicode(arg)) for arg in args[:-1]]
quotedArgsWithCData = quotedArgs + [cData]
- return format%tuple(quotedArgsWithCData)
+ return format % tuple(quotedArgsWithCData)
def getParentsFromContextToObject(context, obj):
"""Returns a list starting with the given context's parent followed by
@@ -62,7 +66,7 @@
break
if w is None:
break
-
+
parents.append(w)
return parents
@@ -97,7 +101,7 @@
keys = list(container.keys())
# include the site manager
- keys.append('++etc++site')
+ keys.append(u'++etc++site')
for name in keys:
@@ -110,14 +114,14 @@
item_len = self.getLengthOf(item)
if item_len >= 0:
result.append(xmlEscape(
- '<collection name=%s length=%s icon_url=%s/>',
+ u'<collection name=%s length=%s icon_url=%s/>',
name, item_len, iconUrl))
else:
result.append(xmlEscape(
- '<item name=%s icon_url=%s/>',
+ u'<item name=%s icon_url=%s/>',
name, iconUrl))
- return ' '.join(result)
+ return u' '.join(result)
def children(self):
@@ -139,7 +143,7 @@
"""
result = ''
oldItem = self.context
-
+
vh = self.request.getVirtualHostRoot()
if vh:
vhrootView = zapi.getMultiAdapter(
@@ -150,13 +154,15 @@
except:
# we got the containment root itself as the virtual host
# and there is no name.
- rootName = '[top]'
+ rootName = _('[top]')
parents = getParentsFromContextToObject(self.context, vh)
else:
- rootName = '[top]'
- baseURL = self.request.getApplicationURL()+'/'
+ rootName = _('[top]')
+ baseURL = self.request.getApplicationURL() + '/'
parents = getParents(self.context)
-
+
+ rootName = translate(rootName, context=self.request, default=rootName)
+
for item in parents:
# skip skin if present
#if item == oldItem:
@@ -168,7 +174,7 @@
keys = []
# include the site manager
- keys.append('++etc++site')
+ keys.append(u'++etc++site')
for name in keys:
# Only include items we can traverse to
@@ -176,34 +182,35 @@
iconUrl = self.getIconUrl(subItem)
subitem_len = self.getLengthOf(subItem)
if subitem_len >= 0:
- # the test below seems to be browken with the ++etc++site case
+ # the test below seems to be broken
+ # with the ++etc++site case
if subItem == oldItem:
subItems.append(xmlEscapeWithCData(
- '<collection name=%s length=%s '
- 'icon_url=%s>%s</collection>',
+ u'<collection name=%s length=%s '
+ u'icon_url=%s>%s</collection>',
name, subitem_len, iconUrl, result))
else:
subItems.append(xmlEscape(
- '<collection name=%s length=%s '
- 'icon_url=%s/>',
+ u'<collection name=%s length=%s '
+ u'icon_url=%s/>',
name, subitem_len, iconUrl))
else:
subItems.append(xmlEscape(
- '<item name=%s icon_url=%s />', name, iconUrl))
+ u'<item name=%s icon_url=%s />', name, iconUrl))
- result = ' '.join(subItems)
+ result = u' '.join(subItems)
oldItem = item
# do not forget root folder
iconUrl = self.getIconUrl(oldItem)
- result = (xmlEscapeWithCData('<collection name=%s baseURL=%s length=%s '
- 'icon_url=%s isroot="">%s</collection>',
+ result = (xmlEscapeWithCData(
+ u'<collection name=%s baseURL=%s length=%s '
+ u'icon_url=%s isroot="">%s</collection>',
rootName, baseURL, len(oldItem), iconUrl, result))
self.request.response.setHeader('Content-Type', 'text/xml')
setNoCacheHeaders(self.request.response)
- res= u'<?xml version="1.0" ?><children> %s </children>' % result
- return res
+ return u'<?xml version="1.0" ?><children> %s </children>' % result
class XmlObjectView(BrowserView):
"""Provide a xml interface for dynamic navigation tree in UI"""
Modified: Zope3/trunk/src/zope/app/testing/setup.py
===================================================================
--- Zope3/trunk/src/zope/app/testing/setup.py 2005-05-04 11:50:10 UTC (rev 30237)
+++ Zope3/trunk/src/zope/app/testing/setup.py 2005-05-04 13:24:21 UTC (rev 30238)
@@ -156,24 +156,39 @@
def buildSampleFolderTree():
# set up a reasonably complex folder structure
#
- # ____________ rootFolder ____________
- # / \
- # folder1 __________________ folder2
- # | \ |
- # folder1_1 ____ folder1_2 folder2_1
+ # ____________ rootFolder ______________________________
+ # / \ \
+ # folder1 __________________ folder2 folder3
+ # | \ | |
+ # folder1_1 ____ folder1_2 folder2_1 folder3_1
# | \ | |
# folder1_1_1 folder1_1_2 folder1_2_1 folder2_1_1
root = rootFolder()
- root['folder1'] = Folder()
- root['folder1']['folder1_1'] = Folder()
- root['folder1']['folder1_1']['folder1_1_1'] = Folder()
- root['folder1']['folder1_1']['folder1_1_2'] = Folder()
- root['folder1']['folder1_2'] = Folder()
- root['folder1']['folder1_2']['folder1_2_1'] = Folder()
- root['folder2'] = Folder()
- root['folder2']['folder2_1'] = Folder()
- root['folder2']['folder2_1']['folder2_1_1'] = Folder()
+ root[u'folder1'] = Folder()
+ root[u'folder1'][u'folder1_1'] = Folder()
+ root[u'folder1'][u'folder1_1'][u'folder1_1_1'] = Folder()
+ root[u'folder1'][u'folder1_1'][u'folder1_1_2'] = Folder()
+ root[u'folder1'][u'folder1_2'] = Folder()
+ root[u'folder1'][u'folder1_2'][u'folder1_2_1'] = Folder()
+ root[u'folder2'] = Folder()
+ root[u'folder2'][u'folder2_1'] = Folder()
+ root[u'folder2'][u'folder2_1'][u'folder2_1_1'] = Folder()
+ root[u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER A}"
+ u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER KA}"
+ u"\N{CYRILLIC SMALL LETTER A}3"] = Folder()
+ root[u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER A}"
+ u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER KA}"
+ u"\N{CYRILLIC SMALL LETTER A}3"][
+ u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER A}"
+ u"\N{CYRILLIC SMALL LETTER PE}"
+ u"\N{CYRILLIC SMALL LETTER KA}"
+ u"\N{CYRILLIC SMALL LETTER A}3_1"] = Folder()
return root
More information about the Zope3-Checkins
mailing list