[Checkins] SVN: z3c.flashmessage/trunk/ Importing initial code.

Christian Theune ct at gocept.com
Thu Jul 12 08:10:10 EDT 2007


Log message for revision 77728:
  Importing initial code.
  

Changed:
  A   z3c.flashmessage/trunk/
  A   z3c.flashmessage/trunk/bootstrap.py
  A   z3c.flashmessage/trunk/buildout.cfg
  A   z3c.flashmessage/trunk/setup.py
  A   z3c.flashmessage/trunk/src/
  A   z3c.flashmessage/trunk/src/z3c/
  A   z3c.flashmessage/trunk/src/z3c/__init__.py
  A   z3c.flashmessage/trunk/src/z3c/flashmessage/
  A   z3c.flashmessage/trunk/src/z3c/flashmessage/README.txt
  A   z3c.flashmessage/trunk/src/z3c/flashmessage/__init__.py
  A   z3c.flashmessage/trunk/src/z3c/flashmessage/configure.zcml
  A   z3c.flashmessage/trunk/src/z3c/flashmessage/ftesting.zcml
  A   z3c.flashmessage/trunk/src/z3c/flashmessage/interfaces.py
  A   z3c.flashmessage/trunk/src/z3c/flashmessage/message.py
  A   z3c.flashmessage/trunk/src/z3c/flashmessage/session.py
  A   z3c.flashmessage/trunk/src/z3c/flashmessage/sketches.txt
  A   z3c.flashmessage/trunk/src/z3c/flashmessage/tests.py

-=-
Added: z3c.flashmessage/trunk/bootstrap.py
===================================================================
--- z3c.flashmessage/trunk/bootstrap.py	                        (rev 0)
+++ z3c.flashmessage/trunk/bootstrap.py	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,52 @@
+##############################################################################
+#
+# Copyright (c) 2006 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.
+#
+##############################################################################
+"""Bootstrap a buildout-based project
+
+Simply run this script in a directory containing a buildout.cfg.
+The script accepts buildout command-line options, so you can
+use the -c option to specify an alternate configuration file.
+
+$Id: bootstrap.py 72703 2007-02-20 11:49:26Z jim $
+"""
+
+import os, shutil, sys, tempfile, urllib2
+
+tmpeggs = tempfile.mkdtemp()
+
+ez = {}
+exec urllib2.urlopen('http://peak.telecommunity.com/dist/ez_setup.py'
+                     ).read() in ez
+ez['use_setuptools'](to_dir=tmpeggs, download_delay=0)
+
+import pkg_resources
+
+cmd = 'from setuptools.command.easy_install import main; main()'
+if sys.platform == 'win32':
+    cmd = '"%s"' % cmd # work around spawn lamosity on windows
+
+ws = pkg_resources.working_set
+assert os.spawnle(
+    os.P_WAIT, sys.executable, sys.executable,
+    '-c', cmd, '-mqNxd', tmpeggs, 'zc.buildout',
+    dict(os.environ,
+         PYTHONPATH=
+         ws.find(pkg_resources.Requirement.parse('setuptools')).location
+         ),
+    ) == 0
+
+ws.add_entry(tmpeggs)
+ws.require('zc.buildout')
+import zc.buildout.buildout
+zc.buildout.buildout.main(sys.argv[1:] + ['bootstrap'])
+shutil.rmtree(tmpeggs)


Property changes on: z3c.flashmessage/trunk/bootstrap.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.flashmessage/trunk/buildout.cfg
===================================================================
--- z3c.flashmessage/trunk/buildout.cfg	                        (rev 0)
+++ z3c.flashmessage/trunk/buildout.cfg	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,8 @@
+[buildout]
+develop = .
+parts = test
+find-links = http://download.zope.org/distribution/
+
+[test]
+recipe = zc.recipe.testrunner
+eggs = z3c.flashmessage [test]

