From 3ccab4c0b24674115d2423b2825718be48abb695 Mon Sep 17 00:00:00 2001 From: Zach Gohr Date: Wed, 9 Jan 2013 14:26:11 -0600 Subject: Remove duplicates when replacing file paths --- wkhtmltopdf/views.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/wkhtmltopdf/views.py b/wkhtmltopdf/views.py index 4d0ccca..fd5b8c8 100644 --- a/wkhtmltopdf/views.py +++ b/wkhtmltopdf/views.py @@ -168,8 +168,13 @@ class PDFTemplateResponse(TemplateResponse, PDFResponse): if not x['root'].endswith('/'): x['root'] += '/' - for occur in re.findall('''["|']({0}.*?)["|']'''.format(x['url']), content): - content = content.replace(occur, pathname2fileurl(x['root']) + occur[len(x['url']):]) + occurences = re.findall('''["|']({0}.*?)["|']'''.format(x['url']), + content) + occurences = list(set(occurences)) # Remove dups + for occur in occurences: + content = content.replace(occur, + pathname2fileurl(x['root']) + + occur[len(x['url']):]) return content -- cgit v1.2.3