Changeset 229

Show
Ignore:
Timestamp:
12/27/05 08:00:27 (3 years ago)
Author:
athomas
Message:

XmlRpcPlugin:

  • Removed use of decorators for < Python 2.4 compatibility.
  • Fixed bug in signatures with overridden names.
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • xmlrpcplugin/0.9/tracrpc/api.py

    r228 r229  
    6363        self.description = pydoc.getdoc(callable) 
    6464        if name is None: 
    65             self.name = provider.xmlrpc_namespace() + '.' + signature[2].__name__ 
     65            self.name = provider.xmlrpc_namespace() + '.' + callable.__name__ 
    6666        else: 
    6767            self.name = provider.xmlrpc_namespace() + '.' + name 
     
    124124        return self.rpc_signatures 
    125125 
    126 class XMLRPCSystem(AbstractRPCHandler): 
     126class XMLRPCSystem(Component): 
    127127    """ Core of the XML-RPC system. """ 
    128     implements(IPermissionRequestor
     128    implements(IPermissionRequestor, IXMLRPCHandler
    129129 
    130130    method_handlers = ExtensionPoint(IXMLRPCHandler) 
     
    137137    def xmlrpc_namespace(self): 
    138138        return 'system' 
     139 
     140    def xmlrpc_methods(self): 
     141        yield ('XML_RPC', ((list, list),), self.multicall) 
     142        yield ('XML_RPC', ((list,),), self.listMethods) 
     143        yield ('XML_RPC', ((str, str),), self.methodHelp) 
     144        yield ('XML_RPC', ((list, str),), self.methodSignature) 
    139145 
    140146    def get_method(self, method): 
     
    157163                    yield c 
    158164 
    159     @expose_rpc('XML_RPC', list, list) 
    160165    def multicall(self, req, signatures): 
    161166        """ Takes an array of XML-RPC calls encoded as structs of the form (in 
     
    172177                yield xmlrpclib.Fault(2, "'%s' while executing '%s()'" % (str(e), signature['methodName'])) 
    173178 
    174     @expose_rpc('XML_RPC', list) 
    175179    def listMethods(self, req): 
    176180        """ This method returns a list of strings, one for each (non-system) 
     
    179183            yield method.name 
    180184 
    181     @expose_rpc('XML_RPC', str, str) 
    182185    def methodHelp(self, req, method): 
    183186        """ This method takes one parameter, the name of a method implemented 
     
    189192        return '\n'.join((p.signature, '', p.description)) 
    190193 
    191     @expose_rpc('XML_RPC', list, str) 
    192194    def methodSignature(self, req, method): 
    193195        """ This method takes one parameter, the name of a method implemented 
  • xmlrpcplugin/0.9/tracrpc/ticket.py

    r226 r229  
    11from trac.core import * 
    2 from tracrpc.api import AbstractRPCHandler, expose_rpc 
     2from tracrpc.api import IXMLRPCHandler, expose_rpc 
    33import trac.ticket.model as model 
    44import trac.ticket.query as query 
     
    66import xmlrpclib 
    77 
    8 class TicketRPC(AbstractRPCHandler): 
     8class TicketRPC(Component): 
    99    """ An interface to Trac's ticketing system. """ 
     10 
     11    implements(IXMLRPCHandler) 
    1012 
    1113    # IXMLRPCHandler methods 
     
    1315        return 'ticket' 
    1416 
     17    def xmlrpc_methods(self): 
     18        yield ('TICKET_VIEW', ((list,), (list, str)), self.query) 
     19        yield ('TICKET_VIEW', ((list, int),), self.get) 
     20        yield ('TICKET_CREATE', ((int, str, str), (int, str, str, dict)), self.create) 
     21        yield ('TICKET_APPEND', ((list, int, str), (list, int, str, dict)), self.update) 
     22        yield ('TICKET_ADMIN', ((None, int),), self.delete) 
     23        yield ('TICKET_VIEW', ((dict, int), (dict, int, int)), self.changeLog) 
     24 
    1525    # Exported methods 
    16     @expose_rpc('TICKET_VIEW', list) 
    17     @expose_rpc('TICKET_VIEW', list, str) 
    1826    def query(self, qstr = 'status!=closed'): 
    1927        """ Perform a ticket query, returning a list of ticket ID's. """ 
     
    2432        return out 
    2533 
    26     @expose_rpc('TICKET_VIEW', list, int) 
    2734    def get(self, id): 
    2835        """ Fetch a ticket. Returns [id, time_created, time_changed, attributes]. """ 
     
    3037        return (t.id, t.time_created, t.time_changed, t.values) 
    3138 
    32     @expose_rpc('TICKET_CREATE', int, str, str) 
    33     @expose_rpc('TICKET_CREATE', int, str, str, dict) 
    3439    def create(self, summary, description, attributes = {}): 
    3540        """ Create a new ticket, returning the ticket ID. """ 
     
    4247        return t.id 
    4348 
    44     @expose_rpc('TICKET_APPEND', list, int, str) 
    45     @expose_rpc('TICKET_APPEND', list, int, str, dict) 
    4649    def update(self, req, id, comment, attributes = {}): 
    4750        """ Update a ticket, returning the new ticket in the same form as getTicket(). """ 
     
    5255        return self.getTicket(t.id) 
    5356 
    54     @expose_rpc('TICKET_ADMIN', str, int) 
    5557    def delete(self, id): 
    5658        """ Delete ticket with the given id. """ 
     
    5860        t.delete() 
    5961 
    60     @expose_rpc('TICKET_VIEW', dict, int) 
    61     @expose_rpc('TICKET_VIEW', dict, int, int) 
    6262    def changeLog(self, id, when = 0): 
    6363        t = model.Ticket(self.env, id) 
     
    7070def ticketModelFactory(cls, cls_attributes): 
    7171    """ Return a class which exports an interface to trac.ticket.model.<cls>. """ 
    72     class TicketModelImpl(AbstractRPCHandler): 
     72    class TicketModelImpl(Component): 
     73        implements(IXMLRPCHandler) 
     74 
    7375        def xmlrpc_namespace(self): 
    7476            return 'ticket.' + cls.__name__.lower() 
    7577 
    76         @expose_rpc('TICKET_VIEW', list) 
     78        def xmlrpc_methods(self): 
     79            yield ('TICKET_VIEW', ((list,),), self.getAll) 
     80            yield ('TICKET_VIEW', ((dict, str),), self.get) 
     81            yield ('TICKET_ADMIN', ((None, str,),), self.delete) 
     82            yield ('TICKET_ADMIN', ((None, str, dict),), self.create) 
     83            yield ('TICKET_ADMIN', ((None, str, dict),), self.update) 
     84 
    7785        def getAll(self): 
    7886            for i in cls.select(self.env): 
     
    8088        getAll.__doc__ = """ Get a list of all ticket %s names. """ % cls.__name__.lower() 
    8189 
    82         @expose_rpc('TICKET_VIEW', dict, str) 
    8390        def get(self, name): 
    8491            i = cls(self.env, name) 
     
    8996        get.__doc__ = """ Get a ticket %s. """ % cls.__name__.lower() 
    9097 
    91         @expose_rpc('TICKET_ADMIN', None, str) 
    9298        def delete(self, name): 
    9399            cls(self.env, name).delete() 
    94100        delete.__doc__ = """ Delete a ticket %s """ % cls.__name__.lower() 
    95101 
    96         @expose_rpc('TICKET_ADMIN', None, str, dict) 
    97102        def create(self, name, attributes): 
    98103            self._updateHelper(name, attributes).insert() 
    99104        create.__doc__ = """ Create a new ticket %s with the given attributes. """ % cls.__name__.lower() 
    100105 
    101         @expose_rpc('TICKET_ADMIN', None, str, dict) 
    102106        def update(self, name, attributes): 
    103107            self._updateHelper(name, attributes).update() 
     
    116120def ticketEnumFactory(cls): 
    117121    """ Return a class which exports an interface to one of the Trac ticket abstract enum types. """ 
    118     class AbstractEnumImpl(AbstractRPCHandler): 
     122    class AbstractEnumImpl(Component): 
     123        implements(IXMLRPCHandler) 
     124 
    119125        def xmlrpc_namespace(self): 
    120126            return 'ticket.' + cls.__name__.lower() 
    121127 
    122         @expose_rpc('TICKET_VIEW', list) 
     128        def xmlrpc_methods(self): 
     129            yield ('TICKET_VIEW', ((list,),), self.getAll) 
     130            yield ('TICKET_VIEW', ((str, str),), self.get) 
     131            yield ('TICKET_ADMIN', ((None, str,),), self.delete) 
     132            yield ('TICKET_ADMIN', ((None, str, str),), self.create) 
     133            yield ('TICKET_ADMIN', ((None, str, str),), self.update) 
     134 
    123135        def getAll(self): 
    124136            for i in cls.select(self.env): 
     
    126138        getAll.__doc__ = """ Get a list of all ticket %s names. """ % cls.__name__.lower() 
    127139 
    128         @expose_rpc('TICKET_VIEW', str, str) 
    129140        def get(self, name): 
    130141            i = cls(self.env, name) 
     
    132143        get.__doc__ = """ Get a ticket %s. """ % cls.__name__.lower() 
    133144 
    134         @expose_rpc('TICKET_ADMIN', None, str) 
    135145        def delete(self, name): 
    136146            cls(self.env, name).delete() 
    137147        delete.__doc__ = """ Delete a ticket %s """ % cls.__name__.lower() 
    138148 
    139         @expose_rpc('TICKET_ADMIN', None, str, str) 
    140149        def create(self, name, value): 
    141150            self._updateHelper(name, value).insert() 
    142151        create.__doc__ = """ Create a new ticket %s with the given value. """ % cls.__name__.lower() 
    143152 
    144         @expose_rpc('TICKET_ADMIN', None, str, str) 
    145153        def update(self, name, value): 
    146154            self._updateHelper(name, value).update() 
  • xmlrpcplugin/0.9/tracrpc/web_ui.py

    r227 r229  
    3939                        'namespace' : method.namespace, 
    4040                        } 
    41                 namespaces[namespace]['methods'].append((method.signature, wiki_to_oneliner(method.description, self.env), method.permission)) 
     41                try: 
     42                    namespaces[namespace]['methods'].append((method.signature, wiki_to_oneliner(method.description, self.env), method.permission)) 
     43                except Exception, e: 
     44                    raise Exception('%s: %s' % (method.name, str(e))) 
    4245            req.hdf['xmlrpc.functions'] = namespaces 
    4346            return 'xmlrpclist.cs', None 
  • xmlrpcplugin/0.9/tracrpc/wiki.py

    r225 r229  
    1212from trac.wiki.formatter import wiki_to_html 
    1313from trac.attachment import Attachment 
    14 from tracrpc.api import AbstractRPCHandler, expose_rpc 
     14from tracrpc.api import IXMLRPCHandler, expose_rpc 
    1515 
    16 class WikiRPC(AbstractRPCHandler): 
     16class WikiRPC(Component): 
    1717    """ Implementation of the [http://www.jspwiki.org/Wiki.jsp?page=WikiRPCInterface2 WikiRPC API]. """ 
     18 
     19    implements(IXMLRPCHandler) 
    1820 
    1921    def __init__(self): 
     
    2224    def xmlrpc_namespace(self): 
    2325        return 'wiki' 
     26 
     27    def xmlrpc_methods(self): 
     28        yield ('WIKI_VIEW', ((dict, xmlrpclib.DateTime),), self.getRecentChanges) 
     29        yield ('WIKI_VIEW', ((int,),), self.getRPCVersionSupported) 
     30        yield ('WIKI_VIEW', ((str, str), (str, str, int),), self.getPage) 
     31        yield ('WIKI_VIEW', ((str, str, int),), self.getPage, 'getPageVersion') 
     32        yield ('WIKI_VIEW', ((str, str), (str, str, int)), self.getPageHTML) 
     33        yield ('WIKI_VIEW', ((str, str), (str, str, int)), self.getPageHTML, 'getPageHTMLVersion') 
     34        yield ('WIKI_VIEW', ((list,),), self.getAllPages) 
     35        yield ('WIKI_VIEW', ((dict, str), (dict, str, int)), self.getPageInfo) 
     36        yield ('WIKI_VIEW', ((dict, str, int),), self.getPageInfo, 'getPageInfoVersion') 
     37        yield ('WIKI_VIEW', ((bool, str, str, dict),), self.putPage) 
     38        yield ('WIKI_VIEW', ((list, str),), self.listAttachments) 
     39        yield ('WIKI_VIEW', ((xmlrpclib.Binary, str),), self.getAttachment) 
     40        yield ('WIKI_MODIFY', ((bool, str, str, xmlrpclib.Binary),), self.putAttachment) 
     41        yield ('WIKI_VIEW', ((list, str),), self.listLinks) 
    2442 
    2543    def _to_timestamp(self, datetime): 
     
    3149                    author=author, version=int(version)) 
    3250 
    33     @expose_rpc('WIKI_VIEW', dict, xmlrpclib.DateTime) 
    3451    def getRecentChanges(self, since): 
    3552        """ Get list of changed pages since timestamp """ 
     
    4461        return result 
    4562 
    46     @expose_rpc('WIKI_VIEW', int) 
    4763    def getRPCVersionSupported(self): 
    4864        """ Returns 2 with this version of the Trac API. """ 
    4965        return 2 
    5066 
    51     @expose_rpc('WIKI_VIEW', str, str) 
    52     @expose_rpc('WIKI_VIEW', str, str, int) 
    5367    def getPage(self, pagename, version=None): 
    5468        """ Get the raw Wiki text of page, latest version. """ 
     
    6276            raise xmlrpclib.Fault(0, msg) 
    6377 
    64     getPageVersion = getPage 
    65  
    66     @expose_rpc('WIKI_VIEW', str, str) 
    67     @expose_rpc('WIKI_VIEW', str, str, int) 
    6878    def getPageHTML(self, req, pagename, version=None): 
    6979        """ Return page in rendered HTML, latest version. """ 
     
    7282        return '<html><body>%s</body></html>' % html 
    7383 
    74     getPageHTMLVersion = getPageHTML 
    75  
    76     @expose_rpc('WIKI_VIEW', list) 
    7784    def getAllPages(self): 
    7885        """ Returns a list of all pages. The result is an array of utf8 pagenames. """ 
    7986        return list(self.wiki.get_pages()) 
    8087 
    81     @expose_rpc('WIKI_VIEW', dict, str) 
    82     @expose_rpc('WIKI_VIEW', dict, str, int) 
    8388    def getPageInfo(self, pagename, version=None): 
    8489        """ Returns information about the given page. """ 
     
    8893                                   page.version) 
    8994 
    90     getPageInfoVersion = getPageInfo 
    91  
    92     @expose_rpc('WIKI_VIEW', bool, str, str, dict) 
    9395    def putPage(self, req, pagename, content, attributes): 
    9496        """ writes the content of the page. """ 
     
    110112        return True 
    111113 
    112     @expose_rpc('WIKI_VIEW', list, str) 
    113114    def listAttachments(self, pagename): 
    114115        """ Lists attachments on a given page. """ 
    115116        return [pagename + '/' + a.filename for a in Attachment.select(self.env, 'wiki', pagename)] 
    116117 
    117     @expose_rpc('WIKI_VIEW', xmlrpclib.Binary, str) 
    118118    def getAttachment(self, path): 
    119119        """ returns the content of an attachment. """ 
     
    122122        return xmlrpclib.Binary(attachment.open().read()) 
    123123 
    124     @expose_rpc('WIKI_MODIFY', bool, str, str, xmlrpclib.Binary) 
    125124    def putAttachment(self, path, data): 
    126125        """ (over)writes an attachment. """ 
     
    132131        return True 
    133132 
    134     @expose_rpc('WIKI_VIEW', list, str) 
    135133    def listLinks(self, pagename): 
    136134        """ ''Not implemented'' """