[Zope-Checkins] CVS: Zope3/lib/python/Zope/App/Security - LocalSecurityMap.py:1.1.2.1

Anthony Baxter anthony@interlink.com.au
Fri, 8 Feb 2002 14:16:56 -0500


Update of /cvs-repository/Zope3/lib/python/Zope/App/Security
In directory cvs.zope.org:/tmp/cvs-serv16303

Added Files:
      Tag: Zope-3x-branch
	LocalSecurityMap.py 
Log Message:
new class: LocalSecurityMap. Unlike SecurityMap, which just notes that
a particular row/entry has an entry, this one actually stores a value to
go with it, for instance Allow/Deny, or Assign/Remove


=== Added File Zope3/lib/python/Zope/App/Security/LocalSecurityMap.py ===
# LocalSecurityMap
#
# Copyright (c) 2001 Zope Coporation and Contributors.  All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 1.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.

""" Generic three dimensional array type """


class LocalSecurityMap:
   
    def __init__(self):
        self._clear()

    def _clear(self):
        self._byrow = {}
        self._bycol = {}

    def addCell(self, rowentry, colentry, value):
        row = self._byrow.setdefault(rowentry, {})
        row[colentry] = value

        col = self._bycol.setdefault(colentry, {})
        col[rowentry] = value

    def delCell(self, rowentry, colentry):
        row = self._byrow.get(rowentry)
        if row and row.has_key(colentry):
            del self._byrow[rowentry][colentry]
            del self._bycol[colentry][rowentry]

    def getCell(self, rowentry, colentry, default=None):
        " return the value of a cell by row, entry "
        row = self._byrow.get(rowentry)
        if row: return row.get(colentry, default)

    def getRow(self, rowentry):
        " return a list of (colentry, value) tuples from a row "
        row = self._byrow.get(rowentry)
        if row:
            return row.items()

    def getCol(self, rowentry):
        " return a list of (rowentry, value) tuples from a col "
        col = self._bycol.get(colentry)
        if col:
            return col.items()