z3c.optionstorage-1.0.7/0000755000177100020040000000000011340100214014760 5ustar menesismenesisz3c.optionstorage-1.0.7/bootstrap.py0000644000177100020040000000336711340100146017364 0ustar menesismenesis############################################################################## # # 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) z3c.optionstorage-1.0.7/README.txt0000644000177100020040000000016411340100146016463 0ustar menesismenesisOption Storages are vocabularies that store their values in the ZODB and can be managed during application runtime. z3c.optionstorage-1.0.7/setup.cfg0000644000177100020040000000007311340100214016601 0ustar menesismenesis[egg_info] tag_build = tag_date = 0 tag_svn_revision = 0 z3c.optionstorage-1.0.7/CHANGES.txt0000644000177100020040000000131511340100146016575 0ustar menesismenesis======= CHANGES ======= 1.0.7 (2010-02-21) ------------------ - Remove dependency on zope.app.publisher by using a newer zope.browserpage 1.0.6 (2010-02-20) ------------------ - Remove dependency on zope.app.zapi and zope.deprecation - Replace the use of zope.app.publisher with zope.browserpage 1.0.5 (2010-01-04) ------------------ - Remove dependency on zope.app.schema. 1.0.4 (2007-11-03) ------------------ - Fix up package meta data. 0.1.3 (2007-07-04) ------------------ - Ensure that all package files are included in the egg. 0.1.2 (2007-07-04) ------------------ - Bug fix. 0.1.1 (2007-07-04) ------------------ - Fix packaging data. 0.1.0 (2007-06-22) ------------------ - Initial release. z3c.optionstorage-1.0.7/setup.py0000644000177100020040000000502111340100146016474 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 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. # ############################################################################## """Setup for z3c.optionstorage package $Id: setup.py 109196 2010-02-21 00:35:46Z menesis $ """ import os from setuptools import setup, find_packages def read(*rnames): return open(os.path.join(os.path.dirname(__file__), *rnames)).read() setup(name='z3c.optionstorage', version = '1.0.7', author='Zope Corporation and Contributors', author_email='zope-dev@zope.org', description='Optional Storages -- Persistent, Managable Vocabularies', long_description=( read('README.txt') + '\n\n' + read('CHANGES.txt') ), keywords = "zope3 vocabulary zodb managable", classifiers = [ 'Development Status :: 5 - Production/Stable', 'Environment :: Web Environment', 'Intended Audience :: Developers', 'License :: OSI Approved :: Zope Public License', 'Programming Language :: Python', 'Natural Language :: English', 'Operating System :: OS Independent', 'Topic :: Internet :: WWW/HTTP', 'Framework :: Zope3'], url='http://pypi.python.org/pypi/z3c.optionstorage', license='ZPL 2.1', packages=find_packages('src'), package_dir = {'': 'src'}, namespace_packages=['z3c'], extras_require=dict(test=['zope.testing']), install_requires = ['setuptools', 'ZODB3', 'zope.annotation', 'zope.browserpage>=3.10', 'zope.component', 'zope.configuration', 'zope.i18n', 'zope.interface', 'zope.proxy', 'zope.schema', 'zope.security', 'zope.traversing', 'zope.app.form'], include_package_data = True, zip_safe = False, ) z3c.optionstorage-1.0.7/src/0000755000177100020040000000000011340100214015547 5ustar menesismenesisz3c.optionstorage-1.0.7/src/z3c.optionstorage.egg-info/0000755000177100020040000000000011340100214022634 5ustar menesismenesisz3c.optionstorage-1.0.7/src/z3c.optionstorage.egg-info/namespace_packages.txt0000644000177100020040000000000411340100213027160 0ustar menesismenesisz3c z3c.optionstorage-1.0.7/src/z3c.optionstorage.egg-info/top_level.txt0000644000177100020040000000000411340100213025357 0ustar menesismenesisz3c z3c.optionstorage-1.0.7/src/z3c.optionstorage.egg-info/SOURCES.txt0000644000177100020040000000204411340100213024517 0ustar menesismenesisCHANGES.txt README.txt ZopePublicLicense.txt bootstrap.py buildout.cfg setup.py src/z3c/__init__.py src/z3c.optionstorage.egg-info/PKG-INFO src/z3c.optionstorage.egg-info/SOURCES.txt src/z3c.optionstorage.egg-info/dependency_links.txt src/z3c.optionstorage.egg-info/namespace_packages.txt src/z3c.optionstorage.egg-info/not-zip-safe src/z3c.optionstorage.egg-info/requires.txt src/z3c.optionstorage.egg-info/top_level.txt src/z3c/optionstorage/__init__.py src/z3c/optionstorage/configure.zcml src/z3c/optionstorage/interfaces.py src/z3c/optionstorage/meta.zcml src/z3c/optionstorage/metaconfigure.py src/z3c/optionstorage/metadirectives.py src/z3c/optionstorage/tests.py src/z3c/optionstorage/vocabulary.py src/z3c/optionstorage/browser/__init__.py src/z3c/optionstorage/browser/configure.zcml src/z3c/optionstorage/browser/meta.zcml src/z3c/optionstorage/browser/metaconfigure.py src/z3c/optionstorage/browser/metadirectives.py src/z3c/optionstorage/browser/optiondict.pt src/z3c/optionstorage/browser/optionstorage.pt src/z3c/optionstorage/browser/widgets.pyz3c.optionstorage-1.0.7/src/z3c.optionstorage.egg-info/dependency_links.txt0000644000177100020040000000000111340100213026701 0ustar menesismenesis z3c.optionstorage-1.0.7/src/z3c.optionstorage.egg-info/requires.txt0000644000177100020040000000031211340100213025227 0ustar menesismenesissetuptools ZODB3 zope.annotation zope.browserpage>=3.10 zope.component zope.configuration zope.i18n zope.interface zope.proxy zope.schema zope.security zope.traversing zope.app.form [test] zope.testingz3c.optionstorage-1.0.7/src/z3c.optionstorage.egg-info/not-zip-safe0000644000177100020040000000000111340100160025062 0ustar menesismenesis z3c.optionstorage-1.0.7/src/z3c.optionstorage.egg-info/PKG-INFO0000644000177100020040000000366411340100213023741 0ustar menesismenesisMetadata-Version: 1.0 Name: z3c.optionstorage Version: 1.0.7 Summary: Optional Storages -- Persistent, Managable Vocabularies Home-page: http://pypi.python.org/pypi/z3c.optionstorage Author: Zope Corporation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: Option Storages are vocabularies that store their values in the ZODB and can be managed during application runtime. ======= CHANGES ======= 1.0.7 (2010-02-21) ------------------ - Remove dependency on zope.app.publisher by using a newer zope.browserpage 1.0.6 (2010-02-20) ------------------ - Remove dependency on zope.app.zapi and zope.deprecation - Replace the use of zope.app.publisher with zope.browserpage 1.0.5 (2010-01-04) ------------------ - Remove dependency on zope.app.schema. 1.0.4 (2007-11-03) ------------------ - Fix up package meta data. 0.1.3 (2007-07-04) ------------------ - Ensure that all package files are included in the egg. 0.1.2 (2007-07-04) ------------------ - Bug fix. 0.1.1 (2007-07-04) ------------------ - Fix packaging data. 0.1.0 (2007-06-22) ------------------ - Initial release. Keywords: zope3 vocabulary zodb managable Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Programming Language :: Python Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Topic :: Internet :: WWW/HTTP Classifier: Framework :: Zope3 z3c.optionstorage-1.0.7/src/z3c/0000755000177100020040000000000011340100214016246 5ustar menesismenesisz3c.optionstorage-1.0.7/src/z3c/__init__.py0000644000177100020040000000031011340100146020355 0ustar menesismenesis# this is a namespace package try: import pkg_resources pkg_resources.declare_namespace(__name__) except ImportError: import pkgutil __path__ = pkgutil.extend_path(__path__, __name__) z3c.optionstorage-1.0.7/src/z3c/optionstorage/0000755000177100020040000000000011340100214021143 5ustar menesismenesisz3c.optionstorage-1.0.7/src/z3c/optionstorage/browser/0000755000177100020040000000000011340100214022626 5ustar menesismenesisz3c.optionstorage-1.0.7/src/z3c/optionstorage/browser/widgets.py0000644000177100020040000000165711340100146024663 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 Zope Foundation 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. # ############################################################################## from zope.app.form.browser import DropdownWidget class OptionStorageVocabularyWidget(DropdownWidget): def _getDefault(self): default = self.vocabulary.getDefaultKey() if not default: default = super(OptionStorageVocabularyWidget, self)._getDefault() return default z3c.optionstorage-1.0.7/src/z3c/optionstorage/browser/metadirectives.py0000644000177100020040000000246411340100146026222 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 Zope Foundation 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. # ############################################################################## from zope.browserpage.metadirectives import IViewDirective from zope.configuration.fields import MessageID from zope.interface import Interface from zope.schema import TextLine class IOptionStorageDirective(IViewDirective): """ The manageableVocabularies directive is used to create a vocabulary editing view for a given interface. """ class IOptionStorageOptionsSubdirective(Interface): name = TextLine( title=u"Key of option dictionary in storage", required=True, ) topic = MessageID( title=u"Topic of option dictionary in storage", required=True, ) z3c.optionstorage-1.0.7/src/z3c/optionstorage/browser/metaconfigure.py0000644000177100020040000000247511340100146026044 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 Zope Foundation 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. # ############################################################################## from zope.browserpage.metaconfigure import page from z3c.optionstorage.browser import OptionStorageView class optionStorage(object): def __init__(self, _context, class_=None, **kwargs): self._context = _context self.class_ = class_ self.opts = kwargs.copy() self.dictlist = [] def options(self, _context, name, topic): self.dictlist.append((name, topic)) def __call__(self): class_ = self.class_ if class_ is None: class_ = OptionStorageView class_ = type("OptionStorageView", (class_,), {"dictlist": self.dictlist}) page(self._context, class_=class_, **self.opts) return () z3c.optionstorage-1.0.7/src/z3c/optionstorage/browser/optionstorage.pt0000644000177100020040000000050311340100146026072 0ustar menesismenesis
z3c.optionstorage-1.0.7/src/z3c/optionstorage/browser/__init__.py0000644000177100020040000000651611340100146024753 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 Zope Foundation 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. # ############################################################################## from zope.browserpage.viewpagetemplatefile import ViewPageTemplateFile from z3c.optionstorage.interfaces import IOptionStorage from z3c.optionstorage import OptionDict def checkFields(request, *fields): for field in fields: if field not in request: return False return True class StorageNameNotFoundError(LookupError): pass class OptionStorageView(object): storagetemplate = ViewPageTemplateFile("optionstorage.pt") dicttemplate = ViewPageTemplateFile("optiondict.pt") dictlist = [] # (name, topic) def __init__(self, context, request): self.context = context self.request = request self.name = None self.topic = None self.dict = None def getNameTopicList(self): storage = IOptionStorage(self.context) for name, topic in self.dictlist: yield {"name": name, "topic": topic} def __call__(self, name=None): if name is None: return self.storagetemplate() storage = IOptionStorage(self.context) for _name, topic in self.dictlist: if name == _name: if name not in storage: storage[name] = OptionDict() self.dict = storage[name] self.name = name self.topic = topic break else: raise StorageNameNotFoundError form = self.request.form if "SAVE" not in form: return self.dicttemplate() language = {} key = {} value = {} for entry in form: entryvalue = form[entry].strip() if not entryvalue: pass elif entry.startswith("lang-"): language[int(entry[5:])] = entryvalue elif entry.startswith("key-"): key[int(entry[4:])] = entryvalue elif entry.startswith("value-"): tok = entry.split("-") value[int(tok[1]), int(tok[2])] = entryvalue try: defaultkey = int(form["default-key"]) except KeyError: defaultkey = None try: defaultlanguage = int(form["default-lang"]) except KeyError: defaultlanguage = None self.dict.delAllValues() for keynum, languagenum in value: if keynum in key and languagenum in language: self.dict.addValue(key[keynum], language[languagenum], value[keynum, languagenum]) if defaultkey in key: self.dict.setDefaultKey(key[defaultkey]) if defaultlanguage in language: self.dict.setDefaultLanguage(language[defaultlanguage]) return self.dicttemplate() z3c.optionstorage-1.0.7/src/z3c/optionstorage/browser/optiondict.pt0000644000177100020040000000370211340100146025355 0ustar menesismenesis

