Merge lp:~bac/lazr.lifecycle/snapshot into lp:lazr.lifecycle

Proposed by Brad Crittenden
Status: Merged
Merged at revision: not available
Proposed branch: lp:~bac/lazr.lifecycle/snapshot
Merge into: lp:lazr.lifecycle
Diff against target: 159 lines (+46/-12)
5 files modified
src/lazr/lifecycle/NEWS.txt (+6/-0)
src/lazr/lifecycle/docs/snapshot.txt (+12/-5)
src/lazr/lifecycle/interfaces.py (+9/-0)
src/lazr/lifecycle/snapshot.py (+18/-6)
src/lazr/lifecycle/version.txt (+1/-1)
To merge this branch: bzr merge lp:~bac/lazr.lifecycle/snapshot
Reviewer Review Type Date Requested Status
Gary Poster code Approve
Review via email: mp+15612@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Brad Crittenden (bac) wrote :

Add the IDoNotSnapshot marker interface and add support for ignoring fields that provide it.

When taking snapshots by using the 'providing' argument, the user can choose to selectively ignore some fields by:

alsoProvides(ignored_field, IDoNotSnapshot)

lp:~bac/lazr.lifecycle/snapshot updated
37. By Brad Crittenden

Changes from review: provide doNotSnapshot wrapper method, make version 1.1.

Revision history for this message
Gary Poster (gary) wrote :

I like this.

As we discussed on IRC, I think this should be 1.1, not 1.0.1.

Please update the CHANGES file too.

We also agreed that adding a sugar function called doNotSnapshot would be nice, so that the field in the interface could look like this...

  ignore_me = doNotSnapshot(Attribute('ignored attribute'))

...rather than this.

  ignore_me = Attribute('ignored attribute')
  alsoProvides(ignore_me, IDoNotSnapshot)

The mechanism would stay the same: it's just sugar.

Thank you!

Gary

review: Approve (code)
lp:~bac/lazr.lifecycle/snapshot updated
38. By Brad Crittenden

