From ed9881478d064e55679a2eb684c29baf1939776c Mon Sep 17 00:00:00 2001 From: Joseph Date: Thu, 16 Jul 2015 23:44:55 -0700 Subject: Skip absolute path substitution where STATIC or MEDIA URL is not set STATIC_URL or MEDIA_URL settings default to '' and None These default values cause the url match and replace algorithm to insert the *_ROOT setting in EVERY quoted string!! --- wkhtmltopdf/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index 603d29a..e841380 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -152,7 +152,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('/'): -- cgit v1.2.3 From 4b73d48254749bbf08c42126f10b16ac2d71f004 Mon Sep 17 00:00:00 2001 From: Joseph Date: Tue, 28 Jul 2015 18:36:08 -0700 Subject: Patch python3 / mod_wsgi incompatibility on sys.stderrr.fileno() call Root cause of this issue is in python3 / mod_wsgi. See: https://github.com/GrahamDumpleton/mod_wsgi/issues/85 This patch detects if there is something screwy with fileno() and simply skips setting stderr if there is to avoid the AttributeError that occurs otherwise. Pull https://github.com/incuna/django-wkhtmltopdf/pull/40 fixed this same issue when it arose for python 2.7, but the nature of the issue seems to have shifted, making it trickier to detect that the fileno() method cannot be called. --- wkhtmltopdf/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/wkhtmltopdf/utils.py b/wkhtmltopdf/utils.py index e841380..9c338bf 100644 --- a/wkhtmltopdf/utils.py +++ b/wkhtmltopdf/utils.py @@ -93,8 +93,13 @@ def wkhtmltopdf(pages, output=None, **kwargs): list(pages), [output])) ck_kwargs = {'env': env} - if hasattr(sys.stderr, 'fileno'): + try: + i = sys.stderr.fileno() ck_kwargs['stderr'] = sys.stderr + except AttributeError: + # can't call fileno() on mod_wsgi stderr object + pass + return check_output(ck_args, **ck_kwargs) -- cgit v1.2.3