Pyjamas y Juno
Así que, que miércoles, aprendamos algo mientras tanto. Las víctimas: Pyjamas y Juno.
Pyjamas es una versión Python de GWT y es una bendición: finalmente puedo escribir HTML y JS en python ;-)
Y Juno es refrescantemente simple. Ya que todo el frontend está hecho en Pyjamas, lo único que necesito es una manera de routear llamadas JSONRPC a código python y operar en el backend.
Así que acá hay dos fragmentos útiles:
# This decorator decodes JSONRPC arguments as sent by Pyjamas to # Juno, and calls the target function with the decoded version. def JSONRemote(target): def wrapper(web,*args,**kwargs): postdata=web.input().keys()[0] data = json.loads(postdata) id, method, params = data["id"],data["method"],[web,]+data["params"][1] kwargs['method']=method return target(*params,**kwargs) return wrapper
usando esto, cualquier metodo Juno funciona como método JSONRPC!
Ejemplo:
@route('/user') @JSONRemote def list(web,startwith='*',method=None): try: result=search(filter='(&(uid=*@bigclient.ar)(sn=%s*))'%startwith) resp=JSONResponse(result) except ldap.LDAPError, e: resp=JSONResponse(None,e.desc) return resp
¿Ven? Nada de decodificar JSON. Y no codificar tampoco, porque creo la respuesta usando esto:
# This class creates a correct JSON response from Juno as required by Pyjamas class JSONResponse(JunoResponse): def __init__(self,result=None,error=None,id=None,code=200): JunoResponse.__init__(self) self.headers['Content-Type']='text/javascript' self.append(json.dumps({'result':result,'error':error,'id':id,'code':code}))
Probablemente no sea una gran implementación pero me sirve por ahora.
Hello
Just wanted to highlight the meaning of Pyjama
=========================
Pajamas, also spelled pyjamas can refer to several related types of clothing. The original paijama are loose, lightweight trousers fitted with drawstring waistbands and worn in South and West Asia by both sexes.[1] In many English-speaking nations, pajamas are loose-fitting, two-piece garments derived from the original garment and worn chiefly for sleeping,[2] but sometimes also for lounging,[3] also by both sexes.[4] More generally, pajamas may refer to several garments, for both daywear and nightwear, derived from traditional pyjamas and involving variations of style and material.
========================
http://en.wikipedia.org/wik...