From 369ac7b2a33b0de2e95eb2f0ec38d543ad7ca98d Mon Sep 17 00:00:00 2001 From: Girts Folkmanis Date: Mon, 7 Nov 2016 17:11:07 -0800 Subject: cairo_backend.py: use BytesIO instead of StringIO This fixes a crash in cairocffi on Python3, and should be compatible with both python2 and python3. In python2, byte strings are just strings. In python3, when getting binary data, the user probably wants a byte string instead of a regular string. --- gerber/render/cairo_backend.py | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'gerber') diff --git a/gerber/render/cairo_backend.py b/gerber/render/cairo_backend.py index df4fcf1..d7026b8 100644 --- a/gerber/render/cairo_backend.py +++ b/gerber/render/cairo_backend.py @@ -25,10 +25,7 @@ from .render import GerberContext, RenderSettings from .theme import THEMES from ..primitives import * -try: - from cStringIO import StringIO -except(ImportError): - from io import StringIO +from io import BytesIO class GerberCairoContext(GerberContext): @@ -125,9 +122,9 @@ class GerberCairoContext(GerberContext): self.surface.write_to_png(filename) def dump_str(self): - """ Return a string containing the rendered image. + """ Return a byte-string containing the rendered image. """ - fobj = StringIO() + fobj = BytesIO() self.surface.write_to_png(fobj) return fobj.getvalue() -- cgit