#41 closed enhancement (fixed)
[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: |
Description
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.
Attachments (1)
Change History (5)
Changed 18 years ago by cboos
comment:1 Changed 18 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?
comment:2 Changed 18 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.
comment:3 Changed 18 years ago by cmlenz
- Resolution set to fixed
- Status changed from assigned to closed
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.
comment:4 Changed 18 years ago by cboos
Well, either way. I'm also happy with r250 :)
Implementation of this feature on top of r248.