comparison MoinMoin/wikiutil.py @ 175:df4fe62dc160

fixing eventlog UnicodeDecodeError, try2 imported from: moin--main--1.5--patch-177
author Thomas Waldmann <tw@waldmann-edv.de>
date Mon, 31 Oct 2005 18:58:37 +0000
parents 11740ebb136c
children 722b8f648630
comparison
equal deleted inserted replaced
174:51bde0757167 175:df4fe62dc160
152 s = urllib.unquote(s) 152 s = urllib.unquote(s)
153 if want_unicode: 153 if want_unicode:
154 s = s.decode(config.charset) 154 s = s.decode(config.charset)
155 return s 155 return s
156 156
157 def parseQueryString(qstr, want_unicode=False): 157 def parseQueryString(qstr, want_unicode=True):
158 """ Parse a querystring "key=value&..." into a dict. 158 """ Parse a querystring "key=value&..." into a dict.
159 """ 159 """
160 is_unicode = isinstance(qstr, unicode) 160 is_unicode = isinstance(qstr, unicode)
161 if is_unicode: 161 if is_unicode:
162 qstr = qstr.encode(config.charset) 162 qstr = qstr.encode(config.charset)
163 values = {} 163 values = {}
164 for key, value in cgi.parse_qs(qstr).items(): 164 for key, value in cgi.parse_qs(qstr).items():
165 if len(value) < 2: 165 if len(value) < 2:
166 v = ''.join(value) 166 v = ''.join(value)
167 if want_unicode: 167 if want_unicode:
168 v = v.decode(config.charset) 168 try:
169 v = unicode(v, config.charset)
170 except UnicodeDecodeError:
171 v = unicode(v, 'iso-8859-1', 'replace')
169 values[key] = v 172 values[key] = v
170 return values 173 return values
171 174
172 def makeQueryString(qstr=None, want_unicode=False, **kw): 175 def makeQueryString(qstr=None, want_unicode=False, **kw):
173 """ Make a querystring from arguments. 176 """ Make a querystring from arguments.