[Zope3-checkins] CVS: Zope3/src/zope/fssync/server - __init__.py:1.1 entryadapter.py:1.1 interfaces.py:1.1

Fred L. Drake, Jr. fred at zope.com
Tue Jan 13 14:32:26 EST 2004


Update of /cvs-repository/Zope3/src/zope/fssync/server
In directory cvs.zope.org:/tmp/cvs-serv19335/src/zope/fssync/server

Added Files:
	__init__.py entryadapter.py interfaces.py 
Log Message:
rename z.a.fssync.classes to z.fssync.entryadapter


=== Added File Zope3/src/zope/fssync/server/__init__.py ===
#
# This file is necessary to make this directory a package.


=== Added File Zope3/src/zope/fssync/server/entryadapter.py ===
##############################################################################
#
# Copyright (c) 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.
#
##############################################################################
"""Filesystem synchronization classes.

$Id: entryadapter.py,v 1.1 2004/01/13 19:32:24 fdrake Exp $
"""

from zope.component import queryAdapter
from zope.fssync.server.interfaces import IObjectFile
from zope.interface import implements
from zope.proxy import removeAllProxies
from zope.xmlpickle import toxml

from zope.app.fssync import fspickle
from zope.app.interfaces.annotation import IAnnotations

class AttrMapping(object):
    """Convenience object implementing a mapping on selected object attributes
    """

    def __init__(self, context, attrs):
        self.attrs = attrs
        self.context = context

    def __getitem__(self, name):
        if name in self.attrs:
            return getattr(self.context, name)
        raise KeyError, name

    def get(self, name, default=None):
        if name in self.attrs:
            return getattr(self.context, name, default)
        return default

    def __contains__(self, name):
        return (name in self.attrs) and hasattr(self.context, name)

    def __delitem__(self, name):
        if name in self.attrs:
            delattr(self.context, name)
            return
        raise KeyError, name

    def __setitem__(self, name, value):
        if name in self.attrs:
            setattr(self.context, name, value)
            return
        raise KeyError, name

    def __iter__(self):
        return iter(self.attrs)

class ObjectEntryAdapter(object):
    """Convenience Base class for ObjectEntry adapter implementations."""

    def __init__(self, context):
        self.context = context

    def extra(self):
        "See IObjectEntry"
        return None

    def annotations(self):
        "See IObjectEntry"
        return queryAdapter(self.context, IAnnotations)

    def typeIdentifier(self):
        "See IObjectEntry"
        class_ = self.context.__class__
        return "%s.%s" % (class_.__module__, class_.__name__)

    def factory(self):
        "See IObjectEntry"
        # Return the dotted class name, assuming that it can be used
        class_ = self.context.__class__
        return "%s.%s" % (class_.__module__, class_.__name__)

class DefaultFileAdpater(ObjectEntryAdapter):
    """Default File-system representation for objects."""

    implements(IObjectFile)

    def __init__(self, context):
        # XXX for now, remove all proxies.
        ObjectEntryAdapter.__init__(self, removeAllProxies(context))

    def getBody(self):
        "See IObjectFile"
        s = fspickle.dumps(self.context)
        return toxml(s)

    def setBody(self, body):
        "See IObjectFile"
        raise NotImplementedError

    def factory(self):
        "See IObjectEntry"
        # We have no factory, cause we're a pickle.
        return None

    def annotations(self):
        # The annotations are already stored in the pickle.
        # This is only the right thing if the annotations are
        # stored in the object's attributes (such as IAttributeAnnotatable);
        # if that's not the case, then either this method needs to be
        # overridden or this class shouldn't be used.
        return None


=== Added File Zope3/src/zope/fssync/server/interfaces.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.
#
##############################################################################
"""Interfaces for filesystem synchronization.

$Id: interfaces.py,v 1.1 2004/01/13 19:32:24 fdrake Exp $
"""

from zope.interface import Interface


class IObjectEntry(Interface):
    """File-system object representation."""

    def extra():
        """Return extra data for the entry.

        The data are returned as a mapping object that allows *both*
        data retrieval and setting.  The mapping is from names to
        objects that will be serialized to or from the file system.
        """

    def annotations():
        """Returns annotations data for the entry.

        This behaves similar to extra().  The default implementation
        might return queryAdapter(obj, IAnnotations).
        """

    def typeIdentifier():
        """Return a dotted name that identifies the object type.

        This is typically a dotted class name.

        This is used when synchronizing from the file system to the
        database to decide whether the existing object and the new
        object are of the same type.
        """

    def factory():
        """Return the dotted name of a factory to recreate an empty entry.

        The factory will be called with no arguments. It is usually
        the dotted name of the object class.
        """


class IObjectFile(IObjectEntry):
    """File-system object representation for file-like objects."""

    def getBody():
        """Return the file body."""

    def setBody(body):
        """Change the file body."""


class IObjectDirectory(IObjectEntry):
    """File-system object representation for directory-like objects."""

    def contents():
        """Return the contents.

        A sequence of name, value object are returned. The value in each
        pair will be syncronized.
        """


class IContentDirectory(IObjectDirectory):
    """Marker interface for synchronization of content containers.

    Any container type object should implement this interface
    verifying if the objects are of container types.
    """




More information about the Zope3-Checkins mailing list