
    g!                     `    S SK r SSKJrJr  SSKJr  \ R                  " S5      r " S S5      rg)    N   )NotFoundMultipleObjectsReturned)MODELSz![A-Z](?:[a-z]+|[A-Z]*(?=[A-Z]|$))c                   H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)Query   z4Simple Query class used by the `Model.query` method.c                     Xl         X l        X0l        UR                  U l        SR	                  [
        R                  UR                  5      5      R                  5       U l	        X@l
        g )N )modelsamdbresultcountjoinRE_SPLIT_CAMELCASEfindall__name__lowernamepolymorphic)selfr   r   r   r   s        ;/usr/lib/python3/dist-packages/samba/domain/models/query.py__init__Query.__init__"   sK    

\\
HH/77GHNNP	&    c              #   X   #    U R                    H  nU R                  U5      v   M     g7f)z-Loop over Query class yields Model instances.N)r   _from_message)r   messages     r   __iter__Query.__iter__*   s$     {{G$$W-- #s   (*c                      S[        U 5       S3$ )zBProvide repr method that provides more useful output in the shell.z<Query >)listr   s    r   __repr__Query.__repr__/   s    dA&&r   c                     U R                   (       a2  [        US   S   5      n[        R                  " X R                  5      nOU R                  nUR                  U R                  U5      $ )zReturns the model class to use to construct instances.

If polymorphic query is enabled it will use the last item from
the objectClass list.

Otherwise, it will use the model from the queryset.
objectClass)r   strr   getr   r   r   )r   r   object_classr   s       r   r   Query._from_message3   sS     w}5b9:LJJ|ZZ8EJJE""4::w77r   c                 b    U R                   (       a  U R                  U R                  S   5      $ g)z;Returns the first item in the Query or None for no results.r   Nr   r   r   r$   s    r   firstQuery.firstC   s'    ::%%dkk!n55 r   c                 b    U R                   (       a  U R                  U R                  S   5      $ g)z:Returns the last item in the Query or None for no results.r)   Nr/   r$   s    r   last
Query.lastH   s'    ::%%dkk"o66 r   c                     U R                   S:  a&  [        SU R                   SU R                    S35      eU R                   (       a  U R                  U R                  S   5      $ g)zReturns one item or None if no results were found.

:returns: Model instance or None if not found.
:raises MultipleObjectsReturned: if more than one results were returned
r   More than one  objects returned (got ).r   N)r   r   r   r   r   r$   s    r   r+   	Query.getM   s^     ::>) +B4::,bQS SZZ%%dkk!n55 r   c                    U R                   S:  a&  [        U R                  R                  5        S35      eU R                   S:  a&  [	        SU R                   SU R                    S35      eU R                  U R                  S   5      $ )zMust return EXACTLY one item or raise an exception.

:returns: Model instance
:raises NotFound: if no results were returned
:raises MultipleObjectsReturned: if more than one results were returned
r   z matching query not foundr6   r7   r8   r   )r   r   r   
capitalizer   r   r   r$   s    r   one	Query.oneY   s     ::>99'')**CDF FZZ!^) +B4::,bQS S %%dkk!n55r   )r   r   r   r   r   r   N)r   
__module____qualname____firstlineno____doc__r   r   r%   r   r0   r3   r+   r<   __static_attributes__ r   r   r   r      s-    >'.
'8 6
7

66r   r   )	re
exceptionsr   r   registryr   compiler   r   rC   r   r   <module>rH      s,   . 
 9 ZZ DE H6 H6r   