[python-bugzilla] [PATCH 09/13] Make attachment data handling compatible for python3

abn at redhat.com abn at redhat.com
Tue Oct 29 13:22:28 UTC 2013


From: Arun Babu Neelicattu <abn at redhat.com>

---
 bin/bugzilla     | 2 +-
 bugzilla/base.py | 8 +++++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/bin/bugzilla b/bin/bugzilla
index da0c7a0..8b6b92b 100755
--- a/bin/bugzilla
+++ b/bin/bugzilla
@@ -993,7 +993,7 @@ def _do_set_attach(bz, opt, parser, args):
         data = sys.stdin.read(4096)
 
         while data:
-            fileobj.write(data)
+            fileobj.write(data.encode(locale.getpreferredencoding()))
             data = sys.stdin.read(4096)
         fileobj.seek(0)
 
diff --git a/bugzilla/base.py b/bugzilla/base.py
index d4c2632..d1a65c6 100644
--- a/bugzilla/base.py
+++ b/bugzilla/base.py
@@ -9,6 +9,7 @@
 # option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
 # the full text of the license.
 
+import locale
 import os
 import sys
 
@@ -1259,7 +1260,12 @@ class BugzillaBase(object):
             kwargs["file_name"] = kwargs.pop("filename")
 
         kwargs['summary'] = description
-        kwargs['data'] = Binary(f.read())
+
+        data = f.read()
+        if not isinstance(data, bytes):
+            data = data.encode(locale.getpreferredencoding())
+        kwargs['data'] = Binary(data)
+
         kwargs['ids'] = self._listify(idlist)
 
         if 'file_name' not in kwargs and hasattr(f, "name"):
-- 
1.8.3.1



More information about the python-bugzilla mailing list