HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //proc/self/root/lib/python3.6/site-packages/ipalib/__pycache__/plugable.cpython-36.pyc
3

�d[emj�@sndZddlmZddlZddlZddlZddlZddlZddlZddlm	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlmZddlmZddlmZddlmZdd	lmZmZmZdd
lmZddlmZmZddl m!Z!m"Z"dd
l#m$Z$m%Z%m&Z&ej'�re(Z)ej*e+�Z,dZ-dd�Z.Gdd�d�Z/Gdd�de�Z0Gdd�de�Z1Gdd�de�Z2Gdd�de
j3�Z4dS)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)�LOGGING_FORMAT_FILE�LOGGING_FORMAT_STDERR)�VERSION�API_VERSION�DEFAULT_PLUGINSz%s: need a %r; got a %r: %rccs�tjj|�|kotjj|�s dStjj|�r0dSd}x`ttj|��D]N}|j|�sTqDtjj||�}tjj	|�spqD|dt
|��}|dkr�qD|VqDWdS)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!�/usr/lib/python3.6/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".
    cCstj�|_dS)N)�collections�OrderedDict�_Registry__registry)�selfr!r!r"rdszRegistry.__init__cs��fdd�}|S)Ncs@t|�std|��|�jkr*tj|d��t�|d��j|<|S)z�
            Register the plugin ``plugin``.

            :param plugin: A subclass of `Plugin` to attempt to register.
            zplugin must be callable; got %r)�plugin)�callable�	TypeErrorr'rZPluginDuplicateError�dict)r))�kwargsr(r!r"�registerhs
z#Registry.__call__.<locals>.registerr!)r(r-r.r!)r-r(r"�__call__gszRegistry.__call__cCst|jj��S)N)�iterr'�values)r(r!r!r"�__iter__|szRegistry.__iter__N)�__name__�
__module__�__qualname__�__doc__rr/r2r!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,|dk	st�||_d|_d|_tj�|_dS)NF)�AssertionError�_Plugin__api�_Plugin__finalize_called�_Plugin__finalized�	threading�RLock�_Plugin__finalize_lock)r(�apir!r!r"r�s
zPlugin.__init__cCs|jS)N)r3)�clsr!r!r"Z
__name_getter�szPlugin.__name_gettercCsdj|j|j�S)Nz{}/{})�formatr�version)rAr!r!r"Z__full_name_getter�szPlugin.__full_name_gettercCs|jS)N)�	__bases__)rAr!r!r"Z__bases_getter�szPlugin.__bases_gettercCs|jS)N)r6)rAr!r!r"Z__doc_getter�szPlugin.__doc_gettercCs<|j}t|�js d|j|jfSt|�jdd�dj�SdS)Nz<%s.%s>z

�r)�docr�msgr4r3�unicode�split�strip)rArFr!r!r"Z__summary_getter�s
zPlugin.__summary_gettercCs|jS)z?
        Return `API` instance passed to `__init__()`.
        )r:)r(r!r!r"r@�sz
Plugin.apicCs|jjS)N)r:�env)r(r!r!r"rK�sz
Plugin.envcCs|jjS)N)r:�Backend)r(r!r!r"rL�szPlugin.BackendcCs|jjS)N)r:�Command)r(r!r!r"rM�szPlugin.Commandc	CsT|j�D|jdkst�|jr dSd|_|j�d|_|jj�sFt|�WdQRXdS)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()`.
        FNT)r?r<r9r;�_on_finalizer:�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"rN�szPlugin._on_finalizec	Cs$|j�|js|j�WdQRXdS)zR
        Finalize plugin initialization if it has not yet been finalized.
        N)r?r<rP)r(r!r!r"�ensure_finalized�szPlugin.ensure_finalizedc@s&eZdZdZd	Zd
dd�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||_||_dS)N)rrR)r(rrRr!r!r"r�szPlugin.finalize_attr.__init__cCsZ|dks|jdkr|jS|j�yt||j�Stk
rTtd|j|jf��YnXdS)Nz7attribute '%s' of plugin '%s' was not set in finalize())r@rRrQ�getattrr�RuntimeError�AttributeError)r(�objrAr!r!r"�__get__�szPlugin.finalize_attr.__get__)rrR)N)r3r4r5r6�	__slots__rrWr!r!r!r"�
finalize_attr�s

rYcCsd|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__r4r3)r(r!r!r"�__repr__szPlugin.__repr__N)r3r4r5r6rCr�classmethodZ_Plugin__name_getterrrZ_Plugin__full_name_getter�	full_nameZ_Plugin__bases_getter�basesZ_Plugin__doc_getterrFZ_Plugin__summary_getterZsummary�propertyr@rKrLrMrPrNrQrYr[r!r!r!r"r7�s,$r7csdeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Z�fdd�Zd
d�Z	dd�Z
dd�Zdd�Z�Z
S)�APINameSpacecCs||_||_d|_d|_dS)N)�_APINameSpace__api�_APINameSpace__base�_APINameSpace__plugins�_APINameSpace__plugins_by_key)r(r@�baser!r!r"rszAPINameSpace.__init__cs��jdk	r�jdk	rdS�jj}t�}i}�_xt�jjD]h}t�fdd�|jD��sXq:|j|�|||<|||j	|j
f<|||j<|j
|j|j	d�kr:|||j	<q:Wt
|tjd�d��_dS)Nc3s|]}t|�j�VqdS)N)�
issubclassrb)�.0�b)r(r!r"�	<genexpr>,sz+APINameSpace.__enumerate.<locals>.<genexpr>r8r])�key)rcrdra�_API__default_map�set�
_API__plugins�anyr^�addrrCr]�getr�operator�
attrgetter)r(Zdefault_mapZpluginsZkey_dictr)r!)r(r"Z__enumerate#s


zAPINameSpace.__enumeratecCs|j�t|j�S)N)�_APINameSpace__enumeraterrc)r(r!r!r"�__len__7szAPINameSpace.__len__cCs|j�||jkS)N)rsrd)r(rjr!r!r"�__contains__;szAPINameSpace.__contains__cCs|j�t|j�S)N)rsr0rc)r(r!r!r"r2?szAPINameSpace.__iter__cs2|j�t�j�}|jdd�|D��|j�|S)Ncss|]}|jVqdS)N)r)rg�pr!r!r"riGsz'APINameSpace.__dir__.<locals>.<genexpr>)rs�super�__dir__�extend�sort)r(�names)rZr!r"rxCs

zAPINameSpace.__dir__cCs|j�|j|S)N)rsrd)r(rjr!r!r"�
get_pluginKszAPINameSpace.get_plugincCs|j|�}|jj|�S)N)r|ra�_get)r(rjr)r!r!r"�__getitem__Os
zAPINameSpace.__getitem__cCs
tj|�S)N)�six�
itervalues)r(r!r!r"r/SszAPINameSpace.__call__cCs*y||Stk
r$t|��YnXdS)N)�KeyErrorrU)r(rjr!r!r"�__getattr__VszAPINameSpace.__getattr__)r3r4r5rrsrtrur2rxr|r~r/r��
__classcell__r!r!)rZr"r`sr`cs�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|�j�t�|_i|_i|_i|_i|_t�|_	t
�|_dS)N)rwr�rrlrm�_API__plugins_by_keyrk�_API__instances�
_API__next�
_API__donerrK)r()rZr!r"rbszAPI.__init__cCst�dS)N)�NotImplementedError)r(r!r!r"r^lsz	API.basescCst�dS)N)r�)r(r!r!r"�packagespszAPI.packagescCs
t|j�S)zL
        Return the number of plugin namespaces in this API object.
        )rr^)r(r!r!r"rttszAPI.__len__cCsdd�|jD�S)zN
        Iterate (in ascending order) through plugin namespace names.
        css|]}|jVqdS)N)r3)rgrer!r!r"ri~szAPI.__iter__.<locals>.<genexpr>)r^)r(r!r!r"r2zszAPI.__iter__cCs|t|�kS)z�
        Return True if this API object contains plugin namespace ``name``.

        :param name: The plugin namespace name to test for membership.
        )rl)r(rr!r!r"ru�szAPI.__contains__cCs4||kr(y
t||�Stk
r&YnXt|��dS)z�
        Return the plugin namespace corresponding to ``name``.

        :param name: The name of the plugin namespace you wish to retrieve.
        N)rSrUr�)r(rr!r!r"r~�s
zAPI.__getitem__ccs@x:|D]2}yt||�VWqtk
r6t|��YqXqWdS)zQ
        Iterate (in ascending order by name) through plugin namespaces.
        N)rSrUr�)r(rr!r!r"r/�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)rSrK)r(r!r!r"rO�szAPI.is_production_modecCs.||jkrtd|jj|f��|jj|�dS)Nz%s.%s() already called)r��	ExceptionrZr3ro)r(rr!r!r"Z__doing�s
zAPI.__doingcCs||jkrt||��dS)N)r�rS)r(rr!r!r"Z__do_if_not_done�s
zAPI.__do_if_not_donecCs
||jkS)N)r�)r(rr!r!r"�isdone�sz
API.isdoneNcKst|jd�|jjf|�|jjftt��|s6|j�}||_tj	�}|j
sR|jjrVdS|jjrftj
}ntj}|j|�xh|jD]^}tjd|�}|s�q~tj|jd��}t|j|�}tjd|�}x|D]}	|jtj|	|��q�Wq~Wtj}|jjr�tj
}n*|jjdk�r |jjdk�rtj}ntj}tj�}
|
j|�|
jtjt��|j |
�t!j"�}|j#�dk�rnt$j%|d
��|jj&dk�r�dS|jj'dk�r�dSt(j)|jj'�}t(j*|��s�yt+j,|�Wn"t-k
�r�t.j/d
|�dSXtj}|jj�r�tj
}|jj'dk	�rpytj0|jj'�}
Wn6t1k
�rJ}
zt.j/d|jj'|
�WYdd}
~
Xn&X|
j|�|
jtjt2��|j |
�dS)z?
        Initialize environment variables and logging.
        �	bootstrapNz?^log_logger_level_(debug|info|warn|warning|error|critical|\d+)$rEz\s*,\s*�clir�utf-8�utf8)�encoding�dummy�	unit_testzCould not create log_dir %rzCannot open log file %r: %s>r�r�)r�r�)3�_API__doingrK�
