%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/samba/netcmd/domain/models/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/samba/netcmd/domain/models/__pycache__/model.cpython-312.pyc

�

�I�d6<����ddlZddlmZmZddlmZmZmZmZm	Z	m
Z
mZmZm
Z
ddlmZddlmZmZmZmZmZddlmZmZmZmZmZmZiZGd�d	e�ZGd
�de��Zy)
�N)�ABCMeta�abstractmethod)	�ERR_NO_SUCH_OBJECT�FLAG_MOD_ADD�FLAG_MOD_REPLACE�LdbError�Message�MessageElement�
SCOPE_BASE�
SCOPE_SUBTREE�
binary_encode)�SDUtils�)�DeleteError�DoesNotExist�MultipleObjectsReturned�ProtectError�UnprotectError)�
DateTimeField�DnField�Field�	GUIDField�IntegerField�StringFieldc���eZdZ�fd�Z�xZS)�	ModelMetac���t�|�||||fi|��}|jdk7r5tt	j
|d���|_||_|t|<|S)N�Modelc�"�t|t�S�N)�
isinstancer)�fs �B/usr/lib/python3/dist-packages/samba/netcmd/domain/models/model.py�<lambda>z#ModelMeta.__new__.<locals>.<lambda>.s
��
�1�e�@T��)	�super�__new__�__name__�dict�inspect�
getmembers�fields�meta�MODELS)�mcls�name�bases�	namespace�kwargs�cls�	__class__s      �r#r'zModelMeta.__new__*sW����g�o�d�D�%��E�f�E���<�<�7�"��g�0�0��6T�U�V�C�J��C�H��F�4�L��
r%)r(�
__module__�__qualname__r'�
__classcell__)r5s@r#rr(s
����r%rc���eZdZed�Zed�Zed�Zedd��Z	e
d�Zed�Zed	�Z
ed
d���Zed
�Ze
dd��Ze
dd��Zedd��Zedd��Zd�Zd�Zd�Zd�Zd�Zeed���Zed��Zeed���Zed��Z d�Z!d(d�Z"d)d�Z#ed��Z$ed ��Z%ed!��Z&ed"��Z'ed(d#��Z(d$�Z)d%�Z*d&�Z+d'�Z,y)*r�cn�distinguishedName�dn�dsCorePropagationDataT)�hidden�instanceTyper0�objectCategory�objectClassc�"�|j�Sr )�get_object_class)�objs r#r$zModel.<lambda>?s��3�3G�3G�3I�r%)�default�
objectGUID�
uSNChanged�
uSNCreated�whenChanged�whenCreatedc���d|_|jj�D]O\}}||vr||}n3t|j�r|j	|�}n|j}t|||��Qy)z�Create a new model instance and optionally populate fields.

        Does not save the object to the database, call .save() for that.

        :param kwargs: Optional input fields to populate object with
        N)�_messager,�items�callablerE�setattr)�selfr3�
field_name�fieldrEs     r#�__init__zModel.__init__Fsm����
�!%���!2�!2�!4�	/��J���V�#� ��,���%�-�-�(��-�-��-���-�-���D�*�g�.�	/r%c�<�d|jj�d|�d�S)z,Return object representation for this model.�<z: �>)r5r(�rPs r#�__repr__zModel.__repr__[s"���4�>�>�*�*�+�2�d�V�1�5�5r%c�,�t|j�S)z4Stringify model instance to implement in each model.)�strr:rWs r#�__str__z
Model.__str___s���4�7�7�|�r%c�:�|�y|j|jk(S)z�Basic object equality check only really checks if the dn matches.

        :param other: The other object to compare with
        F�r<)rP�others  r#�__eq__zModel.__eq__cs��
�=���7�7�e�h�h�&�&r%c�F�|j�t|j�Sy)z�Automatically called by custom JSONEncoder class.

        When turning an object into json any fields of type RelatedField
        will also end up calling this method.
        N)r<rZrWs r#�__json__zModel.__json__ms!���7�7���t�w�w�<��r%c��y)z�Return the base DN for the container of this model.

        :param ldb: Ldb connection
        :return: Dn to use for new objects
        N�)�ldbs r#�get_base_dnzModel.get_base_dnvs��	
r%c�$�|j|�S)z�Return the DN used for querying.

        By default, this just calls get_base_dn, but it is possible to
        return a different Dn for querying.

        :param ldb: Ldb connection
        :return: Dn to use for searching
        )re)r4rds  r#�
get_search_dnzModel.get_search_dn�s�����s�#�#r%c��y)z'Returns the objectClass for this model.Nrcrcr%r#rCzModel.get_object_class�s��	
r%c�8�|�}|j||�|S)z�Create a new model instance from the Ldb Message object.

        :param ldb: Ldb connection
        :param message: Ldb Message object to create instance from
        )�_apply)r4rd�messagerDs    r#�from_messagezModel.from_message�s���e���
