> From: Al Niessner <[EMAIL PROTECTED]>
> To: Dave Kuhlman <[EMAIL PROTECTED]>
> Cc: "[email protected]"
> <[email protected]>
> Sent: Monday, December 1, 2008 1:41:12 PM
> Subject: Re: [Generateds-users] Unicode problem
>
>
> Here is the stack output. I will trace it out tomorrow and see what I
> can do with it. It does not look positive because it seems to be a deep
> rooted Python thing. I will get back to you though.
>
[snip]
> File "/tmp/Test71/SciPyScripts/communicationsInterface.py", line 939,
> in exportChildren
> outfile.write('<%srequest>%s\n' % (namespace_,
> quote_xml(self.get_request()), namespace_))
> UnicodeEncodeError: 'ascii' codec can't encode character u'\xb5' in
> position 18: ordinal not in range(128)
So, we have a unicode character. Before writing it out, we need to
encode it in some external character set. Consider the following:
>>> a = u'\xb5'
>>>
>>> print a
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeEncodeError: 'ascii' codec can't encode character u'\xb5' in
position 0: ordinal not in range(128)
>>>
>>> print a.encode('utf-8')
ยต
>>>
(Not sure whether the mu/micro symbol will show up in email.)
Suggestion -- You might try using the -s and the --super flags to
generateDS.py. That will generate a sub-class module that will
import your (main) generated file. Then in the sub-class where the
problem occurs, copy and modify the export method from the
super-class. Add something like the ".encode('utf-8')" to that
method. Now, process your XML with the sub-class module/file.
Once you get that working, let's talk about whether generateDS.py
should be modified so that it generates code that handles this
situation automatically and without modifications to a generated
file.
A bit of excuse making -- I had zero understanding of unicode when
I initially started work on generateDS.py. Now, at least, I have a
smidgen.
And, here is a Web page that I found very helpful:
http://farmdev.com/talks/unicode/
Excuse me if I'm insulting you here. I don't know where you are on
the unicode learning curve.
- Dave
--
Dave Kuhlman
http://www.rexx.com/~dkuhlman
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
generateds-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/generateds-users