<s> from __future__ import absolute_import <EOL> import copy <EOL> import itertools <EOL> import operator <EOL> import pprint <EOL> import re <EOL> import warnings <EOL> from bson import SON <EOL> from bson . code import Code <EOL> from bson import json_util <EOL> import pymongo <EOL> import pymongo . errors <EOL> from pymongo . common import validate_read_preference <EOL> from mongoengine import signals <EOL> from mongoengine . connection import get_db <EOL> from mongoengine . context_managers import switch_db <EOL> from mongoengine . common import _import_class <EOL> from mongoengine . base . common import get_document <EOL> from mongoengine . errors import ( OperationError , NotUniqueError , <EOL> InvalidQueryError , LookUpError ) <EOL> from mongoengine . python_support import IS_PYMONGO_3 <EOL> from mongoengine . queryset import transform <EOL> from mongoengine . queryset . field_list import QueryFieldList <EOL> from mongoengine . queryset . visitor import Q , QNode <EOL> if IS_PYMONGO_3 : <EOL> from pymongo . collection import ReturnDocument <EOL> __all__ = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> DO_NOTHING = <NUM_LIT:0> <EOL> NULLIFY = <NUM_LIT:1> <EOL> CASCADE = <NUM_LIT:2> <EOL> DENY = <NUM_LIT:3> <EOL> PULL = <NUM_LIT:4> <EOL> RE_TYPE = type ( re . compile ( '<STR_LIT>' ) ) <EOL> class BaseQuerySet ( object ) : <EOL> """<STR_LIT>""" <EOL> __dereference = False <EOL> _auto_dereference = True <EOL> def __init__ ( self , document , collection ) : <EOL> self . _document = document <EOL> self . _collection_obj = collection <EOL> self . _mongo_query = None <EOL> self . _query_obj = Q ( ) <EOL> self . _initial_query = { } <EOL> self . _where_clause = None <EOL> self . _loaded_fields = QueryFieldList ( ) <EOL> self . _ordering = None <EOL> self . _snapshot = False <EOL> self . _timeout = True <EOL> self . _class_check = True <EOL> self . _slave_okay = False <EOL> self . _read_preference = None <EOL> self . _iter = False <EOL> self . _scalar = [ ] <EOL> self . _none = False <EOL> self . _as_pymongo = False <EOL> self . _as_pymongo_coerce = False <EOL> self . _search_text = None <EOL> if document . _meta . get ( '<STR_LIT>' ) is True : <EOL> if len ( self . _document . _subclasses ) == <NUM_LIT:1> : <EOL> self . _initial_query = { "<STR_LIT>" : self . _document . _subclasses [ <NUM_LIT:0> ] } <EOL> else : <EOL> self . _initial_query = { <EOL> "<STR_LIT>" : { "<STR_LIT>" : self . _document . _subclasses } } <EOL> self . _loaded_fields = QueryFieldList ( always_include = [ '<STR_LIT>' ] ) <EOL> self . _cursor_obj = None <EOL> self . _limit = None <EOL> self . _skip = None <EOL> self . _hint = - <NUM_LIT:1> <EOL> self . only_fields = [ ] <EOL> self . _max_time_ms = None <EOL> def __call__ ( self , q_obj = None , class_check = True , read_preference = None , <EOL> ** query ) : <EOL> """<STR_LIT>""" <EOL> query = Q ( ** query ) <EOL> if q_obj : <EOL> if not isinstance ( q_obj , QNode ) : <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" % q_obj ) <EOL> raise InvalidQueryError ( msg ) <EOL> query &= q_obj <EOL> if read_preference is None : <EOL> queryset = self . clone ( ) <EOL> else : <EOL> queryset = self . read_preference ( read_preference ) <EOL> queryset . _query_obj &= query <EOL> queryset . _mongo_query = None <EOL> queryset . _cursor_obj = None <EOL> queryset . _class_check = class_check <EOL> return queryset <EOL> def __getitem__ ( self , key ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> if isinstance ( key , slice ) : <EOL> try : <EOL> queryset . _cursor_obj = queryset . _cursor [ key ] <EOL> queryset . _skip , queryset . _limit = key . start , key . stop <EOL> if key . start and key . stop : <EOL> queryset . _limit = key . stop - key . start <EOL> except IndexError , err : <EOL> start = key . start or <NUM_LIT:0> <EOL> if start >= <NUM_LIT:0> and key . stop >= <NUM_LIT:0> and key . step is None : <EOL> if start == key . stop : <EOL> queryset . limit ( <NUM_LIT:0> ) <EOL> queryset . _skip = key . start <EOL> queryset . _limit = key . stop - start <EOL> return queryset <EOL> raise err <EOL> return queryset <EOL> elif isinstance ( key , int ) : <EOL> if queryset . _scalar : <EOL> return queryset . _get_scalar ( <EOL> queryset . _document . _from_son ( queryset . _cursor [ key ] , <EOL> _auto_dereference = self . _auto_dereference , <EOL> only_fields = self . only_fields ) ) <EOL> if queryset . _as_pymongo : <EOL> return queryset . _get_as_pymongo ( queryset . _cursor [ key ] ) <EOL> return queryset . _document . _from_son ( queryset . _cursor [ key ] , <EOL> _auto_dereference = self . _auto_dereference , <EOL> only_fields = self . only_fields ) <EOL> raise AttributeError <EOL> def __iter__ ( self ) : <EOL> raise NotImplementedError <EOL> def _has_data ( self ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . order_by ( ) <EOL> return False if queryset . first ( ) is None else True <EOL> def __nonzero__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _has_data ( ) <EOL> def __bool__ ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _has_data ( ) <EOL> def all ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . __call__ ( ) <EOL> def filter ( self , * q_objs , ** query ) : <EOL> """<STR_LIT>""" <EOL> return self . __call__ ( * q_objs , ** query ) <EOL> def search_text ( self , text , language = None ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> if queryset . _search_text : <EOL> raise OperationError ( <EOL> "<STR_LIT>" ) <EOL> query_kwargs = SON ( { '<STR_LIT>' : text } ) <EOL> if language : <EOL> query_kwargs [ '<STR_LIT>' ] = language <EOL> queryset . _query_obj &= Q ( __raw__ = { '<STR_LIT>' : query_kwargs } ) <EOL> queryset . _mongo_query = None <EOL> queryset . _cursor_obj = None <EOL> queryset . _search_text = text <EOL> return queryset <EOL> def get ( self , * q_objs , ** query ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset = queryset . order_by ( ) . limit ( <NUM_LIT:2> ) <EOL> queryset = queryset . filter ( * q_objs , ** query ) <EOL> try : <EOL> result = queryset . next ( ) <EOL> except StopIteration : <EOL> msg = ( "<STR_LIT>" <EOL> % queryset . _document . _class_name ) <EOL> raise queryset . _document . DoesNotExist ( msg ) <EOL> try : <EOL> queryset . next ( ) <EOL> except StopIteration : <EOL> return result <EOL> queryset . rewind ( ) <EOL> message = u'<STR_LIT>' % queryset . count ( ) <EOL> raise queryset . _document . MultipleObjectsReturned ( message ) <EOL> def create ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return self . _document ( ** kwargs ) . save ( ) <EOL> def first ( self ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> try : <EOL> result = queryset [ <NUM_LIT:0> ] <EOL> except IndexError : <EOL> result = None <EOL> return result <EOL> def insert ( self , doc_or_docs , load_bulk = True , <EOL> write_concern = None , signal_kwargs = None ) : <EOL> """<STR_LIT>""" <EOL> Document = _import_class ( '<STR_LIT>' ) <EOL> if write_concern is None : <EOL> write_concern = { } <EOL> docs = doc_or_docs <EOL> return_one = False <EOL> if isinstance ( docs , Document ) or issubclass ( docs . __class__ , Document ) : <EOL> return_one = True <EOL> docs = [ docs ] <EOL> for doc in docs : <EOL> if not isinstance ( doc , self . _document ) : <EOL> msg = ( "<STR_LIT>" <EOL> % str ( self . _document ) ) <EOL> raise OperationError ( msg ) <EOL> if doc . pk and not doc . _created : <EOL> msg = "<STR_LIT>" <EOL> raise OperationError ( msg ) <EOL> signal_kwargs = signal_kwargs or { } <EOL> signals . pre_bulk_insert . send ( self . _document , <EOL> documents = docs , ** signal_kwargs ) <EOL> raw = [ doc . to_mongo ( ) for doc in docs ] <EOL> try : <EOL> ids = self . _collection . insert ( raw , ** write_concern ) <EOL> except pymongo . errors . DuplicateKeyError , err : <EOL> message = '<STR_LIT>' <EOL> raise NotUniqueError ( message % unicode ( err ) ) <EOL> except pymongo . errors . OperationFailure , err : <EOL> message = '<STR_LIT>' <EOL> if re . match ( '<STR_LIT>' , unicode ( err ) ) : <EOL> message = u'<STR_LIT>' <EOL> raise NotUniqueError ( message % unicode ( err ) ) <EOL> raise OperationError ( message % unicode ( err ) ) <EOL> if not load_bulk : <EOL> signals . post_bulk_insert . send ( <EOL> self . _document , documents = docs , loaded = False , ** signal_kwargs ) <EOL> return return_one and ids [ <NUM_LIT:0> ] or ids <EOL> documents = self . in_bulk ( ids ) <EOL> results = [ ] <EOL> for obj_id in ids : <EOL> results . append ( documents . get ( obj_id ) ) <EOL> signals . post_bulk_insert . send ( <EOL> self . _document , documents = results , loaded = True , ** signal_kwargs ) <EOL> return return_one and results [ <NUM_LIT:0> ] or results <EOL> def count ( self , with_limit_and_skip = False ) : <EOL> """<STR_LIT>""" <EOL> if self . _limit == <NUM_LIT:0> and with_limit_and_skip or self . _none : <EOL> return <NUM_LIT:0> <EOL> return self . _cursor . count ( with_limit_and_skip = with_limit_and_skip ) <EOL> def delete ( self , write_concern = None , _from_doc_delete = False , cascade_refs = None ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> doc = queryset . _document <EOL> if write_concern is None : <EOL> write_concern = { } <EOL> has_delete_signal = signals . signals_available and ( <EOL> signals . pre_delete . has_receivers_for ( self . _document ) or <EOL> signals . post_delete . has_receivers_for ( self . _document ) ) <EOL> call_document_delete = ( queryset . _skip or queryset . _limit or <EOL> has_delete_signal ) and not _from_doc_delete <EOL> if call_document_delete : <EOL> cnt = <NUM_LIT:0> <EOL> for doc in queryset : <EOL> doc . delete ( ** write_concern ) <EOL> cnt += <NUM_LIT:1> <EOL> return cnt <EOL> delete_rules = doc . _meta . get ( '<STR_LIT>' ) or { } <EOL> for rule_entry in delete_rules : <EOL> document_cls , field_name = rule_entry <EOL> if document_cls . _meta . get ( '<STR_LIT>' ) : <EOL> continue <EOL> rule = doc . _meta [ '<STR_LIT>' ] [ rule_entry ] <EOL> if rule == DENY and document_cls . objects ( <EOL> ** { field_name + '<STR_LIT>' : self } ) . count ( ) > <NUM_LIT:0> : <EOL> msg = ( "<STR_LIT>" <EOL> % ( document_cls . __name__ , field_name ) ) <EOL> raise OperationError ( msg ) <EOL> for rule_entry in delete_rules : <EOL> document_cls , field_name = rule_entry <EOL> if document_cls . _meta . get ( '<STR_LIT>' ) : <EOL> continue <EOL> rule = doc . _meta [ '<STR_LIT>' ] [ rule_entry ] <EOL> if rule == CASCADE : <EOL> cascade_refs = set ( ) if cascade_refs is None else cascade_refs <EOL> if doc . _collection == document_cls . _collection : <EOL> for ref in queryset : <EOL> cascade_refs . add ( ref . id ) <EOL> ref_q = document_cls . objects ( ** { field_name + '<STR_LIT>' : self , '<STR_LIT>' : cascade_refs } ) <EOL> ref_q_count = ref_q . count ( ) <EOL> if ref_q_count > <NUM_LIT:0> : <EOL> ref_q . delete ( write_concern = write_concern , cascade_refs = cascade_refs ) <EOL> elif rule == NULLIFY : <EOL> document_cls . objects ( ** { field_name + '<STR_LIT>' : self } ) . update ( <EOL> write_concern = write_concern , ** { '<STR_LIT>' % field_name : <NUM_LIT:1> } ) <EOL> elif rule == PULL : <EOL> document_cls . objects ( ** { field_name + '<STR_LIT>' : self } ) . update ( <EOL> write_concern = write_concern , <EOL> ** { '<STR_LIT>' % field_name : self } ) <EOL> result = queryset . _collection . remove ( queryset . _query , ** write_concern ) <EOL> if result : <EOL> return result . get ( "<STR_LIT:n>" ) <EOL> def update ( self , upsert = False , multi = True , write_concern = None , <EOL> full_result = False , ** update ) : <EOL> """<STR_LIT>""" <EOL> if not update and not upsert : <EOL> raise OperationError ( "<STR_LIT>" ) <EOL> if write_concern is None : <EOL> write_concern = { } <EOL> queryset = self . clone ( ) <EOL> query = queryset . _query <EOL> update = transform . update ( queryset . _document , ** update ) <EOL> if upsert and '<STR_LIT>' in query : <EOL> if '<STR_LIT>' in update : <EOL> update [ "<STR_LIT>" ] [ "<STR_LIT>" ] = queryset . _document . _class_name <EOL> else : <EOL> update [ "<STR_LIT>" ] = { "<STR_LIT>" : queryset . _document . _class_name } <EOL> try : <EOL> result = queryset . _collection . update ( query , update , multi = multi , <EOL> upsert = upsert , ** write_concern ) <EOL> if full_result : <EOL> return result <EOL> elif result : <EOL> return result [ '<STR_LIT:n>' ] <EOL> except pymongo . errors . DuplicateKeyError , err : <EOL> raise NotUniqueError ( u'<STR_LIT>' % unicode ( err ) ) <EOL> except pymongo . errors . OperationFailure , err : <EOL> if unicode ( err ) == u'<STR_LIT>' : <EOL> message = u'<STR_LIT>' <EOL> raise OperationError ( message ) <EOL> raise OperationError ( u'<STR_LIT>' % unicode ( err ) ) <EOL> def upsert_one ( self , write_concern = None , ** update ) : <EOL> """<STR_LIT>""" <EOL> atomic_update = self . update ( multi = False , upsert = True , write_concern = write_concern , <EOL> full_result = True , ** update ) <EOL> if atomic_update [ '<STR_LIT>' ] : <EOL> document = self . get ( ) <EOL> else : <EOL> document = self . _document . objects . with_id ( atomic_update [ '<STR_LIT>' ] ) <EOL> return document <EOL> def update_one ( self , upsert = False , write_concern = None , ** update ) : <EOL> """<STR_LIT>""" <EOL> return self . update ( <EOL> upsert = upsert , multi = False , write_concern = write_concern , ** update ) <EOL> def modify ( self , upsert = False , full_response = False , remove = False , new = False , ** update ) : <EOL> """<STR_LIT>""" <EOL> if remove and new : <EOL> raise OperationError ( "<STR_LIT>" ) <EOL> if not update and not upsert and not remove : <EOL> raise OperationError ( <EOL> "<STR_LIT>" ) <EOL> queryset = self . clone ( ) <EOL> query = queryset . _query <EOL> if not IS_PYMONGO_3 or not remove : <EOL> update = transform . update ( queryset . _document , ** update ) <EOL> sort = queryset . _ordering <EOL> try : <EOL> if IS_PYMONGO_3 : <EOL> if full_response : <EOL> msg = "<STR_LIT>" <EOL> warnings . warn ( msg , DeprecationWarning ) <EOL> if remove : <EOL> result = queryset . _collection . find_one_and_delete ( <EOL> query , sort = sort , ** self . _cursor_args ) <EOL> else : <EOL> if new : <EOL> return_doc = ReturnDocument . AFTER <EOL> else : <EOL> return_doc = ReturnDocument . BEFORE <EOL> result = queryset . _collection . find_one_and_update ( <EOL> query , update , upsert = upsert , sort = sort , return_document = return_doc , <EOL> ** self . _cursor_args ) <EOL> else : <EOL> result = queryset . _collection . find_and_modify ( <EOL> query , update , upsert = upsert , sort = sort , remove = remove , new = new , <EOL> full_response = full_response , ** self . _cursor_args ) <EOL> except pymongo . errors . DuplicateKeyError , err : <EOL> raise NotUniqueError ( u"<STR_LIT>" % err ) <EOL> except pymongo . errors . OperationFailure , err : <EOL> raise OperationError ( u"<STR_LIT>" % err ) <EOL> if full_response : <EOL> if result [ "<STR_LIT:value>" ] is not None : <EOL> result [ "<STR_LIT:value>" ] = self . _document . _from_son ( result [ "<STR_LIT:value>" ] , only_fields = self . only_fields ) <EOL> else : <EOL> if result is not None : <EOL> result = self . _document . _from_son ( result , only_fields = self . only_fields ) <EOL> return result <EOL> def with_id ( self , object_id ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> if not queryset . _query_obj . empty : <EOL> msg = "<STR_LIT>" <EOL> raise InvalidQueryError ( msg ) <EOL> return queryset . filter ( pk = object_id ) . first ( ) <EOL> def in_bulk ( self , object_ids ) : <EOL> """<STR_LIT>""" <EOL> doc_map = { } <EOL> docs = self . _collection . find ( { '<STR_LIT>' : { '<STR_LIT>' : object_ids } } , <EOL> ** self . _cursor_args ) <EOL> if self . _scalar : <EOL> for doc in docs : <EOL> doc_map [ doc [ '<STR_LIT>' ] ] = self . _get_scalar ( <EOL> self . _document . _from_son ( doc , only_fields = self . only_fields ) ) <EOL> elif self . _as_pymongo : <EOL> for doc in docs : <EOL> doc_map [ doc [ '<STR_LIT>' ] ] = self . _get_as_pymongo ( doc ) <EOL> else : <EOL> for doc in docs : <EOL> doc_map [ doc [ '<STR_LIT>' ] ] = self . _document . _from_son ( <EOL> doc , <EOL> only_fields = self . only_fields , <EOL> _auto_dereference = self . _auto_dereference ) <EOL> return doc_map <EOL> def none ( self ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset . _none = True <EOL> return queryset <EOL> def no_sub_classes ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _document . _meta . get ( '<STR_LIT>' ) is True : <EOL> self . _initial_query = { "<STR_LIT>" : self . _document . _class_name } <EOL> return self <EOL> def using ( self , alias ) : <EOL> """<STR_LIT>""" <EOL> with switch_db ( self . _document , alias ) as cls : <EOL> collection = cls . _get_collection ( ) <EOL> return self . clone_into ( self . __class__ ( self . _document , collection ) ) <EOL> def clone ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . clone_into ( self . __class__ ( self . _document , self . _collection_obj ) ) <EOL> def clone_into ( self , cls ) : <EOL> """<STR_LIT>""" <EOL> if not isinstance ( cls , BaseQuerySet ) : <EOL> raise OperationError ( <EOL> '<STR_LIT>' % cls . __name__ ) <EOL> copy_props = ( '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ) <EOL> for prop in copy_props : <EOL> val = getattr ( self , prop ) <EOL> setattr ( cls , prop , copy . copy ( val ) ) <EOL> if self . _cursor_obj : <EOL> cls . _cursor_obj = self . _cursor_obj . clone ( ) <EOL> return cls <EOL> def select_related ( self , max_depth = <NUM_LIT:1> ) : <EOL> """<STR_LIT>""" <EOL> max_depth += <NUM_LIT:1> <EOL> queryset = self . clone ( ) <EOL> return queryset . _dereference ( queryset , max_depth = max_depth ) <EOL> def limit ( self , n ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset . _limit = n if n != <NUM_LIT:0> else <NUM_LIT:1> <EOL> return queryset <EOL> def skip ( self , n ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset . _skip = n <EOL> return queryset <EOL> def hint ( self , index = None ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset . _hint = index <EOL> return queryset <EOL> def distinct ( self , field ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> try : <EOL> field = self . _fields_to_dbfields ( [ field ] ) . pop ( ) <EOL> finally : <EOL> distinct = self . _dereference ( queryset . _cursor . distinct ( field ) , <NUM_LIT:1> , <EOL> name = field , instance = self . _document ) <EOL> doc_field = self . _document . _fields . get ( field . split ( '<STR_LIT:.>' , <NUM_LIT:1> ) [ <NUM_LIT:0> ] ) <EOL> instance = False <EOL> EmbeddedDocumentField = _import_class ( '<STR_LIT>' ) <EOL> ListField = _import_class ( '<STR_LIT>' ) <EOL> GenericEmbeddedDocumentField = _import_class ( '<STR_LIT>' ) <EOL> if isinstance ( doc_field , ListField ) : <EOL> doc_field = getattr ( doc_field , "<STR_LIT>" , doc_field ) <EOL> if isinstance ( doc_field , ( EmbeddedDocumentField , GenericEmbeddedDocumentField ) ) : <EOL> instance = getattr ( doc_field , "<STR_LIT>" , False ) <EOL> if '<STR_LIT:.>' in field : <EOL> for field_part in field . split ( '<STR_LIT:.>' ) [ <NUM_LIT:1> : ] : <EOL> if instance and isinstance ( doc_field , ( EmbeddedDocumentField , GenericEmbeddedDocumentField ) ) : <EOL> doc_field = instance <EOL> doc_field = getattr ( doc_field , field_part , doc_field ) <EOL> if isinstance ( doc_field , ListField ) : <EOL> doc_field = getattr ( doc_field , "<STR_LIT>" , doc_field ) <EOL> if isinstance ( doc_field , ( EmbeddedDocumentField , GenericEmbeddedDocumentField ) ) : <EOL> instance = getattr ( doc_field , "<STR_LIT>" , False ) <EOL> if instance and isinstance ( doc_field , ( EmbeddedDocumentField , <EOL> GenericEmbeddedDocumentField ) ) : <EOL> distinct = [ instance ( ** doc ) for doc in distinct ] <EOL> return distinct <EOL> def only ( self , * fields ) : <EOL> """<STR_LIT>""" <EOL> fields = dict ( [ ( f , QueryFieldList . ONLY ) for f in fields ] ) <EOL> self . only_fields = fields . keys ( ) <EOL> return self . fields ( True , ** fields ) <EOL> def exclude ( self , * fields ) : <EOL> """<STR_LIT>""" <EOL> fields = dict ( [ ( f , QueryFieldList . EXCLUDE ) for f in fields ] ) <EOL> return self . fields ( ** fields ) <EOL> def fields ( self , _only_called = False , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> operators = [ "<STR_LIT>" ] <EOL> cleaned_fields = [ ] <EOL> for key , value in kwargs . items ( ) : <EOL> parts = key . split ( '<STR_LIT>' ) <EOL> if parts [ <NUM_LIT:0> ] in operators : <EOL> op = parts . pop ( <NUM_LIT:0> ) <EOL> value = { '<STR_LIT:$>' + op : value } <EOL> key = '<STR_LIT:.>' . join ( parts ) <EOL> cleaned_fields . append ( ( key , value ) ) <EOL> fields = sorted ( cleaned_fields , key = operator . itemgetter ( <NUM_LIT:1> ) ) <EOL> queryset = self . clone ( ) <EOL> for value , group in itertools . groupby ( fields , lambda x : x [ <NUM_LIT:1> ] ) : <EOL> fields = [ field for field , value in group ] <EOL> fields = queryset . _fields_to_dbfields ( fields ) <EOL> queryset . _loaded_fields += QueryFieldList ( <EOL> fields , value = value , _only_called = _only_called ) <EOL> return queryset <EOL> def all_fields ( self ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset . _loaded_fields = QueryFieldList ( <EOL> always_include = queryset . _loaded_fields . always_include ) <EOL> return queryset <EOL> def order_by ( self , * keys ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset . _ordering = queryset . _get_order_by ( keys ) <EOL> return queryset <EOL> def explain ( self , format = False ) : <EOL> """<STR_LIT>""" <EOL> plan = self . _cursor . explain ( ) <EOL> if format : <EOL> plan = pprint . pformat ( plan ) <EOL> return plan <EOL> def snapshot ( self , enabled ) : <EOL> """<STR_LIT>""" <EOL> if IS_PYMONGO_3 : <EOL> msg = "<STR_LIT>" <EOL> warnings . warn ( msg , DeprecationWarning ) <EOL> queryset = self . clone ( ) <EOL> queryset . _snapshot = enabled <EOL> return queryset <EOL> def timeout ( self , enabled ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset . _timeout = enabled <EOL> return queryset <EOL> def slave_okay ( self , enabled ) : <EOL> """<STR_LIT>""" <EOL> if IS_PYMONGO_3 : <EOL> msg = "<STR_LIT>" <EOL> warnings . warn ( msg , DeprecationWarning ) <EOL> queryset = self . clone ( ) <EOL> queryset . _slave_okay = enabled <EOL> return queryset <EOL> def read_preference ( self , read_preference ) : <EOL> """<STR_LIT>""" <EOL> validate_read_preference ( '<STR_LIT>' , read_preference ) <EOL> queryset = self . clone ( ) <EOL> queryset . _read_preference = read_preference <EOL> queryset . _cursor_obj = None <EOL> return queryset <EOL> def scalar ( self , * fields ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset . _scalar = list ( fields ) <EOL> if fields : <EOL> queryset = queryset . only ( * fields ) <EOL> else : <EOL> queryset = queryset . all_fields ( ) <EOL> return queryset <EOL> def values_list ( self , * fields ) : <EOL> """<STR_LIT>""" <EOL> return self . scalar ( * fields ) <EOL> def as_pymongo ( self , coerce_types = False ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset . _as_pymongo = True <EOL> queryset . _as_pymongo_coerce = coerce_types <EOL> return queryset <EOL> def max_time_ms ( self , ms ) : <EOL> """<STR_LIT>""" <EOL> return self . _chainable_method ( "<STR_LIT>" , ms ) <EOL> def to_json ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> return json_util . dumps ( self . as_pymongo ( ) , * args , ** kwargs ) <EOL> def from_json ( self , json_data ) : <EOL> """<STR_LIT>""" <EOL> son_data = json_util . loads ( json_data ) <EOL> return [ self . _document . _from_son ( data , only_fields = self . only_fields ) for data in son_data ] <EOL> def aggregate ( self , * pipeline , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> initial_pipeline = [ ] <EOL> if self . _query : <EOL> initial_pipeline . append ( { '<STR_LIT>' : self . _query } ) <EOL> if self . _ordering : <EOL> initial_pipeline . append ( { '<STR_LIT>' : dict ( self . _ordering ) } ) <EOL> if self . _limit is not None : <EOL> initial_pipeline . append ( { '<STR_LIT>' : self . _limit } ) <EOL> if self . _skip is not None : <EOL> initial_pipeline . append ( { '<STR_LIT>' : self . _skip } ) <EOL> pipeline = initial_pipeline + list ( pipeline ) <EOL> return self . _collection . aggregate ( pipeline , cursor = { } , ** kwargs ) <EOL> def map_reduce ( self , map_f , reduce_f , output , finalize_f = None , limit = None , <EOL> scope = None ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> MapReduceDocument = _import_class ( '<STR_LIT>' ) <EOL> if not hasattr ( self . _collection , "<STR_LIT>" ) : <EOL> raise NotImplementedError ( "<STR_LIT>" ) <EOL> map_f_scope = { } <EOL> if isinstance ( map_f , Code ) : <EOL> map_f_scope = map_f . scope <EOL> map_f = unicode ( map_f ) <EOL> map_f = Code ( queryset . _sub_js_fields ( map_f ) , map_f_scope ) <EOL> reduce_f_scope = { } <EOL> if isinstance ( reduce_f , Code ) : <EOL> reduce_f_scope = reduce_f . scope <EOL> reduce_f = unicode ( reduce_f ) <EOL> reduce_f_code = queryset . _sub_js_fields ( reduce_f ) <EOL> reduce_f = Code ( reduce_f_code , reduce_f_scope ) <EOL> mr_args = { '<STR_LIT>' : queryset . _query } <EOL> if finalize_f : <EOL> finalize_f_scope = { } <EOL> if isinstance ( finalize_f , Code ) : <EOL> finalize_f_scope = finalize_f . scope <EOL> finalize_f = unicode ( finalize_f ) <EOL> finalize_f_code = queryset . _sub_js_fields ( finalize_f ) <EOL> finalize_f = Code ( finalize_f_code , finalize_f_scope ) <EOL> mr_args [ '<STR_LIT>' ] = finalize_f <EOL> if scope : <EOL> mr_args [ '<STR_LIT>' ] = scope <EOL> if limit : <EOL> mr_args [ '<STR_LIT>' ] = limit <EOL> if output == '<STR_LIT>' and not queryset . _ordering : <EOL> map_reduce_function = '<STR_LIT>' <EOL> else : <EOL> map_reduce_function = '<STR_LIT>' <EOL> if isinstance ( output , basestring ) : <EOL> mr_args [ '<STR_LIT>' ] = output <EOL> elif isinstance ( output , dict ) : <EOL> ordered_output = [ ] <EOL> for part in ( '<STR_LIT:replace>' , '<STR_LIT>' , '<STR_LIT>' ) : <EOL> value = output . get ( part ) <EOL> if value : <EOL> ordered_output . append ( ( part , value ) ) <EOL> break <EOL> else : <EOL> raise OperationError ( "<STR_LIT>" ) <EOL> db_alias = output . get ( '<STR_LIT>' ) <EOL> remaing_args = [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT>' ] <EOL> if db_alias : <EOL> ordered_output . append ( ( '<STR_LIT>' , get_db ( db_alias ) . name ) ) <EOL> del remaing_args [ <NUM_LIT:0> ] <EOL> for part in remaing_args : <EOL> value = output . get ( part ) <EOL> if value : <EOL> ordered_output . append ( ( part , value ) ) <EOL> mr_args [ '<STR_LIT>' ] = SON ( ordered_output ) <EOL> results = getattr ( queryset . _collection , map_reduce_function ) ( <EOL> map_f , reduce_f , ** mr_args ) <EOL> if map_reduce_function == '<STR_LIT>' : <EOL> results = results . find ( ) <EOL> if queryset . _ordering : <EOL> results = results . sort ( queryset . _ordering ) <EOL> for doc in results : <EOL> yield MapReduceDocument ( queryset . _document , queryset . _collection , <EOL> doc [ '<STR_LIT>' ] , doc [ '<STR_LIT:value>' ] ) <EOL> def exec_js ( self , code , * fields , ** options ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> code = queryset . _sub_js_fields ( code ) <EOL> fields = [ queryset . _document . _translate_field_name ( f ) for f in fields ] <EOL> collection = queryset . _document . _get_collection_name ( ) <EOL> scope = { <EOL> '<STR_LIT>' : collection , <EOL> '<STR_LIT>' : options or { } , <EOL> } <EOL> query = queryset . _query <EOL> if queryset . _where_clause : <EOL> query [ '<STR_LIT>' ] = queryset . _where_clause <EOL> scope [ '<STR_LIT>' ] = query <EOL> code = Code ( code , scope = scope ) <EOL> db = queryset . _document . _get_db ( ) <EOL> return db . eval ( code , * fields ) <EOL> def where ( self , where_clause ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> where_clause = queryset . _sub_js_fields ( where_clause ) <EOL> queryset . _where_clause = where_clause <EOL> return queryset <EOL> def sum ( self , field ) : <EOL> """<STR_LIT>""" <EOL> map_func = """<STR_LIT>""" % dict ( field = field ) <EOL> reduce_func = Code ( """<STR_LIT>""" ) <EOL> for result in self . map_reduce ( map_func , reduce_func , output = '<STR_LIT>' ) : <EOL> return result . value <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def aggregate_sum ( self , field ) : <EOL> """<STR_LIT>""" <EOL> result = self . _document . _get_collection ( ) . aggregate ( [ <EOL> { '<STR_LIT>' : self . _query } , <EOL> { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT:$>' + field } } } <EOL> ] ) <EOL> if IS_PYMONGO_3 : <EOL> result = list ( result ) <EOL> else : <EOL> result = result . get ( '<STR_LIT:result>' ) <EOL> if result : <EOL> return result [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> return <NUM_LIT:0> <EOL> def average ( self , field ) : <EOL> """<STR_LIT>""" <EOL> map_func = """<STR_LIT>""" % dict ( field = field ) <EOL> reduce_func = Code ( """<STR_LIT>""" ) <EOL> finalize_func = Code ( """<STR_LIT>""" ) <EOL> for result in self . map_reduce ( map_func , reduce_func , <EOL> finalize_f = finalize_func , output = '<STR_LIT>' ) : <EOL> return result . value <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def aggregate_average ( self , field ) : <EOL> """<STR_LIT>""" <EOL> result = self . _document . _get_collection ( ) . aggregate ( [ <EOL> { '<STR_LIT>' : self . _query } , <EOL> { '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : { '<STR_LIT>' : '<STR_LIT:$>' + field } } } <EOL> ] ) <EOL> if IS_PYMONGO_3 : <EOL> result = list ( result ) <EOL> else : <EOL> result = result . get ( '<STR_LIT:result>' ) <EOL> if result : <EOL> return result [ <NUM_LIT:0> ] [ '<STR_LIT>' ] <EOL> return <NUM_LIT:0> <EOL> def item_frequencies ( self , field , normalize = False , map_reduce = True ) : <EOL> """<STR_LIT>""" <EOL> if map_reduce : <EOL> return self . _item_frequencies_map_reduce ( field , <EOL> normalize = normalize ) <EOL> return self . _item_frequencies_exec_js ( field , normalize = normalize ) <EOL> def next ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . _limit == <NUM_LIT:0> or self . _none : <EOL> raise StopIteration <EOL> raw_doc = self . _cursor . next ( ) <EOL> if self . _as_pymongo : <EOL> return self . _get_as_pymongo ( raw_doc ) <EOL> doc = self . _document . _from_son ( raw_doc , <EOL> _auto_dereference = self . _auto_dereference , only_fields = self . only_fields ) <EOL> if self . _scalar : <EOL> return self . _get_scalar ( doc ) <EOL> return doc <EOL> def rewind ( self ) : <EOL> """<STR_LIT>""" <EOL> self . _iter = False <EOL> self . _cursor . rewind ( ) <EOL> @ property <EOL> def _collection ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _collection_obj <EOL> @ property <EOL> def _cursor_args ( self ) : <EOL> if not IS_PYMONGO_3 : <EOL> fields_name = '<STR_LIT>' <EOL> cursor_args = { <EOL> '<STR_LIT>' : self . _timeout , <EOL> '<STR_LIT>' : self . _snapshot <EOL> } <EOL> if self . _read_preference is not None : <EOL> cursor_args [ '<STR_LIT>' ] = self . _read_preference <EOL> else : <EOL> cursor_args [ '<STR_LIT>' ] = self . _slave_okay <EOL> else : <EOL> fields_name = '<STR_LIT>' <EOL> if self . _snapshot : <EOL> msg = "<STR_LIT>" <EOL> warnings . warn ( msg , DeprecationWarning ) <EOL> cursor_args = { <EOL> '<STR_LIT>' : self . _timeout <EOL> } <EOL> if self . _loaded_fields : <EOL> cursor_args [ fields_name ] = self . _loaded_fields . as_dict ( ) <EOL> if self . _search_text : <EOL> if fields_name not in cursor_args : <EOL> cursor_args [ fields_name ] = { } <EOL> cursor_args [ fields_name ] [ '<STR_LIT>' ] = { '<STR_LIT>' : "<STR_LIT>" } <EOL> return cursor_args <EOL> @ property <EOL> def _cursor ( self ) : <EOL> if self . _cursor_obj is None : <EOL> if IS_PYMONGO_3 and self . _read_preference is not None : <EOL> self . _cursor_obj = self . _collection . with_options ( read_preference = self . _read_preference ) . find ( self . _query , ** self . _cursor_args ) <EOL> else : <EOL> self . _cursor_obj = self . _collection . find ( self . _query , <EOL> ** self . _cursor_args ) <EOL> if self . _where_clause : <EOL> where_clause = self . _sub_js_fields ( self . _where_clause ) <EOL> self . _cursor_obj . where ( where_clause ) <EOL> if self . _ordering : <EOL> self . _cursor_obj . sort ( self . _ordering ) <EOL> elif self . _ordering is None and self . _document . _meta [ '<STR_LIT>' ] : <EOL> order = self . _get_order_by ( self . _document . _meta [ '<STR_LIT>' ] ) <EOL> self . _cursor_obj . sort ( order ) <EOL> if self . _limit is not None : <EOL> self . _cursor_obj . limit ( self . _limit ) <EOL> if self . _skip is not None : <EOL> self . _cursor_obj . skip ( self . _skip ) <EOL> if self . _hint != - <NUM_LIT:1> : <EOL> self . _cursor_obj . hint ( self . _hint ) <EOL> return self . _cursor_obj <EOL> def __deepcopy__ ( self , memo ) : <EOL> """<STR_LIT>""" <EOL> return self . clone ( ) <EOL> @ property <EOL> def _query ( self ) : <EOL> if self . _mongo_query is None : <EOL> self . _mongo_query = self . _query_obj . to_query ( self . _document ) <EOL> if self . _class_check and self . _initial_query : <EOL> if "<STR_LIT>" in self . _mongo_query : <EOL> self . _mongo_query = { "<STR_LIT>" : [ self . _initial_query , self . _mongo_query ] } <EOL> else : <EOL> self . _mongo_query . update ( self . _initial_query ) <EOL> return self . _mongo_query <EOL> @ property <EOL> def _dereference ( self ) : <EOL> if not self . __dereference : <EOL> self . __dereference = _import_class ( '<STR_LIT>' ) ( ) <EOL> return self . __dereference <EOL> def no_dereference ( self ) : <EOL> """<STR_LIT>""" <EOL> queryset = self . clone ( ) <EOL> queryset . _auto_dereference = False <EOL> return queryset <EOL> def _item_frequencies_map_reduce ( self , field , normalize = False ) : <EOL> map_func = """<STR_LIT>""" % dict ( field = field ) <EOL> reduce_func = """<STR_LIT>""" <EOL> values = self . map_reduce ( map_func , reduce_func , '<STR_LIT>' ) <EOL> frequencies = { } <EOL> for f in values : <EOL> key = f . key <EOL> if isinstance ( key , float ) : <EOL> if int ( key ) == key : <EOL> key = int ( key ) <EOL> frequencies [ key ] = int ( f . value ) <EOL> if normalize : <EOL> count = sum ( frequencies . values ( ) ) <EOL> frequencies = dict ( [ ( k , float ( v ) / count ) <EOL> for k , v in frequencies . items ( ) ] ) <EOL> return frequencies <EOL> def _item_frequencies_exec_js ( self , field , normalize = False ) : <EOL> """<STR_LIT>""" <EOL> freq_func = """<STR_LIT>""" <EOL> total , data , types = self . exec_js ( freq_func , field ) <EOL> values = dict ( [ ( types . get ( k ) , int ( v ) ) for k , v in data . iteritems ( ) ] ) <EOL> if normalize : <EOL> values = dict ( [ ( k , float ( v ) / total ) for k , v in values . items ( ) ] ) <EOL> frequencies = { } <EOL> for k , v in values . iteritems ( ) : <EOL> if isinstance ( k , float ) : <EOL> if int ( k ) == k : <EOL> k = int ( k ) <EOL> frequencies [ k ] = v <EOL> return frequencies <EOL> def _fields_to_dbfields ( self , fields ) : <EOL> """<STR_LIT>""" <EOL> ret = [ ] <EOL> subclasses = [ ] <EOL> document = self . _document <EOL> if document . _meta [ '<STR_LIT>' ] : <EOL> subclasses = [ get_document ( x ) <EOL> for x in document . _subclasses ] [ <NUM_LIT:1> : ] <EOL> for field in fields : <EOL> try : <EOL> field = "<STR_LIT:.>" . join ( f . db_field for f in <EOL> document . _lookup_field ( field . split ( '<STR_LIT:.>' ) ) ) <EOL> ret . append ( field ) <EOL> except LookUpError , err : <EOL> found = False <EOL> for subdoc in subclasses : <EOL> try : <EOL> subfield = "<STR_LIT:.>" . join ( f . db_field for f in <EOL> subdoc . _lookup_field ( field . split ( '<STR_LIT:.>' ) ) ) <EOL> ret . append ( subfield ) <EOL> found = True <EOL> break <EOL> except LookUpError : <EOL> pass <EOL> if not found : <EOL> raise err <EOL> return ret <EOL> def _get_order_by ( self , keys ) : <EOL> """<STR_LIT>""" <EOL> key_list = [ ] <EOL> for key in keys : <EOL> if not key : <EOL> continue <EOL> if key == '<STR_LIT>' : <EOL> key_list . append ( ( '<STR_LIT>' , { '<STR_LIT>' : "<STR_LIT>" } ) ) <EOL> continue <EOL> direction = pymongo . ASCENDING <EOL> if key [ <NUM_LIT:0> ] == '<STR_LIT:->' : <EOL> direction = pymongo . DESCENDING <EOL> if key [ <NUM_LIT:0> ] in ( '<STR_LIT:->' , '<STR_LIT:+>' ) : <EOL> key = key [ <NUM_LIT:1> : ] <EOL> key = key . replace ( '<STR_LIT>' , '<STR_LIT:.>' ) <EOL> try : <EOL> key = self . _document . _translate_field_name ( key ) <EOL> except Exception : <EOL> pass <EOL> key_list . append ( ( key , direction ) ) <EOL> if self . _cursor_obj and key_list : <EOL> self . _cursor_obj . sort ( key_list ) <EOL> return key_list <EOL> def _get_scalar ( self , doc ) : <EOL> def lookup ( obj , name ) : <EOL> chunks = name . split ( '<STR_LIT>' ) <EOL> for chunk in chunks : <EOL> obj = getattr ( obj , chunk ) <EOL> return obj <EOL> data = [ lookup ( doc , n ) for n in self . _scalar ] <EOL> if len ( data ) == <NUM_LIT:1> : <EOL> return data [ <NUM_LIT:0> ] <EOL> return tuple ( data ) <EOL> def _get_as_pymongo ( self , row ) : <EOL> if not getattr ( self , '<STR_LIT>' , None ) : <EOL> self . __as_pymongo_fields = [ ] <EOL> for field in self . _loaded_fields . fields - set ( [ '<STR_LIT>' ] ) : <EOL> self . __as_pymongo_fields . append ( field ) <EOL> while '<STR_LIT:.>' in field : <EOL> field , _ = field . rsplit ( '<STR_LIT:.>' , <NUM_LIT:1> ) <EOL> self . __as_pymongo_fields . append ( field ) <EOL> all_fields = not self . __as_pymongo_fields <EOL> def clean ( data , path = None ) : <EOL> path = path or '<STR_LIT>' <EOL> if isinstance ( data , dict ) : <EOL> new_data = { } <EOL> for key , value in data . iteritems ( ) : <EOL> new_path = '<STR_LIT>' % ( path , key ) if path else key <EOL> if all_fields : <EOL> include_field = True <EOL> elif self . _loaded_fields . value == QueryFieldList . ONLY : <EOL> include_field = new_path in self . __as_pymongo_fields <EOL> else : <EOL> include_field = new_path not in self . __as_pymongo_fields <EOL> if include_field : <EOL> new_data [ key ] = clean ( value , path = new_path ) <EOL> data = new_data <EOL> elif isinstance ( data , list ) : <EOL> data = [ clean ( d , path = path ) for d in data ] <EOL> else : <EOL> if self . _as_pymongo_coerce : <EOL> from mongoengine . fields import EmbeddedDocumentField <EOL> obj = self . _document <EOL> for chunk in path . split ( '<STR_LIT:.>' ) : <EOL> obj = getattr ( obj , chunk , None ) <EOL> if obj is None : <EOL> break <EOL> elif isinstance ( obj , EmbeddedDocumentField ) : <EOL> obj = obj . document_type <EOL> if obj and data is not None : <EOL> data = obj . to_python ( data ) <EOL> return data <EOL> return clean ( row ) <EOL> def _sub_js_fields ( self , code ) : <EOL> """<STR_LIT>""" <EOL> def field_sub ( match ) : <EOL> field_name = match . group ( <NUM_LIT:1> ) . split ( '<STR_LIT:.>' ) <EOL> fields = self . _document . _lookup_field ( field_name ) <EOL> return u'<STR_LIT>' % fields [ - <NUM_LIT:1> ] . db_field <EOL> def field_path_sub ( match ) : <EOL> field_name = match . group ( <NUM_LIT:1> ) . split ( '<STR_LIT:.>' ) <EOL> fields = self . _document . _lookup_field ( field_name ) <EOL> return "<STR_LIT:.>" . join ( [ f . db_field for f in fields ] ) <EOL> code = re . sub ( u'<STR_LIT>' , field_sub , code ) <EOL> code = re . sub ( u'<STR_LIT>' , field_path_sub , <EOL> code ) <EOL> return code <EOL> def _chainable_method ( self , method_name , val ) : <EOL> queryset = self . clone ( ) <EOL> method = getattr ( queryset . _cursor , method_name ) <EOL> method ( val ) <EOL> setattr ( queryset , "<STR_LIT:_>" + method_name , val ) <EOL> return queryset <EOL> def ensure_index ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> warnings . warn ( msg , DeprecationWarning ) <EOL> self . _document . __class__ . ensure_index ( ** kwargs ) <EOL> return self <EOL> def _ensure_indexes ( self ) : <EOL> """<STR_LIT>""" <EOL> msg = ( "<STR_LIT>" <EOL> "<STR_LIT>" ) <EOL> warnings . warn ( msg , DeprecationWarning ) <EOL> self . _document . __class__ . ensure_indexes ( ) </s>