�
�3�� ��
r%c
���||_|jj�D]>\}}|j|vs�t	|||j|||j���@y)z�Internal method to apply Ldb Message to current object.

        :param ldb: Ldb connection
        :param message: Ldb Message object to apply
        N)rLr,rMr0rO�
from_db_value)rPrdrk�attrrRs     r#rjzModel._apply�s[�� ��
��;�;�,�,�.�	S�K�D�%��z�z�W�$���d�E�$7�$7��W�U�Z�Z�=P�$Q�R�	Sr%Nc�T�|r'|D�cgc]}|j|j��c}nd}	|j|jt|��}|j||d�ycc}w#t
$r4}|jdtk(rtd|j�����d}~wwxYw)z�Refresh object from database.

        :param ldb: Ldb connection
        :param fields: Optional list of field names to refresh
        N)�scope�attrsrzRefresh failed, object gone: )
r,r0�searchr<rr�argsrrrj)rPrdr,r"rr�res�es       r#�refreshz
Model.refresh�s���:@�f�5�����Q��$�$�5�T��	��*�*�T�W�W�J�e�*�D�C�	
���C��Q�� ��6��
�	��v�v�a�y�.�.�"�%B�4�7�7�)�#L�M�M���	�s� A%�"A*�*	B'�3/B"�"B'c��i}|jj�D]2\}}|jr|s�t||�}|��$|||j<�4|S)z�Returns a dict representation of the model.

        :param include_hidden: Include fields with hidden=True when set
        :returns: dict representation of model using Ldb field names as keys
        )r,rMr>�getattrr0)rP�include_hidden�obj_dictrorR�values      r#�as_dictz
Model.as_dict�sY�����;�;�,�,�.�	1�K�D�%��<�<�>���d�+���$�+0�H�U�Z�Z�(�		1��r%c�D�t|�}|j�|d<t|�}|dk(rdnd}|j�D]P\}}|jj|�}|st
d|�d���|d|j�dt|��d	�z
}�R|dkDr|d	z
}|S)
zyBuild LDAP search expression from kwargs.

        :kwargs: fields to use for expression using model field names
        �object_classr�z(&zUnknown field '�'�(�=�))	r)rC�lenrMr,�get�
ValueErrorr0r
)r4r3�criteria�
num_fields�
expressionrQr|rRs        r#�build_expressionzModel.build_expression�s�����<��#&�#7�#7�#9��� ���]�
�%��?�R��
�!)���!1�	C��J���J�J�N�N�:�.�E�� �?�:�,�a�!@�A�A��A�e�j�j�\��=��+?�*@��B�B�J�		C���>��#��J��r%c	+�"K�|j|�}	|j|t|jdi|����}|D]}|j||����y#t$r*}|j
dtk(rtd|�����d}~wwxYw�w)z�Returns a search query for this model.

        :param ldb: Ldb connection
        :param kwargs: Search criteria as keyword args
        �rqr�r�Container does not exist: Nrc)	rgrsrr�rrtrrrl)r4rdr3�base_dn�resultrvrks       r#�queryzModel.query�s������#�#�C�(��	��Z�Z��&3�+?�3�+?�+?�+I�&�+I� �K�F��	1�G��"�"�3��0�0�	1���	��v�v�a�y�.�.�"�%?��y�#I�J�J���	�s'�B�(A�B�	B�"%B�B�Bc	��|jd�}|r	|j|t��}n:|j
|�}	|j|t|jd
i|����}t|�}|dkDrtd|�d	���|dk(r|j||d�Sy#t$r!}|jdt
k(rYd}~y�d}~wwxYw#t$r*}|jdt
k(rtd|�����d}~wwxYw)a�Get one object, must always return one item.

        Either find object by dn=, or any combination of attributes via kwargs.
        If there are more than one result, MultipleObjectsReturned is raised.

        :param ldb: Ldb connection
        :param kwargs: Search criteria as keyword args
        :returns: User object or None if not found
        :raises: MultipleObjects returned if there are more than one results
        r<�rqrNr�r�rz#More than one object returned (got z).rc)
r�rsrrrtrrgrr�rr�rrl)r4rdr3r<rurvr��counts        r#r�z	Model.get�s ���Z�Z��
��
�
��j�j��:�j�6���'�'��,�G�
��j�j��'4�,@�C�,@�,@�,J�6�,J�!�L���C����1�9�)�5�e�W�B�?�A�
A�
�a�Z��#�#�C��Q��0�0���1�
��6�6�!�9� 2�2����	
���
��6�6�!�9� 2�2�&�)C�G�9�'M�N�N���
�s4�B!�(C�!	C�*C�C�C�	D�%C<�<Dc�8�|di|��}|j|�|S)z�Create object constructs object and calls save straight after.

        :param ldb: Ldb connection
        :param kwargs: Fields to populate object from
        :returns: object
        rc)�save)r4rdr3rDs    r#�createzModel.create/s���m�F�m������
