From 465483336de200a7fb33df0794fd4cca7c607d6e Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 16 Sep 2014 21:07:07 +0100 Subject: [PATCH] Fix failing test_pdf.test_embedded_files test on PyPy. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit WeasyPrint still doesn’t actually work on PyPy with non-trivial documents, but at least Travis-CI is green again. --- weasyprint/pdf.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/weasyprint/pdf.py b/weasyprint/pdf.py index 05afb28a..de085578 100644 --- a/weasyprint/pdf.py +++ b/weasyprint/pdf.py @@ -43,8 +43,8 @@ import zlib import cairocffi as cairo from . import VERSION_STRING, Attachment -from .compat import xrange, iteritems, izip -from .urls import iri_to_uri, unquote, urlsplit, URLFetchingError +from .compat import xrange, iteritems, izip, unquote +from .urls import iri_to_uri, urlsplit, URLFetchingError from .html import W3C_DATE_RE from .logger import LOGGER @@ -485,7 +485,10 @@ def _get_filename_from_result(url, result): # TODO: this assumes that the filename has been quoted as UTF-8. # I'm not sure if this assumption holds, as there is some magic # involved with filesystem encoding in other parts of the code - filename = unquote(filename).encode('latin1').decode('utf-8') + filename = unquote(filename) + if not isinstance(filename, bytes): + filename = filename.encode('latin1') + filename = filename.decode('utf-8') else: filename = unquote(filename)