Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Nifty python/xmlrpc thing

Us­ing python, it's triv­ial to turn any mod­ule in­to a XML­R­PC serv­er. So, if you are care­ful writ­ing your app in a mod­u­lar way, you can move the back­end else­where in very lit­tle code.

For ex­am­ple, if I had a mod­ule that has some func­tion­al­i­ty, like this (mod­ule.py):

#Stupid simple module

def  add(a,b):
        return a+b

A pro­gram would use it like this:

import module
print module.add(2,4)

Now, if I move the mod­ule to a re­mote box (server), cre­ate this xml­r­pc serv­er pro­gram in the serv­er (and run it ;-):

#!/usr/bin/env python

#Simple generic XML-RPC server

import module

import SimpleXMLRPCServer

server = SimpleXMLRPCServer.SimpleXMLRPCServer(("localhost", 800
0))

server.register_instance(module)
server.serve_forever()

And this bridge mod­ule in the client (client­mod­ule.py):

import xmlrpclib

server = xmlrpclib.Server('http://remotserver.com:8000')

Now this very slight­ly mod­i­fied ver­sion of our pro­gram works in ex­act­ly the same way as the orig­i­nal:

from clientmodule import server as module

print module.add(2,4)

Of course this has is­sues:

  • It has no se­cu­ri­ty
  • XML­R­PC could in­tro­duce er­rors and the pro­gram does­n't catch them.
  • It could be made even more trans­par­ent with some more python­ing

But any­way, I think it's cute.

Late at night....

...and still lots to do. Well, not re­al­ly late, just 8P­M, but lots and lots and lots to do.

I re­al­ly should start say­ing no to some job­s. Or hire some­one.

As of now, I am teach­ing 3 cours­es, to­tal 21 hours/week, plus con­sult­ing (about 30 hours/week). Call me lazy, but 50h­s/week is just too much.

Sure, I get paid for it, but what do I want mon­ey for if I can't do any­thing I wan­t?

Of course what I want is to play "Driv­er 2"[1] for hours and then code a lit­tle. But hey, to each his own taste.

[1] Yes, I am play­ing Playsta­tion 1 games. I own a PS1. It's nice, it hooks to the TV, so the im­age is big, and the sound is loud. That's about all I ask of the gam­ing ex­pe­ri­ence :-)

Bartleblog now in sf.net

So, the link below will disappear in a minute or two. Right now, you can get it via CVS.

Bartleblog 0.0.1

I got a few mails ask­ing to see Bartle­blog... well, if you have a work­ing PyQt, and a work­ing PyDS (ad­voga­to sup­port is to­tal­ly bro­ken right now), and you have a good back­up of your blog, then you may try to get it from here (Use CVS)

It is just not use­ful for a nor­mal blog­ger right now.

I hope the nice guys at pyc­s.net don't mind me post­ing it here (it's small­er than some of the dy­nam­ic HTML pages ;-)

In a cou­ple of days I will move it to sf.net, as soon as I get the project ap­proved.


Contents © 2000-2024 Roberto Alsina