[Zope3-checkins] SVN: Zope3/branches/jim-adapter/src/zope/ More on
MakeZopeAppSmaller:
Philipp von Weitershausen
philikon at philikon.de
Wed Apr 19 10:53:26 EDT 2006
Log message for revision 67135:
More on MakeZopeAppSmaller:
* Move zope.formlib.Page to zope.publisher.browser.BrowserPage. It really doesn't have
anythign to do with forms and is actually rather useful for all browser pages.
Changed:
U Zope3/branches/jim-adapter/src/zope/app/exception/browser/unauthorized.py
U Zope3/branches/jim-adapter/src/zope/formlib/__init__.py
U Zope3/branches/jim-adapter/src/zope/formlib/form.py
U Zope3/branches/jim-adapter/src/zope/formlib/interfaces.py
U Zope3/branches/jim-adapter/src/zope/formlib/page.py
D Zope3/branches/jim-adapter/src/zope/formlib/page.txt
U Zope3/branches/jim-adapter/src/zope/formlib/tests.py
U Zope3/branches/jim-adapter/src/zope/publisher/browser.py
U Zope3/branches/jim-adapter/src/zope/publisher/interfaces/browser.py
-=-
Modified: Zope3/branches/jim-adapter/src/zope/app/exception/browser/unauthorized.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/app/exception/browser/unauthorized.py 2006-04-19 14:38:04 UTC (rev 67134)
+++ Zope3/branches/jim-adapter/src/zope/app/exception/browser/unauthorized.py 2006-04-19 14:53:25 UTC (rev 67135)
@@ -17,12 +17,13 @@
"""
__docformat__ = 'restructuredtext'
+from zope.publisher.browser import BrowserPage
+from zope.formlib import namedtemplate
+
from zope.app import zapi
-from zope.formlib import page
-from zope.formlib import namedtemplate
from zope.app.pagetemplate import ViewPageTemplateFile
-class Unauthorized(page.Page):
+class Unauthorized(BrowserPage):
def __call__(self):
# Set the error status to 403 (Forbidden) in the case when we don't
Modified: Zope3/branches/jim-adapter/src/zope/formlib/__init__.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/formlib/__init__.py 2006-04-19 14:38:04 UTC (rev 67134)
+++ Zope3/branches/jim-adapter/src/zope/formlib/__init__.py 2006-04-19 14:53:25 UTC (rev 67135)
@@ -11,8 +11,13 @@
#
##############################################################################
"""
-
$Id$
"""
-from zope.formlib.page import Page
+# BBB 2006/04/19 -- to be removed after 12 months
+import zope.deferredimport
+zope.deferredimport.deprecated(
+ "It has moved to zope.publisher.browser.BrowserPage. This reference "
+ "will be gone in Zope 3.5.",
+ Page = 'zope.publisher.browser:BrowserPage',
+ )
Modified: Zope3/branches/jim-adapter/src/zope/formlib/form.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/formlib/form.py 2006-04-19 14:38:04 UTC (rev 67134)
+++ Zope3/branches/jim-adapter/src/zope/formlib/form.py 2006-04-19 14:53:25 UTC (rev 67135)
@@ -10,7 +10,7 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""
+"""Forms
$Id$
"""
@@ -22,12 +22,11 @@
import zope.event
import zope.i18n
import zope.i18nmessageid
-import zope.publisher.interfaces.browser
-
-from zope import component, interface, schema
-
import zope.security
import zope.interface.interfaces
+import zope.publisher.browser
+import zope.publisher.interfaces.browser
+from zope import component, interface, schema
from zope.interface.common import idatetime
from zope.interface.interface import InterfaceClass
from zope.schema.interfaces import IField
@@ -40,7 +39,6 @@
from zope.app.form.interfaces import InputErrors
from zope.app.pagetemplate import ViewPageTemplateFile
-import zope.formlib.page
from zope.formlib import interfaces, namedtemplate
from zope.formlib.i18n import _
@@ -670,7 +668,7 @@
return result
-class FormBase(zope.formlib.page.Page):
+class FormBase(zope.publisher.browser.BrowserPage):
label = u''
Modified: Zope3/branches/jim-adapter/src/zope/formlib/interfaces.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/formlib/interfaces.py 2006-04-19 14:38:04 UTC (rev 67134)
+++ Zope3/branches/jim-adapter/src/zope/formlib/interfaces.py 2006-04-19 14:53:25 UTC (rev 67135)
@@ -10,28 +10,30 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
-"""
+"""Form interfaces
$Id$
"""
-
import re
from zope import interface, schema
-import zope.publisher.interfaces.browser
-import zope.schema.vocabulary
+from zope.publisher.interfaces.browser import IBrowserPage
+##############################################################################
+# BBB 2006/04/19 -- to be removed after 12 months
+
+import zope.deferredimport
+zope.deferredimport.deprecated(
+ "It has moved to zope.publisher.interfaces.browser.IBrowserPage. "
+ "This reference will be gone in Zope 3.5.",
+ IPage = 'zope.publisher.interfaces.browser:IBrowserPage',
+ )
+
+##############################################################################
+
class FormError(Exception):
"""There was an error in managing the form
"""
-class IPage(zope.publisher.interfaces.browser.IBrowserPublisher):
- """Web page
- """
-
- def __call__(*args, **kw):
- """Compute a response body
- """
-
def reConstraint(pat, explanation):
pat = re.compile(pat)
@@ -377,12 +379,12 @@
FormBase = interface.Attribute("""Base class for creating forms
The FormBase class provides reuasable implementation for creating
- forms. It implements ISubPage, IPage, and IFormBaseCustomization.
+ forms. It implements ISubPage, IBrowserPage, and IFormBaseCustomization.
Subclasses will override or use attributes defined by
IFormBaseCustomization.
""")
-class IFormBaseCustomization(ISubPage, IPage):
+class IFormBaseCustomization(ISubPage, IBrowserPage):
"""Attributes provided by the Form base class
These attributes may be used or overridden.
@@ -687,7 +689,7 @@
"""
-class IPageForm(IForm, IPage):
+class IPageForm(IForm, IBrowserPage):
"""A component that displays a form as a page.
"""
Modified: Zope3/branches/jim-adapter/src/zope/formlib/page.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/formlib/page.py 2006-04-19 14:38:04 UTC (rev 67134)
+++ Zope3/branches/jim-adapter/src/zope/formlib/page.py 2006-04-19 14:53:25 UTC (rev 67135)
@@ -12,21 +12,14 @@
##############################################################################
"""Simple Page support
+This module has been deprecated and will be gone in Zope 3.5.
+
$Id$
"""
-from zope import interface
-from zope.publisher.interfaces import NotFound
-from zope.publisher.browser import BrowserView
-from zope.formlib.interfaces import IPage
-
-class Page(BrowserView):
- """Simple page-support class
- """
-
- interface.implements(IPage)
-
- def browserDefault(self, request):
- return self, ()
-
- def publishTraverse(self, request, name):
- raise NotFound(self, name, request)
+# BBB 2006/04/19 -- to be removed after 12 months
+import zope.deferredimport
+zope.deferredimport.deprecated(
+ "It has moved to zope.publisher.browser.BrowserPage. This reference "
+ "will be gone in Zope 3.5.",
+ Page = 'zope.publisher.browser:BrowserPage',
+ )
Deleted: Zope3/branches/jim-adapter/src/zope/formlib/page.txt
===================================================================
--- Zope3/branches/jim-adapter/src/zope/formlib/page.txt 2006-04-19 14:38:04 UTC (rev 67134)
+++ Zope3/branches/jim-adapter/src/zope/formlib/page.txt 2006-04-19 14:53:25 UTC (rev 67135)
@@ -1,121 +0,0 @@
-=====
-Pages
-=====
-
-This is an experimental facility for defining pages in Python.
-
-A page is a view that's implemented in Python and registered in ZCML.
-
-The goal of pages is to put definitions in Python, rather than in
-ZCML.
-
-Pages are simply objects that implement views. There are a number of
-mix-in classes that make this easier.
-
-There are different kinds of pages:
-
-- Adapters, which provide some interface
-
-- Pages, which provide published objects
-
-What are the sorts of facilities we need?
-
-- Browser Publishing -- A browser-published object needs to provide
- IBrowserPublisher.
-
-- Widget management
-
- - Widget set up
-
- - We can set up widgets for input, editing, or display
-
- - select widget type
-
- - initialize widgets with existing data in edit case
-
- - Input processing
-
- - Actions/buttons
-
-A major goal is to make creating pages simple and explicit
-
-Creating simple pages
-=====================
-
-To create a page, which is an object that is published as a page,
-you need to provide an object that:
-
-- has a __call__ method and that
-
-- provides IBrowserPublisher, and
-
-If ZPT is going to be used, then your object should also provide
-request and context attributes.
-
-The Page base class provides a standard constructor
-and a simple implementation of IBrowserPublisher:
-
- >>> import zope.formlib
- >>> class MyPage(zope.formlib.Page):
- ... pass
-
- >>> from zope.publisher.browser import TestRequest
- >>> request = TestRequest()
- >>> context = object()
- >>> page = MyPage(context, request)
-
- >>> from zope.publisher.interfaces.browser import IBrowserPublisher
- >>> IBrowserPublisher.providedBy(page)
- True
-
- >>> page.browserDefault(request) == (page, ())
- True
-
- >>> page.publishTraverse(request, 'bob') # doctest: +ELLIPSIS
- Traceback (most recent call last):
- ...
- NotFound: Object: <MyPage object at ...>, name: 'bob'
-
- >>> page.request is request
- True
-
- >>> page.context is context
- True
-
-But it doesn't supply a __call__ method:
-
- >>> page()
- Traceback (most recent call last):
- ...
- TypeError: 'MyPage' object is not callable
-
-It is the subclass' responsibility to do that.
-
-If we want to use a page template, we will normally store that
-template in a file and use a ViewPageTemplateFile to add it to a
-class:
-
- >>> from zope.app.pagetemplate import ViewPageTemplateFile
- >>> class MyPage(zope.formlib.Page):
- ... __call__ = ViewPageTemplateFile('sample.pt')
-
-(See sample.pt in this directory to see the sample template.)
-
-Now, we'll create a content object and use it with our new page:
-
- >>> class MyContent:
- ... def __init__(self, name):
- ... self.name = name
-
- >>> context = MyContent('bob')
-
- >>> page = MyPage(context, request)
- >>> print page(1, 2, x=3, y=4)
- <html><body>
- Hello bob
- The URL is http://127.0.0.1
- The positional arguments were (1, 2)
- The keyword argument x is 3
- </body></html>
- <BLANKLINE>
-
Modified: Zope3/branches/jim-adapter/src/zope/formlib/tests.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/formlib/tests.py 2006-04-19 14:38:04 UTC (rev 67134)
+++ Zope3/branches/jim-adapter/src/zope/formlib/tests.py 2006-04-19 14:53:25 UTC (rev 67135)
@@ -442,10 +442,6 @@
from zope.testing import doctest
return unittest.TestSuite((
doctest.DocFileSuite(
- 'page.txt',
- setUp=pageSetUp, tearDown=placelesssetup.tearDown,
- ),
- doctest.DocFileSuite(
'form.txt',
setUp=formSetUp, tearDown=placelesssetup.tearDown,
),
Modified: Zope3/branches/jim-adapter/src/zope/publisher/browser.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/publisher/browser.py 2006-04-19 14:38:04 UTC (rev 67134)
+++ Zope3/branches/jim-adapter/src/zope/publisher/browser.py 2006-04-19 14:53:25 UTC (rev 67135)
@@ -31,11 +31,13 @@
from zope.i18n.interfaces import IUserPreferredCharsets
from zope.location import Location
+from zope.publisher.interfaces import NotFound
from zope.publisher.interfaces.browser import IBrowserRequest
from zope.publisher.interfaces.browser import IDefaultBrowserLayer
from zope.publisher.interfaces.browser import IDefaultSkin
from zope.publisher.interfaces.browser import IBrowserApplicationRequest
from zope.publisher.interfaces.browser import IBrowserView
+from zope.publisher.interfaces.browser import IBrowserPage
from zope.publisher.interfaces.browser import IBrowserSkinType
from zope.publisher.http import HTTPRequest, HTTPResponse
@@ -856,6 +858,69 @@
__parent__ = property(__getParent, __setParent)
+class BrowserPage(BrowserView):
+ """Browser page
+
+ To create a page, which is an object that is published as a page,
+ you need to provide an object that:
+
+ - has a __call__ method and that
+
+ - provides IBrowserPublisher, and
+
+ - if ZPT is going to be used, then your object should also provide
+ request and context attributes.
+
+ The BrowserPage base class provides a standard constructor and a
+ simple implementation of IBrowserPublisher:
+
+ >>> class MyPage(BrowserPage):
+ ... pass
+
+ >>> request = TestRequest()
+ >>> context = object()
+ >>> page = MyPage(context, request)
+
+ >>> from zope.publisher.interfaces.browser import IBrowserPublisher
+ >>> IBrowserPublisher.providedBy(page)
+ True
+
+ >>> page.browserDefault(request) == (page, ())
+ True
+
+ >>> page.publishTraverse(request, 'bob') # doctest: +ELLIPSIS
+ Traceback (most recent call last):
+ ...
+ NotFound: Object: <zope.publisher.browser.MyPage object at ...>, name: 'bob'
+
+ >>> page.request is request
+ True
+
+ >>> page.context is context
+ True
+
+ But it doesn't supply a __call__ method:
+
+ >>> page()
+ Traceback (most recent call last):
+ ...
+ NotImplementedError: Subclasses should override __call__ to provide a response body
+
+ It is the subclass' responsibility to do that.
+
+ """
+ implements(IBrowserPage)
+
+ def browserDefault(self, request):
+ return self, ()
+
+ def publishTraverse(self, request, name):
+ raise NotFound(self, name, request)
+
+ def __call__(self, *args, **kw):
+ raise NotImplementedError("Subclasses should override __call__ to "
+ "provide a response body")
+
def setDefaultSkin(request):
"""Sets the default skin for the request.
Modified: Zope3/branches/jim-adapter/src/zope/publisher/interfaces/browser.py
===================================================================
--- Zope3/branches/jim-adapter/src/zope/publisher/interfaces/browser.py 2006-04-19 14:38:04 UTC (rev 67134)
+++ Zope3/branches/jim-adapter/src/zope/publisher/interfaces/browser.py 2006-04-19 14:53:25 UTC (rev 67135)
@@ -106,7 +106,12 @@
the base href.
"""
+class IBrowserPage(IBrowserPublisher):
+ """Browser page"""
+ def __call__(*args, **kw):
+ """Compute a response body"""
+
class IBrowserView(IView):
"""Browser View"""
More information about the Zope3-Checkins
mailing list