LEFT | RIGHT |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This file is part of the Adblock Plus build tools, | 3 # This file is part of the Adblock Plus build tools, |
4 # Copyright (C) 2006-2013 Eyeo GmbH | 4 # Copyright (C) 2006-2013 Eyeo GmbH |
5 # | 5 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
9 # | 9 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 ).split() | 112 ).split() |
113 ).encode('utf-8') | 113 ).encode('utf-8') |
114 | 114 |
115 def createInfoModule(params): | 115 def createInfoModule(params): |
116 template = getTemplate('safariInfo.js.tmpl') | 116 template = getTemplate('safariInfo.js.tmpl') |
117 return template.render(params).encode('utf-8') | 117 return template.render(params).encode('utf-8') |
118 | 118 |
119 def fixAbsoluteUrls(files): | 119 def fixAbsoluteUrls(files): |
120 for filename, content in files.iteritems(): | 120 for filename, content in files.iteritems(): |
121 if os.path.splitext(filename)[1].lower() == '.html': | 121 if os.path.splitext(filename)[1].lower() == '.html': |
122 prefix = '/'.join(['..'] * filename.count('/') + ['']) | |
123 files[filename] = re.sub( | 122 files[filename] = re.sub( |
124 r'(<.*?\b(?:href|src)\s*=\s*(["\']))(\/.*?)(?=\2.*?>)', | 123 r'(<[^<>]*?\b(?:href|src)\s*=\s*["\']?)\/+', |
125 lambda m: '%s%s%s' % (m.group(1), prefix, m.group(3).lstrip('/')), | 124 r'\1' + '/'.join(['..'] * filename.count('/') + ['']), |
126 content, re.S | re.I | 125 content, re.S | re.I |
127 ) | 126 ) |
128 | 127 |
129 def createSignedXarArchive(outFile, files, keyFile): | 128 def createSignedXarArchive(outFile, files, keyFile): |
130 import subprocess | 129 import subprocess |
131 import tempfile | 130 import tempfile |
132 import shutil | 131 import shutil |
133 import M2Crypto | 132 import M2Crypto |
134 | 133 |
135 # write files to temporary directory and create a xar archive | 134 # write files to temporary directory and create a xar archive |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 fixAbsoluteUrls(files) | 260 fixAbsoluteUrls(files) |
262 | 261 |
263 dirname = metadata.get('general', 'basename') + '.safariextension' | 262 dirname = metadata.get('general', 'basename') + '.safariextension' |
264 for filename in files.keys(): | 263 for filename in files.keys(): |
265 files[os.path.join(dirname, filename)] = files.pop(filename) | 264 files[os.path.join(dirname, filename)] = files.pop(filename) |
266 | 265 |
267 if keyFile: | 266 if keyFile: |
268 createSignedXarArchive(outFile, files, keyFile) | 267 createSignedXarArchive(outFile, files, keyFile) |
269 else: | 268 else: |
270 files.zip(outFile) | 269 files.zip(outFile) |
LEFT | RIGHT |