~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to twisted/spread/publish.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2004-06-21 22:01:11 UTC
  • mto: (2.2.3 sid)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040621220111-vkf909euqnyrp3nr
Tags: upstream-1.3.0
ImportĀ upstreamĀ versionĀ 1.3.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Twisted, the Framework of Your Internet
 
2
# Copyright (C) 2001 Matthew W. Lefkowitz
 
3
 
4
# This library is free software; you can redistribute it and/or
 
5
# modify it under the terms of version 2.1 of the GNU Lesser General Public
 
6
# License as published by the Free Software Foundation.
 
7
 
8
# This library is distributed in the hope that it will be useful,
 
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
# Lesser General Public License for more details.
 
12
 
13
# You should have received a copy of the GNU Lesser General Public
 
14
# License along with this library; if not, write to the Free Software
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
16
 
 
17
"""
 
18
 
 
19
Persistently cached objects for PB.
 
20
 
 
21
Maintainer: U{Glyph Lefkowitz<mailto:glyph@twistedmatrix.com>}
 
22
 
 
23
Stability: semi-stable
 
24
 
 
25
Future Plans: None known.
 
26
"""
1
27
 
2
28
# Twisted imports
3
 
from twisted.python import defer
 
29
from twisted.internet import defer
4
30
 
5
31
# sibling imports
6
32
import jelly
9
35
 
10
36
# System Imports
11
37
import time
12
 
import copy
13
38
 
14
39
class Publishable(flavors.Cacheable):
15
40
    """An object whose cached state persists across sessions.
68
93
        try:
69
94
            data = open(self.getFileName()).read()
70
95
        except IOError:
71
 
            print "** Didn't find the file."
72
96
            recent = 0
73
97
        else:
74
98
            newself = jelly.unjelly(banana.decode(data))
75
 
            print '** Found the file.'
76
99
            recent = (newself.timestamp == self.timestamp)
77
 
            print '** ', newself.timestamp, self.timestamp, recent
78
100
        if recent:
79
101
            self._cbGotUpdate(newself.__dict__)
80
102
            self._wasCleanWhenLoaded = 1
82
104
            self.remote.callRemote('getStateToPublish').addCallbacks(self._cbGotUpdate)
83
105
 
84
106
    def __getstate__(self):
85
 
        other = copy.copy(self.__dict__)
 
107
        other = self.__dict__.copy()
86
108
        # Remove PB-specific attributes
87
109
        del other['broker']
 
110
        del other['remote']
88
111
        del other['luid']
89
112
        # remove my own runtime-tracking stuff
90
113
        del other['_activationListeners']
120
143
    expects a RemotePublished as a result.  This will allow you to wait until
121
144
    the result is really available.
122
145
 
123
 
    Idiomatic usage would look like:
 
146
    Idiomatic usage would look like::
124
147
 
125
148
        publish.whenReady(serverObject.getMeAPublishable()).addCallback(lookAtThePublishable)
126
149
    """
127
150
    d2 = defer.Deferred()
128
 
    d.addCallbacks(_pubReady, d2.armAndErrback,
 
151
    d.addCallbacks(_pubReady, d2.errback,
129
152
                   callbackArgs=(d2,))
130
153
    return d2
131
154
 
132
155
def _pubReady(result, d2):
133
156
    '(internal)'
134
 
    result.callWhenActivated(d2.armAndCallback)
 
157
    result.callWhenActivated(d2.callback)