HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/ipalib/__pycache__/plugable.cpython-39.opt-1.pyc
a

�N(ili�@stdZddlmZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
Z
ddlZddlZddl
Z
ddlmZddlmZddlmZddlmZdd	lmZmZmZdd
lmZddlmZmZddlm Z m!Z!dd
l"m#Z#m$Z$ddl%m&Z&m'Z'm(Z(e
j)�re*Z+e�,e-�Z.dZ/dd�Z0Gdd�d�Z1Gdd�de�Z2Gdd�de�Z3Gdd�de�Z4Gdd�de!�Z5dS)z�
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
�)�MappingN)�path)�errors)�Env)�_)�
classproperty)�ReadOnly�lock�islocked)�DEFAULT_CONFIG)�ipa_log_manager�ipautil)�IPAOptionParser�IPAFormatter)�LOGGING_FORMAT_FILE�LOGGING_FORMAT_STDERR)�VERSION�API_VERSION�DEFAULT_PLUGINSz%s: need a %r; got a %r: %rccs�tj�|�|krtj�|�s dStj�|�r0dSd}tt�|��D]N}|�|�sRqBtj�||�}tj�	|�snqB|dt
|��}|dkr�qB|VqBdS)z<
    Iterate through module names found in ``src_dir``.
    Nz.py�__init__)�osr�abspath�isdir�islink�sorted�listdir�endswith�join�isfile�len)Zsrc_dir�suffix�nameZpyfile�module�r#�3/usr/lib/python3.9/site-packages/ipalib/plugable.py�find_modules_in_dirAs
r%c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�RegistryaA decorator that makes plugins available to the API

    Usage::

        register = Registry()

        @register()
        class obj_mod(...):
            ...

    For forward compatibility, make sure that the module-level instance of
    this object is named "register".
    cCst��|_dS�N)�collections�OrderedDict�_Registry__registry��selfr#r#r$rdszRegistry.__init__cs��fdd�}|S)Ncs@t|�std|��|�jvr*tj|d��t�|d��j|<|S)z�
            Register the plugin ``plugin``.

            :param plugin: A subclass of `Plugin` to attempt to register.
            �plugin must be callable; got %r��plugin)�callable�	TypeErrorr*rZPluginDuplicateError�dictr.��kwargsr,r#r$�registerhs
z#Registry.__call__.<locals>.registerr#)r,r4r5r#r3r$�__call__gszRegistry.__call__cCst|j���Sr')�iterr*�valuesr+r#r#r$�__iter__|szRegistry.__iter__N)�__name__�
__module__�__qualname__�__doc__rr6r9r#r#r#r$r&Vs
r&c@s�eZdZdZdZdd�Zedd��Zee�Z	edd��Z
ee
�Zed	d
��Zee�Z
edd��Zee�Zed
d��Zee�Zedd��Zedd��Zedd��Zedd��Zdd�Zdd�Zdd�ZGdd�d�Zdd �Zd!S)"�Pluginz%
    Base class for all plugins.
    �1cCs ||_d|_d|_t��|_dS)NF)�_Plugin__api�_Plugin__finalize_called�_Plugin__finalized�	threading�RLock�_Plugin__finalize_lock)r,�apir#r#r$r�szPlugin.__init__cCs|jSr'�r:��clsr#r#r$Z
__name_getter�szPlugin.__name_gettercCsd�|j|j�S)Nz{}/{})�formatr!�versionrHr#r#r$Z__full_name_getter�szPlugin.__full_name_gettercCs|jSr')�	__bases__rHr#r#r$Z__bases_getter�szPlugin.__bases_gettercCs|jSr')r=rHr#r#r$Z__doc_getter�szPlugin.__doc_gettercCs<|j}t|�js d|j|jfSt|��dd�d��SdS)Nz<%s.%s>z

�r)�docr�msgr;r:�unicode�split�strip)rIrNr#r#r$Z__summary_getter�s
zPlugin.__summary_gettercCs|jS)z?
        Return `API` instance passed to `__init__()`.
        )r@r+r#r#r$rF�sz
