U  W[4$ã@sÔdZddlZddlZddlZddlZddlmZzddlmZWnek rTYnXddl m Z m Z ddl m Z e ¡add„ZGd d „d eƒZiZd d „Zd d„ZGdd„deƒZdd„Zdd„Zddd„ZdS)z& *Real* reloading support for Python. éN)Úreload)Ú InstanceType)ÚlogÚreflect)Ú_PY3cCs ttddƒ}|dkrdS||kS)a· Compare to types.ClassType in a py2/3-compatible way Python 2 used comparison to types.ClassType to check for old-style classes Python 3 has no concept of old-style classes, so if ClassType doesn't exist, it can't be an old-style class - return False in that case. Note that the type() of new-style classes is NOT ClassType, and so this should return False for new-style classes in python 2 as well. Z ClassTypeNF)ÚgetattrÚtypes)ÚtZ _ClassType©r ú8/usr/lib/python3/dist-packages/twisted/python/rebuild.pyÚ _isClassTypes r c@s,eZdZdZeZdd„Zdd„Zdd„ZdS) Ú SensitivezÐ A utility mixin that's sensitive to rebuilds. This is a mixin for classes (usually those which represent collections of callbacks) to make sure that their code is up-to-date before running. cCs|jtk}|S©N)Ú lastRebuild)ÚselfZynr r r ÚneedRebuildUpdate=s zSensitive.needRebuildUpdatecCst ¡|_dSr)Útimer©rr r r ÚrebuildUpToDateBszSensitive.rebuildUpToDatecCsŠt|ƒ}|tjkrt|ƒS|tjkrL|jdkruszlatestClass..)Z __builtin__ÚbuiltinsZ __metaclass__N) rZ namedModulerrrÚ __bases__ÚtupleÚ TypeErrorrr ÚdictÚ__dict__)ZoldClassr%ZnewClassZnewBasesZctorr r r ros      ÿrc@seZdZdZdS)Ú RebuildErrorzT Exception raised when trying to rebuild a class whereas it's not possible. N)rrrr r r r r r/Šsr/cCst|jƒ|_dS)z, Updates an instance to be current. N)rÚ __class__rr r r ÚupdateInstance‘sr1cCs@|dkrtdƒ‚t|ƒt d t |j¡|¡¡t||ƒ}|S)z< A getattr method to cause a class to be refreshed. Ú__del__zWithout this, Python segfaults.z#(rebuilding stale {} instance ({}))) ÚAttributeErrorr1rrÚformatrÚqualr0r)rÚnameÚresultr r r Ú__injectedgetattr__™s ÿ r8éc Cs€t ¡at|dƒr |js tdƒ‚|r:t d t|j ƒ¡¡ddl m }d|_ |j }|tt|ƒ<i}i}i}i}|rˆt d t|j ƒ¡¡| ¡D]À\}} tt| ƒƒrÔ| j|j krÒd|| <|rÒtj d ¡tj ¡qt| ƒtjkr| j|j krPd|| <|rPtj d ¡tj ¡qt| tƒr| j|j krd|| <|rtj d ¡tj ¡q| |¡| |¡|j} | ¡}| ¡}| ¡}|rªt d ¡t d  t|j ƒ¡¡t|ƒt  ¡|rÖt d t|j ƒ¡¡|D]j} t!|| j ƒ| krt d t" #| ¡¡¡n:|r$tj d¡tj ¡d| _$| j  %¡t&| _'|j | _qÚ|rTddl(} |D]^} t!|| j ƒ}|| krŠt d t" #| ¡¡¡n*|  )| ¡D]}t!|ddƒ| kr”||_*q”qX|rÞt d ¡t d t|j ƒ¡¡d}t+j, ¡D]`\}}|d}||ksì|dkrqìt|dƒs&qìt|dƒr6qìd}|j  ¡D]Ö\}} z t-| ƒWnt.k rtYqDYnX| | ƒrêtt| ƒƒr´|rªtj d ¡tj ¡t/| ƒ}n$|rÐtj d ¡tj ¡t0| ƒ}d}t1|||ƒn.tt| ƒƒrD| j$D]}| |ƒrþt/| ƒqþqD|rì|sì|ddkrìtj d¡tj ¡qìd|_ |r|t d ¡t d t|j ƒ¡¡|S)zO Reload a module and do as much as possible to replace its references. ÚALLOW_TWISTED_REBUILDzI am not allowed to be rebuilt.zRebuilding {}...r)Ú componentsTz (scanning {}): r9ÚcÚfÚoÚz (reload {})z (cleaning {}): z)WARNING: class {} not replaced by reload!Úxr Nz-WARNING: new-class {} not replaced by reload!r0z (fixing {}): Ú__file__Z __bundle__é Ú.Fz Rebuilt {}.)2rrÚhasattrr:Ú RuntimeErrorrrr4ÚstrrÚtwisted.pythonr;ZALLOW_DUPLICATESr.r#r!Úitemsr rrZlogfileÚwriteÚflushrrr"Ú isinstanceÚupdateÚ __contains__ÚkeysrÚ linecacheÚ clearcacherrr5r*Úclearr8Ú __getattr__ÚgcZ get_referrersr0ÚsysÚmodulesÚhashÚ ExceptionrrÚsetattr)r%ZdoLogr;ÚdZ newclassesÚclassesZ functionsÚvaluesÚkÚvZ fromOldModuleZclazzrSZnclassZgaÚrZmodcountZmkÚmodZchangedZnvr'r r r Úrebuild§sâ                ÿ      ÿ               r`)r9)r rTrrrOÚimprrÚ ImportErrorrGrrZtwisted.python.compatrrr Úobjectr r#rrrWr/r1r8r`r r r r Ús*  ,