Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Deprecated: Function call_user_method() is deprecated in /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php on line 564

Warning: Cannot modify header information - headers already sent by (output started at /var/hostings/98tau0417/dfwpython.org/pmwiki/cookbook/beautifier/php/Beautifier/Core.php:564) in /var/hostings/98tau0417/dfwpython.org/pmwiki/pmwiki.php on line 1075
The Dallas Ft. Worth Pythoneers | Zope3Notes / DefineInterfaces
SearchWiki:
  8 User(s) Active on Site
  233 Wiki Pages

Most Recently Modified

Club Resources (edit)

How This Wiki Works

Meeting space complements of:
Computer books
            and technical books at discount prices
Check them out; they are a great source of technical books at very good prices!

If you have shopped at Nerdbooks.com, help them out by reviewing them at ResellerRatings.com. You will need your invoice number to prove you are a real customer, and not just ballot stuffing.
Recent Changes Printable View Page History Edit Page
Content Last Modified on October 25, 2005, at 01:42 AM CST

<< Determine where in your filesystem | ZopePackages | Implement unit tests? >>


Defining your Interface(s)

Let's work to define a file, arbitrarily (??? is it arbitrary ???) named "interfaces.py", that contains Python classes, without implementation bodies, that encode the API of your components.

First, import the necessary supporting elements.

  from zope.interface import Interface
  from zope.schema import Text, TextLine, Field
<:vspace>
  from zope.app.container.constraints import ContainerTypesConstraint
  from zope.app.container.constraints import ItemTypePrecondition
  from zope.app.container.interfaces import IContained, IContainer

The sample application being developed here is a folder that contains a set of webpage bookmarks. A bookmark will be a non-container (i.e. non-folder) object new to Zope that we decide will possess a "URL string" and a "textual description" that may be multi-lined and word-wrapped.

Since this is a new interface not based on anything already in Zope, we subclass it from "Interface".

  class IBookMark(Interface):
      """This is the bookmark object."""
<:vspace>
      url = TextLine(
          title=u"URL/Link",
          description=u"URL of the website we're bookmarking",
          default=u"http://www.zope.org",
          required=True)
<:vspace>
      description = Text(
          title=u"Description",
          description=u"Our notes about the bookmarked website",
          default=u"",
          required=False)

Next let's create a new kind of container or folder, specifically to hold all of our bookmarks. Since Zope knows about object containers, we'll subclass it from the existing IContainer interface.

And we'll declare that such a folder will have a name attribute. We'll also give it a precondition limiting the types of objects that can be placed into it. Our bookmark folder will contain only bookmark objects.

class IBookMarkFolder(IContainer):
    """This is the container for all book marks."""
<:vspace>
    name = TextLine(
        title=u"Name of BookMarkFolder",
        description=u"A name for BookMarker",
        default=u"",
        required=True)
<:vspace>
    def __setitem__(name, obj):
        pass
<:vspace>
    __setitem__.precondition = ItemTypePrecondition(IMark)

And conversely, we'll add a constraint that our bookmark objects can only be placed into a bookmark folder. We want to always be able to find our bookmarks so we limit their placement.

Note however that we've not placed any constraint on how many bookmark folders can existing in the system at one time.

class IMarkContained(IContained):
    """A book mark can only contain in a BookMarker"""
<:vspace>
    __parent__ = Field(
        constraint = ContainerTypesConstraint(IBookMarker))

<< Determine where in your filesystem | ZopePackages | Implement unit tests? >>

Recent Changes Printable View Page History Edit Page