]> sipb.mit.edu Git - ikiwiki.git/blob - doc/bugs/pythonproxy-utf8_again.mdwn
ikiwiki (3.20140916) unstable; urgency=low
[ikiwiki.git] / doc / bugs / pythonproxy-utf8_again.mdwn
1 [[!template  id=gitbranch branch=chrysn/more-proxy-utf8-fail author="[[chrysn]]"]]
2 [[!template id=gitbranch author="[[chrysn]], [[smcv]]" branch=smcv/ready/more-proxy-utf8-fail
3   browse=http://git.pseudorandom.co.uk/smcv/ikiwiki.git/shortlog/refs/heads/ready/more-proxy-utf8-fail]]
4
5 the recently introduced fixes for [[crashes in the python proxy even if disabled]]
6 caused the typical python2 implicit conversion failures ("'ascii' codec
7 can't...") on my debian sid system -- to fix it, i had to revert commit 154c4ea9e.
8
9 i did not dig down all the way to the xml / xmlrpc modules, but my impression
10 is that some module changed its behavior between stable and sid and now
11 generates `unicode` strings instead of `str`.
12
13 a [[patch]] to allow both versions by inspecting the types and en-/decoding on
14 demand should work both for anarcat's and my case. i did not test the python3
15 version, but i'm pretty sure it was already broken after the abovementioned
16 patch.
17
18 -- [[chrysn]]
19
20 > update 2014-06-29: the problem persists, but i found it is not trivial to
21 > reproduce. to demonstrate, use this test plugin:
22 >
23 >     #!/usr/bin/env python
24 >     # -*- coding: utf-8 -*-
25 >     
26 >     from proxy import IkiWikiProcedureProxy
27 >     
28 >     def preprocess(self, proxy, *args):
29 >         return repr(self.rpc('pagetype', 'schön'))
30 >     
31 >     proxy = IkiWikiProcedureProxy(__name__)
32 >     proxy.hook('preprocess', preprocess, id='testdirective')
33 >     proxy.run()
34 >
35 > note that when the 'schön' is stored in a variable, the exception changes --
36 > it seems to me that the issue is related to the way exceptions are encoded.
37 >
38 > the suggested patch still applies and solves the issue. --[[chrysn]]
39
40 >> In this patch band:
41 >>
42 >>     -        xml = _IkiWikiExtPluginXMLRPCHandler._read(in_fd).decode('utf8')
43 >>     +        response = _IkiWikiExtPluginXMLRPCHandler._read(in_fd)
44 >>     +        if isinstance(response, unicode):
45 >>     +            xml = response.encode('utf8')
46 >>
47 >> I think you mean `response.decode`, not `response.encode`.
48 >>
49 >> Other than that it looks good to me. I like the use of `repr` in debug
50 >> messages. --[[smcv]]
51
52 >>> afaict, encode is fine there -- the relevant methods in python2 are
53 >>> `unicode.encode` which gives a `str`, and `str.decode` which usually gives
54 >>> a `unicode`. (i'd happily ditch python2 and port all plugins to python3,
55 >>> where this is all easier, but my [[todo/vCard rendering]] still uses an
56 >>> ancient module.) --[[chrysn]]
57
58 >>>> You were right about this, `encode` is appropriate to go from `unicode`
59 >>>> to `str` under Python 2. However, Python 3 is still broken.
60 >>>>
61 >>>> My `ready/more-proxy-utf8-fail` branch, based on yours,
62 >>>> [[fixes the `rst` test when run under Python 3|bugs/rst_plugin_hangs_when_used_with_Python_3]]
63 >>>> and hopefully also fixes this one. Please check that it still
64 >>>> fixes your test-case too.
65 >>>>
66 >>>> Joey, I think this is [[ready for merge|users/smcv/ready]] even if it
67 >>>> doesn't fix chrysn's bug - it does fix Python 3 support
68 >>>> in general. --[[smcv]]
69
70 >>>>> [[merged|done]] --[[smcv]]