Ticket #1075: xmlrpc-11.2-genshi.diff

File xmlrpc-11.2-genshi.diff, 11.4 kB (added by osimons, 1 year ago)

xmlrpc-11.2.patch converted to Genshi (no ClearSilver needed). Note the template name still ends with .cs to make the diff more correct (works fine), but should change to .html and update setup.py package_data if integrated into the repos.

  • trac011-upgrade/externals/trac-xmlrpcplugin/setup.py

    old new  
    77    version='0.1', 
    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, 
    1313    packages=['tracrpc'], 
  • trac011-upgrade/externals/trac-xmlrpcplugin/tracrpc/api.py

    old new  
    33import inspect 
    44import types 
    55import xmlrpclib 
     6import datetime 
     7from tracrpc.util import to_datetime 
    68try: 
    79    set = set 
    810except: 
     
    8789        if result is None: 
    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 
    9398            try: 
     
    224229        version number, second is the minor. Changes to the major version 
    225230        indicate API breaking changes, while minor version changes are simple 
    226231        additions, bug fixes, etc. """ 
    227         return [0, 2
     232        return [0, 3
  • trac011-upgrade/externals/trac-xmlrpcplugin/tracrpc/web_ui.py

    old new  
     1from pkg_resources import resource_filename 
    12from trac.core import * 
    23from trac.web.main import IRequestHandler 
    34from trac.web.chrome import ITemplateProvider, add_stylesheet 
     
    89class XMLRPCWeb(Component): 
    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) 
    1415 
     
    4849                    traceback.print_exc(file=out) 
    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 
    5555        args, method = xmlrpclib.loads(req.read(int(req.get_header('Content-Length')))) 
     
    7373        return [] 
    7474 
    7575    def get_templates_dirs(self): 
    76         from pkg_resources import resource_filename 
    7776        return [resource_filename(__name__, 'templates')] 
  • trac011-upgrade/externals/trac-xmlrpcplugin/tracrpc/util.py

    old new  
    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()) 
  • trac011-upgrade/externals/trac-xmlrpcplugin/tracrpc/ticket.py

    old new  
    11from trac.attachment import Attachment 
    22from trac.core import * 
    33from tracrpc.api import IXMLRPCHandler, expose_rpc 
    4 from tracrpc.util import to_timestamp 
     4from tracrpc.util import to_timestamp, to_datetime 
    55import trac.ticket.model as model 
    66import trac.ticket.query as query 
    77from trac.ticket.api import TicketSystem 
     
    6969    def get(self, req, id): 
    7070        """ Fetch a ticket. Returns [id, time_created, time_changed, attributes]. """ 
    7171        t = model.Ticket(self.env, id) 
    72         return (t.id, t.time_created, t.time_changed, t.values) 
     72        return (t.id, to_datetime(t.time_created),  
     73                to_datetime(t.time_changed), t.values) 
    7374 
    7475    def create(self, req, summary, description, attributes = {}, notify=False): 
    7576        """ Create a new ticket, returning the ticket ID. """ 
     
    118119 
    119120    def changeLog(self, req, id, when=0): 
    120121        t = model.Ticket(self.env, id) 
    121         return t.get_changelog(when) 
     122        for date, author, field, old, new, permanent in t.get_changelog(when): 
     123            yield (to_datetime(date), author, field, old, new, permanent) 
    122124    # Use existing documentation from Ticket model 
    123125    changeLog.__doc__ = pydoc.getdoc(model.Ticket.get_changelog) 
    124126 
     
    126128        """ Lists attachments for a given ticket. Returns (filename, 
    127129        description, size, time, author) for each attachment.""" 
    128130        for t in Attachment.select(self.env, 'ticket', ticket): 
    129             yield (t.filename, t.description or '', t.size, t.time, t.author) 
     131            yield (t.filename, t.description or '', t.size,  
     132                   to_datetime(t.date), t.author) 
    130133 
    131134    def getAttachment(self, req, ticket, filename): 
    132135        """ returns the content of an attachment. """ 
  • trac011-upgrade/externals/trac-xmlrpcplugin/tracrpc/wiki.py

    old new  
    44    from StringIO import StringIO 
    55import xmlrpclib 
    66import posixpath 
     7import time 
    78 
    89from trac.core import * 
    910from trac.perm import IPermissionRequestor 
     
    1213from trac.wiki.formatter import wiki_to_html 
    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): 
    1819    """ Implementation of the [http://www.jspwiki.org/Wiki.jsp?page=WikiRPCInterface2 WikiRPC API]. """ 
     
    9293        page = WikiPage(self.env, pagename, version) 
    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): 
    99101        """ writes the content of the page. """ 
  • trac011-upgrade/externals/trac-xmlrpcplugin/tracrpc/search.py

    old new  
    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: 
    67    a = set() 
     
    4647        self.env.log.debug("Searching with %s" % filters) 
    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:])) 
    5456        return results 
  • trac011-upgrade/externals/trac-xmlrpcplugin/tracrpc/templates/xmlrpclist.cs

    old new  
    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>