Plugin.apicCs|jjSr')r@�envr+r#r#r$rS�sz
Plugin.envcCs|jjSr')r@�Backendr+r#r#r$rT�szPlugin.BackendcCs|jjSr')r@�Commandr+r#r#r$rU�szPlugin.CommandcCsf|j�L|jrWd�dSd|_|��d|_|j��sDt|�Wd�n1sX0YdS)z�
        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()`.
        NT)rErA�_on_finalizerBr@�is_production_moder	r+r#r#r$�finalize�s	
zPlugin.finalizecCsdS)z�
        Do custom finalization.

        This method is called from `finalize()`. Subclasses can override this
        method in order to add custom finalization.
        Nr#r+r#r#r$rV�szPlugin._on_finalizecCs8|j�|js|��Wd�n1s*0YdS)zR
        Finalize plugin initialization if it has not yet been finalized.
        N)rErBrXr+r#r#r$�ensure_finalized�szPlugin.ensure_finalizedc@s&eZdZdZdZddd�Zdd�ZdS)	zPlugin.finalize_attra/
        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!�valueNcCs||_||_dSr'rZ)r,r!r[r#r#r$r�szPlugin.finalize_attr.__init__cCsZ|dus|jdur|jS|��zt||j�WStyTtd|j|jf��Yn0dS)Nz7attribute '%s' of plugin '%s' was not set in finalize())rFr[rY�getattrr!�RuntimeError�AttributeError)r,�objrIr#r#r$�__get__�s�zPlugin.finalize_attr.__get__)N)r:r;r<r=�	__slots__rr`r#r#r#r$�
finalize_attr�s

rbcCsd|jj|jjfS)z�
        Return 'module_name.class_name()' representation.

        This representation could be used to instantiate this Plugin
        instance given the appropriate environment.
        z%s.%s())�	__class__r;r:r+r#r#r$�__repr__s�zPlugin.__repr__N)r:r;r<r=rKr�classmethodZ_Plugin__name_getterrr!Z_Plugin__full_name_getter�	full_nameZ_Plugin__bases_getter�basesZ_Plugin__doc_getterrNZ_Plugin__summary_getterZsummary�propertyrFrSrTrUrXrVrYrbrdr#r#r#r$r>�s>








$r>csdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Z�fdd�Zd
d�Z	dd�Z
dd�Zdd�Z�Z
S)�APINameSpacecCs||_||_d|_d|_dSr')�_APINameSpace__api�_APINameSpace__base�_APINameSpace__plugins�_APINameSpace__plugins_by_key)r,rF�baser#r#r$rszAPINameSpace.__init__cs��jdur�jdurdS�jj}t�}i}�_�jjD]h}t�fdd�|jD��sVq8|�|�|||<|||j	|j
f<|||j<|j
|�|j	d�kr8|||j	<q8t
|t�d�d��_dS)Nc3s|]}t|�j�VqdSr')�
issubclassrk��.0�br+r#r$�	<genexpr>,�z+APINameSpace.__enumerate.<locals>.<genexpr>r?rf)�key)rlrmrj�_API__default_map�set�
_API__plugins�anyrg�addr!rKrf�getr�operator�
attrgetter)r,Zdefault_mapZpluginsZkey_dictr/r#r+r$Z__enumerate#s


zAPINameSpace.__enumeratecCs|��t|j�Sr')�_APINameSpace__enumeraterrlr+r#r#r$�__len__7szAPINameSpace.__len__cCs|��||jvSr'�r~rm�r,rur#r#r$�__contains__;szAPINameSpace.__contains__cCs|��t|j�Sr')r~r7rlr+r#r#r$r9?szAPINameSpace.__iter__cs2|��t���}|�dd�|D��|��|S)Ncss|]}|jVqdSr'�r!)rq�pr#r#r$rsGrtz'APINameSpace.__dir__.<locals>.<genexpr>)r~�super�__dir__�extend�sort)r,�names�rcr#r$r�Cs

