
    h0                     h    d dl mZ d dlmZmZmZmZmZmZ dZ	dZ
dZ G d de      Z G d d	e      Zy
)    )OperationError)CASCADEDENY
DO_NOTHINGNULLIFYPULLBaseQuerySet)QuerySetQuerySetNoCacher   r   r   r   r      d   c                   T     e Zd ZdZdZdZdZd Zd Zd Z	d Z
d Zd fd		Zd
 Z xZS )r
   zThe default queryset, that builds queries and handles a set of results
    returned from a query.

    Wraps a MongoDB cursor, providing :class:`~mongoengine.Document` objects as
    the results.
    TNc                 r    d| _         | j                  r| j                         S t        | j                        S )zIteration utilises a results cache which iterates the cursor
        in batches of ``ITER_CHUNK_SIZE``.

        If ``self._has_more`` the cursor hasn't been exhausted so cache then
        batch. Otherwise iterate the result_cache.
        T)_iter	_has_more_iter_resultsiter_result_cacheselfs    [/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/mongoengine/queryset/queryset.py__iter__zQuerySet.__iter__&   s4     
>>%%'' D&&''    c                     | j                   | j                   S | j                  rt        | j                                t	        | j
                        | _         | j                   S )zSince __len__ is called quite frequently (for example, as part of
        list(qs)), we populate the result cache and cache the length.
        )_lenr   listr   lenr   r   s    r   __len__zQuerySet.__len__5   sP     99 99 >>##%& **+	yyr   c                     | j                   ry| j                          | j                  dt        dz    }t	        |      t        kD  rd|d<   t        |      S )z/Provide a string representation of the QuerySet.. queryset mid-iteration ..N   $...(remaining elements truncated)...)r   _populate_cacher   REPR_OUTPUT_SIZEr   repr)r   datas     r   __repr__zQuerySet.__repr__D   sQ    ::1!!"8$4q$89t9''=DHDzr   c              #   0  K   | j                   g | _         d}	 |t        | j                         k  r/| j                   |    |dz  }|t        | j                         k  r/| j                  syt        | j                         |k  r| j                          }w)zA generator for iterating over the result cache.

        Also populates the cache if there are more possible results to
        yield. Raises StopIteration when there are no more results.
        Nr   r!   )r   r   r   r$   )r   poss     r   r   zQuerySet._iter_resultsO   s      %!#D D..//((--q D..// >> 4%%&#-$$&) s   AB 6Bc                     | j                   g | _         | j                  sy	 t        t              D ]&  }| j                   j	                  t        |              ( y# t        $ r
 d| _        Y yw xY w)z{
        Populates the result cache with ``ITER_CHUNK_SIZE`` more entries
        (until the cursor is exhausted).
        NF)r   r   rangeITER_CHUNK_SIZEappendnextStopIteration)r   _s     r   r$   zQuerySet._populate_cacheo   sm    
 %!#D ~~	#?+ 6""))$t*56 	# #DN		#s   8A A.-A.c                     |du rt         |   |      S | j                  t         |   |      | _        | j                  S )zCount the selected elements in the query.

        :param with_limit_and_skip (optional): take any :meth:`limit` or
            :meth:`skip` that has been applied to this cursor into account when
            getting the count
        F)supercountr   )r   with_limit_and_skip	__class__s     r   r4   zQuerySet.count   sB     %'7=!45599&9:DIyyr   c                     | j                   t        d      | j                  t        | j                  | j
                              S )z!Convert to a non-caching querysetzQuerySet already cached)r   r   _clone_intor   	_document_collectionr   s    r   no_cachezQuerySet.no_cache   s<    ) !:;;@P@P QRRr   )F)__name__
__module____qualname____doc__r   r   r   r   r   r(   r   r$   r4   r;   __classcell__)r6   s   @r   r
   r
      s>     IDM(	'@#0 Sr   r
   c                   "    e Zd ZdZd Zd Zd Zy)r   zA non caching QuerySetc                 `    | j                  t        | j                  | j                              S )zConvert to a caching queryset)r8   r
   r9   r:   r   s    r   cachezQuerySetNoCache.cache   s$    9I9I JKKr   c                    | j                   ryg }t        t        dz         D ]  }	 |j                  t	        |               t        |      t        kD  rd|d<   | j                          t        |      S # t
        $ r Y  >w xY w)z2Provides the string representation of the QuerySetr    r!   r"   r#   )	r   r,   r%   r.   r/   r0   r   rewindr&   )r   r'   r1   s      r   r(   zQuerySetNoCache.__repr__   s    ::1'!+, 	ADJ'	 t9''=DHDz ! s   A44	B Bc                 b    | }|j                   r| j                         }|j                          |S )N)r   clonerE   )r   querysets     r   r   zQuerySetNoCache.__iter__   s(    >>zz|Hr   N)r<   r=   r>   r?   rC   r(   r    r   r   r   r      s     L$r   r   N)mongoengine.errorsr   mongoengine.queryset.baser   r   r   r   r   r	   __all__r%   r-   r
   r   rI   r   r   <module>rM      sC    -   BS| BSJl r   