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__/crud.cpython-39.opt-1.pyc
a

}�f.1�@s�dZddlmZddlmZddlmZddlmZddlmZGdd�de�Z	Gd	d
�d
e�Z
Gdd�de
�ZGd
d�de
�ZGdd�de
�Z
Gdd�de�ZGdd�dej�ZdS)a�
Base classes for standard CRUD operations.

These base classes are for `Method` plugins that provide standard
Create, Retrieve, Updated, and Delete operations (CRUD) for their corresponding
`Object` plugin.  In particuar, these base classes provide logic to
automatically create the plugin args and options by inspecting the params on
their corresponding `Object` plugin.  This provides a single point of definition
for LDAP attributes and enforces a simple, consistent API for CRUD operations.

For example, say we want CRUD operations on a hypothetical "user" entry.  First
we need an `Object` plugin:

>>> from ipalib import Object, Str
>>> class user(Object):
...     takes_params = (
...         Str('login', primary_key=True),
...         Str('first'),
...         Str('last'),
...         Str('ipauniqueid', flags=['no_create', 'no_update']),
...     )
...

Next we need `Create`, `Retrieve`, `Updated`, and `Delete` plugins, and
optionally a `Search` plugin.  For brevity, we'll just define `Create` and
`Retrieve` plugins:

>>> from ipalib import crud
>>> class user_add(crud.Create):
...     pass
...
>>> class user_show(crud.Retrieve):
...     pass
...

Now we'll register the plugins and finalize the `plugable.API` instance:

>>> from ipalib import create_api
>>> api = create_api()
>>> api.add_plugin(user)
>>> api.add_plugin(user_add)
>>> api.add_plugin(user_show)
>>> api.finalize()

First, notice that our ``user`` `Object` has the params we defined with the
``takes_params`` tuple:

>>> list(api.Object.user.params)
['login', 'first', 'last', 'ipauniqueid']
>>> api.Object.user.params.login
Str('login', primary_key=True)

Although we defined neither ``takes_args`` nor ``takes_options`` for our
``user_add`` plugin, the `Create` base class automatically generated them for
us:

>>> list(api.Command.user_add.args)
['login']
>>> list(api.Command.user_add.options)
['first', 'last', 'all', 'raw', 'version']

Notice that ``'ipauniqueid'`` isn't included in the options for our ``user_add``
plugin.  This is because of the ``'no_create'`` flag we used when defining the
``ipauniqueid`` param.  Often times there are LDAP attributes that are
automatically created by the server and therefor should not be supplied as an
option to the `Create` plugin.  Often these same attributes shouldn't be
update-able either, in which case you can also supply the ``'no_update'`` flag,
as we did with our ``ipauniqueid`` param.  Lastly, you can also use the ``'no_search'`` flag for attributes that shouldn't be search-able (because, for
example, the attribute isn't indexed).

