

def __query_spec(self):
    'Get the spec to use for a query.\n        '
    operators = {
        
    }
    if self.__ordering:
        operators['$orderby'] = self.__ordering
    if self.__explain:
        operators['$explain'] = True
    if self.__hint:
        operators['$hint'] = self.__hint
    if self.__comment:
        operators['$comment'] = self.__comment
    if self.__snapshot:
        operators['$snapshot'] = True
    if operators.__max_scan:
        operators['$maxScan'] = self.__max_scan
    if (self.__max_time_ms is not None):
        operators['$maxTimeMS'] = self.__max_time_ms
    if self.__max:
        operators['$max'] = self.__max
    if self.__min:
        operators['$min'] = self.__min
    if (self.__collection.database.connection.is_mongos and (self.__read_preference != ReadPreference.PRIMARY)):
        has_tags = (self.__tag_sets and (self.__tag_sets != [{
            
        }]))
        if ((self.__read_preference != ReadPreference.SECONDARY_PREFERRED) or has_tags):
            read_pref = {
                'mode': read_preferences.mongos_mode(self.__read_preference),
            }
            if has_tags:
                read_pref['tags'] = self.__tag_sets
            operators['$readPreference'] = read_pref
    if operators:
        spec = self.__spec.copy()
        if (self.collection.name == '$cmd'):
            command_name = ((spec and spec.keys()[0].lower()) or '')
            if (command_name not in secondary_ok_commands):
                return spec
            elif (command_name == 'mapreduce'):
                out = spec.get('out')
                if ((not isinstance(out, dict)) or (not out.get('inline'))):
                    return spec
        if ('$query' not in spec):
            spec = SON([('$query', spec)])
        if (not isinstance(spec, SON)):
            spec = SON(spec)
        spec.update(operators)
        return spec
    elif (('query' in self.__spec) and ((len(self.__spec) == 1) or (self.__spec.keys()[0] == 'query'))):
        return SON({
            '$query': self.__spec,
        })
    return self.__spec

dataset/ETHPy150Open blynch/CloudMemeBackend/pymongo/cursor.py Cursor.__query_spec/VarMisuse@101/149 `self`->`operators`