# HG changeset patch # User Paul Boddie # Date 1371218532 -7200 # Node ID d93ed053763b5cb6465bfec8dddfd0b450f3f9c5 # Parent 75848522fcf5dda34cad265f870fd935597b7e3f Introduced conversion to Unicode around StringIO usage, such as in the formatting of output not immediately sent in response to a request. diff -r 75848522fcf5 -r d93ed053763b MoinSupport.py --- a/MoinSupport.py Fri Jun 14 00:44:13 2013 +0200 +++ b/MoinSupport.py Fri Jun 14 16:02:12 2013 +0200 @@ -18,11 +18,16 @@ from MoinMoin.Page import Page from MoinMoin.util import lock from MoinMoin import config, search, wikiutil -from StringIO import StringIO from shlex import shlex import re import time import os +import codecs + +try: + from cStringIO import StringIO +except ImportError: + from StringIO import StringIO # Moin 1.9 request parameters. @@ -372,16 +377,21 @@ values. If 'escape' is set to a true value, the attributes will be suitable for use with the formatter API. If 'escape' is set to a false value, the attributes will have any quoting removed. + + Because Unicode was probably not around when shlex, used here to tokenise + the attributes, was introduced, and since StringIO is not Unicode-capable, + any non-ASCII characters should be quoted in attributes. """ attrs = {} - f = StringIO(s) + f = StringIO(s.encode("utf-8")) name = None need_value = False lex = shlex(f) lex.wordchars += "-" for token in lex: + token = unicode(token, "utf-8") # Capture the name if needed. @@ -849,10 +859,10 @@ """ parser = parser_cls(text, request) - buf = StringIO() + buf = codecs.getwriter("utf-8")(StringIO()) try: parser.formatForOutputType(output_type, buf.write) - return buf.getvalue() + return unicode(buf.getvalue(), "utf-8") finally: buf.close() @@ -860,7 +870,7 @@ "A fixed version of the request method of the same name." - buf = StringIO() + buf = codecs.getwriter("utf-8")(StringIO()) request.redirect(buf) try: parser.format(fmt, **kw) @@ -870,7 +880,7 @@ request.redirect() text = buf.getvalue() buf.close() - return text + return unicode(text, "utf-8") # Finding components for content types. diff -r 75848522fcf5 -r d93ed053763b README.txt --- a/README.txt Fri Jun 14 00:44:13 2013 +0200 +++ b/README.txt Fri Jun 14 16:02:12 2013 +0200 @@ -77,6 +77,8 @@ * Added a superuser parameter to getWikiDict to make the function usable by auth handlers. * Added various parsing and formatting utility methods for enhanced parsers. + * Introduced conversion to Unicode around StringIO usage, such as in the + formatting of output not immediately sent in response to a request. New in MoinSupport 0.3 (Changes since MoinSupport 0.2) ------------------------------------------------------