1.1 --- a/MoinSupport.py Fri Jun 14 00:44:13 2013 +0200
1.2 +++ b/MoinSupport.py Fri Jun 14 16:02:12 2013 +0200
1.3 @@ -18,11 +18,16 @@
1.4 from MoinMoin.Page import Page
1.5 from MoinMoin.util import lock
1.6 from MoinMoin import config, search, wikiutil
1.7 -from StringIO import StringIO
1.8 from shlex import shlex
1.9 import re
1.10 import time
1.11 import os
1.12 +import codecs
1.13 +
1.14 +try:
1.15 + from cStringIO import StringIO
1.16 +except ImportError:
1.17 + from StringIO import StringIO
1.18
1.19 # Moin 1.9 request parameters.
1.20
1.21 @@ -372,16 +377,21 @@
1.22 values. If 'escape' is set to a true value, the attributes will be suitable
1.23 for use with the formatter API. If 'escape' is set to a false value, the
1.24 attributes will have any quoting removed.
1.25 +
1.26 + Because Unicode was probably not around when shlex, used here to tokenise
1.27 + the attributes, was introduced, and since StringIO is not Unicode-capable,
1.28 + any non-ASCII characters should be quoted in attributes.
1.29 """
1.30
1.31 attrs = {}
1.32 - f = StringIO(s)
1.33 + f = StringIO(s.encode("utf-8"))
1.34 name = None
1.35 need_value = False
1.36 lex = shlex(f)
1.37 lex.wordchars += "-"
1.38
1.39 for token in lex:
1.40 + token = unicode(token, "utf-8")
1.41
1.42 # Capture the name if needed.
1.43
1.44 @@ -849,10 +859,10 @@
1.45 """
1.46
1.47 parser = parser_cls(text, request)
1.48 - buf = StringIO()
1.49 + buf = codecs.getwriter("utf-8")(StringIO())
1.50 try:
1.51 parser.formatForOutputType(output_type, buf.write)
1.52 - return buf.getvalue()
1.53 + return unicode(buf.getvalue(), "utf-8")
1.54 finally:
1.55 buf.close()
1.56
1.57 @@ -860,7 +870,7 @@
1.58
1.59 "A fixed version of the request method of the same name."
1.60
1.61 - buf = StringIO()
1.62 + buf = codecs.getwriter("utf-8")(StringIO())
1.63 request.redirect(buf)
1.64 try:
1.65 parser.format(fmt, **kw)
1.66 @@ -870,7 +880,7 @@
1.67 request.redirect()
1.68 text = buf.getvalue()
1.69 buf.close()
1.70 - return text
1.71 + return unicode(text, "utf-8")
1.72
1.73 # Finding components for content types.
1.74
2.1 --- a/README.txt Fri Jun 14 00:44:13 2013 +0200
2.2 +++ b/README.txt Fri Jun 14 16:02:12 2013 +0200
2.3 @@ -77,6 +77,8 @@
2.4 * Added a superuser parameter to getWikiDict to make the function usable by
2.5 auth handlers.
2.6 * Added various parsing and formatting utility methods for enhanced parsers.
2.7 + * Introduced conversion to Unicode around StringIO usage, such as in the
2.8 + formatting of output not immediately sent in response to a request.
2.9
2.10 New in MoinSupport 0.3 (Changes since MoinSupport 0.2)
2.11 ------------------------------------------------------