On 7/30/09 2:07 PM, george hu wrote:
> Hi Chris,
>
> I'm confused about the "callable" here. According to the official
> python document - "Note that classes are callable (calling a class
> returns a new instance); class instances are callable if they have a
> call() method."  When I look at the code of the SQLAlchemy Example, we
> have this :
>
> class RootFactory(object):
>      __acl__ = [ (Allow, Everyone, 'view'), (Allow, 'editor', 'edit') ]
>      def __init__(self, environ):
>          self.__dict__.update(environ['bfg.routes.matchdict'])
>
> I don't think the RootFactory is callable in terms of class instance.

A callable is anything that can be called.  A class is a callable.  Instead of 
its __call__ being called, however, its __init__ is called.  __init__ of a 
class 
returns a class instance.

> And when I look at the source code of RoutesRootFactory, I think it is
> the root factory in the description of "A root factory is a callable
> that accepts an environ and returns a root". And the class above is
> the "root" which returns by RoutesRootFactory

In this case, the RootFactory's __init__ is called.  A RootFactory is 
"returned".

- C


>
>
> On Wed, Jul 29, 2009 at 5:09 PM, Chris McDonough<chr...@plope.com>  wrote:
>> A root factory is a callable that accepts an environ and returns a root
>> object.
>>
>> - C
>>
>> On 7/29/09 3:15 PM, george hu wrote:
>>> It is said "root_factory must be a callable that accepts a ....".  I
>>> suspect it is not accurate.  Instead, the root_factory here is
>>> described in Glossary: "    The “root factory” of an repoze.bfg
>>> application is called on every request sent to the application." And
>>> actually the user defined root_factory passed into the make_app
>>> doesn't have to be callable. The callable object is RoutesRootFactory
>>> which is called by "root=self.root_factory(environ)" in __call__
>>> function of Router class.
>>>
>>> The second point is, the user defined root_factory class must include
>>> a constructor which accept a parameter of environ, because its
>>> instance is created in RoutesRootFactory in a form of: return
>>> factory(environ).
>>> _______________________________________________
>>> Repoze-dev mailing list
>>> Repoze-dev@lists.repoze.org
>>> http://lists.repoze.org/listinfo/repoze-dev
>>>
>>
>

_______________________________________________
Repoze-dev mailing list
Repoze-dev@lists.repoze.org
http://lists.repoze.org/listinfo/repoze-dev

Reply via email to