Explorar o código

[desktop] UTF8 decode byte strings before printing

This annoying bug affects unit tests. Since we're just printing out random byte
strings from random HTTP endpoints, there is no guarantee that we're getting
text. And we often don't, when we do file I/O with WebHDFS. This causes us to
log non-UTF8 safe stuff, which makes nosetest put non-UTF8 data into the XML
report file, which means that Jenkins can't parse it.
bc Wong %!s(int64=11) %!d(string=hai) anos
pai
achega
5d13ff8
Modificáronse 1 ficheiros con 8 adicións e 3 borrados
  1. 8 3
      desktop/core/src/desktop/lib/rest/resource.py

+ 8 - 3
desktop/core/src/desktop/lib/rest/resource.py

@@ -17,6 +17,8 @@
 import logging
 import posixpath
 
+from desktop.lib.i18n import smart_unicode
+
 LOG = logging.getLogger(__name__)
 
 
@@ -72,9 +74,12 @@ class Resource(object):
                                 allow_redirects=allow_redirects,
                                 urlencode=self._urlencode)
 
-    self._client.logger.debug(
-        "%s Got response: %s%s" %
-        (method, resp.content[:32], len(resp.content) > 32 and "..." or ""))
+    if self._client.logger.isEnabledFor(logging.DEBUG):
+      self._client.logger.debug(
+          "%s Got response: %s%s" %
+          (method,
+           smart_unicode(resp.content[:32], errors='replace'),
+           len(resp.content) > 32 and "..." or ""))
 
     return self._format_response(resp)