Proxying every function in a module

Josh West josh at laculine.com
Fri May 25 11:50:55 EDT 2007


Kind and wise fellows,

I've got a web application with the following structure:

1) module of 100 functions corresponding to user actions (e.g. 
"update_profile()", "organisations_list()")
2) a wsgi callable which maps urls to functions eg 
/organisations/list/?sort=date_created is mapped to 
organisations_list("dateCreated")
3) mapping is performed using inspect.getargspec()
4) a bunch of html generating templates

In the templates I want to generate urls by referencing the function to 
which they map, rather than the url, e.g.

<a href="${organisations_list('dateCreated'})'">Sort By Date Created</a>

In other words, I want to always refer to functions, rather than mixing 
up function calls and urls

I would like a class that proxies all the 100 functions in the user 
actions module. When a proxied function is called via this class it 
should return the url to which it is mapped rather than executing the 
user action function.

<a href="${proxyclass.organisations_list('dateCreated')}">Sort By Date 
Created</a>

should produce:

<a href="/organisations/list/?sort=date_created">Sort By Date Created</a>

Obviously, I don't want to write and maintain copies of these 100 
functions in another class.

My question is therefore: what is the best way to proxy these 100 functions?

Thanks





Tim Arnold wrote:
> Hi, I'm using ElementTree which is wonderful. I have a need now to write out 
> an XML file with these two headers:
> <?xml version="1.0" encoding="UTF-8" ?>
> <?NLS TYPE="org.eclipse.help.toc"?>
>
> My elements have the root named tocbody and I'm using:
> newtree = ET.ElementTree(tocbody)
> newtree.write(fname)
>
> I assume if I add the encoding arg I'll get the xml header:
> newtree = ET.ElementTree(tocbody)
> newtree.write(fname,encoding='utf-8')
>
> but how can I get the <?NLS TYPE="org.eclipse.help.toc"?> into the tree?
>
> python2.4.1,hpux10,ElementTree1.2.6
>
> thanks,
> --Tim 
>
>
>   




More information about the Python-list mailing list