works fine under pyjd. not many modifications required.
l.
# This code is derived from http://groups.google.com/group/pyjamas-dev/browse_thread/thread/f8494b11267092d0/f7f5ed7a81c86c8e?lnk=gst&q=rest#f7f5ed7a81c86c8e
import pyjd
from pyjamas import Window
from pyjamas.HTTPRequest import HTTPRequest
from pyjamas.JSONParser import JSONParser
from pyjamas.ui.VerticalPanel import VerticalPanel
from pyjamas.ui.RootPanel import RootPanel
from pyjamas.ui.Label import Label
# jeeeez...
try:
# included in python 2.6...
from json import dumps, loads
except ImportError:
try:
# recommended library (python 2.5)
from simplejson import dumps, loads
except ImportError:
# who's the pyjs daddy?
from pyjamas.JSONParser import JSONParser
parser = JSONParser()
dumps = getattr(parser, 'encode')
loads = getattr(parser, 'decodeAsObject')
JSONDecodeException = None
class RESTClient(VerticalPanel):
def __init__(self):
VerticalPanel.__init__(self)
self.label = Label()
self.add(self.label)
self.log("REST Client")
HTTPRequest().asyncGet(url="http://localhost:8000/files",
handler=self,
#headers={'Accept': "application/json"},
returnxml=False)
def onCompletion(self, text):
self.log("onCompletion text='" + str(text) + "'")
print text
try:
ar = loads(text)
except:
Window.alert("JSONParser decode Error")
self.log(" Decoded text:'" + str(ar) + "'")
def onError(self, text, code):
self.label.setText(text)
def onTimeout(self, text):
self.label.setText(text)
def log(self, txt):
self.label.setText(self.label.getText() + txt + " | ")
if __name__ == '__main__':
pyjd.setup("http://localhost:8000/pyjamas/client.html")
RootPanel().add(RESTClient())
pyjd.run()