[Twisted-Python] Question about Foolscap Slicers and Unslicers.

kgi iacovou at gmail.com
Fri Feb 9 13:05:29 EST 2007

Hi all (and Brian in particular);

I've got a few questions about Foolscap Slicers and Unslicers. The 
documentation I'm reading is at:


In it, a code fragment of custom slicing is given:

    class ListSlicer(BaseSlicer):
        opentype = ("list",)
        slices = list

The docs then say in the next paragraph:

Slicer registration can be either explicit or implicit. In this example, an 
implicit registration is used: by setting the slices attribute to the list 
type, the BaseSlicer's metaclass automatically registers the mapping from 
list to ListSlicer.

To explicitly register a slicer, just leave opentype set to None (to disable 
auto-registration), and then register the slicer manually.

... and then quote an example of this:

    class TupleSlicer(BaseSlicer):
        opentype = ("tuple",)
        slices = None
    registerAdapter(TupleSlicer, tuple, pb.ISlicer)

The problem is that the code sets *slices* to None, but the text talks about 
setting *opentype* to None. I'd be inclined to think the code is right, 
except the text says the same sort of thing happens later on when talking 
about Unslicers:

If the Unslicer has a non-None class attribute named opentype, then it is 
automatically registered. If it does not have this attribute (or if it is set 
to None), then no registration is performed, and the Unslicer must be 
manually registered:

Which is it?

Actually, my real question is: what are the exact uses of "opentype" 
and "slices" respectively? I suspect that "slices" refers to the type being 
sliced, and "opentype" is something low-level to do with the slicing process 
(maybe the symbol inserted in the output stream?). Why is is (seemingly 
always) a 1-tuple?

Lastly (secondly?) there is some text in the document:


under the paragraph heading, "Arbitrary Instances are NOT serialized" that 

Both ends must be willing to transport the object. The sending side expresses 
this by marking the class (subclassing Copyable, or registering an ISlicer 

To me this appears to imply that each of the various ways of transporting a 
non-fundamental type is as good as any other: if I have a subclassed Copyable 
then I wouldn't need an ISlicer adapter, and vice versa.

Is this true? Does this mutual relationship hold true for ISlicer-registered 
types and types making use of foolscap.registerRemoteCopyFactory()? I'm 
asking because I have some types for which I have called 
registerRemoteCopyFactory() yet for which I get an exception saying that the 
object is not sliceable (implying that I need to take the ISlicer approach 
and that the registerRemoteCopyFactory() approach is no longer good enough).

I'm using Python 2.4, Twisted 2.5.0 and head-of-SVN Foolscap.



More information about the Twisted-Python mailing list