Vinzenz Feenstra has uploaded a new change for review. Change subject: Replaced String check with string conversion ......................................................................
Replaced String check with string conversion Currently the string_check is destroying the data when the system is not able to convert them properly. This is now fixed by allowing unicode strings as they are and an attempt of decoding input (non-unicode) strings based on the prefered locale encoding. If this will fail, the replacement of unknown characters are applied. In any case an unicode string is created. If the string is not convertible, the return value will be "????" as a replacement. This however is the last resort, to allow at least some level of data to go through. (e.g. when the application list contains one invalid data string currently it would cause the whole list NOT to be sent. Now it will be sent) Please also note that this commit will fix the failing unit tests. Change-Id: Ie277069cbfa39f9735a2b85b9e9da9c3fcfe5938 Signed-off-by: Vinzenz Feenstra <vfeen...@redhat.com> --- M ovirt-guest-agent/VirtIoChannel.py 1 file changed, 8 insertions(+), 9 deletions(-) git pull ssh://gerrit.ovirt.org:29418/ovirt-guest-agent refs/changes/53/19053/1 diff --git a/ovirt-guest-agent/VirtIoChannel.py b/ovirt-guest-agent/VirtIoChannel.py index f6edd9a..24c0a6f 100644 --- a/ovirt-guest-agent/VirtIoChannel.py +++ b/ovirt-guest-agent/VirtIoChannel.py @@ -42,21 +42,20 @@ .union(set(range(0x86, 0x9F + 1))) -def _string_check(str): +def _string_convert(str): """ - This function tries to convert the given string to a valid representable - form. Normal and valid unicode strings should not fail this test. Invalid - encodings will fail this and might get characters replaced. + This function tries to convert the given string to an unicode string """ + if isinstance(str, unicode): + return str try: - str.encode(locale.getpreferredencoding(), 'strict') + return str.decode(locale.getpreferredencoding(), 'strict') except UnicodeError: try: - return str.encode('ascii', 'replace') + return str.decode(locale.getpreferredencoding(), 'replace') except UnicodeError: # unrepresentable string - return unicode() - return unicode(str) + return u'????' def _filter_xml_chars(u): @@ -105,7 +104,7 @@ if isinstance(o, tuple): return tuple(map(filt, o)) if isinstance(o, basestring): - return _filter_xml_chars(_string_check(o)) + return _filter_xml_chars(_string_convert(o)) return o return filt(obj) -- To view, visit http://gerrit.ovirt.org/19053 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: Ie277069cbfa39f9735a2b85b9e9da9c3fcfe5938 Gerrit-PatchSet: 1 Gerrit-Project: ovirt-guest-agent Gerrit-Branch: master Gerrit-Owner: Vinzenz Feenstra <vfeen...@redhat.com> _______________________________________________ Engine-patches mailing list Engine-patches@ovirt.org http://lists.ovirt.org/mailman/listinfo/engine-patches