Some Topic


 
Keys
Language:
Default
z3c.optionstorage-1.0.7/src/z3c/optionstorage/browser/configure.zcml0000644000177100020040000000061611340100146025505 0ustar menesismenesis z3c.optionstorage-1.0.7/src/z3c/optionstorage/browser/meta.zcml0000644000177100020040000000072411340100146024452 0ustar menesismenesis z3c.optionstorage-1.0.7/src/z3c/optionstorage/metadirectives.py0000644000177100020040000000203411340100146024530 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 Zope Foundation 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. # ############################################################################## from zope.interface import Interface from zope.schema import TextLine class IOptionStorageVocabularyDirective(Interface): """ Define a named vocabulary fetching information from an option storage. """ name = TextLine( title=u"Name", description=u"Provides the name for the option storage "\ u"vocabulary.", required=True) z3c.optionstorage-1.0.7/src/z3c/optionstorage/metaconfigure.py0000644000177100020040000000203011340100146024344 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 Zope Foundation 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. # ############################################################################## from z3c.optionstorage.vocabulary import OptionStorageVocabulary from zope.component.zcml import utility from zope.schema.interfaces import IVocabularyFactory def optionStorageVocabulary(_context, name): def factory(object, name=name): return OptionStorageVocabulary(object, name=name) directlyProvides(factory, IVocabularyFactory) utility(_context, IVocabularyFactory, factory, name=name) z3c.optionstorage-1.0.7/src/z3c/optionstorage/vocabulary.py0000644000177100020040000000651711340100146023701 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 Zope Foundation 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. # ############################################################################## from zope.schema.interfaces import IVocabularyTokenized from zope.schema.vocabulary import SimpleTerm from zope.interface import implements from zope.security.management import getInteraction from zope.i18n.negotiator import negotiator from z3c.optionstorage.interfaces import IOptionStorageVocabulary from z3c.optionstorage import queryOptionStorage class OptionStorageVocabulary(object): # Order matters here. We want our multi-view adapter to be chosen # before the IVocabulary default one. implements(IOptionStorageVocabulary, IVocabularyTokenized) def __init__(self, context, name): self.dict = queryOptionStorage(context, name) if self.dict: # Workaround. Hopefully, in the future titles will be # computed as a view. interaction = getInteraction() request = interaction.participations[0] self.language = negotiator.getLanguage(self.dict.getLanguages(), request) self.defaultlanguage = self.dict.getDefaultLanguage() def __contains__(self, key): if self.dict: try: self.dict.getValue(key, self.language) return True except KeyError: try: self.dict.getValue(key, self.defaultlanguage) return True except KeyError: pass return False def getTerm(self, key): if self.dict: try: value = self.dict.getValue(key, self.language) return SimpleTerm(key, title=value) except KeyError: try: value = self.dict.getValue(key, self.defaultlanguage) return SimpleTerm(key, title=value) except KeyError: pass raise LookupError def getTermByToken(self, token): return self.getTerm(token) def __iter__(self): if self.dict: for key in self.dict.getKeys(): try: yield self.getTerm(key) except LookupError: pass def __len__(self): count = 0 if self.dict: marker = object() for key in self.dict.getKeys(): if (self.dict.queryValue(key, self.language, marker) is not marker or self.dict.queryValue(key, self.defaultlanguage, marker) is not marker): count += 1 return count def getDefaultKey(self): if self.dict: return self.dict.getDefaultKey() z3c.optionstorage-1.0.7/src/z3c/optionstorage/__init__.py0000644000177100020040000001503511340100146023264 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 Zope Foundation 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. # ############################################################################## from zope.annotation.interfaces import IAnnotatable, IAnnotations from zope.proxy import removeAllProxies from zope.interface import implements from zope.traversing.api import getParents from persistent.dict import PersistentDict from persistent import Persistent from interfaces import IOptionStorage, IOptionDict from UserDict import IterableUserDict # This key should in theory be z3c.optionstorage, anyone wanting to change it # can write the generation script. OptionStorageKey = "optionstorage" class Table(object): # Based on zope's SecurityMap. def __init__(self): self._byrow = {} self._bycol = {} def __nonzero__(self): return bool(self._byrow) def _changed(self): pass def clear(self): self._byrow.clear() self._bycol.clear() self._changed() def addCell(self, rowkey, colkey, value): row = self._byrow.get(rowkey) if row: if row.get(colkey) is value: return False else: row = self._byrow[rowkey] = {} col = self._bycol.get(colkey) if not col: col = self._bycol[colkey] = {} row[colkey] = value col[rowkey] = value self._changed() return True def delCell(self, rowkey, colkey): row = self._byrow.get(rowkey) if row and (colkey in row): del row[colkey] if not row: del self._byrow[rowkey] col = self._bycol[colkey] del col[rowkey] if not col: del self._bycol[colkey] return True self._changed() return False def queryCell(self, rowkey, colkey, default=None): row = self._byrow.get(rowkey) if row: return row.get(colkey, default) else: return default def getCell(self, rowkey, colkey): marker = object() cell = self.queryCell(rowkey, colkey, marker) if cell is marker: raise KeyError("Invalid row/column pair") return cell def getRow(self, rowkey): row = self._byrow.get(rowkey) if row: return row.items() else: return [] def getCol(self, colkey): col = self._bycol.get(colkey) if col: return col.items() else: return [] def getRowKeys(self): return self._byrow.keys() def getColKeys(self): return self._bycol.keys() def getAllCells(self): res = [] for r in self._byrow.keys(): for c in self._byrow[r].items(): res.append((r,) + c) return res class PersistentTable(Table, Persistent): def _changed(self): self._p_changed = 1 class OptionDict(Persistent): """An option dict. Test that OptionDict does actually provide it's interfaces: >>> o = OptionDict() >>> from zope.interface.verify import verifyObject >>> verifyObject(IOptionDict, o) True """ implements(IOptionDict) def __init__(self): self._defaultkey = None self._defaultlanguage = None self._table = PersistentTable() def getLanguages(self): return self._table.getColKeys() def getDefaultLanguage(self): return self._defaultlanguage def setDefaultLanguage(self, language): self._defaultlanguage = language def getDefaultKey(self): return self._defaultkey def setDefaultKey(self, key): self._defaultkey = key def getKeys(self): return self._table.getRowKeys() def queryValue(self, key, language, default=None): return self._table.queryCell(key, language, default) def getValue(self, key, language): return self._table.getCell(key, language) def addValue(self, key, language, value): self._table.addCell(key, language, value) def delValue(self, key, language): self._table.delCell(key, language) def delAllValues(self): self._table.clear() self._defaultkey = None class OptionStorage(IterableUserDict, object): implements(IOptionStorage) def __init__(self, context): annotations = IAnnotations(removeAllProxies(context)) if OptionStorageKey in annotations: self.data = annotations[OptionStorageKey] else: self.data = annotations[OptionStorageKey] = PersistentDict() def queryOptionStorage(context, name): lookuplist = getParents(context) lookuplist.insert(0, context) for object in lookuplist: object = removeAllProxies(object) if IAnnotatable.providedBy(object): annotations = IAnnotations(object) if OptionStorageKey in annotations: storage = IOptionStorage(object) if name in storage: return storage[name] return None class OptionStorageProperty(object): def __init__(self, name, dictname, islist=False, readonly=False): self._name = name self._dictname = dictname self._islist = islist self._readonly = readonly def __get__(self, object, type_=None): dict = queryOptionStorage(object, self._dictname) if dict: default = dict.getDefaultKey() return getattr(object, self._name, default) def __set__(self, object, value): if self._readonly: raise AttributeError("Attribute '%s' is read-only" % self._name) if type(value) is not list: values = [value] else: values = value dict = queryOptionStorage(object, self._dictname) if dict: keys = dict.getKeys() invalid = [x for x in values if x not in keys] if invalid: raise ValueError("Invalid values: %s" % ", ".join( map(repr, invalid))) if self._islist: value = values setattr(object, self._name, value) z3c.optionstorage-1.0.7/src/z3c/optionstorage/configure.zcml0000644000177100020040000000132111340100146024014 0ustar menesismenesis z3c.optionstorage-1.0.7/src/z3c/optionstorage/interfaces.py0000644000177100020040000000351311340100146023646 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 Zope Foundation 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. # ############################################################################## from zope.interface.common.mapping import IMapping from zope.interface import Interface class IOptionDictRead(Interface): """Option dictionary read interface.""" def getLanguages(): """Return available languages.""" def getDefaultKey(): """Return default key.""" def getKeys(): """Return available keys.""" def queryValue(key, language, default=None): """Return value for key/language pair.""" def getValue(key, language): """Return value for key/language pair.""" class IOptionDictWrite(Interface): """Option dictionary write interface.""" def setDefaultKey(key): """Change default key.""" def addValue(key, language, value): """Add value for a key/language pair.""" def delValue(key, language): """Delete value for a key/language pair.""" def delAllValues(): """Delete all values.""" class IOptionDict(IOptionDictRead,IOptionDictWrite): """Option dictionary.""" class IOptionStorage(IMapping): """Option storage, mapping names to option dictionaries.""" class IOptionStorageVocabulary(Interface): def getDefaultKey(): """Return default key for an option storage vocabulary.""" z3c.optionstorage-1.0.7/src/z3c/optionstorage/meta.zcml0000644000177100020040000000056211340100146022767 0ustar menesismenesis z3c.optionstorage-1.0.7/src/z3c/optionstorage/tests.py0000644000177100020040000000134611340100146022667 0ustar menesismenesis############################################################################## # # Copyright (c) 2007 Zope Foundation 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. # ############################################################################## from zope.testing import doctest def test_suite(): return doctest.DocTestSuite('z3c.optionstorage') z3c.optionstorage-1.0.7/ZopePublicLicense.txt0000644000177100020040000000420311340100146021103 0ustar menesismenesisZope Public License (ZPL) Version 2.1 ------------------------------------- A copyright notice accompanies this license document that identifies the copyright holders. This license has been certified as open source. It has also been designated as GPL compatible by the Free Software Foundation (FSF). Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions in source code must retain the accompanying copyright notice, this list of conditions, and the following disclaimer. 2. Redistributions in binary form must reproduce the accompanying copyright notice, this list of conditions, and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. Names of the copyright holders must not be used to endorse or promote products derived from this software without prior written permission from the copyright holders. 4. The right to distribute this software or to use it for any purpose does not give you the right to use Servicemarks (sm) or Trademarks (tm) of the copyright holders. Use of them is covered by separate agreement with the copyright holders. 5. If any files are modified, you must cause the modified files to carry prominent notices stating that you changed the files and the date of any change. Disclaimer THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. z3c.optionstorage-1.0.7/buildout.cfg0000644000177100020040000000014311340100146017272 0ustar menesismenesis[buildout] develop = . parts = test [test] recipe = zc.recipe.testrunner eggs = z3c.optionstorage z3c.optionstorage-1.0.7/PKG-INFO0000644000177100020040000000366411340100214016066 0ustar menesismenesisMetadata-Version: 1.0 Name: z3c.optionstorage Version: 1.0.7 Summary: Optional Storages -- Persistent, Managable Vocabularies Home-page: http://pypi.python.org/pypi/z3c.optionstorage Author: Zope Corporation and Contributors Author-email: zope-dev@zope.org License: ZPL 2.1 Description: Option Storages are vocabularies that store their values in the ZODB and can be managed during application runtime. ======= CHANGES ======= 1.0.7 (2010-02-21) ------------------ - Remove dependency on zope.app.publisher by using a newer zope.browserpage 1.0.6 (2010-02-20) ------------------ - Remove dependency on zope.app.zapi and zope.deprecation - Replace the use of zope.app.publisher with zope.browserpage 1.0.5 (2010-01-04) ------------------ - Remove dependency on zope.app.schema. 1.0.4 (2007-11-03) ------------------ - Fix up package meta data. 0.1.3 (2007-07-04) ------------------ - Ensure that all package files are included in the egg. 0.1.2 (2007-07-04) ------------------ - Bug fix. 0.1.1 (2007-07-04) ------------------ - Fix packaging data. 0.1.0 (2007-06-22) ------------------ - Initial release. Keywords: zope3 vocabulary zodb managable Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Environment :: Web Environment Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: Zope Public License Classifier: Programming Language :: Python Classifier: Natural Language :: English Classifier: Operating System :: OS Independent Classifier: Topic :: Internet :: WWW/HTTP Classifier: Framework :: Zope3