what the code "return cls()" meaning

Asked by Oliver Huang

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.

Question information

Language:
English Edit question
Status:
Answered
For:
OpenStack Compute (nova) Edit question
Assignee:
No assignee Edit question
Last query:
Last reply:
Revision history for this message
Russell Bryant (russellb) said :
#1

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/functions.html#classmethod

http://stackoverflow.com/questions/38238/what-are-class-methods-in-python-for

Can you help with this problem?

Provide an answer of your own, or ask Oliver Huang for more information if necessary.

To post a message you must log in.