[z3c_pt] Re: __unicode__ and __str__
+1 Malthe Borch wrote: hey list, ––– currently the way we insert dynamic values as text into the template write stream is to first check if its a string at all (it could be an integer number), and if not, we convert it using ``str``. we perform this check using ``isinstance`` (first for ``unicode``, then ``str``); perhaps we should consider checking for ``__unicode__`` and ``__str__``; or, as a rule, always call them if present. I need to prototype this idea, in particular for speed, but I think it could open up for some interesting usage; and ``isinstance`` is rather lame, anyway. \malthe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups z3c.pt group. To post to this group, send email to z3c_pt@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/z3c_pt?hl=en -~--~~~~--~~--~--~---
[z3c_pt] Re: __unicode__ and __str__
Malthe Borch wrote: currently the way we insert dynamic values as text into the template write stream is to first check if its a string at all (it could be an integer number), and if not, we convert it using ``str``. we perform this check using ``isinstance`` (first for ``unicode``, then ``str``); perhaps we should consider checking for ``__unicode__`` and ``__str__``; or, as a rule, always call them if present. Didn't we decide to drop support for non-unicode string insertion already? I was under the impression that we shouldn't deal with encoding conversions at all inside the machinery. zope.tal and friends have a clear Unicode-only policy as well. In that case a simple (pseudo code): text = 'a' if isinstance(text, unicode): _write(text) else: _write(unicode(text)) should be enough, shouldn't it? Feel free to experiment with using __unicode__ instead, but I have a feeling that checking for the attribute existence, checking if it is a callable and calling it, is more expensive. Hanno --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups z3c.pt group. To post to this group, send email to z3c_pt@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/z3c_pt?hl=en -~--~~~~--~~--~--~---
[z3c_pt] Re: __unicode__ and __str__
2008/10/26 Hanno Schlichting [EMAIL PROTECTED]: That should have next to no performance impact and should work in all cases (except byte-strings). Yes, this should work for the unicode-only version; in theory, the engine supports an encoded-mode, where it deals with strings. I'd have to look closer for this one. Let's prototype the idea and see what we come up with. \malthe --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups z3c.pt group. To post to this group, send email to z3c_pt@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/z3c_pt?hl=en -~--~~~~--~~--~--~---