[Zope3-checkins] SVN: messageboard/trunk/step07/ Synced with code
updates of previous chapters.
Stephan Richter
srichter at cosmos.phy.tufts.edu
Sun Aug 15 15:19:35 EDT 2004
Log message for revision 27138:
Synced with code updates of previous chapters.
Changed:
U messageboard/trunk/step07/browser/widgets.py
U messageboard/trunk/step07/configure.zcml
U messageboard/trunk/step07/fields.py
U messageboard/trunk/step07/interfaces.py
U messageboard/trunk/step07/message.py
U messageboard/trunk/step07/security.zcml
-=-
Modified: messageboard/trunk/step07/browser/widgets.py
===================================================================
--- messageboard/trunk/step07/browser/widgets.py 2004-08-15 19:04:49 UTC (rev 27137)
+++ messageboard/trunk/step07/browser/widgets.py 2004-08-15 19:19:35 UTC (rev 27138)
@@ -30,7 +30,7 @@
input = re.sub(regex, '', input)
if self.context.allowed_tags:
- regex = allowed_regex %'|'.join(
+ regex = allowed_regex %'[ />]|'.join(
self.context.allowed_tags)
input = re.sub(regex, '', input)
Modified: messageboard/trunk/step07/configure.zcml
===================================================================
--- messageboard/trunk/step07/configure.zcml 2004-08-15 19:04:49 UTC (rev 27137)
+++ messageboard/trunk/step07/configure.zcml 2004-08-15 19:19:35 UTC (rev 27138)
@@ -1,7 +1,6 @@
<configure
xmlns="http://namespaces.zope.org/zope"
xmlns:i18n="http://namespaces.zope.org/i18n"
- xmlns:event="http://namespaces.zope.org/event"
xmlns:mail="http://namespaces.zope.org/mail"
i18n_domain="messageboard">
@@ -69,6 +68,10 @@
interface=".interfaces.IMessage"
/>
<require
+ permission="book.messageboard.View"
+ interface=".interfaces.IMessageContainer"
+ />
+ <require
permission="book.messageboard.Add"
set_schema=".interfaces.IMessage"
/>
@@ -83,7 +86,9 @@
<adapter
factory=".message.MailSubscriptions"
provides=".interfaces.IMailSubscriptions"
- for=".interfaces.IMessage" />
+ for=".interfaces.IMessage"
+ permission="book.messageboard.Add"
+ trusted="true" />
<mail:smtpMailer name="msgboard-smtp" hostname="localhost" port="25" />
@@ -93,13 +98,18 @@
queuePath="./mail-queue"
mailer="msgboard-smtp" />
- <event:subscribe
- subscriber=".message.mailer"
- event_types="zope.app.event.interfaces.IObjectModifiedEvent
- zope.app.container.interfaces.IObjectAddedEvent
- zope.app.container.interfaces.IObjectRemovedEvent" />
+ <subscriber
+ factory=".message.mailer"
+ for="zope.app.event.interfaces.IObjectModifiedEvent" />
+ <subscriber
+ factory=".message.mailer"
+ for="zope.app.container.interfaces.IObjectAddedEvent" />
+ <subscriber
+ factory=".message.mailer"
+ for="zope.app.container.interfaces.IObjectRemovedEvent" />
+
<i18n:registerTranslations directory="locales" />
<include package=".browser" />
Modified: messageboard/trunk/step07/fields.py
===================================================================
--- messageboard/trunk/step07/fields.py 2004-08-15 19:04:49 UTC (rev 27137)
+++ messageboard/trunk/step07/fields.py 2004-08-15 19:19:35 UTC (rev 27138)
@@ -24,7 +24,7 @@
_ = MessageIDFactory('messageboard')
forbidden_regex = r'</?(?:%s).*?/?>'
-allowed_regex = r'</??(?!%s)[a-zA-Z0-9]*? ?(?:[a-z0-9]*?=?".*?")*/??>'
+allowed_regex = r'</??(?!%s[ />])[a-zA-Z0-9]*? ?(?:[a-z0-9]*?=?".*?")*/??>'
class ForbiddenTags(ValidationError):
__doc__ = _("Forbidden HTML Tags used.")
@@ -49,7 +49,7 @@
raise ForbiddenTags(value, self.forbidden_tags)
if self.allowed_tags:
- regex = allowed_regex %'|'.join(self.allowed_tags)
+ regex = allowed_regex %'[ />]|'.join(self.allowed_tags)
if re.findall(regex, value):
raise ForbiddenTags(value, self.allowed_tags)
Modified: messageboard/trunk/step07/interfaces.py
===================================================================
--- messageboard/trunk/step07/interfaces.py 2004-08-15 19:04:49 UTC (rev 27137)
+++ messageboard/trunk/step07/interfaces.py 2004-08-15 19:19:35 UTC (rev 27138)
@@ -24,7 +24,7 @@
from zope.app.container.constraints import ContainerTypesConstraint
from zope.app.container.constraints import ItemTypePrecondition
-from zope.app.container.interfaces import IContainer
+from zope.app.container.interfaces import IContained, IContainer
from zope.app.file.interfaces import IFile
from fields import HTML
@@ -32,12 +32,9 @@
_ = MessageIDFactory('messageboard')
-class IMessage(IContainer):
- """A message object. It can contain its own responses."""
+class IMessage(Interface):
+ """A message object."""
- def __setitem__(name, object):
- """Add a IMessage object."""
-
title = TextLine(
title=_("Title/Subject"),
description=_("Title and/or subject of the message."),
@@ -72,12 +69,23 @@
required=False)
-IMessage['__setitem__'].setTaggedValue('precondition',
- ItemTypePrecondition(IMessage, IFile))
-IMessage.setTaggedValue('__parent__', Field(
- constraint=ContainerTypesConstraint(IMessageBoard, IMessage)))
+class IMessageContained(IContained):
+ """Interface that specifies the type of objects that can contain
+ messages."""
+ __parent__ = Field(
+ constraint = ContainerTypesConstraint(IMessageBoard, IMessage))
+class IMessageContainer(IContainer):
+ """We also want to make the message object a container that can contain
+ responses (other messages) and attachments (files and images)."""
+
+ def __setitem__(name, object):
+ """Add a IMessage object."""
+
+ __setitem__.precondition = ItemTypePrecondition(IMessage, IFile)
+
+
class IHTML(IText):
"""A text field that handles HTML input."""
Modified: messageboard/trunk/step07/message.py
===================================================================
--- messageboard/trunk/step07/message.py 2004-08-15 19:04:49 UTC (rev 27137)
+++ messageboard/trunk/step07/message.py 2004-08-15 19:19:35 UTC (rev 27138)
@@ -26,11 +26,11 @@
from zope.app.container.interfaces import IObjectAddedEvent
from zope.app.container.interfaces import IObjectRemovedEvent
from zope.app.event.interfaces import IObjectModifiedEvent
-from zope.app.event.interfaces import ISubscriber
from zope.app.mail.interfaces import IMailDelivery
from zope.app.size.interfaces import ISized
from book.messageboard.interfaces import IMessage
+from book.messageboard.interfaces import IMessageContained, IMessageContainer
from book.messageboard.interfaces import IMailSubscriptions
_ = MessageIDFactory('messageboard')
@@ -59,7 +59,7 @@
>>> message.body
u'Message Body'
"""
- implements(IMessage)
+ implements(IMessage, IMessageContained, IMessageContainer)
# See book.messageboard.interfaces.IMessage
title = u''
@@ -231,19 +231,10 @@
class MessageMailer:
- """Class to handle all outgoing mail.
-
- Verify the interface implementation
-
- >>> from zope.interface.verify import verifyClass
- >>> verifyClass(ISubscriber, MessageMailer)
- True
- """
+ """Class to handle all outgoing mail."""
- implements(ISubscriber)
-
- def notify(self, event):
- r"""See zope.app.event.interfaces.ISubscriber
+ def __call__(self, event):
+ r"""Called by the event system.
Here is a demonstration on how the notification process and mail
sending works.
@@ -287,7 +278,7 @@
>>> from zope.app.event.objectevent import ObjectModifiedEvent
>>> event = ObjectModifiedEvent(msg)
- >>> mailer.notify(event)
+ >>> mailer(event)
>>> from pprint import pprint
>>> pprint(mail_result)
@@ -364,8 +355,7 @@
if not toaddrs:
return
msg = 'Subject: %s\n\n\n%s' %(subject, body)
- mail_utility = zapi.getUtility(None, IMailDelivery,
- 'msgboard-delivery')
+ mail_utility = zapi.getUtility(IMailDelivery, 'msgboard-delivery')
mail_utility.send('mailer at messageboard.org' , toaddrs, msg)
mailer = MessageMailer()
Modified: messageboard/trunk/step07/security.zcml
===================================================================
--- messageboard/trunk/step07/security.zcml 2004-08-15 19:04:49 UTC (rev 27137)
+++ messageboard/trunk/step07/security.zcml 2004-08-15 19:19:35 UTC (rev 27138)
@@ -1,5 +1,6 @@
<configure
- xmlns="http://namespaces.zope.org/zope">
+ xmlns="http://namespaces.zope.org/zope"
+ i18n_domain="messageboard">
<role
id="book.messageboard.User"
More information about the Zope3-Checkins
mailing list