summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Kittner <andkit@gmx.de>2011-01-27 00:21:21 +0100
committerZac Medico <zmedico@gentoo.org>2013-01-18 21:15:18 -0800
commit0d7e395a3227264ff8bcc2c35d024c2b39e07679 (patch)
tree254370172b7a68ba17a12e16a8b5801fb29868d6
parent812c9ee0778547c0fb918ce4b62c7ba3957f6727 (diff)
downloadportage-0d7e395a3227264ff8bcc2c35d024c2b39e07679.tar.gz
portage-0d7e395a3227264ff8bcc2c35d024c2b39e07679.tar.bz2
portage-0d7e395a3227264ff8bcc2c35d024c2b39e07679.zip
Fix unicode vs. bytes issue in glsa-check (#341293)
http://git.overlays.gentoo.org/gitweb/?p=proj/gentoolkit.git;a=commit;h=01d40ffed91033119bae05dac5c9cea86b94aa2e
-rwxr-xr-xbin/glsa-check17
-rw-r--r--pym/portage/glsa.py1
2 files changed, 11 insertions, 7 deletions
diff --git a/bin/glsa-check b/bin/glsa-check
index 3d047b54d..b2da90ae0 100755
--- a/bin/glsa-check
+++ b/bin/glsa-check
@@ -283,7 +283,7 @@ if mode == "test":
# mail mode as requested by solar
if mode == "mail":
import portage.mail, socket
- from io import StringIO
+ from io import BytesIO
from email.mime.text import MIMEText
# color doesn't make any sense for mail
@@ -302,11 +302,13 @@ if mode == "mail":
mysubject = "[glsa-check] Summary for %s" % socket.getfqdn()
# need a file object for summarylist()
- myfd = StringIO()
- myfd.write("GLSA Summary report for host %s\n" % socket.getfqdn())
- myfd.write("(Command was: %s)\n\n" % " ".join(sys.argv))
+ myfd = BytesIO()
+ line = "GLSA Summary report for host %s\n" % socket.getfqdn()
+ myfd.write(line.encode("utf-8"))
+ line = "(Command was: %s)\n\n" % " ".join(sys.argv)
+ myfd.write(line.encode("utf-8"))
summarylist(glsalist, fd1=myfd, fd2=myfd)
- summary = str(myfd.getvalue())
+ summary = myfd.getvalue().decode("utf-8")
myfd.close()
myattachments = []
@@ -317,9 +319,10 @@ if mode == "mail":
if verbose:
sys.stderr.write(("invalid GLSA: %s (error message was: %s)\n" % (myid, e)))
continue
- myfd = StringIO()
+ myfd = BytesIO()
myglsa.dump(outstream=myfd)
- myattachments.append(MIMEText(str(myfd.getvalue()), _charset="utf8"))
+ attachment = myfd.getvalue().decode("utf-8")
+ myattachments.append(MIMEText(attachment, _charset="utf8"))
myfd.close()
mymessage = portage.mail.create_message(myfrom, myrecipient, mysubject, summary, myattachments)
diff --git a/pym/portage/glsa.py b/pym/portage/glsa.py
index c0c69dd2d..1dd8a98b9 100644
--- a/pym/portage/glsa.py
+++ b/pym/portage/glsa.py
@@ -604,6 +604,7 @@ class Glsa:
@param outfile: Stream that should be used for writing
(defaults to sys.stdout)
"""
+ outstream = getattr(outstream, "buffer", outstream)
outstream = codecs.getwriter(encoding)(outstream)
width = 76
outstream.write(("GLSA %s: \n%s" % (self.nr, self.title)).center(width)+"\n")