[Zope3-checkins] CVS: Zope3/src/zope/app/renderer - vocabulary.py:1.1 configure.zcml:1.2 sourcetype.py:1.2

Stephan Richter srichter@cosmos.phy.tufts.edu
Thu, 31 Jul 2003 14:49:14 -0400


Update of /cvs-repository/Zope3/src/zope/app/renderer
In directory cvs.zope.org:/tmp/cvs-serv18657

Modified Files:
	configure.zcml sourcetype.py 
Added Files:
	vocabulary.py 
Log Message:
Add vocabulary for the source type. You will se it being used in the ZWiki
code shortly.

Add a test that went missing when moving the renderer code.


=== Added File Zope3/src/zope/app/renderer/vocabulary.py ===
##############################################################################
#
# Copyright (c) 2002 Zope Corporation and Contributors.
# All Rights Reserved.
# 
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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.
# 
##############################################################################
"""Vocabulary for the Source Type Registry

$Id: vocabulary.py,v 1.1 2003/07/31 18:48:38 srichter Exp $
"""
from zope.interface import implements
from zope.component import getService
from zope.schema.interfaces import \
     ITokenizedTerm, IVocabulary, IVocabularyTokenized

class SourceTypeTerm:

    implements(ITokenizedTerm)

    def __init__(self, title):
        self.value = self.token = title
        self.title = title


class SourceTypeVocabulary(object):

    implements(IVocabulary, IVocabularyTokenized)

    def __init__(self, context):
        self.types = getService(context, 'SourceTypeRegistry')
    
    def __contains__(self, value):
        return value in self.types.getAllTitles()
    
    def __iter__(self):
        terms = map(lambda st: SourceTypeTerm(st), self.types.getAllTitles())
        return iter(terms)
    
    def __len__(self):
        return len(self.types.getAllTitles())
    
    def getQuery(self):
        return None
    
    def getTerm(self, value):
        if value not in self:
            raise KeyError, 'item (%s) not in vocabulary.' %value
        return SourceTypeTerm(value)

    def getTermByToken(self, token):
        if token not in self:
            raise KeyError, 'item (%s) not in vocabulary.' %token
        return self.getTerm(token)


=== Zope3/src/zope/app/renderer/configure.zcml 1.1 => 1.2 ===
--- Zope3/src/zope/app/renderer/configure.zcml:1.1	Thu Jul 31 13:59:36 2003
+++ Zope3/src/zope/app/renderer/configure.zcml	Thu Jul 31 14:48:38 2003
@@ -12,6 +12,24 @@
       component=".sourcetype.SourceTypes" />
 
 
+  <!-- Source Type Vocabulary Setup -->
+
+  <vocabulary
+     name="SourceTypes"
+     factory=".vocabulary.SourceTypeVocabulary" />
+
+  <content class=".vocabulary.SourceTypeVocabulary">
+    <allow interface="zope.schema.interfaces.IVocabulary"/>
+    <allow interface="zope.schema.interfaces.IVocabularyTokenized"/>
+    <allow attributes="__contains__"/>
+  </content>
+
+  <content class=".vocabulary.SourceTypeTerm">
+    <allow
+        interface="zope.schema.interfaces.ITokenizedTerm"
+        attributes="title"/>
+  </content>
+
   <!-- Plain Text Support -->
 
   <renderer:sourcetype


=== Zope3/src/zope/app/renderer/sourcetype.py 1.1 => 1.2 ===
--- Zope3/src/zope/app/renderer/sourcetype.py:1.1	Thu Jul 31 13:59:36 2003
+++ Zope3/src/zope/app/renderer/sourcetype.py	Thu Jul 31 14:48:38 2003
@@ -52,5 +52,7 @@
         klass = self.__types[title][1]
         return klass(source)
 
+    _clear = __init__
 
 SourceTypes = GlobalSourceTypeService()
+clear = SourceTypes._clear