aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Peterson <max@incuna.com>2016-02-19 21:54:43 +0000
committerMax Peterson <max@incuna.com>2016-02-19 21:54:43 +0000
commit44496fc3c418a94103bcd2da259f85f245778a15 (patch)
tree2f87f77f793cf243a83d82034aa656a8e451e095
parent3e7c17331bade835e14d3b9939fc7e8bd375f113 (diff)
parent61bec5852aed5399bc251dfd06118c584792f0d1 (diff)
downloaddjango-wkhtmltopdf-44496fc3c418a94103bcd2da259f85f245778a15.tar.gz
django-wkhtmltopdf-44496fc3c418a94103bcd2da259f85f245778a15.tar.bz2
django-wkhtmltopdf-44496fc3c418a94103bcd2da259f85f245778a15.zip
Merge pull request #99 from pauricthelodger/bytes-error
Fix unidecode bytes error on python2
-rw-r--r--wkhtmltopdf/tests/tests.py16
-rw-r--r--wkhtmltopdf/utils.py6
2 files changed, 18 insertions, 4 deletions
diff --git a/wkhtmltopdf/tests/tests.py b/wkhtmltopdf/tests/tests.py
index 8f40c5e..822f529 100644
--- a/wkhtmltopdf/tests/tests.py
+++ b/wkhtmltopdf/tests/tests.py
@@ -130,8 +130,14 @@ class TestViews(TestCase):
self.assertEqual(response['Content-Disposition'],
'attachment; filename="4\'5.pdf"')
response = PDFResponse(content=content, filename=u"♥.pdf")
+ try:
+ import unidecode
+ except ImportError:
+ filename = '?.pdf'
+ else:
+ filename = '.pdf'
self.assertEqual(response['Content-Disposition'],
- 'attachment; filename="?.pdf"')
+ 'attachment; filename="{0}"'.format(filename))
# Content as a direct output
response = PDFResponse(content=content, filename="nospace.pdf",
@@ -148,8 +154,14 @@ class TestViews(TestCase):
'inline; filename="4\'5.pdf"')
response = PDFResponse(content=content, filename=u"♥.pdf",
show_content_in_browser=True)
+ try:
+ import unidecode
+ except ImportError:
+ filename = '?.pdf'
+ else:
+ filename = '.pdf'
self.assertEqual(response['Content-Disposition'],
- 'inline; filename="?.pdf"')
+ 'inline; filename="{0}"'.format(filename))
# Content-Type
response = PDFResponse(content=content,
diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py
index 6be961c..1866b4a 100644
--- a/wkhtmltopdf/utils.py
+++ b/wkhtmltopdf/utils.py
@@ -190,9 +190,11 @@ def http_quote(string):
if isinstance(string, six.text_type):
try:
import unidecode
- string = bytes(unidecode.unidecode(string), 'ascii')
except ImportError:
- string = string.encode('ascii', 'replace')
+ pass
+ else:
+ string = unidecode.unidecode(string)
+ string = string.encode('ascii', 'replace')
# Wrap in double-quotes for ; , and the like
string = string.replace(b'\\', b'\\\\').replace(b'"', b'\\"')
return '"{0!s}"'.format(string.decode())