[Zope3-checkins] CVS: Zope3/src/persistence - wrapper.py:1.1.2.1

Jim Fulton jim at zope.com
Tue Oct 7 05:40:18 EDT 2003


Update of /cvs-repository/Zope3/src/persistence
In directory cvs.zope.org:/tmp/cvs-serv6573/src/persistence

Added Files:
      Tag: schema-utility-struct-failure
	wrapper.py 
Log Message:
Added code to return the proxied object's __class__ attribute. All
proxies should do this.

I think this class is going to need more work. For example, it
probably doesn't handle __call__ properly.  It may need to be
rewritten to use zope.proxy.

We can't expose IPersistent without a special interface
descriptor. Adding this would add too much dependence on
zope.interface. In any case, I'm refactoring interfaces in a major way
right now that would probably require changing this again.

This probably should be moved to zope.app.

Finally, it's silly to have a package with one file.


=== Added File Zope3/src/persistence/wrapper.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.
#
##############################################################################
"""Provide persistent wrappers for objects that cannot derive from
persistence for some reason."""

from persistence import Persistent

class Struct(Persistent):
  """Wraps a non-persistent object, assuming that *all* changes are
  made through external attribute assignments.
  """

  # XXX to do this right and expose both IPersistent and the
  # underlying object's interfaces, we'd need to use a specialized
  # descriptor.  This would create to great a dependency on
  # zope.interface.

  __class__ = property(lambda self: self.__proxied__.__class__)

  def __init__(self, o):
    self.__proxied__ = o

  def __getattr__(self, name):
    if name.startswith('_p_') or name in ['__proxied__']:
      return object.__getattribute__(self, name)
    return getattr(self.__proxied__, name)

  def __setattr__(self, name, v):
    if name.startswith('_p_') or name in ['__proxied__']:
      return Persistent.__setattr__(self, name, v)
    setattr(self.__proxied__, name, v)
    self._p_changed = 1

  def __delattr__(self, name):
    if name.startswith('_p_') or name in ['__proxied__']:
      return Persistent.__delattr__(self, name)
    delattr(self.__proxied__, name, v)
    self._p_changed = 1




More information about the Zope3-Checkins mailing list