zAPINameSpace.__dir__cCs|��|j|Sr'r�r�r#r#r$�
get_pluginKszAPINameSpace.get_plugincCs|�|�}|j�|�Sr')r�rj�_get)r,rur/r#r#r$�__getitem__Os
zAPINameSpace.__getitem__cCs
t�|�Sr')�six�
itervaluesr+r#r#r$r6SszAPINameSpace.__call__cCs*z
||WSty$t|��Yn0dSr')�KeyErrorr^r�r#r#r$�__getattr__Vs
zAPINameSpace.__getattr__)r:r;r<rr~rr�r9r�r�r�r6r��
__classcell__r#r#r�r$risrics�eZdZdZ�fdd�Zedd��Zedd��Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zd0dd�Zd1dd�Zd2dd �Zd!d"�Zd#d$�Zd%d&�Zd3d(d)�Zd*d+�Zd,d-�Zd.d/�Z�ZS)4�APIzK
    Dynamic API object through which `Plugin` instances are accessed.
    csBtt|���t�|_i|_i|_i|_i|_t�|_	t
�|_dSr')r�r�rrwrx�_API__plugins_by_keyrv�_API__instances�
_API__next�
_API__donerrSr+r�r#r$rbszAPI.__init__cCst�dSr'��NotImplementedErrorr+r#r#r$rglsz	API.basescCst�dSr'r�r+r#r#r$�packagespszAPI.packagescCs
t|j�S)zL
        Return the number of plugin namespaces in this API object.
        )rrgr+r#r#r$rtszAPI.__len__cCsdd�|jD�S)zN
        Iterate (in ascending order) through plugin namespace names.
        css|]}|jVqdSr'rG)rqrnr#r#r$rs~rtzAPI.__iter__.<locals>.<genexpr>)rgr+r#r#r$r9zszAPI.__iter__cCs|t|�vS)z�
        Return True if this API object contains plugin namespace ``name``.

        :param name: The plugin namespace name to test for membership.
        )rw�r,r!r#r#r$r��szAPI.__contains__cCs4||vr(zt||�WSty&Yn0t|��dS)z�
        Return the plugin namespace corresponding to ``name``.

        :param name: The name of the plugin namespace you wish to retrieve.
        N�r\r^r�r�r#r#r$r��szAPI.__getitem__c	cs:|D]0}zt||�VWqty2t|��Yq0qdS)zQ
        Iterate (in ascending order by name) through plugin namespaces.
        Nr�r�r#r#r$r6�s
zAPI.__call__cCst|jdd�dkS)z�
        If the object has self.env.mode defined and that mode is
        production return True, otherwise return False.
        �modeNZ
production)r\rSr+r#r#r$rW�szAPI.is_production_modecCs.||jvrtd|jj|f��|j�|�dS)Nz%s.%s() already called)r��	Exceptionrcr:rzr�r#r#r$Z__doing�s

�zAPI.__doingcCs||jvrt||��dSr')r�r\r�r#r#r$Z__do_if_not_done�s
zAPI.__do_if_not_donecCs
||jvSr')r�r�r#r#r$�isdone�sz
API.isdoneNc
Ksv|�d�|jjfi|��|jjfitt���|s>|��}||_t�	�}|j
sZ|jjr^dS|jjrntj
}ntj}|�|�|jD]Z}t�d|�}|s�q�t�|�d��}t|j|�}t�d|�}|D]}	|�t�|	|��q�q�tj}|jjr�tj
}n*|jjdk�r |jjdk�rtj}ntj}t��}
|
�|�|
�t�t��|� |
�t!�"�}|�#�dv�rnt$j%|d	��|jj&d
v�r�dS|jj'du�r�dSt(�)|jj'�}t(�*|��s�zt+�,|�Wn"t-�y�t.�/d|�YdS0tj}|jj�r�tj
}|jj'du�rrzt�0|jj'�}
Wn8t1�yL}
zt.�/d|jj'|
�WYd}
~
n.d}
~
00|
�|�|
�t�t2��|� |
�dS)
z?
        Initialize environment variables and logging.
        �	bootstrapNz?^log_logger_level_(debug|info|warn|warning|error|critical|\d+)$rMz\s*,\s*�clir>�utf8zutf-8)�encoding�ZdummyZ	unit_testzCould not create log_dir %rzCannot open log file %r: %s)3�_API__doingrS�
