changeset 5100:3920769287c4

twikidraw/anywikidraw action: fix nonascii drawing name handling
author Thomas Waldmann <tw AT waldmann-edv DOT de>
date Sun, 13 Sep 2009 00:46:27 +0200
parents 753ac1cbbc38
children d8ccac2f24c5
files MoinMoin/action/anywikidraw.py MoinMoin/action/twikidraw.py
diffstat 2 files changed, 14 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/MoinMoin/action/anywikidraw.py	Sun Sep 13 00:06:37 2009 +0200
+++ b/MoinMoin/action/anywikidraw.py	Sun Sep 13 00:46:27 2009 +0200
@@ -77,16 +77,17 @@
         mapfile = ci.get('drawing.map')
         map = mapfile.read()
         mapfile.close()
+        map = map.decode(config.charset)
     except (KeyError, IOError, OSError):
-        map = ''
+        map = u''
     if map:
         # ToDo mapid must become uniq
         # we have a image map. inline it and add a map ref to the img tag
-        mapid = 'ImageMapOf' + drawing
-        map = map.replace('id="%s.svg"' % drawing, '')
-        map = map.replace('name="%s.svg"' % drawing, 'name="%s"' % mapid)
+        mapid = u'ImageMapOf' + drawing
+        map = map.replace(u'id="%s.svg"' % drawing, '')
+        map = map.replace(u'name="%s.svg"' % drawing, u'name="%s"' % mapid)
         # unxml, because 4.01 concrete will not validate />
-        map = map.replace('/>', '>')
+        map = map.replace(u'/>', u'>')
         title = _('Clickable drawing: %(filename)s') % {'filename': self.text(drawing)}
         if 'title' not in kw:
             kw['title'] = title
--- a/MoinMoin/action/twikidraw.py	Sun Sep 13 00:06:37 2009 +0200
+++ b/MoinMoin/action/twikidraw.py	Sun Sep 13 00:46:27 2009 +0200
@@ -17,7 +17,7 @@
 from MoinMoin import log
 logging = log.getLogger(__name__)
 
-from MoinMoin import wikiutil
+from MoinMoin import wikiutil, config
 from MoinMoin.action import AttachFile, do_show
 from MoinMoin.Page import Page
 from MoinMoin.security.textcha import TextCha
@@ -79,17 +79,18 @@
         mapfile = ci.get('drawing.map')
         map = mapfile.read()
         mapfile.close()
+        map = map.decode(config.charset)
     except (KeyError, IOError, OSError):
-        map = ''
+        map = u''
     if map:
         # we have a image map. inline it and add a map ref to the img tag
-        mapid = 'ImageMapOf' + drawing
-        map = map.replace('%MAPNAME%', mapid)
+        mapid = u'ImageMapOf' + drawing
+        map = map.replace(u'%MAPNAME%', mapid)
         # add alt and title tags to areas
-        map = re.sub(r'href\s*=\s*"((?!%TWIKIDRAW%).+?)"', r'href="\1" alt="\1" title="\1"', map)
-        map = map.replace('%TWIKIDRAW%"', '%s" alt="%s" title="%s"' % (drawing_url, title, title))
+        map = re.sub(ur'href\s*=\s*"((?!%TWIKIDRAW%).+?)"', ur'href="\1" alt="\1" title="\1"', map)
+        map = map.replace(u'%TWIKIDRAW%"', u'%s" alt="%s" title="%s"' % (drawing_url, title, title))
         # unxml, because 4.01 concrete will not validate />
-        map = map.replace('/>', '>')
+        map = map.replace(u'/>', u'>')
         title = _('Clickable drawing: %(filename)s') % {'filename': self.text(drawing)}
         if 'title' not in kw:
             kw['title'] = title