Opened 17 years ago
Closed 15 years ago
#2251 closed enhancement (fixed)
[patch] JSON support
Reported by: | okamototk | Owned by: | Alec Thomas |
---|---|---|---|
Priority: | normal | Component: | XmlRpcPlugin |
Severity: | normal | Keywords: | |
Cc: | Trac Release: | 0.11 |
Description (last modified by )
Hi,
If XmlRpcPlugin support JSON protocol, it's fine to support Ajax function. I develop the patch with Shibuya.trac project which is the group by Japanese users and developers.
Please apply our patch to support json.
regards,
Takashi Okamoto
Shibuya.trac: http://sourceforge.jp/projects/shibuya-trac/wiki/FrontPage
Attachments (2)
Change History (9)
Changed 17 years ago by
Attachment: | jsonsupport.patch added |
---|
comment:1 Changed 17 years ago by
Component: | TracHacks → XmlRpcPlugin |
---|
comment:2 Changed 16 years ago by
Type: | enhancement → defect |
---|
I tried your patch with the recent releases of Trac (0.11dev-r7092) and xmlrpc (TracXMLRPC-1.0.0-py2.5.egg) and your getticket example.
I get the following error:
2008-05-30 00:00:56,759 Trac[main] DEBUG: Dispatching <Request "POST u'/json/ticket.get'"> 2008-05-30 00:00:56,779 Trac[web_ui] DEBUG: /json/ticket.get matches True 2008-05-30 00:00:56,821 Trac[svn_fs] DEBUG: Subversion bindings imported 2008-05-30 00:00:56,829 Trac[api] DEBUG: action controllers for ticket workflow: ['ConfigurableTicketWorkflow'] 2008-05-30 00:00:56,861 Trac[web_ui] ERROR: Cannot write in JSON: <DateTime '20080122T19:50:46' at 16f57a0> 2008-05-30 00:00:56,862 Trac[web_ui] ERROR: Traceback (most recent call last): File "build/bdist.linux-x86_64/egg/tracrpc/web_ui.py", line 73, in process_request self._send_response(req, json.write(result[0]).encode('utf-8'), content_type) File "build/bdist.linux-x86_64/egg/tracrpc/json.py", line 935, in write return JsonWriter().write(obj, escaped_forward_slash) File "build/bdist.linux-x86_64/egg/tracrpc/json.py", line 883, in write self._write(obj) File "build/bdist.linux-x86_64/egg/tracrpc/json.py", line 903, in _write self._write(item) File "build/bdist.linux-x86_64/egg/tracrpc/json.py", line 932, in _write raise WriteException, "Cannot write in JSON: %s" % repr(obj) WriteException: Cannot write in JSON: <DateTime '20080122T19:50:46' at 16f57a0> 2008-05-30 00:00:57,047 Trac[main] DEBUG: 13 unreachable objects found.
comment:3 Changed 16 years ago by
Type: | defect → enhancement |
---|
comment:4 Changed 16 years ago by
Status: | new → assigned |
---|
This patch shouldn't include its own JSON parser, just add one as a dependency to the setup.py. Is there some other reason that something like simplejson can't be used?
Otherwise looks pretty good to me.
comment:5 Changed 16 years ago by
I removed json.py and installed the hardy package python-json. The error of last comment remains. athomas did this patch works for your config ootb? can you post your version of trac/json/xmlrpcplugin? How would I do replace json / simplejson?
comment:6 Changed 15 years ago by
Description: | modified (diff) |
---|---|
Summary: | [PATCH] JSON support → [patch] JSON support |
comment:7 Changed 15 years ago by
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
(In [6065]) XmlRpcPlugin: JSON-RPC support. It requires either Python 2.6 (part of standard lib, but untested by me), or easy_install simplejson
for 2.4/2.5 (tested).
Building on recent changes with types, all methods are already protocol and type agnostic and work unchanged. Summary of important changes:
- With a lot of recent changes to the core of the plugin, I wanted this change to be as unobtrusive as possible. Therefore it just switches on
Content-Type
header in main handler, leaving XML-RPC and JSON-RPC to doing their own things. At some stage the protocol code will be abstracted using extension-points so that adding protocol handlers can be done more cleanly - including from other plugins. - It tries to conform quite closely to the various versions, drafts and ongoing discussions for the JSON-RPC specification. However, that work is somewhat in flux, so changes may be needed later.
- JSON-RPC has no notion of types outside the standard Javascript types that are easily converted to very similar Python types. In order to support 'datetime' and 'binary' at any level in arguments (like a 'due' field in attributes for milestone update), some form of type-hint was needed:
{"__jsonclass__": ["binary", "<base64-encoded>"]}
is how to specify a binary value (similar structure for 'datetime'). See the new HTML documentation on/xmlrpc
or/jsonrpc
for details. Custom encoder + decoder handles all conversions. - For the first time in the history of the plugin, the new feature comes complete with unittests that actually shows and verifies that it works. Not bad :-)
Bumped version.
Closes #2251. Closes #3241. Please create new tickets for issues that follows this change.
Patch to support JSON