where is the "BaseHandler.__init__" exec ?

Jian Lee lijian.gnu at gmail.com
Thu Apr 29 01:45:52 UTC 2010


Hi, Chris

Thanks for your reply very much. 

After i debug the code step by step, I'm found the "return cl()"
in pykickstart/version.makeVersion() exec the __init__ !

Maybe my description is not clearly, but i'm try to do this.

1. just suppose the DEVEL=F13, use pdb to trace in returnClassForVersion, the v is:

---------------------------------
(Pdb) p v
<class 'f13.F13Handler'>
==================

2. and returnClassForVersion return a Class to makeVersion

3. the makeVersion instance f13.F13Handler(), but f13.F13Handler does not
 have a __init__ func, so exec BaseHandler.__init__  instead.

I've learned those knowledge in book, but have not used in mycode.
So have puzzle above.

Thanks again, for the foolish question.



Chris Lumens <clumens at redhat.com> write:

>> where is the "BaseHandler.__init__" exec ?
>> 
>> look at the following code, after func "returnClassForVersion" have executed,
>> the "commands" attr of "handler" have fixed by "command-object" mapping  already.
>> 
>> but from  the line 173  to 177, there is just a imputil.imp.load_module func , 
>> and the module itself haven't execute a "BaseHandler.__init__" func. 
>> 
>> how the "handler" get a fixed attr "commands" ?
>
>returnClassForVersion just returns the class.  It does not return an
>instance of that class, so you have to do that yourself.  Look at
>makeVersion in pykickstart/version.py.  That returns an instance of the
>class, and that's how the handler gets a commands dict.
>
>Look at pykickstart/base.py:BaseHandler.__init__.  There,
>_registerCommands is called which sets up that attr.
>
>Does that clear things up?
>
>- Chris
>




---------------------

Jian Lee  [ http://jianlee.ylinux.org ]




More information about the Kickstart-list mailing list