Edgewall Software

Ticket #41 (closed enhancement: fixed)

Opened 9 years ago

Last modified 9 years ago

[PATCH] Implement a `text` serialization method

Reported by: cboos Owned by: cmlenz
Priority: major Milestone: 0.3
Component: Template processing Version: 0.2
Keywords: Cc:


While it's possible to use the XML serializer to produce text by stripping the toplevel tag away (e.g. see Trac's revisionlog.txt) and, in more complex cases, post-processing the output (see Trac's notification.py).

It would be useful to simply have a serializer which takes care of all the details.


text_serializer-r248.patch Download (2.8 KB) - added by cboos 9 years ago.
Implementation of this feature on top of r248.

Change History

Changed 9 years ago by cboos

Implementation of this feature on top of r248.

Changed 9 years ago by cmlenz

  • priority changed from minor to major
  • status changed from new to assigned
  • type changed from defect to enhancement

Very nice, thanks!

The only problem I see with this is that in Stream.render(), if you use a legacy charset such as ISO-8859-1, non-representable characters will be replaced by XML character entities. That's likely not the expected result for plain text… but what would the expected result be, then? "replace" mode?

Changed 9 years ago by cboos

I'm not sure it's a real problem, as the workaround is easy. Instead of:

  template.render('txt', encoding='latin-1')

which may produce those character entities, one would have to use:

  template.render('txt', encoding=None).encode('latin-1', 'replace')

Of course, when the encoding parameter is not used, there won't be any problem as the default is "utf-8", which can encode all the unicode code points.

So I think it would be enough to document that clearly in the @param encoding section of the render method.

Changed 9 years ago by cmlenz

  • status changed from assigned to closed
  • resolution set to fixed

Implemented in [250].

I've changed the TextSerializer to not inherit from XMLSerializer, because that does a lot more work than necessary.

Also, I've modified Stream.render() to use “replace” instead of “xmlcharrefreplace” if method is “text”.
Did that before I read your comment. Doesn't feel that clean, so maybe I'll back that out again.

Changed 9 years ago by cboos

Well, either way. I'm also happy with r250 :)

Add/Change #41 ([PATCH] Implement a `text` serialization method)


E-mail address and user name can be saved in the Preferences.

Change Properties
<Author field>
as closed
The resolution will be deleted. Next status will be 'reopened'
Note: See TracTickets for help on using tickets.