Revamping the require decorator

1 view
Skip to first unread message

Kevin H

unread,
Feb 26, 2008, 11:19:02 AM2/26/08
to Authority
Right now the @require decorator included in Authority falls into the
category of "the simplest thing that could possibly work". Its
biggest problem ATM, is that it takes no arguments, which it will need
to in order to take conditions like "has_permission", etc.

As I understand it there are basically two ways to do this, the
"nested functions" method, and the "class-based method". This article
shows an example of each with a simple decorator:
http://muharem.wordpress.com/2006/10/19/python-decorator-mini-study-part-2-of-3/

My question to the list is: Which should we use? Personally I find
the class-based method easier to understand, but I'd be interested in
hearing other's experiences with these kind of issues.

Another issue with this decorator is that because it checks the user
object, which is stored in the session, it will need access to at
least the beaker session. Right now it is getting this from the WSGI
environment, which is brought in using pylons. In the interest of
decoupling from Pylons, is there another (better) way of getting the
session object?

Also, any ideas/examples on how to test the require decorator (or
decorators in general) would be most welcome.

Kevin Horn

Kevin Horn

unread,
Feb 26, 2008, 3:27:52 PM2/26/08
to Authority
bit of an update...

I've cobbled together a class-based version of the decorator in my local copy, but it isn't quite right yet, I don't think.

I've also done up some "conditions", which with the decorator, should make Authority significantly more functional.

I'll try to get these tested and committed today, but I may not have a chance.  I may just commit the untested code in order to share between home and work.

Kevin Horn

Chris Perkins

unread,
Feb 26, 2008, 3:49:28 PM2/26/08
to authori...@googlegroups.com
I am ok if you commit it broken.  I can work my unit tests around it.  If you know how to make a mock-eviron class I am all ears, that is my latest challenge.

-chris

Kevin Horn

unread,
Feb 26, 2008, 5:38:02 PM2/26/08
to authori...@googlegroups.com
OK, you asked for it :)

Committed in #25.

Kevin Horn

Kevin Horn

unread,
Feb 26, 2008, 11:36:58 PM2/26/08
to authori...@googlegroups.com
FYI...

Committed a fix (#26) to make the require2 class-based decorator at least sort of work.  I've only tested it with the httpbasicmatch authscheme, but it seems to work in at least that case.  Also note, I haven't tried it with any of the conditions yet...I'm a little short on time today.

I'd love for you guys to try it out and see how it goes.  If we can make the middleware and the require decorator solid, then I think we can make authority do just about whatever we want.

Kevin Horn
Reply all
Reply to author
Forward
0 new messages