Ir al contenido principal

Ralsina.Me — El sitio web de Roberto Alsina

Publicaciones sobre python (publicaciones antiguas, página 4)

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­

#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


And this bridge mod­ule in the client (client­mod­

import xmlrpclib

server = xmlrpclib.Server('')

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.

Bartleblog now in

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­ 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, as soon as I get the project ap­proved.

klog == bartleblog

I won­der if bartle­bog is a good name. It sure is bet­ter than klog, and I like XIXth cen­tu­ry lit ref­er­ences.

I al­so sus­pect al­most noone will get it, and that it just can't be pro­nounced ;-)

I want­ed it to be bartle­by, but there is some tool us­ing that name in source­forge.

On oth­er is­sues: it's HOT here!.

Contents © 2000-2023 Roberto Alsina