Updated NEWS and reworded a docstring.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/lazr/lifecycle/NEWS.txt'
--- src/lazr/lifecycle/NEWS.txt 2009-08-31 14:37:56 +0000
+++ src/lazr/lifecycle/NEWS.txt 2009-12-03 18:31:09 +0000
@@ -2,6 +2,12 @@
2NEWS for lazr.lifecycle2NEWS for lazr.lifecycle
3=======================3=======================
44
51.1 (2009-12-03)
6================
7
8- Add IDoNotSnapshot and doNotSnapshot to allow the exclusion of
9certain fields.
10
51.0 (2009-08-31)111.0 (2009-08-31)
6================12================
713
814
=== modified file 'src/lazr/lifecycle/docs/snapshot.txt'
--- src/lazr/lifecycle/docs/snapshot.txt 2009-03-05 17:51:50 +0000
+++ src/lazr/lifecycle/docs/snapshot.txt 2009-12-03 18:31:09 +0000
@@ -5,15 +5,17 @@
5initial state of the object before the modifications. The Snapshot class can5initial state of the object before the modifications. The Snapshot class can
6be used to easily represent such states:6be used to easily represent such states:
77
8 >>> from zope.interface import Interface, implements, Attribute8 >>> from zope.interface import (
9 ... alsoProvides, Attribute, Interface, implements)
9 >>> from zope.schema import List, TextLine, Text10 >>> from zope.schema import List, TextLine, Text
10 >>> from lazr.lifecycle.snapshot import Snapshot11 >>> from lazr.lifecycle.snapshot import doNotSnapshot, Snapshot
1112
12 >>> class IFoo(Interface):13 >>> class IFoo(Interface):
13 ... title = TextLine(title=u'My Title')14 ... title = TextLine(title=u'My Title')
14 ... description = Text(title=u'Description')15 ... description = Text(title=u'Description')
15 ... remotes = List(title=u'remotes')16 ... remotes = List(title=u'remotes')
16 ... totals = Attribute('totals')17 ... totals = Attribute('totals')
18 ... ignore_me = doNotSnapshot(Attribute('ignored attribute'))
1719
18 >>> class Foo:20 >>> class Foo:
19 ... implements(IFoo)21 ... implements(IFoo)
@@ -64,7 +66,7 @@
64 ...66 ...
65 SnapshotCreationError: ...67 SnapshotCreationError: ...
6668
67If no names argument is supplied, the snapshot will contain all 69If no names argument is supplied, the snapshot will contain all
68IFields of the specified interface(s).70IFields of the specified interface(s).
6971
70 >>> snapshot = Snapshot(foo, providing=IFoo)72 >>> snapshot = Snapshot(foo, providing=IFoo)
@@ -73,7 +75,7 @@
73 >>> hasattr(snapshot, 'description')75 >>> hasattr(snapshot, 'description')
74 True76 True
7577
76(Totals is not a Fields so isn't copied over).78Totals is not a Fields so isn't copied over.
7779
78 >>> hasattr(snapshot, 'totals')80 >>> hasattr(snapshot, 'totals')
79 False81 False
@@ -82,6 +84,12 @@
82 >>> snapshot.remotes == ["OK"]84 >>> snapshot.remotes == ["OK"]
83 True85 True
8486
87Fields can be explicitly ignored if they provide the IDoNotSnapshot
88interface.
89
90 >>> hasattr(snapshot, 'ignore_me')
91 False
92
85We can also give more than one interface to provide as an iterable. If93We can also give more than one interface to provide as an iterable. If
86we don't specify any names, all the names in the given interfaces will94we don't specify any names, all the names in the given interfaces will
87be copied:95be copied:
@@ -166,4 +174,3 @@
166174
167 >>> getSiteManager().unregisterAdapter(snapshot_iterable)175 >>> getSiteManager().unregisterAdapter(snapshot_iterable)
168 True176 True
169
170177
=== modified file 'src/lazr/lifecycle/interfaces.py'
--- src/lazr/lifecycle/interfaces.py 2009-03-24 16:17:11 +0000
+++ src/lazr/lifecycle/interfaces.py 2009-12-03 18:31:09 +0000
@@ -18,6 +18,7 @@
1818
19__metaclass__ = type19__metaclass__ = type
20__all__ = [20__all__ = [
21 'IDoNotSnapshot',
21 'IObjectCreatedEvent',22 'IObjectCreatedEvent',
22 'IObjectDeletedEvent',23 'IObjectDeletedEvent',
23 'IObjectModifiedEvent',24 'IObjectModifiedEvent',
@@ -57,3 +58,11 @@
57 lookup. The snapshot value is what should be returned from the adapter58 lookup. The snapshot value is what should be returned from the adapter
58 lookup.59 lookup.
59 """60 """
61
62
63class IDoNotSnapshot(Interface):
64 """Marker interface for attributes to exclude from the snapshot.
65
66 Some attributes such as collections should not be included as part of the
67 snapshot as they may be huge and not intrinsic to the object.
68 """
6069
=== modified file 'src/lazr/lifecycle/snapshot.py'
--- src/lazr/lifecycle/snapshot.py 2009-03-24 16:17:11 +0000
+++ src/lazr/lifecycle/snapshot.py 2009-12-03 18:31:09 +0000
@@ -21,21 +21,32 @@
2121
22__metaclass__ = type22__metaclass__ = type
2323
24__all__ = ['SnapshotCreationError',24__all__ = [
25 'Snapshot',25 'doNotSnapshot',
26 ]26 'SnapshotCreationError',
27 'Snapshot',
28 ]
2729
28from zope.component import queryAdapter30from zope.component import queryAdapter
29from zope.interface.interfaces import IInterface31from zope.interface.interfaces import IInterface
30from zope.interface import directlyProvides32from zope.interface import alsoProvides, directlyProvides
31from zope.schema.interfaces import IField33from zope.schema.interfaces import IField
34from zope.schema import Field
32from zope.security.proxy import removeSecurityProxy35from zope.security.proxy import removeSecurityProxy
3336
34from lazr.lifecycle.interfaces import ISnapshotValueFactory37from lazr.lifecycle.interfaces import (
38 IDoNotSnapshot, ISnapshotValueFactory)
39
3540
36_marker = object()41_marker = object()
3742
3843
44def doNotSnapshot(field):
45 """Simple wrapper method to provide `IDoNotSnapshot`."""
46 alsoProvides(field, IDoNotSnapshot)
47 return field
48
49
39class SnapshotCreationError(Exception):50class SnapshotCreationError(Exception):
40 """Something went wrong while creating a snapshot."""51 """Something went wrong while creating a snapshot."""
4152
@@ -66,7 +77,8 @@
66 for iface in providing:77 for iface in providing:
67 for name in iface.names(all=True):78 for name in iface.names(all=True):
68 field = iface[name]79 field = iface[name]
69 if IField.providedBy(field):80 if (IField.providedBy(field) and
81 not IDoNotSnapshot.providedBy(field)):
70 names.add(name)82 names.add(name)
7183
72 for name in names:84 for name in names:
7385
=== modified file 'src/lazr/lifecycle/version.txt'
--- src/lazr/lifecycle/version.txt 2009-08-29 16:09:41 +0000
+++ src/lazr/lifecycle/version.txt 2009-12-03 18:31:09 +0000
@@ -1,1 +1,1 @@
11.011.1

Subscribers

People subscribed via source and target branches