~cjwatson/lazr.lifecycle/zope.lifecycleevent-4.2.0-compat

« back to all changes in this revision

Viewing changes to src/lazr/lifecycle/snapshot.py

  • Committer: Brad Crittenden
  • Date: 2009-12-04 15:37:40 UTC
  • mfrom: (34.1.4 snapshot)
  • Revision ID: bac@canonical.com-20091204153740-h8bq1wk16guxlfk7
Tags: 1.1
[r=gary_poster][bug=488762] Create 'doNotSnapshot' and exclude fields so marked from the snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 
22
22
__metaclass__ = type
23
23
 
24
 
__all__ = ['SnapshotCreationError',
25
 
           'Snapshot',
26
 
           ]
 
24
__all__ = [
 
25
    'doNotSnapshot',
 
26
    'SnapshotCreationError',
 
27
    'Snapshot',
 
28
    ]
27
29
 
28
30
from zope.component import queryAdapter
29
31
from zope.interface.interfaces import IInterface
30
 
from zope.interface import directlyProvides
 
32
from zope.interface import alsoProvides, directlyProvides
31
33
from zope.schema.interfaces import IField
 
34
from zope.schema import Field
32
35
from zope.security.proxy import removeSecurityProxy
33
36
 
34
 
from lazr.lifecycle.interfaces import ISnapshotValueFactory
 
37
from lazr.lifecycle.interfaces import (
 
38
    IDoNotSnapshot, ISnapshotValueFactory)
 
39
 
35
40
 
36
41
_marker = object()
37
42
 
38
43
 
 
44
def doNotSnapshot(field):
 
45
    """Simple wrapper method to provide `IDoNotSnapshot`."""
 
46
    alsoProvides(field, IDoNotSnapshot)
 
47
    return field
 
48
 
 
49
 
39
50
class SnapshotCreationError(Exception):
40
51
    """Something went wrong while creating a snapshot."""
41
52
 
66
77
            for iface in providing:
67
78
                for name in iface.names(all=True):
68
79
                    field = iface[name]
69
 
                    if IField.providedBy(field):
 
80
                    if (IField.providedBy(field) and
 
81
                        not IDoNotSnapshot.providedBy(field)):
70
82
                        names.add(name)
71
83
 
72
84
        for name in names: