problem with replacement for identity functions

2 views
Skip to first unread message

laurentA

unread,
Jul 24, 2008, 4:47:25 AM7/24/08
to TurboGears
Hello.
Because we are building a TurboGears interface to a software that
already provide with identification capabilities, we need to rewrite
the require decorator to not use TG's identification.

I tried to stay as near as possible to the original "require", but I
must have made some mistake, because I have this error:
------
Page handler: <bound method Root.do_decorate of
<laurent.controllers.Root object at 0x883348c>>
Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/
cherrypy/_cphttptools.py", line 121, in _run
self.main()
File "/usr/lib/python2.5/site-packages/CherryPy-2.3.0-py2.5.egg/
cherrypy/_cphttptools.py", line 264, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in do_decorate
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.5-py2.5.egg/
turbogears/controllers.py", line 359, in expose
*args, **kw)
File "<string>", line 5, in run_with_transaction
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.5-py2.5.egg/
turbogears/database.py", line 358, in so_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.5-py2.5.egg/
turbogears/controllers.py", line 372, in <lambda>
mapping, fragment, args, kw)))
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.5-py2.5.egg/
turbogears/controllers.py", line 401, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.5-py2.5.egg/
turbogears/errorhandling.py", line 77, in try_call
return func(self, *args, **kw)
File "/usr/lib/python2.5/site-packages/DecoratorTools-1.7-py2.5.egg/
peak/util/decorators.py", line 601, in do_decorate
frame, getattr(f,'__name__',None), f, frame.f_locals
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.5-py2.5.egg/
turbogears/decorator.py", line 74, in callback
return decorate(v, entangler(v), make_weak_signature(v))
File "/usr/lib/python2.5/site-packages/TurboGears-1.0.5-py2.5.egg/
turbogears/decorator.py", line 92, in make_weak_signature
argnames, varargs, kwargs, defaults = getargspec(func)
File "/usr/lib/python2.5/inspect.py", line 742, in getargspec
raise TypeError('arg is not a Python function')
TypeError: arg is not a Python function
------
We are using TG 1.0.5 with python 2.5.2 and my code is this:
------
import cherrypy
import xmlrpclib

from turbogears.decorator import weak_signature_decorator

s = xmlrpclib.Server('http://server:8000', allow_none=True)

def setCookie(name, value):
cookie = cherrypy.response.simple_cookie
cookie["omc-"+name] = value
#cookie["omc-"+name]["path"] = "/"

def getCookie( name):
cookie = cherrypy.request.simple_cookie
if "omc-"+name in cookie.keys():
return cookie["omc-"+name].value
return None

def setRedirect(dest):
setCookie("redirection", dest)

class not_anonymous():
"""
Predicate for checking whether current visitor is anonymous.
"""

def eval_with_object(self):
session = getCookie("session")
if session != None:
if s.sessionIsValid(session):
return True
return False

def require(predicate=None, obj=None):
def entangle(fn):
def require(func, self, *args, **kwargs):
if predicate is None or \
predicate.eval_with_object():
return fn(self, *args, **kwargs)
setRedirect(cherrypy.request.path)
raise cherrypy.HTTPRedirect("/login")
fn._require = predicate
return require
return weak_signature_decorator(entangle)
------

Does anyone have any idea what I did wrong?

Thanks.

Diez B. Roggisch

unread,
Jul 24, 2008, 2:45:58 PM7/24/08
to turbo...@googlegroups.com
laurentA schrieb:

> Hello.
> Because we are building a TurboGears interface to a software that
> already provide with identification capabilities, we need to rewrite
> the require decorator to not use TG's identification.
>
> I tried to stay as near as possible to the original "require", but I
> must have made some mistake, because I have this error:
<snip/>

> ------
>
> Does anyone have any idea what I did wrong?


Not about the above code - but wouldn't it be easier to write a new
identity-plugin and map your exisiting system to the expected
user/group/permissions-model? I've done so before, it's pretty
straightforward.

Diez

laurentA

unread,
Jul 25, 2008, 2:44:53 AM7/25/08
to TurboGears
On 24 juil, 20:45, "Diez B. Roggisch" <de...@web.de> wrote:

> Not about the above code - but wouldn't it be easier to write a new
> identity-plugin and map your exisiting system to the expected
> user/group/permissions-model? I've done so before, it's pretty
> straightforward.
>
> Diez

I forgot to specify that our software also provide with session
management, too. So I can't use TG's one...
In fact, I didn't activate identity when I initialized the project.
There is not DBMS installed, either...

Does anyone else have any idea why it doesn't work?

Thanks.

Marco Mariani

unread,
Jul 25, 2008, 4:05:22 AM7/25/08
to turbo...@googlegroups.com
laurentA wrote:
> File "/usr/lib/python2.5/inspect.py", line 742, in getargspec
> raise TypeError('arg is not a Python function')
> TypeError: arg is not a Python function
>


Well, check what you are passing to "getargspec".
If the "func" parameter is not a callable, stop reading and follow it.

If it's a callable, try with this monkeypatch: the inspect module should
accept it, but it requires a function or method instead.

> import inspect
> from inspect import isfunction, ismethod, getargs
>
> def getargspec(func):
> if getattr(func, '__call__') and not isfunction(func) and not
> ismethod(func):
> func = func.__call__
> if ismethod(func):
> func = func.im_func
> if not isfunction(func):


> raise TypeError('arg is not a Python function')

> args, varargs, varkw = getargs(func.func_code)
> return args, varargs, varkw, func.func_defaults
>
> inspect.getargspec = getargspec
>


--
This e-mail (and any attachment(s)) is strictly confidential and for use only by intended recipient(s). Any use, distribution, reproduction or disclosure by any other person is strictly prohibited. The content of this e-mail does not constitute a commitment by the Company except where provided for in a written agreement between this e-mail addressee and the Company.
If you are not an intended recipient(s), please notify the sender promptly and destroy this message and its attachments without reading or saving it in any manner.
Any non authorized use of the content of this message constitutes a violation of the obligation to abstain from learning of the correspondence among other subjects, except for more serious offence, and exposes the person responsible to the relevant consequences.

Diez B. Roggisch

unread,
Jul 25, 2008, 5:38:27 AM7/25/08
to turbo...@googlegroups.com
laurentA schrieb:

> On 24 juil, 20:45, "Diez B. Roggisch" <de...@web.de> wrote:
>
>> Not about the above code - but wouldn't it be easier to write a new
>> identity-plugin and map your exisiting system to the expected
>> user/group/permissions-model? I've done so before, it's pretty
>> straightforward.
>>
>> Diez
>
> I forgot to specify that our software also provide with session
> management, too. So I can't use TG's one...
> In fact, I didn't activate identity when I initialized the project.
> There is not DBMS installed, either...

That doesn't matter. I did do visit-tracking (essentiall *not*, or only
in-process-based) and authentication without any DB, just with backend
systems available.

All you need to do is to write your own identity-provider. It doesn't
matter where it takes it's information from - send pigeons if you like.

Diez

laurentA

unread,
Jul 25, 2008, 9:02:41 AM7/25/08
to TurboGears
On 25 juil, 11:38, "Diez B. Roggisch" <de...@web.de> wrote:

>
> That doesn't matter. I did do visit-tracking (essentiall *not*, or only
> in-process-based) and authentication without any DB, just with backend
> systems available.
>
> All you need to do is to write your own identity-provider. It doesn't
> matter where it takes it's information from - send pigeons if you like.

I am trying to do that, but I can't find anywhere a list of what
method is used from the outside, and when (I'm basing mine from
saprovider) in order to know what I need to keep as is, and what to
adapt...

On a side note, I found what caused the error in my first message:
HTTPRedirect!!!
------
class Root(controllers.RootController):
omc = omc()

@expose(template="genshi:laurent.templates.index")
# @omcidentity.require(omcidentity.not_anonymous())
def index(self):
#raise HTTPRedirect("/login")
import time
return dict(now=time.ctime())
------
If I uncomment the raise, index gives me the error, while it works
perfectly otherwise...
I find this a bit frightening...

Diez B. Roggisch

unread,
Jul 25, 2008, 9:07:38 AM7/25/08
to turbo...@googlegroups.com
laurentA schrieb:

> On 25 juil, 11:38, "Diez B. Roggisch" <de...@web.de> wrote:
>
>> That doesn't matter. I did do visit-tracking (essentiall *not*, or only
>> in-process-based) and authentication without any DB, just with backend
>> systems available.
>>
>> All you need to do is to write your own identity-provider. It doesn't
>> matter where it takes it's information from - send pigeons if you like.
>
> I am trying to do that, but I can't find anywhere a list of what
> method is used from the outside, and when (I'm basing mine from
> saprovider) in order to know what I need to keep as is, and what to
> adapt...

I didn't have that list either. just declare an entry-point, configure
your TG-app to use that provider - and then, when something fails,
implement. I did this and in an hour I had a provider working against a
xmlrpc server of our infrastructure that did what I wanted.

Diez

Reply all
Reply to author
Forward
0 new messages