Changeset 2609

Show
Ignore:
Timestamp:
09/03/07 04:30:23 (1 year ago)
Author:
athomas
Message:

Port of XML-RPC to 0.11. Thanks to the work of eblot, stp, ben@groovie.org,
osimons and mmay :)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • xmlrpcplugin/trunk/setup.py

    r1278 r2609  
    88    author='Alec Thomas', 
    99    author_email='alec@swapoff.org', 
    10     url='http://trac-hacks.swapoff.org/wiki/XmlRpcPlugin', 
     10    url='http://trac-hacks.org/wiki/XmlRpcPlugin', 
    1111    description='XML-RPC interface to Trac', 
    1212    zip_safe=True, 
  • xmlrpcplugin/trunk/tracrpc/api.py

    r1950 r2609  
    44import types 
    55import xmlrpclib 
     6import datetime 
     7from tracrpc.util import to_datetime 
    68try: 
    79    set = set 
     
    8890            result = 0 
    8991        elif isinstance(result, dict): 
    90             pass 
     92            for key,val in result.iteritems(): 
     93                if isinstance(val, datetime.datetime): 
     94                    result[key] = to_datetime(val) 
     95            #pass 
    9196        elif not isinstance(result, basestring): 
    9297            # Try and convert result to a list 
     
    225230        indicate API breaking changes, while minor version changes are simple 
    226231        additions, bug fixes, etc. """ 
    227         return [0, 2
     232        return [0, 3
  • xmlrpcplugin/trunk/tracrpc/search.py

    r1278 r2609  
    11from trac.core import * 
    22from tracrpc.api import IXMLRPCHandler 
    3 from trac.Search import ISearchSource 
     3from tracrpc.util import to_datetime 
     4from trac.search import ISearchSource 
    45 
    56try: 
     
    4748 
    4849        results = [] 
     50        converters = [unicode, unicode, to_datetime, unicode, unicode]           
    4951        for source in self.search_sources: 
    5052            for result in source.get_search_results(req, query, filters): 
    51                 result = map(unicode, result) 
     53                result = [f(v) for f,v in zip(converters, result)] 
    5254                results.append(['/'.join(req.base_url.split('/')[0:3]) 
    5355                                + result[0]] + list(result[1:])) 
  • xmlrpcplugin/trunk/tracrpc/templates/xmlrpclist.cs

    r1519 r2609  
    1 <?cs include "header.cs"?> 
    2 <?cs include "macros.cs"?> 
     1<!DOCTYPE html 
     2    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
     3    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
     4<html xmlns="http://www.w3.org/1999/xhtml" 
     5      xmlns:py="http://genshi.edgewall.org/" 
     6      xmlns:xi="http://www.w3.org/2001/XInclude"> 
     7  <xi:include href="layout.html" /> 
     8  <xi:include href="macros.html" /> 
     9  <head> 
     10    <title>XML-RPC</title> 
     11  </head> 
     12  <body> 
    313 
    4 <div id="ctxtnav" class="nav"></div
     14    <div id="ctxtnav" class="nav" /
    515 
    6 <div id="content" class="wiki"> 
     16    <div id="content" class="wiki"> 
    717 
    8 <h2>XML-RPC exported functions</h2> 
     18      <h2>XML-RPC exported functions</h2> 
    919 
    10 <div id="searchable"> 
    11 <dl> 
    12 <?cs each:namespace = xmlrpc.functions ?> 
     20      <div id="searchable"> 
     21        <dl py:for="key in xmlrpc.functions" py:with="namespace = xmlrpc.functions[key]"> 
     22          <dt> 
     23            <h3 id="${'xmlrpc.' + to_unicode(namespace.namespace)}"> 
     24              ${namespace.namespace} - ${namespace.description} 
     25            </h3> 
     26          </dt> 
     27          <dd> 
     28            <table class="listing tickets"> 
     29              <thead> 
     30                <tr> 
     31                  <th>Function</th> 
     32                  <th>Description</th> 
     33                  <th><nobr>Permission required</nobr></th> 
     34                </tr> 
     35              </thead> 
     36              <tbody py:for="idx, function in enumerate(namespace.methods)"> 
     37                <tr class="${'color3-' + (idx % 2 == 0 and 'even' or 'odd')}"> 
     38                  <td><nobr>${function[0]}</nobr></td> 
     39                  <td>${function[1]}</td> 
     40                  <td>${function[2]}</td> 
     41                </tr> 
     42              </tbody> 
     43            </table> 
     44          </dd> 
     45        </dl> 
     46      </div> 
    1347 
    14 <dt><h3 id=xmlrpc.<?cs var:namespace.namespace ?>><?cs var:namespace.namespace ?> - <?cs var:namespace.description ?></h3></dt> 
    15 <dd> 
    16 <table class="listing tickets"> 
    17 <thead> 
    18 <tr> 
    19 <th>Function</th> 
    20 <th>Description</th> 
    21 <th><nobr>Permission required</nobr></th> 
    22 </tr> 
    23 </thead> 
     48      <script type="text/javascript"> 
     49        addHeadingLinks(document.getElementById("searchable")); 
     50      </script> 
     51    </div> 
    2452 
    25 <?cs set idx = #0 ?> 
    26 <tbody> 
    27 <?cs each:function = namespace.methods ?> 
    28 <tr class="color3-<?cs if idx % #2 == 0 ?>even<?cs else ?>odd<?cs /if ?>" style=""> 
    29 <td><nobr><?cs var:function.0?></nobr></td><td><?cs var:function.1?></td><td><?cs var:function.2 ?></td> 
    30 </tr> 
    31 <?cs set idx = idx + #1 ?> 
    32 <?cs /each ?> 
    33 </tbody> 
    34 </table> 
    35 </dd> 
    36 <?cs /each ?> 
    37 </dl> 
    38 </div> 
    39  
    40 <script type="text/javascript"> 
    41 addHeadingLinks(document.getElementById("searchable")); 
    42 </script> 
    43  
    44 </div> 
    45  
    46 <?cs include:"footer.cs"?> 
     53  </body> 
     54</html> 
  • xmlrpcplugin/trunk/tracrpc/ticket.py

    r1950 r2609  
    11from trac.attachment import Attachment 
    22from trac.core import * 
     3from trac.perm import PermissionCache 
    34from tracrpc.api import IXMLRPCHandler, expose_rpc 
    4 from tracrpc.util import to_timestamp 
     5from tracrpc.util import to_timestamp, to_datetime 
    56import trac.ticket.model as model 
    67import trac.ticket.query as query 
     
    6566        ticketSystem = TicketSystem(self.env) 
    6667        t = model.Ticket(self.env, id) 
    67         return ticketSystem.get_available_actions(t, req.perm
     68        return ticketSystem.get_available_actions(req, t
    6869 
    6970    def get(self, req, id): 
    7071        """ Fetch a ticket. Returns [id, time_created, time_changed, attributes]. """ 
    7172        t = model.Ticket(self.env, id) 
    72         return (t.id, t.time_created, t.time_changed, t.values) 
     73        return (t.id, to_datetime(t.time_created),  
     74                to_datetime(t.time_changed), t.values) 
    7375 
    7476    def create(self, req, summary, description, attributes = {}, notify=False): 
     
    119121    def changeLog(self, req, id, when=0): 
    120122        t = model.Ticket(self.env, id) 
    121         return t.get_changelog(when) 
     123        for date, author, field, old, new, permanent in t.get_changelog(when): 
     124            yield (to_datetime(date), author, field, old, new, permanent) 
    122125    # Use existing documentation from Ticket model 
    123126    changeLog.__doc__ = pydoc.getdoc(model.Ticket.get_changelog) 
     
    127130        description, size, time, author) for each attachment.""" 
    128131        for t in Attachment.select(self.env, 'ticket', ticket): 
    129             yield (t.filename, t.description or '', t.size, t.time, t.author) 
     132            yield (t.filename, t.description or '', t.size,  
     133                   to_datetime(t.date), t.author) 
    130134 
    131135    def getAttachment(self, req, ticket, filename): 
     
    241245 
    242246        def get(self, req, name): 
    243             i = cls(self.env, name) 
    244             return i.value 
     247            if (cls.__name__ == 'Status'): 
     248               i = cls(self.env) 
     249               x = name 
     250            else:  
     251               i = cls(self.env, name) 
     252               x = i.value 
     253            return x 
    245254        get.__doc__ = """ Get a ticket %s. """ % cls.__name__.lower() 
    246255 
  • xmlrpcplugin/trunk/tracrpc/util.py

    r1735 r2609  
    11import time 
     2import xmlrpclib 
    23 
    34def to_timestamp(datetime): 
    45    """ Convert xmlrpclib.DateTime string representation to UNIX timestamp. """ 
    56    return time.mktime(time.strptime('%s UTC' % datetime.value, '%Y%m%dT%H:%M:%S %Z')) - time.timezone 
     7 
     8def to_datetime(dt): 
     9    """ Convert a datetime.datetime object to a xmlrpclib DateTime object """ 
     10    return xmlrpclib.DateTime(dt.utctimetuple()) 
  • xmlrpcplugin/trunk/tracrpc/web_ui.py

    r1175 r2609  
     1from pkg_resources import resource_filename 
    12from trac.core import * 
    23from trac.web.main import IRequestHandler 
     
    910    """ Handle XML-RPC calls from HTTP clients, as well as presenting a list of 
    1011        methods available to the currently logged in user. Browsing to 
    11         <trac>/xmlrpc will display this list. """ 
     12        <trac>/xmlrpc or <trac>/login/xmlrpc will display this list. """ 
    1213 
    1314    implements(IRequestHandler, ITemplateProvider) 
     
    4950                    raise Exception('%s: %s\n%s' % (method.name, str(e), out.getvalue())) 
    5051            add_stylesheet(req, 'common/css/wiki.css') 
    51             req.hdf['xmlrpc.functions'] = namespaces 
    52             return 'xmlrpclist.cs', None 
     52            return ('xmlrpclist.cs', {'xmlrpc': {'functions': namespaces}}, None) 
    5353 
    5454        # Handle XML-RPC call 
     
    7474 
    7575    def get_templates_dirs(self): 
    76         from pkg_resources import resource_filename 
    7776        return [resource_filename(__name__, 'templates')] 
  • xmlrpcplugin/trunk/tracrpc/wiki.py

    r1735 r2609  
    55import xmlrpclib 
    66import posixpath 
     7import time 
    78 
    89from trac.core import * 
     
    1314from trac.attachment import Attachment 
    1415from tracrpc.api import IXMLRPCHandler, expose_rpc 
    15 from tracrpc.util import to_timestamp 
     16from tracrpc.util import to_timestamp, to_datetime 
    1617 
    1718class WikiRPC(Component): 
     
    9394        if page.exists: 
    9495            last_update = page.get_history().next() 
    95             return self._page_info(page.name, last_update[1], last_update[2], 
    96                                    page.version) 
     96            return self._page_info(page.name,  
     97                                   time.mktime(last_update[1].utctimetuple()),  
     98                                   last_update[2], page.version) 
    9799 
    98100    def putPage(self, req, pagename, content, attributes):