]> khamidou — GitHub mirrors - imapclient.git/commitdiff
Make debug logging handle bytes better
authorMenno Smits <menno@freshfoo.com>
Tue, 11 Aug 2015 10:46:09 +0000 (22:46 +1200)
committerMenno Smits <menno@freshfoo.com>
Tue, 11 Aug 2015 10:46:09 +0000 (22:46 +1200)
Avoid issues with 8-bit data.

imapclient/imapclient.py

index cfb371ab4fc7750159a8680bbe266ac0dcd0dc9e..c959db33c098b9ecc6779699bc28af98bff140cd 100644 (file)
@@ -1077,7 +1077,10 @@ class IMAPClient(object):
     debug = property(__debug_get, __debug_set)
 
     def _log(self, text):
-        self.log_file.write('%s %s\n' % (datetime.now().strftime('%M:%S.%f'), text))
+        timestamp = datetime.now().strftime('%M:%S.%f')
+        if isinstance(text, binary_type):
+            text = repr(text)[1:-1]
+        self.log_file.write(timestamp + ' ' + text + '\n')
         self.log_file.flush()
 
     def _normalise_folder(self, folder_name):