[Twisted-Python] grokking Cacheable

attempting to grok Cacheable here. . was wondering if someone could show a quick example of its correct use? ----------------------------- attached is what i have so far, just to test. . i am getting this error when the observer is being serialized? ----------------------------------------- 24/10/2002 09:17 [Broker,0,127.0.0.1] twisted.spread.jelly.InsecureJelly: Class not allowed for instance: twisted.spread.flavors.RemoteCacheObserver <RemoteCacheObserver(<twisted.spread.pb.Broker instance at 0x83ab0f4>, <mon.net.rop.Cashew instance at 0x838b5a4>, <mon_server.rop_myApp.Persp instance at 0x83834d4>) at 138104980> ------------------------------- i havent seen any example code in the list, docs, or examples dir about this dark corner of the pb universe, so i thought i'd ask ------------ any elucidation is quite appreciated thanks car

that particular error means that the server class 'mon.net.rop.Cashew' has no registered copier on the client. You need to call pb.setCopierForClass on the client like: from twisted.spread import pb class YourClientClass(pb.RemoteCache): pass pb.setCopierForClass('mon.net.rop.Cashew', YourClientClass) and instances of mon.net.rop.Cashew will be transformed into YourClientClass when they arrive at the client. YourClientClass must be derived from pb.RemoteCache. This appears to be one the most common errors when programming with Cacheables as it occurs not only when you forget to designate a copier, but when an unexpected server object tried to get sent to the client because of a reference of assignment you werent aware of. This is a good security measure :) -----Original Message----- From: twisted-python-admin@twistedmatrix.com [mailto:twisted-python-admin@twistedmatrix.com]On Behalf Of carball@hush.com Sent: Friday, October 25, 2002 1:12 AM To: Twisted-Python@twistedmatrix.com Subject: [Twisted-Python] grokking Cacheable attempting to grok Cacheable here. . was wondering if someone could show a quick example of its correct use? ----------------------------- attached is what i have so far, just to test. . i am getting this error when the observer is being serialized? ----------------------------------------- 24/10/2002 09:17 [Broker,0,127.0.0.1] twisted.spread.jelly.InsecureJelly: Class not allowed for instance: twisted.spread.flavors.RemoteCacheObserver <RemoteCacheObserver(<twisted.spread.pb.Broker instance at 0x83ab0f4>, <mon.net.rop.Cashew instance at 0x838b5a4>, <mon_server.rop_myApp.Persp instance at 0x83834d4>) at 138104980> ------------------------------- i havent seen any example code in the list, docs, or examples dir about this dark corner of the pb universe, so i thought i'd ask ------------ any elucidation is quite appreciated thanks car

Sean Riley wrote:
That's why I tend to not use the default implementation of getStateToCacheAndObserveFor and now explicitly list out which attributes I want to transmit. (Although in some cases, I'm also transforming the data into a different format for the client-side representation as well.) - Bruce

On Fri, 25 Oct 2002 09:16:08 -0600, Bruce Mitchener <bruce@cubik.org> wrote:
Just thought I'd chime in and explain why this is an especially good idea ;-). For both Copyables and Cacheables, it's good to be nice and explicit about what you want sent vs. what you don't; so not accepting the default is definitely a good idea. By transforming the data for client-side representation you not only save potentially unnecessary space and prevent errors that result from copying unknown types, you also make your application easier to interface to from other programming languages, because it's obvious what that language should expect in a copied structure from you. In Cacheables this is even more true because you typically don't want to lose the "observer" object, which is ignored by the default implementation. -- | <`'> | Glyph Lefkowitz: Travelling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |

that particular error means that the server class 'mon.net.rop.Cashew' has no registered copier on the client. You need to call pb.setCopierForClass on the client like: from twisted.spread import pb class YourClientClass(pb.RemoteCache): pass pb.setCopierForClass('mon.net.rop.Cashew', YourClientClass) and instances of mon.net.rop.Cashew will be transformed into YourClientClass when they arrive at the client. YourClientClass must be derived from pb.RemoteCache. This appears to be one the most common errors when programming with Cacheables as it occurs not only when you forget to designate a copier, but when an unexpected server object tried to get sent to the client because of a reference of assignment you werent aware of. This is a good security measure :) -----Original Message----- From: twisted-python-admin@twistedmatrix.com [mailto:twisted-python-admin@twistedmatrix.com]On Behalf Of carball@hush.com Sent: Friday, October 25, 2002 1:12 AM To: Twisted-Python@twistedmatrix.com Subject: [Twisted-Python] grokking Cacheable attempting to grok Cacheable here. . was wondering if someone could show a quick example of its correct use? ----------------------------- attached is what i have so far, just to test. . i am getting this error when the observer is being serialized? ----------------------------------------- 24/10/2002 09:17 [Broker,0,127.0.0.1] twisted.spread.jelly.InsecureJelly: Class not allowed for instance: twisted.spread.flavors.RemoteCacheObserver <RemoteCacheObserver(<twisted.spread.pb.Broker instance at 0x83ab0f4>, <mon.net.rop.Cashew instance at 0x838b5a4>, <mon_server.rop_myApp.Persp instance at 0x83834d4>) at 138104980> ------------------------------- i havent seen any example code in the list, docs, or examples dir about this dark corner of the pb universe, so i thought i'd ask ------------ any elucidation is quite appreciated thanks car

Sean Riley wrote:
That's why I tend to not use the default implementation of getStateToCacheAndObserveFor and now explicitly list out which attributes I want to transmit. (Although in some cases, I'm also transforming the data into a different format for the client-side representation as well.) - Bruce

On Fri, 25 Oct 2002 09:16:08 -0600, Bruce Mitchener <bruce@cubik.org> wrote:
Just thought I'd chime in and explain why this is an especially good idea ;-). For both Copyables and Cacheables, it's good to be nice and explicit about what you want sent vs. what you don't; so not accepting the default is definitely a good idea. By transforming the data for client-side representation you not only save potentially unnecessary space and prevent errors that result from copying unknown types, you also make your application easier to interface to from other programming languages, because it's obvious what that language should expect in a copied structure from you. In Cacheables this is even more true because you typically don't want to lose the "observer" object, which is ignored by the default implementation. -- | <`'> | Glyph Lefkowitz: Travelling Sorcerer | | < _/ > | Lead Developer, the Twisted project | | < ___/ > | http://www.twistedmatrix.com |
participants (4)
-
Bruce Mitchener
-
carball@hush.com
-
Glyph Lefkowitz
-
Sean Riley