_bootstrapZ_finalize_corer2r�build_global_parser�parser�logging�	getLogger�handlers�validate_api�debug�DEBUG�INFOZsetLevel�re�matchrZconvert_log_level�groupr\rQZ	addFilterZFilter�context�verboseZWARNINGZ
StreamHandlerZsetFormatterZ	FormatterrZ
addHandler�sys�getfilesystemencoding�lowerrZSystemEncodingErrorr��logr�dirnamerr�makedirs�OSError�logger�errorZFileHandler�IOErrorr)r,r��	overridesZroot_logger�level�attrr�r[ZregexpsZregexpZhandlerZfseZlog_dir�er#r#r$r��s|


�


(
�z
API.bootstrapc
Cs�dd�}|durRtdt�dddttfd�gd	��d
�}|��|jddd
dd�|jdddddd�|jdddd|ddd�|jdddd d�|jd!dd"d�|jd#d$d%d&d�|d'kr�|jd(d)dd*d�|jd+d,d-d.d/d0�|jd1d2d-d3d4d0�|S)5zD
        Add global options to an IPAOptionParser instance.
        cSs0tj�|�s$|�td�t|d��||j_dS)Nz%(filename)s: file not found)�filename)rrrr�rr2r8�conf)�option�optr[r�r#r#r$�config_file_callbacks
�z5API.build_global_parser.<locals>.config_file_callbackNFz0%prog [global-options] COMMAND [command-options]zManage an IPA domainzVERSION: %s, API_VERSION: %s�
)z0See "ipa help topics" for available help topics.z@See "ipa help <TOPIC>" for more information on a specific topic.z6See "ipa help commands" for the full list of commands.zFSee "ipa <COMMAND> --help" for more information on a specific command.)Zadd_help_option�	formatter�usage�descriptionrK�epilogz-hz--help�helpzShow this help message and exit)�actionr�z-erSzKEY=VAL�appendz#Set environment variable KEY to VAL)�dest�metavarr�r�z-cr��FILE�callback�stringzLoad configuration from FILE.)r�r�r�r��typer�z-dz--debug�
store_truezProduce full debuging outputz
--delegatez"Delegate the TGT to the IPA serverz-vz	--verbose�countzEProduce more verbose output. A second -v displays the XML-RPC requestr�z-az--prompt-allz(Prompt for ALL values (even if optional)z-nz--no-prompt�store_false�interactivez'Prompt for NO values (even if required))r�r�r�z-fz
--no-fallback�fallbackz7Only use the server configured in /etc/ipa/default.conf)r�IPAHelpFormatterrrrZdisable_interspersed_argsZ
add_option)r,r�r�r�r#r#r$r�sZ��
���
��
�
�
�
�zAPI.build_global_parserc
	Cs�|�||�}|��\}}i}|jdur�|jD]h}z|�dd�}WntyRYn0t|�dkr~|\}}	|	��|t|���<q,t�	t
dj|d����q,dD] }t||d�}	|	dur�|	||<q�t
|d�r�|j|d<|dur�||d	<|j|fi|��||fS)
N�=rM�zUnable to parse option {item})�item)r�r�r�Z
prompt_allr�r�Zdelegate�prodZ
webui_prodr�)r��
parse_argsrSrQ�
ValueErrorrrR�strrZOptionErrorrrJr\�hasattrr�r�)
r,r�r��options�argsr�r�r8rur[r#r#r$�bootstrap_with_global_optionsMs2


�


z!API.bootstrap_with_global_optionscCs>|�d�|�d�|jjdvr$dS|jD]}|�|�q*dS)z�
        Load plugins from all standard locations.

        `API.bootstrap` will automatically be called if it hasn't been
        already.
        �load_pluginsr�r�N)r��_API__do_if_not_donerSr�r��add_package)r,�packager#r#r$r�ms


zAPI.load_pluginscsd|j�|j}t�t�|��}tj��d�d}t�t�|j��}||krXtj	�|d��t
�d��t|dt
|��}�fdd�|D�}|D]�}t
�d|�zt�|�}Wnptjy�}	z(t
�d	||	j�WYd
}	~	q�WYd
}	~	n8d
}	~	0t�y|jj}
|
�rt
�d|��Yn0z|�|�Wq�tj�y\}	zt
�d|	�WYd
}	~	q�d
}	~	00q�d
S)
zx
        Add plugin modules from the ``package``.

        :param package: A package from which to add modules.
        �.r)r!�filez%importing all plugin modules in %s...�modulescsg|]}d��|f��qS)r�)r)rqZmname�Zpackage_namer#r$�
