Posts about programming (old posts, page 25)

2009-05-14 10:10

A bit more work in rst2pdf

A bit of time today, too:

  • Started looking at issue reported by msoulier (not reproduced yet)
  • Implemented improvement requested in Issue 111 in r520 (including docs and sample config file). Now it needs to be verified by adk2012
  • Verified Issue 106 isn't happening anymore and closed it.
  • Closed Issue 76 as WontFix because I am not keeping RL2.1 installed :-(
  • Closed Issue 99 because it's fixed in wordaxe 0.3.2

UPDATE: The changelog in SVN is getting more than long enough to deserve a new release!

2009-05-13 11:03

rst2pdf bugfixes

After an awfully long time, I set aside one hour for coding, and spent it on bugfixing for rst2pdf.

Not much work (the fixes were very simple) but at least I am doing something. Important since some people actually use this program ;-)

2009-04-12 10:32

PyQt by Example (Session 4) in spanish! (and some thanks)

Thanks to Leonardo De Luca, session 4 is now available in spanish

Also, thanks to:

  • ZeD who pointed out a bug in session 2 and wrote a sphinx config file (works very well!)
  • Emanuele Rampichini who pointed out a bug (which I have not fixed yet)
  • Simon Edwards who posted about this series in his blog and pointed out some differences if you want to use PyKDE instead of PyQt.

2009-03-22 21:16

Juno and middleware

This is how you add basic authentication to your Juno app:

init({
    'middleware':[('paste.auth.basic.AuthBasicHandler',
                      {'realm':'Admin',
                       'authfunc':valid_user})],
    })

Where valid_user is the obvious function that takes user/pass and returns true/false.

Not exactly a sophisticated role-based auth, but I don't need that for my app (LDAP's access controls take care of it).

2009-03-20 15:57

Pyjamas and Juno

I am currently in dire need of creating a nice admin page for a LDAP addressbook, which should do some slightly unusual things with the data (like manipulating Postfix's virtual table).

So, what the heck, let's also learn something new while I'm at it. The victims: Pyjamas and Juno.

Pyjamas is sort of a Python version of GWT and is bliss. Finally I can code HTML and JS in python ;-)

And Juno is refreshingly simple. Since the whole frontend is done by Pyjamas, all I needed is a way to route JSONRPC calls to python code and operate in the backend.

So, here are two useful snippets:

# 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

Using this, any plain juno method works as a JSONRPC method!

For example:

@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

See? No JSON decoding. And no encoding either, because I am creating the response using this:

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

This is probably not a great implementation but it's good enough for me right now.

2009-03-17 21:10

Translations coming

The spanish translations of most sessions of "PyQt by Example" are almost done, thanks to several volunteers.

Tomorrow I will upload at least one.

If anyone wants to translate them to other languages, I will be happy to include those too.

Contents © 2000-2019 Roberto Alsina