Commits

Anonymous committed bf25b16

Added RPC to metanav, and added some navigation and protocol presentation fallback in case of no available protocols.

Comments (0)

Files changed (1)

t5437/t5437-protocol_api-r7194.diff

 diff --git a/trunk/tracrpc/templates/xmlrpclist.html b/trunk/tracrpc/templates/xmlrpclist.html
 --- a/trunk/tracrpc/templates/xmlrpclist.html
 +++ b/trunk/tracrpc/templates/xmlrpclist.html
-@@ -7,23 +7,25 @@
+@@ -7,23 +7,30 @@
    <xi:include href="layout.html" />
    <xi:include href="macros.html" />
    <head>
 +        <h3>${proto_name}</h3>
 +        ${proto_docs}
 +      </div>
++      <div py:if="not rpc.protocols" style="margin:2em;">
++        <span class="important" style="width:50%;padding:1em;">
++          <strong>Error:</strong> No available protocols for handling RPC requests.
++        </span>
++      </div>
 +
 +      <h2>RPC Funtions</h2>
  
            <dt>
              <h3 id="${'xmlrpc.' + to_unicode(namespace.namespace)}">
                ${namespace.namespace} - ${namespace.description}
-@@ -50,60 +52,6 @@
+@@ -50,60 +57,6 @@
          </dl>
        </div>
        
 diff --git a/trunk/tracrpc/web_ui.py b/trunk/tracrpc/web_ui.py
 --- a/trunk/tracrpc/web_ui.py
 +++ b/trunk/tracrpc/web_ui.py
-@@ -6,132 +6,61 @@
+@@ -6,132 +6,75 @@
  (c) 2009      ::: www.CodeResort.com - BV Network AS (simon-code@bvnetwork.no)
  """
  
 -from StringIO import StringIO
  from pkg_resources import resource_filename
 -from types import GeneratorType
--
--import genshi
+ 
+ import genshi
  
  from trac.core import *
 -from trac.perm import PermissionError
 +from trac.web.api import RequestDone, HTTPUnsupportedMediaType
  from trac.web.main import IRequestHandler
 -from trac.web.chrome import ITemplateProvider, add_stylesheet
-+from trac.web.chrome import ITemplateProvider, add_stylesheet, add_script
++from trac.web.chrome import ITemplateProvider, add_stylesheet, add_script, \
++                        INavigationContributor
  from trac.wiki.formatter import wiki_to_oneliner
  
 -from tracrpc.api import IXMLRPCHandler, XMLRPCSystem
 -        """ Extending the JSON decoder to support some additional types:
 -        1. {'__jsonclass__': ["datetime", "<rfc3339str>"]} => datetime.datetime
 -        2. {'__jsonclass__': ["binary", "<base64str>"]} => xmlrpclib.Binary """
--
++class RPCWeb(Component):
++    """ Handle RPC calls from HTTP clients, as well as presenting a list of
++        methods available to the currently logged in user. Browsing to
++        <trac>/rpc or <trac>/login/rpc will display this list. """
+ 
 -        dt = re.compile(
 -            '^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})(?:\.(\d{1,}))?')
--
++    implements(IRequestHandler, ITemplateProvider, INavigationContributor)
+ 
 -        def _normalize(self, obj):
 -            """ Helper to traverse JSON decoded object for custom types. """
 -            if isinstance(obj, tuple):
 -                return to_unicode(obj)
 -            else:
 -                return obj
--
++    protocols = ExtensionPoint(IRPCProtocol)
+ 
 -        def decode(self, obj, *args, **kwargs):
 -            obj = json.JSONDecoder.decode(self, obj, *args, **kwargs)
 -            return self._normalize(obj)
--    
++    # INavigationContributor methods
+     
 -except ImportError:
 -    json = None
--
++    def get_active_navigation_item(self, req):
++        pass
+ 
 -class XMLRPCWeb(Component):
 -    """ Handle XML-RPC calls from HTTP clients, as well as presenting a list of
-+class RPCWeb(Component):
-+    """ Handle RPC calls from HTTP clients, as well as presenting a list of
-         methods available to the currently logged in user. Browsing to
+-        methods available to the currently logged in user. Browsing to
 -        <trac>/xmlrpc or <trac>/login/xmlrpc will display this list. """
 -
 -    content_type_re = re.compile(r'(text|application)/(xml|json)')
-+        <trac>/rpc or <trac>/login/rpc will display this list. """
+-
+-    implements(IRequestHandler, ITemplateProvider)
++    def get_navigation_items(self, req):
++        if 'XML_RPC' in req.perm:
++            yield ('metanav', 'rpc', genshi.builder.tag.a('RPC',
++                                    href=req.href.rpc(),
++                                    title="Remote Procedure Call API"))
  
-     implements(IRequestHandler, ITemplateProvider)
- 
-+    protocols = ExtensionPoint(IRPCProtocol)
-+
      # IRequestHandler methods
 +
      def match_request(self, req):
 +                        req.args['protocol'] = protocol
 +                        return True
 +        # No protocol call, need to handle for docs or error if handled path
-+        return must_handle_request
++        return req.path_info in ['/rpc', '/login/rpc'] or must_handle_request
  
      def process_request(self, req):
 -
              req.perm.require('XML_RPC') # Need at least XML_RPC
              namespaces = {}
              for method in XMLRPCSystem(self.env).all_methods(req):
-@@ -139,172 +68,35 @@
+@@ -139,172 +82,35 @@
                  if namespace not in namespaces:
                      namespaces[namespace] = {
                          'description' : wiki_to_oneliner(