_bootstrapZ_finalize_corer,r�build_global_parser�parser�logging�	getLoggerZhandlers�validate_api�debug�DEBUG�INFOZsetLevel�re�matchrZconvert_log_level�grouprSrIZ	addFilter�Filter�context�verboseZWARNINGZ
StreamHandlerZsetFormatterZ	FormatterrZ
addHandler�sys�getfilesystemencoding�lowerrZSystemEncodingErrorr��logr�dirnamerr�makedirs�OSError�logger�errorZFileHandler�IOErrorr)r(r��	overridesZroot_logger�level�attrr�rRZregexpsZregexpZhandlerZfseZlog_dir�er!r!r"r��sx





$
z
API.bootstrapcCsdd�}|dkrXtjdt�dddttfdjd	d:dd;g�d�}|j�|jddddd�|jdddddd�|jdddd|dd d!�|jd"d#d$d%d�|jd&d$d'd�|jd(d)d*d+d�|d,k�r�|jd-d.d$d/d�|jd0d1d2d3d4d5�|jd6d7d2d8d9d5�|S)<zJ
        Add global options to an optparse.OptionParser instance.
        cSs0tjj|�s$|jtd�t|d��||j_dS)Nz%(filename)s: file not found)�filename)rrrr�rr,r1�conf)Zoption�optrRr�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 za specific topic.z6See "ipa help commands" for the full list of commands.z3See "ipa <COMMAND> --help" for more information on za specific command.)Zadd_help_optionZ	formatterZusage�descriptionrC�epilogz-hz--help�helpzShow this help message and exit)�actionr�z-erKzKEY=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-promptZstore_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.confz@See "ipa help <TOPIC>" for more information on a specific topic.zFSee "ipa <COMMAND> --help" for more information on a specific command.)�optparseZOptionParser�IPAHelpFormatterrrrZdisable_interspersed_argsZ
