[Checkins] SVN: zmi.core/trunk/s Copy browser code from zope.app.dtmlpage.
Yusei Tahara
yusei at domen.cx
Sat Nov 21 03:55:07 EST 2009
Log message for revision 105942:
Copy browser code from zope.app.dtmlpage.
Changed:
U zmi.core/trunk/setup.py
U zmi.core/trunk/src/zmi/core/configure.zcml
A zmi.core/trunk/src/zmi/core/dtmlpage/
A zmi.core/trunk/src/zmi/core/dtmlpage/__init__.py
A zmi.core/trunk/src/zmi/core/dtmlpage/browser.py
A zmi.core/trunk/src/zmi/core/dtmlpage/configure.zcml
A zmi.core/trunk/src/zmi/core/dtmlpage/tests/
A zmi.core/trunk/src/zmi/core/dtmlpage/tests/__init__.py
A zmi.core/trunk/src/zmi/core/dtmlpage/tests/test_dtmlpage.py
A zmi.core/trunk/src/zmi/core/dtmlpage/tests/test_functional.py
A zmi.core/trunk/src/zmi/core/dtmlpage/url.txt
-=-
Modified: zmi.core/trunk/setup.py
===================================================================
--- zmi.core/trunk/setup.py 2009-11-21 08:42:11 UTC (rev 105941)
+++ zmi.core/trunk/setup.py 2009-11-21 08:55:06 UTC (rev 105942)
@@ -55,6 +55,7 @@
'zope.app.catalog',
'zope.app.component',
'zope.app.container',
+ 'zope.app.dtmlpage',
'zope.app.error',
'zope.app.exception',
'zope.app.file',
Modified: zmi.core/trunk/src/zmi/core/configure.zcml
===================================================================
--- zmi.core/trunk/src/zmi/core/configure.zcml 2009-11-21 08:42:11 UTC (rev 105941)
+++ zmi.core/trunk/src/zmi/core/configure.zcml 2009-11-21 08:55:06 UTC (rev 105942)
@@ -6,6 +6,7 @@
<include package=".catalog" />
<include package=".component" />
<include package=".container" />
+ <include package=".dtmlpage" />
<include package=".error" />
<include package=".exception" />
<include package=".file" />
Added: zmi.core/trunk/src/zmi/core/dtmlpage/browser.py
===================================================================
--- zmi.core/trunk/src/zmi/core/dtmlpage/browser.py (rev 0)
+++ zmi.core/trunk/src/zmi/core/dtmlpage/browser.py 2009-11-21 08:55:06 UTC (rev 105942)
@@ -0,0 +1,26 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Define view component for ZPT page eval results.
+
+$Id: browser.py 26731 2004-07-23 21:27:21Z pruggera $
+"""
+__docformat__ = 'restructuredtext'
+
+class DTMLPageEval(object):
+
+ def index(self, REQUEST=None, **kw):
+ """Call a Page Template"""
+
+ template = self.context
+ return template.render(REQUEST, **kw)
Added: zmi.core/trunk/src/zmi/core/dtmlpage/configure.zcml
===================================================================
--- zmi.core/trunk/src/zmi/core/dtmlpage/configure.zcml (rev 0)
+++ zmi.core/trunk/src/zmi/core/dtmlpage/configure.zcml 2009-11-21 08:55:06 UTC (rev 105942)
@@ -0,0 +1,58 @@
+<configure
+ xmlns='http://namespaces.zope.org/zope'
+ xmlns:browser='http://namespaces.zope.org/browser'
+ i18n_domain='zope'
+ >
+
+ <browser:page
+ name="index.html"
+ for="zope.app.dtmlpage.interfaces.IDTMLPage"
+ permission="zope.View"
+ class="zmi.core.dtmlpage.browser.DTMLPageEval"
+ attribute="index"
+ />
+
+ <browser:editform
+ schema="zope.app.dtmlpage.interfaces.IDTMLPage"
+ name="edit.html"
+ menu="zmi_views"
+ label="Edit a DTML page"
+ permission="zope.ManageContent"
+ />
+
+ <browser:icon
+ name="zmi_icon"
+ for="zope.app.dtmlpage.interfaces.IDTMLPage"
+ file="dtml.gif"
+ />
+
+ <browser:addform
+ schema="zope.app.dtmlpage.interfaces.IDTMLPage"
+ label="Add a DTML Page"
+ content_factory="zope.app.dtmlpage.dtmlpage.DTMLPage"
+ name="zope.app.dtmlpage.DTMLPage"
+ permission="zope.ManageContent"
+ />
+
+ <browser:addMenuItem
+ class="zope.app.dtmlpage.dtmlpage.DTMLPage"
+ title="DTML Page"
+ description="A simple, content-based DTML page"
+ view="zope.app.dtmlpage.DTMLPage"
+ permission="zope.ManageContent"
+ />
+
+
+ <!-- Preview view - requires zope.app.preview -->
+
+ <configure package="zope.app.preview">
+ <browser:page
+ for="zope.app.dtmlpage.interfaces.IDTMLPage"
+ name="preview.html"
+ template="preview.pt"
+ permission="zope.ManageContent"
+ menu="zmi_views" title="Preview"
+ />
+ </configure>
+
+</configure>
Added: zmi.core/trunk/src/zmi/core/dtmlpage/tests/test_dtmlpage.py
===================================================================
--- zmi.core/trunk/src/zmi/core/dtmlpage/tests/test_dtmlpage.py (rev 0)
+++ zmi.core/trunk/src/zmi/core/dtmlpage/tests/test_dtmlpage.py 2009-11-21 08:55:06 UTC (rev 105942)
@@ -0,0 +1,77 @@
+##############################################################################
+#
+# Copyright (c) 2001, 2002 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Basic tests for Page Templates used in content-space.
+
+$Id: test_dtmlpage.py 95502 2009-01-29 18:58:08Z brandon_rhodes $
+"""
+import unittest
+
+from zope.security.checker import NamesChecker, defineChecker
+from zope.traversing.adapters import Traverser, DefaultTraversable
+from zope.traversing.interfaces import ITraverser, ITraversable
+
+from zope.app.testing.placelesssetup import PlacelessSetup
+from zope.app.testing import ztapi
+from zope.container.contained import contained
+from zope.app.dtmlpage.dtmlpage import DTMLPage
+
+
+class Data(object):
+
+ def __init__(self, **kw):
+ self.__dict__.update(kw)
+
+ def __getitem__(self, name):
+ return getattr(self, name)
+
+
+class DTMLPageTests(PlacelessSetup, unittest.TestCase):
+
+ def setUp(self):
+ super(DTMLPageTests, self).setUp()
+ ztapi.provideAdapter(None, ITraverser, Traverser)
+ ztapi.provideAdapter(None, ITraversable, DefaultTraversable)
+ defineChecker(Data, NamesChecker(['URL', 'name', '__getitem__']))
+
+ def test(self):
+ page = DTMLPage()
+ page.setSource(
+ u'<html>'
+ u'<head><title><dtml-var title></title></head>'
+ u'<body>'
+ u'<a href="<dtml-var "REQUEST.URL[\'1\']">">'
+ u'<dtml-var name>'
+ u'</a></body></html>'
+ )
+
+ page = contained(page, Data(name=u'zope'))
+
+ out = page.render(Data(URL={u'1': u'http://foo.com/'}),
+ title=u"Zope rules")
+ out = ' '.join(out.split())
+
+
+ self.assertEqual(
+ out,
+ u'<html><head><title>Zope rules</title></head><body>'
+ u'<a href="http://foo.com/">'
+ u'zope'
+ u'</a></body></html>'
+ )
+
+def test_suite():
+ return unittest.makeSuite(DTMLPageTests)
+
+if __name__=='__main__':
+ unittest.TextTestRunner().run(test_suite())
Added: zmi.core/trunk/src/zmi/core/dtmlpage/tests/test_functional.py
===================================================================
--- zmi.core/trunk/src/zmi/core/dtmlpage/tests/test_functional.py (rev 0)
+++ zmi.core/trunk/src/zmi/core/dtmlpage/tests/test_functional.py 2009-11-21 08:55:06 UTC (rev 105942)
@@ -0,0 +1,136 @@
+##############################################################################
+#
+# Copyright (c) 2003, 2004 Zope Corporation and Contributors.
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL). A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+##############################################################################
+"""Functional tests for DTML Page.
+
+$Id: test_functional.py 81021 2007-10-24 03:20:07Z srichter $
+"""
+
+import re
+import unittest
+from zope.testing import renormalizing
+from zope.app.testing.functional import BrowserTestCase
+from zope.app.dtmlpage.dtmlpage import DTMLPage
+from zope.app.dtmlpage.testing import DTMLPageLayer
+from zope.app.testing import functional
+from xml.sax.saxutils import escape
+
+
+class DTMLPageTest(BrowserTestCase):
+
+ content = u'<html><body><dtml-var "REQUEST.URL[1]"></body></html>'
+
+ def addDTMLPage(self):
+ dtmlpage = DTMLPage(self.content)
+ root = self.getRootFolder()
+ root['dtmlpage'] = dtmlpage
+ self.commit()
+
+ def testAddForm(self):
+ response = self.publish(
+ '/+/zope.app.dtmlpage.DTMLPage=',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Add a DTML Page' in body)
+ self.assert_('Source' in body)
+ self.assert_('Object Name' in body)
+ self.assert_('"Add"' in body)
+ self.checkForBrokenLinks(body, '/+/zope.app.dtmlpage.DTMLPage=',
+ 'mgr:mgrpw')
+
+ def testAdd(self):
+ response = self.publish(
+ '/+/zope.app.dtmlpage.DTMLPage=',
+ form={'type_name': u'zope.app.dtmlpage.DTMLPage',
+ 'field.source': u'<h1>A DTML Page</h1>',
+ 'add_input_name': u'dtmlpage',
+ 'UPDATE_SUBMIT': u'Add'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 302)
+ self.assertEqual(response.getHeader('Location'),
+ 'http://localhost/@@contents.html')
+ root = self.getRootFolder()
+ self.assert_('dtmlpage' in root)
+ dtmlpage = root['dtmlpage']
+ self.assertEqual(dtmlpage.source, '<h1>A DTML Page</h1>')
+
+ def testEditForm(self):
+ self.addDTMLPage()
+ response = self.publish(
+ '/dtmlpage/@@edit.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Edit a DTML page' in body)
+ self.assert_('Source' in body)
+ self.assert_(escape(self.content) in body)
+ self.checkForBrokenLinks(body, '/dtmlpage/@@edit.html', 'mgr:mgrpw')
+
+ def testEdit(self):
+ self.addDTMLPage()
+ response = self.publish(
+ '/dtmlpage/@@edit.html',
+ form={'field.source': u'<h1>A DTML Page</h1>',
+ 'UPDATE_SUBMIT': u'Edit'},
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('Edit a DTML page' in body)
+ self.assert_('Source' in body)
+ self.assert_(escape(u'<h1>A DTML Page</h1>') in body)
+ root = self.getRootFolder()
+ dtmlpage = root['dtmlpage']
+ self.assertEqual(dtmlpage.source, '<h1>A DTML Page</h1>')
+
+ def testIndex(self):
+ self.addDTMLPage()
+ response = self.publish(
+ '/dtmlpage/@@index.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assertEqual(
+ body,
+ '<html><body>http://localhost/dtmlpage</body></html>')
+ self.checkForBrokenLinks(body, '/dtmlpage/@@index.html', 'mgr:mgrpw')
+
+ def testPreview(self):
+ self.addDTMLPage()
+ response = self.publish(
+ '/dtmlpage/@@preview.html',
+ basic='mgr:mgrpw')
+ self.assertEqual(response.getStatus(), 200)
+ body = response.getBody()
+ self.assert_('<iframe src="."' in body)
+ self.checkForBrokenLinks(body, '/dtmlpage/@@preview.html', 'mgr:mgrpw')
+
+
+checker = renormalizing.RENormalizing([
+ (re.compile(r"HTTP/1\.1 200 .*"), "HTTP/1.1 200 OK"),
+ (re.compile(r"HTTP/1\.1 303 .*"), "HTTP/1.1 303 See Other"),
+ ])
+
+
+def test_suite():
+ url = functional.FunctionalDocFileSuite('../url.txt', checker=checker)
+ url.layer = DTMLPageLayer
+ DTMLPageTest.layer = DTMLPageLayer
+ return unittest.TestSuite((
+ unittest.makeSuite(DTMLPageTest),
+ url,
+ ))
+
+
+if __name__ == '__main__':
+ unittest.main(defaultTest='test_suite')
Added: zmi.core/trunk/src/zmi/core/dtmlpage/url.txt
===================================================================
--- zmi.core/trunk/src/zmi/core/dtmlpage/url.txt (rev 0)
+++ zmi.core/trunk/src/zmi/core/dtmlpage/url.txt 2009-11-21 08:55:06 UTC (rev 105942)
@@ -0,0 +1,68 @@
+Special URL handling for DTML pages
+===================================
+
+When a DTML page containing a head tag is visited, without a trailing
+slash, the base href isn't set. When visited with a slash, it is:
+
+
+ >>> print http(r"""
+ ... POST /+/zope.app.dtmlpage.DTMLPage%3D HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... Content-Length: 497
+ ... Content-Type: multipart/form-data; boundary=---------------------------824954900632940947241835499
+ ... Referer: http://localhost:8081/+/zope.app.dtmlpage.DTMLPage%3D
+ ...
+ ... -----------------------------824954900632940947241835499
+ ... Content-Disposition: form-data; name="field.source"
+ ...
+ ... <html>
+ ... <head></head>
+ ... <body>
+ ... <a href="eek.html">Eek</a>
+ ... </body>
+ ... </html>
+ ...
+ ... -----------------------------824954900632940947241835499
+ ... Content-Disposition: form-data; name="UPDATE_SUBMIT"
+ ...
+ ... Add
+ ... -----------------------------824954900632940947241835499
+ ... Content-Disposition: form-data; name="add_input_name"
+ ...
+ ... dtml.html
+ ... -----------------------------824954900632940947241835499--
+ ... """)
+ HTTP/1.1 303 See Other
+ ...
+
+
+ >>> print http(r"""
+ ... GET /dtml.html HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """)
+ HTTP/1.1 200 OK
+ ...
+ <html>
+ <head></head>
+ <body>
+ <a href="eek.html">Eek</a>
+ </body>
+ </html>
+ <BLANKLINE>
+
+
+ >>> print http(r"""
+ ... GET /dtml.html/ HTTP/1.1
+ ... Authorization: Basic mgr:mgrpw
+ ... """)
+ HTTP/1.1 200 OK
+ ...
+ <html>
+ <head>
+ <base href="http://localhost/dtml.html" />
+ </head>
+ <body>
+ <a href="eek.html">Eek</a>
+ </body>
+ </html>
+ <BLANKLINE>
Property changes on: zmi.core/trunk/src/zmi/core/dtmlpage/url.txt
___________________________________________________________________
Added: svn:eol-style
+ native
More information about the checkins
mailing list