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

Barry Warsaw barry@wooz.org
Thu, 13 Dec 2001 13:02:40 -0500


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

Added Files:
      Tag: Zope-3x-branch
	SecurityMap.py 
Log Message:
New base class for all *Map classes


=== Added File Zope3/lib/python/Zope/App/Security/SecurityMap.py ===
# SecurityMap.py
#
# 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 symmetric one-to-many id map."""


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

    def addCell(self, rowentry, colentry):
        """Add a cell to the table."""
        self._byrow.setdefault(rowentry, []).append(colentry)
        self._bycol.setdefault(colentry, []).append(rowentry)

    def getColumnsForRow(self, rowentry):
        """Return a list of column entries for a given row entry.

        If the row entry is not in the table, return an empty list.
        """
        return self._byrow.get(rowentry, [])

    def getRowsForColumn(self, colentry):
        """Return a list of row entries for a given column entry.

        If the column entry is not in the table, return an empty list.
        """
        return self._bycol.get(colentry, [])

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