Andrii,
Thanks for catching this.
That fix seems good to me. I've added it. It's basically your fix,
I believe, with a little bit of extra caution added to protect
against converting a string that is not unicode. Perhaps that
cannot occur, but I worry. Oh, and I used isinstance to check the
type, which I should have done to begin with.
Attached is a patch. And, the change is also at the Bitbucket repo:
https://bitbucket.org/dkuhlman/generateds
Sigh. I finally figured out why my tests did not exhibit this bug.
I was exporting with the standard, unmodified module generated by
generateDS.py. That code uses sys.stdout to write its output, and
apparently the file sys.stdout does not throw an exception when you
write non-ascii, unicode characters to it, whereas a file opened
with open('xxx', 'w') does cause an exception. I wonder how many
more weird things there are for me to learn about unicode?
Thanks again for your help with this.
Dave
On Tue, Jan 17, 2017 at 02:36:26PM +0000, Andrii Iudin wrote:
> Dear Dave,
>
> Many thanks for implementing and providing the fix. It has solved the
> problem with the export part. However, now there is a problem with
> outfile.write(self.convert_unicode(self.valueOf_))
>
> Python seems to be refusing to write unicode into a file. It may be solved
> by encoding to utf-8 in
> def convert_unicode(instring):
> ...
> result = quote_xml(instring).encode('utf8')
>
> Please tell if this looks like a reasonable solution.
>
> Also, thank you for praising the EBI site! Even though we do only a part of
> the work (there are many teams here responsible for different services), it
> is very nice to hear.
>
> Best regards,
> Andrii
>
> On 17/01/2017 00:20, Dave Kuhlman wrote:
> >generateDS.py is attached.
> >
> >Dave
> >
>
--
Dave Kuhlman
http://www.davekuhlman.org
diff -r 9de33b2d129a generateDS.py
--- a/generateDS.py Mon Jan 16 16:01:58 2017 -0800
+++ b/generateDS.py Tue Jan 17 12:49:17 2017 -0800
@@ -5334,10 +5334,10 @@
return instring
@staticmethod
def convert_unicode(instring):
- if (type(instring) is str or
- (sys.version_info.major == 2
- and type(instring) == unicode)):
+ if isinstance(instring, str):
result = quote_xml(instring)
+ elif sys.version_info.major == 2 and isinstance(instring, unicode):
+ result = quote_xml(instring).encode('utf8')
else:
result = GeneratedsSuper.gds_encode(str(instring))
return result
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, SlashDot.org! http://sdm.link/slashdot
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users