)]}'
{"virtualbmc/vbmc.py":[{"author":{"_account_id":26340,"name":"Ilya Etingof","email":"etingof@gmail.com","username":"etingof"},"change_message_id":"87687012a15658840abbc455abae46140832c81e","unresolved":false,"context_lines":[{"line_number":105,"context_line":"                # conn.defineXML can\u0027t take bytes but"},{"line_number":106,"context_line":"                # in py3 ET.tostring returns bytes unless \"unicode\""},{"line_number":107,"context_line":"                # in py2 \"unicode\" is unknown so specify \"utf8\" instead"},{"line_number":108,"context_line":"                enc \u003d sys.version_info[0] \u003c 3 and \"utf8\" or \"unicode\""},{"line_number":109,"context_line":"                conn.defineXML(ET.tostring(tree, encoding\u003denc))"},{"line_number":110,"context_line":"        except libvirt.libvirtError:"},{"line_number":111,"context_line":"            LOG.error(\u0027Failed setting the boot device  %(bootdev)s for \u0027"}],"source_content_type":"text/x-python","patch_set":2,"id":"5f7c97a3_013969cd","line":108,"updated":"2018-07-30 14:49:34.000000000","message":"If I read the code correctly, it seems that in Py2 we get serialized unicode string (`bytes`) out of `tostring`, while in Py3 we get original unicode object (e.g. `str`).\n\nThis looks suspiciously asymetrical. Is this how `defineXML` needs to be used in the context of different Pythons?\n\nAlternatively, may be we can get `tostring` to always serialize unicode (into `bytes` on Py3 and `str` on Py2).  If `defineXML` requires non-serialized unicode, just decode whatever `tostring` returns...?","commit_id":"cad28ace1750503abd6808970f96b3b8b30c0d6c"},{"author":{"_account_id":1926,"name":"Derek Higgins","email":"derekh@redhat.com","username":"derekh"},"change_message_id":"65ea44d228041e1adb9c207b43045fec990aa18a","unresolved":false,"context_lines":[{"line_number":105,"context_line":"                # conn.defineXML can\u0027t take bytes but"},{"line_number":106,"context_line":"                # in py3 ET.tostring returns bytes unless \"unicode\""},{"line_number":107,"context_line":"                # in py2 \"unicode\" is unknown so specify \"utf8\" instead"},{"line_number":108,"context_line":"                enc \u003d sys.version_info[0] \u003c 3 and \"utf8\" or \"unicode\""},{"line_number":109,"context_line":"                conn.defineXML(ET.tostring(tree, encoding\u003denc))"},{"line_number":110,"context_line":"        except libvirt.libvirtError:"},{"line_number":111,"context_line":"            LOG.error(\u0027Failed setting the boot device  %(bootdev)s for \u0027"}],"source_content_type":"text/x-python","patch_set":2,"id":"5f7c97a3_45c8bb1e","line":108,"in_reply_to":"5f7c97a3_013969cd","updated":"2018-07-31 08:25:27.000000000","message":"I think you have it the wrong way around, defineXML\nrequires a str type regardless of the python version. It is toString that is behaving differently in py3. Passing in the \"encodng\" parameter make it return a str instead of bytes.","commit_id":"cad28ace1750503abd6808970f96b3b8b30c0d6c"},{"author":{"_account_id":26340,"name":"Ilya Etingof","email":"etingof@gmail.com","username":"etingof"},"change_message_id":"214cd5cd5a55be1e83bb1f2e9dec34fde108859d","unresolved":false,"context_lines":[{"line_number":105,"context_line":"                # conn.defineXML can\u0027t take bytes but"},{"line_number":106,"context_line":"                # in py3 ET.tostring returns bytes unless \"unicode\""},{"line_number":107,"context_line":"                # in py2 \"unicode\" is unknown so specify \"utf8\" instead"},{"line_number":108,"context_line":"                enc \u003d sys.version_info[0] \u003c 3 and \"utf8\" or \"unicode\""},{"line_number":109,"context_line":"                conn.defineXML(ET.tostring(tree, encoding\u003denc))"},{"line_number":110,"context_line":"        except libvirt.libvirtError:"},{"line_number":111,"context_line":"            LOG.error(\u0027Failed setting the boot device  %(bootdev)s for \u0027"}],"source_content_type":"text/x-python","patch_set":2,"id":"5f7c97a3_d07b2af0","line":108,"in_reply_to":"5f7c97a3_45c8bb1e","updated":"2018-07-31 09:54:35.000000000","message":"tl;dr; I think your patch should work! \\o/\n\nHere\u0027s my thinking: looking at the underlying API [1], it seems that at least libvirt itself requires unicode serialized in utf-8.\n\nNow, depending on Python version, serialized unicode is represented differently:\n\n* in Python2 serialized unicode is `str`, non-serialized unicode is type `unicode`\n* in Python3 serialized unicode is `bytes`, non-serialized unicode is type `str`\n\nIf we always pass type `str` to `defineXML`, we actually pass different things:\n\n* in Python2 we pass serialized unicode which is what libvirt seems to want\n* in Python3 we pass unicode object which can\u0027t be directly consumed by libvirt without implicit serialization\n\nIn the latter case it seems that Python 3 C API [2] does unicode-\u003ec-string conversion behind the scenes using `utf-8` serialization which is what we happen to need!\n\n1. https://libvirt.org/html/libvirt-libvirt-domain.html (search `virDomainDefineXML`)\n2. https://docs.python.org/3/c-api/arg.html#strings-and-buffers","commit_id":"cad28ace1750503abd6808970f96b3b8b30c0d6c"}]}