add_option)r(r�r�r�r!r!r"r�sP






zAPI.build_global_parserc
Cs|j||�}|j�\}}i}|jdk	r�t|j�tks8t�xt|jD]j}y|jdd�}Wntk
rhYnXt|�dkr�|\}}	|	j	�|t
|j	��<q@tjt
dj|d����q@Wx(dD] }t||d�}	|	dk	r�|	||<q�Wt|d
�r�|j|d<|dk	�r�||d<|j|f|�||fS)N�=rE�zUnable to parse option {item})�itemr�r�r��
prompt_allr�r��delegate�prodZ
webui_prodr�)r�r�r�r�r�r�r�)r��
parse_argsrKr��listr9rI�
ValueErrorrrJ�strrZOptionErrorrrBrS�hasattrr�r�)
r(r�r�Zoptions�argsr�r�r1rjrRr!r!r"�bootstrap_with_global_optionsMs4




z!API.bootstrap_with_global_optionscCsB|jd�|jd�|jjdkr$dSx|jD]}|j|�q,WdS)z�
        Load plugins from all standard locations.

        `API.bootstrap` will automatically be called if it hasn't been
        already.
        �load_pluginsr�r�r�N)r�r�)r��_API__do_if_not_donerKr�r��add_package)r(�packager!r!r"r�ms

zAPI.load_pluginscs\|j�|j}tjtj|��}tj�jd�d}tjtj|j��}||krXtj	�|d��t
jd��t|dt
|��}�fdd�|D�}x�|D]�}t
jd|�ytj|�}Wnftjk
r�}	zt
jd	||	j�w�WYd
d
}	~	Xn2tk
�r|jj}
|
�r
t
jd|��YnXy|j|�Wq�tjk
�rR}	zt
jd|	�WYd
d
}	~	Xq�Xq�Wd
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|]}dj�|f��qS)r�)r)rgZmname)�package_namer!r"�
<listcomp>�sz#API.add_package.<locals>.<listcomp>zimporting plugin module %szskipping plugin module %s: %sNzcould not load plugin module %sz%s)r3�__file__rr�rr�r��
rpartitionrZPluginsPackageErrorr�r�rSr#�	importlib�
import_moduleZSkipPluginModule�reasonr�rKZstartup_tracebackZ	exception�
add_module�PluginModuleError)r(r�Zpackage_fileZpackage_dir�parentZ
parent_dirr�rr r��tbr!)r�r"r�|s6

