Ñò Ã#xPc@s‡dZddkZddkZddkZddkZddkZddklZddkZddkZddk Z ddk l Z ddk Z ddk Z ddk lZddklZlZlZlZlZddklZddkTd Zd „Zd efd „ƒYZd efd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdS(sÀ Plugin framework. The classes in this module make heavy use of Python container emulation. If you are unfamiliar with this Python feature, see http://docs.python.org/ref/sequence-types.html iÿÿÿÿN(tpath(tEnv(t_(tReadOnlyt NameSpacetlocktislockedt check_name(tDEFAULT_CONFIG(t*s%s: need a %r; got a %r: %rcCsOt|ddƒdjotSt|iddƒdjotS|iidjS(sv If the object has self.env.mode defined and that mode is production return True, otherwise return False. tenvtmodet productionN(tgetattrtNonetFalseR R (tobj((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pytis_production_mode0s tSetProxycBs2eZdZd„Zd„Zd„Zd„ZRS(sc A read-only container with set/sequence behaviour. This container acts as a proxy to an actual set-like object (a set, frozenset, or dict) that is passed to the constructor. To the extent possible in Python, this underlying set-like object cannot be modified through the SetProxy... which just means you wont do it accidentally. cCsjtttf}t|ƒ|jo tdt|ƒ|fƒ‚n||_t|ƒpt|ƒndS(sR :param s: The target set-like object (a set, frozenset, or dict) s %r not in %rN(tsett frozensettdictttypet TypeErrort _SetProxy__sRR(tselftstallowed((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt__init__Es    cCs t|iƒS(s? Return the number of items in this container. (tlenR(R((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt__len__Psccs#xt|iƒD] }|VqWdS(s< Iterate (in ascending order) through keys. N(tsortedR(Rtkey((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt__iter__VscCs ||ijS(sv Return True if this container contains ``key``. :param key: The key to test for membership. (R(RR ((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt __contains__]s(t__name__t __module__t__doc__RRR!R"(((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyR<s   t DictProxycBs)eZdZd„Zd„Zd„ZRS(sd A read-only container with mapping behaviour. This container acts as a proxy to an actual mapping object (a dict) that is passed to the constructor. To the extent possible in Python, this underlying mapping object cannot be modified through the DictProxy... which just means you wont do it accidentally. Also see `SetProxy`. cCsVt|ƒtj o tdt|ƒtfƒ‚n||_tt|ƒi|ƒdS(s> :param d: The target mapping object (a dict) s %r is not %rN(RRRt _DictProxy__dtsuperR&R(Rtd((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyRqs  cCs |i|S(s| Return the value corresponding to ``key``. :param key: The key of the value you wish to retrieve. (R'(RR ((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt __getitem__zsccs!x|D]}|i|VqWdS(sE Iterate (in ascending order by key) through values. N(R'(RR ((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt__call__‚s(R#R$R%RR*R+(((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyR&fs  t MagicDictcBseZdZd„ZRS(s A mapping container whose values can be accessed as attributes. For example: >>> magic = MagicDict({'the_key': 'the value'}) >>> magic['the_key'] 'the value' >>> magic.the_key 'the value' This container acts as a proxy to an actual mapping object (a dict) that is passed to the constructor. To the extent possible in Python, this underlying mapping object cannot be modified through the MagicDict... which just means you wont do it accidentally. Also see `DictProxy` and `SetProxy`. cCs6y ||SWn#tj otd|ƒ‚nXdS(sƒ Return the value corresponding to ``name``. :param name: The name of the attribute you wish to retrieve. sno magic attribute %rN(tKeyErrortAttributeError(Rtname((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt __getattr__žs (R#R$R%R0(((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyR,ŠstPlugincBs„eZdZeZd Zd„Zd„Ze eƒZ d„Z d„Z d„Z defd„ƒYZd„Zd „Zd „ZRS( s% Base class for all plugins. cCshd|_t|_t|_tiƒ|_|i}|i |_ |i |_ d|i |i f|_ td„|iDƒƒ|_t|iƒ|_|iipd|i |_n)t|iƒiddƒdiƒ|_ti|tƒ|idjoti|i dƒ|_nt|iti ƒp6t!t"|i dti t#|iƒ|ifƒ‚ndS(Ns%s.%scss)x"|]}d|i|ifVqWdS(s%s.%sN(R$R#(t.0tb((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pys ½s s<%s>s iis.label($Rt _Plugin__apiRt_Plugin__finalize_calledt_Plugin__finalizedt threadingtRLockt_Plugin__finalize_lockt __class__R#R/R$tmoduletfullnamettuplet __bases__tbasesRR%tdoctmsgtsummarytunicodetsplittstriptlog_mgrt get_loggertTruetlabelttexttFixMet isinstancetLazyTextRt TYPE_ERRORR(Rtcls((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyR³s0       (  cCs|iS(s Return `API` instance passed to `set_api()`. If `set_api()` has not yet been called, None is returned. (R4(R((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt __get_apiÑscCs||iiiƒza|itjpt‚|iodSt|_|iƒt|_t |ƒpt |ƒnWdQXdS(sè Finalize plugin initialization. This method calls `_on_finalize()` and locks the plugin object. Subclasses should not override this method. Custom finalization is done in `_on_finalize()`. N( R9t__exit__t __enter__R6RtAssertionErrorR5RHt _on_finalizeRR(R((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pytfinalizeÚs      cCsdS(s¬ Do custom finalization. This method is called from `finalize()`. Subclasses can override this method in order to add custom finalization. N((R((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyRTîscCs7|iiiƒz|ip|iƒnWdQXdS(sR Finalize plugin initialization if it has not yet been finalized. N(R9RQRRR6RU(R((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pytensure_finalized÷s t finalize_attrcBs)eZdZdZdd„Zd„ZRS(s/ Create a stub object for plugin attribute that isn't set until the finalization of the plugin initialization. When the stub object is accessed, it calls `ensure_finalized()` to make sure the plugin initialization is finalized. The stub object is expected to be replaced with the actual attribute value during the finalization (preferably in `_on_finalize()`), otherwise an `AttributeError` is raised. This is used to implement on-demand finalization of plugin initialization. R/tvaluecCs||_||_dS(N(R/RX(RR/RX((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyRs cCsy|djp|idjo|iS|iƒyt||iƒSWn/tj o#td|i|ifƒ‚nXdS(Ns7attribute '%s' of plugin '%s' was not set in finalize()(RtapiRXRVR R/t RuntimeErrorR.(RRRO((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt__get__s (snamesvalueN(R#R$R%t __slots__RRR[(((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyRWÿs  c Csæ|idjp td‚|dj p td‚||_t|tƒpdSx:|D]2}t||ƒ pt‚t||||ƒqVWxSdD]K}t||ƒo5t||ƒ pt‚t||t||ƒƒq“q“WdS(s2 Set reference to `API` instance. s!set_api() can only be called onces!set_api() argument cannot be NoneNR tcontext(senvscontext(R4RRSRLtAPIthasattrtsetattrR (RRYR/((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pytset_api#s cGsY|f|}|id|ƒti|ƒ}|djotid|d|ƒ‚ndS(s— Call ``executable`` with ``args`` using subprocess.call(). If the call exits with a non-zero exit status, `ipalib.errors.SubprocessError` is raised, from which you can retrieve the exit code by checking the SubprocessError.returncode attribute. This method does *not* return what ``executable`` sent to stdout... for that, use `Plugin.callread()`. s Calling %rit returncodetargvN(tdebugt subprocesstcallterrorstSubprocessError(Rt executabletargsRctcode((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyRf4s  cCsd|ii|iifS(s½ Return 'module_name.class_name()' representation. This representation could be used to instantiate this Plugin instance given the appropriate environment. s%s.%s()(R:R$R#(R((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt__repr__Es N(R#R$R%RHtfinalize_earlyRRIRt_Plugin__get_apitpropertyRYRURTRVtobjectRWRaRfRl(((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyR1ªs     $  t RegistrarcBs5eZdZd„Zd„Zd„Zed„ZRS(s Collects plugin classes as they are registered. The Registrar does not instantiate plugins... it only implements the override logic and stores the plugins in a namespace per allowed base class. The plugins are instantiated when `API.finalize()` is called. cGsKtd„|Dƒƒ|_tƒ|_tt|ƒit|iƒƒƒdS(sw :param allowed: Base classes from which plugins accepted by this Registrar must subclass. cssx|]}|hfVqWdS(N((R2tbase((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pys as N(Rt_Registrar__allowedRt_Registrar__registeredR(RqRt_Registrar__base_iter(RR((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyR\s ccsŸx˜|iiƒD]‡\}}t|ƒpti|ƒpt‚n|i}t|ƒpt||ƒ pt‚nt||t |ƒƒ||fVqWdS(N( Rst iteritemsRtinspecttisclassRSR#R_R`R,(RRrtsub_dR/((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt __base_itergs    ccs£t|ƒpti|ƒpt‚nt}xB|iiƒD]1\}}t||ƒot}||fVq>q>W|p%t i d|d|ii ƒƒ‚ndS(sõ Iterates through allowed bases that ``klass`` is a subclass of. Raises `errors.PluginSubclassError` if ``klass`` is not a subclass of any allowed base. :param klass: The plugin class to find bases for. tpluginR?N( RRwRxRSRRsRvt issubclassRHRgtPluginSubclassErrortkeys(RtklasstfoundRrRy((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyt __findbasesqs   cCsýti|ƒptd|ƒ‚n||ijotid|ƒ‚nxœ|i|ƒD]‹\}}|i|jo3|p(tid|id|id|ƒ‚qØn0|o(ti d|id|id|ƒ‚n|||i®s (RLRSRÿRR#R/R×R$R;R{R=R?RR(Rtp(Rý(s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyR¨s  (R#R$R((Rý(s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyR§sc3sÀx¹|D]±}t||ƒpt‚|ˆjoˆ|ƒˆ|Æs t_API__finalizedc3sx|]}ˆ|ƒVqWdS(N((R2R(R(s3/usr/lib/python2.6/site-packages/ipalib/plugable.pys Ùs Råc3sx|]}ˆ|ƒVqWdS(N((R2R(R(s3/usr/lib/python2.6/site-packages/ipalib/plugable.pys Ûs N(RžRâRpRRRRŠR RRˆR_RSR¡t itervaluesRRaRYRVRRHR=(RRtproduction_modeR/Rrt namespaceR((RRRåRR Rýs3/usr/lib/python2.6/site-packages/ipalib/plugable.pyRU‹s@       ",  " %  N(R#R$R%RRžRâRŽRRRÎRÚRÛRãRU(((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyR^¯s     <+  .( R%treR«RwR7R°RReRÅRgtconfigRRîRJRRrRRRRRt constantsRtipapython.ipa_log_managerRNRRR&R,R1RqR^(((s3/usr/lib/python2.6/site-packages/ipalib/plugable.pyts0          (  *$ ¨]