diff options
Diffstat (limited to 'wkhtmltopdf')
-rw-r--r-- | wkhtmltopdf/__init__.py | 2 | ||||
-rw-r--r-- | wkhtmltopdf/tests/run.py | 12 | ||||
-rw-r--r-- | wkhtmltopdf/utils.py | 13 |
3 files changed, 23 insertions, 4 deletions
diff --git a/wkhtmltopdf/__init__.py b/wkhtmltopdf/__init__.py index 873fb03..a9fe3b7 100644 --- a/wkhtmltopdf/__init__.py +++ b/wkhtmltopdf/__init__.py @@ -3,4 +3,4 @@ if 'DJANGO_SETTINGS_MODULE' in os.environ: from .utils import * __author__ = 'Incuna Ltd' -__version__ = '2.0.2' +__version__ = '2.0.3' diff --git a/wkhtmltopdf/tests/run.py b/wkhtmltopdf/tests/run.py index a840e68..5004ee1 100644 --- a/wkhtmltopdf/tests/run.py +++ b/wkhtmltopdf/tests/run.py @@ -2,10 +2,12 @@ import os import sys +import django from django.conf import settings DIRNAME = os.path.abspath(os.path.dirname(__file__)) +sys.path.insert(0, os.getcwd()) settings.configure( DEBUG=True, @@ -19,6 +21,10 @@ settings.configure( 'wkhtmltopdf.tests', 'wkhtmltopdf', ), + MIDDLEWARE_CLASSES=( + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + ), MEDIA_ROOT=os.path.join(DIRNAME, 'media'), MEDIA_URL='/media/', STATIC_ROOT=os.path.join(DIRNAME, 'static'), @@ -27,6 +33,12 @@ settings.configure( ) try: + django.setup() +except AttributeError: + pass # Django < 1.7; okay to ignore + + +try: from django.test.runner import DiscoverRunner except ImportError: from discover_runner.runner import DiscoverRunner diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index 3c9b4a7..053a2e7 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -5,6 +5,7 @@ from itertools import chain import os import re import sys +import shlex try: from urllib.request import pathname2url @@ -88,13 +89,19 @@ def wkhtmltopdf(pages, output=None, **kwargs): cmd = 'WKHTMLTOPDF_CMD' cmd = getattr(settings, cmd, os.environ.get(cmd, 'wkhtmltopdf')) - ck_args = list(chain(cmd.split(), + ck_args = list(chain(shlex.split(cmd), _options_to_args(**options), list(pages), [output])) ck_kwargs = {'env': env} - if hasattr(sys.stderr, 'fileno'): + # Handling of fileno() attr. based on https://github.com/GrahamDumpleton/mod_wsgi/issues/85 + try: + i = sys.stderr.fileno() ck_kwargs['stderr'] = sys.stderr + except (AttributeError, IOError): + # can't call fileno() on mod_wsgi stderr object + pass + return check_output(ck_args, **ck_kwargs) @@ -152,7 +159,7 @@ def make_absolute_paths(content): has_scheme = re.compile(r'^[^:/]+://') for x in overrides: - if has_scheme.match(x['url']): + if not x['url'] or has_scheme.match(x['url']): continue if not x['root'].endswith('/'): |