zAPI.add_packagecCsZy
|j}Wntk
rYn*Xt|t�rHx|D]}|jf|�q0WdStj|jd��dS)zn
        Add plugins from the ``module``.

        :param module: A module from which to add plugins.
        N)r)r.rU�
isinstancer$�
add_pluginrr�r3)r(r r.r-r!r!r"r��s


zAPI.add_moduleFcCs�t|�std|��x,|jD]}t||j�rPqWtj||jd��|jj|j�}|r�|st|r`dStj	|j
|j|d��|jj
|�||j|<n |r�|r�dStj|j
|j|d��|j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.
        zplugin must be callable; got %r)r)r^N)rerr))r*r+r^rfrZPluginSubclassErrorr�rpr]ZPluginOverrideErrorr3rrm�remover�ZPluginMissingOverrideErrorro)r(r)�overrideZno_failre�prevr!r!r"r��s8
zAPI.add_plugincs�|jd�|jd�|jjdk	r@|jj|jjkr@tjd|jj�xx|jD]n}|jjsb|j	t
kr�qHnFy|j|j}Wnt
k
r�Yn"Xtj|j�}tj|�}||kr�qH|j|j|j<qHW|j�}xz|jD]p�x:|jD]0}t�fdd�|jD��s�q�|jjs�|j|�q�W�j}|�s(t||��s(t�t||t|���q�WxRtj|j�D]B}|�sf|j|k�sft�|jj�sL|j�|�sLt |��sLt��qLW|�s�t!|�dS)z�
        Finalize the registration, instantiate the plugins.

        `API.bootstrap` will automatically be called if it hasn't been
        already.
        rPr�Nz%IPA_CONFDIR env sets confdir to '%s'.c3s|]}t|��VqdS)N)rf)rgrh)rer!r"riszAPI.finalize.<locals>.<genexpr>)"r�r�rKZenv_confdirZconfdirr��informr�r]rrkrr�r
Z
APIVersionrCrOr^rnZplugins_on_demandr}r3r�r9�setattrr`rr�r�r@rQr
r	)r(r)Zdefault_versionrCZproduction_moder�instancer!)rer"rP�sN




zAPI.finalizecCs`t|�std|��||jkr&t|��y|j|}Wn&tk
rZ||�}|j|<YnX|S)Nzplugin must be callable; got %r)r*r+rmr�r�)r(r)r�r!r!r"r}$s
zAPI._getcCst|�std|��|j|S)Nzplugin must be callable; got %r)r*r+r�)r(r)r!r!r"�get_plugin_next1szAPI.get_plugin_next)N)NN)NN)FF)r3r4r5r6rr_r^r�rtr2rur~r/rOr�r�r�r�r�r�r�r�r�r�rPr}r�r�r!r!)rZr"r�]s.


Z
>
 '
4;
r�c@seZdZdd�ZdS)r�cs@|j|j�d|j�|j�}dj��fdd�|D��}d|S)N� r�c3s |]}tj|���d�VqdS))Zinitial_indentZsubsequent_indentN)�textwrapZfill)rg�line)�indent�
text_widthr!r"ri>sz1IPAHelpFormatter.format_epilog.<locals>.<genexpr>z
%s
)�widthZcurrent_indent�
splitlinesr)r(r��lines�resultr!)r�r�r"�
format_epilog9s

zIPAHelpFormatter.format_epilogN)r3r4r5r�r!r!r!r"r�8sr�)5r6�collections.abcrr�rqr�r�r=rrr�r�r%r�rZipalibrZ
ipalib.configrZipalib.textrZipalib.utilrZipalib.baserr	r
Zipalib.constantsrZ	ipapythonrr
Zipapython.ipa_log_managerrrZipapython.versionrrrZPY3r�rHr�r3r�Z
TYPE_ERRORr#r$r7r`r�ZIndentedHelpFormatterr�r!r!r!r"�<module>sH
*A^