]> sipb.mit.edu Git - ikiwiki.git/blobdiff - doc/bugs/pythonproxy-utf8_again.mdwn
related bug
[ikiwiki.git] / doc / bugs / pythonproxy-utf8_again.mdwn
index 96b0600036d33346afb09081df2a94eff0e780c2..8269a9beaf497e2e3a6356c0af021c1072f1433a 100644 (file)
@@ -14,3 +14,46 @@ version, but i'm pretty sure it was already broken after the abovementioned
 patch.
 
 -- [[chrysn]]
+
+> update 2014-06-29: the problem persists, but i found it is not trivial to
+> reproduce. to demonstrate, use this test plugin:
+>
+>     #!/usr/bin/env python
+>     # -*- coding: utf-8 -*-
+>     
+>     from proxy import IkiWikiProcedureProxy
+>     
+>     def preprocess(self, proxy, *args):
+>         return repr(self.rpc('pagetype', 'schön'))
+>     
+>     proxy = IkiWikiProcedureProxy(__name__)
+>     proxy.hook('preprocess', preprocess, id='testdirective')
+>     proxy.run()
+>
+> note that when the 'schön' is stored in a variable, the exception changes --
+> it seems to me that the issue is related to the way exceptions are encoded.
+>
+> the suggested patch still applies and solves the issue. --[[chrysn]]
+
+>> In this patch band:
+>>
+>>     -        xml = _IkiWikiExtPluginXMLRPCHandler._read(in_fd).decode('utf8')
+>>     +        response = _IkiWikiExtPluginXMLRPCHandler._read(in_fd)
+>>     +        if isinstance(response, unicode):
+>>     +            xml = response.encode('utf8')
+>>
+>> I think you mean `response.decode`, not `response.encode`.
+>>
+>> Other than that it looks good to me. I like the use of `repr` in debug
+>> messages. --[[smcv]]
+
+>>> afaict, encode is fine there -- the relevant methods in python2 are
+>>> `unicode.encode` which gives a `str`, and `str.decode` which usually gives
+>>> a `unicode`. (i'd happily ditch python2 and port all plugins to python3,
+>>> where this is all easier, but my [[todo/vCard rendering]] still uses an
+>>> ancient module.) --[[chrysn]]
+
+>>>> You were right about this, `encode` is appropriate to go from `unicode`
+>>>> to `str` under Python 2. I'm a bit concerned that it might break
+>>>> Python 3 (see also [[bugs/rst_plugin_hangs_when_used_with_Python_3]]).
+>>>> Testing now. --[[smcv]]