Added: z3c.flashmessage/trunk/setup.py
===================================================================
--- z3c.flashmessage/trunk/setup.py	                        (rev 0)
+++ z3c.flashmessage/trunk/setup.py	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,24 @@
+from setuptools import setup, find_packages
+
+setup(
+    name = "z3c.flashmessage",
+    version = "1.0",
+    author = "Jasper Op de Coul, Christian Theune",
+    author_email = "jasper at infrae.com, ct at gocept.com",
+    description = "A package for sending `flash messages` to users.",
+    license = "ZPL 2.1",
+    keywords = "zope3",
+    zip_safe=False,
+    packages = find_packages('src'),
+    include_package_data = True,
+    package_dir = {'':'src'},
+    namespace_packages = ['z3c'],
+    install_requires = ['setuptools',
+                        'ZODB3',
+                        'zope.interface',
+                        'zope.component',
+                        'zope.app.session',
+                        'zope.security'],
+    extras_require=dict(test=['zope.app.testing',
+                              'zope.app.zcmlfiles'])
+)


Property changes on: z3c.flashmessage/trunk/setup.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.flashmessage/trunk/src/z3c/__init__.py
===================================================================
--- z3c.flashmessage/trunk/src/z3c/__init__.py	                        (rev 0)
+++ z3c.flashmessage/trunk/src/z3c/__init__.py	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,7 @@
+# this is a namespace package
+try:
+    import pkg_resources
+    pkg_resources.declare_namespace(__name__)
+except ImportError:
+    import pkgutil
+    __path__ = pkgutil.extend_path(__path__, __name__)


Property changes on: z3c.flashmessage/trunk/src/z3c/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.flashmessage/trunk/src/z3c/flashmessage/README.txt
===================================================================
--- z3c.flashmessage/trunk/src/z3c/flashmessage/README.txt	                        (rev 0)
+++ z3c.flashmessage/trunk/src/z3c/flashmessage/README.txt	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,36 @@
+==============
+Flash messages
+==============
+
+Components to display small messages for users.
+
+
+Sending a message to the current user
+=====================================
+
+To send a message to the current user, you can use the session-based message
+source. Let's set one up:
+
+>>> from z3c.flashmessage.session import SessionMessageSource
+>>> source = SessionMessageSource()
+
+>>> source.send(u'The world will come to an end in 40 seconds!')
+
+Then, the user can receive the message:
+
+>>> m = list(source.receive())
+>>> m
+[<z3c.flashmessage.message.Message object at 0x...>]
+>>> m[0].message
+u'The world will come to an end in 40 seconds!'
+>>> m[0].type
+u'message'
+
+The standard message will remove itself from the source when it was received:
+
+>>> list(source.receive())
+[]
+
+
+
+


Property changes on: z3c.flashmessage/trunk/src/z3c/flashmessage/README.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.flashmessage/trunk/src/z3c/flashmessage/__init__.py
===================================================================
--- z3c.flashmessage/trunk/src/z3c/flashmessage/__init__.py	                        (rev 0)
+++ z3c.flashmessage/trunk/src/z3c/flashmessage/__init__.py	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1 @@
+# Make this a Python package


Property changes on: z3c.flashmessage/trunk/src/z3c/flashmessage/__init__.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.flashmessage/trunk/src/z3c/flashmessage/configure.zcml
===================================================================
--- z3c.flashmessage/trunk/src/z3c/flashmessage/configure.zcml	                        (rev 0)
+++ z3c.flashmessage/trunk/src/z3c/flashmessage/configure.zcml	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,5 @@
+<configure xmlns="http://namespaces.zope.org/zope">
+
+  <subscriber factory=".events.remove_received_message" />
+
+</configure>

Added: z3c.flashmessage/trunk/src/z3c/flashmessage/ftesting.zcml
===================================================================
--- z3c.flashmessage/trunk/src/z3c/flashmessage/ftesting.zcml	                        (rev 0)
+++ z3c.flashmessage/trunk/src/z3c/flashmessage/ftesting.zcml	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,21 @@
+<configure
+   xmlns="http://namespaces.zope.org/zope"
+   i18n_domain="zope"
+   >
+
+  <!-- This file is the equivalent of site.zcml and it is -->
+  <!-- used for functional testing setup -->
+  <include package="zope.app.zcmlfiles" />
+  <include package="zope.app.session" />
+
+  <utility
+    factory="zope.app.session.http.CookieClientIdManager"
+    provides="zope.app.session.interfaces.IClientIdManager"
+    />
+
+  <utility
+    factory="zope.app.session.session.RAMSessionDataContainer"
+    provides="zope.app.session.interfaces.ISessionDataContainer"
+    />
+
+</configure>

