Skip to content

Commit c059c6e

Browse files
abncrobinso
authored andcommitted
Make attachment data handling compatible for python3
1 parent 0952c53 commit c059c6e

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

bin/bugzilla

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ def _do_set_attach(bz, opt, parser, args):
993993
data = sys.stdin.read(4096)
994994

995995
while data:
996-
fileobj.write(data)
996+
fileobj.write(data.encode(locale.getpreferredencoding()))
997997
data = sys.stdin.read(4096)
998998
fileobj.seek(0)
999999

bugzilla/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
# option) any later version. See http://www.gnu.org/copyleft/gpl.html for
1010
# the full text of the license.
1111

12+
import locale
1213
import os
1314
import sys
1415

@@ -1259,7 +1260,12 @@ def attachfile(self, idlist, attachfile, description, **kwargs):
12591260
kwargs["file_name"] = kwargs.pop("filename")
12601261

12611262
kwargs['summary'] = description
1262-
kwargs['data'] = Binary(f.read())
1263+
1264+
data = f.read()
1265+
if not isinstance(data, bytes):
1266+
data = data.encode(locale.getpreferredencoding())
1267+
kwargs['data'] = Binary(data)
1268+
12631269
kwargs['ids'] = self._listify(idlist)
12641270

12651271
if 'file_name' not in kwargs and hasattr(f, "name"):

0 commit comments

Comments
 (0)