[Zope-Checkins] CVS: Zope3/lib/python/Zope/Publisher - RequestDataProperty.py:1.1.2.1
Jim Fulton
jim@zope.com
Mon, 25 Mar 2002 18:26:39 -0500
Update of /cvs-repository/Zope3/lib/python/Zope/Publisher
In directory cvs.zope.org:/tmp/cvs-serv30818
Added Files:
Tag: Zope3-publisher-refactor-branch
RequestDataProperty.py
Log Message:
Added module to support read-only request properties
=== Added File Zope3/lib/python/Zope/Publisher/RequestDataProperty.py ===
##############################################################################
#
# Copyright (c) 2001, 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
#
##############################################################################
"""
Revision information:
$Id: RequestDataProperty.py,v 1.1.2.1 2002/03/25 23:26:38 jim Exp $
"""
class RequestDataGetter(object):
def __init__(self, request):
self.__get = getattr(request, self._gettrname)
def __getitem__(self, name):
return self.__get(name)
def get(self, name, default=None):
return self.__get(name, default)
class RequestDataMapper(object):
def __init__(self, request):
self.__map = getattr(request, self._mapname)
def __getitem__(self, name):
return self.__map[name]
def get(self, name, default=None):
return self.__map.get(name, default)
def keys(self): return self.__map.keys()
def items(self): return self.__map.items()
def values(self): return self.__map.values()
def __len__(self): return len(self.__map)
class RequestDataProperty(object):
def __init__(self, gettr_class):
self.__gettr_class = gettr_class
def __get__(self, request, rclass=None):
if request is not None:
return self.__gettr_class(request)
def __set__(*args):
raise AttributeError, 'Unassignable attribute'