JSONRPCClient.py :  » Web-Frameworks » Webware » Webware-1.0.2 » WebKit » Examples » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Web Frameworks » Webware 
Webware » Webware 1.0.2 » WebKit » Examples » JSONRPCClient.py
#
# JSON-RPC demo client contributed by Christoph Zwerschke
#

try:
  import simplejson
except ImportError:
  simplejson = None

from ExamplePage import ExamplePage


class JSONRPCClient(ExamplePage):
  """Demo client for using the JSON-RPC example."""

  def writeJavaScript(self):
    ExamplePage.writeJavaScript(self)
    if not simplejson:
      return
    self.write('''\
      <script type="text/javascript" src="jsonrpc.js"></script>
      <script type="text/javascript">
      <!--
      jsonrpc = new JSONRpcClient("JSONRPCExample");
      methods = jsonrpc.system.listMethods();
      function dojsonrpc() {
        p = document.getElementById("parameter").value;
        i = document.getElementById("method").selectedIndex;
        r = jsonrpc[methods[i]](p);
        document.getElementById("result").value = r;
      }
      -->
      </script>
    ''')

  def writeContent(self):
    self.write('''\
      <h3>JSON-RPC Example</h3>
      <p>This example shows how you can call methods
      of a <a href="http://json-rpc.org">JSON-RPC</a> servlet
      built with Webware for Python from yourwebbrowser import 
      via JavaScript (which has to be activated to run this demo).
      <noscript><span style="color:red">
      Unfortunately, JavaScript is not activated.
      </span></noscript></p>
      <p>The example uses a JSON-RPC JavaScript client
      based on Jan-Klaas' "JavaScript o lait" library
      (<a href="http://jsolait.net">jsolait</a>).
      You can also use other JavaScript libraries and toolkits
      such as <a href="http://dojotoolkit.org">dojo</a> or
      <a href="http://pyjamas.pyworks.org">pyjamas</a>
      for that purpose.</p>
      <p>In order to run the JSON-RPC servlet,
      <a href="http://cheeseshop.python.org/pypi/simplejson">simplejson</a>
      must be installed on your server.''')
    if not simplejson:
      self.write(''' <span style="color:red">
      Unfortunately, simplejson is not installed.</span>''')
      return
    self.write('''</p>
      <p>Type in any example text to be used as input parameter,
      choose one of the available methods to be invoked by the
      example servlet and press the button to display the result.</p>
      <table>
      <tr align="center">
      <th>Input parameter</th>
      <th>Remote method</th>
      <th>Result</th>
      </tr><tr align="center">
      <td>
      <input id="parameter" type="text" size="20" value="Hello, World!">
      </td><td>
      <select id="method" size="1">
      <script type="text/javascript">
      <!--
      for (m in methods)
        document.writeln('<option>' + methods[m] + '</option>');
      -->
      </script>
      </select>
      </td><td>
      <input type="text" size="20" id="result">
      </td>
      </tr><tr align="center">
      <td colspan="3">
      <input type="button" value="Invoke remote method"
        onclick="dojsonrpc()">
      </td>
      </tr>
      </table>
    ''')
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.