As with our ``user_add` plugin, we defined neither ``takes_args`` nor
``takes_options`` for our ``user_show`` plugin; instead the `Retrieve` base
class created them for us:

>>> list(api.Command.user_show.args)
['login']
>>> list(api.Command.user_show.options)
['all', 'raw', 'version']

As you can see, `Retrieve` plugins take a single argument (the primary key) and
no options.  If needed, you can still specify options for your `Retrieve` plugin
with a ``takes_options`` tuple.

Flags like ``'no_create'`` remove LDAP attributes from those that can be
supplied as *input* to a `Method`, but they don't effect the attributes that can
be returned as *output*.  Regardless of what flags have been used, the output
entry (or list of entries) can contain all the attributes defined on the
`Object` plugin (in our case, the above ``user.params``).

For example, compare ``user.params`` with ``user_add.output_params`` and
``user_show.output_params``:

>>> list(api.Object.user.params)
['login', 'first', 'last', 'ipauniqueid']
>>> list(api.Command.user_add.output_params)
['login', 'first', 'last', 'ipauniqueid']
>>> list(api.Command.user_show.output_params)
['login', 'first', 'last', 'ipauniqueid']

Note that the above are all equal.
�)�Method)�backend)�
parameters)�output)�_cs:eZdZdZejZdd�Z�fdd�Z�fdd�Z	�Z
S)�Createz
    Create a new entry.
    cKs*d|jvrd|d<|r&|jfi|��S|S)NZoptional_createF�required)�flags�clone)�selfZparam�kw�r
�//usr/lib/python3.9/site-packages/ipalib/crud.pyZ__clone�s
zCreate.__clonec#s@|jjr|j|jjdd�Vtt|���D]}|�|�Vq*dS)NT��	attribute)�obj�primary_key�_Create__clone�superr�get_args�r�arg��	__class__r
rr�szCreate.get_argsc#s�|jr&tt|���D]}|�|�Vq|j�|j�D]L}d|jv}d|jvrNq4d|jvrp|j	|ddddd�Vq4|j||d�Vq4|js�tt|���D]}|�|�Vq�dS)N�virtual_attributeZ	no_createZ
ask_createFT�r�queryr�autofill�	alwaysaskr)
�extra_options_firstrr�get_optionsrr�params_minus�argsr	r
�r�optionrrr
rr �s 


�
zCreate.get_options)�__name__�
__module__�__qualname__�__doc__r�standard_entry�
has_outputrrr �
__classcell__r
r
rrr�s
rcs eZdZdZ�fdd�Z�ZS)�PKQueryz<
    Base class for `Retrieve`, `Update`, and `Delete`.
    c#s:|jjr|jjjddd�Vtt|���D]
}|Vq*dS)NT)rr)rrr
rr,rrrr
rr�szPKQuery.get_args)r%r&r'r(rr+r
r
rrr,�sr,c@seZdZdZejZdS)�Retrievez/
    Retrieve an entry by its primary key.
    N)r%r&r'r(rr)r*r
r
r
rr-�sr-cs&eZdZdZejZ�fdd�Z�ZS)�Updatez4
    Update one or more attributes on an entry.
    c	#s�|jr tt|���D]
}|Vq|j��D]�}|j}d|jv}|jrP|�dg�}d|jvr\q*d|jvr�|j	|dddd|d�Vq*d|jvr�|j	|dd|d	�Vq*|j	|dd|d
�Vq*|js�tt|���D]
}|Vq�dS)NrZnonemptyZ	no_updateZ
ask_updateFT)rrrrrr	Z
req_update)rrrr	)rrrr	)
rrr.r rZparams_minus_pkr	r�unionr
)rr$Z	new_flagsrrr
rr �s4


�

�
�
zUpdate.get_options)	r%r&r'r(rr)r*r r+r
r
rrr.�sr.c@seZdZdZejZdS)�Deletez%
    Delete one or more entries.
    N)r%r&r'r(rZstandard_deleter*r
r
r
rr0�sr0cs2eZdZdZejZ�fdd�Z�fdd�Z�Z	S)�SearchzB
    Retrieve all entries that match a given search criteria.
    c#s4tjddtd�d�Vtt|���D]
}|Vq$dS)Nz	criteria?Fz3A string searched in all relevant object attributes)Znoextrawhitespace�doc)rZStrrrr1rrrr
rr�s�zSearch.get_argsc	#s�|jr tt|���D]
}|Vq|j�|j�D]z}d|jv}d|jvrHq.d|jvrj|j|ddddd�Vq.t	|t
j�r�|j|j
t
j|dddd�Vq.|j|dddd�Vq.|js�tt|���D]
}|Vq�dS)NrZ	no_searchZ
ask_searchTFr)rrrr)rrr1r rr!r"r	r
�
isinstancer�FlagZclone_retype�nameZBoolr#rr
rr �s.


�
�
�
zSearch.get_options)
r%r&r'r(rZstandard_list_of_entriesr*rr r+r
r
rrr1�sr1c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�CrudBackendz7
    Base class defining generic CRUD backend API.
    cKstd|j��dS)aa
        Create a new entry.

        This method should take key word arguments representing the
        attributes the created entry will have.

        If this methods constructs the primary_key internally, it should raise
        an exception if the primary_key was passed.  Likewise, if this method
        requires the primary_key to be passed in from the caller, it should
        raise an exception if the primary key was *not* passed.

        This method should return a dict of the exact entry as it was created
        in the backing store, including any automatically created attributes.
        z%s.create()N��NotImplementedErrorr5�rrr
r
r�createszCrudBackend.createcCstd|j��dS)a�
        Retrieve an existing entry.

        This method should take a two arguments: the primary_key of the
        entry in question and a list of the attributes to be retrieved.
        If the list of attributes is None then all non-operational
        attributes will be returned.

        If such an entry exists, this method should return a dict
        representing that entry.  If no such entry exists, this method
        should return None.
        z
%s.retrieve()Nr7)rrZ
attributesr
r
r�retrieve,s
zCrudBackend.retrievecKstd|j��dS)a�
        Update an existing entry.

        This method should take one required argument, the primary_key of the
        entry to modify, plus optional keyword arguments for each of the
        attributes being updated.

        This method should return a dict representing the entry as it now
        exists in the backing store.  If no such entry exists, this method
        should return None.
        z%s.update()Nr7)rrrr
r
r�update;szCrudBackend.updatecCstd|j��dS)z�
        Delete an existing entry.

        This method should take one required argument, the primary_key of the
        entry to delete.
        z%s.delete()Nr7)rrr
r
r�deleteIszCrudBackend.deletecKstd|j��dS)a!
        Return entries matching specific criteria.

        This method should take keyword arguments representing the search
        criteria.  If a key is the name of an entry attribute, the value
        should be treated as a filter on that attribute.  The meaning of
        keys outside this namespace is left to the implementation.

        This method should return and iterable containing the matched
        entries, where each entry is a dict.  If no entries are matched,
        this method should return an empty iterable.
        z%s.search()Nr7r9r
r
r�searchRs
zCrudBackend.searchN)	r%r&r'r(r:r;r<r=r>r
r
r
rr6s	r6N)r(Zipalib.frontendrZipalibrrrZipalib.textrrr,r-r.r0r1ZConnectibler6r
r
r
r�<module>sf&()