Ian,

Thanks much for catching this and especially for providing these fixes.

I've pushed your changes to Bitbucket at
https://bitbucket.org/dkuhlman/generateds.

I'll make a new release after we've accumulated a few more fixes.

I'm pleased to hear that generateDS.py was helpful.

Thanks again.

Dave

On Tue, Nov 22, 2016 at 11:30:07AM +0000, Ian Glover wrote:
> Hi,
> 
> I've been trying update one of our libraries which uses that uses a 
> GenerateDS generated module to Python 3 (it saved so much time when 
> originally writing this - thank you). I had a couple of problems. 
> 
> First was running under Python3 due to a bytes/string mismatch in 
> process_includes.py: resolve_ref returned a string if the reference was a 
> local file and bytes if it was loaded from a remote URL. I fixed this by 
> patching it as
> 
> 
> --- a/process_includes.py     Thu Nov 17 09:53:36 2016 -0800
> +++ b/process_includes.py     Tue Nov 22 11:19:43 2016 +0000
> @@ -208,7 +208,7 @@
>              else:
>                  if os.path.exists(locn):
>                      infile = open(locn)
> -                    content = infile.read()
> +                    content = infile.read().encode()
>                      infile.close()
>                      params.parent_url = locn
>                      params.base_url = os.path.split(locn)[0]
> @@ -240,11 +240,7 @@
>      save_base_url = params.base_url
>      string_content = resolve_ref(child, params, options)
>      if string_content is not None:
> -        if sys.version_info.major == 2:
> -            root = etree.fromstring(string_content, base_url=params.base_url)
> -        else:
> -            root = etree.fromstring(
> -                string_content.encode(), base_url=params.base_url)
> +        root = etree.fromstring(string_content, base_url=params.base_url)
>          roots.append(root)
>          for child1 in root:
>              if not isinstance(child1, etree._Comment):
> 
> 
> The second was that the generated code used the renamed StringIO library in 
> one place. I fixed this as 
> 
> --- a/generateDS.py   Thu Nov 17 09:53:36 2016 -0800
> +++ b/generateDS.py   Tue Nov 22 11:19:43 2016 +0000
> @@ -5761,8 +5761,12 @@
>  
>  
>  def parseString(inString, silence=False):
> -    from StringIO import StringIO
> -%(preserve_cdata_tags)s    doc = parsexml_(StringIO(inString), parser)
> +    if sys.version_info.major == 2:
> +        from StringIO import StringIO as IOBuffer
> +    else:
> +        from io import BytesIO as IOBuffer
> +
> +%(preserve_cdata_tags)s    doc = parsexml_(IOBuffer(inString), parser)
>      rootNode = doc.getroot()
>      rootTag, rootClass = get_root_tag(rootNode)
>      if rootClass is None:
> 
> When I made these changes I was able to get our libraries tests to pass under 
> Python 2 and 3 with the generated code.
> 
> Hope this is useful. Let me know if there's anything I can do to improve 
> these changes or make them easier to integrate.
> 
> Best Regards,
> Ian
> 
> ------------------------------------------------------------------------------
> _______________________________________________
> generateds-users mailing list
> generateds-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/generateds-users

-- 

Dave Kuhlman
http://www.davekuhlman.org

------------------------------------------------------------------------------
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users

Reply via email to