Added: z3c.flashmessage/trunk/src/z3c/flashmessage/interfaces.py
===================================================================
--- z3c.flashmessage/trunk/src/z3c/flashmessage/interfaces.py	                        (rev 0)
+++ z3c.flashmessage/trunk/src/z3c/flashmessage/interfaces.py	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,51 @@
+# -*- coding: latin-1 -*-
+# Copyright (c) 2007 Infrae, gocept gmbh & co. kg and Contributors
+# See also LICENSE.txt
+# $Id$
+"""Flash message interfaces"""
+
+import zope.interface
+
+
+class IMessage(zope.interface.Interface):
+    """A message that can be displayed to the user."""
+
+    message = zope.schema.TextLine(title=u"The message itself.")
+
+    type = zope.schema.TextLine(title=u"A classifier for the message",
+                                default=u"message")
+
+    def prepare(source):
+        """Prepare for being received.
+
+        This method is called by the IMessageSource before the message is
+        returned before being displayed to the user.
+
+        Two things are generally reasonable to do here:
+
+            - Decide whether the message should be deleted from the source
+            - Update the message
+
+        """
+
+
+class IMessageSource(zope.interface.Interface):
+
+    def send(message, type=u"message"):
+        """Send a message to this source.
+
+        Message can either be a unicode string or an IMessage object.
+
+        """
+
+    def receive(type=None):
+        """Return all messages of the given type from this source.
+
+        If type is None, all messages will be returned.
+
+        The result is an iterable.
+
+        """
+
+    def delete(message):
+        """Remove the given message from the source."""


Property changes on: z3c.flashmessage/trunk/src/z3c/flashmessage/interfaces.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.flashmessage/trunk/src/z3c/flashmessage/message.py
===================================================================
--- z3c.flashmessage/trunk/src/z3c/flashmessage/message.py	                        (rev 0)
+++ z3c.flashmessage/trunk/src/z3c/flashmessage/message.py	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,32 @@
+# -*- coding: latin-1 -*-
+# Copyright (c) 2007 Infrae, gocept gmbh & co. kg and Contributors
+# See also LICENSE.txt
+# $Id$
+"""A simple message that can be displayed."""
+
+import persistent
+import zope.interface
+
+import z3c.flashmessage.interfaces
+
+
+class Message(persistent.Persistent):
+    """A message that is displayed to the user.
+
+    This is the default message which will delete itself after being received.
+
+    """
+
+    zope.interface.implements(z3c.flashmessage.interfaces.IMessage)
+
+    def __init__(self, message, type=u"message"):
+        self.message = message
+        self.type = type
+
+    def prepare(self, source):
+        """Prepare for being received.
+
+        Messages that get are received get removed from the source.
+
+        """
+        source.delete(self)


Property changes on: z3c.flashmessage/trunk/src/z3c/flashmessage/message.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.flashmessage/trunk/src/z3c/flashmessage/session.py
===================================================================
--- z3c.flashmessage/trunk/src/z3c/flashmessage/session.py	                        (rev 0)
+++ z3c.flashmessage/trunk/src/z3c/flashmessage/session.py	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,47 @@
+# -*- coding: latin-1 -*-
+# Copyright (c) 2007 Infrae, gocept gmbh & co. kg and Contributors
+# See also LICENSE.txt
+# $Id$
+"""A message source that stores messages in the session."""
+
+import zope.interface
+
+import zope.app.session.interfaces
+
+import persistent.list
+
+import z3c.flashmessage.interfaces
+import z3c.flashmessage.message
+
+
+class SessionMessageSource(object):
+
+    zope.interface.implements(z3c.flashmessage.interfaces.IMessageSource)
+
+    @property
+    def _storage(self):
+        request = zope.security.management.getInteraction().participations[0]
+        session = zope.app.session.interfaces.ISession(
+            request)['z3c.flashmessage']
+        messages = session.setdefault('messages',
+                                      persistent.list.PersistentList())
+        return messages
+
+    def send(self, message, type=u"message"):
+        """Send a message to this source."""
+        if not z3c.flashmessage.interfaces.IMessage.providedBy(message):
+            # The programmer has passed in not a message, so we create a
+            # message for him. This is allowed by the API for convenience.
+            message = z3c.flashmessage.message.Message(message, type=type)
+        message.source = self
+        self._storage.append(message)
+
+    def receive(self, type=None):
+        """Return all messages of the given type from this source."""
+        for message in self._storage:
+            message.prepare(self)
+            yield message
+
+    def delete(self, message):
+        """Remove the given message from the source."""
+        self._storage.remove(message)


