Edgewall Software

Opened 16 years ago

Last modified 8 years ago

#247 new enhancement

make template objects pickle-able

Reported by: wotevah Owned by: cmlenz
Priority: minor Milestone: 0.9
Component: General Version: 0.4.4
Keywords: pickle Cc:

Description

Pickle refuses to serialize template objects with the following error:

"a class that defines slots without defining getstate cannot be pickled"

It was referring to QName, but after adding getstate() to that it complains about some directives as well.

It would be useful to add the necessary getstate/setstate methods to each class that has slots, so pickle could work. I have thought about writing a filter to replace the offending classes since I've done something similar for consistent charset handling, but use of slots makes QName and the others difficult to subclass and besides, it doesn't seem like the right thing to do.

I know the loader caches templates. I want to have more flexibility in choosing what kind of cache to use, for example a persistent cache using memcached that can be used across different processes and survive restarts.

Change History (4)

comment:1 follow-up: Changed 16 years ago by cmlenz

  • Component changed from Parsing to General
  • Milestone set to 0.6

The “pickle-ability” of templates has improved quite a bit in 0.5 (see for example [831]), but unfortunately still incomplete. One thing it doesn't support is the assignment closure used for py:for and py:with.

This is something that I hope to address in the context of other changes, such as code generation instead of AST transformation.

comment:2 in reply to: ↑ 1 Changed 16 years ago by wotevah

Replying to cmlenz:

The “pickle-ability” of templates has improved quite a bit in 0.5 (see for example [831])

Thank you, I guess I will have to wait. I did notice that in [831] Template.setstate() resets the filter list to default, which is not what I would want - in my framework I always push a filter first, which converts the input charset (based on XML_DECL) to Unicode before _flatten has a chance to str() it and break :) This means after restore that filter is gone.

I am not even sure why Template needs getstate/setstate at all, as it does not appear to define slots and is not the kind of object I'd consider conserving memory with. Is the reason related to the filters, perhaps they aren't easy to save state for ?

comment:3 Changed 15 years ago by cmlenz

  • Milestone changed from 0.6 to 0.7

comment:4 Changed 8 years ago by hodgestar

  • Milestone changed from 0.7 to 0.9

Moved to milestone 0.9.

Note: See TracTickets for help on using tickets.