<listcomp>�rtz#API.add_package.<locals>.<listcomp>zimporting plugin module %szskipping plugin module %s: %sNzcould not load plugin module %sz%s)r:�__file__rr�rr�r��
rpartitionrZPluginsPackageErrorr�r�r\r%�	importlib�
import_moduleZSkipPluginModule�reasonr�rSZstartup_traceback�	exception�
add_module�PluginModuleError)r,r�Zpackage_fileZpackage_dir�parentZ
parent_dirr�r!r"r��tbr#r�r$r�|s8� zAPI.add_packagecCsXz
|j}WntyYn*0t|t�rF|D]}|jfi|��q,dStj|jd��dS)zn
        Add plugins from the ``module``.

        :param module: A module from which to add plugins.
        Nr�)r5r^�
isinstancer&�
add_pluginrr�r:)r,r"r5r4r#r#r$r��s

zAPI.add_moduleFcCs�t|�std|��|jD]}t||j�rq@qtj||jd��|j�|j�}|r�|sr|r^dStj	|j
|j|d��|j�
|�||j|<n |r�|r�dStj|j
|j|d��|j�|�||j|j<dS)z�
        Add the plugin ``plugin``.

        :param plugin: A subclass of `Plugin` to attempt to add.
        :param override: If true, override an already added plugin.
        r-)r/rgN)rnr!r/)r0r1rgrorZPluginSubclassErrorr�r{rfZPluginOverrideErrorr:r!rx�remover�ZPluginMissingOverrideErrorrz)r,r/�overrideZno_failrn�prevr#r#r$r��s>
���zAPI.add_pluginc	sb|�d�|�d�|jjdur@|jj|jjkr@t�d|jj�|jD]l}|jjs`|j	t
vr�qFnDz|j|j}Wnt
y�Yn"0t�|j�}t�|�}||kr�qF|j|j|j<qF|��}|jD]Z�|jD]0}t�fdd�|jD��s�q�|jjs�|�|�q̈j}|�s
t||t|���q�t�|j�D]$}|�s4|jj�s*|��|�s*�q*|�s^t|�dS)z�
        Finalize the registration, instantiate the plugins.

        `API.bootstrap` will automatically be called if it hasn't been
        already.
        rXr�Nz%IPA_CONFDIR env sets confdir to '%s'.c3s|]}t|��VqdSr')rorp�rnr#r$rsrtzAPI.finalize.<locals>.<genexpr>)r�r�rSZenv_confdirZconfdirr��inforxr�rfrrvr!r�r
Z
APIVersionrKrWrgryZplugins_on_demandr�r:�setattrrir�r�r�rYr	)r,r/Zdefault_versionrKZproduction_moder!�instancer#r�r$rX�sL

�





zAPI.finalizecCs^t|�std|��||jvr&t|��z|j|}Wn$tyX||�}|j|<Yn0|S�Nr-)r0r1rxr�r�)r,r/rr#r#r$r�$s
zAPI._getcCst|�std|��|j|Sr)r0r1r�)r,r/r#r#r$�get_plugin_next1szAPI.get_plugin_next)N)NN)NN)FF)r:r;r<r=rrhrgr�rr9r�r�r6rWr�r�r�r�r�r�r�r�r�r�rXr�rr�r#r#r�r$r�]s2




Z
>
 '
4;
r�c@seZdZdd�ZdS)r�cs@|j|j�d|j�|��}d���fdd�|D��}d|S)N� r�c3s |]}tj|���d�VqdS))�initial_indent�subsequent_indentN)�textwrap�fill)rq�line��indent�
text_widthr#r$rs=s�
�z1IPAHelpFormatter.format_epilog.<locals>.<genexpr>z
%s
)�width�current_indent�
splitlinesr)r,r��lines�resultr#rr$�
format_epilog9s
�zIPAHelpFormatter.format_epilogN)r:r;r<rr#r#r#r$r�8sr�)6r=�collections.abcrr�r|r�r�rCrrrr(r�r�ZipalibrZ
ipalib.configrZipalib.textrZipalib.utilrZipalib.baserr	r
Zipalib.constantsrZ	ipapythonrr
Zipapython.configrrZipapython.ipa_log_managerrrZipapython.versionrrrZPY3r�rPr�r:r�Z
TYPE_ERRORr%r&r>rir�r�r#r#r#r$�<module>sH
*A^