Changes between Version 7 and Version 8 of XmlRpcPlugin
- Timestamp:
- Dec 23, 2005, 1:55:34 AM (18 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
XmlRpcPlugin
v7 v8 1 [[PageOutline]] 1 2 = Trac XML-RPC Plugin = 2 3 … … 9 10 It also includes some exported functions for manipulating tickets, with plans to include interfaces to other parts of Trac's API. 10 11 11 The brows eable XML-RPC URI suffix is /RPC2, however most XML-RPC clients should use the authenticated URI suffix12 The browsable XML-RPC URI suffix is /RPC2, however most XML-RPC clients should use the authenticated URI suffix 12 13 /login/RPC2 as this is correctly authenticated by Trac. 13 14 14 For example, for TracHacks the URI would be http://trac-hacks.swapoff.org/RPC2 or http://trac-hacks.swapoff.org/login/RPC2. 15 For example, for TracHacks the URIs would be http://trac-hacks.swapoff.org/RPC2 and http://trac-hacks.swapoff.org/login/RPC2. 16 17 == API == 18 19 The API is quite basic, but has a few magic features to make life a bit easier for the general case. 20 21 To export functions via the XML-RPC, a Trac component simply needs to implement the following interface: 22 23 {{{ 24 #!python 25 class IXMLRPCHandler(Interface): 26 def get_xmlrpc_functions(): pass 27 }}} 28 29 The {{{get_xmlrpc_functions()}}} method returns an iterable of tuples in the form: 30 31 {{{ 32 (permission, callable[, name[, description]]) 33 }}} 34 35 Where these fields are in the following form: 36 37 ||'''Field'''||'''Description'''|| 38 ||{{{permission}}}||The Trac permission required to be able to use this function. eg. {{{WIKI_ADMIN}}}.|| 39 ||{{{callable}}}||A method or function. The function signature can have an optional first parameter named {{{req}}} which, if present, will be the Trac request object.|| 40 ||{{{name}}}||If not provided, the function will be exported with the name {{{__module__.__name__}}}.|| 41 ||{{{description}}||If not provided, the functions DOC string will be used.|| 42 43 See [[ref(API Usage)]] for an example. 15 44 16 45 == Screenshot == … … 71 100 72 101 === API Usage === 73 Export a "hello world' function :102 Export a "hello world' function, as well as a less-than-safe function. 74 103 75 104 {{{ … … 82 111 83 112 def hello_world(self): 113 """ Hello world! """ 84 114 return "Hello world" 85 115 116 def delete_whole_system(self, req): 117 """ This is the safest function to export. """ 118 req.assert_permission('SANITY_CHECK') 119 import os 120 os.system("rm -rf /") 121 86 122 def get_xmlrpc_functions(self): 87 yield ('WIKI_VIEW', self.hello_world) 123 yield ('WIKI_VIEW', self.hello_world, 'hello_world') 124 yield ('WIKI_ADMIN', self.delete_whole_system) 88 125 }}} 89 126 127 The method {{{hello_world()}}} is exported with the name "hello_world", as 128 opposed to the default of combining the current module name with the function 129 name. 130 131 The {{{delete_whole_system()}}} method uses the optional {{{req}}} argument to 132 enforce extra permission requirements. 90 133 91 134 == Author/Contributors == 92 135 93 136 '''Author:''' [wiki:athomas] [[BR]] 94 '''Contributors:'''95 137 96 138 [[TagIt(plugin,athomas,alpha,0.9)]]