Property changes on: z3c.flashmessage/trunk/src/z3c/flashmessage/session.py
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.flashmessage/trunk/src/z3c/flashmessage/sketches.txt
===================================================================
--- z3c.flashmessage/trunk/src/z3c/flashmessage/sketches.txt	                        (rev 0)
+++ z3c.flashmessage/trunk/src/z3c/flashmessage/sketches.txt	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,90 @@
+==============
+Flash messages
+==============
+
+...
+
+
+Sending a message to the current user
+=====================================
+
+To send a message to the current user, you can use the session-based message
+source. Let's set one up:
+
+>>> from z3c.flashmessage.session import SessionMessageSource
+>>> source = SessionMessageSource()
+
+>>> source.send(u'The world will come to an end in 40 seconds!')
+
+Then, the use can receive the message:
+
+>>> m = list(source.receive())
+>>> m
+[<Message object at 0x...>]
+>>> m[0].message
+u'The world will come to an end in 40 seconds!')
+>>> m[0].type
+'message'
+
+Calling `receive()` another time, will not return any messages, as they get
+removed, when receiving:
+
+>>> messages.receive()
+[]
+
+
+Display messages in categories
+==============================
+
+We allow to distinguish between different kinds of messages. The default kind
+is 'message':
+
+>>> messages.send('Hey, user!', type='error')
+
+>>> m = messages.receive()
+>>> m
+[<Message object at 0x...>]
+
+Looking at the object, we can get the message and its kind:
+
+>>> m[0].message
+u'Hey, user!'
+>>> m[0].type
+'error'
+
+
+Persistent messages
+===================
+
+
+
+
+Using message objects
+=====================
+
+More generally, we could construct message objects instead of passing strings
+around (more object-oriented instead of data-oriented):
+
+>>> m = Message(u"Hey, user!", type="error")
+
+
+This also allows for more specialized messages, like messages that time out
+after a certain time, e.g
+
+
+
+
+
+
+getUtility(IMessageSource, 'session').send('Boooh')
+
+getUtility(IMessageSource, 'global').send('Boooh')
+
+
+
+
+
+getUtility(IMessageSource, 'global').receive()
+
+
+- timeout for messages


Property changes on: z3c.flashmessage/trunk/src/z3c/flashmessage/sketches.txt
___________________________________________________________________
Name: svn:eol-style
   + native

Added: z3c.flashmessage/trunk/src/z3c/flashmessage/tests.py
===================================================================
--- z3c.flashmessage/trunk/src/z3c/flashmessage/tests.py	                        (rev 0)
+++ z3c.flashmessage/trunk/src/z3c/flashmessage/tests.py	2007-07-12 12:10:10 UTC (rev 77728)
@@ -0,0 +1,38 @@
+# -*- coding: latin-1 -*-
+# Copyright (c) 2007 Infrae, gocept gmbh & co. kg and Contributors
+# See also LICENSE.txt
+# $Id$
+"""Test harness"""
+
+import unittest
+import doctest
+import os
+
+from zope.app.testing.functional import FunctionalDocFileSuite, ZCMLLayer
+import zope.security.management
+import zope.publisher.browser
+
+
+FlashMessageLayer = ZCMLLayer(
+    os.path.join(os.path.dirname(__file__), 'ftesting.zcml'),
+    __name__, 'FlashMessageLayer', allow_teardown=True)
+
+
+def setUp(test):
+    request = zope.publisher.browser.TestRequest()
+    zope.security.management.newInteraction()
+    interaction = zope.security.management.getInteraction()
+    interaction.add(request)
+
+def tearDown(test):
+    pass
+
+def test_suite():
+    suite = unittest.TestSuite()
+    test = FunctionalDocFileSuite('README.txt',
+                                  optionflags=doctest.ELLIPSIS,
+                                  setUp=setUp,
+                                  tearDown=tearDown)
+    test.layer = FlashMessageLayer
+    suite.addTest(test)
+    return suite


Property changes on: z3c.flashmessage/trunk/src/z3c/flashmessage/tests.py
___________________________________________________________________
Name: svn:eol-style
   + native



More information about the Checkins mailing list