Craig,

I'm not sure what your use case is, but as an alternative, you might try
using the "etree" export.  So generate the bindings like:

generateDS.py -qf -o foo.py --external-encoding='utf-8' --export="write
etree" foo.xsd


Then use the attached mintest-2.py file to write out your file.  As far as
I can tell, it successfully writes out the XML.  You will need lxml, which
I believe most distributions should have.

Hope this helps,
Logan


On Thu, Aug 29, 2013 at 8:58 PM, W. Craig Trader <craig.tra...@gmail.com>wrote:

> I have an application that needs to write I18N data to XML, using UTF-8
> encoding, running on Python 2.7.  See attached schema, and example
> program.  I generated the foo.py wrapper as follows:
>
> generateDS.py -qf -o foo.py --external-encoding='utf-8' --export="write"
> foo.xsd
>
> When I run the test program, I get the following error:
>
> Traceback (most recent call last):
>   File "mintest.py", line 15, in <module>
>     a.export( out, 0 )
>   File "/home/ctrader/src/gds-test/foo.py", line 648, in export
>     self.exportChildren(outfile, level + 1, namespace_, name_,
> pretty_print=pretty_print)
>   File "/home/ctrader/src/gds-test/foo.py", line 668, in exportChildren
>     outfile.write('<%sfoo>%s</%sfoo>%s' % (namespace_,
> self.gds_format_string(quote_xml(self.foo).encode(ExternalEncoding),
> input_name='foo'), namespace_, eol_))
>   File "/home/ctrader/foo/lib/python2.7/codecs.py", line 691, in write
>     return self.writer.write(data)
>   File "/home/ctrader/foo/lib/python2.7/codecs.py", line 351, in write
>     data, consumed = self.encode(object, self.errors)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xd9 in position 5:
> ordinal not in range(128)
>
> After a long debugging session, I determined that the problem is that the
> code that generateDS generates for the export methods uses regular strings,
> not unicode strings, for its constants.  When you concatenate 'aaa' + X +
> 'ccc', it works fine, as long as X is a regular string, or a unicode string
> containing only ASCII characters. When X isn't ASCII, you get the exception
> I noted above.
>
> For my short-term problem, I went through the entire generateDS.py program
> and converted every statement that emits code for the wrapper classes to
> emit unicode constants instead of string constants, and got rid of the
> calls to gds_format_string(), but that's not a good long-term fix.
>
> Can anyone suggest a better solution?
>
> Other problems observed:
>
>    - gDS doesn't generate the <?xml ?> directive at the start of the
>    export.
>    - gDS does not deal well with complex namespaces in schemas.
>
> I worked around both of those by writing my data to a string, and then
> massaging the string before writing the result to a file.  Again, it works
> in the short-term, but isn't a long-term solution.
>
> - Craig -
>
>
>
>
> ------------------------------------------------------------------------------
> Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
> Discover the easy way to master current and previous Microsoft technologies
> and advance your career. Get an incredible 1,500+ hours of step-by-step
> tutorial videos with LearnDevNow. Subscribe today and save!
> http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
> _______________________________________________
> generateds-users mailing list
> generateds-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/generateds-users
>
>

Attachment: mintest-2.py
Description: Binary data

------------------------------------------------------------------------------
Learn the latest--Visual Studio 2012, SharePoint 2013, SQL 2012, more!
Discover the easy way to master current and previous Microsoft technologies
and advance your career. Get an incredible 1,500+ hours of step-by-step
tutorial videos with LearnDevNow. Subscribe today and save!
http://pubads.g.doubleclick.net/gampad/clk?id=58040911&iu=/4140/ostg.clktrk
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to