Ask Your Question
0

what the code "return cls()" meaning

asked 2012-03-13 08:48:56 -0600

oliver-huang gravatar image

I am a newcomer of openstack and python. When I read the code in file nova-2011.3\nova\api\openstack__init__.py

I found these lines

class APIRouter(base_wsgi.Router): """ Routes requests on the OpenStack API to the appropriate controller and method. """

@classmethod
def factory(cls, global_config, **local_config):
    """Simple paste factory, :class:`nova.wsgi.Router` doesn't have one"""
    return cls()

My question is: what the code "return cls()" means in the factory() class method? where to find the factory() method body?

Please help me, thx.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
0

answered 2012-03-22 19:57:43 -0600

Since factory is marked as a @classmethod, the first argument is the class, APIRouter. So, "return cls()" is effectively the same thing as "return APIRouter()".

http://docs.python.org/library/functi...

http://stackoverflow.com/questions/38...

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Get to know Ask OpenStack

Resources for moderators

Question Tools

1 follower

Stats

Asked: 2012-03-13 08:48:56 -0600

Seen: 1,705 times

Last updated: Mar 22 '12