Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Pyjamas y Juno

Así que, que miérco­le­s, apren­da­mos al­go mien­tras tan­to. Las víc­ti­ma­s: Py­ja­mas y Juno.

Py­ja­mas es una ver­sión Py­thon de GWT y es una ben­di­ció­n: fi­nal­men­te pue­do es­cri­bir HT­ML y JS en py­thon ;-)

Y Juno es re­fres­cante­men­te sim­ple. Ya que to­do el fron­tend es­tá he­cho en Py­ja­ma­s, lo úni­co que ne­ce­si­to es una ma­ne­ra de rou­tear lla­ma­das JSONRPC a có­di­go py­thon y ope­rar en el ba­cken­d.

Así que acá hay dos frag­men­tos úti­le­s:

# 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):
        data = json.loads(postdata)
        id, method, params = data["id"],data["method"],[web,]+data["params"][1]
        return target(*params,**kwargs)
    return wrapper

usan­do es­to, cual­quier me­to­do Juno fun­cio­na co­mo mé­to­do JSONRP­C!


def list(web,startwith='*',method=None):
    except ldap.LDAPError, e:
    return resp

¿Ven? Na­da de de­co­di­fi­car JSO­N. Y no co­di­fi­car tam­po­co, por­que creo la res­pues­ta usan­do es­to:

# 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):

Pro­ba­ble­men­te no sea una gran im­ple­men­ta­ción pe­ro me sir­ve por aho­ra.

Ibn Saeed / 2009-04-26 22:39:


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.

Contents © 2000-2024 Roberto Alsina