��
r%c��|j|fi|��}|�3t|�}|�|j|�|j|fi|��dfS|dfS)a!Retrieve object and if it doesn't exist create a new instance.

        :param ldb: Ldb connection
        :param defaults: Attributes only used for create but not search
        :param kwargs: Attributes used for searching existing object
        :returns: (object, bool created)
        TF)r�r)�updater�)r4rd�defaultsr3rDrrs      r#�
get_or_createzModel.get_or_create;s^���c�g�g�c�$�V�$���;���L�E��#����X�&��3�:�:�c�+�U�+�T�1�1���:�r%c��|j��|j|�}|jd|jxs|j���||_t|j��}|jj�D]M\}}|dk7s�t||�}|j|t�}|��1t|�s�=|j|��O|j|�|j|t��}|j||d�y|j!||j"�}	t|j��}|jj�D]q\}}|dk7s�t||�}t|	|�}
||
k7s�*|j|t$�}|dgfvrt'gt$|j�}|j|��st|�r#|j)|�|j+|�yy)a�Save model to Ldb database.

        The save operation will save all fields excluding fields that
        return None when calling their `to_db_value` methods.

        The `to_db_value` method can either return a ldb Message object,
        or None if the field is to be excluded.

        For updates, the existing object is fetched and only fields
        that are changed are included in the update ldb Message.

        Also for updates, any fields that currently have a value,
        but are to be set to None will be seen as a delete operation.

        After the save operation the object is refreshed from the server,
        as often the server will populate some fields.

        :param ldb: Ldb connection
        NzCN=r]r<r�r)r<re�	add_childr:r0r	r,rMry�to_db_valuerr��addrsrrjrlrLrr
�modifyrw)rPrdr<rkrorRr|�db_valueru�existing_obj�	old_values           r#r�z
Model.saveMs���(�7�7�?��!�!�#�&�B��L�L�3�t�w�w�3�$�)�)�4�5�6��D�G�����)�G�#�{�{�0�0�2�
.���e��4�<�#�D�$�/�E�$�0�0���E�H� �+��H�
����H�-�
.�
�G�G�G���*�*�R�z�*�2�C��K�K��S��V�$� �,�,�S�$�-�-�@�L�����)�G�#�{�{�0�0�2�

.���e��4�<�#�D�$�/�E� '��d� ;�I��	�)�#(�#4�#4�U�<L�#M��$��b�z�1�'5�b�6F�6;�j�j�(B�H� ���H�-�

.� �7�|��
�
�7�#����S�!�	r%c��|j�td��	|j|j�y#t$r}td|����d}~wwxYw)z�Delete item from Ldb database.

        If self.dn is None then the object has not yet been saved.

        :param ldb: Ldb connection
        Nz,Cannot delete object that doesn't have a dn.zDelete failed: )r<r�deleter)rPrdrvs   r#r�zModel.delete�sP���7�7�?��L�M�M�	5��J�J�t�w�w����	5����s�3�4�4��	5�s�5�	A�A�Ac��t|�}	|j|jd�y#t$r}t	d|����d}~wwxYw)zUProtect object from accidental deletion.

        :param ldb: Ldb connection
        �(D;;DTSD;;;WD)zFailed to protect object: N)r�dacl_add_acer<rr�rPrd�utilsrvs    r#�protectz
Model.protect�sM��
����	A����t�w�w�(8�9���	A��!;�A�3�?�@�@��	A���*�	A�A�Ac��t|�}	|j|jd�y#t$r}t	d|����d}~wwxYw)zWUnprotect object from accidental deletion.

        :param ldb: Ldb connection
        r�zFailed to unprotect object: N)r�dacl_delete_acesr<rrr�s    r#�	unprotectzModel.unprotect�sM��
����	E��"�"�4�7�7�,<�=���	E� �#?��s�!C�D�D��	E�r�r )F)-r(r6r7rr:r�distinguished_namer<r�ds_core_propagation_datar�
instance_typer0�object_categoryrr�object_guid�usn_changed�usn_created�when_changed�when_createdrSrXr[r_ra�staticmethodrre�classmethodrgrCrlrjrwr}r�r�r�r�r�r�r�r�r�rcr%r#rr5s���	�T�	�B� �!4�5��	���B�,�-D�48� :�� ��0�M��v��D��.�/�O��}�'I�K�L��L�)�K��|�D�9�K��|�D�9�K� ��t�<�L� ��t�<�L�/�*6��'� ���
���
��	$��	$���
���
�����S�!�$� ����2�1��1�0�-1��-1�^�	��	�����"D"�L
5�
A�
Er%r)�	metaclass) r*�abcrrrdrrrrr	r
rrr
�samba.sd_utilsr�
exceptionsrrrrrr,rrrrrrr.rrrcr%r#�<module>r�sY��.�'�F�F�F�"�!�!���

��
��
�CE�i�CEr%

Zerion Mini Shell 1.0