# HG changeset patch # User souliane # Date 1454603853 -3600 # Node ID a51355982f111802eeee0f40999687ef62409f3d # Parent 9fd517248dc852cf6ef146e8d5401c196ee7c7b8 plugin blog_import_dokuwiki: fixes wrong URL when a substitution occurs twice diff -r 9fd517248dc8 -r a51355982f11 src/plugins/plugin_blog_import_dokuwiki.py --- a/src/plugins/plugin_blog_import_dokuwiki.py Thu Feb 04 17:36:22 2016 +0100 +++ b/src/plugins/plugin_blog_import_dokuwiki.py Thu Feb 04 17:37:33 2016 +0100 @@ -247,7 +247,7 @@ tgt = '/blog/%s/%s" target="#"' % (profile_jid.user, backlink) text = text.replace(src, tgt) - subs = [] + subs = {} link_pattern = r"""<(img|a)[^>]* (src|href)="([^"]+)"[^>]*>""" for tag in re.finditer(link_pattern, text): @@ -257,10 +257,10 @@ continue if self.media_repo: self.moveMedia(link, subs) - else: - subs.append((link, urlparse.urljoin(self.url, link))) + elif link not in subs: + subs[link] = urlparse.urljoin(self.url, link) - for url, new_url in subs: + for url, new_url in subs.iteritems(): text = text.replace(url, new_url) return text @@ -268,7 +268,7 @@ """Move a media from the DokuWiki host to the new repository. @param link (unicode): media link - @param subs (set(couple)): substitutions list + @param subs (dict): substitutions data """ url = urlparse.urljoin(self.url, link) user_media = re.match(r"(/lib/exe/\w+.php\?)(.*)", link) @@ -282,7 +282,7 @@ log.warning("No media found in fetch URL: %s" % user_media.group(2)) return if re.match(r"^\w*://", media): # external URL to link directly - subs.append((link, media)) + subs[link] = media return try: # create thumbnail thumb_width = params["w"][0] @@ -308,7 +308,7 @@ self.createThumbnail(filepath, thumbnail, thumb_width) new_url = os.path.join(self.media_repo, filename) - subs.append((link, new_url)) + subs[link] = new_url def downloadMedia(self, source, dest): """Copy media to localhost.